vshError(ctl,
_("Requested volume '%s' is not in pool '%s'"),
n, virStoragePoolGetName(pool));
- virStorageVolFree(vol);
- vol = NULL;
+ g_clear_pointer(&vol, virshStorageVolFree);
}
}
}
cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStoragePool) pool = NULL;
- virStorageVolPtr vol = NULL;
+ g_autoptr(virshStorageVol) vol = NULL;
g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml");
const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL;
/* Convert the snapshot parameters into backingStore XML */
if (snapshotStrVol) {
- virStorageVolPtr snapVol;
+ g_autoptr(virshStorageVol) snapVol = NULL;
g_autofree char *snapshotStrVolPath = NULL;
/* Lookup snapshot backing volume. Try the backing-vol
* parameter as a name */
}
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
- virStorageVolFree(snapVol);
goto cleanup;
}
snapshotStrFormat);
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</backingStore>\n");
-
- /* Cleanup snapshot allocations */
- virStorageVolFree(snapVol);
}
virBufferAdjustIndent(&buf, -2);
ret = true;
cleanup:
- if (vol)
- virStorageVolFree(vol);
return ret;
}
cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStoragePool) pool = NULL;
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
const char *from = NULL;
bool ret = false;
unsigned int flags = 0;
if ((vol = virStorageVolCreateXML(pool, buffer, flags))) {
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
virStorageVolGetName(vol), from);
- virStorageVolFree(vol);
ret = true;
} else {
vshError(ctl, _("Failed to create vol from %s"), from);
cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStoragePool) pool = NULL;
- virStorageVolPtr newvol = NULL, inputvol = NULL;
+ g_autoptr(virshStorageVol) newvol = NULL;
+ g_autoptr(virshStorageVol) inputvol = NULL;
const char *from = NULL;
bool ret = false;
g_autofree char *buffer = NULL;
ret = true;
cleanup:
- if (inputvol)
- virStorageVolFree(inputvol);
- if (newvol)
- virStorageVolFree(newvol);
return ret;
}
cmdVolClone(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStoragePool) origpool = NULL;
- virStorageVolPtr origvol = NULL, newvol = NULL;
+ g_autoptr(virshStorageVol) origvol = NULL;
+ g_autoptr(virshStorageVol) newvol = NULL;
const char *name = NULL;
g_autofree char *origxml = NULL;
xmlChar *newxml = NULL;
cleanup:
xmlFree(newxml);
- if (origvol)
- virStorageVolFree(origvol);
- if (newvol)
- virStorageVolFree(newvol);
return ret;
}
cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
- virStorageVolPtr vol = NULL;
+ g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
int fd = -1;
virStreamPtr st = NULL;
ret = true;
cleanup:
- if (vol)
- virStorageVolFree(vol);
if (st)
virStreamFree(st);
VIR_FORCE_CLOSE(fd);
cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
{
const char *file = NULL;
- virStorageVolPtr vol = NULL;
+ g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
int fd = -1;
virStreamPtr st = NULL;
VIR_FORCE_CLOSE(fd);
if (!ret && created)
unlink(file);
- if (vol)
- virStorageVolFree(vol);
if (st)
virStreamFree(st);
return ret;
static bool
cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
bool ret = true;
const char *name;
bool delete_snapshots = vshCommandOptBool(cmd, "delete-snapshots");
ret = false;
}
- virStorageVolFree(vol);
return ret;
}
static bool
cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
const char *name;
const char *algorithm_str = NULL;
vshPrintExtra(ctl, _("Vol %s wiped\n"), name);
ret = true;
out:
- virStorageVolFree(vol);
return ret;
}
cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolInfo info;
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
bool bytes = vshCommandOptBool(cmd, "bytes");
bool physical = vshCommandOptBool(cmd, "physical");
int rc;
rc = virStorageVolGetInfo(vol, &info);
if (rc < 0) {
- virStorageVolFree(vol);
return false;
}
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
}
- virStorageVolFree(vol);
return true;
}
static bool
cmdVolResize(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
const char *capacityStr = NULL;
unsigned long long capacity = 0;
unsigned int flags = 0;
}
cleanup:
- virStorageVolFree(vol);
return ret;
}
static bool
cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
bool ret = true;
char *dump;
ret = false;
}
- virStorageVolFree(vol);
return ret;
}
if (list && list->vols) {
for (i = 0; i < list->nvols; i++) {
- if (list->vols[i])
- virStorageVolFree(list->vols[i]);
+ virshStorageVolFree(list->vols[i]);
}
g_free(list->vols);
}
static bool
cmdVolName(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
if (!(vol = virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virStorageVolGetName(vol));
- virStorageVolFree(vol);
return true;
}
cmdVolPool(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStoragePool) pool = NULL;
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
char uuid[VIR_UUID_STRING_BUFLEN];
/* Use the supplied string to locate the volume */
pool = virStoragePoolLookupByVolume(vol);
if (pool == NULL) {
vshError(ctl, "%s", _("failed to get parent pool"));
- virStorageVolFree(vol);
return false;
}
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
}
- /* Cleanup */
- virStorageVolFree(vol);
return true;
}
static bool
cmdVolKey(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
vshPrint(ctl, "%s\n", virStorageVolGetKey(vol));
- virStorageVolFree(vol);
return true;
}
static bool
cmdVolPath(vshControl *ctl, const vshCmd *cmd)
{
- virStorageVolPtr vol;
+ g_autoptr(virshStorageVol) vol = NULL;
g_autofree char *StorageVolPath = NULL;
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) {
- virStorageVolFree(vol);
return false;
}
vshPrint(ctl, "%s\n", StorageVolPath);
- virStorageVolFree(vol);
return true;
}