From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860457719165.2469441010113; Wed, 6 Mar 2019 00:20:57 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E401E3082A4C; Wed, 6 Mar 2019 08:20:55 +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 5D6DF5D782; Wed, 6 Mar 2019 08:20:55 +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 8626E1819AFB; Wed, 6 Mar 2019 08:20:53 +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 x268Kqpn032432 for ; Wed, 6 Mar 2019 03:20:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BCC951A91A; Wed, 6 Mar 2019 08:20:52 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40BE11A267 for ; Wed, 6 Mar 2019 08:20:52 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:26 +0100 Message-Id: <40e98095ac1b4f50b31ea60f6bae2a982479718a.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 01/23] util: xml: Enforce return value check from virXMLFormatElement 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 06 Mar 2019 08:20:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function does not transfer errors from 'attrBuf' and 'childBuf' arguments into 'buf', but rather reports them right away, thus we need to make sure that it's always checked.t Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virxml.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/virxml.h b/src/util/virxml.h index 78a1e7fa5e..b91fedde82 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -217,7 +217,8 @@ int virXMLFormatElement(virBufferPtr buf, const char *name, virBufferPtr attrBuf, - virBufferPtr childBuf); + virBufferPtr childBuf) + ATTRIBUTE_RETURN_CHECK; struct _virXPathContextNodeSave { xmlXPathContextPtr ctxt; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860467167131.4523963968851; Wed, 6 Mar 2019 00:21:07 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id EEBFE308FED5; Wed, 6 Mar 2019 08:21:04 +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 C26195D9D4; Wed, 6 Mar 2019 08:21:04 +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 63353131F7; Wed, 6 Mar 2019 08:21:04 +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 x268Kr9F032440 for ; Wed, 6 Mar 2019 03:20:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 952DA1A267; Wed, 6 Mar 2019 08:20:53 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 192A0277D0 for ; Wed, 6 Mar 2019 08:20:52 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:27 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 02/23] conf: Use virXMLFormatElement in virDomainControllerDriverFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 06 Mar 2019 08:21:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Refactor adding of the controller element. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d84cc2d482..e7c71bb43d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24255,7 +24255,7 @@ virDomainDiskDefFormat(virBufferPtr buf, } -static void +static int virDomainControllerDriverFormat(virBufferPtr buf, virDomainControllerDefPtr def) { @@ -24280,11 +24280,7 @@ virDomainControllerDriverFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferError(&driverBuf) !=3D 0 || virBufferUse(&driverBuf)) { - virBufferAddLit(buf, "\n"); - } + return virXMLFormatElement(buf, "driver", &driverBuf, NULL); } @@ -24417,7 +24413,8 @@ virDomainControllerDefFormat(virBufferPtr buf, } } - virDomainControllerDriverFormat(&childBuf, def); + if (virDomainControllerDriverFormat(&childBuf, def) < 0) + goto cleanup; if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860470469435.4395911411748; Wed, 6 Mar 2019 00:21:10 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A44A8309264B; Wed, 6 Mar 2019 08:21:08 +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 73D264D4; Wed, 6 Mar 2019 08:21:08 +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 0F08D3FB13; Wed, 6 Mar 2019 08:21:08 +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 x268KsrN032452 for ; Wed, 6 Mar 2019 03:20:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6E7A71A91A; Wed, 6 Mar 2019 08:20:54 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E62881A267 for ; Wed, 6 Mar 2019 08:20:53 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:28 +0100 Message-Id: <9222e474e5776f3b79f36d60511287f76d6f66ef.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 03/23] conf: Use virXMLFormatElement in virDomainControllerDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 06 Mar 2019 08:21:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Refactor the function to use the XML formatting aid and use automatic cleaning to simplify the control flow. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 44 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e7c71bb43d..cbefa7749b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24292,15 +24292,15 @@ virDomainControllerDefFormat(virBufferPtr buf, const char *type =3D virDomainControllerTypeToString(def->type); const char *model =3D NULL; const char *modelName =3D NULL; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; virBufferSetChildIndent(&childBuf, buf); if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected controller type %d"), def->type); - goto cleanup; + return -1; } if (def->model !=3D -1) { @@ -24309,32 +24309,32 @@ virDomainControllerDefFormat(virBufferPtr buf, if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected model type %d"), def->model); - goto cleanup; + return -1; } } - virBufferAsprintf(buf, - "idx); if (model) - virBufferEscapeString(buf, " model=3D'%s'", model); + virBufferEscapeString(&attrBuf, " model=3D'%s'", model); switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: if (def->opts.vioserial.ports !=3D -1) { - virBufferAsprintf(buf, " ports=3D'%d'", + virBufferAsprintf(&attrBuf, " ports=3D'%d'", def->opts.vioserial.ports); } if (def->opts.vioserial.vectors !=3D -1) { - virBufferAsprintf(buf, " vectors=3D'%d'", + virBufferAsprintf(&attrBuf, " vectors=3D'%d'", def->opts.vioserial.vectors); } break; case VIR_DOMAIN_CONTROLLER_TYPE_USB: if (def->opts.usbopts.ports !=3D -1) { - virBufferAsprintf(buf, " ports=3D'%d'", + virBufferAsprintf(&attrBuf, " ports=3D'%d'", def->opts.usbopts.ports); } break; @@ -24373,7 +24373,7 @@ virDomainControllerDefFormat(virBufferPtr buf, virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected model name value %d"), def->opts.pciopts.modelName); - goto cleanup; + return -1; } virBufferAsprintf(&childBuf, "\n", modelNa= me); } @@ -24414,10 +24414,10 @@ virDomainControllerDefFormat(virBufferPtr buf, } if (virDomainControllerDriverFormat(&childBuf, def) < 0) - goto cleanup; + return -1; if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) - goto cleanup; + return -1; if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && def->opts.pciopts.pcihole64) { @@ -24425,23 +24425,7 @@ virDomainControllerDefFormat(virBufferPtr buf, "pcihole64>\n", def->opts.pciopts.pcihole64size); } - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - - if (virBufferUse(&childBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } - - ret =3D 0; - - cleanup: - virBufferFreeAndReset(&childBuf); - - return ret; + return virXMLFormatElement(buf, "controller", &attrBuf, &childBuf); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860471074697.0560926572958; Wed, 6 Mar 2019 00:21:11 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 373DBC047B60; Wed, 6 Mar 2019 08:21:09 +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 094885C28C; Wed, 6 Mar 2019 08:21:09 +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 B567F181A13C; Wed, 6 Mar 2019 08:21:08 +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 x268Ktsb032460 for ; Wed, 6 Mar 2019 03:20:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46B371A267; Wed, 6 Mar 2019 08:20:55 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFAC8277B3 for ; Wed, 6 Mar 2019 08:20:54 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:29 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 04/23] conf: Refactor virDomainMemballoonDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Mar 2019 08:21:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 47 ++++++++++-------------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cbefa7749b..fd3f19d6ce 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25837,19 +25837,20 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model =3D virDomainMemballoonModelTypeToString(def->model); - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected memballoon model %d"), def->model); - goto cleanup; + return -1; } - virBufferAsprintf(buf, "autodeflate !=3D VIR_TRISTATE_SWITCH_ABSENT) - virBufferAsprintf(buf, " autodeflate=3D'%s'", + virBufferAsprintf(&attrBuf, " autodeflate=3D'%s'", virTristateSwitchTypeToString(def->autodeflate)); virBufferSetChildIndent(&childrenBuf, buf); @@ -25858,40 +25859,14 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAsprintf(&childrenBuf, "\n", def->p= eriod); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) - goto cleanup; - - if (def->virtio) { - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; - - virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; - - if (virBufferUse(&driverBuf)) { - virBufferAddLit(&childrenBuf, "\n"); - } - } - - if (virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - - if (!virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, "/>\n"); - } else { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } + return -1; - ret =3D 0; + virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - cleanup: - virBufferFreeAndReset(&childrenBuf); + if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) = < 0) + return -1; - return ret; + return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf); } static int --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860460119251.42977871132632; Wed, 6 Mar 2019 00:21:00 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 1167430842AC; Wed, 6 Mar 2019 08:20:58 +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 D58DC6090C; Wed, 6 Mar 2019 08:20:57 +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 920A5181A12A; Wed, 6 Mar 2019 08:20:57 +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 x268Kuka032467 for ; Wed, 6 Mar 2019 03:20:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1FBF91A91A; Wed, 6 Mar 2019 08:20:56 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97DCC1A267 for ; Wed, 6 Mar 2019 08:20:55 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:30 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 05/23] conf: Refactor virDomainWatchdogDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 06 Mar 2019 08:20:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fd3f19d6ce..ed480bcf8e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25893,46 +25893,29 @@ virDomainWatchdogDefFormat(virBufferPtr buf, { const char *model =3D virDomainWatchdogModelTypeToString(def->model); const char *action =3D virDomainWatchdogActionTypeToString(def->action= ); - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; virBufferSetChildIndent(&childBuf, buf); if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected watchdog model %d"), def->model); - goto cleanup; + return -1; } if (!action) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected watchdog action %d"), def->action); - goto cleanup; - } - - if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) - goto cleanup; - - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - - virBufferAsprintf(buf, "\n"); - virBufferAddBuffer(buf, &childBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); + return -1; } - ret =3D 0; + virBufferAsprintf(&attrBuf, " model=3D'%s' action=3D'%s'", model, acti= on); - cleanup: - virBufferFreeAndReset(&childBuf); + if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) + return -1; - return ret; + return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf); } static int virDomainPanicDefFormat(virBufferPtr buf, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860466918807.8237026459999; Wed, 6 Mar 2019 00:21:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED5A130917AB; Wed, 6 Mar 2019 08:21:04 +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 BD7AD1001DC5; Wed, 6 Mar 2019 08:21:04 +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 5C050181A137; Wed, 6 Mar 2019 08:21:04 +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 x268KuAh032482 for ; Wed, 6 Mar 2019 03:20:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id EC2A01A91B; Wed, 6 Mar 2019 08:20:56 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7070D1A267 for ; Wed, 6 Mar 2019 08:20:56 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:31 +0100 Message-Id: <4dbc08d61a461ef48ca82efe22e298770b6f7a2b.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 06/23] conf: Refactor virDomainPanicDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 06 Mar 2019 08:21:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ed480bcf8e..766846a557 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25921,36 +25921,18 @@ virDomainWatchdogDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; - - virBufferAddLit(buf, "model) - virBufferAsprintf(buf, " model=3D'%s'", + virBufferAsprintf(&attrBuf, " model=3D'%s'", virDomainPanicModelTypeToString(def->model)); virBufferSetChildIndent(&childrenBuf, buf); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) - goto cleanup; - - if (virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } - - ret =3D 0; - - cleanup: - virBufferFreeAndReset(&childrenBuf); + return -1; - return ret; + return virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf); } static int --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860471180215.3702940131467; Wed, 6 Mar 2019 00:21:11 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 56CCD30224BE; Wed, 6 Mar 2019 08:21:09 +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 280F11A91B; Wed, 6 Mar 2019 08:21:09 +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 D9E373FB12; Wed, 6 Mar 2019 08:21:08 +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 x268Kv8c032489 for ; Wed, 6 Mar 2019 03:20:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id C4B391A91B; Wed, 6 Mar 2019 08:20:57 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 493501A267 for ; Wed, 6 Mar 2019 08:20:57 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:32 +0100 Message-Id: <07f58c4d21b815f507685fc0f538c2605a3715d1.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 07/23] conf: Refactor formatting of 'driver' in virDomainRNGDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 06 Mar 2019 08:21:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 766846a557..71e0c8679b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25982,8 +25982,7 @@ virDomainRNGDefFormat(virBufferPtr buf, { const char *model =3D virDomainRNGModelTypeToString(def->model); const char *backend =3D virDomainRNGBackendTypeToString(def->backend); - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; virBufferAsprintf(buf, "\n", model); virBufferAdjustIndent(buf, 2); @@ -26002,11 +26001,11 @@ virDomainRNGDefFormat(virBufferPtr buf, case VIR_DOMAIN_RNG_BACKEND_EGD: if (virDomainChrAttrsDefFormat(buf, def->source.chardev, false) < = 0) - goto cleanup; + return -1; virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (virDomainChrSourceDefFormat(buf, def->source.chardev, flags) <= 0) - goto cleanup; + return -1; virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -26014,28 +26013,18 @@ virDomainRNGDefFormat(virBufferPtr buf, break; } - virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; + virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - if (virBufferUse(&driverBuf)) { - virBufferAddLit(buf, "\n"); - } + if (virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL) < 0) + return -1; if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) - goto cleanup; + return -1; virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); - ret =3D 0; - - cleanup: - virBufferFreeAndReset(&driverBuf); - - return ret; + return 0; } void --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155186047504464.58554263779774; Wed, 6 Mar 2019 00:21:15 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 32FC3C057F4F; Wed, 6 Mar 2019 08:21:13 +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 F34FA600D7; Wed, 6 Mar 2019 08:21:12 +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 AC29A181A266; Wed, 6 Mar 2019 08:21:12 +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 x268KwK3032502 for ; Wed, 6 Mar 2019 03:20:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9DFF71A91B; Wed, 6 Mar 2019 08:20:58 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21C481A267 for ; Wed, 6 Mar 2019 08:20:57 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:33 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 08/23] conf: Refactor virDomainInputDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 06 Mar 2019 08:21:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 54 +++++++++++++----------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 71e0c8679b..83e11f603f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26244,9 +26244,9 @@ virDomainInputDefFormat(virBufferPtr buf, { const char *type =3D virDomainInputTypeToString(def->type); const char *bus =3D virDomainInputBusTypeToString(def->bus); - virBuffer childbuf =3D VIR_BUFFER_INITIALIZER; - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; /* don't format keyboard into migratable XML for backward compatibilit= y */ if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && @@ -26258,16 +26258,15 @@ virDomainInputDefFormat(virBufferPtr buf, if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input type %d"), def->type); - goto cleanup; + return -1; } if (!bus) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input bus type %d"), def->bus); - goto cleanup; + return -1; } - virBufferAsprintf(buf, "model) { const char *model =3D virDomainInputModelTypeToString(def->model); @@ -26275,44 +26274,23 @@ virDomainInputDefFormat(virBufferPtr buf, if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected input model %d"), def->model); - goto cleanup; + return -1; } - virBufferAsprintf(buf, " model=3D'%s'", model); + virBufferAsprintf(&attrBuf, " model=3D'%s'", model); } - virBufferSetChildIndent(&childbuf, buf); - virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; - - if (virBufferUse(&driverBuf)) { - virBufferAddLit(&childbuf, "\n"); - } - virBufferEscapeString(&childbuf, "\n", def->sour= ce.evdev); - if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0) - goto cleanup; - - if (virBufferCheckError(&childbuf) < 0) - goto cleanup; - - if (!virBufferUse(&childbuf)) { - virBufferAddLit(buf, "/>\n"); - } else { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childbuf); - virBufferAddLit(buf, "\n"); - } + virBufferSetChildIndent(&childBuf, buf); + virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - ret =3D 0; + if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0) + return -1; - cleanup: - virBufferFreeAndReset(&childbuf); - virBufferFreeAndReset(&driverBuf); + virBufferEscapeString(&childBuf, "\n", def->sour= ce.evdev); + if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) + return -1; - return ret; + return virXMLFormatElement(buf, "input", &attrBuf, &childBuf); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860475421401.3187253660757; Wed, 6 Mar 2019 00:21:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AFA281F11; Wed, 6 Mar 2019 08:21:13 +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 EB8DF1001DE8; Wed, 6 Mar 2019 08:21:12 +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 A096E181A265; Wed, 6 Mar 2019 08:21:12 +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 x268Kx6e032509 for ; Wed, 6 Mar 2019 03:20:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7603B1A91B; Wed, 6 Mar 2019 08:20:59 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE9A51A267 for ; Wed, 6 Mar 2019 08:20:58 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:34 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 09/23] conf: Refactor virDomainHubDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Mar 2019 08:21:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 83e11f603f..5d745f8bce 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26976,38 +26976,23 @@ virDomainHubDefFormat(virBufferPtr buf, unsigned int flags) { const char *type =3D virDomainHubTypeToString(def->type); - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; virBufferSetChildIndent(&childBuf, buf); if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hub type %d"), def->type); - goto cleanup; + return -1; } if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) - goto cleanup; - - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - - virBufferAsprintf(buf, "\n"); - virBufferAddBuffer(buf, &childBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } - - ret =3D 0; + return -1; - cleanup: - virBufferFreeAndReset(&childBuf); + virBufferAsprintf(&attrBuf, " type=3D'%s'", type); - return ret; + return virXMLFormatElement(buf, "hub", &attrBuf, &childBuf); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860474986839.875026555989; Wed, 6 Mar 2019 00:21:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2686A307D942; Wed, 6 Mar 2019 08:21:13 +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 E93231001DC5; Wed, 6 Mar 2019 08:21:12 +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 A23523FAF6; Wed, 6 Mar 2019 08:21:12 +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 x268L04A032523 for ; Wed, 6 Mar 2019 03:21:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4E2701A91B; Wed, 6 Mar 2019 08:21:00 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6A311A267 for ; Wed, 6 Mar 2019 08:20:59 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:35 +0100 Message-Id: <616e575513a7e35d0d02fc68ab6b6ed3b3a411ff.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 10/23] conf: Split out formatting of 'blkiotune' from virDomainDefFormatInternal 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 06 Mar 2019 08:21:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Split out the code into a separate function named virDomainDefFormatBlkiotune and use virXMLFormatElement. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 89 ++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d745f8bce..01ec5c8ca9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27696,6 +27696,51 @@ virDomainVsockDefFormat(virBufferPtr buf, } +static int +virDomainDefFormatBlkiotune(virBufferPtr buf, + virDomainDefPtr def) +{ + VIR_AUTOCLEAN(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; + ssize_t n; + + virBufferSetChildIndent(&childrenBuf, buf); + if (def->blkio.weight) + virBufferAsprintf(&childrenBuf, "%u\n", + def->blkio.weight); + + for (n =3D 0; n < def->blkio.ndevices; n++) { + virBlkioDevicePtr dev =3D &def->blkio.devices[n]; + + if (!dev->weight && !dev->riops && !dev->wiops && + !dev->rbps && !dev->wbps) + continue; + virBufferAddLit(&childrenBuf, "\n"); + virBufferAdjustIndent(&childrenBuf, 2); + virBufferEscapeString(&childrenBuf, "%s\n", + dev->path); + if (dev->weight) + virBufferAsprintf(&childrenBuf, "%u\n", + dev->weight); + if (dev->riops) + virBufferAsprintf(&childrenBuf, "%u\n", + dev->riops); + if (dev->wiops) + virBufferAsprintf(&childrenBuf, "%u\n", + dev->wiops); + if (dev->rbps) + virBufferAsprintf(&childrenBuf, "%llu\n", + dev->rbps); + if (dev->wbps) + virBufferAsprintf(&childrenBuf, "%llu\n", + dev->wbps); + virBufferAdjustIndent(&childrenBuf, -2); + virBufferAddLit(&childrenBuf, "\n"); + } + + return virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf); +} + + /* This internal version appends to an existing buffer * (possibly with auto-indent), rather than flattening * to string. @@ -27797,51 +27842,9 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAsprintf(buf, "%llu\n", def->mem.cur_balloon); - /* start format blkiotune */ - virBufferSetChildIndent(&childrenBuf, buf); - if (def->blkio.weight) - virBufferAsprintf(&childrenBuf, "%u\n", - def->blkio.weight); - - for (n =3D 0; n < def->blkio.ndevices; n++) { - virBlkioDevicePtr dev =3D &def->blkio.devices[n]; - - if (!dev->weight && !dev->riops && !dev->wiops && - !dev->rbps && !dev->wbps) - continue; - virBufferAddLit(&childrenBuf, "\n"); - virBufferAdjustIndent(&childrenBuf, 2); - virBufferEscapeString(&childrenBuf, "%s\n", - dev->path); - if (dev->weight) - virBufferAsprintf(&childrenBuf, "%u\n", - dev->weight); - if (dev->riops) - virBufferAsprintf(&childrenBuf, "%u\n", - dev->riops); - if (dev->wiops) - virBufferAsprintf(&childrenBuf, "%u\n", - dev->wiops); - if (dev->rbps) - virBufferAsprintf(&childrenBuf, "%llu\n", - dev->rbps); - if (dev->wbps) - virBufferAsprintf(&childrenBuf, "%llu\n", - dev->wbps); - virBufferAdjustIndent(&childrenBuf, -2); - virBufferAddLit(&childrenBuf, "\n"); - } - - if (virBufferCheckError(&childrenBuf) < 0) + if (virDomainDefFormatBlkiotune(buf, def) < 0) goto error; - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, "\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } - virBufferFreeAndReset(&childrenBuf); - if (virDomainMemtuneFormat(buf, &def->mem) < 0) goto error; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860479011151.38228351498435; Wed, 6 Mar 2019 00:21:19 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id D2F0A81DE9; Wed, 6 Mar 2019 08:21:16 +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 943516B47B; Wed, 6 Mar 2019 08:21:16 +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 4F7703FA46; Wed, 6 Mar 2019 08:21:16 +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 x268L1Vf032535 for ; Wed, 6 Mar 2019 03:21:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F45427CB8; Wed, 6 Mar 2019 08:21:01 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F12D277D0 for ; Wed, 6 Mar 2019 08:21:00 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:36 +0100 Message-Id: <7c63a23d16e31f93c11fe3f16e22ddf644919c71.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 11/23] conf: Split out domain features formatting from virDomainDefFormatInternal 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Mar 2019 08:21:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Pure code motion of code for formatting domain features to a function called virDomainDefFormatFeatures. Best viewed with the '--patience' option for git show. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 760 +++++++++++++++++++++-------------------- 1 file changed, 388 insertions(+), 372 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 01ec5c8ca9..215fb111bb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27741,277 +27741,13 @@ virDomainDefFormatBlkiotune(virBufferPtr buf, } -/* This internal version appends to an existing buffer - * (possibly with auto-indent), rather than flattening - * to string. - * Return -1 on failure. */ -int -virDomainDefFormatInternal(virDomainDefPtr def, - virCapsPtr caps, - unsigned int flags, - virBufferPtr buf, - virDomainXMLOptionPtr xmlopt) +static int +virDomainDefFormatFeatures(virBufferPtr buf, + virDomainDefPtr def) { - unsigned char *uuid; - char uuidstr[VIR_UUID_STRING_BUFLEN]; - const char *type =3D NULL; - int n; - size_t i; virBuffer attributeBuf =3D VIR_BUFFER_INITIALIZER; virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; - char *netprefix =3D NULL; - - virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | - VIR_DOMAIN_DEF_FORMAT_STATUS | - VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | - VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | - VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST, - -1); - - if (!(type =3D virDomainVirtTypeToString(def->virtType))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected domain type %d"), def->virtType); - goto error; - } - - if (def->id =3D=3D -1) - flags |=3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; - - virBufferAsprintf(buf, "id); - if (def->namespaceData && def->ns.href) - virBufferAsprintf(buf, " %s", (def->ns.href)()); - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - - virBufferEscapeString(buf, "%s\n", def->name); - - uuid =3D def->uuid; - virUUIDFormat(uuid, uuidstr); - virBufferAsprintf(buf, "%s\n", uuidstr); - - if (def->genidRequested) { - char genidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(def->genid, genidstr); - virBufferAsprintf(buf, "%s\n", genidstr); - } - - virBufferEscapeString(buf, "%s\n", def->title); - - virBufferEscapeString(buf, "%s\n", - def->description); - - if (def->metadata) { - xmlBufferPtr xmlbuf; - int oldIndentTreeOutput =3D xmlIndentTreeOutput; - - /* Indentation on output requires that we previously set - * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2 - * spaces per level of indentation of intermediate elements, - * but no leading indentation before the starting element. - * Thankfully, libxml maps what looks like globals into - * thread-local uses, so we are thread-safe. */ - xmlIndentTreeOutput =3D 1; - xmlbuf =3D xmlBufferCreate(); - if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { - xmlBufferFree(xmlbuf); - xmlIndentTreeOutput =3D oldIndentTreeOutput; - goto error; - } - virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); - xmlBufferFree(xmlbuf); - xmlIndentTreeOutput =3D oldIndentTreeOutput; - } - - if (virDomainDefHasMemoryHotplug(def)) { - virBufferAsprintf(buf, - "%llu\n", - def->mem.memory_slots, def->mem.max_memory); - } - - virBufferAddLit(buf, "mem.dump_core) - virBufferAsprintf(buf, " dumpCore=3D'%s'", - virTristateSwitchTypeToString(def->mem.dump_core= )); - virBufferAsprintf(buf, " unit=3D'KiB'>%llu\n", - virDomainDefGetMemoryTotal(def)); - - virBufferAsprintf(buf, "%llu\n", - def->mem.cur_balloon); - - if (virDomainDefFormatBlkiotune(buf, def) < 0) - goto error; - - if (virDomainMemtuneFormat(buf, &def->mem) < 0) - goto error; - - if (virDomainCpuDefFormat(buf, def) < 0) - goto error; - - if (def->niothreadids > 0) { - virBufferAsprintf(buf, "%zu\n", - def->niothreadids); - if (virDomainDefIothreadShouldFormat(def)) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < def->niothreadids; i++) { - virBufferAsprintf(buf, "\n", - def->iothreadids[i]->iothread_id); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } - } - - if (virDomainCputuneDefFormat(buf, def, flags) < 0) - goto error; - - if (virDomainNumatuneFormatXML(buf, def->numa) < 0) - goto error; - - if (def->resource) - virDomainResourceDefFormat(buf, def->resource); - - if (def->sysinfo) - ignore_value(virSysinfoFormat(buf, def->sysinfo)); - - if (def->os.bootloader) { - virBufferEscapeString(buf, "%s\n", - def->os.bootloader); - virBufferEscapeString(buf, - "%s\n", - def->os.bootloaderArgs); - } - - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - virBufferAddLit(buf, "os.arch) - virBufferAsprintf(buf, " arch=3D'%s'", virArchToString(def->os.arc= h)); - if (def->os.machine) - virBufferAsprintf(buf, " machine=3D'%s'", def->os.machine); - /* - * HACK: For xen driver we previously used bogus 'linux' as the - * os type for paravirt, whereas capabilities declare it to - * be 'xen'. So we convert to the former for backcompat - */ - if (def->virtType =3D=3D VIR_DOMAIN_VIRT_XEN && - def->os.type =3D=3D VIR_DOMAIN_OSTYPE_XEN) - virBufferAsprintf(buf, ">%s\n", - virDomainOSTypeToString(VIR_DOMAIN_OSTYPE_LINUX)= ); - else - virBufferAsprintf(buf, ">%s\n", - virDomainOSTypeToString(def->os.type)); - - virBufferEscapeString(buf, "%s\n", - def->os.init); - for (i =3D 0; def->os.initargv && def->os.initargv[i]; i++) - virBufferEscapeString(buf, "%s\n", - def->os.initargv[i]); - for (i =3D 0; def->os.initenv && def->os.initenv[i]; i++) - virBufferAsprintf(buf, "%s\n", - def->os.initenv[i]->name, def->os.initenv[i]->va= lue); - if (def->os.initdir) - virBufferEscapeString(buf, "%s\n", - def->os.initdir); - if (def->os.inituser) - virBufferAsprintf(buf, "%s\n", def->os.initus= er); - if (def->os.initgroup) - virBufferAsprintf(buf, "%s\n", def->os.init= group); - - if (def->os.loader) - virDomainLoaderDefFormat(buf, def->os.loader); - virBufferEscapeString(buf, "%s\n", - def->os.kernel); - virBufferEscapeString(buf, "%s\n", - def->os.initrd); - virBufferEscapeString(buf, "%s\n", - def->os.cmdline); - virBufferEscapeString(buf, "%s\n", - def->os.dtb); - virBufferEscapeString(buf, "%s\n", - def->os.root); - if (def->os.slic_table) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "%s
\n", - def->os.slic_table); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "
\n"); - } - - if (!def->os.bootloader) { - for (n =3D 0; n < def->os.nBootDevs; n++) { - const char *boottype =3D - virDomainBootTypeToString(def->os.bootDevs[n]); - if (!boottype) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected boot device type %d"), - def->os.bootDevs[n]); - goto error; - } - virBufferAsprintf(buf, "\n", boottype); - } - - if (def->os.bootmenu) { - virBufferAsprintf(buf, "os.bootmenu= )); - if (def->os.bm_timeout_set) - virBufferAsprintf(buf, " timeout=3D'%u'", def->os.bm_timeo= ut); - virBufferAddLit(buf, "/>\n"); - } - - if (def->os.bios.useserial || def->os.bios.rt_set) { - virBufferAddLit(buf, "os.bios.useserial) - virBufferAsprintf(buf, " useserial=3D'%s'", - virTristateBoolTypeToString(def->os.bios= .useserial)); - if (def->os.bios.rt_set) - virBufferAsprintf(buf, " rebootTimeout=3D'%d'", def->os.bi= os.rt_delay); - - virBufferAddLit(buf, "/>\n"); - } - } - - if (def->os.smbios_mode) { - const char *mode; - - mode =3D virDomainSmbiosModeTypeToString(def->os.smbios_mode); - if (mode =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected smbios mode %d"), def->os.smbios_= mode); - goto error; - } - virBufferAsprintf(buf, "\n", mode); - } - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "
\n"); - - - if (def->idmap.uidmap) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < def->idmap.nuidmap; i++) { - virBufferAsprintf(buf, - "\n", - def->idmap.uidmap[i].start, - def->idmap.uidmap[i].target, - def->idmap.uidmap[i].count); - } - for (i =3D 0; i < def->idmap.ngidmap; i++) { - virBufferAsprintf(buf, - "\n", - def->idmap.gidmap[i].start, - def->idmap.gidmap[i].target, - def->idmap.gidmap[i].count); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + size_t i; for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) @@ -28156,130 +27892,412 @@ virDomainDefFormatInternal(virDomainDefPtr def, def->hyperv_spinlocks); break; - case VIR_DOMAIN_HYPERV_VENDOR_ID: - if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWIT= CH_ON) - break; - virBufferEscapeString(buf, " value=3D'%s'", - def->hyperv_vendor_id); - break; + case VIR_DOMAIN_HYPERV_VENDOR_ID: + if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWIT= CH_ON) + break; + virBufferEscapeString(buf, " value=3D'%s'", + def->hyperv_vendor_id); + break; + + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_HYPERV_LAST: + break; + } + + virBufferAddLit(buf, "/>\n"); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; + + case VIR_DOMAIN_FEATURE_KVM: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + break; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < VIR_DOMAIN_KVM_LAST; j++) { + switch ((virDomainKVM) j) { + case VIR_DOMAIN_KVM_HIDDEN: + if (def->kvm_features[j]) + virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virDomainKVMTypeToString(j), + virTristateSwitchTypeToStrin= g( + def->kvm_features[j])); + break; + + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_KVM_LAST: + break; + } + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; + + case VIR_DOMAIN_FEATURE_CAPABILITIES: + if (def->features[i] =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY= _DEFAULT && + !virDomainDefHasCapabilitiesFeatures(def)) { + break; + } + + virBufferAsprintf(buf, "\n", + virDomainCapabilitiesPolicyTypeToString(= def->features[i])); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { + if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABS= ENT) + virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virDomainCapsFeatureTypeToString= (j), + virTristateSwitchTypeToString( + def->caps_features[j])); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; + + case VIR_DOMAIN_FEATURE_GIC: + if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { + virBufferAddLit(buf, "gic_version !=3D VIR_GIC_VERSION_NONE) + virBufferAsprintf(buf, " version=3D'%s'", + virGICVersionTypeToString(def->g= ic_version)); + virBufferAddLit(buf, "/>\n"); + } + break; + + case VIR_DOMAIN_FEATURE_IOAPIC: + if (def->features[i] =3D=3D VIR_DOMAIN_IOAPIC_NONE) + break; + + virBufferAsprintf(buf, "\n", + virDomainIOAPICTypeToString(def->feature= s[i])); + break; + + case VIR_DOMAIN_FEATURE_HPT: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + break; + + virBufferFreeAndReset(&attributeBuf); + virBufferFreeAndReset(&childrenBuf); + + if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { + virBufferAsprintf(&attributeBuf, + " resizing=3D'%s'", + virDomainHPTResizingTypeToString(def= ->hpt_resizing)); + } + if (def->hpt_maxpagesize > 0) { + virBufferSetChildIndent(&childrenBuf, buf); + virBufferAsprintf(&childrenBuf, + "%llu\n", + def->hpt_maxpagesize); + } + + if (virXMLFormatElement(buf, "hpt", + &attributeBuf, &childrenBuf) < 0) { + goto error; + } + break; + + case VIR_DOMAIN_FEATURE_MSRS: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + break; + + virBufferAsprintf(buf, "\n", + virDomainMsrsUnknownTypeToString(def->ms= rs_features[VIR_DOMAIN_MSRS_UNKNOWN])); + break; + + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_FEATURE_LAST: + break; + } + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + return 0; + + error: + virBufferFreeAndReset(&attributeBuf); + virBufferFreeAndReset(&childrenBuf); + return -1; +} + + +/* This internal version appends to an existing buffer + * (possibly with auto-indent), rather than flattening + * to string. + * Return -1 on failure. */ +int +virDomainDefFormatInternal(virDomainDefPtr def, + virCapsPtr caps, + unsigned int flags, + virBufferPtr buf, + virDomainXMLOptionPtr xmlopt) +{ + unsigned char *uuid; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + const char *type =3D NULL; + int n; + size_t i; + char *netprefix =3D NULL; + + virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | + VIR_DOMAIN_DEF_FORMAT_STATUS | + VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | + VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | + VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST, + -1); + + if (!(type =3D virDomainVirtTypeToString(def->virtType))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected domain type %d"), def->virtType); + goto error; + } + + if (def->id =3D=3D -1) + flags |=3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + virBufferAsprintf(buf, "id); + if (def->namespaceData && def->ns.href) + virBufferAsprintf(buf, " %s", (def->ns.href)()); + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + + virBufferEscapeString(buf, "%s\n", def->name); + + uuid =3D def->uuid; + virUUIDFormat(uuid, uuidstr); + virBufferAsprintf(buf, "%s\n", uuidstr); + + if (def->genidRequested) { + char genidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(def->genid, genidstr); + virBufferAsprintf(buf, "%s\n", genidstr); + } + + virBufferEscapeString(buf, "%s\n", def->title); + + virBufferEscapeString(buf, "%s\n", + def->description); + + if (def->metadata) { + xmlBufferPtr xmlbuf; + int oldIndentTreeOutput =3D xmlIndentTreeOutput; + + /* Indentation on output requires that we previously set + * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2 + * spaces per level of indentation of intermediate elements, + * but no leading indentation before the starting element. + * Thankfully, libxml maps what looks like globals into + * thread-local uses, so we are thread-safe. */ + xmlIndentTreeOutput =3D 1; + xmlbuf =3D xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, + virBufferGetIndent(buf, false) / 2, 1) < 0) { + xmlBufferFree(xmlbuf); + xmlIndentTreeOutput =3D oldIndentTreeOutput; + goto error; + } + virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); + xmlBufferFree(xmlbuf); + xmlIndentTreeOutput =3D oldIndentTreeOutput; + } + + if (virDomainDefHasMemoryHotplug(def)) { + virBufferAsprintf(buf, + "%llu\n", + def->mem.memory_slots, def->mem.max_memory); + } + + virBufferAddLit(buf, "mem.dump_core) + virBufferAsprintf(buf, " dumpCore=3D'%s'", + virTristateSwitchTypeToString(def->mem.dump_core= )); + virBufferAsprintf(buf, " unit=3D'KiB'>%llu\n", + virDomainDefGetMemoryTotal(def)); + + virBufferAsprintf(buf, "%llu\n", + def->mem.cur_balloon); + + if (virDomainDefFormatBlkiotune(buf, def) < 0) + goto error; - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_HYPERV_LAST: - break; - } + if (virDomainMemtuneFormat(buf, &def->mem) < 0) + goto error; - virBufferAddLit(buf, "/>\n"); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - break; + if (virDomainCpuDefFormat(buf, def) < 0) + goto error; - case VIR_DOMAIN_FEATURE_KVM: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) - break; + if (def->niothreadids > 0) { + virBufferAsprintf(buf, "%zu\n", + def->niothreadids); + if (virDomainDefIothreadShouldFormat(def)) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->niothreadids; i++) { + virBufferAsprintf(buf, "\n", + def->iothreadids[i]->iothread_id); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + } - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < VIR_DOMAIN_KVM_LAST; j++) { - switch ((virDomainKVM) j) { - case VIR_DOMAIN_KVM_HIDDEN: - if (def->kvm_features[j]) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", - virDomainKVMTypeToString(j), - virTristateSwitchTypeToStrin= g( - def->kvm_features[j])); - break; + if (virDomainCputuneDefFormat(buf, def, flags) < 0) + goto error; - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_KVM_LAST: - break; - } - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - break; + if (virDomainNumatuneFormatXML(buf, def->numa) < 0) + goto error; - case VIR_DOMAIN_FEATURE_CAPABILITIES: - if (def->features[i] =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY= _DEFAULT && - !virDomainDefHasCapabilitiesFeatures(def)) { - break; - } + if (def->resource) + virDomainResourceDefFormat(buf, def->resource); - virBufferAsprintf(buf, "\n", - virDomainCapabilitiesPolicyTypeToString(= def->features[i])); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { - if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABS= ENT) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", - virDomainCapsFeatureTypeToString= (j), - virTristateSwitchTypeToString( - def->caps_features[j])); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - break; + if (def->sysinfo) + ignore_value(virSysinfoFormat(buf, def->sysinfo)); - case VIR_DOMAIN_FEATURE_GIC: - if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { - virBufferAddLit(buf, "gic_version !=3D VIR_GIC_VERSION_NONE) - virBufferAsprintf(buf, " version=3D'%s'", - virGICVersionTypeToString(def->g= ic_version)); - virBufferAddLit(buf, "/>\n"); - } - break; + if (def->os.bootloader) { + virBufferEscapeString(buf, "%s\n", + def->os.bootloader); + virBufferEscapeString(buf, + "%s\n", + def->os.bootloaderArgs); + } - case VIR_DOMAIN_FEATURE_IOAPIC: - if (def->features[i] =3D=3D VIR_DOMAIN_IOAPIC_NONE) - break; + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAddLit(buf, "os.arch) + virBufferAsprintf(buf, " arch=3D'%s'", virArchToString(def->os.arc= h)); + if (def->os.machine) + virBufferAsprintf(buf, " machine=3D'%s'", def->os.machine); + /* + * HACK: For xen driver we previously used bogus 'linux' as the + * os type for paravirt, whereas capabilities declare it to + * be 'xen'. So we convert to the former for backcompat + */ + if (def->virtType =3D=3D VIR_DOMAIN_VIRT_XEN && + def->os.type =3D=3D VIR_DOMAIN_OSTYPE_XEN) + virBufferAsprintf(buf, ">%s\n", + virDomainOSTypeToString(VIR_DOMAIN_OSTYPE_LINUX)= ); + else + virBufferAsprintf(buf, ">%s\n", + virDomainOSTypeToString(def->os.type)); - virBufferAsprintf(buf, "\n", - virDomainIOAPICTypeToString(def->feature= s[i])); - break; + virBufferEscapeString(buf, "%s\n", + def->os.init); + for (i =3D 0; def->os.initargv && def->os.initargv[i]; i++) + virBufferEscapeString(buf, "%s\n", + def->os.initargv[i]); + for (i =3D 0; def->os.initenv && def->os.initenv[i]; i++) + virBufferAsprintf(buf, "%s\n", + def->os.initenv[i]->name, def->os.initenv[i]->va= lue); + if (def->os.initdir) + virBufferEscapeString(buf, "%s\n", + def->os.initdir); + if (def->os.inituser) + virBufferAsprintf(buf, "%s\n", def->os.initus= er); + if (def->os.initgroup) + virBufferAsprintf(buf, "%s\n", def->os.init= group); - case VIR_DOMAIN_FEATURE_HPT: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) - break; + if (def->os.loader) + virDomainLoaderDefFormat(buf, def->os.loader); + virBufferEscapeString(buf, "%s\n", + def->os.kernel); + virBufferEscapeString(buf, "%s\n", + def->os.initrd); + virBufferEscapeString(buf, "%s\n", + def->os.cmdline); + virBufferEscapeString(buf, "%s\n", + def->os.dtb); + virBufferEscapeString(buf, "%s\n", + def->os.root); + if (def->os.slic_table) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s
\n", + def->os.slic_table); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "
\n"); + } - virBufferFreeAndReset(&attributeBuf); - virBufferFreeAndReset(&childrenBuf); + if (!def->os.bootloader) { + for (n =3D 0; n < def->os.nBootDevs; n++) { + const char *boottype =3D + virDomainBootTypeToString(def->os.bootDevs[n]); + if (!boottype) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected boot device type %d"), + def->os.bootDevs[n]); + goto error; + } + virBufferAsprintf(buf, "\n", boottype); + } - if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { - virBufferAsprintf(&attributeBuf, - " resizing=3D'%s'", - virDomainHPTResizingTypeToString(def= ->hpt_resizing)); - } - if (def->hpt_maxpagesize > 0) { - virBufferSetChildIndent(&childrenBuf, buf); - virBufferAsprintf(&childrenBuf, - "%llu\n", - def->hpt_maxpagesize); - } + if (def->os.bootmenu) { + virBufferAsprintf(buf, "os.bootmenu= )); + if (def->os.bm_timeout_set) + virBufferAsprintf(buf, " timeout=3D'%u'", def->os.bm_timeo= ut); + virBufferAddLit(buf, "/>\n"); + } - if (virXMLFormatElement(buf, "hpt", - &attributeBuf, &childrenBuf) < 0) { - goto error; - } - break; + if (def->os.bios.useserial || def->os.bios.rt_set) { + virBufferAddLit(buf, "os.bios.useserial) + virBufferAsprintf(buf, " useserial=3D'%s'", + virTristateBoolTypeToString(def->os.bios= .useserial)); + if (def->os.bios.rt_set) + virBufferAsprintf(buf, " rebootTimeout=3D'%d'", def->os.bi= os.rt_delay); - case VIR_DOMAIN_FEATURE_MSRS: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) - break; + virBufferAddLit(buf, "/>\n"); + } + } - virBufferAsprintf(buf, "\n", - virDomainMsrsUnknownTypeToString(def->ms= rs_features[VIR_DOMAIN_MSRS_UNKNOWN])); - break; + if (def->os.smbios_mode) { + const char *mode; - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_FEATURE_LAST: - break; - } + mode =3D virDomainSmbiosModeTypeToString(def->os.smbios_mode); + if (mode =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected smbios mode %d"), def->os.smbios_= mode); + goto error; } + virBufferAsprintf(buf, "\n", mode); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "
\n"); + + if (def->idmap.uidmap) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->idmap.nuidmap; i++) { + virBufferAsprintf(buf, + "\n", + def->idmap.uidmap[i].start, + def->idmap.uidmap[i].target, + def->idmap.uidmap[i].count); + } + for (i =3D 0; i < def->idmap.ngidmap; i++) { + virBufferAsprintf(buf, + "\n", + def->idmap.gidmap[i].start, + def->idmap.gidmap[i].target, + def->idmap.gidmap[i].count); + } virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBufferAddLit(buf, "\n"); } + if (virDomainDefFormatFeatures(buf, def) < 0) + goto error; + if (virCPUDefFormatBufFull(buf, def->cpu, def->numa) < 0) goto error; @@ -28528,8 +28546,6 @@ virDomainDefFormatInternal(virDomainDefPtr def, error: virBufferFreeAndReset(buf); - virBufferFreeAndReset(&childrenBuf); - virBufferFreeAndReset(&attributeBuf); return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860478645754.5941630003051; Wed, 6 Mar 2019 00:21:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F819307EAB3; Wed, 6 Mar 2019 08:21:17 +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 D419C1001DC5; Wed, 6 Mar 2019 08:21:16 +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 950FA181A269; Wed, 6 Mar 2019 08:21:16 +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 x268L2mV032541 for ; Wed, 6 Mar 2019 03:21:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2CEDF282FE; Wed, 6 Mar 2019 08:21:02 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A164127CB8 for ; Wed, 6 Mar 2019 08:21:01 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:37 +0100 Message-Id: <1eb1327e68f7f472fbcefccf7e2721ad8bffe771.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 12/23] conf: Refactor control flow in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 06 Mar 2019 08:21:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use an early return to avoid one level of nesting scopes. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 423 +++++++++++++++++++++-------------------- 1 file changed, 212 insertions(+), 211 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 215fb111bb..70f3ac4fde 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27754,268 +27754,269 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; } - if (i !=3D VIR_DOMAIN_FEATURE_LAST || - virDomainDefHasCapabilitiesFeatures(def)) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - - for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { - const char *name =3D virDomainFeatureTypeToString(i); - size_t j; - - if (!name) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected feature %zu"), i); - goto error; - } - - switch ((virDomainFeature) i) { - case VIR_DOMAIN_FEATURE_ACPI: - case VIR_DOMAIN_FEATURE_PAE: - case VIR_DOMAIN_FEATURE_VIRIDIAN: - case VIR_DOMAIN_FEATURE_PRIVNET: - /* NOTE: This is for old style booleans. New XML - * should use the explicit state=3Don|off output below */ - switch ((virTristateSwitch) def->features[i]) { - case VIR_TRISTATE_SWITCH_ABSENT: - break; + if (i =3D=3D VIR_DOMAIN_FEATURE_LAST && + !virDomainDefHasCapabilitiesFeatures(def)) + return 0; - case VIR_TRISTATE_SWITCH_ON: - virBufferAsprintf(buf, "<%s/>\n", name); - break; + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); - case VIR_TRISTATE_SWITCH_LAST: - case VIR_TRISTATE_SWITCH_OFF: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected state of feature '%s'"), na= me); + for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { + const char *name =3D virDomainFeatureTypeToString(i); + size_t j; - goto error; - break; - } + if (!name) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected feature %zu"), i); + goto error; + } + switch ((virDomainFeature) i) { + case VIR_DOMAIN_FEATURE_ACPI: + case VIR_DOMAIN_FEATURE_PAE: + case VIR_DOMAIN_FEATURE_VIRIDIAN: + case VIR_DOMAIN_FEATURE_PRIVNET: + /* NOTE: This is for old style booleans. New XML + * should use the explicit state=3Don|off output below */ + switch ((virTristateSwitch) def->features[i]) { + case VIR_TRISTATE_SWITCH_ABSENT: break; - case VIR_DOMAIN_FEATURE_VMCOREINFO: - case VIR_DOMAIN_FEATURE_HAP: - case VIR_DOMAIN_FEATURE_PMU: - case VIR_DOMAIN_FEATURE_PVSPINLOCK: - case VIR_DOMAIN_FEATURE_VMPORT: - case VIR_DOMAIN_FEATURE_HTM: - case VIR_DOMAIN_FEATURE_NESTED_HV: - switch ((virTristateSwitch) def->features[i]) { - case VIR_TRISTATE_SWITCH_LAST: - case VIR_TRISTATE_SWITCH_ABSENT: - break; + case VIR_TRISTATE_SWITCH_ON: + virBufferAsprintf(buf, "<%s/>\n", name); + break; - case VIR_TRISTATE_SWITCH_ON: - virBufferAsprintf(buf, "<%s state=3D'on'/>\n", name); - break; + case VIR_TRISTATE_SWITCH_LAST: + case VIR_TRISTATE_SWITCH_OFF: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected state of feature '%s'"), name); - case VIR_TRISTATE_SWITCH_OFF: - virBufferAsprintf(buf, "<%s state=3D'off'/>\n", name); - break; - } + goto error; + break; + } - break; + break; - case VIR_DOMAIN_FEATURE_SMM: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) { - virTristateSwitch state =3D def->features[i]; - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + case VIR_DOMAIN_FEATURE_VMCOREINFO: + case VIR_DOMAIN_FEATURE_HAP: + case VIR_DOMAIN_FEATURE_PMU: + case VIR_DOMAIN_FEATURE_PVSPINLOCK: + case VIR_DOMAIN_FEATURE_VMPORT: + case VIR_DOMAIN_FEATURE_HTM: + case VIR_DOMAIN_FEATURE_NESTED_HV: + switch ((virTristateSwitch) def->features[i]) { + case VIR_TRISTATE_SWITCH_LAST: + case VIR_TRISTATE_SWITCH_ABSENT: + break; - virBufferAsprintf(&attrBuf, " state=3D'%s'", - virTristateSwitchTypeToString(state)= ); + case VIR_TRISTATE_SWITCH_ON: + virBufferAsprintf(buf, "<%s state=3D'on'/>\n", name); + break; - if (state =3D=3D VIR_TRISTATE_SWITCH_ON && - def->tseg_specified) { - const char *unit; - unsigned long long short_size =3D virFormatIntPret= ty(def->tseg_size, - = &unit); + case VIR_TRISTATE_SWITCH_OFF: + virBufferAsprintf(buf, "<%s state=3D'off'/>\n", name); + break; + } - virBufferSetChildIndent(&childBuf, buf); - virBufferAsprintf(&childBuf, "%l= lu\n", - unit, short_size); - } + break; - if (virXMLFormatElement(buf, "smm", &attrBuf, &childBu= f) < 0) - goto error; + case VIR_DOMAIN_FEATURE_SMM: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virTristateSwitch state =3D def->features[i]; + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&attrBuf, " state=3D'%s'", + virTristateSwitchTypeToString(state)); + + if (state =3D=3D VIR_TRISTATE_SWITCH_ON && + def->tseg_specified) { + const char *unit; + unsigned long long short_size =3D virFormatIntPretty(d= ef->tseg_size, + &un= it); + + virBufferSetChildIndent(&childBuf, buf); + virBufferAsprintf(&childBuf, "%llu\n", + unit, short_size); } - break; + if (virXMLFormatElement(buf, "smm", &attrBuf, &childBuf) <= 0) + goto error; + } - case VIR_DOMAIN_FEATURE_APIC: - if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { - virBufferAddLit(buf, "apic_eoi) { - virBufferAsprintf(buf, " eoi=3D'%s'", - virTristateSwitchTypeToString(de= f->apic_eoi)); - } - virBufferAddLit(buf, "/>\n"); + break; + + case VIR_DOMAIN_FEATURE_APIC: + if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { + virBufferAddLit(buf, "apic_eoi) { + virBufferAsprintf(buf, " eoi=3D'%s'", + virTristateSwitchTypeToString(def->a= pic_eoi)); } + virBufferAddLit(buf, "/>\n"); + } + break; + + case VIR_DOMAIN_FEATURE_HYPERV: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - case VIR_DOMAIN_FEATURE_HYPERV: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < VIR_DOMAIN_HYPERV_LAST; j++) { + if (def->hyperv_features[j] =3D=3D VIR_TRISTATE_SWITCH_ABS= ENT) + continue; + + virBufferAsprintf(buf, "<%s state=3D'%s'", + virDomainHypervTypeToString(j), + virTristateSwitchTypeToString( + def->hyperv_features[j])); + + switch ((virDomainHyperv) j) { + case VIR_DOMAIN_HYPERV_RELAXED: + case VIR_DOMAIN_HYPERV_VAPIC: + case VIR_DOMAIN_HYPERV_VPINDEX: + case VIR_DOMAIN_HYPERV_RUNTIME: + case VIR_DOMAIN_HYPERV_SYNIC: + case VIR_DOMAIN_HYPERV_STIMER: + case VIR_DOMAIN_HYPERV_RESET: + case VIR_DOMAIN_HYPERV_FREQUENCIES: + case VIR_DOMAIN_HYPERV_REENLIGHTENMENT: + case VIR_DOMAIN_HYPERV_TLBFLUSH: + case VIR_DOMAIN_HYPERV_IPI: + case VIR_DOMAIN_HYPERV_EVMCS: break; - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < VIR_DOMAIN_HYPERV_LAST; j++) { - if (def->hyperv_features[j] =3D=3D VIR_TRISTATE_SWITCH= _ABSENT) - continue; - - virBufferAsprintf(buf, "<%s state=3D'%s'", - virDomainHypervTypeToString(j), - virTristateSwitchTypeToString( - def->hyperv_features[j])); - - switch ((virDomainHyperv) j) { - case VIR_DOMAIN_HYPERV_RELAXED: - case VIR_DOMAIN_HYPERV_VAPIC: - case VIR_DOMAIN_HYPERV_VPINDEX: - case VIR_DOMAIN_HYPERV_RUNTIME: - case VIR_DOMAIN_HYPERV_SYNIC: - case VIR_DOMAIN_HYPERV_STIMER: - case VIR_DOMAIN_HYPERV_RESET: - case VIR_DOMAIN_HYPERV_FREQUENCIES: - case VIR_DOMAIN_HYPERV_REENLIGHTENMENT: - case VIR_DOMAIN_HYPERV_TLBFLUSH: - case VIR_DOMAIN_HYPERV_IPI: - case VIR_DOMAIN_HYPERV_EVMCS: + case VIR_DOMAIN_HYPERV_SPINLOCKS: + if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWITCH_O= N) break; + virBufferAsprintf(buf, " retries=3D'%d'", + def->hyperv_spinlocks); + break; - case VIR_DOMAIN_HYPERV_SPINLOCKS: - if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWIT= CH_ON) - break; - virBufferAsprintf(buf, " retries=3D'%d'", - def->hyperv_spinlocks); + case VIR_DOMAIN_HYPERV_VENDOR_ID: + if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWITCH_O= N) break; + virBufferEscapeString(buf, " value=3D'%s'", + def->hyperv_vendor_id); + break; - case VIR_DOMAIN_HYPERV_VENDOR_ID: - if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWIT= CH_ON) - break; - virBufferEscapeString(buf, " value=3D'%s'", - def->hyperv_vendor_id); - break; + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_HYPERV_LAST: + break; + } - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_HYPERV_LAST: - break; - } + virBufferAddLit(buf, "/>\n"); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; - virBufferAddLit(buf, "/>\n"); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + case VIR_DOMAIN_FEATURE_KVM: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - case VIR_DOMAIN_FEATURE_KVM: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < VIR_DOMAIN_KVM_LAST; j++) { + switch ((virDomainKVM) j) { + case VIR_DOMAIN_KVM_HIDDEN: + if (def->kvm_features[j]) + virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virDomainKVMTypeToString(j), + virTristateSwitchTypeToString( + def->kvm_features[j])); break; - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < VIR_DOMAIN_KVM_LAST; j++) { - switch ((virDomainKVM) j) { - case VIR_DOMAIN_KVM_HIDDEN: - if (def->kvm_features[j]) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", - virDomainKVMTypeToString(j), - virTristateSwitchTypeToStrin= g( - def->kvm_features[j])); - break; - - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_KVM_LAST: - break; - } - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - break; - - case VIR_DOMAIN_FEATURE_CAPABILITIES: - if (def->features[i] =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY= _DEFAULT && - !virDomainDefHasCapabilitiesFeatures(def)) { + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_KVM_LAST: break; } + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; - virBufferAsprintf(buf, "\n", - virDomainCapabilitiesPolicyTypeToString(= def->features[i])); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { - if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABS= ENT) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", - virDomainCapsFeatureTypeToString= (j), - virTristateSwitchTypeToString( - def->caps_features[j])); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + case VIR_DOMAIN_FEATURE_CAPABILITIES: + if (def->features[i] =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY_DEF= AULT && + !virDomainDefHasCapabilitiesFeatures(def)) { break; + } - case VIR_DOMAIN_FEATURE_GIC: - if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { - virBufferAddLit(buf, "gic_version !=3D VIR_GIC_VERSION_NONE) - virBufferAsprintf(buf, " version=3D'%s'", - virGICVersionTypeToString(def->g= ic_version)); - virBufferAddLit(buf, "/>\n"); - } - break; + virBufferAsprintf(buf, "\n", + virDomainCapabilitiesPolicyTypeToString(def-= >features[i])); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { + if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABSENT) + virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virDomainCapsFeatureTypeToString(j), + virTristateSwitchTypeToString( + def->caps_features[j])); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; - case VIR_DOMAIN_FEATURE_IOAPIC: - if (def->features[i] =3D=3D VIR_DOMAIN_IOAPIC_NONE) - break; + case VIR_DOMAIN_FEATURE_GIC: + if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { + virBufferAddLit(buf, "gic_version !=3D VIR_GIC_VERSION_NONE) + virBufferAsprintf(buf, " version=3D'%s'", + virGICVersionTypeToString(def->gic_v= ersion)); + virBufferAddLit(buf, "/>\n"); + } + break; - virBufferAsprintf(buf, "\n", - virDomainIOAPICTypeToString(def->feature= s[i])); + case VIR_DOMAIN_FEATURE_IOAPIC: + if (def->features[i] =3D=3D VIR_DOMAIN_IOAPIC_NONE) break; - case VIR_DOMAIN_FEATURE_HPT: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) - break; + virBufferAsprintf(buf, "\n", + virDomainIOAPICTypeToString(def->features[i]= )); + break; - virBufferFreeAndReset(&attributeBuf); - virBufferFreeAndReset(&childrenBuf); + case VIR_DOMAIN_FEATURE_HPT: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) + break; - if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { - virBufferAsprintf(&attributeBuf, - " resizing=3D'%s'", - virDomainHPTResizingTypeToString(def= ->hpt_resizing)); - } - if (def->hpt_maxpagesize > 0) { - virBufferSetChildIndent(&childrenBuf, buf); - virBufferAsprintf(&childrenBuf, - "%llu\n", - def->hpt_maxpagesize); - } + virBufferFreeAndReset(&attributeBuf); + virBufferFreeAndReset(&childrenBuf); - if (virXMLFormatElement(buf, "hpt", - &attributeBuf, &childrenBuf) < 0) { - goto error; - } - break; + if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { + virBufferAsprintf(&attributeBuf, + " resizing=3D'%s'", + virDomainHPTResizingTypeToString(def->hp= t_resizing)); + } + if (def->hpt_maxpagesize > 0) { + virBufferSetChildIndent(&childrenBuf, buf); + virBufferAsprintf(&childrenBuf, + "%llu\n", + def->hpt_maxpagesize); + } - case VIR_DOMAIN_FEATURE_MSRS: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) - break; + if (virXMLFormatElement(buf, "hpt", + &attributeBuf, &childrenBuf) < 0) { + goto error; + } + break; - virBufferAsprintf(buf, "\n", - virDomainMsrsUnknownTypeToString(def->ms= rs_features[VIR_DOMAIN_MSRS_UNKNOWN])); + case VIR_DOMAIN_FEATURE_MSRS: + if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - /* coverity[dead_error_begin] */ - case VIR_DOMAIN_FEATURE_LAST: - break; - } - } + virBufferAsprintf(buf, "\n", + virDomainMsrsUnknownTypeToString(def->msrs_f= eatures[VIR_DOMAIN_MSRS_UNKNOWN])); + break; - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + /* coverity[dead_error_begin] */ + case VIR_DOMAIN_FEATURE_LAST: + break; + } } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + return 0; error: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860482055492.07863984800326; Wed, 6 Mar 2019 00:21:22 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 6F4513092662; Wed, 6 Mar 2019 08:21:20 +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 429B76B47D; Wed, 6 Mar 2019 08:21:20 +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 F1F3B3FA4F; Wed, 6 Mar 2019 08:21:19 +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 x268L3Li032547 for ; Wed, 6 Mar 2019 03:21:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 08B971A267; Wed, 6 Mar 2019 08:21:03 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F9B127CB8 for ; Wed, 6 Mar 2019 08:21:02 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:38 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 13/23] conf: Rename temp buffers in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 06 Mar 2019 08:21:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" These buffers are used temporarily for some of the partial formatters but not globally. Prefix the name with 'tmp' to be explicit. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 70f3ac4fde..9ed153a71f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27745,8 +27745,8 @@ static int virDomainDefFormatFeatures(virBufferPtr buf, virDomainDefPtr def) { - virBuffer attributeBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer tmpAttrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer tmpChildBuf =3D VIR_BUFFER_INITIALIZER; size_t i; for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { @@ -27979,23 +27979,23 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferFreeAndReset(&attributeBuf); - virBufferFreeAndReset(&childrenBuf); + virBufferFreeAndReset(&tmpAttrBuf); + virBufferFreeAndReset(&tmpChildBuf); if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { - virBufferAsprintf(&attributeBuf, + virBufferAsprintf(&tmpAttrBuf, " resizing=3D'%s'", virDomainHPTResizingTypeToString(def->hp= t_resizing)); } if (def->hpt_maxpagesize > 0) { - virBufferSetChildIndent(&childrenBuf, buf); - virBufferAsprintf(&childrenBuf, + virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferAsprintf(&tmpChildBuf, "%llu\n", def->hpt_maxpagesize); } if (virXMLFormatElement(buf, "hpt", - &attributeBuf, &childrenBuf) < 0) { + &tmpAttrBuf, &tmpChildBuf) < 0) { goto error; } break; @@ -28020,8 +28020,8 @@ virDomainDefFormatFeatures(virBufferPtr buf, return 0; error: - virBufferFreeAndReset(&attributeBuf); - virBufferFreeAndReset(&childrenBuf); + virBufferFreeAndReset(&tmpAttrBuf); + virBufferFreeAndReset(&tmpChildBuf); return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860483042482.46373925955277; Wed, 6 Mar 2019 00:21:23 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 74BDE5858E; Wed, 6 Mar 2019 08:21:21 +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 4D7BD6B475; Wed, 6 Mar 2019 08:21:21 +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 EA8243F5CC; Wed, 6 Mar 2019 08:21:20 +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 x268L37q032563 for ; Wed, 6 Mar 2019 03:21:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id DB1071A91B; Wed, 6 Mar 2019 08:21:03 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C03E1A267 for ; Wed, 6 Mar 2019 08:21:03 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:39 +0100 Message-Id: <665fb06780b7561842d6def1ea22b3ccf478767b.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 14/23] conf: Remove impossible error in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 06 Mar 2019 08:21:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 'i' is always in range of the enum, thus the name is always populated by virDomainFeatureTypeToString. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9ed153a71f..52022aed0b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27765,12 +27765,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, const char *name =3D virDomainFeatureTypeToString(i); size_t j; - if (!name) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected feature %zu"), i); - goto error; - } - switch ((virDomainFeature) i) { case VIR_DOMAIN_FEATURE_ACPI: case VIR_DOMAIN_FEATURE_PAE: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860478839306.65650524721593; Wed, 6 Mar 2019 00:21:18 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id ED97D318A613; Wed, 6 Mar 2019 08:21:16 +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 C143A6B478; Wed, 6 Mar 2019 08:21:16 +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 8115E3FA48; Wed, 6 Mar 2019 08:21:16 +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 x268L491032572 for ; Wed, 6 Mar 2019 03:21:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id B2C5828542; Wed, 6 Mar 2019 08:21:04 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36C37277B3 for ; Wed, 6 Mar 2019 08:21:04 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:40 +0100 Message-Id: <445236e97871660c188cdea382cb6486fe68c8b2.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 15/23] conf: Simplify lifecycle of temp buffers in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 06 Mar 2019 08:21:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOCLEAN to avoid leaking the buffer on error path and get rid of resetting mid loop since virXMLFormatElement does the reset internally. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 52022aed0b..605ae3667b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27745,8 +27745,8 @@ static int virDomainDefFormatFeatures(virBufferPtr buf, virDomainDefPtr def) { - virBuffer tmpAttrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer tmpChildBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpAttrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpChildBuf =3D VIR_BUFFER_INITIALIZER; size_t i; for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { @@ -27784,8 +27784,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, case VIR_TRISTATE_SWITCH_OFF: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected state of feature '%s'"), name); - - goto error; + return -1; break; } @@ -27835,7 +27834,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, } if (virXMLFormatElement(buf, "smm", &attrBuf, &childBuf) <= 0) - goto error; + return -1; } break; @@ -27973,9 +27972,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { virBufferAsprintf(&tmpAttrBuf, " resizing=3D'%s'", @@ -27988,10 +27984,8 @@ virDomainDefFormatFeatures(virBufferPtr buf, def->hpt_maxpagesize); } - if (virXMLFormatElement(buf, "hpt", - &tmpAttrBuf, &tmpChildBuf) < 0) { - goto error; - } + if (virXMLFormatElement(buf, "hpt", &tmpAttrBuf, &tmpChildBuf)= < 0) + return -1; break; case VIR_DOMAIN_FEATURE_MSRS: @@ -28012,11 +28006,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, virBufferAddLit(buf, "\n"); return 0; - - error: - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155186048711847.994909415333495; Wed, 6 Mar 2019 00:21:27 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 182C899CE8; Wed, 6 Mar 2019 08:21:25 +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 D8B58600C5; Wed, 6 Mar 2019 08:21:24 +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 9D1A83D38B; Wed, 6 Mar 2019 08:21:24 +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 x268L55g032577 for ; Wed, 6 Mar 2019 03:21:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8DC0A277B3; Wed, 6 Mar 2019 08:21:05 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1180D1A91B for ; Wed, 6 Mar 2019 08:21:04 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:41 +0100 Message-Id: <567d72a32429b048b989face2b406f5f55ad22d9.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 16/23] conf: Avoid extra set of temp buffers in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Mar 2019 08:21:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use the top level set of temp buffers to do the job. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 605ae3667b..a1ed889e1d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27816,10 +27816,8 @@ virDomainDefFormatFeatures(virBufferPtr buf, case VIR_DOMAIN_FEATURE_SMM: if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) { virTristateSwitch state =3D def->features[i]; - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - virBufferAsprintf(&attrBuf, " state=3D'%s'", + virBufferAsprintf(&tmpAttrBuf, " state=3D'%s'", virTristateSwitchTypeToString(state)); if (state =3D=3D VIR_TRISTATE_SWITCH_ON && @@ -27828,12 +27826,12 @@ virDomainDefFormatFeatures(virBufferPtr buf, unsigned long long short_size =3D virFormatIntPretty(d= ef->tseg_size, &un= it); - virBufferSetChildIndent(&childBuf, buf); - virBufferAsprintf(&childBuf, "%llu\n", + virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferAsprintf(&tmpChildBuf, "%ll= u\n", unit, short_size); } - if (virXMLFormatElement(buf, "smm", &attrBuf, &childBuf) <= 0) + if (virXMLFormatElement(buf, "smm", &tmpAttrBuf, &tmpChild= Buf) < 0) return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860490530725.5860550765501; Wed, 6 Mar 2019 00:21:30 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id DF15F3092656; Wed, 6 Mar 2019 08:21:28 +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 611991A91B; Wed, 6 Mar 2019 08:21:28 +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 1CC54181A26F; Wed, 6 Mar 2019 08:21: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 x268L65l032586 for ; Wed, 6 Mar 2019 03:21:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 677F51A91B; Wed, 6 Mar 2019 08:21:06 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF0611A267 for ; Wed, 6 Mar 2019 08:21:05 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:42 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 17/23] conf: Avoid extra scope when formatting 'smm' feature 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 06 Mar 2019 08:21:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use an early break and remove the temporary variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a1ed889e1d..b42c63fb4d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27814,27 +27814,26 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; case VIR_DOMAIN_FEATURE_SMM: - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) { - virTristateSwitch state =3D def->features[i]; - - virBufferAsprintf(&tmpAttrBuf, " state=3D'%s'", - virTristateSwitchTypeToString(state)); + if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + break; - if (state =3D=3D VIR_TRISTATE_SWITCH_ON && - def->tseg_specified) { - const char *unit; - unsigned long long short_size =3D virFormatIntPretty(d= ef->tseg_size, - &un= it); + virBufferAsprintf(&tmpAttrBuf, " state=3D'%s'", + virTristateSwitchTypeToString(def->features[= i])); - virBufferSetChildIndent(&tmpChildBuf, buf); - virBufferAsprintf(&tmpChildBuf, "%ll= u\n", - unit, short_size); - } + if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON && + def->tseg_specified) { + const char *unit; + unsigned long long short_size =3D virFormatIntPretty(def->= tseg_size, + &unit); - if (virXMLFormatElement(buf, "smm", &tmpAttrBuf, &tmpChild= Buf) < 0) - return -1; + virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferAsprintf(&tmpChildBuf, "%llu\n", + unit, short_size); } + if (virXMLFormatElement(buf, "smm", &tmpAttrBuf, &tmpChildBuf)= < 0) + return -1; + break; case VIR_DOMAIN_FEATURE_APIC: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15518604941481012.0978456065257; Wed, 6 Mar 2019 00:21:34 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 77549307CEBD; Wed, 6 Mar 2019 08:21:32 +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 3ED7E6013F; Wed, 6 Mar 2019 08:21:32 +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 F2A913D38C; Wed, 6 Mar 2019 08:21:31 +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 x268L7Nh032602 for ; Wed, 6 Mar 2019 03:21:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 41DAC277B3; Wed, 6 Mar 2019 08:21:07 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B849C1A267 for ; Wed, 6 Mar 2019 08:21:06 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:43 +0100 Message-Id: <9fc7289fb09b161425a10d63316dab55889ac566.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 18/23] conf: Avoid formatting empty element 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 06 Mar 2019 08:21:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If none of the 'capabilities' features are enabled we'd still format the opening and closing tag for the Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 9 ++++++++- tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-cputune.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-idmap.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-memtune.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml | 3 +-- tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml | 3 +-- 12 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b42c63fb4d..90aa02a7ea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27933,8 +27933,15 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; } - virBufferAsprintf(buf, "\n", + virBufferAsprintf(buf, "features[i])); + + if (!virDomainDefHasCapabilitiesFeatures(def)) { + virBufferAddLit(buf, "/>\n"); + break; + } else { + virBufferAddLit(buf, ">\n"); + } virBufferAdjustIndent(buf, 2); for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABSENT) diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml b/tests/lxccon= f2xmldata/lxcconf2xml-blkiotune.xml index 641edb94fa..ab07fb0e80 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml @@ -25,8 +25,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml b/tests/lxcco= nf2xmldata/lxcconf2xml-cpusettune.xml index bafaa960f8..6df089d00f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml @@ -13,8 +13,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml b/tests/lxcconf2= xmldata/lxcconf2xml-cputune.xml index f7f8041dd6..359c820a2d 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml @@ -15,8 +15,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml b/tests/lxcconf2xm= ldata/lxcconf2xml-idmap.xml index dd3843d5cb..1efcc131cb 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml @@ -14,8 +14,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml b/tests/l= xcconf2xmldata/lxcconf2xml-macvlannetwork.xml index a345e8e019..cced2f25db 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml @@ -9,8 +9,7 @@ /sbin/init - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml b/tests/lxcconf2= xmldata/lxcconf2xml-memtune.xml index 57e751aaba..24af021e49 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml @@ -15,8 +15,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml b/tests/lxcc= onf2xmldata/lxcconf2xml-miscnetwork.xml index 63189cfaec..9e41e408ee 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork.xml @@ -9,8 +9,7 @@ /sbin/init - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml b/tests/lxcc= onf2xmldata/lxcconf2xml-nonenetwork.xml index 0122ab05c7..1a8e51bb56 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml @@ -9,8 +9,7 @@ /sbin/init - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml b/tests/lxccon= f2xmldata/lxcconf2xml-nonetwork.xml index 04ea280b3c..3c9f4474e5 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml @@ -10,8 +10,7 @@ - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml b/tests/lxcc= onf2xmldata/lxcconf2xml-physnetwork.xml index 4fb3f954e0..fa3cf67fc3 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml @@ -9,8 +9,7 @@ /sbin/init - - + destroy diff --git a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml b/tests/lxcc= onf2xmldata/lxcconf2xml-vlannetwork.xml index 47ed898b0f..08bea62f7f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml @@ -9,8 +9,7 @@ /sbin/init - - + destroy --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860497763201.59111910997774; Wed, 6 Mar 2019 00:21:37 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 153D4309E97C; Wed, 6 Mar 2019 08:21:36 +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 DDA9D60F8D; Wed, 6 Mar 2019 08:21:35 +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 99002181A266; Wed, 6 Mar 2019 08:21:35 +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 x268LA9O032627 for ; Wed, 6 Mar 2019 03:21:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 37EA61A91B; Wed, 6 Mar 2019 08:21:10 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B12091A267 for ; Wed, 6 Mar 2019 08:21:07 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:44 +0100 Message-Id: <841ed1d216393f5133be436d7bc0481647d73c18.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 19/23] conf: Refactor formating of 'capabilities' features 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 06 Mar 2019 08:21:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement for the formatting which allows us to avoid looking through the array to see if any feature is enabled. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 90aa02a7ea..beabbace94 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27928,30 +27928,23 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; case VIR_DOMAIN_FEATURE_CAPABILITIES: - if (def->features[i] =3D=3D VIR_DOMAIN_CAPABILITIES_POLICY_DEF= AULT && - !virDomainDefHasCapabilitiesFeatures(def)) { - break; - } + virBufferSetChildIndent(&tmpChildBuf, buf); - virBufferAsprintf(buf, "features[i])); - - if (!virDomainDefHasCapabilitiesFeatures(def)) { - virBufferAddLit(buf, "/>\n"); - break; - } else { - virBufferAddLit(buf, ">\n"); - } - virBufferAdjustIndent(buf, 2); for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABSENT) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virBufferAsprintf(&tmpChildBuf, "<%s state=3D'%s'/>\n", virDomainCapsFeatureTypeToString(j), - virTristateSwitchTypeToString( - def->caps_features[j])); + virTristateSwitchTypeToString(def->c= aps_features[j])); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + + /* the 'default' policy should be printed if any capability is= present */ + if (def->features[i] !=3D VIR_DOMAIN_CAPABILITIES_POLICY_DEFAU= LT || + virBufferUse(&tmpChildBuf)) + virBufferAsprintf(&tmpAttrBuf, " policy=3D'%s'", + virDomainCapabilitiesPolicyTypeToString(= def->features[i])); + + if (virXMLFormatElement(buf, "capabilities", &tmpAttrBuf, &tmp= ChildBuf) < 0) + return -1; break; case VIR_DOMAIN_FEATURE_GIC: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860501781328.62333388741195; Wed, 6 Mar 2019 00:21:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E97B307D874; Wed, 6 Mar 2019 08:21:40 +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 DADA31001DC5; Wed, 6 Mar 2019 08:21:39 +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 9707F181A276; Wed, 6 Mar 2019 08:21:39 +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 x268LBCu032638 for ; Wed, 6 Mar 2019 03:21:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 11E731A267; Wed, 6 Mar 2019 08:21:11 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8928227CB8 for ; Wed, 6 Mar 2019 08:21:10 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:45 +0100 Message-Id: <3afca50b23e5199523795286800cb63d0eda08a1.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 20/23] conf: Use virXMLFormatElement in virDomainDefFormatFeatures 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 06 Mar 2019 08:21:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Remove logic necessary to figure out whether to format the 'features' element by using virXMLFormatElement. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 91 +++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index beabbace94..f48b41da87 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27150,19 +27150,6 @@ virDomainPerfDefFormat(virBufferPtr buf, virDomain= PerfDefPtr perf) virBufferAddLit(buf, "\n"); } -static bool -virDomainDefHasCapabilitiesFeatures(virDomainDefPtr def) -{ - size_t i; - - for (i =3D 0; i < VIR_DOMAIN_CAPS_FEATURE_LAST; i++) { - if (def->caps_features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) - return true; - } - - return false; -} - static void virDomainSchedulerFormat(virBufferPtr buf, @@ -27747,19 +27734,10 @@ virDomainDefFormatFeatures(virBufferPtr buf, { VIR_AUTOCLEAN(virBuffer) tmpAttrBuf =3D VIR_BUFFER_INITIALIZER; VIR_AUTOCLEAN(virBuffer) tmpChildBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; size_t i; - for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { - if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ABSENT) - break; - } - - if (i =3D=3D VIR_DOMAIN_FEATURE_LAST && - !virDomainDefHasCapabilitiesFeatures(def)) - return 0; - - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + virBufferSetChildIndent(&childBuf, buf); for (i =3D 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { const char *name =3D virDomainFeatureTypeToString(i); @@ -27777,7 +27755,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; case VIR_TRISTATE_SWITCH_ON: - virBufferAsprintf(buf, "<%s/>\n", name); + virBufferAsprintf(&childBuf, "<%s/>\n", name); break; case VIR_TRISTATE_SWITCH_LAST: @@ -27803,11 +27781,11 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; case VIR_TRISTATE_SWITCH_ON: - virBufferAsprintf(buf, "<%s state=3D'on'/>\n", name); + virBufferAsprintf(&childBuf, "<%s state=3D'on'/>\n", name); break; case VIR_TRISTATE_SWITCH_OFF: - virBufferAsprintf(buf, "<%s state=3D'off'/>\n", name); + virBufferAsprintf(&childBuf, "<%s state=3D'off'/>\n", name); break; } @@ -27826,24 +27804,24 @@ virDomainDefFormatFeatures(virBufferPtr buf, unsigned long long short_size =3D virFormatIntPretty(def->= tseg_size, &unit); - virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferSetChildIndent(&tmpChildBuf, &childBuf); virBufferAsprintf(&tmpChildBuf, "%llu\n", unit, short_size); } - if (virXMLFormatElement(buf, "smm", &tmpAttrBuf, &tmpChildBuf)= < 0) + if (virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChi= ldBuf) < 0) return -1; break; case VIR_DOMAIN_FEATURE_APIC: if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { - virBufferAddLit(buf, "apic_eoi) { - virBufferAsprintf(buf, " eoi=3D'%s'", + virBufferAsprintf(&childBuf, " eoi=3D'%s'", virTristateSwitchTypeToString(def->a= pic_eoi)); } - virBufferAddLit(buf, "/>\n"); + virBufferAddLit(&childBuf, "/>\n"); } break; @@ -27851,13 +27829,13 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + virBufferAddLit(&childBuf, "\n"); + virBufferAdjustIndent(&childBuf, 2); for (j =3D 0; j < VIR_DOMAIN_HYPERV_LAST; j++) { if (def->hyperv_features[j] =3D=3D VIR_TRISTATE_SWITCH_ABS= ENT) continue; - virBufferAsprintf(buf, "<%s state=3D'%s'", + virBufferAsprintf(&childBuf, "<%s state=3D'%s'", virDomainHypervTypeToString(j), virTristateSwitchTypeToString( def->hyperv_features[j])); @@ -27880,14 +27858,14 @@ virDomainDefFormatFeatures(virBufferPtr buf, case VIR_DOMAIN_HYPERV_SPINLOCKS: if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWITCH_O= N) break; - virBufferAsprintf(buf, " retries=3D'%d'", + virBufferAsprintf(&childBuf, " retries=3D'%d'", def->hyperv_spinlocks); break; case VIR_DOMAIN_HYPERV_VENDOR_ID: if (def->hyperv_features[j] !=3D VIR_TRISTATE_SWITCH_O= N) break; - virBufferEscapeString(buf, " value=3D'%s'", + virBufferEscapeString(&childBuf, " value=3D'%s'", def->hyperv_vendor_id); break; @@ -27896,23 +27874,23 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; } - virBufferAddLit(buf, "/>\n"); + virBufferAddLit(&childBuf, "/>\n"); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(&childBuf, -2); + virBufferAddLit(&childBuf, "\n"); break; case VIR_DOMAIN_FEATURE_KVM: if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + virBufferAddLit(&childBuf, "\n"); + virBufferAdjustIndent(&childBuf, 2); for (j =3D 0; j < VIR_DOMAIN_KVM_LAST; j++) { switch ((virDomainKVM) j) { case VIR_DOMAIN_KVM_HIDDEN: if (def->kvm_features[j]) - virBufferAsprintf(buf, "<%s state=3D'%s'/>\n", + virBufferAsprintf(&childBuf, "<%s state=3D'%s'/>\n= ", virDomainKVMTypeToString(j), virTristateSwitchTypeToString( def->kvm_features[j])); @@ -27923,12 +27901,12 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; } } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(&childBuf, -2); + virBufferAddLit(&childBuf, "\n"); break; case VIR_DOMAIN_FEATURE_CAPABILITIES: - virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferSetChildIndent(&tmpChildBuf, &childBuf); for (j =3D 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) { if (def->caps_features[j] !=3D VIR_TRISTATE_SWITCH_ABSENT) @@ -27943,17 +27921,17 @@ virDomainDefFormatFeatures(virBufferPtr buf, virBufferAsprintf(&tmpAttrBuf, " policy=3D'%s'", virDomainCapabilitiesPolicyTypeToString(= def->features[i])); - if (virXMLFormatElement(buf, "capabilities", &tmpAttrBuf, &tmp= ChildBuf) < 0) + if (virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf= , &tmpChildBuf) < 0) return -1; break; case VIR_DOMAIN_FEATURE_GIC: if (def->features[i] =3D=3D VIR_TRISTATE_SWITCH_ON) { - virBufferAddLit(buf, "gic_version !=3D VIR_GIC_VERSION_NONE) - virBufferAsprintf(buf, " version=3D'%s'", + virBufferAsprintf(&childBuf, " version=3D'%s'", virGICVersionTypeToString(def->gic_v= ersion)); - virBufferAddLit(buf, "/>\n"); + virBufferAddLit(&childBuf, "/>\n"); } break; @@ -27961,7 +27939,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] =3D=3D VIR_DOMAIN_IOAPIC_NONE) break; - virBufferAsprintf(buf, "\n", + virBufferAsprintf(&childBuf, "\n", virDomainIOAPICTypeToString(def->features[i]= )); break; @@ -27975,13 +27953,13 @@ virDomainDefFormatFeatures(virBufferPtr buf, virDomainHPTResizingTypeToString(def->hp= t_resizing)); } if (def->hpt_maxpagesize > 0) { - virBufferSetChildIndent(&tmpChildBuf, buf); + virBufferSetChildIndent(&tmpChildBuf, &childBuf); virBufferAsprintf(&tmpChildBuf, "%llu\n", def->hpt_maxpagesize); } - if (virXMLFormatElement(buf, "hpt", &tmpAttrBuf, &tmpChildBuf)= < 0) + if (virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChi= ldBuf) < 0) return -1; break; @@ -27989,7 +27967,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferAsprintf(buf, "\n", + virBufferAsprintf(&childBuf, "\n", virDomainMsrsUnknownTypeToString(def->msrs_f= eatures[VIR_DOMAIN_MSRS_UNKNOWN])); break; @@ -27999,10 +27977,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, } } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - - return 0; + return virXMLFormatElement(buf, "features", NULL, &childBuf); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860483404649.7428379329268; Wed, 6 Mar 2019 00:21:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7970E30832D1; Wed, 6 Mar 2019 08:21:21 +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 45B1C1001DF0; Wed, 6 Mar 2019 08:21:21 +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 E2384181A135; Wed, 6 Mar 2019 08:21:20 +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 x268LBC0032651 for ; Wed, 6 Mar 2019 03:21:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id E28091A91B; Wed, 6 Mar 2019 08:21:11 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64E251A267 for ; Wed, 6 Mar 2019 08:21:11 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:46 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 21/23] conf: domain: Use VIR_AUTOCLEAN(virBuffer) where appropriate 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 06 Mar 2019 08:21:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 90 +++++++++++++----------------------------- 1 file changed, 28 insertions(+), 62 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f48b41da87..ea4fbf2280 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6761,8 +6761,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virDomainDeviceInfoPtr info, unsigned int flags) { - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) { @@ -6910,9 +6910,6 @@ virDomainDeviceInfoFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&attrBuf); - virBufferFreeAndReset(&childBuf); - return ret; } @@ -23738,7 +23735,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr b= uf, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) || @@ -23756,8 +23753,6 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr b= uf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); - return ret; } @@ -23843,8 +23838,8 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf, bool attrIndex, virDomainXMLOptionPtr xmlopt) { - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; virBufferSetChildIndent(&childBuf, buf); @@ -23869,8 +23864,6 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&attrBuf); - virBufferFreeAndReset(&childBuf); return ret; } @@ -24102,7 +24095,7 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) || !xmlopt || @@ -24112,16 +24105,9 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf, virBufferSetChildIndent(&childBuf, buf); if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0) - goto error; - - if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0) - goto error; - - return 0; + return -1; - error: - virBufferFreeAndReset(&childBuf); - return -1; + return virXMLFormatElement(buf, "privateData", NULL, &childBuf); } @@ -24259,7 +24245,7 @@ static int virDomainControllerDriverFormat(virBufferPtr buf, virDomainControllerDefPtr def) { - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverBuf =3D VIR_BUFFER_INITIALIZER; if (def->queues) virBufferAsprintf(&driverBuf, " queues=3D'%u'", def->queues); @@ -24454,7 +24440,7 @@ virDomainFSDefFormat(virBufferPtr buf, const char *fsdriver =3D virDomainFSDriverTypeToString(def->fsdriver); const char *wrpolicy =3D virDomainFSWrpolicyTypeToString(def->wrpolicy= ); const char *src =3D def->src->path; - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; if (!type) { @@ -24560,8 +24546,6 @@ virDomainFSDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&driverBuf); - return ret; } @@ -25382,8 +25366,8 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceDefPtr def, unsigned int flags) { - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; virBufferSetChildIndent(&childBuf, buf); @@ -25499,8 +25483,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf, return 0; error: - virBufferFreeAndReset(&attrBuf); - virBufferFreeAndReset(&childBuf); return -1; } @@ -25669,7 +25651,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf, unsigned int flags) { const char *mode =3D virDomainSmartcardTypeToString(def->type); - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; size_t i; int ret =3D -1; @@ -25727,7 +25709,6 @@ virDomainSmartcardDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); return ret; } @@ -25792,7 +25773,7 @@ virDomainSoundDefFormat(virBufferPtr buf, unsigned int flags) { const char *model =3D virDomainSoundModelTypeToString(def->model); - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; size_t i; int ret =3D -1; @@ -25825,8 +25806,6 @@ virDomainSoundDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); - return ret; } @@ -26175,7 +26154,7 @@ virDomainVideoDefFormat(virBufferPtr buf, unsigned int flags) { const char *model =3D virDomainVideoTypeToString(def->type); - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; if (!model) { @@ -26232,8 +26211,6 @@ virDomainVideoDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&driverBuf); - return ret; } @@ -27236,7 +27213,7 @@ virDomainCachetuneDefFormat(virBufferPtr buf, virDomainResctrlDefPtr resctrl, unsigned int flags) { - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; size_t i =3D 0; int ret =3D -1; VIR_AUTOFREE(char *) vcpus =3D NULL; @@ -27282,7 +27259,6 @@ virDomainCachetuneDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childrenBuf); return ret; } @@ -27306,7 +27282,7 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, virDomainResctrlDefPtr resctrl, unsigned int flags) { - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; VIR_AUTOFREE(char *) vcpus =3D NULL; @@ -27344,7 +27320,6 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childrenBuf); return ret; } @@ -27354,7 +27329,7 @@ virDomainCputuneDefFormat(virBufferPtr buf, unsigned int flags) { size_t i; - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; virBufferSetChildIndent(&childrenBuf, buf); @@ -27468,7 +27443,6 @@ virDomainCputuneDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childrenBuf); return ret; } @@ -27537,9 +27511,9 @@ static int virDomainIOMMUDefFormat(virBufferPtr buf, const virDomainIOMMUDef *iommu) { - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer driverAttrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; virBufferSetChildIndent(&childBuf, buf); @@ -27573,8 +27547,6 @@ virDomainIOMMUDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); - virBufferFreeAndReset(&driverAttrBuf); return ret; } @@ -27583,7 +27555,7 @@ static int virDomainMemtuneFormat(virBufferPtr buf, const virDomainMemtune *mem) { - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; virBufferSetChildIndent(&childBuf, buf); @@ -27637,7 +27609,6 @@ virDomainMemtuneFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); return ret; } @@ -27646,9 +27617,9 @@ static int virDomainVsockDefFormat(virBufferPtr buf, virDomainVsockDefPtr vsock) { - virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; - virBuffer cidAttrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) cidAttrBuf =3D VIR_BUFFER_INITIALIZER; int ret =3D -1; if (vsock->model) { @@ -27676,9 +27647,6 @@ virDomainVsockDefFormat(virBufferPtr buf, ret =3D 0; cleanup: - virBufferFreeAndReset(&childBuf); - virBufferFreeAndReset(&attrBuf); - virBufferFreeAndReset(&cidAttrBuf); return ret; } @@ -28544,7 +28512,7 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, virCapsPtr caps, unsigned int flags) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; int state; int reason; size_t i; @@ -28578,7 +28546,6 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, return virBufferContentAndReset(&buf); error: - virBufferFreeAndReset(&buf); return NULL; } @@ -29530,7 +29497,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, virCapsPtr caps, virDomainXMLOptionPtr xmlopt) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; int flags =3D VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_S= ECURE; int rc =3D -1; char *netprefix; @@ -30005,7 +29972,7 @@ virDomainGetBlkioParametersAssignFromDef(virDomainD= efPtr def, int *nparams, int maxparams) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; char *data =3D NULL; size_t i; @@ -30045,7 +30012,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainD= efPtr def, error: VIR_FREE(data); - virBufferFreeAndReset(&buf); return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860486968985.7660752049259; Wed, 6 Mar 2019 00:21:26 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EA1181E08; Wed, 6 Mar 2019 08:21:25 +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 00A9F5D78F; Wed, 6 Mar 2019 08:21:24 +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 A8182181A26C; Wed, 6 Mar 2019 08:21:24 +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 x268LC6k032658 for ; Wed, 6 Mar 2019 03:21:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id BB85A1A91B; Wed, 6 Mar 2019 08:21:12 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FA511A267 for ; Wed, 6 Mar 2019 08:21:12 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:47 +0100 Message-Id: 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 Subject: [libvirt] [PATCH 22/23] conf: Move XPath context node in descendants of virSysinfoParseXML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Mar 2019 08:21:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than moving the XPath root node in the caller and then still passing it down, make sure that the callees move the node themselves. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ea4fbf2280..bbeb1c1a8d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14606,9 +14606,12 @@ virSysinfoBIOSParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoBIOSDefPtr *bios) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoBIOSDefPtr def; + ctxt->node =3D node; + if (!virXMLNodeNameEqual(node, "bios")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'bios' element")); @@ -14666,10 +14669,13 @@ virSysinfoSystemParseXML(xmlNodePtr node, unsigned char *domUUID, bool uuid_generated) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoSystemDefPtr def; VIR_AUTOFREE(char *) tmpUUID =3D NULL; + ctxt->node =3D node; + if (!virXMLNodeNameEqual(node, "system")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'system' element")= ); @@ -14786,15 +14792,19 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ct= xt, static int -virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt, +virSysinfoOEMStringsParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, virSysinfoOEMStringsDefPtr *oem) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoOEMStringsDefPtr def; int nstrings; size_t i; VIR_AUTOFREE(xmlNodePtr *) strings =3D NULL; + ctxt->node =3D node; + nstrings =3D virXPathNodeSet("./entry", ctxt, &strings); if (nstrings < 0) return -1; @@ -14824,9 +14834,12 @@ virSysinfoChassisParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoChassisDefPtr *chassisdef) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoChassisDefPtr def; + ctxt->node =3D node; + if (!xmlStrEqual(node->name, BAD_CAST "chassis")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'chassis' element"= )); @@ -14868,7 +14881,7 @@ virSysinfoParseXML(xmlNodePtr node, bool uuid_generated) { virSysinfoDefPtr def; - xmlNodePtr oldnode, tmpnode; + xmlNodePtr tmpnode; VIR_AUTOFREE(char *) type =3D NULL; if (!virXMLNodeNameEqual(node, "sysinfo")) { @@ -14894,25 +14907,15 @@ virSysinfoParseXML(xmlNodePtr node, /* Extract BIOS related metadata */ if ((tmpnode =3D virXPathNode("./bios[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system related metadata */ if ((tmpnode =3D virXPathNode("./system[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system, - domUUID, uuid_generated) < 0) { - ctxt->node =3D oldnode; + domUUID, uuid_generated) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system base board metadata */ @@ -14921,24 +14924,14 @@ virSysinfoParseXML(xmlNodePtr node, /* Extract chassis related metadata */ if ((tmpnode =3D virXPathNode("./chassis[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system related metadata */ if ((tmpnode =3D virXPathNode("./oemStrings[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoOEMStringsParseXML(ctxt, &def->oemStrings) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) = < 0) goto error; - } - ctxt->node =3D oldnode; } cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 21:30:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15518604907466.388253957934353; Wed, 6 Mar 2019 00:21:30 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 0714181E00; Wed, 6 Mar 2019 08:21:29 +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 C1B5460145; Wed, 6 Mar 2019 08:21:28 +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 7BAFD181A270; Wed, 6 Mar 2019 08:21: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 x268LDD6032663 for ; Wed, 6 Mar 2019 03:21:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 954B71A91B; Wed, 6 Mar 2019 08:21:13 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18C491A267 for ; Wed, 6 Mar 2019 08:21:12 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:48 +0100 Message-Id: <32fbcb528578a5a3673c341f0c0d8ab9341f0162.1551859940.git.pkrempa@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 Subject: [libvirt] [PATCH 23/23] conf: domain: Use VIR_XPATH_NODE_AUTORESTORE where appropriate 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Mar 2019 08:21:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 131 +++++++++++++---------------------------- 1 file changed, 42 insertions(+), 89 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bbeb1c1a8d..eb660f5764 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8109,11 +8109,10 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { virNetDevCoalescePtr ret =3D NULL; - xmlNodePtr save =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned long long tmp =3D 0; VIR_AUTOFREE(char *) str =3D NULL; - save =3D ctxt->node; ctxt->node =3D node; str =3D virXPathString("string(./rx/frames/@max)", ctxt); @@ -8140,7 +8139,6 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, ret->rx_max_coalesced_frames =3D tmp; cleanup: - ctxt->node =3D save; return ret; error: @@ -8512,16 +8510,15 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, virCapsPtr caps, unsigned int flags) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); size_t i =3D 0, j; int n; - xmlNodePtr saved_node; virCapsHostPtr host =3D &caps->host; VIR_AUTOFREE(xmlNodePtr *) list =3D NULL; /* Check args and save context */ if (def =3D=3D NULL || ctxt =3D=3D NULL) return 0; - saved_node =3D ctxt->node; /* Allocate a security labels based on XML */ if ((n =3D virXPathNodeSet("./seclabel", ctxt, &list)) < 0) @@ -8553,7 +8550,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, def->seclabels[i] =3D seclabel; } def->nseclabels =3D n; - ctxt->node =3D saved_node; /* libvirt versions prior to 0.10.0 support just a single seclabel ele= ment * in guest's XML and model attribute can be suppressed if type is non= e or @@ -8603,7 +8599,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, return 0; error: - ctxt->node =3D saved_node; for (; i > 0; i--) virSecurityLabelDefFree(def->seclabels[i - 1]); VIR_FREE(def->seclabels); @@ -8940,7 +8935,7 @@ virDomainDiskSourcePrivateDataParse(xmlNodePtr node, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - xmlNodePtr saveNode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; if (!(flags & VIR_DOMAIN_DEF_PARSE_STATUS) || @@ -8960,8 +8955,6 @@ virDomainDiskSourcePrivateDataParse(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D saveNode; - return ret; } @@ -8971,7 +8964,7 @@ virDomainDiskSourcePRParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virStoragePRDefPtr *pr) { - xmlNodePtr saveNode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; ctxt->node =3D node; @@ -8986,7 +8979,6 @@ virDomainDiskSourcePRParse(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D saveNode; return ret; } @@ -8998,7 +8990,7 @@ virDomainStorageSourceParse(xmlNodePtr node, unsigned int flags) { int ret =3D -1; - xmlNodePtr saveNode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr tmp; ctxt->node =3D node; @@ -9053,7 +9045,6 @@ virDomainStorageSourceParse(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D saveNode; return ret; } @@ -9081,7 +9072,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - xmlNodePtr save_ctxt =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr source; int ret =3D -1; VIR_AUTOUNREF(virStorageSourcePtr) backingStore =3D NULL; @@ -9148,7 +9139,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, ret =3D 0; cleanup: - ctxt->node =3D save_ctxt; return ret; } @@ -9627,7 +9617,7 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr c= txt, virDomainXMLOptionPtr xmlopt) { xmlNodePtr private_node =3D virXPathNode("./privateData", ctxt); - xmlNodePtr save_node =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; if (!xmlopt || @@ -9643,7 +9633,6 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr c= txt, ret =3D 0; cleanup: - ctxt->node =3D save_node; return ret; } @@ -9664,7 +9653,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, { virDomainDiskDefPtr def; xmlNodePtr cur; - xmlNodePtr save_ctxt =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); bool source =3D false; virStorageEncryptionPtr encryption =3D NULL; VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; @@ -10081,7 +10070,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlo= pt, cleanup: virStorageEncryptionFree(encryption); - ctxt->node =3D save_ctxt; return def; error: @@ -10367,7 +10355,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPt= r xmlopt, bool processedTarget =3D false; int numaNode =3D -1; int ports =3D -1; - xmlNodePtr saved =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int rc; VIR_AUTOFREE(char *) typeStr =3D NULL; VIR_AUTOFREE(char *) idx =3D NULL; @@ -10695,7 +10683,6 @@ virDomainControllerDefParseXML(virDomainXMLOptionPt= r xmlopt, } cleanup: - ctxt->node =3D saved; return def; error: @@ -10722,8 +10709,9 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainFSDefPtr def; - xmlNodePtr cur, save_node =3D ctxt->node; + xmlNodePtr cur; VIR_AUTOFREE(char *) type =3D NULL; VIR_AUTOFREE(char *) fsdriver =3D NULL; VIR_AUTOFREE(char *) source =3D NULL; @@ -10888,7 +10876,6 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - ctxt->node =3D save_node; return def; error: @@ -10906,7 +10893,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, { virDomainActualNetDefPtr actual =3D NULL; int ret =3D -1; - xmlNodePtr save_ctxt =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr bandwidth_node =3D NULL; xmlNodePtr vlanNode; xmlNodePtr virtPortNode; @@ -11066,7 +11053,6 @@ virDomainActualNetDefParseXML(xmlNodePtr node, error: virDomainActualNetDefFree(actual); - ctxt->node =3D save_ctxt; return ret; } @@ -11106,7 +11092,7 @@ virDomainChrSourceReconnectDefParseXML(virDomainChr= SourceReconnectDefPtr def, { int ret =3D -1; int tmpVal; - xmlNodePtr saveNode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr cur; VIR_AUTOFREE(char *) tmp =3D NULL; @@ -11143,7 +11129,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChr= SourceReconnectDefPtr def, ret =3D 0; cleanup: - ctxt->node =3D saveNode; return ret; } @@ -11165,7 +11150,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, xmlNodePtr tmpNode; virHashTablePtr filterparams =3D NULL; virDomainActualNetDefPtr actual =3D NULL; - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainChrSourceReconnectDef reconnect =3D {0}; int rv, val; VIR_AUTOFREE(char *) macaddr =3D NULL; @@ -11949,7 +11934,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, } cleanup: - ctxt->node =3D oldnode; virDomainActualNetDefFree(actual); virHashFree(filterparams); return def; @@ -12829,7 +12813,7 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, unsigned int flags) { virDomainTPMDefPtr def; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int nbackends; VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) model =3D NULL; @@ -12908,7 +12892,6 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; cleanup: - ctxt->node =3D save; return def; error: @@ -12957,7 +12940,7 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xml= opt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainInputDefPtr def; VIR_AUTOFREE(char *) evdev =3D NULL; VIR_AUTOFREE(char *) type =3D NULL; @@ -13099,7 +13082,6 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xml= opt, goto error; cleanup: - ctxt->node =3D save; return def; error: @@ -13154,7 +13136,7 @@ virDomainTimerDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { virDomainTimerDefPtr def; - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr catchup; int ret; VIR_AUTOFREE(char *) name =3D NULL; @@ -13264,8 +13246,6 @@ virDomainTimerDefParseXML(xmlNodePtr node, } cleanup: - ctxt->node =3D oldnode; - return def; error: @@ -13508,7 +13488,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainGraphicsListenDef newListen =3D {0}; int nListens; int ret =3D -1; @@ -13579,7 +13559,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, ret =3D 0; cleanup: virDomainGraphicsListenDefClear(&newListen); - ctxt->node =3D save; return ret; } @@ -13668,7 +13647,7 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDe= fPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int enableVal; xmlNodePtr glNode; int ret =3D -1; @@ -13714,7 +13693,6 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDe= fPtr def, ret =3D 0; cleanup: - ctxt->node =3D save; return ret; } @@ -14069,7 +14047,7 @@ virDomainGraphicsDefParseXMLEGLHeadless(virDomainGr= aphicsDefPtr def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr glNode; ctxt->node =3D node; @@ -14077,7 +14055,6 @@ virDomainGraphicsDefParseXMLEGLHeadless(virDomainGr= aphicsDefPtr def, if ((glNode =3D virXPathNode("./gl", ctxt))) def->data.egl_headless.rendernode =3D virXMLPropString(glNode, "rendernode"); - ctxt->node =3D save; return 0; } @@ -14200,7 +14177,7 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xml= opt, unsigned int flags) { virDomainSoundDefPtr def; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) model =3D NULL; if (VIR_ALLOC(def) < 0) @@ -14246,7 +14223,6 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xml= opt, goto error; cleanup: - ctxt->node =3D save; return def; error: @@ -14313,7 +14289,7 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlop= t, unsigned int flags) { virDomainRNGDefPtr def; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int nbackends; VIR_AUTOFREE(xmlNodePtr *) backends =3D NULL; VIR_AUTOFREE(char *) model =3D NULL; @@ -14410,7 +14386,6 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; cleanup: - ctxt->node =3D save; return def; error: @@ -14427,7 +14402,7 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPt= r xmlopt, unsigned int flags) { virDomainMemballoonDefPtr def; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int period =3D 0; VIR_AUTOFREE(char *) model =3D NULL; VIR_AUTOFREE(char *) deflate =3D NULL; @@ -14477,7 +14452,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPt= r xmlopt, goto error; cleanup: - ctxt->node =3D save; return def; error: @@ -14515,7 +14489,7 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xml= opt, virDomainShmemDefPtr def =3D NULL; virDomainShmemDefPtr ret =3D NULL; xmlNodePtr msi =3D NULL; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr server =3D NULL; VIR_AUTOFREE(char *) tmp =3D NULL; @@ -14596,7 +14570,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xml= opt, VIR_STEAL_PTR(ret, def); cleanup: - ctxt->node =3D save; virDomainShmemDefFree(def); return ret; } @@ -14745,7 +14718,7 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, { int ret =3D -1; size_t i, nboards =3D 0; - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); int n; VIR_AUTOFREE(virSysinfoBaseBoardDefPtr) boards =3D NULL; VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; @@ -14786,7 +14759,6 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, *nbaseBoard =3D nboards; ret =3D 0; cleanup: - ctxt->node =3D oldnode; return ret; } @@ -15117,7 +15089,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xml= opt, { virDomainVideoDefPtr def; xmlNodePtr cur; - xmlNodePtr saved =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) type =3D NULL; VIR_AUTOFREE(char *) heads =3D NULL; VIR_AUTOFREE(char *) vram =3D NULL; @@ -15230,7 +15202,6 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xml= opt, def->driver =3D virDomainVideoDriverDefParseXML(node); cleanup: - ctxt->node =3D saved; return def; error: @@ -15246,7 +15217,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, unsigned int flags) { virDomainHostdevDefPtr def; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) mode =3D virXMLPropString(node, "mode"); VIR_AUTOFREE(char *) type =3D virXMLPropString(node, "type"); @@ -15307,7 +15278,6 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, } cleanup: - ctxt->node =3D save; return def; error: @@ -15522,7 +15492,7 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, { int n; size_t i; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainRedirFilterDefPtr def =3D NULL; VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; @@ -15545,7 +15515,6 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, def->usbdevs[def->nusbdevs++] =3D usbdev; } - ctxt->node =3D save; return def; error: @@ -15662,7 +15631,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, virDomainMemoryDefPtr def) { int ret =3D -1; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node =3D node; VIR_AUTOFREE(char *) nodemask =3D NULL; @@ -15709,7 +15678,6 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D save; return ret; } @@ -15720,7 +15688,7 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, virDomainMemoryDefPtr def) { int ret =3D -1; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); ctxt->node =3D node; int rv; @@ -15762,7 +15730,6 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D save; return ret; } @@ -15771,7 +15738,7 @@ static virDomainSEVDefPtr virDomainSEVDefParseXML(xmlNodePtr sevNode, xmlXPathContextPtr ctxt) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainSEVDefPtr def; unsigned long policy; VIR_AUTOFREE(char *) type =3D NULL; @@ -15824,7 +15791,6 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, def->session =3D virXPathString("string(./session)", ctxt); cleanup: - ctxt->node =3D save; return def; error: @@ -15839,7 +15805,7 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xm= lopt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr node; virDomainMemoryDefPtr def; int val; @@ -15903,12 +15869,10 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr = xmlopt, &def->info, flags) < 0) goto error; - ctxt->node =3D save; return def; error: virDomainMemoryDefFree(def); - ctxt->node =3D save; return NULL; } @@ -15918,7 +15882,7 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { virDomainIOMMUDefPtr ret =3D NULL; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr driver; int val; VIR_AUTOFREE(char *) tmp =3D NULL; @@ -15982,7 +15946,6 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, VIR_STEAL_PTR(ret, iommu); cleanup: - ctxt->node =3D save; return ret; } @@ -15994,7 +15957,7 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xml= opt, unsigned int flags) { virDomainVsockDefPtr ret =3D NULL; - xmlNodePtr save =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); xmlNodePtr cid; int val; VIR_AUTOFREE(char *) tmp =3D NULL; @@ -16046,7 +16009,6 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xml= opt, VIR_STEAL_PTR(ret, vsock); cleanup: - ctxt->node =3D save; return ret; } @@ -17770,7 +17732,7 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, { size_t i; virDomainIdMapEntryPtr idmap =3D NULL; - xmlNodePtr save_ctxt =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); if (VIR_ALLOC_N(idmap, num) < 0) goto cleanup; @@ -17799,7 +17761,6 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, } cleanup: - ctxt->node =3D save_ctxt; return idmap; } @@ -18175,7 +18136,7 @@ virDomainHugepagesParseXML(xmlNodePtr node, virDomainHugePagePtr hugepage) { int ret =3D -1; - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_AUTOFREE(char *) nodeset =3D NULL; ctxt->node =3D node; @@ -18204,7 +18165,6 @@ virDomainHugepagesParseXML(xmlNodePtr node, ret =3D 0; cleanup: - ctxt->node =3D oldnode; return ret; } @@ -18213,8 +18173,8 @@ static virDomainResourceDefPtr virDomainResourceDefParse(xmlNodePtr node, xmlXPathContextPtr ctxt) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResourceDefPtr def =3D NULL; - xmlNodePtr tmp =3D ctxt->node; ctxt->node =3D node; @@ -18228,11 +18188,9 @@ virDomainResourceDefParse(xmlNodePtr node, goto error; } - ctxt->node =3D tmp; return def; error: - ctxt->node =3D tmp; virDomainResourceDefFree(def); return NULL; } @@ -18797,7 +18755,7 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, xmlNodePtr node, virResctrlAllocPtr alloc) { - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int level; unsigned int cache; int type; @@ -18859,7 +18817,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, ret =3D 0; cleanup: - ctxt->node =3D oldnode; return ret; } @@ -18931,7 +18888,7 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, virDomainResctrlDefPtr resctrl) { virDomainResctrlMonDefPtr domresmon =3D NULL; - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int level =3D 0; size_t i =3D 0; int n =3D 0; @@ -19026,7 +18983,6 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, ret =3D 0; cleanup: - ctxt->node =3D oldnode; virDomainResctrlMonDefFree(domresmon); return ret; } @@ -19089,7 +19045,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, xmlNodePtr node, unsigned int flags) { - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResctrlDefPtr resctrl =3D NULL; ssize_t i =3D 0; int n; @@ -19153,7 +19109,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, ret =3D 0; cleanup: - ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); return ret; } @@ -19246,7 +19201,7 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPt= r ctxt, xmlNodePtr node, virResctrlAllocPtr alloc) { - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); unsigned int id; unsigned int bandwidth; int ret =3D -1; @@ -19285,7 +19240,6 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPt= r ctxt, ret =3D 0; cleanup: - ctxt->node =3D oldnode; return ret; } @@ -19296,7 +19250,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, xmlNodePtr node, unsigned int flags) { - xmlNodePtr oldnode =3D ctxt->node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResctrlDefPtr resctrl =3D NULL; VIR_AUTOPTR(virBitmap) vcpus =3D NULL; VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; @@ -19356,7 +19310,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ret =3D 0; cleanup: - ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list