#include <config.h>
#include "virsh-pool.h"
+#include "virsh-util.h"
#include "internal.h"
#include "virbuffer.h"
static bool
cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *name;
int autostart;
vshError(ctl, _("failed to mark pool %s as autostarted"), name);
else
vshError(ctl, _("failed to unmark pool %s as autostarted"), name);
- virStoragePoolFree(pool);
return false;
}
else
vshPrintExtra(ctl, _("Pool %s unmarked as autostarted\n"), name);
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
bool build;
vshPrintExtra(ctl, _("Pool %s created from %s\n"),
virStoragePoolGetName(pool), from);
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *name;
g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml");
}
vshPrintExtra(ctl, _("Pool %s created\n"), name);
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
vshPrintExtra(ctl, _("Pool %s defined from %s\n"),
virStoragePoolGetName(pool), from);
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *name;
g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml");
}
vshPrintExtra(ctl, _("Pool %s defined\n"), name);
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name;
unsigned int flags = 0;
ret = false;
}
- virStoragePoolFree(pool);
-
return ret;
}
static bool
cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name;
vshError(ctl, _("Failed to refresh pool %s"), name);
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
bool inactive = vshCommandOptBool(cmd, "inactive");
unsigned int flags = 0;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
if (list && list->pools) {
for (i = 0; i < list->npools; i++) {
- if (list->pools[i])
- virStoragePoolFree(list->pools[i]);
+ virshStoragePoolFree(list->pools[i]);
}
g_free(list->pools);
}
remove_entry:
/* the pool has to be removed as it failed one of the filters */
- virStoragePoolFree(list->pools[i]);
- list->pools[i] = NULL;
+ g_clear_pointer(&list->pools[i], virshStoragePoolFree);
deleted++;
}
cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolInfo info;
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
int autostart = 0;
bool ret = true;
bool bytes = false;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolName(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
- virStoragePoolFree(pool);
return true;
}
static bool
cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name = NULL;
bool build;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = true;
const char *name;
ret = false;
}
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYNAME)))
else
vshError(ctl, "%s", _("failed to get pool UUID"));
- virStoragePoolFree(pool);
return true;
}
cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
- virStoragePoolPtr pool = NULL;
- virStoragePoolPtr pool_edited = NULL;
+ g_autoptr(virshStoragePool) pool = NULL;
+ g_autoptr(virshStoragePool) pool_edited = NULL;
unsigned int flags = VIR_STORAGE_XML_INACTIVE;
g_autofree char *tmp_desc = NULL;
virshControl *priv = ctl->privData;
ret = true;
cleanup:
- if (pool)
- virStoragePoolFree(pool);
- if (pool_edited)
- virStoragePoolFree(pool_edited);
-
return ret;
}
static bool
cmdPoolEvent(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool = NULL;
+ g_autoptr(virshStoragePool) pool = NULL;
bool ret = false;
int eventId = -1;
int timeout = 0;
if (eventId >= 0 &&
virConnectStoragePoolEventDeregisterAny(priv->conn, eventId) < 0)
ret = false;
- if (pool)
- virStoragePoolFree(pool);
return ret;
}
const char **name, unsigned int flags)
{
virStorageVolPtr vol = NULL;
- virStoragePoolPtr pool = NULL;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *n = NULL, *p = NULL;
virshControl *priv = ctl->privData;
if (virStoragePoolIsActive(pool) != 1) {
vshError(ctl, _("pool '%s' is not active"), p);
- virStoragePoolFree(pool);
return NULL;
}
}
/* If the pool was specified, then make sure that the returned
* volume is from the given pool */
if (pool && vol) {
- virStoragePoolPtr volpool = NULL;
+ g_autoptr(virshStoragePool) volpool = NULL;
if ((volpool = virStoragePoolLookupByVolume(vol))) {
if (STRNEQ(virStoragePoolGetName(volpool),
virStorageVolFree(vol);
vol = NULL;
}
- virStoragePoolFree(volpool);
}
}
- if (pool)
- virStoragePoolFree(pool);
-
return vol;
}
static bool
cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
virStorageVolPtr vol = NULL;
g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml");
cleanup:
if (vol)
virStorageVolFree(vol);
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
virStorageVolPtr vol;
const char *from = NULL;
bool ret = false;
}
cleanup:
- virStoragePoolFree(pool);
return ret;
}
static bool
cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool = NULL;
+ g_autoptr(virshStoragePool) pool = NULL;
virStorageVolPtr newvol = NULL, inputvol = NULL;
const char *from = NULL;
bool ret = false;
ret = true;
cleanup:
- if (pool)
- virStoragePoolFree(pool);
if (inputvol)
virStorageVolFree(inputvol);
if (newvol)
static bool
cmdVolClone(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr origpool = NULL;
+ g_autoptr(virshStoragePool) origpool = NULL;
virStorageVolPtr origvol = NULL, newvol = NULL;
const char *name = NULL;
g_autofree char *origxml = NULL;
virStorageVolFree(origvol);
if (newvol)
virStorageVolFree(newvol);
- if (origpool)
- virStoragePoolFree(origpool);
return ret;
}
cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
virStorageVolInfo volumeInfo;
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
const char *unit;
double val;
bool details = vshCommandOptBool(cmd, "details");
/* Cleanup remaining memory */
VIR_FREE(volInfoTexts);
- virStoragePoolFree(pool);
virshStorageVolListFree(list);
/* Return the desired value */
static bool
cmdVolPool(vshControl *ctl, const vshCmd *cmd)
{
- virStoragePoolPtr pool;
+ g_autoptr(virshStoragePool) pool = NULL;
virStorageVolPtr vol;
char uuid[VIR_UUID_STRING_BUFLEN];
/* Cleanup */
virStorageVolFree(vol);
- virStoragePoolFree(pool);
return true;
}