From nobody Sun Feb 8 14:41:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628757591; cv=none; d=zohomail.com; s=zohoarc; b=QOV61onKgt/YEWFsG/Bayky03BQKs0yx6qK3QgzAVGOr5QbA9RBGWrIRlhhq60/A3+uKvX8vAUhNQy37TqoNf9wp+btZH0dvYC99y75B/dx7tUdc/HpcmiAb6oqpdG2PrgcAWikBY4IEFuhqgz1HHkMO8RIyGaR4lZcyN/Hwhgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628757591; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ueDC9W+oWgTgPfYaAUKsbzWOATEf5jeGMu9Jg7/k12E=; b=Bb2x4NzYbA5gxvNsLiHJ6QawyeytZ87wVcBro1UpI34EiH/MrzVSVboVTiFvyGF0hAyCsxc9hqsEccc8bUueI50SFMbTNvL4ZM4b5YvpnivV6zbZOCV4OwUKeuewERDNB8dRjMwIVcHki55ltcGCm0b42xgaGCKNeQoLHqRDcC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628757591937264.39508681476923; Thu, 12 Aug 2021 01:39:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-jN6DiF5UPSiALOuwq1Musg-1; Thu, 12 Aug 2021 04:39:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98AA4190A7A1; Thu, 12 Aug 2021 08:39:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58222295E5; Thu, 12 Aug 2021 08:39:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 283BB181A3ED; Thu, 12 Aug 2021 08:39:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17C8XIFZ003735 for ; Thu, 12 Aug 2021 04:33:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54BE710016FF; Thu, 12 Aug 2021 08:33:18 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A942B10013C1 for ; Thu, 12 Aug 2021 08:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628757590; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ueDC9W+oWgTgPfYaAUKsbzWOATEf5jeGMu9Jg7/k12E=; b=B/Atqty41Pkf5yJufCUl4FPWawscDDQhwTiT1IRPA+UGBeHWaw4U0Hg7gGUhOaUb2zb62x 6F4moiZcd57orAJfIUp7zqpqs8IxhyCYlT8vLXb9JLtWSZuwapFOTVuJ2lvJ9ZnaaDO3kR Gd1caDlDCj/4/6A/IyALr23A/1zJ6ws= X-MC-Unique: jN6DiF5UPSiALOuwq1Musg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 12/12] tools: virsh: remove redundant labels Date: Thu, 12 Aug 2021 10:32:50 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628757592924100001 Signed-off-by: J=C3=A1n Tomko --- 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 =3D NULL; size_t i; int rc; - char **ret =3D NULL; g_auto(GStrv) tmp =3D NULL; =20 virCheckFlags(0, NULL); @@ -456,7 +455,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, return NULL; =20 if ((rc =3D virDomainGetIOThreadInfo(dom, &info, flags)) < 0) - goto cleanup; + return NULL; =20 niothreads =3D rc; =20 @@ -465,10 +464,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, for (i =3D 0; i < niothreads; i++) tmp[i] =3D g_strdup_printf("%u", info[i]->iothread_id); =20 - ret =3D g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } =20 =20 @@ -482,7 +478,6 @@ virshDomainVcpuCompleter(vshControl *ctl, g_autoptr(xmlXPathContext) ctxt =3D NULL; int nvcpus =3D 0; unsigned int id; - char **ret =3D NULL; g_auto(GStrv) tmp =3D NULL; =20 virCheckFlags(0, NULL); @@ -492,21 +487,18 @@ virshDomainVcpuCompleter(vshControl *ctl, =20 if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; =20 /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; =20 tmp =3D g_new0(char *, nvcpus + 1); =20 for (id =3D 0; id < nvcpus; id++) tmp[id] =3D g_strdup_printf("%u", id); =20 - ret =3D g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } =20 =20 @@ -522,7 +514,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, unsigned int id; g_auto(GStrv) vcpulist =3D NULL; const char *vcpuid =3D NULL; - char **ret =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -530,25 +521,22 @@ virshDomainVcpulistCompleter(vshControl *ctl, return NULL; =20 if (vshCommandOptStringQuiet(ctl, cmd, "vcpulist", &vcpuid) < 0) - goto cleanup; + return NULL; =20 if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; =20 /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; =20 vcpulist =3D g_new0(char *, nvcpus + 1); =20 for (id =3D 0; id < nvcpus; id++) vcpulist[id] =3D g_strdup_printf("%u", id); =20 - ret =3D virshCommaStringListComplete(vcpuid, (const char **)vcpulist); - - cleanup: - return ret; + return virshCommaStringListComplete(vcpuid, (const char **)vcpulist); } =20 =20 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 d= om, bool title, =20 /* fall back to xml */ if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0) - goto cleanup; + return NULL; =20 if (title) desc =3D virXPathString("string(./title[1])", ctxt); @@ -91,8 +91,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, if (!desc) desc =3D g_strdup(""); =20 - cleanup: - return desc; } =20 @@ -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 =3D false; int rv =3D 0; int period =3D -1; bool config =3D vshCommandOptBool(cmd, "config"); @@ -326,26 +323,25 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) * This is not really an unsigned long, but it */ if ((rv =3D vshCommandOptInt(ctl, cmd, "period", &period)) < 0) - goto cleanup; + return false; if (rv > 0) { if (period < 0) { vshError(ctl, _("Invalid collection period value '%d'"), perio= d); - goto cleanup; + return false; } =20 if (virDomainSetMemoryStatsPeriod(dom, period, flags) < 0) { vshError(ctl, "%s", _("Unable to change balloon collection period.")); - } else { - ret =3D true; + return false; } - goto cleanup; + return true; } =20 nr_stats =3D virDomainMemoryStats(dom, stats, VIR_DOMAIN_MEMORY_STAT_N= R, 0); if (nr_stats =3D=3D -1) { vshError(ctl, _("Failed to get memory statistics for domain %s"), = name); - goto cleanup; + return false; } =20 for (i =3D 0; i < nr_stats; i++) { @@ -377,9 +373,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "hugetlb_pgfail %llu\n", stats[i].val); } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -590,7 +584,6 @@ static const vshCmdOptDef opts_domblklist[] =3D { static bool cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; unsigned int flags =3D 0; g_autoptr(xmlDoc) xmldoc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; @@ -606,11 +599,11 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) details =3D vshCommandOptBool(cmd, "details"); =20 if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; =20 ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto cleanup; + return false; =20 if (details) table =3D vshTableNew(_("Type"), _("Device"), _("Target"), _("Sour= ce"), NULL); @@ -618,7 +611,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) table =3D vshTableNew(_("Target"), _("Source"), NULL); =20 if (!table) - goto cleanup; + return false; =20 for (i =3D 0; i < ndisks; i++) { g_autofree char *type =3D NULL; @@ -633,14 +626,14 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) device =3D virXPathString("string(./@device)", ctxt); if (!type || !device) { vshPrint(ctl, "unable to query block list details"); - goto cleanup; + return false; } } =20 target =3D virXPathString("string(./target/@dev)", ctxt); if (!target) { vshError(ctl, "unable to query block list"); - goto cleanup; + return false; } =20 if (STREQ_NULLABLE(type, "nvme")) { @@ -652,7 +645,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) !(addrNode =3D virXPathNode("./source/address", ctxt)) || virPCIDeviceAddressParseXML(addrNode, &addr) < 0) { vshError(ctl, "Unable to query NVMe disk address"); - goto cleanup; + return false; } =20 source =3D 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; } } =20 vshTablePrintToStdout(table, ctl); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -706,7 +696,6 @@ static const vshCmdOptDef opts_domiflist[] =3D { static bool cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; unsigned int flags =3D 0; g_autoptr(xmlDoc) xmldoc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; @@ -719,16 +708,16 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; =20 ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); if (ninterfaces < 0) - goto cleanup; + return false; =20 table =3D vshTableNew(_("Interface"), _("Type"), _("Source"), _("Model"), _("MAC"), NULL); if (!table) - goto cleanup; + return false; =20 for (i =3D 0; i < ninterfaces; i++) { g_autofree char *type =3D NULL; @@ -757,15 +746,12 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) model ? model : "-", mac ? mac : "-", NULL) < 0) - goto cleanup; + return false; } =20 vshTablePrintToStdout(table, ctl); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -810,7 +796,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) g_autofree xmlNodePtr *interfaces =3D NULL; int ninterfaces; unsigned int flags =3D 0; - bool ret =3D false; =20 if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) return false; @@ -819,7 +804,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) flags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - goto cleanup; + return false; =20 /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) =3D=3D 0) @@ -831,7 +816,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) =20 if ((ninterfaces =3D virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) { vshError(ctl, _("Failed to extract interface information")); - goto cleanup; + return false; } =20 if (ninterfaces < 1) { @@ -840,10 +825,10 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, _("Interface (dev: %s) not found."), iface); =20 - goto cleanup; + return false; } else if (ninterfaces > 1) { vshError(ctl, _("multiple matching interfaces found")); - goto cleanup; + return false; } =20 ctxt->node =3D interfaces[0]; @@ -853,11 +838,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s up", iface); =20 - ret =3D true; - - cleanup: - - return ret; + return true; } =20 /* @@ -882,16 +863,13 @@ static bool cmdDomControl(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; virDomainControlInfo info; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 - if (virDomainGetControlInfo(dom, &info, 0) < 0) { - ret =3D false; - goto cleanup; - } + if (virDomainGetControlInfo(dom, &info, 0) < 0) + return false; =20 if (info.state !=3D VIR_DOMAIN_CONTROL_OK && info.state !=3D VIR_DOMAIN_CONTROL_ERROR) { @@ -907,8 +885,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) virshDomainControlStateToString(info.state)); } =20 - cleanup: - return ret; + return true; } =20 /* @@ -989,7 +966,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) const char *field =3D NULL; int rc, nparams =3D 0; size_t i; - bool ret =3D false; bool human =3D vshCommandOptBool(cmd, "human"); /* human readable outp= ut */ =20 if (!(dom =3D 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; =20 if (!device) device =3D ""; @@ -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 !=3D VIR_ERR_NO_SUPPORT) - goto cleanup; + return false; =20 vshResetLibvirtError(); =20 @@ -1022,7 +998,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) sizeof(stats)) =3D=3D -1) { vshError(ctl, _("Failed to get block stats %s %s"), name, device); - goto cleanup; + return false; } =20 /* human friendly output */ @@ -1040,7 +1016,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) params =3D g_new0(virTypedParameter, nparams); if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0= ) { vshError(ctl, _("Failed to get block stats for domain '%s' dev= ice '%s'"), name, device); - goto cleanup; + return false; } =20 /* set for prettier output */ @@ -1089,10 +1065,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) } } =20 - ret =3D true; - - cleanup: - return ret; + return true; } #undef DOMBLKSTAT_LEGACY_PRINT =20 @@ -1126,17 +1099,16 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom =3D NULL; const char *name =3D NULL, *device =3D NULL; virDomainInterfaceStatsStruct stats; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0) - goto cleanup; + return false; =20 if (virDomainInterfaceStats(dom, device, &stats, sizeof(stats)) =3D=3D= -1) { vshError(ctl, _("Failed to get interface stats %s %s"), name, devi= ce); - goto cleanup; + return false; } =20 if (stats.rx_bytes >=3D 0) @@ -1163,10 +1135,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) if (stats.tx_drop >=3D 0) vshPrint(ctl, "%s tx_drop %lld\n", device, stats.tx_drop); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -1398,17 +1367,14 @@ static bool cmdDomstate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D true; bool showReason =3D vshCommandOptBool(cmd, "reason"); int state, reason; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 - if ((state =3D virshDomainState(ctl, dom, &reason)) < 0) { - ret =3D false; - goto cleanup; - } + if ((state =3D virshDomainState(ctl, dom, &reason)) < 0) + return false; =20 if (showReason) { vshPrint(ctl, "%s (%s)\n", @@ -1419,8 +1385,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) virshDomainStateToString(state)); } =20 - cleanup: - return ret; + return true; } =20 /* @@ -1461,7 +1426,6 @@ static bool cmdDomTime(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; bool now =3D vshCommandOptBool(cmd, "now"); bool pretty =3D vshCommandOptBool(cmd, "pretty"); bool rtcSync =3D vshCommandOptBool(cmd, "sync"); @@ -1482,7 +1446,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) =20 if (rv < 0) { /* invalid integer format */ - goto cleanup; + return false; } else if (rv > 0) { /* valid integer to set */ doSet =3D true; @@ -1491,18 +1455,18 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (doSet || now || rtcSync) { if (now && ((seconds =3D time(NULL)) =3D=3D (time_t) -1)) { vshError(ctl, _("Unable to get current time")); - goto cleanup; + return false; } =20 if (rtcSync) flags |=3D VIR_DOMAIN_TIME_SYNC; =20 if (virDomainSetTime(dom, seconds, nseconds, flags) < 0) - goto cleanup; + return false; =20 } else { if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0) - goto cleanup; + return false; =20 if (pretty) { g_autoptr(GDateTime) then =3D NULL; @@ -1517,9 +1481,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) } } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* 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 =3D NULL; char *buffer; int rv; - bool ret =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; bool current =3D vshCommandOptBool(cmd, "current"); bool config =3D vshCommandOptBool(cmd, "config"); @@ -346,7 +345,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; =20 if (persistent && virDomainIsActive(dom) =3D=3D 1) @@ -354,7 +353,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) =20 if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } =20 if (flags || current) @@ -366,14 +365,11 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) =20 if (rv < 0) { vshError(ctl, _("Failed to attach device from %s"), from); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, "%s", _("Device attached successfully\n")); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -888,7 +884,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virNetDevBandwidthRate inbound, outbound; virDomainNetType typ; int ret; - bool functionReturn =3D false; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; unsigned int flags =3D 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; =20 /* check interface type */ if ((int)(typ =3D virDomainNetTypeFromString(type)) < 0) { vshError(ctl, _("No support for %s in command 'attach-interface'"), type); - goto cleanup; + return false; } =20 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 =3D=3D 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; } } =20 @@ -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 int= erface"), source); - goto cleanup; + return false; } =20 virBufferAddLit(&buf, "\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; } =20 @@ -1048,12 +1043,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *c= md) =20 if (vshCommandOptBool(cmd, "print-xml")) { vshPrint(ctl, "%s", xml); - functionReturn =3D true; - goto cleanup; + return true; } =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; =20 if (persistent && virDomainIsActive(dom) =3D=3D 1) @@ -1066,13 +1060,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *c= md) =20 if (ret !=3D 0) { vshError(ctl, "%s", _("Failed to attach interface")); - } else { - vshPrintExtra(ctl, "%s", _("Interface attached successfully\n")); - functionReturn =3D true; + return false; } =20 - cleanup: - return functionReturn; + vshPrintExtra(ctl, "%s", _("Interface attached successfully\n")); + return true; } =20 /* @@ -2690,11 +2682,11 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async); =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; =20 /* 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; =20 if (bandwidth) ret =3D virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); @@ -2703,7 +2695,6 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) else ret =3D virshBlockJobInfo(ctl, dom, path, raw, bytes); =20 - cleanup: return ret; } =20 @@ -2987,7 +2978,6 @@ static bool cmdConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; bool force =3D vshCommandOptBool(cmd, "force"); bool safe =3D vshCommandOptBool(cmd, "safe"); unsigned int flags =3D 0; @@ -2997,17 +2987,14 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "devname", &name) < 0) /* sc_proh= ibit_devname */ - goto cleanup; + return false; =20 if (force) flags |=3D VIR_DOMAIN_CONSOLE_FORCE; if (safe) flags |=3D VIR_DOMAIN_CONSOLE_SAFE; =20 - ret =3D cmdRunConsole(ctl, dom, name, flags); - - cleanup: - return ret; + return cmdRunConsole(ctl, dom, name, flags); } #endif /* WIN32 */ =20 @@ -3056,7 +3043,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) const char *element; const char *attr; bool config; - bool ret =3D false; unsigned int flags =3D 0; unsigned int xmlflags =3D 0; size_t i; @@ -3071,13 +3057,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) =20 if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0 || vshCommandOptStringReq(ctl, cmd, "state", &state) < 0) - goto cleanup; + return false; =20 config =3D vshCommandOptBool(cmd, "config"); =20 if (STRNEQ(state, "up") && STRNEQ(state, "down")) { vshError(ctl, _("invalid link state '%s'"), state); - goto cleanup; + return false; } =20 if (config) { @@ -3091,13 +3077,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) flags =3D VIR_DOMAIN_AFFECT_CONFIG; =20 if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0) - goto cleanup; + return false; =20 obj =3D xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt); if (obj =3D=3D NULL || obj->type !=3D XPATH_NODESET || obj->nodesetval =3D=3D NULL || obj->nodesetval->nodeNr =3D=3D 0) { vshError(ctl, _("Failed to extract interface information or no int= erfaces found")); - goto cleanup; + return false; } =20 if (virMacAddrParse(iface, &macaddr) =3D=3D 0) { @@ -3125,7 +3111,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } =20 vshError(ctl, _("interface (%s: %s) not found"), element, iface); - goto cleanup; + return false; =20 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; =20 if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) =3D=3D NULL) - goto cleanup; + return false; } =20 if (!(xml_buf =3D virXMLNodeToString(xml, obj->nodesetval->nodeTab[i])= )) { vshSaveLibvirtError(); vshError(ctl, _("Failed to create XML")); - goto cleanup; + return false; } =20 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 =3D true; + return false; } =20 - cleanup: - - return ret; + vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); + return true; } =20 /* "domiftune" command @@ -3447,7 +3429,6 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *name; - bool ret =3D false; const char *target =3D NULL; int suspendTarget; unsigned long long duration =3D 0; @@ -3456,29 +3437,26 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) - goto cleanup; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) - goto cleanup; + return false; =20 if ((suspendTarget =3D virshNodeSuspendTargetTypeFromString(target)) <= 0) { vshError(ctl, "%s", _("Invalid target")); - goto cleanup; + return false; } =20 if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0= ) { vshError(ctl, _("Domain '%s' could not be suspended"), virDomainGetName(dom)); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, _("Domain '%s' successfully suspended"), virDomainGetName(dom)); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -3506,7 +3484,6 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *name; - bool ret =3D false; unsigned int flags =3D 0; =20 if (!(dom =3D 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; } =20 vshPrintExtra(ctl, _("Domain '%s' successfully woken up"), virDomainGetName(dom)); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4036,7 +4010,6 @@ static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; #ifndef WIN32 bool console =3D vshCommandOptBool(cmd, "console"); #endif @@ -4051,11 +4024,11 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) =20 if (virDomainGetID(dom) !=3D (unsigned int)-1) { vshError(ctl, "%s", _("Domain is already active")); - goto cleanup; + return false; } =20 if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "paused")) flags |=3D VIR_DOMAIN_START_PAUSED; @@ -4075,7 +4048,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (last_error->code !=3D VIR_ERR_NO_SUPPORT && last_error->code !=3D VIR_ERR_INVALID_ARG) { vshReportError(ctl); - goto cleanup; + return false; } vshResetLibvirtError(); rc =3D 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 &=3D ~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(d= om)); - goto cleanup; + return false; } =20 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 =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4485,7 +4455,6 @@ static bool cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - bool ret =3D false; unsigned int flags =3D 0; g_autofree char *xml =3D NULL; virshControl *priv =3D ctl->privData; @@ -4498,13 +4467,10 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *= cmd) =20 xml =3D virDomainSaveImageGetXMLDesc(priv->conn, file, flags); if (!xml) - goto cleanup; + return false; =20 vshPrint(ctl, "%s", xml); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4542,7 +4508,6 @@ static bool cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - bool ret =3D false; const char *xmlfile =3D NULL; g_autofree char *xml =3D NULL; unsigned int flags =3D 0; @@ -4560,18 +4525,15 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *c= md) return false; =20 if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; =20 if (virDomainSaveImageDefineXML(priv->conn, file, xml, flags) < 0) { vshError(ctl, _("Failed to update %s"), file); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, _("State file %s updated.\n"), file); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4785,7 +4747,6 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *c= md) { g_autoptr(virshDomain) dom =3D NULL; const char *name; - bool ret =3D false; int hassave; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) @@ -4794,14 +4755,14 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd = *cmd) hassave =3D virDomainHasManagedSaveImage(dom, 0); if (hassave < 0) { vshError(ctl, "%s", _("Failed to check for domain managed save ima= ge")); - goto cleanup; + return false; } =20 if (hassave) { if (virDomainManagedSaveRemove(dom, 0) < 0) { vshError(ctl, _("Failed to remove managed save image for domai= n '%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; remova= l skipped"), name); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4859,7 +4817,7 @@ cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd) =20 dom =3D virshCommandOptDomain(ctl, cmd, NULL); if (dom =3D=3D NULL) - goto cleanup; + return false; =20 #define EDIT_GET_XML virDomainManagedSaveGetXMLDesc(dom, getxml_flags) #define EDIT_NOT_CHANGED \ @@ -4906,7 +4864,6 @@ static const vshCmdOptDef opts_managed_save_dumpxml[]= =3D { static bool cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; g_autoptr(virshDomain) dom =3D NULL; unsigned int flags =3D 0; g_autofree char *xml =3D NULL; @@ -4915,16 +4872,13 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd= *cmd) flags |=3D VIR_DOMAIN_XML_SECURE; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; =20 if (!(xml =3D virDomainManagedSaveGetXMLDesc(dom, flags))) - goto cleanup; + return false; =20 vshPrint(ctl, "%s", xml); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -4961,7 +4915,6 @@ static const vshCmdOptDef opts_managed_save_define[] = =3D { static bool cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; g_autoptr(virshDomain) dom =3D NULL; const char *xmlfile =3D NULL; g_autofree char *xml =3D NULL; @@ -4981,20 +4934,17 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd = *cmd) return false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; =20 if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) { vshError(ctl, _("Failed to update %s XML configuration"), virDomainGetName(dom)); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, _("Managed save state file of domain '%s' updated.\= n"), virDomainGetName(dom)); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -5264,7 +5214,6 @@ static bool cmdRestore(vshControl *ctl, const vshCmd *cmd) { const char *from =3D NULL; - bool ret =3D false; unsigned int flags =3D 0; const char *xmlfile =3D NULL; g_autofree char *xml =3D NULL; @@ -5285,20 +5234,17 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) =20 if (xmlfile && virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; =20 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; } =20 vshPrintExtra(ctl, _("Domain restored from %s\n"), from); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -5451,7 +5397,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "verbose")) verbose =3D true; @@ -5460,18 +5406,18 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) true, doDump, &data) < 0) - goto cleanup; + return false; =20 virshWatchJob(ctl, dom, verbose, eventLoop, &data.ret, 0, NULL, NULL, _("Dump")); =20 virThreadJoin(&workerThread); =20 - if (!data.ret) - vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); + if (data.ret) + return false; =20 - cleanup: - return !data.ret; + vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); + return true; } =20 static const vshCmdInfo info_screenshot[] =3D { @@ -5751,7 +5697,6 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) const char *password =3D NULL; const char *user =3D NULL; unsigned int flags =3D 0; - bool ret =3D false; =20 if (vshCommandOptBool(cmd, "encrypted")) flags =3D VIR_DOMAIN_PASSWORD_ENCRYPTED; @@ -5766,13 +5711,10 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *c= md) return false; =20 if (virDomainSetUserPassword(dom, user, password, flags) < 0) - goto cleanup; + return false; =20 vshPrintExtra(ctl, _("Password set successfully for %s in %s"), user, = name); - ret =3D true; - - cleanup: - return ret; + return true; } /* * "resume" command @@ -5839,7 +5781,6 @@ static bool cmdShutdown(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name; const char *mode =3D NULL; int flags =3D 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++; } =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; =20 if (flags) rv =3D 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; } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -5923,7 +5862,6 @@ static bool cmdReboot(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *name; const char *mode =3D NULL; int flags =3D 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++; } =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; =20 if (virDomainReboot(dom, flags) =3D=3D 0) { vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name); } else { vshError(ctl, _("Failed to reboot domain '%s'"), name); - goto cleanup; + return false; } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -6586,7 +6522,6 @@ static bool cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; bool maximum =3D vshCommandOptBool(cmd, "maximum"); bool active =3D vshCommandOptBool(cmd, "active"); bool config =3D vshCommandOptBool(cmd, "config"); @@ -6636,7 +6571,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) VIR_DOMAIN_AFFECT_LIVE, true); =20 if (conf_max =3D=3D -2 || conf_cur =3D=3D -2 || live_max =3D=3D -2= || live_cur =3D=3D -2) - goto cleanup; + return false; =20 #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 =3D virshCPUCountCollect(ctl, dom, flags, false); =20 if (count < 0) - goto cleanup; + return false; =20 vshPrint(ctl, "%d\n", count); } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -6692,12 +6624,11 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, { g_autofree char *str =3D NULL; size_t i; - int ret =3D -1; =20 vshPrint(ctl, "%-15s ", _("CPU Affinity:")); if (pretty) { if (!(str =3D virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(maxcpu)))) - goto cleanup; + return -1; vshPrint(ctl, _("%s (out of %d)"), str, maxcpu); } else { for (i =3D 0; i < maxcpu; i++) @@ -6705,10 +6636,7 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, } vshPrint(ctl, "\n"); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -6732,11 +6660,11 @@ virshDomainGetVcpuBitmap(vshControl *ctl, flags |=3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) - goto cleanup; + return NULL; =20 if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) { vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count")); - goto cleanup; + return NULL; } =20 ignore_value(virXPathUInt("string(/domain/vcpu/@current)", ctxt, &curv= cpus)); @@ -6751,7 +6679,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, for (i =3D 0; i < curvcpus; i++) ignore_value(virBitmapSetBit(ret, i)); =20 - goto cleanup; + return NULL; } =20 for (i =3D 0; i < nnodes; i++) { @@ -6770,10 +6698,9 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (virBitmapCountBits(ret) !=3D curvcpus) { vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap")); virBitmapFree(ret); - ret =3D NULL; + return NULL; } =20 - cleanup: return ret; } =20 @@ -6946,7 +6873,6 @@ virshVcpuPinQuery(vshControl *ctl, int cpumaplen; size_t i; int ncpus; - bool ret =3D false; g_autoptr(vshTable) table =3D NULL; =20 if ((ncpus =3D virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) { @@ -6956,7 +6882,7 @@ virshVcpuPinQuery(vshControl *ctl, else vshError(ctl, "%s", _("cannot get vcpupin for transient do= main")); } - goto cleanup; + return false; } =20 if (got_vcpu && vcpu >=3D 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; } =20 cpumaplen =3D VIR_CPU_MAPLEN(maxcpu); @@ -6979,7 +6905,7 @@ virshVcpuPinQuery(vshControl *ctl, cpumaplen, flags)) >=3D 0) { table =3D vshTableNew(_("VCPU"), _("CPU Affinity"), NULL); if (!table) - goto cleanup; + return false; =20 for (i =3D 0; i < ncpus; i++) { g_autofree char *pinInfo =3D NULL; @@ -6989,20 +6915,18 @@ virshVcpuPinQuery(vshControl *ctl, =20 if (!(pinInfo =3D virBitmapDataFormat(VIR_GET_CPUMAP(cpumap, c= pumaplen, i), cpumaplen))) - goto cleanup; + return false; =20 vcpuStr =3D g_strdup_printf("%zu", i); =20 if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0) - goto cleanup; + return false; } =20 vshTablePrintToStdout(table, ctl); } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 =20 @@ -7089,25 +7013,22 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) /* Query mode: show CPU affinity information then exit.*/ if (!cpulist) { ret =3D virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags); - goto cleanup; + return false; } =20 /* Pin mode: pinning specified vcpu to specified physical cpus */ if (!(cpumap =3D virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; =20 /* use old API without any explicit flags */ if (flags =3D=3D VIR_DOMAIN_AFFECT_CURRENT && !current) { if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) !=3D 0) - goto cleanup; + return false; } else { if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != =3D 0) - goto cleanup; + return false; } - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -7193,22 +7114,20 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret =3D virshPrintPinInfo(ctl, cpumap, cpumaplen); vshPrint(ctl, "\n"); } - goto cleanup; + return false; } =20 /* Pin mode: pinning emulator threads to specified physical cpus */ if (!(cpumap =3D virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; =20 if (flags =3D=3D -1) flags =3D VIR_DOMAIN_AFFECT_LIVE; =20 if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) !=3D 0) - goto cleanup; + return false; =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -7254,7 +7173,6 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; unsigned int count =3D 0; - bool ret =3D false; bool maximum =3D vshCommandOptBool(cmd, "maximum"); bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); @@ -7284,26 +7202,23 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0) - goto cleanup; + return false; =20 if (count =3D=3D 0) { vshError(ctl, _("Can't set 0 processors for a VM")); - goto cleanup; + return false; } =20 /* none of the options were specified */ if (!current && flags =3D=3D 0) { if (virDomainSetVcpus(dom, count) !=3D 0) - goto cleanup; + return false; } else { if (virDomainSetVcpusFlags(dom, count, flags) < 0) - goto cleanup; + return false; } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -7438,7 +7353,6 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) bool live =3D vshCommandOptBool(cmd, "live"); const char *vcpulist =3D NULL; int state =3D 0; - bool ret =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; =20 VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable); @@ -7466,12 +7380,9 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) state =3D 1; =20 if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -7511,7 +7422,6 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) unsigned long long threshold; const char *dev =3D NULL; g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; =20 if (vshCommandOptStringReq(ctl, cmd, "dev", &dev)) return false; @@ -7524,12 +7434,9 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cm= d) return false; =20 if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -7661,7 +7568,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) bool current =3D vshCommandOptBool(cmd, "current"); unsigned int iothread_id =3D 0; int maxcpu; - bool ret =3D false; g_autofree unsigned char *cpumap =3D NULL; int cpumaplen; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; @@ -7679,25 +7585,22 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) - goto cleanup; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) - goto cleanup; + return false; =20 if ((maxcpu =3D virshNodeGetCPUCount(priv->conn)) < 0) - goto cleanup; + return false; =20 if (!(cpumap =3D virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; =20 if (virDomainPinIOThread(dom, iothread_id, cpumap, cpumaplen, flags) !=3D 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -7731,7 +7634,6 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; int iothread_id =3D 0; - bool ret =3D false; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -7749,19 +7651,16 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <=3D 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } =20 if (virDomainAddIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -7900,7 +7799,6 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; int iothread_id =3D 0; - bool ret =3D false; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -7918,19 +7816,16 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <=3D 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } =20 if (virDomainDelIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -8159,7 +8054,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - bool ret =3D false; g_autofree char *buffer =3D NULL; #ifndef WIN32 bool console =3D vshCommandOptBool(cmd, "console"); @@ -8176,7 +8070,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) return false; =20 if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "paused")) flags |=3D VIR_DOMAIN_START_PAUSED; @@ -8192,7 +8086,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) =20 if (!dom) { vshError(ctl, _("Failed to create domain from %s"), from); - goto cleanup; + return false; } =20 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 =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -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; =20 if ((set || edit) && !key) { vshError(ctl, "%s", _("namespace key is required when modifying metadata")); - goto cleanup; + return false; } =20 if (set || rem) { if (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, set, key, uri, flags)) - goto cleanup; + return false; =20 if (rem) vshPrintExtra(ctl, "%s\n", _("Metadata removed")); @@ -8605,7 +8496,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) /* get */ if (!(data =3D virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEME= NT, uri, flags))) - goto cleanup; + return false; =20 vshPrint(ctl, "%s\n", data); } @@ -8698,7 +8589,6 @@ static bool cmdSendKey(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const char *codeset_option; int codeset; unsigned int holdtime =3D 0; @@ -8714,7 +8604,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) codeset_option =3D "linux"; =20 if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) - goto cleanup; + return false; =20 /* 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 =3D virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { vshError(ctl, _("unknown codeset: '%s'"), codeset_option); - goto cleanup; + return false; } =20 while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { if (count =3D=3D VIR_DOMAIN_SEND_KEY_MAX_KEYS) { vshError(ctl, _("too many keycodes")); - goto cleanup; + return false; } =20 if ((keycode =3D virshKeyCodeGetInt(opt->data)) < 0) { if ((keycode =3D virKeycodeValueFromString(codeset, opt->data)= ) < 0) { vshError(ctl, _("invalid keycode: '%s'"), opt->data); - goto cleanup; + return false; } } =20 @@ -8744,11 +8634,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) count++; } =20 - if (!(virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0= )) - ret =3D true; + if (virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0) + return false; =20 - cleanup: - return ret; + return true; } =20 /* @@ -8882,7 +8771,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes =3D 0; unsigned long long max; unsigned long kibibytes =3D 0; - bool ret =3D false; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -8911,15 +8799,13 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max =3D ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes =3D VIR_DIV_UP(bytes, 1024); =20 if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) - goto cleanup; + return false; =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -8959,7 +8845,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes =3D 0; unsigned long long max; unsigned long kibibytes =3D 0; - bool ret =3D false; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -8983,17 +8868,15 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max =3D ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes =3D VIR_DIV_UP(bytes, 1024); =20 if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAX= IMUM) < 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - goto cleanup; + return false; } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -9888,7 +9771,6 @@ static bool cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; const vshCmdOpt *opt =3D NULL; g_autofree char **cmdargv =3D NULL; size_t ncmdargv =3D 0; @@ -9903,7 +9785,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *c= md) =20 dom =3D virshCommandOptDomain(ctl, cmd, NULL); if (dom =3D=3D NULL) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "noseclabel")) setlabel =3D false; @@ -9916,16 +9798,16 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd = *cmd) cmdargv[ncmdargv - 1] =3D NULL; =20 if ((nfdlist =3D virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0) - goto cleanup; + return false; =20 if (setlabel) { secmodel =3D g_new0(virSecurityModel, 1); seclabel =3D g_new0(virSecurityLabel, 1); =20 if (virNodeGetSecurityModel(priv->conn, secmodel) < 0) - goto cleanup; + return false; if (virDomainGetSecurityLabel(dom, seclabel) < 0) - goto cleanup; + return false; } =20 /* Fork once because we don't want to affect @@ -9933,7 +9815,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *c= md) * can only be changed in single-threaded process */ if ((pid =3D virFork()) < 0) - goto cleanup; + return false; if (pid =3D=3D 0) { int status; =20 @@ -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; } } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -10136,7 +10015,6 @@ static const vshCmdOptDef opts_domxmltonative[] =3D= { static bool cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; const char *format =3D NULL; const char *xmlFile =3D NULL; g_autofree char *configData =3D NULL; @@ -10159,26 +10037,22 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *= cmd) xmlData =3D 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; } =20 if (!xmlData) { vshError(ctl, "%s", _("failed to retrieve XML")); - goto cleanup; + return false; } =20 - if (!(configData =3D virConnectDomainXMLToNative(priv->conn, format, x= mlData, flags))) { - goto cleanup; - } else { - vshPrint(ctl, "%s", configData); - ret =3D true; - } + if (!(configData =3D virConnectDomainXMLToNative(priv->conn, format, x= mlData, flags))) + return false; =20 - cleanup: - return ret; + vshPrint(ctl, "%s", configData); + return true; } =20 /* @@ -10246,22 +10120,18 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *new_name =3D NULL; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0) - goto cleanup; + return false; =20 if (virDomainRename(dom, new_name, 0) < 0) - goto cleanup; + return false; =20 vshPrintExtra(ctl, "Domain successfully renamed\n"); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -11076,19 +10946,15 @@ cmdMigrateGetMaxDowntime(vshControl *ctl, const v= shCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; unsigned long long downtime; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (virDomainMigrateGetMaxDowntime(dom, &downtime, 0) < 0) - goto done; + return false; =20 vshPrint(ctl, "%llu\n", downtime); - ret =3D true; - - done: - return ret; + return true; } =20 =20 @@ -11121,7 +10987,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *= cmd) { g_autoptr(virshDomain) dom =3D NULL; unsigned long long size =3D 0; - bool ret =3D false; const char *unit; double value; int rc; @@ -11131,21 +10996,19 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd= *cmd) =20 rc =3D vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { - goto cleanup; + return false; } else if (rc !=3D 0) { if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) - goto cleanup; + return false; } =20 if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0) - goto cleanup; + return false; =20 value =3D vshPrettyCapacity(size, &unit); vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit); =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -11182,24 +11045,20 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshC= md *cmd) g_autoptr(virshDomain) dom =3D NULL; unsigned long bandwidth =3D 0; unsigned int flags =3D 0; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) - goto done; + return false; =20 if (vshCommandOptBool(cmd, "postcopy")) flags |=3D VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; =20 if (virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) < 0) - goto done; + return false; =20 - ret =3D true; - - done: - return ret; + return true; } =20 /* @@ -11230,7 +11089,6 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd= *cmd) g_autoptr(virshDomain) dom =3D NULL; unsigned long bandwidth; unsigned int flags =3D 0; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -11239,14 +11097,11 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshC= md *cmd) flags |=3D VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; =20 if (virDomainMigrateGetMaxSpeed(dom, &bandwidth, flags) < 0) - goto done; + return false; =20 vshPrint(ctl, "%lu\n", bandwidth); =20 - ret =3D true; - - done: - return ret; + return true; } =20 /* @@ -11272,18 +11127,14 @@ static bool cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (virDomainMigrateStartPostCopy(dom, 0) < 0) - goto cleanup; + return false; =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -11578,7 +11429,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; int port =3D 0; g_autofree char *listen_addr =3D NULL; =20 @@ -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; } =20 if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0) - goto cleanup; + return false; =20 /* Get the VNC port */ if (virXPathInt("string(/domain/devices/graphics[@type=3D'vnc']/@port)= ", ctxt, &port)) { vshError(ctl, _("Failed to get VNC port. Is this domain using VNC?= ")); - goto cleanup; + return false; } =20 listen_addr =3D 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); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -11649,20 +11496,16 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; - bool ret =3D false; g_autofree char *tty =3D NULL; =20 if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; =20 if (!(tty =3D virXPathString("string(/domain/devices/console/@tty)", c= txt))) - goto cleanup; + return false; =20 vshPrint(ctl, "%s\n", tty); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -11849,7 +11692,6 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd = *cmd) bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; - bool ret =3D false; =20 VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -11863,18 +11705,15 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCm= d *cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0) - goto cleanup; + return false; =20 if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) { vshError(ctl, _("Failed to detach device with alias %s"), alias); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, "%s", _("Device detach request sent successfully\n"= )); - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -11911,7 +11750,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; - bool ret =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; bool current =3D vshCommandOptBool(cmd, "current"); bool config =3D vshCommandOptBool(cmd, "config"); @@ -11932,7 +11770,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; =20 if (persistent && virDomainIsActive(dom) =3D=3D 1) @@ -11940,7 +11778,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) =20 if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } =20 if (vshCommandOptBool(cmd, "force")) @@ -11948,14 +11786,11 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cm= d) =20 if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) { vshError(ctl, _("Failed to update device from %s"), from); - goto cleanup; + return false; } =20 vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -12179,13 +12014,12 @@ virshFindDisk(const char *doc, g_autoptr(xmlXPathObject) obj =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr cur =3D NULL; - xmlNodePtr ret =3D NULL; size_t i; =20 xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt); if (!xml) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } =20 obj =3D xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); @@ -12194,7 +12028,7 @@ virshFindDisk(const char *doc, obj->nodesetval =3D=3D NULL || obj->nodesetval->nodeNr =3D=3D 0) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } =20 /* search disk using @path */ @@ -12234,10 +12068,10 @@ virshFindDisk(const char *doc, } =20 if (STREQ_NULLABLE(tmp, path)) { - ret =3D xmlCopyNode(obj->nodesetval->nodeTab[i], 1); + xmlNodePtr ret =3D xmlCopyNode(obj->nodesetval->nodeTa= b[i], 1); /* drop backing store since they are not needed here */ virshDiskDropBackingStore(ret); - goto cleanup; + return ret; } } cur =3D cur->next; @@ -12245,9 +12079,7 @@ virshFindDisk(const char *doc, } =20 vshError(NULL, _("No disk found whose source path or target is %s"), p= ath); - - cleanup: - return ret; + return NULL; } =20 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; } =20 /* find the current source subelement */ @@ -12319,7 +12151,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (type =3D=3D VIRSH_UPDATE_DISK_XML_EJECT) { if (!source) { vshError(NULL, _("The disk device '%s' doesn't have media"), t= arget); - goto cleanup; + return NULL; } =20 /* forcibly switch to empty file cdrom */ @@ -12327,7 +12159,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, new_source =3D NULL; } else if (!new_source) { vshError(NULL, _("New disk media source was not specified")); - goto cleanup; + return NULL; } =20 if (source) { @@ -12339,7 +12171,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, =20 if (source_path && type =3D=3D VIRSH_UPDATE_DISK_XML_INSERT) { vshError(NULL, _("The disk device '%s' already has media"), ta= rget); - goto cleanup; + return NULL; } =20 startupPolicy =3D virXMLPropString(source, "startupPolicy"); @@ -12387,10 +12219,9 @@ virshUpdateDiskXML(xmlNodePtr disk_node, =20 if (!(ret =3D virXMLNodeToString(NULL, disk_node))) { vshSaveLibvirtError(); - goto cleanup; + return NULL; } =20 - cleanup: return ret; } =20 @@ -13684,29 +13515,25 @@ static bool cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; unsigned long long minimum =3D 0; const char *mountPoint =3D NULL; unsigned int flags =3D 0; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false; =20 if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) - goto cleanup; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0) - goto cleanup; + return false; =20 if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) { vshError(ctl, _("Unable to invoke fstrim")); - goto cleanup; + return false; } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 static const vshCmdInfo info_domfsfreeze[] =3D { @@ -13914,20 +13741,17 @@ cmdGuestAgentTimeout(vshControl *ctl, const vshCm= d *cmd) g_autoptr(virshDomain) dom =3D NULL; int timeout =3D VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; const unsigned int flags =3D 0; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0) - goto cleanup; + return false; =20 if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0) - goto cleanup; + return false; =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -14047,25 +13871,22 @@ cmdGetUserSSHKeys(vshControl *ctl, const vshCmd *= cmd) int nkeys =3D 0; size_t i; const unsigned int flags =3D 0; - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; =20 nkeys =3D virDomainAuthorizedSSHKeysGet(dom, user, &keys, flags); if (nkeys < 0) - goto cleanup; + return false; =20 for (i =3D 0; i < nkeys; i++) { vshPrint(ctl, "%s", keys[i]); } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 =20 @@ -14115,7 +13936,6 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cm= d) g_auto(GStrv) keys =3D NULL; int nkeys =3D 0; unsigned int flags =3D 0; - bool ret =3D false; =20 VSH_REQUIRE_OPTION("remove", "file"); VSH_EXCLUSIVE_OPTIONS("reset", "remove"); @@ -14124,10 +13944,10 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *= cmd) return false; =20 if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; =20 if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; =20 if (vshCommandOptBool(cmd, "remove")) { flags |=3D VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE; @@ -14137,7 +13957,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cm= d) =20 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; } =20 if (!(keys =3D g_strsplit(buffer, "\n", -1))) - goto cleanup; + return false; =20 nkeys =3D g_strv_length(keys); if (nkeys =3D=3D 0) { vshError(ctl, _("File %s contains no keys"), from); - goto cleanup; + return false; } } =20 if (virDomainAuthorizedSSHKeysSet(dom, user, (const char **) keys, nkeys, flags) = < 0) { - goto cleanup; + return false; } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 =20 @@ -14200,23 +14018,19 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd= *cmd) { g_autoptr(virshDomain) dom =3D NULL; int seconds =3D 1; /* the default value is 1 */ - bool ret =3D false; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0) - goto cleanup; + return false; =20 if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) - goto cleanup; + return false; =20 vshPrintExtra(ctl, _("Start to calculate domain's memory " "dirty rate successfully.\n")); - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 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[] =3D { static bool cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; g_autofree char *caps =3D NULL; const char *virttype =3D NULL; const char *emulatorbin =3D 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; =20 caps =3D virConnectGetDomainCapabilities(priv->conn, emulatorbin, arch, machine, virttype, flags); if (!caps) { vshError(ctl, "%s", _("failed to get emulator capabilities")); - goto cleanup; + return false; } =20 vshPrint(ctl, "%s\n", caps); - ret =3D true; - cleanup: - return ret; + return true; } =20 /* @@ -154,7 +151,6 @@ static const vshCmdOptDef opts_freecell[] =3D { static bool cmdFreecell(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; int cell =3D -1; unsigned long long memory =3D 0; g_autofree xmlNodePtr *nodes =3D NULL; @@ -177,13 +173,13 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (all) { if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } =20 xml =3D virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } =20 nodes_cnt =3D virXPathNodeSet("/capabilities/host/topology/cells/c= ell", @@ -192,7 +188,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt =3D=3D -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } =20 nodes_free =3D g_new0(unsigned long long, nodes_cnt); @@ -203,14 +199,14 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) g_autofree char *val =3D 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] =3D id; if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]), id, 1) !=3D 1) { vshError(ctl, _("failed to get free memory for NUMA node " "number: %lu"), id); - goto cleanup; + return false; } } =20 @@ -225,21 +221,18 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) } else { if (cellno) { if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != =3D 1) - goto cleanup; + return false; =20 vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); } else { if ((memory =3D virNodeGetFreeMemory(priv->conn)) =3D=3D 0) - goto cleanup; + return false; =20 vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); } } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 =20 @@ -476,7 +469,6 @@ static const vshCmdOptDef opts_allocpages[] =3D { static bool cmdAllocpages(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D false; bool add =3D vshCommandOptBool(cmd, "add"); bool all =3D vshCommandOptBool(cmd, "all"); bool cellno =3D vshCommandOptBool(cmd, "cellno"); @@ -511,13 +503,13 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) =20 if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } =20 xml =3D virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } =20 nodes_cnt =3D virXPathNodeSet("/capabilities/host/topology/cells/c= ell", @@ -526,7 +518,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt =3D=3D -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } =20 for (i =3D 0; i < nodes_cnt; i++) { @@ -534,22 +526,20 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) g_autofree char *val =3D virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - goto cleanup; + return false; } =20 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; } =20 - ret =3D true; - cleanup: - return ret; + return true; } =20 =20 @@ -583,7 +573,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; virshControl *priv =3D ctl->privData; - bool ret =3D false; =20 if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; @@ -591,7 +580,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) if ((caps =3D virConnectGetDomainCapabilities(priv->conn, NULL, NULL, = NULL, type, 0))) { if (!(xml =3D virXMLParseStringCtxt(caps, _("(domainCapabilities)"= ), &ctxt))) - goto cleanup; + return false; =20 ignore_value(virXPathInt("string(./vcpu[1]/@max)", ctxt, &vcpus)); } else { @@ -599,13 +588,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) } =20 if (vcpus < 0 && (vcpus =3D virConnectGetMaxVcpus(priv->conn, type)) <= 0) - goto cleanup; + return false; =20 vshPrint(ctl, "%d\n", vcpus); - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -673,13 +659,12 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GN= UC_UNUSED) g_autofree unsigned char *cpumap =3D NULL; unsigned int online; bool pretty =3D vshCommandOptBool(cmd, "pretty"); - bool ret =3D false; virshControl *priv =3D ctl->privData; =20 cpunum =3D virNodeGetCPUMap(priv->conn, &cpumap, &online, 0); if (cpunum < 0) { vshError(ctl, "%s", _("Unable to get cpu map")); - goto cleanup; + return false; } =20 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 =3D virBitmapDataFormat(cpumap, VIR_CPU_MAPLE= N(cpunum)); =20 if (!str) - goto cleanup; + return false; vshPrint(ctl, "%s", str); } else { for (cpu =3D 0; cpu < cpunum; cpu++) @@ -698,10 +683,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNU= C_UNUSED) } vshPrint(ctl, "\n"); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -767,7 +749,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) int cpuNum =3D VIR_NODE_CPU_STATS_ALL_CPUS; g_autofree virNodeCPUStatsPtr params =3D NULL; int nparams =3D 0; - bool ret =3D false; unsigned long long cpu_stats[VIRSH_CPU_LAST] =3D { 0 }; bool present[VIRSH_CPU_LAST] =3D { false }; virshControl *priv =3D ctl->privData; @@ -791,7 +772,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) for (i =3D 0; i < 2; i++) { if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, 0) != =3D 0) { vshError(ctl, "%s", _("Unable to get node cpu stats")); - goto cleanup; + return false; } =20 for (j =3D 0; j < nparams; j++) { @@ -845,10 +826,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) } } =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* @@ -879,7 +857,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) size_t i; int cellNum =3D VIR_NODE_MEMORY_STATS_ALL_CELLS; g_autofree virNodeMemoryStatsPtr params =3D NULL; - bool ret =3D false; virshControl *priv =3D ctl->privData; =20 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) !=3D= 0) { vshError(ctl, "%s", _("Unable to get number of memory stats")); - goto cleanup; + return false; } =20 if (nparams =3D=3D 0) { /* nothing to output */ - ret =3D true; - goto cleanup; + return true; } =20 /* now go get all the memory parameters */ params =3D g_new0(virNodeMemoryStats, nparams); if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, 0) != =3D 0) { vshError(ctl, "%s", _("Unable to get memory stats")); - goto cleanup; + return false; } =20 for (i =3D 0; i < nparams; i++) vshPrint(ctl, "%-7s: %20llu KiB\n", params[i].field, params[i].val= ue); =20 - ret =3D true; - - cleanup: - return ret; + return true; } =20 /* 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 =3D vshStringToArray(value, &arr); if (narr !=3D 2) { vshError(ctl, _("Malformed device value '%s'"), value); - goto cleanup; + return NULL; } =20 if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; + return NULL; =20 dev =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1= ], 0); } else { @@ -135,10 +135,9 @@ vshFindNodeDevice(vshControl *ctl, const char *value) =20 if (!dev) { vshError(ctl, "%s '%s'", _("Could not find matching device"), valu= e); - goto cleanup; + return NULL; } =20 - cleanup: return dev; } =20 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 *ne= wname) =20 doc =3D virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt= ); if (!doc) - goto cleanup; + return NULL; =20 obj =3D xmlXPathEval(BAD_CAST "/volume/name", ctxt); if (obj =3D=3D NULL || obj->nodesetval =3D=3D NULL || obj->nodesetval->nodeTab =3D=3D NULL) - goto cleanup; + return NULL; =20 xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newnam= e); xmlDocDumpMemory(doc, &newxml, &size); =20 - cleanup: return newxml; } =20 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 *cm= d, const char *name, bool report) { size_t i; - const vshCmdOptDef *ret =3D NULL; g_autofree char *alias =3D NULL; =20 if (STREQ(name, helpopt.name)) @@ -457,7 +456,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cm= d, const char *name, if (report) vshError(ctl, _("invalid '=3D' after option --= %s"), opt->name); - goto cleanup; + return NULL; } *optstr =3D g_strdup(value + 1); } @@ -466,12 +465,11 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *= cmd, const char *name, if ((*opts_seen & (1ULL << i)) && opt->type !=3D VSH_OT_ARGV) { if (report) vshError(ctl, _("option --%s already seen"), name); - goto cleanup; + return NULL; } *opts_seen |=3D 1ULL << i; *opt_index =3D i; - ret =3D opt; - goto cleanup; + return opt; } } =20 @@ -479,8 +477,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cm= d, const char *name, vshError(ctl, _("command '%s' doesn't support option --%s"), cmd->name, name); } - cleanup: - return ret; + return NULL; } =20 static const vshCmdOptDef * --=20 2.31.1