]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: domain: remove 'ret' variable and use 'count' instead
authorKristina Hanicova <khanicov@redhat.com>
Fri, 24 Sep 2021 15:17:49 +0000 (17:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 25 Sep 2021 07:30:43 +0000 (09:30 +0200)
This patch also includes use of an early return in case of an
error. I think the changes make the functions more readable.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-domain.c

index 1102f044de3ce22a46d03413a644bcd4db950566..5e4eebda4e85c82a5353783ccc8dffe4322f1914 100644 (file)
@@ -13602,10 +13602,10 @@ static bool
 cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
 {
     g_autoptr(virshDomain) dom = NULL;
-    int ret = -1;
     const vshCmdOpt *opt = NULL;
     g_autofree const char **mountpoints = NULL;
     size_t nmountpoints = 0;
+    int count = 0;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -13615,16 +13615,13 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
         mountpoints[nmountpoints-1] = opt->data;
     }
 
-    ret = virDomainFSFreeze(dom, mountpoints, nmountpoints, 0);
-    if (ret < 0) {
+    if ((count = virDomainFSFreeze(dom, mountpoints, nmountpoints, 0)) < 0) {
         vshError(ctl, _("Unable to freeze filesystems"));
-        goto cleanup;
+        return false;
     }
 
-    vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), ret);
-
- cleanup:
-    return ret >= 0;
+    vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), count);
+    return true;
 }
 
 static const vshCmdInfo info_domfsthaw[] = {
@@ -13650,10 +13647,10 @@ static bool
 cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
 {
     g_autoptr(virshDomain) dom = NULL;
-    int ret = -1;
     const vshCmdOpt *opt = NULL;
     g_autofree const char **mountpoints = NULL;
     size_t nmountpoints = 0;
+    int count = 0;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -13663,16 +13660,13 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
         mountpoints[nmountpoints-1] = opt->data;
     }
 
-    ret = virDomainFSThaw(dom, mountpoints, nmountpoints, 0);
-    if (ret < 0) {
+    if ((count = virDomainFSThaw(dom, mountpoints, nmountpoints, 0)) < 0) {
         vshError(ctl, _("Unable to thaw filesystems"));
-        goto cleanup;
+        return false;
     }
 
-    vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), ret);
-
- cleanup:
-    return ret >= 0;
+    vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), count);
+    return true;
 }
 
 static const vshCmdInfo info_domfsinfo[] = {