From nobody Mon Feb 9 04:45:53 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=1632409731; cv=none; d=zohomail.com; s=zohoarc; b=Voyx/Zc76iYTOx8nJikoIjTEe6C4fcubxlK5ZWk5A4qiu0/BF82Qf8LOBhRfwIeSUwrgid0YEfkS6DmtlmUjTH4/7mbU2NTlbfUkgW9RIMA/5hG+ENitusC5VUvuCB1NmF1fqVwvqnsnfzxRHkHjgcKIW00r/CSfzdN8s4v2YeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632409731; 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=7Sc8K3w9h3UnWXuLkJ4gBq+zyeuzOWMeE5uEwiK0KC4=; b=eCU3S36b+Jx103EdEyMItTJ2JBi7WIaMCFv71EImGNVAjrqf63wUgoxvS+zKDMICmDKwIefPoe0zc/BUyhTyiReuHO/pE9Y1i7RNx/JD2OWT+mmmQkSofXS/syR44QvhUDA2lVemGloOGvX7q1mC4u/gvHEqqhJ8B7KAoPrVRjg= 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 1632409731434927.2723028941981; Thu, 23 Sep 2021 08:08: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-471-e0DjzqucNjmH8FKV4tu3EQ-1; Thu, 23 Sep 2021 11:08: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 6B2851808328; Thu, 23 Sep 2021 15:08:42 +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 1981B5D9DC; Thu, 23 Sep 2021 15:08:42 +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 DA631180BAD2; Thu, 23 Sep 2021 15:08:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NF8O8N030587 for ; Thu, 23 Sep 2021 11:08:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0FCF2171FF; Thu, 23 Sep 2021 15:08:24 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 760017621C for ; Thu, 23 Sep 2021 15:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632409730; 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=7Sc8K3w9h3UnWXuLkJ4gBq+zyeuzOWMeE5uEwiK0KC4=; b=Yo52qO6BPzPDTGfzm3ycW6hcKpbjEhSNptFX51lPgdIKco+PAOtmSuJw+NViTD0ntaFPt7 VAheZR9su5oXIhmR8aW9r01+t9AwnPPxK/O5cwn/R6Gho3E57rciKJu2s8nR8eeuk0jIpV ADmYwHt8aFhoCVFAqra388/S0PBQUaM= X-MC-Unique: e0DjzqucNjmH8FKV4tu3EQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 4/5] virsh: domain, host & volume: refactor bigger functions Date: Thu, 23 Sep 2021 17:08:03 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632409732530100001 Content-Type: text/plain; charset="utf-8" This patch refactors a few bigger functions mainly trying to remove too deep indentation and make them more readable and more consistent with the rest of the file. Signed-off-by: Kristina Hanicova --- tools/virsh-domain.c | 203 ++++++++++++++++++++----------------------- tools/virsh-host.c | 140 ++++++++++++++--------------- tools/virsh-volume.c | 56 ++++++------ 3 files changed, 190 insertions(+), 209 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ec427443c4..2881956d78 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5133,7 +5133,6 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) int nparams =3D 0; int nupdates =3D 0; size_t i; - int ret; bool ret_val =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; bool current =3D vshCommandOptBool(cmd, "current"); @@ -5161,64 +5160,61 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (nparams) { - params =3D g_new0(virTypedParameter, nparams); + if (!nparams) + goto cleanup; =20 - memset(params, 0, sizeof(*params) * nparams); - if (flags || current) { - /* We cannot query both live and config at once, so settle - on current in that case. If we are setting, then the - two values should match when we re-query; otherwise, we - report the error later. */ - ret =3D virDomainGetSchedulerParametersFlags(dom, params, &npa= rams, - ((live && config) ?= 0 - : flags)); - } else { - ret =3D virDomainGetSchedulerParameters(dom, params, &nparams); - } - if (ret =3D=3D -1) + params =3D g_new0(virTypedParameter, nparams); + memset(params, 0, sizeof(*params) * nparams); + + if (flags || current) { + /* We cannot query both live and config at once, so settle + on current in that case. If we are setting, then the + two values should match when we re-query; otherwise, we + report the error later. */ + if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, + ((live && config) ? 0 : f= lags)) =3D=3D -1) goto cleanup; - - /* See if any params are being set */ - if ((nupdates =3D cmdSchedInfoUpdate(ctl, cmd, params, nparams, - &updates)) < 0) + } else { + if (virDomainGetSchedulerParameters(dom, params, &nparams) =3D=3D = -1) goto cleanup; + } =20 - /* Update parameters & refresh data */ - if (nupdates > 0) { - if (flags || current) - ret =3D virDomainSetSchedulerParametersFlags(dom, updates, - nupdates, flags= ); - else - ret =3D virDomainSetSchedulerParameters(dom, updates, nupd= ates); + /* See if any params are being set */ + if ((nupdates =3D cmdSchedInfoUpdate(ctl, cmd, params, nparams, + &updates)) < 0) + goto cleanup; =20 - if (ret =3D=3D -1) + /* Update parameters & refresh data */ + if (nupdates > 0) { + if (flags || current) { + if (virDomainSetSchedulerParametersFlags(dom, updates, + nupdates, flags) =3D= =3D -1) goto cleanup; =20 - if (flags || current) - ret =3D virDomainGetSchedulerParametersFlags(dom, params, - &nparams, - ((live && confi= g) ? 0 - : flags)); - else - ret =3D virDomainGetSchedulerParameters(dom, params, &npar= ams); - if (ret =3D=3D -1) + if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, + ((live && config) ? 0= : flags)) =3D=3D -1) goto cleanup; } else { - /* When not doing --set, --live and --config do not mix. */ - if (live && config) { - vshError(ctl, "%s", - _("cannot query both live and config at once")); + if (virDomainSetSchedulerParameters(dom, updates, nupdates) = =3D=3D -1) goto cleanup; - } - } =20 - ret_val =3D true; - for (i =3D 0; i < nparams; i++) { - char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); - vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); + if (virDomainGetSchedulerParameters(dom, params, &nparams) =3D= =3D -1) + goto cleanup; } + } else { + /* When not doing --set, --live and --config do not mix. */ + if (live && config) { + vshError(ctl, "%s", + _("cannot query both live and config at once")); + goto cleanup; + } + } + + ret_val =3D true; + for (i =3D 0; i < nparams; i++) { + char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "%-15s: %s\n", params[i].field, str); + VIR_FREE(str); } =20 cleanup: @@ -6503,7 +6499,6 @@ virshCPUCountCollect(vshControl *ctl, unsigned int flags, bool checkState) { - int ret =3D -2; virDomainInfo info; int count; g_autoptr(xmlDoc) xml =3D NULL; @@ -6524,11 +6519,11 @@ virshCPUCountCollect(vshControl *ctl, /* fallback code */ if (!(last_error->code =3D=3D VIR_ERR_NO_SUPPORT || last_error->code =3D=3D VIR_ERR_INVALID_ARG)) - goto cleanup; + return -2; =20 if (flags & VIR_DOMAIN_VCPU_GUEST) { vshError(ctl, "%s", _("Failed to retrieve vCPU count from the gues= t")); - goto cleanup; + return -2; } =20 if (!(flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) && @@ -6538,36 +6533,32 @@ virshCPUCountCollect(vshControl *ctl, vshResetLibvirtError(); =20 if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { - count =3D virDomainGetMaxVcpus(dom); - } else { - if (virDomainGetInfo(dom, &info) < 0) - goto cleanup; + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) + return virDomainGetMaxVcpus(dom); =20 - count =3D info.nrVirtCpu; + if (virDomainGetInfo(dom, &info) < 0) + return -2; + + return info.nrVirtCpu; + } + + if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, + &xml, &ctxt) < 0) + return -2; + + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { + if (virXPathInt("string(/domain/vcpu)", ctxt, &count) < 0) { + vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count")= ); + return -2; } } else { - if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, - &xml, &ctxt) < 0) - goto cleanup; - - if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { - if (virXPathInt("string(/domain/vcpu)", ctxt, &count) < 0) { - vshError(ctl, "%s", _("Failed to retrieve maximum vcpu cou= nt")); - goto cleanup; - } - } else { - if (virXPathInt("string(/domain/vcpu/@current)", ctxt, &count)= < 0) { - vshError(ctl, "%s", _("Failed to retrieve current vcpu cou= nt")); - goto cleanup; - } + if (virXPathInt("string(/domain/vcpu/@current)", ctxt, &count) < 0= ) { + vshError(ctl, "%s", _("Failed to retrieve current vcpu count")= ); + return -2; } } =20 - ret =3D count; - cleanup: - - return ret; + return count; } =20 static bool @@ -9588,7 +9579,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cm= d) vshEventCleanup(ctl); if (eventId >=3D 0 && virConnectDomainQemuMonitorEventDeregister(priv->conn, eventId) < = 0) - ret =3D false; + return false; =20 return ret; } @@ -9790,6 +9781,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *c= md) int nfdlist; int *fdlist; size_t i; + int status; bool setlabel =3D true; g_autofree virSecurityModelPtr secmodel =3D NULL; g_autofree virSecurityLabelPtr seclabel =3D NULL; @@ -9828,40 +9820,8 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *= cmd) */ if ((pid =3D virFork()) < 0) return false; - if (pid =3D=3D 0) { - int status; - - if (setlabel && - virDomainLxcEnterSecurityLabel(secmodel, - seclabel, - NULL, - 0) < 0) - _exit(EXIT_CANCELED); - - if (virDomainLxcEnterCGroup(dom, 0) < 0) - _exit(EXIT_CANCELED); - - if (virDomainLxcEnterNamespace(dom, - nfdlist, - fdlist, - NULL, - NULL, - 0) < 0) - _exit(EXIT_CANCELED); - - /* Fork a second time because entering the - * pid namespace only takes effect after fork - */ - if ((pid =3D virFork()) < 0) - _exit(EXIT_CANCELED); - if (pid =3D=3D 0) { - execv(cmdargv[0], cmdargv); - _exit(errno =3D=3D ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); - } - if (virProcessWait(pid, &status, true) < 0) - _exit(EXIT_CANNOT_INVOKE); - virProcessExitWithStatus(status); - } else { + + if (pid !=3D 0) { for (i =3D 0; i < nfdlist; i++) VIR_FORCE_CLOSE(fdlist[i]); VIR_FREE(fdlist); @@ -9869,8 +9829,33 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *= cmd) vshReportError(ctl); return false; } + return true; + } + + if (setlabel && + virDomainLxcEnterSecurityLabel(secmodel, seclabel, NULL, 0) < 0) + _exit(EXIT_CANCELED); + + if (virDomainLxcEnterCGroup(dom, 0) < 0) + _exit(EXIT_CANCELED); + + if (virDomainLxcEnterNamespace(dom, nfdlist, fdlist, NULL, NULL, 0) < = 0) + _exit(EXIT_CANCELED); + + /* Fork a second time because entering the + * pid namespace only takes effect after fork + */ + if ((pid =3D virFork()) < 0) + _exit(EXIT_CANCELED); + + if (pid =3D=3D 0) { + execv(cmdargv[0], cmdargv); + _exit(errno =3D=3D ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); } =20 + if (virProcessWait(pid, &status, true) < 0) + _exit(EXIT_CANNOT_INVOKE); + virProcessExitWithStatus(status); return true; } =20 diff --git a/tools/virsh-host.c b/tools/virsh-host.c index e6ed4a26ce..591746655b 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -162,7 +162,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) bool cellno =3D vshCommandOptBool(cmd, "cellno"); size_t i; g_autofree char *cap_xml =3D NULL; - g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; virshControl *priv =3D ctl->privData; =20 @@ -171,68 +170,69 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) return false; =20 - if (all) { - if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) { - vshError(ctl, "%s", _("unable to get node capabilities")); - return false; - } + if (!all) { + if (cellno) { + if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != =3D 1) + return false; =20 - xml =3D virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); - if (!xml) { - vshError(ctl, "%s", _("unable to get node capabilities")); - return false; + vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); + return true; } =20 - nodes_cnt =3D virXPathNodeSet("/capabilities/host/topology/cells/c= ell", - ctxt, &nodes); - - if (nodes_cnt =3D=3D -1) { - vshError(ctl, "%s", _("could not get information about " - "NUMA topology")); + if ((memory =3D virNodeGetFreeMemory(priv->conn)) =3D=3D 0) return false; - } =20 - nodes_free =3D g_new0(unsigned long long, nodes_cnt); - nodes_id =3D g_new0(unsigned long, nodes_cnt); + vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); + return true; + } =20 - for (i =3D 0; i < nodes_cnt; i++) { - unsigned long id; - g_autofree char *val =3D virXMLPropString(nodes[i], "id"); - if (virStrToLong_ulp(val, NULL, 10, &id)) { - vshError(ctl, "%s", _("conversion from string failed")); - 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); - return false; - } - } + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) { + vshError(ctl, "%s", _("unable to get node capabilities")); + return false; + } =20 - for (cell =3D 0; cell < nodes_cnt; cell++) { - vshPrint(ctl, "%5lu: %10llu KiB\n", nodes_id[cell], - (nodes_free[cell]/1024)); - memory +=3D nodes_free[cell]; - } + if (!virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt)) { + vshError(ctl, "%s", _("unable to get node capabilities")); + return false; + } =20 - vshPrintExtra(ctl, "--------------------\n"); - vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024); - } else { - if (cellno) { - if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != =3D 1) - return false; + nodes_cnt =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", + ctxt, &nodes); =20 - vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); - } else { - if ((memory =3D virNodeGetFreeMemory(priv->conn)) =3D=3D 0) - return false; + if (nodes_cnt =3D=3D -1) { + vshError(ctl, "%s", _("could not get information about " + "NUMA topology")); + return false; + } + + nodes_free =3D g_new0(unsigned long long, nodes_cnt); + nodes_id =3D g_new0(unsigned long, nodes_cnt); =20 - vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); + for (i =3D 0; i < nodes_cnt; i++) { + unsigned long id; + g_autofree char *val =3D virXMLPropString(nodes[i], "id"); + if (virStrToLong_ulp(val, NULL, 10, &id)) { + vshError(ctl, "%s", _("conversion from string failed")); + 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); + return false; } } =20 + for (cell =3D 0; cell < nodes_cnt; cell++) { + vshPrint(ctl, "%5lu: %10llu KiB\n", nodes_id[cell], + (nodes_free[cell]/1024)); + memory +=3D nodes_free[cell]; + } + + vshPrintExtra(ctl, "--------------------\n"); + vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024); + return true; } =20 @@ -804,30 +804,30 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) cpu_stats[i]); } } + return true; + } + + if (present[VIRSH_CPU_USAGE]) { + vshPrint(ctl, "%-15s %5.1llu%%\n", + _("usage:"), cpu_stats[VIRSH_CPU_USAGE]); + vshPrint(ctl, "%-15s %5.1llu%%\n", + _("idle:"), 100 - cpu_stats[VIRSH_CPU_USAGE]); } else { - if (present[VIRSH_CPU_USAGE]) { - vshPrint(ctl, "%-15s %5.1llu%%\n", - _("usage:"), cpu_stats[VIRSH_CPU_USAGE]); - vshPrint(ctl, "%-15s %5.1llu%%\n", - _("idle:"), 100 - cpu_stats[VIRSH_CPU_USAGE]); - } else { - double usage, total_time =3D 0; - for (i =3D 0; i < VIRSH_CPU_USAGE; i++) - total_time +=3D cpu_stats[i]; - - usage =3D (cpu_stats[VIRSH_CPU_USER] + cpu_stats[VIRSH_CPU_SYS= TEM]) - / total_time * 100; - - vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage); - for (i =3D 0; i < VIRSH_CPU_USAGE; i++) { - if (present[i]) { - vshPrint(ctl, "%-15s %5.1lf%%\n", _(virshCPUOutput[i]), - cpu_stats[i] / total_time * 100); - } + double usage, total_time =3D 0; + for (i =3D 0; i < VIRSH_CPU_USAGE; i++) + total_time +=3D cpu_stats[i]; + + usage =3D (cpu_stats[VIRSH_CPU_USER] + cpu_stats[VIRSH_CPU_SYSTEM]) + / total_time * 100; + + vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage); + for (i =3D 0; i < VIRSH_CPU_USAGE; i++) { + if (present[i]) { + vshPrint(ctl, "%-15s %5.1lf%%\n", _(virshCPUOutput[i]), + cpu_stats[i] / total_time * 100); } } } - return true; } =20 diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 152f5b0dbe..ef437413df 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -1057,7 +1057,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) virStorageVolPtr vol; bool bytes =3D vshCommandOptBool(cmd, "bytes"); bool physical =3D vshCommandOptBool(cmd, "physical"); - bool ret =3D true; int rc; unsigned int flags =3D 0; =20 @@ -1074,41 +1073,39 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) else rc =3D virStorageVolGetInfo(vol, &info); =20 - if (rc =3D=3D 0) { - double val; - const char *unit; + if (rc < 0) { + virStorageVolFree(vol); + return false; + } =20 - vshPrint(ctl, "%-15s %s\n", _("Type:"), - virshVolumeTypeToString(info.type)); + vshPrint(ctl, "%-15s %s\n", _("Type:"), + virshVolumeTypeToString(info.type)); =20 - if (bytes) { - vshPrint(ctl, "%-15s %llu %s\n", _("Capacity:"), - info.capacity, _("bytes")); - } else { - val =3D vshPrettyCapacity(info.capacity, &unit); - vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit); - } + if (bytes) { + vshPrint(ctl, "%-15s %llu %s\n", _("Capacity:"), + info.capacity, _("bytes")); =20 - if (bytes) { - if (physical) - vshPrint(ctl, "%-15s %llu %s\n", _("Physical:"), - info.allocation, _("bytes")); - else - vshPrint(ctl, "%-15s %llu %s\n", _("Allocation:"), - info.allocation, _("bytes")); - } else { - val =3D vshPrettyCapacity(info.allocation, &unit); - if (physical) - vshPrint(ctl, "%-15s %2.2lf %s\n", _("Physical:"), val, un= it); - else - vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, = unit); - } + if (physical) + vshPrint(ctl, "%-15s %llu %s\n", _("Physical:"), + info.allocation, _("bytes")); + else + vshPrint(ctl, "%-15s %llu %s\n", _("Allocation:"), + info.allocation, _("bytes")); } else { - ret =3D false; + const char *unit; + double val =3D vshPrettyCapacity(info.capacity, &unit); + + vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit); + + val =3D vshPrettyCapacity(info.allocation, &unit); + if (physical) + vshPrint(ctl, "%-15s %2.2lf %s\n", _("Physical:"), val, unit); + else + vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit= ); } =20 virStorageVolFree(vol); - return ret; + return true; } =20 /* @@ -1203,7 +1200,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) delta ? _("Failed to change size of volume '%s' by %s") : _("Failed to change size of volume '%s' to %s"), virStorageVolGetName(vol), capacityStr); - ret =3D false; } =20 cleanup: --=20 2.31.1