From nobody Mon Feb 9 17:21:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1632439552; cv=none; d=zohomail.com; s=zohoarc; b=NBOqTFoDCQ2560rV+S2vsUOI3Qu8xXMFFLpRd0Id/fsnmyI816uQzxYel4f7pjbUm/ptqq9hhENRS2DKJ/Ag/wPme3RWFvWnZ0gPvQVPDr8iuT6DMB6AaX9ItNk0VRBXVrzIyK/YkkqC0/4TtwQvupPqzt9yXDZgo+Lk+LHK5s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439552; 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=lXV5hrdmUgSKCyPdpp27v4OvkgCyaohOSd1BuYwCG38=; b=cHB7MlMNnbeGjdjtS1/4YIfr3yid5o/qCSmaUSVWgWda9U2nSBLbjtmP4v4MobsS19GeiOf0ntJF83Nioyhv2r6Jb/dH5fotCBHECu8JPe96LSPh/OfvLkNWtxVqDB9mo4qy7LKErkK39sibJRHMNiTwbaMASPtS9sZWdI8MWa8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632439552518292.66718940837825; Thu, 23 Sep 2021 16:25:52 -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-156-YQCAf-QAPQagBeeeGIhBSg-1; Thu, 23 Sep 2021 19:25:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5ACF48042C3; Thu, 23 Sep 2021 23:25:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 105655C1A1; Thu, 23 Sep 2021 23:25:45 +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 B4D524EA29; Thu, 23 Sep 2021 23:25:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPOoO010301 for ; Thu, 23 Sep 2021 19:25:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F6F619733; Thu, 23 Sep 2021 23:25:24 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9478D19730 for ; Thu, 23 Sep 2021 23:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439551; 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=lXV5hrdmUgSKCyPdpp27v4OvkgCyaohOSd1BuYwCG38=; b=bg7du5tVuk0UJ2QbzR2CFihzj4pG271zUwAALeuorjCWXfUlF2vBOZ9+qvHSg2t/A/9psE 1CDU1VPMK3sIX3Yq+WRh4UZLL/P6liZKRH8fsBWYmBhMbIsV0vW6RM548OKIpBea7xF7v5 pEswueCjy3gJuvJNJeTlXNNUrJsHqZg= X-MC-Unique: YQCAf-QAPQagBeeeGIhBSg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 1/6] virsh: domain: refactor cmdSchedinfo() Date: Fri, 24 Sep 2021 01:25:07 +0200 Message-Id: <11567d78c8238b905bd241a71c0c50e21a2d53f1.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.16 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: 1632440455788100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 99 +++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f876f30cc5..b64df640ba 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5157,7 +5157,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"); @@ -5176,73 +5175,69 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) return false; =20 /* Print SchedulerType */ - schedulertype =3D virDomainGetSchedulerType(dom, &nparams); - if (schedulertype !=3D NULL) { - vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), schedulertype); - VIR_FREE(schedulertype); - } else { + if (!(schedulertype =3D virDomainGetSchedulerType(dom, &nparams))) { vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), _("Unknown")); goto cleanup; } =20 - if (nparams) { - params =3D g_new0(virTypedParameter, nparams); + vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), schedulertype); + VIR_FREE(schedulertype); =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) - goto cleanup; + if (!nparams) + goto cleanup; =20 - /* See if any params are being set */ - if ((nupdates =3D cmdSchedInfoUpdate(ctl, cmd, params, nparams, - &updates)) < 0) + 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; + } 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: --=20 2.31.1 From nobody Mon Feb 9 17:21:40 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=1632439538; cv=none; d=zohomail.com; s=zohoarc; b=hq37UewsEraz+QiaEMq9tSEPkCnuK5qSlHIqaewRh7peztb/L7RYZ2pulE8w5GPl+5oE8qpm+QSIAjNS4Al3h4kmth8TWmCA3uvR+hbFVrCRNDgp0ykAuq5RQgDg1A4wYwQBdUituRI6qtET0gvUK6hc6o9QC/0cy6xjvDvzImk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439538; 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=4eibmKz9CXHdA8irrhapU1IUAt58+Xt10q7OlaEXdeM=; b=UxxLSo/5U4joHav0LoVWZNj86zn5dm3iaxHiXSCAMMLXobk0SvfqJQwTlalVQNddHSgFEAKaPzmZugUZtLkVMnQHmh/UAE8jnYxdA/7VGPPlApcTpP27E4lSBcjcLfl4M+SG0FPsvu+MzAX69HD4VvKnpAaVNi/NlLz83MwEgjs= 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 163243953830685.15315289925638; Thu, 23 Sep 2021 16:25:38 -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-81-6lVltV9DMfOf4hTiF1Vapg-1; Thu, 23 Sep 2021 19:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60000362F8; Thu, 23 Sep 2021 23:25:30 +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 D65D919733; Thu, 23 Sep 2021 23:25:29 +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 B9DEC180598A; Thu, 23 Sep 2021 23:25:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPPtn010309 for ; Thu, 23 Sep 2021 19:25:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED49F19736; Thu, 23 Sep 2021 23:25:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2407E19730 for ; Thu, 23 Sep 2021 23:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439537; 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=4eibmKz9CXHdA8irrhapU1IUAt58+Xt10q7OlaEXdeM=; b=M/CtuKTwDTeJYBSER4dgCdmQ6u+P3exqPoeRkVzPoB7MoiAyokqVXDDwQS2vzwXKl9BD4R R8qUAE1j2SRCGG4D4AlUESnN70xc5zaW+ZBMfp+WYAsd0FKWFnEWxgLQAb191Cb2hO/Y2j yiQ4WfIXWArdsHzRNi5wMEJIiMq1LBo= X-MC-Unique: 6lVltV9DMfOf4hTiF1Vapg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 2/6] virsh: domain: refactor virshCPUCountCollect() Date: Fri, 24 Sep 2021 01:25:08 +0200 Message-Id: <6bd078a0254de89e694d176b37470f311ec8c547.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.84 on 10.5.11.23 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: 1632439538956100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 49 ++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b64df640ba..3dc5fb046e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6533,7 +6533,6 @@ virshCPUCountCollect(vshControl *ctl, unsigned int flags, bool checkState) { - int ret =3D -2; virDomainInfo info; int count; g_autoptr(xmlDoc) xml =3D NULL; @@ -6554,11 +6553,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)) && @@ -6568,36 +6567,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 --=20 2.31.1 From nobody Mon Feb 9 17:21:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1632439537; cv=none; d=zohomail.com; s=zohoarc; b=KSF6AvfVjmBsHnLVv1+LHZzk+d/qHUkCON0RqXAWiP0Kvk1TN0OqXrrIF6W+NTNjWYL2jpDU8RtSq/MfcwLxmUyIbDaQs4t1ltabdscIGSuEYRI4erEQ01CeG+w4F/J++Yri+2r1qPnfunMwXrB7AuM7xi0TxKZ/xGswvbqcAk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439537; 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=kaNgTpcGB8n2Q/RApCFKe9vuWN+SEL71dOra7C+Li3c=; b=J5QOfBnOkr6zkxswvLddt8x5EdixXj3MqrEzTebMCZe3lhk1/l8+83b6L8elTAOSoMR3z+gHVRCqt7R9Q1098hLvAvZ+wK5bVzWc6l3IUqr/06wUw171a6IW37gGHrZ5UjAIyVy9UBkaPUhmvTzqez9+MM/ud467a/DGnCCGQ3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632439537900626.5430175303759; Thu, 23 Sep 2021 16:25:37 -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-30-tvu1nS1XOleNzUN0DZKb0Q-1; Thu, 23 Sep 2021 19:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C9DD1006AA5; Thu, 23 Sep 2021 23:25:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 535B77621B; Thu, 23 Sep 2021 23:25:30 +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 EF7D04E58F; Thu, 23 Sep 2021 23:25:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPRIl010319 for ; Thu, 23 Sep 2021 19:25:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A3A319733; Thu, 23 Sep 2021 23:25:27 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73F9019730 for ; Thu, 23 Sep 2021 23:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439536; 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=kaNgTpcGB8n2Q/RApCFKe9vuWN+SEL71dOra7C+Li3c=; b=FHxXc7L9/32nudj9B9vgii30btkaqUCh55Nun6M/Y/S0hZ8lu7zCzatJcNMkJq05FvlFwW Ks8NSph788vMS/pARIGPB7rAs//cMbtwN7wZBNbB4/B6zi3ZyMAJMPmOK5nP4IyYF9eTOm DerpfrG5hfjvaB9+gzKf6iNH3SIjFRY= X-MC-Unique: tvu1nS1XOleNzUN0DZKb0Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 3/6] virsh: domain: refactor cmdLxcEnterNamespace() Date: Fri, 24 Sep 2021 01:25:09 +0200 Message-Id: <0485648899eb86b1242582c59877b29fda7a11cf.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.16 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: 1632439538946100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 62 ++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3dc5fb046e..6f2249ddde 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9858,6 +9858,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; @@ -9896,40 +9897,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); @@ -9937,8 +9906,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 --=20 2.31.1 From nobody Mon Feb 9 17:21:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1632439552; cv=none; d=zohomail.com; s=zohoarc; b=OXHcqoAxgsS9uodlx2r+5B5PEzvydfVcnJy7/ZTpdK/zRQymu+dGPj/XUAA/ywr20uruItS2wNfKskzsr3EUZJdOapk+l8RN+KBtQf7C4fuBfYaYT4Mrzh38IiLvwPSozUBTRTfEzItAshSwcAqHFAxJmxAbBnDp0NwM/s87W5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439552; 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=L8BHH34jD9t9gFUUGxOm9hqCNgou/J4x8e1JZZ+JVf8=; b=fd1ozsSQwgrLDJagkOXhrB9qn9b9hYSxKUKywof/f0BDtMpqExMP0jDJOs13+rZ9wSOqG1csKvTTHyQI8K5QS3QNAv49/DjKMe288q6NlAaCVMwqiazIkasT87Ci3bDED/Hjx+eDkH3Vr1IVm71qRX/FaNt0y5TAh4517uwNHBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632439552797414.9570893650234; Thu, 23 Sep 2021 16:25:52 -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-314-B0yFPeLtM-SnSzjo5R-Spg-1; Thu, 23 Sep 2021 19:25:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6546F1808305; Thu, 23 Sep 2021 23:25:45 +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 207DE1981C; Thu, 23 Sep 2021 23:25:45 +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 C4939180BAD2; Thu, 23 Sep 2021 23:25:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPSeM010329 for ; Thu, 23 Sep 2021 19:25:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8A6FB19733; Thu, 23 Sep 2021 23:25:28 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9330019730 for ; Thu, 23 Sep 2021 23:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439551; 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=L8BHH34jD9t9gFUUGxOm9hqCNgou/J4x8e1JZZ+JVf8=; b=a1nXfM3f/Yx3j0Hzwt889hi3rd4hZ7tOB5Kmc9ejyLmyLCBy/wAtA4xezItgT9BttdALII 0hwjkf0SEgxAwefZVAh60/IR5HfWEaJl9YHlMR78HlzPkgLix+klBtkF8gF5m4mghYbxvc AJSshk8VoUWhpOLDZWgNR38+QeP3P3w= X-MC-Unique: B0yFPeLtM-SnSzjo5R-Spg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 4/6] virsh: host: refactor cmdFreecell() Date: Fri, 24 Sep 2021 01:25:10 +0200 Message-Id: <55bc0347b71ad9ce7992a845eec92da20052ee88.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.11 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: 1632439553791100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-host.c | 99 +++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index e6ed4a26ce..be9cbc2096 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,68 @@ 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 topolo= gy")); + 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 --=20 2.31.1 From nobody Mon Feb 9 17:21:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1632439558; cv=none; d=zohomail.com; s=zohoarc; b=LEbmkCyent9Rtm/u0HNDUbSMhfyGHE8pmRZRjZezblU8x/hANwMbvOUhwtf1NtLK24tyBoNZpIFN0UbJuKy6Hnh10otQkWBu5p+np6CKZxOFp0PVzEBNGIupdKEb3gCfoO/i5tdr8Uo8dh3RIIzCV588u4NEo5PT9ncGDzPrsBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439558; 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=TSRw5CP2Of3MmT7CUDVs+0dnkVvIL1chRFmZrfU8y+s=; b=l63CXnlumYUD06mVQfw+PD2KMaKK/4aXB4HC4QSijN0ZQkk5BwgTd/17lONfr9Xg2iEmqgSzaZiTGhAoJ6ut3yDJB9WRJXjwmTeYkAJpoh4U4ZB1Ax+Vkas2QOY1kB9TlmXCFCB4747E02yLgG91zJErR/rtA+YnGrnYCBnU/b0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632439558358829.1311796737043; Thu, 23 Sep 2021 16:25:58 -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-566-UlnsJC4LOUeVFeHCwb0Dng-1; Thu, 23 Sep 2021 19:25:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5A8B1084688; Thu, 23 Sep 2021 23:25:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C88F460BE5; Thu, 23 Sep 2021 23:25:47 +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 9C2D74EA37; Thu, 23 Sep 2021 23:25:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPTxN010341 for ; Thu, 23 Sep 2021 19:25:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id EEA2919736; Thu, 23 Sep 2021 23:25:29 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2176919730 for ; Thu, 23 Sep 2021 23:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439557; 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=TSRw5CP2Of3MmT7CUDVs+0dnkVvIL1chRFmZrfU8y+s=; b=HFBuumR1xszyTb4r5i3TkM0JFnB4XMU46/fnIgq7QFqKGgAYlNRpjm6HMLPoshN6FJ60DB fR23Z4ks/xeAfqn6vaGM8fMVA3lpxvSlz+4f07mmbUse6Aq1fKLY/XPxRjyhfiYmRQWqiX 9hu9HFBtLAecxGWiwkz3Antkx0w8Cs0= X-MC-Unique: UlnsJC4LOUeVFeHCwb0Dng-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 5/6] virsh: host: refactor cmdNodeCpuStats() Date: Fri, 24 Sep 2021 01:25:11 +0200 Message-Id: <5221e426ad6e9a9a3347a1b5dba3d4e0ffb68ca5.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.12 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: 1632439559970100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-host.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index be9cbc2096..bcd44cefe1 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -803,30 +803,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 --=20 2.31.1 From nobody Mon Feb 9 17:21:40 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=1632439556; cv=none; d=zohomail.com; s=zohoarc; b=Psp62kCj9d2fo2CTFd1MznQZgr5rAlZhl/3tnjkDvxhZeJKS4gyJnlCm85myahNY7g+33EJqIhhG0PSnpfTHlDwR3IsSPgisalsv0sAUBFOQTI7gdKQJ7NvbqWjbdUlYLySkYIV77meHeyP9qEOCdiayyo1S9fNNetCEG5ur0RE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632439556; 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=PboRz9Un0s5rWbmuv9vC7TLQHzfkQplYnYnWifVLAxw=; b=lI2VjavOkwl+Z099HfozonJ9BlkvxtJlsD9kRsBElFz7vInocNr9y2IdJv2latmdXkaSgK1J6lmJFRWDFZK1SCbusinmEDrLJQJIdEVcoDrUCKqa7gDzkSHqO6pARtqq/hufYuBMLDiCg8cqsqdlN0TD+7lbu7gslJfGnm/Hp9Q= 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 163243955581892.73265444431354; Thu, 23 Sep 2021 16:25:55 -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-569-g8F_JPnaPLywFXUvyy1GBA-1; Thu, 23 Sep 2021 19:25:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF08E362FC; Thu, 23 Sep 2021 23:25:47 +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 D506660936; Thu, 23 Sep 2021 23:25:47 +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 A8473181A1CF; Thu, 23 Sep 2021 23:25:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NNPVkA010352 for ; Thu, 23 Sep 2021 19:25:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9736419733; Thu, 23 Sep 2021 23:25:31 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ECF819730 for ; Thu, 23 Sep 2021 23:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632439554; 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=PboRz9Un0s5rWbmuv9vC7TLQHzfkQplYnYnWifVLAxw=; b=f1wT69ypMQgvV3q616Y5WDcAIsECNK236gLW4JGcezHzsXBE8jc5UPEv7Lg9XcCryEFKc9 Bmbl/uWLoYx26fQSlRZffthh3l4XYn/5Nj0RWatQNI5dOauTogN2cWBlRWszOV3cLap4xv OMWpabgrtO6GzYQky/IZHIoEIf6YwhY= X-MC-Unique: g8F_JPnaPLywFXUvyy1GBA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 6/6] virsh: volume: refactor cmdVolInfo() Date: Fri, 24 Sep 2021 01:25:12 +0200 Message-Id: <515ff2baa062237785b3dcce391dbcca5b31b7d1.1632439268.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.13 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: 1632439557888100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- tools/virsh-volume.c | 52 ++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 152f5b0dbe..38bb62a48f 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,36 @@ 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.allocati= on, _("bytes")); + else + vshPrint(ctl, "%-15s %llu %s\n", _("Allocation:"), info.alloca= tion, _("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 /* --=20 2.31.1