]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Refactor cleanup in 'cmdVolClone'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 30 Nov 2022 15:40:14 +0000 (16:40 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:49:25 +0000 (16:49 +0100)
Automatically free 'newxml' and remove the 'cleanup' label and 'ret'
variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-volume.c

index 2df23c9b6f5dc1dfcb4295918ab569eec6d1bc80..508c620cd3a655816a8b1df4f85dbfc8ea1388d9 100644 (file)
@@ -570,12 +570,11 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
     g_autoptr(virshStorageVol) newvol = NULL;
     const char *name = NULL;
     g_autofree char *origxml = NULL;
-    xmlChar *newxml = NULL;
-    bool ret = false;
+    g_autofree xmlChar *newxml = NULL;
     unsigned int flags = 0;
 
     if (!(origvol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
-        goto cleanup;
+        return false;
 
     if (vshCommandOptBool(cmd, "prealloc-metadata"))
         flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@@ -586,38 +585,30 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
     origpool = virStoragePoolLookupByVolume(origvol);
     if (!origpool) {
         vshError(ctl, "%s", _("failed to get parent pool"));
-        goto cleanup;
+        return false;
     }
 
     if (vshCommandOptStringReq(ctl, cmd, "newname", &name) < 0)
-        goto cleanup;
+        return false;
 
-    origxml = virStorageVolGetXMLDesc(origvol, 0);
-    if (!origxml)
-        goto cleanup;
+    if (!(origxml = virStorageVolGetXMLDesc(origvol, 0)))
+        return false;
 
-    newxml = virshMakeCloneXML(origxml, name);
-    if (!newxml) {
+    if (!(newxml = virshMakeCloneXML(origxml, name))) {
         vshError(ctl, "%s", _("Failed to allocate XML buffer"));
-        goto cleanup;
+        return false;
     }
 
-    newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, flags);
-
-    if (newvol != NULL) {
-        vshPrintExtra(ctl, _("Vol %s cloned from %s\n"),
-                      virStorageVolGetName(newvol), virStorageVolGetName(origvol));
-    } else {
+    if (!(newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml,
+                                              origvol, flags))) {
         vshError(ctl, _("Failed to clone vol from %s"),
                  virStorageVolGetName(origvol));
-        goto cleanup;
+        return false;
     }
 
-    ret = true;
-
- cleanup:
-    xmlFree(newxml);
-    return ret;
+    vshPrintExtra(ctl, _("Vol %s cloned from %s\n"),
+                  virStorageVolGetName(newvol), virStorageVolGetName(origvol));
+    return true;
 }
 
 /*