From nobody Sat Feb 7 12:19:27 2026 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 154760136957426.42069055971274; Tue, 15 Jan 2019 17:16:09 -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 3FF4C637EE; Wed, 16 Jan 2019 01:16:07 +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 E83E610640FD; Wed, 16 Jan 2019 01:16:06 +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 419FF1803397; Wed, 16 Jan 2019 01:16:06 +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 x0G1Ftl9022721 for ; Tue, 15 Jan 2019 20:15:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 93B9019940; Wed, 16 Jan 2019 01:15:55 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-153.phx2.redhat.com [10.3.116.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3049C19C7C for ; Wed, 16 Jan 2019 01:15:55 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:43 -0500 Message-Id: <20190116011549.16309-2-jferlan@redhat.com> In-Reply-To: <20190116011549.16309-1-jferlan@redhat.com> References: <20190116011549.16309-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] conf: Extract host XML formatting from virCapabilitiesFormatXML 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.28]); Wed, 16 Jan 2019 01:16:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's extract out the code into it's own method/helper. NB: One minor change between the two is usage of "buf" instead of "&buf" in the new code since we pass the address of &buf to the helper. Signed-off-by: John Ferlan --- src/conf/capabilities.c | 135 ++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 59 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 8e9bba0dbe..33c0c37fbf 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1056,130 +1056,147 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr= buf, return 0; } =20 -/** - * virCapabilitiesFormatXML: - * @caps: capabilities to format - * - * Convert the capabilities object into an XML representation - * - * Returns the XML document as a string - */ -char * -virCapabilitiesFormatXML(virCapsPtr caps) + +static int +virCapabilitiesFormatHostXML(virCapsPtr caps, + virBufferPtr buf) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - size_t i, j, k; + size_t i, j; char host_uuid[VIR_UUID_STRING_BUFLEN]; =20 - virBufferAddLit(&buf, "\n\n"); - virBufferAdjustIndent(&buf, 2); - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); if (virUUIDIsValid(caps->host.host_uuid)) { virUUIDFormat(caps->host.host_uuid, host_uuid); - virBufferAsprintf(&buf, "%s\n", host_uuid); + virBufferAsprintf(buf, "%s\n", host_uuid); } - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); =20 if (caps->host.arch) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", virArchToString(caps->host.arch)); if (caps->host.nfeatures) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); for (i =3D 0; i < caps->host.nfeatures; i++) { - virBufferAsprintf(&buf, "<%s/>\n", + virBufferAsprintf(buf, "<%s/>\n", caps->host.features[i]); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virCPUDefFormatBuf(&buf, caps->host.cpu); + virCPUDefFormatBuf(buf, caps->host.cpu); =20 for (i =3D 0; i < caps->host.nPagesSize; i++) { - virBufferAsprintf(&buf, "\n", + virBufferAsprintf(buf, "\n", caps->host.pagesSize[i]); } =20 - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); =20 /* The PM query was successful. */ if (caps->host.powerMgmt) { /* The host supports some PM features. */ unsigned int pm =3D caps->host.powerMgmt; - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); while (pm) { int bit =3D ffs(pm) - 1; - virBufferAsprintf(&buf, "<%s/>\n", + virBufferAsprintf(buf, "<%s/>\n", virCapsHostPMTargetTypeToString(bit)); pm &=3D ~(1U << bit); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } else { /* The host does not support any PM feature. */ - virBufferAddLit(&buf, "\n"); + virBufferAddLit(buf, "\n"); } =20 - virBufferAsprintf(&buf, "\n", + virBufferAsprintf(buf, "\n", caps->host.iommu ? "yes" : "no"); =20 if (caps->host.offlineMigrate) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); if (caps->host.liveMigrate) - virBufferAddLit(&buf, "\n"); + virBufferAddLit(buf, "\n"); if (caps->host.nmigrateTrans) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); for (i =3D 0; i < caps->host.nmigrateTrans; i++) { - virBufferAsprintf(&buf, "%s= \n", + virBufferAsprintf(buf, "%s\= n", caps->host.migrateTrans[i]); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } =20 if (caps->host.netprefix) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->host.netprefix); =20 if (caps->host.nnumaCell && - virCapabilitiesFormatNUMATopology(&buf, caps->host.nnumaCell, + virCapabilitiesFormatNUMATopology(buf, caps->host.nnumaCell, caps->host.numaCell) < 0) goto error; =20 - if (virCapabilitiesFormatCaches(&buf, &caps->host.cache) < 0) + if (virCapabilitiesFormatCaches(buf, &caps->host.cache) < 0) goto error; =20 - if (virCapabilitiesFormatMemoryBandwidth(&buf, &caps->host.memBW) < 0) + if (virCapabilitiesFormatMemoryBandwidth(buf, &caps->host.memBW) < 0) goto error; =20 for (i =3D 0; i < caps->host.nsecModels; i++) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "%s\n", + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "%s\n", caps->host.secModels[i].model); - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->host.secModels[i].doi); for (j =3D 0; j < caps->host.secModels[i].nlabels; j++) { - virBufferAsprintf(&buf, "%s= \n", + virBufferAsprintf(buf, "%s\= n", caps->host.secModels[i].labels[j].type, caps->host.secModels[i].labels[j].label); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } =20 - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n\n"); + + return 0; + + error: + return -1; +} + + +/** + * virCapabilitiesFormatXML: + * @caps: capabilities to format + * + * Convert the capabilities object into an XML representation + * + * Returns the XML document as a string + */ +char * +virCapabilitiesFormatXML(virCapsPtr caps) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + size_t i, j, k; =20 + virBufferAddLit(&buf, "\n\n"); + virBufferAdjustIndent(&buf, 2); + + if (virCapabilitiesFormatHostXML(caps, &buf) < 0) + goto error; =20 for (i =3D 0; i < caps->nguests; i++) { virBufferAddLit(&buf, "\n"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list