Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- 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-completer-domain.c b/tools/virsh-completer-domain.c index 471f9974a1..c86d8e8156 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -447,7 +447,6 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, g_autofree virDomainIOThreadInfoPtr *info = NULL; size_t i; int rc; - char **ret = NULL; g_auto(GStrv) tmp = NULL; virCheckFlags(0, NULL); @@ -456,7 +455,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, return NULL; if ((rc = virDomainGetIOThreadInfo(dom, &info, flags)) < 0) - goto cleanup; + return NULL; niothreads = rc; @@ -465,10 +464,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, for (i = 0; i < niothreads; i++) tmp[i] = g_strdup_printf("%u", info[i]->iothread_id); - ret = g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } @@ -482,7 +478,6 @@ virshDomainVcpuCompleter(vshControl *ctl, g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; - char **ret = NULL; g_auto(GStrv) tmp = NULL; virCheckFlags(0, NULL); @@ -492,21 +487,18 @@ virshDomainVcpuCompleter(vshControl *ctl, if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; tmp = g_new0(char *, nvcpus + 1); for (id = 0; id < nvcpus; id++) tmp[id] = g_strdup_printf("%u", id); - ret = g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } @@ -522,7 +514,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, unsigned int id; g_auto(GStrv) vcpulist = NULL; const char *vcpuid = NULL; - char **ret = NULL; virCheckFlags(0, NULL); @@ -530,25 +521,22 @@ virshDomainVcpulistCompleter(vshControl *ctl, return NULL; if (vshCommandOptStringQuiet(ctl, cmd, "vcpulist", &vcpuid) < 0) - goto cleanup; + return NULL; if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; vcpulist = g_new0(char *, nvcpus + 1); for (id = 0; id < nvcpus; id++) vcpulist[id] = g_strdup_printf("%u", id); - ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist); - - cleanup: - return ret; + return virshCommaStringListComplete(vcpuid, (const char **)vcpulist); } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 49f632f11b..d5e9ad3bce 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -81,7 +81,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, /* fall back to xml */ if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0) - goto cleanup; + return NULL; if (title) desc = virXPathString("string(./title[1])", ctxt); @@ -91,8 +91,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, if (!desc) desc = g_strdup(""); - cleanup: - return desc; } @@ -299,7 +297,6 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; unsigned int nr_stats; size_t i; - bool ret = false; int rv = 0; int period = -1; bool config = vshCommandOptBool(cmd, "config"); @@ -326,26 +323,25 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) * This is not really an unsigned long, but it */ if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) - goto cleanup; + return false; if (rv > 0) { if (period < 0) { vshError(ctl, _("Invalid collection period value '%d'"), period); - goto cleanup; + return false; } if (virDomainSetMemoryStatsPeriod(dom, period, flags) < 0) { vshError(ctl, "%s", _("Unable to change balloon collection period.")); - } else { - ret = true; + return false; } - goto cleanup; + return true; } nr_stats = virDomainMemoryStats(dom, stats, VIR_DOMAIN_MEMORY_STAT_NR, 0); if (nr_stats == -1) { vshError(ctl, _("Failed to get memory statistics for domain %s"), name); - goto cleanup; + return false; } for (i = 0; i < nr_stats; i++) { @@ -377,9 +373,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "hugetlb_pgfail %llu\n", stats[i].val); } - ret = true; - cleanup: - return ret; + return true; } /* @@ -590,7 +584,6 @@ static const vshCmdOptDef opts_domblklist[] = { static bool cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; unsigned int flags = 0; g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; @@ -606,11 +599,11 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) details = vshCommandOptBool(cmd, "details"); if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto cleanup; + return false; if (details) table = vshTableNew(_("Type"), _("Device"), _("Target"), _("Source"), NULL); @@ -618,7 +611,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) table = vshTableNew(_("Target"), _("Source"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ndisks; i++) { g_autofree char *type = NULL; @@ -633,14 +626,14 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) device = virXPathString("string(./@device)", ctxt); if (!type || !device) { vshPrint(ctl, "unable to query block list details"); - goto cleanup; + return false; } } target = virXPathString("string(./target/@dev)", ctxt); if (!target) { vshError(ctl, "unable to query block list"); - goto cleanup; + return false; } if (STREQ_NULLABLE(type, "nvme")) { @@ -652,7 +645,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) !(addrNode = virXPathNode("./source/address", ctxt)) || virPCIDeviceAddressParseXML(addrNode, &addr) < 0) { vshError(ctl, "Unable to query NVMe disk address"); - goto cleanup; + return false; } source = g_strdup_printf("nvme://%04x:%02x:%02x.%d/%s", @@ -669,20 +662,17 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) if (details) { if (vshTableRowAppend(table, type, device, target, NULLSTR_MINUS(source), NULL) < 0) - goto cleanup; + return false; } else { if (vshTableRowAppend(table, target, NULLSTR_MINUS(source), NULL) < 0) - goto cleanup; + return false; } } vshTablePrintToStdout(table, ctl); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -706,7 +696,6 @@ static const vshCmdOptDef opts_domiflist[] = { static bool cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; unsigned int flags = 0; g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; @@ -719,16 +708,16 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; ninterfaces = virXPathNodeSet("./devices/interface", ctxt, &interfaces); if (ninterfaces < 0) - goto cleanup; + return false; table = vshTableNew(_("Interface"), _("Type"), _("Source"), _("Model"), _("MAC"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ninterfaces; i++) { g_autofree char *type = NULL; @@ -757,15 +746,12 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) model ? model : "-", mac ? mac : "-", NULL) < 0) - goto cleanup; + return false; } vshTablePrintToStdout(table, ctl); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -810,7 +796,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) g_autofree xmlNodePtr *interfaces = NULL; int ninterfaces; unsigned int flags = 0; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) return false; @@ -819,7 +804,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) flags = VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - goto cleanup; + return false; /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) == 0) @@ -831,7 +816,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) { vshError(ctl, _("Failed to extract interface information")); - goto cleanup; + return false; } if (ninterfaces < 1) { @@ -840,10 +825,10 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, _("Interface (dev: %s) not found."), iface); - goto cleanup; + return false; } else if (ninterfaces > 1) { vshError(ctl, _("multiple matching interfaces found")); - goto cleanup; + return false; } ctxt->node = interfaces[0]; @@ -853,11 +838,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s up", iface); - ret = true; - - cleanup: - - return ret; + return true; } /* @@ -882,16 +863,13 @@ static bool cmdDomControl(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = true; virDomainControlInfo info; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if (virDomainGetControlInfo(dom, &info, 0) < 0) { - ret = false; - goto cleanup; - } + if (virDomainGetControlInfo(dom, &info, 0) < 0) + return false; if (info.state != VIR_DOMAIN_CONTROL_OK && info.state != VIR_DOMAIN_CONTROL_ERROR) { @@ -907,8 +885,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) virshDomainControlStateToString(info.state)); } - cleanup: - return ret; + return true; } /* @@ -989,7 +966,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) const char *field = NULL; int rc, nparams = 0; size_t i; - bool ret = false; bool human = vshCommandOptBool(cmd, "human"); /* human readable output */ if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -1000,7 +976,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) API contract. */ if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0) - goto cleanup; + return false; if (!device) device = ""; @@ -1014,7 +990,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) if (rc < 0) { /* try older API if newer is not supported */ if (last_error->code != VIR_ERR_NO_SUPPORT) - goto cleanup; + return false; vshResetLibvirtError(); @@ -1022,7 +998,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) sizeof(stats)) == -1) { vshError(ctl, _("Failed to get block stats %s %s"), name, device); - goto cleanup; + return false; } /* human friendly output */ @@ -1040,7 +1016,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) params = g_new0(virTypedParameter, nparams); if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) { vshError(ctl, _("Failed to get block stats for domain '%s' device '%s'"), name, device); - goto cleanup; + return false; } /* set for prettier output */ @@ -1089,10 +1065,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - - cleanup: - return ret; + return true; } #undef DOMBLKSTAT_LEGACY_PRINT @@ -1126,17 +1099,16 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *name = NULL, *device = NULL; virDomainInterfaceStatsStruct stats; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) return false; if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0) - goto cleanup; + return false; if (virDomainInterfaceStats(dom, device, &stats, sizeof(stats)) == -1) { vshError(ctl, _("Failed to get interface stats %s %s"), name, device); - goto cleanup; + return false; } if (stats.rx_bytes >= 0) @@ -1163,10 +1135,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) if (stats.tx_drop >= 0) vshPrint(ctl, "%s tx_drop %lld\n", device, stats.tx_drop); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -1398,17 +1367,14 @@ static bool cmdDomstate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = true; bool showReason = vshCommandOptBool(cmd, "reason"); int state, reason; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if ((state = virshDomainState(ctl, dom, &reason)) < 0) { - ret = false; - goto cleanup; - } + if ((state = virshDomainState(ctl, dom, &reason)) < 0) + return false; if (showReason) { vshPrint(ctl, "%s (%s)\n", @@ -1419,8 +1385,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) virshDomainStateToString(state)); } - cleanup: - return ret; + return true; } /* @@ -1461,7 +1426,6 @@ static bool cmdDomTime(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool now = vshCommandOptBool(cmd, "now"); bool pretty = vshCommandOptBool(cmd, "pretty"); bool rtcSync = vshCommandOptBool(cmd, "sync"); @@ -1482,7 +1446,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { /* invalid integer format */ - goto cleanup; + return false; } else if (rv > 0) { /* valid integer to set */ doSet = true; @@ -1491,18 +1455,18 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (doSet || now || rtcSync) { if (now && ((seconds = time(NULL)) == (time_t) -1)) { vshError(ctl, _("Unable to get current time")); - goto cleanup; + return false; } if (rtcSync) flags |= VIR_DOMAIN_TIME_SYNC; if (virDomainSetTime(dom, seconds, nseconds, flags) < 0) - goto cleanup; + return false; } else { if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0) - goto cleanup; + return false; if (pretty) { g_autoptr(GDateTime) then = NULL; @@ -1517,9 +1481,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - cleanup: - return ret; + return true; } /* 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 @@ -325,7 +325,6 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; char *buffer; int rv; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -346,7 +345,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -354,7 +353,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } if (flags || current) @@ -366,14 +365,11 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { vshError(ctl, _("Failed to attach device from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", _("Device attached successfully\n")); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -888,7 +884,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virNetDevBandwidthRate inbound, outbound; virDomainNetType typ; int ret; - bool functionReturn = false; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autofree char *xml = NULL; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -917,35 +912,35 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 || vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0) - goto cleanup; + return false; /* check interface type */ if ((int)(typ = virDomainNetTypeFromString(type)) < 0) { vshError(ctl, _("No support for %s in command 'attach-interface'"), type); - goto cleanup; + return false; } if (inboundStr) { memset(&inbound, 0, sizeof(inbound)); if (virshParseRateStr(ctl, inboundStr, &inbound) < 0) - goto cleanup; + return false; if (!inbound.average && !inbound.floor) { vshError(ctl, _("either inbound average or floor is mandatory")); - goto cleanup; + return false; } } if (outboundStr) { memset(&outbound, 0, sizeof(outbound)); if (virshParseRateStr(ctl, outboundStr, &outbound) < 0) - goto cleanup; + return false; if (outbound.average == 0) { vshError(ctl, _("outbound average is mandatory")); - goto cleanup; + return false; } if (outbound.floor) { vshError(ctl, _("outbound floor is unsupported yet")); - goto cleanup; + return false; } } @@ -975,7 +970,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (virshAddressParse(pciaddrstr, false, &addr) < 0) { vshError(ctl, _("cannot parse pci address '%s' for network interface"), source); - goto cleanup; + return false; } virBufferAddLit(&buf, "<source>\n"); @@ -998,7 +993,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) case VIR_DOMAIN_NET_TYPE_LAST: vshError(ctl, _("No support for %s in command 'attach-interface'"), type); - goto cleanup; + return false; break; } @@ -1048,12 +1043,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "print-xml")) { vshPrint(ctl, "%s", xml); - functionReturn = true; - goto cleanup; + return true; } if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -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")); + return true; } /* @@ -2690,11 +2682,11 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async); if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; /* XXX Allow path to be optional to list info on all devices at once */ if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) - goto cleanup; + return false; if (bandwidth) ret = virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); @@ -2703,7 +2695,6 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) else ret = virshBlockJobInfo(ctl, dom, path, raw, bytes); - cleanup: return ret; } @@ -2987,7 +2978,6 @@ static bool cmdConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool force = vshCommandOptBool(cmd, "force"); bool safe = vshCommandOptBool(cmd, "safe"); unsigned int flags = 0; @@ -2997,17 +2987,14 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "devname", &name) < 0) /* sc_prohibit_devname */ - goto cleanup; + return false; if (force) flags |= VIR_DOMAIN_CONSOLE_FORCE; if (safe) flags |= VIR_DOMAIN_CONSOLE_SAFE; - ret = cmdRunConsole(ctl, dom, name, flags); - - cleanup: - return ret; + return cmdRunConsole(ctl, dom, name, flags); } #endif /* WIN32 */ @@ -3056,7 +3043,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) const char *element; const char *attr; bool config; - bool ret = false; unsigned int flags = 0; unsigned int xmlflags = 0; size_t i; @@ -3071,13 +3057,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0 || vshCommandOptStringReq(ctl, cmd, "state", &state) < 0) - goto cleanup; + return false; config = vshCommandOptBool(cmd, "config"); if (STRNEQ(state, "up") && STRNEQ(state, "down")) { vshError(ctl, _("invalid link state '%s'"), state); - goto cleanup; + return false; } if (config) { @@ -3091,13 +3077,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) flags = VIR_DOMAIN_AFFECT_CONFIG; if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0) - goto cleanup; + return false; obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt); if (obj == NULL || obj->type != XPATH_NODESET || obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) { vshError(ctl, _("Failed to extract interface information or no interfaces found")); - goto cleanup; + return false; } if (virMacAddrParse(iface, &macaddr) == 0) { @@ -3125,7 +3111,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } vshError(ctl, _("interface (%s: %s) not found"), element, iface); - goto cleanup; + return false; hit: /* find and modify/add link state node */ @@ -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")); + return true; } /* "domiftune" command @@ -3447,7 +3429,6 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; const char *target = NULL; int suspendTarget; unsigned long long duration = 0; @@ -3456,29 +3437,26 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) - goto cleanup; + return false; if ((suspendTarget = virshNodeSuspendTargetTypeFromString(target)) < 0) { vshError(ctl, "%s", _("Invalid target")); - goto cleanup; + return false; } if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0) { vshError(ctl, _("Domain '%s' could not be suspended"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' successfully suspended"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -3506,7 +3484,6 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; unsigned int flags = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -3515,16 +3492,13 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) if (virDomainPMWakeup(dom, flags) < 0) { vshError(ctl, _("Domain '%s' could not be woken up"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' successfully woken up"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4036,7 +4010,6 @@ static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); #endif @@ -4051,11 +4024,11 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (virDomainGetID(dom) != (unsigned int)-1) { vshError(ctl, "%s", _("Domain is already active")); - goto cleanup; + return false; } if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; @@ -4075,7 +4048,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (last_error->code != VIR_ERR_NO_SUPPORT && last_error->code != VIR_ERR_INVALID_ARG) { vshReportError(ctl); - goto cleanup; + return false; } vshResetLibvirtError(); rc = virDomainHasManagedSaveImage(dom, 0); @@ -4085,7 +4058,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) } else if (rc > 0) { if (virDomainManagedSaveRemove(dom, 0) < 0) { vshReportError(ctl); - goto cleanup; + return false; } } flags &= ~VIR_DOMAIN_START_FORCE_BOOT; @@ -4096,7 +4069,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) (flags ? virDomainCreateWithFlags(dom, flags) : virDomainCreate(dom))) < 0) { vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(dom)); - goto cleanup; + return false; } started: @@ -4104,13 +4077,10 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) virDomainGetName(dom)); #ifndef WIN32 if (console && !cmdRunConsole(ctl, dom, NULL, 0)) - goto cleanup; + return false; #endif - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4485,7 +4455,6 @@ static bool cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) { const char *file = NULL; - bool ret = false; unsigned int flags = 0; g_autofree char *xml = NULL; virshControl *priv = ctl->privData; @@ -4498,13 +4467,10 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) xml = virDomainSaveImageGetXMLDesc(priv->conn, file, flags); if (!xml) - goto cleanup; + return false; vshPrint(ctl, "%s", xml); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4542,7 +4508,6 @@ static bool cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) { const char *file = NULL; - bool ret = false; const char *xmlfile = NULL; g_autofree char *xml = NULL; unsigned int flags = 0; @@ -4560,18 +4525,15 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) return false; if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; if (virDomainSaveImageDefineXML(priv->conn, file, xml, flags) < 0) { vshError(ctl, _("Failed to update %s"), file); - goto cleanup; + return false; } vshPrintExtra(ctl, _("State file %s updated.\n"), file); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4785,7 +4747,6 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; int hassave; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -4794,14 +4755,14 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) hassave = virDomainHasManagedSaveImage(dom, 0); if (hassave < 0) { vshError(ctl, "%s", _("Failed to check for domain managed save image")); - goto cleanup; + return false; } if (hassave) { if (virDomainManagedSaveRemove(dom, 0) < 0) { vshError(ctl, _("Failed to remove managed save image for domain '%s'"), name); - goto cleanup; + return false; } else vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name); @@ -4810,10 +4771,7 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%s' has no manage save image; removal skipped"), name); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4859,7 +4817,7 @@ cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd) dom = virshCommandOptDomain(ctl, cmd, NULL); if (dom == NULL) - goto cleanup; + return false; #define EDIT_GET_XML virDomainManagedSaveGetXMLDesc(dom, getxml_flags) #define EDIT_NOT_CHANGED \ @@ -4906,7 +4864,6 @@ static const vshCmdOptDef opts_managed_save_dumpxml[] = { static bool cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autoptr(virshDomain) dom = NULL; unsigned int flags = 0; g_autofree char *xml = NULL; @@ -4915,16 +4872,13 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_XML_SECURE; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (!(xml = virDomainManagedSaveGetXMLDesc(dom, flags))) - goto cleanup; + return false; vshPrint(ctl, "%s", xml); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4961,7 +4915,6 @@ static const vshCmdOptDef opts_managed_save_define[] = { static bool cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autoptr(virshDomain) dom = NULL; const char *xmlfile = NULL; g_autofree char *xml = NULL; @@ -4981,20 +4934,17 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) return false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) { vshError(ctl, _("Failed to update %s XML configuration"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Managed save state file of domain '%s' updated.\n"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -5264,7 +5214,6 @@ static bool cmdRestore(vshControl *ctl, const vshCmd *cmd) { const char *from = NULL; - bool ret = false; unsigned int flags = 0; const char *xmlfile = NULL; g_autofree char *xml = NULL; @@ -5285,20 +5234,17 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) if (xmlfile && virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; if (((flags || xml) ? virDomainRestoreFlags(priv->conn, from, xml, flags) : virDomainRestore(priv->conn, from)) < 0) { vshError(ctl, _("Failed to restore domain from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain restored from %s\n"), from); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -5451,7 +5397,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "verbose")) verbose = true; @@ -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); + return true; } static const vshCmdInfo info_screenshot[] = { @@ -5751,7 +5697,6 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) const char *password = NULL; const char *user = NULL; unsigned int flags = 0; - bool ret = false; if (vshCommandOptBool(cmd, "encrypted")) flags = VIR_DOMAIN_PASSWORD_ENCRYPTED; @@ -5766,13 +5711,10 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) return false; if (virDomainSetUserPassword(dom, user, password, flags) < 0) - goto cleanup; + return false; vshPrintExtra(ctl, _("Password set successfully for %s in %s"), user, name); - ret = true; - - cleanup: - return ret; + return true; } /* * "resume" command @@ -5839,7 +5781,6 @@ static bool cmdShutdown(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *name; const char *mode = NULL; int flags = 0; @@ -5872,13 +5813,13 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Unknown mode %s value, expecting " "'acpi', 'agent', 'initctl', 'signal', " "or 'paravirt'"), mode); - goto cleanup; + return false; } tmp++; } if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; if (flags) rv = virDomainShutdownFlags(dom, flags); @@ -5888,12 +5829,10 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%s' is being shutdown\n"), name); } else { vshError(ctl, _("Failed to shutdown domain '%s'"), name); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -5923,7 +5862,6 @@ static bool cmdReboot(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *name; const char *mode = NULL; int flags = 0; @@ -5955,24 +5893,22 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Unknown mode %s value, expecting " "'acpi', 'agent', 'initctl', 'signal' " "or 'paravirt'"), mode); - goto cleanup; + return false; } tmp++; } if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; if (virDomainReboot(dom, flags) == 0) { vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name); } else { vshError(ctl, _("Failed to reboot domain '%s'"), name); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -6586,7 +6522,6 @@ static bool cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); bool active = vshCommandOptBool(cmd, "active"); bool config = vshCommandOptBool(cmd, "config"); @@ -6636,7 +6571,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) VIR_DOMAIN_AFFECT_LIVE, true); if (conf_max == -2 || conf_cur == -2 || live_max == -2 || live_cur == -2) - goto cleanup; + return false; #define PRINT_COUNT(VAR, WHICH, STATE) if (VAR > 0) \ vshPrint(ctl, "%-12s %-12s %3d\n", WHICH, STATE, VAR) @@ -6650,15 +6585,12 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) int count = virshCPUCountCollect(ctl, dom, flags, false); if (count < 0) - goto cleanup; + return false; vshPrint(ctl, "%d\n", count); } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -6692,12 +6624,11 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, { g_autofree char *str = NULL; size_t i; - int ret = -1; vshPrint(ctl, "%-15s ", _("CPU Affinity:")); if (pretty) { if (!(str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(maxcpu)))) - goto cleanup; + return -1; vshPrint(ctl, _("%s (out of %d)"), str, maxcpu); } else { for (i = 0; i < maxcpu; i++) @@ -6705,10 +6636,7 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, } vshPrint(ctl, "\n"); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -6732,11 +6660,11 @@ virshDomainGetVcpuBitmap(vshControl *ctl, flags |= VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) - goto cleanup; + return NULL; if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) { vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count")); - goto cleanup; + return NULL; } ignore_value(virXPathUInt("string(/domain/vcpu/@current)", ctxt, &curvcpus)); @@ -6751,7 +6679,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, for (i = 0; i < curvcpus; i++) ignore_value(virBitmapSetBit(ret, i)); - goto cleanup; + return NULL; } for (i = 0; i < nnodes; i++) { @@ -6770,10 +6698,9 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (virBitmapCountBits(ret) != curvcpus) { vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap")); virBitmapFree(ret); - ret = NULL; + return NULL; } - cleanup: return ret; } @@ -6946,7 +6873,6 @@ virshVcpuPinQuery(vshControl *ctl, int cpumaplen; size_t i; int ncpus; - bool ret = false; g_autoptr(vshTable) table = NULL; if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) { @@ -6956,7 +6882,7 @@ virshVcpuPinQuery(vshControl *ctl, else vshError(ctl, "%s", _("cannot get vcpupin for transient domain")); } - goto cleanup; + return false; } if (got_vcpu && vcpu >= ncpus) { @@ -6970,7 +6896,7 @@ virshVcpuPinQuery(vshControl *ctl, vshError(ctl, _("vcpu %d is out of range of persistent cpu count %d"), vcpu, ncpus); - goto cleanup; + return false; } cpumaplen = VIR_CPU_MAPLEN(maxcpu); @@ -6979,7 +6905,7 @@ virshVcpuPinQuery(vshControl *ctl, cpumaplen, flags)) >= 0) { table = vshTableNew(_("VCPU"), _("CPU Affinity"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ncpus; i++) { g_autofree char *pinInfo = NULL; @@ -6989,20 +6915,18 @@ virshVcpuPinQuery(vshControl *ctl, if (!(pinInfo = virBitmapDataFormat(VIR_GET_CPUMAP(cpumap, cpumaplen, i), cpumaplen))) - goto cleanup; + return false; vcpuStr = g_strdup_printf("%zu", i); if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0) - goto cleanup; + return false; } vshTablePrintToStdout(table, ctl); } - ret = true; - cleanup: - return ret; + return true; } @@ -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; - - cleanup: - return ret; + return true; } /* @@ -7193,22 +7114,20 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = virshPrintPinInfo(ctl, cpumap, cpumaplen); vshPrint(ctl, "\n"); } - goto cleanup; + return false; } /* Pin mode: pinning emulator threads to specified physical cpus */ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; if (flags == -1) flags = VIR_DOMAIN_AFFECT_LIVE; if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -7254,7 +7173,6 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned int count = 0; - bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); @@ -7284,26 +7202,23 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0) - goto cleanup; + return false; if (count == 0) { vshError(ctl, _("Can't set 0 processors for a VM")); - goto cleanup; + return false; } /* none of the options were specified */ if (!current && flags == 0) { if (virDomainSetVcpus(dom, count) != 0) - goto cleanup; + return false; } else { if (virDomainSetVcpusFlags(dom, count, flags) < 0) - goto cleanup; + return false; } - ret = true; - - cleanup: - return ret; + return true; } @@ -7438,7 +7353,6 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) bool live = vshCommandOptBool(cmd, "live"); const char *vcpulist = NULL; int state = 0; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable); @@ -7466,12 +7380,9 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) state = 1; if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7511,7 +7422,6 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) unsigned long long threshold; const char *dev = NULL; g_autoptr(virshDomain) dom = NULL; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "dev", &dev)) return false; @@ -7524,12 +7434,9 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) return false; if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7661,7 +7568,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) bool current = vshCommandOptBool(cmd, "current"); unsigned int iothread_id = 0; int maxcpu; - bool ret = false; g_autofree unsigned char *cpumap = NULL; int cpumaplen; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -7679,25 +7585,22 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) - goto cleanup; + return false; if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0) - goto cleanup; + return false; if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; if (virDomainPinIOThread(dom, iothread_id, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -7731,7 +7634,6 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -7749,19 +7651,16 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } if (virDomainAddIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7900,7 +7799,6 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -7918,19 +7816,16 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } if (virDomainDelIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -8159,7 +8054,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *from = NULL; - bool ret = false; g_autofree char *buffer = NULL; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); @@ -8176,7 +8070,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) return false; if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; @@ -8192,7 +8086,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (!dom) { vshError(ctl, _("Failed to create domain from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' created from %s\n"), @@ -8201,10 +8095,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (console) cmdRunConsole(ctl, dom, NULL, 0); #endif - ret = true; - - cleanup: - return ret; + return true; } /* @@ -8567,18 +8458,18 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "uri", &uri) < 0 || vshCommandOptStringReq(ctl, cmd, "key", &key) < 0 || vshCommandOptStringReq(ctl, cmd, "set", &set) < 0) - goto cleanup; + return false; if ((set || edit) && !key) { vshError(ctl, "%s", _("namespace key is required when modifying metadata")); - goto cleanup; + return false; } if (set || rem) { if (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, set, key, uri, flags)) - goto cleanup; + return false; if (rem) vshPrintExtra(ctl, "%s\n", _("Metadata removed")); @@ -8605,7 +8496,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) /* get */ if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, flags))) - goto cleanup; + return false; vshPrint(ctl, "%s\n", data); } @@ -8698,7 +8589,6 @@ static bool cmdSendKey(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *codeset_option; int codeset; unsigned int holdtime = 0; @@ -8714,7 +8604,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) codeset_option = "linux"; if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) - goto cleanup; + return false; /* The qnum codeset was originally called rfb, so we need to keep * accepting the old name for backwards compatibility reasons */ @@ -8724,19 +8614,19 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) codeset = virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { vshError(ctl, _("unknown codeset: '%s'"), codeset_option); - goto cleanup; + return false; } while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) { vshError(ctl, _("too many keycodes")); - goto cleanup; + return false; } if ((keycode = virshKeyCodeGetInt(opt->data)) < 0) { if ((keycode = virKeycodeValueFromString(codeset, opt->data)) < 0) { vshError(ctl, _("invalid keycode: '%s'"), opt->data); - goto cleanup; + return false; } } @@ -8744,11 +8634,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) count++; } - if (!(virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0)) - ret = true; + if (virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0) + return false; - cleanup: - return ret; + return true; } /* @@ -8882,7 +8771,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8911,15 +8799,13 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes = VIR_DIV_UP(bytes, 1024); if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -8959,7 +8845,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8983,17 +8868,15 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes = VIR_DIV_UP(bytes, 1024); if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -9888,7 +9771,6 @@ static bool cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const vshCmdOpt *opt = NULL; g_autofree char **cmdargv = NULL; size_t ncmdargv = 0; @@ -9903,7 +9785,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) dom = virshCommandOptDomain(ctl, cmd, NULL); if (dom == NULL) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "noseclabel")) setlabel = false; @@ -9916,16 +9798,16 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) cmdargv[ncmdargv - 1] = NULL; if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0) - goto cleanup; + return false; if (setlabel) { secmodel = g_new0(virSecurityModel, 1); seclabel = g_new0(virSecurityLabel, 1); if (virNodeGetSecurityModel(priv->conn, secmodel) < 0) - goto cleanup; + return false; if (virDomainGetSecurityLabel(dom, seclabel) < 0) - goto cleanup; + return false; } /* Fork once because we don't want to affect @@ -9933,7 +9815,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) * can only be changed in single-threaded process */ if ((pid = virFork()) < 0) - goto cleanup; + return false; if (pid == 0) { int status; @@ -9973,14 +9855,11 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) VIR_FREE(fdlist); if (virProcessWait(pid, NULL, false) < 0) { vshReportError(ctl); - goto cleanup; + return false; } } - ret = true; - - 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); + 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; - - cleanup: - return ret; + return true; } /* @@ -11076,19 +10946,15 @@ cmdMigrateGetMaxDowntime(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned long long downtime; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (virDomainMigrateGetMaxDowntime(dom, &downtime, 0) < 0) - goto done; + return false; vshPrint(ctl, "%llu\n", downtime); - ret = true; - - done: - return ret; + return true; } @@ -11121,7 +10987,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned long long size = 0; - bool ret = false; const char *unit; double value; int rc; @@ -11131,21 +10996,19 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { - goto cleanup; + return false; } else if (rc != 0) { if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) - goto cleanup; + return false; } if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0) - goto cleanup; + return false; value = vshPrettyCapacity(size, &unit); vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit); - ret = true; - cleanup: - return ret; + return true; } /* @@ -11182,24 +11045,20 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth = 0; unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) - goto done; + return false; if (vshCommandOptBool(cmd, "postcopy")) flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; if (virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) < 0) - goto done; + return false; - ret = true; - - done: - return ret; + return true; } /* @@ -11230,7 +11089,6 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth; unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -11239,14 +11097,11 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; if (virDomainMigrateGetMaxSpeed(dom, &bandwidth, flags) < 0) - goto done; + return false; vshPrint(ctl, "%lu\n", bandwidth); - ret = true; - - done: - return ret; + return true; } /* @@ -11272,18 +11127,14 @@ static bool cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (virDomainMigrateStartPostCopy(dom, 0) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11578,7 +11429,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; - bool ret = false; int port = 0; g_autofree char *listen_addr = NULL; @@ -11588,17 +11438,17 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) /* Check if the domain is active and don't rely on -1 for this */ if (!virDomainIsActive(dom)) { vshError(ctl, _("Domain is not running")); - goto cleanup; + return false; } if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0) - goto cleanup; + return false; /* Get the VNC port */ if (virXPathInt("string(/domain/devices/graphics[@type='vnc']/@port)", ctxt, &port)) { vshError(ctl, _("Failed to get VNC port. Is this domain using VNC?")); - goto cleanup; + return false; } listen_addr = virXPathString("string(/domain/devices/graphics" @@ -11620,10 +11470,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s:%d\n", listen_addr, port-5900); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11649,20 +11496,16 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - bool ret = false; g_autofree char *tty = NULL; if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; if (!(tty = virXPathString("string(/domain/devices/console/@tty)", ctxt))) - goto cleanup; + return false; vshPrint(ctl, "%s\n", tty); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11849,7 +11692,6 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool ret = false; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -11863,18 +11705,15 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0) - goto cleanup; + return false; if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) { vshError(ctl, _("Failed to detach device with alias %s"), alias); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", _("Device detach request sent successfully\n")); - ret = true; - - cleanup: - return ret; + return true; } @@ -11911,7 +11750,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *from = NULL; g_autofree char *buffer = NULL; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -11932,7 +11770,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -11940,7 +11778,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } if (vshCommandOptBool(cmd, "force")) @@ -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; - - cleanup: - return ret; + return true; } /* @@ -12179,13 +12014,12 @@ virshFindDisk(const char *doc, g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL; - xmlNodePtr ret = NULL; size_t i; xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt); if (!xml) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); @@ -12194,7 +12028,7 @@ virshFindDisk(const char *doc, obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } /* search disk using @path */ @@ -12234,10 +12068,10 @@ virshFindDisk(const char *doc, } if (STREQ_NULLABLE(tmp, path)) { - ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); + xmlNodePtr ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); /* drop backing store since they are not needed here */ virshDiskDropBackingStore(ret); - goto cleanup; + return ret; } } cur = cur->next; @@ -12245,9 +12079,7 @@ virshFindDisk(const char *doc, } vshError(NULL, _("No disk found whose source path or target is %s"), path); - - cleanup: - return ret; + return NULL; } typedef enum { @@ -12285,7 +12117,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (!(STREQ_NULLABLE(device_type, "cdrom") || STREQ_NULLABLE(device_type, "floppy"))) { vshError(NULL, _("The disk device '%s' is not removable"), target); - goto cleanup; + return NULL; } /* find the current source subelement */ @@ -12319,7 +12151,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (type == VIRSH_UPDATE_DISK_XML_EJECT) { if (!source) { vshError(NULL, _("The disk device '%s' doesn't have media"), target); - goto cleanup; + return NULL; } /* forcibly switch to empty file cdrom */ @@ -12327,7 +12159,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, new_source = NULL; } else if (!new_source) { vshError(NULL, _("New disk media source was not specified")); - goto cleanup; + return NULL; } if (source) { @@ -12339,7 +12171,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (source_path && type == VIRSH_UPDATE_DISK_XML_INSERT) { vshError(NULL, _("The disk device '%s' already has media"), target); - goto cleanup; + return NULL; } startupPolicy = virXMLPropString(source, "startupPolicy"); @@ -12387,10 +12219,9 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (!(ret = virXMLNodeToString(NULL, disk_node))) { vshSaveLibvirtError(); - goto cleanup; + return NULL; } - cleanup: return ret; } @@ -13684,29 +13515,25 @@ static bool cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; unsigned long long minimum = 0; const char *mountPoint = NULL; unsigned int flags = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false; if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0) - goto cleanup; + return false; if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) { vshError(ctl, _("Unable to invoke fstrim")); - goto cleanup; + return false; } - ret = true; - - cleanup: - return ret; + return true; } static const vshCmdInfo info_domfsfreeze[] = { @@ -13914,20 +13741,17 @@ cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; int timeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; const unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0) - goto cleanup; + return false; if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -14047,25 +13871,22 @@ cmdGetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) int nkeys = 0; size_t i; const unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; nkeys = virDomainAuthorizedSSHKeysGet(dom, user, &keys, flags); if (nkeys < 0) - goto cleanup; + return false; for (i = 0; i < nkeys; i++) { vshPrint(ctl, "%s", keys[i]); } - ret = true; - cleanup: - return ret; + return true; } @@ -14115,7 +13936,6 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) g_auto(GStrv) keys = NULL; int nkeys = 0; unsigned int flags = 0; - bool ret = false; VSH_REQUIRE_OPTION("remove", "file"); VSH_EXCLUSIVE_OPTIONS("reset", "remove"); @@ -14124,10 +13944,10 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "remove")) { flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE; @@ -14137,7 +13957,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) if (!from) { vshError(ctl, _("Option --file is required")); - goto cleanup; + return false; } } } @@ -14145,27 +13965,25 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) if (from) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshSaveLibvirtError(); - goto cleanup; + return false; } if (!(keys = g_strsplit(buffer, "\n", -1))) - goto cleanup; + return false; nkeys = g_strv_length(keys); if (nkeys == 0) { vshError(ctl, _("File %s contains no keys"), from); - goto cleanup; + return false; } } if (virDomainAuthorizedSSHKeysSet(dom, user, (const char **) keys, nkeys, flags) < 0) { - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } @@ -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; - - 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 @@ -97,7 +97,6 @@ static const vshCmdOptDef opts_domcapabilities[] = { static bool cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autofree char *caps = NULL; const char *virttype = NULL; const char *emulatorbin = NULL; @@ -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; } /* @@ -154,7 +151,6 @@ static const vshCmdOptDef opts_freecell[] = { static bool cmdFreecell(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; int cell = -1; unsigned long long memory = 0; g_autofree xmlNodePtr *nodes = NULL; @@ -177,13 +173,13 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (all) { if (!(cap_xml = virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell", @@ -192,7 +188,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt == -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } nodes_free = g_new0(unsigned long long, nodes_cnt); @@ -203,14 +199,14 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - goto cleanup; + return false; } nodes_id[i] = id; if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]), id, 1) != 1) { vshError(ctl, _("failed to get free memory for NUMA node " "number: %lu"), id); - goto cleanup; + return false; } } @@ -225,21 +221,18 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) } else { if (cellno) { if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != 1) - goto cleanup; + return false; vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); } else { if ((memory = virNodeGetFreeMemory(priv->conn)) == 0) - goto cleanup; + return false; vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); } } - ret = true; - - cleanup: - return ret; + return true; } @@ -476,7 +469,6 @@ static const vshCmdOptDef opts_allocpages[] = { static bool cmdAllocpages(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; bool add = vshCommandOptBool(cmd, "add"); bool all = vshCommandOptBool(cmd, "all"); bool cellno = vshCommandOptBool(cmd, "cellno"); @@ -511,13 +503,13 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (!(cap_xml = virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell", @@ -526,7 +518,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt == -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } for (i = 0; i < nodes_cnt; i++) { @@ -534,22 +526,20 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - goto cleanup; + return false; } if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts, id, 1, flags) < 0) - goto cleanup; + return false; } } else { if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts, startCell, cellCount, flags) < 0) - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } @@ -583,7 +573,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; @@ -591,7 +580,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) if ((caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type, 0))) { if (!(xml = virXMLParseStringCtxt(caps, _("(domainCapabilities)"), &ctxt))) - goto cleanup; + return false; ignore_value(virXPathInt("string(./vcpu[1]/@max)", ctxt, &vcpus)); } else { @@ -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; } /* @@ -673,13 +659,12 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) g_autofree unsigned char *cpumap = NULL; unsigned int online; bool pretty = vshCommandOptBool(cmd, "pretty"); - bool ret = false; virshControl *priv = ctl->privData; cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0); if (cpunum < 0) { vshError(ctl, "%s", _("Unable to get cpu map")); - goto cleanup; + return false; } vshPrint(ctl, "%-15s %d\n", _("CPUs present:"), cpunum); @@ -690,7 +675,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) g_autofree char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum)); if (!str) - goto cleanup; + return false; vshPrint(ctl, "%s", str); } else { for (cpu = 0; cpu < cpunum; cpu++) @@ -698,10 +683,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } vshPrint(ctl, "\n"); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -767,7 +749,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; g_autofree virNodeCPUStatsPtr params = NULL; int nparams = 0; - bool ret = false; unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 }; bool present[VIRSH_CPU_LAST] = { false }; virshControl *priv = ctl->privData; @@ -791,7 +772,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < 2; i++) { if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get node cpu stats")); - goto cleanup; + return false; } for (j = 0; j < nparams; j++) { @@ -845,10 +826,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -879,7 +857,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) size_t i; int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; g_autofree virNodeMemoryStatsPtr params = NULL; - bool ret = false; virshControl *priv = ctl->privData; if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) @@ -889,29 +866,25 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) if (virNodeGetMemoryStats(priv->conn, cellNum, NULL, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get number of memory stats")); - goto cleanup; + return false; } if (nparams == 0) { /* nothing to output */ - ret = true; - goto cleanup; + return true; } /* now go get all the memory parameters */ params = g_new0(virNodeMemoryStats, nparams); if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get memory stats")); - goto cleanup; + return false; } for (i = 0; i < nparams; i++) vshPrint(ctl, "%-7s: %20llu KiB\n", params[i].field, params[i].value); - ret = true; - - cleanup: - return ret; + return true; } /* diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c4b1d556ca..945ccc7f45 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -122,11 +122,11 @@ vshFindNodeDevice(vshControl *ctl, const char *value) narr = vshStringToArray(value, &arr); if (narr != 2) { vshError(ctl, _("Malformed device value '%s'"), value); - goto cleanup; + return NULL; } if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; + return NULL; dev = virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1], 0); } else { @@ -135,10 +135,9 @@ vshFindNodeDevice(vshControl *ctl, const char *value) if (!dev) { vshError(ctl, "%s '%s'", _("Could not find matching device"), value); - goto cleanup; + return NULL; } - cleanup: return dev; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b4dfcc2f7a..c51dc023e3 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -529,17 +529,16 @@ virshMakeCloneXML(const char *origxml, const char *newname) doc = virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt); if (!doc) - goto cleanup; + return NULL; obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt); if (obj == NULL || obj->nodesetval == NULL || obj->nodesetval->nodeTab == NULL) - goto cleanup; + return NULL; xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newname); xmlDocDumpMemory(doc, &newxml, &size); - cleanup: return newxml; } diff --git a/tools/vsh.c b/tools/vsh.c index f9600bafba..4356bc391d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -432,7 +432,6 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, bool report) { size_t i; - const vshCmdOptDef *ret = NULL; g_autofree char *alias = NULL; if (STREQ(name, helpopt.name)) @@ -457,7 +456,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, if (report) vshError(ctl, _("invalid '=' after option --%s"), opt->name); - goto cleanup; + return NULL; } *optstr = g_strdup(value + 1); } @@ -466,12 +465,11 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, if ((*opts_seen & (1ULL << i)) && opt->type != VSH_OT_ARGV) { if (report) vshError(ctl, _("option --%s already seen"), name); - goto cleanup; + return NULL; } *opts_seen |= 1ULL << i; *opt_index = i; - ret = opt; - goto cleanup; + return opt; } } @@ -479,8 +477,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, vshError(ctl, _("command '%s' doesn't support option --%s"), cmd->name, name); } - cleanup: - return ret; + return NULL; } static const vshCmdOptDef * -- 2.31.1