[libvirt PATCH 12/12] tools: virsh: remove redundant labels

Martin Kletzander mkletzan at redhat.com
Thu Aug 12 16:21:43 UTC 2021


On Thu, Aug 12, 2021 at 10:32:50AM +0200, Ján Tomko wrote:
>Signed-off-by: Ján Tomko <jtomko at redhat.com>
>---
> tools/virsh-completer-domain.c |  30 +-
> tools/virsh-domain-monitor.c   | 128 +++----
> tools/virsh-domain.c           | 634 ++++++++++++---------------------
> tools/virsh-host.c             |  87 ++---
> tools/virsh-nodedev.c          |   7 +-
> tools/virsh-volume.c           |   5 +-
> tools/vsh.c                    |  11 +-
> 7 files changed, 317 insertions(+), 585 deletions(-)
>
>diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>index 0b536b75dd..d06c24cc74 100644
>--- a/tools/virsh-domain.c
>+++ b/tools/virsh-domain.c
>@@ -1066,13 +1060,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
>
>     if (ret != 0) {
>         vshError(ctl, "%s", _("Failed to attach interface"));
>-    } else {
>-        vshPrintExtra(ctl, "%s", _("Interface attached successfully\n"));
>-        functionReturn = true;
>+        return false;
>     }
>
>- cleanup:
>-    return functionReturn;
>+    vshPrintExtra(ctl, "%s", _("Interface attached successfully\n"));

It'd be nice if there was an empty line in here (before the return) O:-)

>+    return true;
> }
>
> /*
>@@ -3150,29 +3136,25 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
>                           BAD_CAST "link",
>                           NULL);
>         if (!cur)
>-            goto cleanup;
>+            return false;
>
>         if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) == NULL)
>-            goto cleanup;
>+            return false;
>     }
>
>     if (!(xml_buf = virXMLNodeToString(xml, obj->nodesetval->nodeTab[i]))) {
>         vshSaveLibvirtError();
>         vshError(ctl, _("Failed to create XML"));
>-        goto cleanup;
>+        return false;
>     }
>
>     if (virDomainUpdateDeviceFlags(dom, xml_buf, flags) < 0) {
>         vshError(ctl, _("Failed to update interface link state"));
>-        goto cleanup;
>-    } else {
>-        vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
>-        ret = true;
>+        return false;
>     }
>
>- cleanup:
>-
>-    return ret;
>+    vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));

same here

>+    return true;
> }
>
> /* "domiftune" command
>@@ -5460,18 +5406,18 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
>                         true,
>                         doDump,
>                         &data) < 0)
>-        goto cleanup;
>+        return false;
>
>     virshWatchJob(ctl, dom, verbose, eventLoop,
>                   &data.ret, 0, NULL, NULL, _("Dump"));
>
>     virThreadJoin(&workerThread);
>
>-    if (!data.ret)
>-        vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to);
>+    if (data.ret)
>+        return false;
>
>- cleanup:
>-    return !data.ret;
>+    vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to);

and here

>+    return true;
> }
>
> static const vshCmdInfo info_screenshot[] = {
>@@ -7089,25 +7013,22 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>     /* Query mode: show CPU affinity information then exit.*/
>     if (!cpulist) {
>         ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags);
>-        goto cleanup;
>+        return false;
>     }
>
>     /* Pin mode: pinning specified vcpu to specified physical cpus */
>     if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
>-        goto cleanup;
>+        return false;
>
>     /* use old API without any explicit flags */
>     if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) {
>         if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
>-            goto cleanup;
>+            return false;
>     } else {
>         if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
>-            goto cleanup;
>+            return false;
>     }
>-    ret = true;
>-

also the empty line could have stayed here =(

>- cleanup:
>-    return ret;
>+    return true;
> }
>
> /*
>@@ -10136,7 +10015,6 @@ static const vshCmdOptDef opts_domxmltonative[] = {
> static bool
> cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
> {
>-    bool ret = false;
>     const char *format = NULL;
>     const char *xmlFile = NULL;
>     g_autofree char *configData = NULL;
>@@ -10159,26 +10037,22 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
>         xmlData = virDomainGetXMLDesc(dom, flags);
>     } else if (xmlFile) {
>         if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
>-            goto cleanup;
>+            return false;
>     } else {
>         vshError(ctl, "%s", _("need either domain or domain XML"));
>-        goto cleanup;
>+        return false;
>     }
>
>     if (!xmlData) {
>         vshError(ctl, "%s", _("failed to retrieve XML"));
>-        goto cleanup;
>+        return false;
>     }
>
>-    if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) {
>-        goto cleanup;
>-    } else {
>-        vshPrint(ctl, "%s", configData);
>-        ret = true;
>-    }
>+    if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags)))
>+        return false;
>
>- cleanup:
>-    return ret;
>+    vshPrint(ctl, "%s", configData);

è qui

>+    return true;
> }
>
> /*
>@@ -10246,22 +10120,18 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd)
> {
>     g_autoptr(virshDomain) dom = NULL;
>     const char *new_name = NULL;
>-    bool ret = false;
>
>     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
>-        return ret;
>+        return false;
>
>     if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0)
>-        goto cleanup;
>+        return false;
>
>     if (virDomainRename(dom, new_name, 0) < 0)
>-        goto cleanup;
>+        return false;
>
>     vshPrintExtra(ctl, "Domain successfully renamed\n");
>-    ret = true;
>-

y aquí

>- cleanup:
>-    return ret;
>+    return true;
> }
>
> /*
>@@ -11948,14 +11786,11 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
>
>     if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) {
>         vshError(ctl, _("Failed to update device from %s"), from);
>-        goto cleanup;
>+        return false;
>     }
>
>     vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
>-    ret = true;
>-

e aqui

>- cleanup:
>-    return ret;
>+    return true;
> }
>
> /*
>@@ -12245,9 +12079,7 @@ virshFindDisk(const char *doc,
>     }
>
>     vshError(NULL, _("No disk found whose source path or target is %s"), path);
>-

you know the drill

>- cleanup:
>-    return ret;
>+    return NULL;
> }
>
> typedef enum {
>@@ -14200,23 +14018,19 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd)
> {
>     g_autoptr(virshDomain) dom = NULL;
>     int seconds = 1; /* the default value is 1 */
>-    bool ret = false;
>
>     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
>         return false;
>
>     if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0)
>-        goto cleanup;
>+        return false;
>
>     if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0)
>-        goto cleanup;
>+        return false;
>
>     vshPrintExtra(ctl, _("Start to calculate domain's memory "
>                          "dirty rate successfully.\n"));
>-    ret = true;
>-

conosci il trapano

>- cleanup:
>-    return ret;
>+    return true;
> }
>
>
>diff --git a/tools/virsh-host.c b/tools/virsh-host.c
>index a32af023ae..2b8b953648 100644
>--- a/tools/virsh-host.c
>+++ b/tools/virsh-host.c
>@@ -110,19 +109,17 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
>         vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 ||
>         vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 ||
>         vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0)
>-        return ret;
>+        return false;
>
>     caps = virConnectGetDomainCapabilities(priv->conn, emulatorbin,
>                                            arch, machine, virttype, flags);
>     if (!caps) {
>         vshError(ctl, "%s", _("failed to get emulator capabilities"));
>-        goto cleanup;
>+        return false;
>     }
>
>     vshPrint(ctl, "%s\n", caps);

...

>-    ret = true;
>- cleanup:
>-    return ret;
>+    return true;
> }
>
> /*
>@@ -599,13 +588,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
>     }
>
>     if (vcpus < 0 && (vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0)
>-        goto cleanup;
>+        return false;
>
>     vshPrint(ctl, "%d\n", vcpus);

...

>-    ret = true;
>-
>- cleanup:
>-    return ret;
>+    return true;
> }
>
> /*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210812/b953b65e/attachment-0001.sig>


More information about the libvir-list mailing list