From nobody Wed May 8 09:53:11 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 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 From nobody Wed May 8 09:53:11 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 154760136216078.5169967634721; Tue, 15 Jan 2019 17:16:02 -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 463B25D68A; Wed, 16 Jan 2019 01:16:00 +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 EEAD76092D; Wed, 16 Jan 2019 01:15:59 +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 7AC181803390; Wed, 16 Jan 2019 01:15:59 +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 x0G1FuaM022727 for ; Tue, 15 Jan 2019 20:15:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1305219940; Wed, 16 Jan 2019 01:15:56 +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 C021E19C7C 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:44 -0500 Message-Id: <20190116011549.16309-3-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 2/7] conf: Alter virCapabilitiesFormatHostXML to take virCapsHostPtr 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.39]); Wed, 16 Jan 2019 01:16:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than deref off of "caps->host.", let's pass "&caps->host" and make the helper use "host->" instead. Signed-off-by: John Ferlan --- src/conf/capabilities.c | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 33c0c37fbf..863cd06a8d 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1058,7 +1058,7 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, =20 =20 static int -virCapabilitiesFormatHostXML(virCapsPtr caps, +virCapabilitiesFormatHostXML(virCapsHostPtr host, virBufferPtr buf) { size_t i, j; @@ -1066,40 +1066,40 @@ virCapabilitiesFormatHostXML(virCapsPtr caps, =20 virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - if (virUUIDIsValid(caps->host.host_uuid)) { - virUUIDFormat(caps->host.host_uuid, host_uuid); + if (virUUIDIsValid(host->host_uuid)) { + virUUIDFormat(host->host_uuid, host_uuid); virBufferAsprintf(buf, "%s\n", host_uuid); } virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); =20 - if (caps->host.arch) + if (host->arch) virBufferAsprintf(buf, "%s\n", - virArchToString(caps->host.arch)); - if (caps->host.nfeatures) { + virArchToString(host->arch)); + if (host->nfeatures) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < caps->host.nfeatures; i++) { + for (i =3D 0; i < host->nfeatures; i++) { virBufferAsprintf(buf, "<%s/>\n", - caps->host.features[i]); + host->features[i]); } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } - virCPUDefFormatBuf(buf, caps->host.cpu); + virCPUDefFormatBuf(buf, host->cpu); =20 - for (i =3D 0; i < caps->host.nPagesSize; i++) { + for (i =3D 0; i < host->nPagesSize; i++) { virBufferAsprintf(buf, "\n", - caps->host.pagesSize[i]); + host->pagesSize[i]); } =20 virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); =20 /* The PM query was successful. */ - if (caps->host.powerMgmt) { + if (host->powerMgmt) { /* The host supports some PM features. */ - unsigned int pm =3D caps->host.powerMgmt; + unsigned int pm =3D host->powerMgmt; virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); while (pm) { @@ -1116,19 +1116,19 @@ virCapabilitiesFormatHostXML(virCapsPtr caps, } =20 virBufferAsprintf(buf, "\n", - caps->host.iommu ? "yes" : "no"); + host->iommu ? "yes" : "no"); =20 - if (caps->host.offlineMigrate) { + if (host->offlineMigrate) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - if (caps->host.liveMigrate) + if (host->liveMigrate) virBufferAddLit(buf, "\n"); - if (caps->host.nmigrateTrans) { + if (host->nmigrateTrans) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < caps->host.nmigrateTrans; i++) { + for (i =3D 0; i < host->nmigrateTrans; i++) { virBufferAsprintf(buf, "%s\= n", - caps->host.migrateTrans[i]); + host->migrateTrans[i]); } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -1137,32 +1137,32 @@ virCapabilitiesFormatHostXML(virCapsPtr caps, virBufferAddLit(buf, "\n"); } =20 - if (caps->host.netprefix) + if (host->netprefix) virBufferAsprintf(buf, "%s\n", - caps->host.netprefix); + host->netprefix); =20 - if (caps->host.nnumaCell && - virCapabilitiesFormatNUMATopology(buf, caps->host.nnumaCell, - caps->host.numaCell) < 0) + if (host->nnumaCell && + virCapabilitiesFormatNUMATopology(buf, host->nnumaCell, + host->numaCell) < 0) goto error; =20 - if (virCapabilitiesFormatCaches(buf, &caps->host.cache) < 0) + if (virCapabilitiesFormatCaches(buf, &host->cache) < 0) goto error; =20 - if (virCapabilitiesFormatMemoryBandwidth(buf, &caps->host.memBW) < 0) + if (virCapabilitiesFormatMemoryBandwidth(buf, &host->memBW) < 0) goto error; =20 - for (i =3D 0; i < caps->host.nsecModels; i++) { + for (i =3D 0; i < host->nsecModels; i++) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "%s\n", - caps->host.secModels[i].model); + host->secModels[i].model); virBufferAsprintf(buf, "%s\n", - caps->host.secModels[i].doi); - for (j =3D 0; j < caps->host.secModels[i].nlabels; j++) { + host->secModels[i].doi); + for (j =3D 0; j < host->secModels[i].nlabels; j++) { virBufferAsprintf(buf, "%s\= n", - caps->host.secModels[i].labels[j].type, - caps->host.secModels[i].labels[j].label); + host->secModels[i].labels[j].type, + host->secModels[i].labels[j].label); } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -1195,7 +1195,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAddLit(&buf, "\n\n"); virBufferAdjustIndent(&buf, 2); =20 - if (virCapabilitiesFormatHostXML(caps, &buf) < 0) + if (virCapabilitiesFormatHostXML(&caps->host, &buf) < 0) goto error; =20 for (i =3D 0; i < caps->nguests; i++) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 09:53:11 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 15476013621771002.2717348402317; Tue, 15 Jan 2019 17:16:02 -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 5AD724E8B7; Wed, 16 Jan 2019 01:16:00 +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 0F4035D978; Wed, 16 Jan 2019 01:16:00 +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 AB8261803393; Wed, 16 Jan 2019 01:15:59 +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 x0G1FuPN022735 for ; Tue, 15 Jan 2019 20:15:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8374C19940; Wed, 16 Jan 2019 01:15:56 +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 3E03719C7C for ; Wed, 16 Jan 2019 01:15:56 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:45 -0500 Message-Id: <20190116011549.16309-4-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 3/7] conf: Extract guest 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.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.38]); Wed, 16 Jan 2019 01:16:01 +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 | 112 ++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 863cd06a8d..c320c0f72d 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1178,91 +1178,77 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, } =20 =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 void +virCapabilitiesFormatGuestXML(virCapsPtr caps, + virBufferPtr buf) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i, j, k; =20 - virBufferAddLit(&buf, "\n\n"); - virBufferAdjustIndent(&buf, 2); - - if (virCapabilitiesFormatHostXML(&caps->host, &buf) < 0) - goto error; - for (i =3D 0; i < caps->nguests; i++) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "%s\n", + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "%s\n", virDomainOSTypeToString(caps->guests[i]->ostype)= ); if (caps->guests[i]->arch.id) - virBufferAsprintf(&buf, "\n", + virBufferAsprintf(buf, "\n", virArchToString(caps->guests[i]->arch.id)); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "%d\n", + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "%d\n", caps->guests[i]->arch.wordsize); if (caps->guests[i]->arch.defaultInfo.emulator) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->guests[i]->arch.defaultInfo.emulator); if (caps->guests[i]->arch.defaultInfo.loader) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->guests[i]->arch.defaultInfo.loader); =20 for (j =3D 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++= ) { virCapsGuestMachinePtr machine =3D caps->guests[i]->arch.defau= ltInfo.machines[j]; - virBufferAddLit(&buf, "canonical) - virBufferAsprintf(&buf, " canonical=3D'%s'", machine->cano= nical); + virBufferAsprintf(buf, " canonical=3D'%s'", machine->canon= ical); if (machine->maxCpus > 0) - virBufferAsprintf(&buf, " maxCpus=3D'%d'", machine->maxCpu= s); - virBufferAsprintf(&buf, ">%s\n", machine->name); + virBufferAsprintf(buf, " maxCpus=3D'%d'", machine->maxCpus= ); + virBufferAsprintf(buf, ">%s\n", machine->name); } =20 for (j =3D 0; j < caps->guests[i]->arch.ndomains; j++) { - virBufferAsprintf(&buf, "guests[i]->arch.domains[j]= ->type)); if (!caps->guests[i]->arch.domains[j]->info.emulator && !caps->guests[i]->arch.domains[j]->info.loader && !caps->guests[i]->arch.domains[j]->info.nmachines) { - virBufferAddLit(&buf, "/>\n"); + virBufferAddLit(buf, "/>\n"); continue; } - virBufferAddLit(&buf, ">\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); if (caps->guests[i]->arch.domains[j]->info.emulator) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->guests[i]->arch.domains[j]->info.e= mulator); if (caps->guests[i]->arch.domains[j]->info.loader) - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", caps->guests[i]->arch.domains[j]->info.l= oader); =20 for (k =3D 0; k < caps->guests[i]->arch.domains[j]->info.nmach= ines; k++) { virCapsGuestMachinePtr machine =3D caps->guests[i]->arch.d= omains[j]->info.machines[k]; - virBufferAddLit(&buf, "canonical) - virBufferAsprintf(&buf, " canonical=3D'%s'", machine->= canonical); + virBufferAsprintf(buf, " canonical=3D'%s'", machine->c= anonical); if (machine->maxCpus > 0) - virBufferAsprintf(&buf, " maxCpus=3D'%d'", machine->ma= xCpus); - virBufferAsprintf(&buf, ">%s\n", machine->name); + virBufferAsprintf(buf, " maxCpus=3D'%d'", machine->max= Cpus); + virBufferAsprintf(buf, ">%s\n", machine->name); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } =20 - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); =20 if (caps->guests[i]->nfeatures) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); =20 for (j =3D 0; j < caps->guests[i]->nfeatures; j++) { if (STREQ(caps->guests[i]->features[j]->name, "pae") || @@ -1270,22 +1256,46 @@ virCapabilitiesFormatXML(virCapsPtr caps) STREQ(caps->guests[i]->features[j]->name, "ia64_be") || STREQ(caps->guests[i]->features[j]->name, "cpuselectio= n") || STREQ(caps->guests[i]->features[j]->name, "deviceboot"= )) { - virBufferAsprintf(&buf, "<%s/>\n", + virBufferAsprintf(buf, "<%s/>\n", caps->guests[i]->features[j]->name); } else { - virBufferAsprintf(&buf, "<%s default=3D'%s' toggle=3D'= %s'/>\n", + virBufferAsprintf(buf, "<%s default=3D'%s' toggle=3D'%= s'/>\n", caps->guests[i]->features[j]->name, caps->guests[i]->features[j]->defaul= tOn ? "on" : "off", caps->guests[i]->features[j]->toggle= ? "yes" : "no"); } } =20 - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n\n"); } +} + + +/** + * 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; + + virBufferAddLit(&buf, "\n\n"); + virBufferAdjustIndent(&buf, 2); + + if (virCapabilitiesFormatHostXML(&caps->host, &buf) < 0) + goto error; + + virCapabilitiesFormatGuestXML(caps, &buf); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 09:53:11 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 1547601370061261.3108717771014; Tue, 15 Jan 2019 17:16:10 -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 3EAE8C057E00; Wed, 16 Jan 2019 01:16: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 F3A2810640FC; Wed, 16 Jan 2019 01:16:07 +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 6DDF33F7CB; Wed, 16 Jan 2019 01:16:07 +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 x0G1Fv5Z022745 for ; Tue, 15 Jan 2019 20:15:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id F122519940; Wed, 16 Jan 2019 01:15:56 +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 AE0FD19C7C for ; Wed, 16 Jan 2019 01:15:56 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:46 -0500 Message-Id: <20190116011549.16309-5-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 4/7] conf: Alter virCapabilitiesFormatGuestXML to take virCapsGuestPtr 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.31]); Wed, 16 Jan 2019 01:16:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than deref off of "caps->guests", let's pass "caps->guests" and caps->nguests to have the helper use "guests[i]->" instead. Signed-off-by: John Ferlan --- src/conf/capabilities.c | 71 +++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index c320c0f72d..1269a4c739 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1179,31 +1179,32 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, =20 =20 static void -virCapabilitiesFormatGuestXML(virCapsPtr caps, +virCapabilitiesFormatGuestXML(virCapsGuestPtr *guests, + size_t nguests, virBufferPtr buf) { size_t i, j, k; =20 - for (i =3D 0; i < caps->nguests; i++) { + for (i =3D 0; i < nguests; i++) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "%s\n", - virDomainOSTypeToString(caps->guests[i]->ostype)= ); - if (caps->guests[i]->arch.id) + virDomainOSTypeToString(guests[i]->ostype)); + if (guests[i]->arch.id) virBufferAsprintf(buf, "\n", - virArchToString(caps->guests[i]->arch.id)); + virArchToString(guests[i]->arch.id)); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "%d\n", - caps->guests[i]->arch.wordsize); - if (caps->guests[i]->arch.defaultInfo.emulator) + guests[i]->arch.wordsize); + if (guests[i]->arch.defaultInfo.emulator) virBufferAsprintf(buf, "%s\n", - caps->guests[i]->arch.defaultInfo.emulator); - if (caps->guests[i]->arch.defaultInfo.loader) + guests[i]->arch.defaultInfo.emulator); + if (guests[i]->arch.defaultInfo.loader) virBufferAsprintf(buf, "%s\n", - caps->guests[i]->arch.defaultInfo.loader); + guests[i]->arch.defaultInfo.loader); =20 - for (j =3D 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++= ) { - virCapsGuestMachinePtr machine =3D caps->guests[i]->arch.defau= ltInfo.machines[j]; + for (j =3D 0; j < guests[i]->arch.defaultInfo.nmachines; j++) { + virCapsGuestMachinePtr machine =3D guests[i]->arch.defaultInfo= .machines[j]; virBufferAddLit(buf, "canonical) virBufferAsprintf(buf, " canonical=3D'%s'", machine->canon= ical); @@ -1212,26 +1213,26 @@ virCapabilitiesFormatGuestXML(virCapsPtr caps, virBufferAsprintf(buf, ">%s\n", machine->name); } =20 - for (j =3D 0; j < caps->guests[i]->arch.ndomains; j++) { + for (j =3D 0; j < guests[i]->arch.ndomains; j++) { virBufferAsprintf(buf, "guests[i]->arch.domains[j]= ->type)); - if (!caps->guests[i]->arch.domains[j]->info.emulator && - !caps->guests[i]->arch.domains[j]->info.loader && - !caps->guests[i]->arch.domains[j]->info.nmachines) { + virDomainVirtTypeToString(guests[i]->arch.domains[j]->type= )); + if (!guests[i]->arch.domains[j]->info.emulator && + !guests[i]->arch.domains[j]->info.loader && + !guests[i]->arch.domains[j]->info.nmachines) { virBufferAddLit(buf, "/>\n"); continue; } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - if (caps->guests[i]->arch.domains[j]->info.emulator) + if (guests[i]->arch.domains[j]->info.emulator) virBufferAsprintf(buf, "%s\n", - caps->guests[i]->arch.domains[j]->info.e= mulator); - if (caps->guests[i]->arch.domains[j]->info.loader) + guests[i]->arch.domains[j]->info.emulato= r); + if (guests[i]->arch.domains[j]->info.loader) virBufferAsprintf(buf, "%s\n", - caps->guests[i]->arch.domains[j]->info.l= oader); + guests[i]->arch.domains[j]->info.loader); =20 - for (k =3D 0; k < caps->guests[i]->arch.domains[j]->info.nmach= ines; k++) { - virCapsGuestMachinePtr machine =3D caps->guests[i]->arch.d= omains[j]->info.machines[k]; + for (k =3D 0; k < guests[i]->arch.domains[j]->info.nmachines; = k++) { + virCapsGuestMachinePtr machine =3D guests[i]->arch.domains= [j]->info.machines[k]; virBufferAddLit(buf, "canonical) virBufferAsprintf(buf, " canonical=3D'%s'", machine->c= anonical); @@ -1246,23 +1247,23 @@ virCapabilitiesFormatGuestXML(virCapsPtr caps, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); =20 - if (caps->guests[i]->nfeatures) { + if (guests[i]->nfeatures) { virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); =20 - for (j =3D 0; j < caps->guests[i]->nfeatures; j++) { - if (STREQ(caps->guests[i]->features[j]->name, "pae") || - STREQ(caps->guests[i]->features[j]->name, "nonpae") || - STREQ(caps->guests[i]->features[j]->name, "ia64_be") || - STREQ(caps->guests[i]->features[j]->name, "cpuselectio= n") || - STREQ(caps->guests[i]->features[j]->name, "deviceboot"= )) { + for (j =3D 0; j < guests[i]->nfeatures; j++) { + if (STREQ(guests[i]->features[j]->name, "pae") || + STREQ(guests[i]->features[j]->name, "nonpae") || + STREQ(guests[i]->features[j]->name, "ia64_be") || + STREQ(guests[i]->features[j]->name, "cpuselection") || + STREQ(guests[i]->features[j]->name, "deviceboot")) { virBufferAsprintf(buf, "<%s/>\n", - caps->guests[i]->features[j]->name); + guests[i]->features[j]->name); } else { virBufferAsprintf(buf, "<%s default=3D'%s' toggle=3D'%= s'/>\n", - caps->guests[i]->features[j]->name, - caps->guests[i]->features[j]->defaul= tOn ? "on" : "off", - caps->guests[i]->features[j]->toggle= ? "yes" : "no"); + guests[i]->features[j]->name, + guests[i]->features[j]->defaultOn ? = "on" : "off", + guests[i]->features[j]->toggle ? "ye= s" : "no"); } } =20 @@ -1294,7 +1295,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) if (virCapabilitiesFormatHostXML(&caps->host, &buf) < 0) goto error; =20 - virCapabilitiesFormatGuestXML(caps, &buf); + virCapabilitiesFormatGuestXML(caps->guests, caps->nguests, &buf); =20 virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 09:53:11 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 1547601375292692.510187446816; Tue, 15 Jan 2019 17:16:15 -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 D216B87645; Wed, 16 Jan 2019 01:16:12 +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 7C5F34DC3B; Wed, 16 Jan 2019 01:16: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 D5B203F6E4; Wed, 16 Jan 2019 01:16:11 +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 x0G1FvrD022752 for ; Tue, 15 Jan 2019 20:15:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6D93419940; Wed, 16 Jan 2019 01:15:57 +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 288E719C7C for ; Wed, 16 Jan 2019 01:15:57 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:47 -0500 Message-Id: <20190116011549.16309-6-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 5/7] conf: Introduce storage pool functions into capabilities 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.26]); Wed, 16 Jan 2019 01:16:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1581670 Introduce the bare bones functions to processing capability data for the storage driver. Currently just looking to store and format the storage pool types in output, such as: dir fs ... iscsi-direct Signed-off-by: John Ferlan --- src/conf/capabilities.c | 60 ++++++++++++++++++++++++++++++++++++++++ src/conf/capabilities.h | 15 ++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 76 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1269a4c739..c60743a38d 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -28,6 +28,7 @@ #include "cpu_conf.h" #include "domain_conf.h" #include "physmem.h" +#include "storage_conf.h" #include "viralloc.h" #include "virarch.h" #include "virbuffer.h" @@ -180,6 +181,17 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest) VIR_FREE(guest); } =20 + +static void +virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr pool) +{ + if (!pool) + return; + + VIR_FREE(pool); +} + + void virCapabilitiesFreeNUMAInfo(virCapsPtr caps) { @@ -221,6 +233,10 @@ virCapsDispose(void *object) virCapsPtr caps =3D object; size_t i; =20 + for (i =3D 0; i < caps->npools; i++) + virCapabilitiesFreeStoragePool(caps->pools[i]); + VIR_FREE(caps->pools); + for (i =3D 0; i < caps->nguests; i++) virCapabilitiesFreeGuest(caps->guests[i]); VIR_FREE(caps->guests); @@ -792,6 +808,30 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, emulator, machinetype); } =20 + +int +virCapabilitiesAddStoragePool(virCapsPtr caps, + int poolType) +{ + virCapsStoragePoolPtr pool; + + if (VIR_ALLOC(pool) < 0) + goto error; + + pool->type =3D poolType; + + if (VIR_RESIZE_N(caps->pools, caps->npools_max, caps->npools, 1) < 0) + goto error; + caps->pools[caps->npools++] =3D pool; + + return 0; + + error: + virCapabilitiesFreeStoragePool(pool); + return -1; +} + + static int virCapabilitiesFormatNUMATopology(virBufferPtr buf, size_t ncells, @@ -1276,6 +1316,24 @@ virCapabilitiesFormatGuestXML(virCapsGuestPtr *guest= s, } =20 =20 +static void +virCapabilitiesFormatStoragePoolXML(virCapsStoragePoolPtr *pools, + size_t npools, + virBufferPtr buf) +{ + size_t i; + + for (i =3D 0; i < npools; i++) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "%s\n", + virStoragePoolTypeToString(pools[i]->type)); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n\n"); + } +} + + /** * virCapabilitiesFormatXML: * @caps: capabilities to format @@ -1297,6 +1355,8 @@ virCapabilitiesFormatXML(virCapsPtr caps) =20 virCapabilitiesFormatGuestXML(caps->guests, caps->nguests, &buf); =20 + virCapabilitiesFormatStoragePoolXML(caps->pools, caps->npools, &buf); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 31c2a07a9b..cca1a20949 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -211,6 +211,13 @@ struct _virCapsHost { bool iommu; }; =20 +typedef struct _virCapsStoragePool virCapsStoragePool; +typedef virCapsStoragePool *virCapsStoragePoolPtr; +struct _virCapsStoragePool { + int type; +}; + + typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr, xmlXPathContextPtr, void **); typedef void (*virDomainDefNamespaceFree)(void *); @@ -235,6 +242,10 @@ struct _virCaps { size_t nguests; size_t nguests_max; virCapsGuestPtr *guests; + + size_t npools; + size_t npools_max; + virCapsStoragePoolPtr *pools; }; =20 typedef struct _virCapsDomainData virCapsDomainData; @@ -318,6 +329,10 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, bool defaultOn, bool toggle); =20 +int +virCapabilitiesAddStoragePool(virCapsPtr caps, + int poolType); + int virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel, const char *type, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3d6306809..9aaa8830e4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -49,6 +49,7 @@ virCapabilitiesAddGuestFeature; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; +virCapabilitiesAddStoragePool; virCapabilitiesAllocMachines; virCapabilitiesClearHostNUMACellCPUTopology; virCapabilitiesDomainDataLookup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 09:53:11 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 1547601380490729.8647918208932; Tue, 15 Jan 2019 17:16:20 -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 7D5143DBEC; Wed, 16 Jan 2019 01:16:18 +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 235AC5DEE1; Wed, 16 Jan 2019 01:16:18 +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 B40A21803394; Wed, 16 Jan 2019 01:16:17 +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 x0G1FvNt022757 for ; Tue, 15 Jan 2019 20:15:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id E00ED19C7C; Wed, 16 Jan 2019 01:15:57 +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 9BCE819940 for ; Wed, 16 Jan 2019 01:15:57 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:48 -0500 Message-Id: <20190116011549.16309-7-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 6/7] storage: Process storage pool capabilities 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.30]); Wed, 16 Jan 2019 01:16:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1581670 During storage driver backend initialization, let's save which backends are available in the storage pool capabilities. In order to format those, we need add a connectGetCapabilities processor to the storageHypervisorDriver. This allows a storage connection, such as "storage:///system" to find the API and format the results. NB: This is not available from other hypervisor drivers such as QEMU type connections. Signed-off-by: John Ferlan --- src/conf/virstorageobj.h | 4 ++++ src/storage/storage_backend.c | 16 ++++++++++++++++ src/storage/storage_backend.h | 3 +++ src/storage/storage_driver.c | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 1106aa71bd..34adc26df3 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -24,6 +24,8 @@ =20 # include "storage_conf.h" =20 +# include "capabilities.h" + typedef struct _virStoragePoolObj virStoragePoolObj; typedef virStoragePoolObj *virStoragePoolObjPtr; =20 @@ -45,6 +47,8 @@ struct _virStorageDriverState { =20 /* Immutable pointer, self-locking APIs */ virObjectEventStatePtr storageEventState; + + virCapsPtr caps; }; =20 typedef bool diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a54c338cf0..0ccc616db4 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -187,3 +187,19 @@ virStorageBackendForType(int type) type, NULLSTR(virStoragePoolTypeToString(type))); return NULL; } + + +virCapsPtr +virStorageBackendGetCapabilities(void) +{ + virCapsPtr caps; + size_t i; + + if (!(caps =3D virCapabilitiesNew(virArchFromHost(), false, false))) + return NULL; + + for (i =3D 0; i < virStorageBackendsCount; i++) + virCapabilitiesAddStoragePool(caps, virStorageBackends[i]->type); + + return caps; +} diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 2b178494ae..c670c66287 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -126,4 +126,7 @@ int virStorageBackendDriversRegister(bool allmodules); =20 int virStorageBackendRegister(virStorageBackendPtr backend); =20 +virCapsPtr +virStorageBackendGetCapabilities(void); + #endif /* LIBVIRT_STORAGE_BACKEND_H */ diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 4a13e90481..04beff6b07 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -300,6 +300,9 @@ storageStateInitialize(bool privileged, =20 driver->storageEventState =3D virObjectEventStateNew(); =20 + if (!(driver->caps =3D virStorageBackendGetCapabilities())) + goto error; + storageDriverUnlock(); =20 ret =3D 0; @@ -368,6 +371,7 @@ storageStateCleanup(void) =20 storageDriverLock(); =20 + virObjectUnref(driver->caps); virObjectUnref(driver->storageEventState); =20 /* free inactive pools */ @@ -577,6 +581,18 @@ storageConnectListStoragePools(virConnectPtr conn, names, maxnames); } =20 + +static char * +storageConnectGetCapabilities(virConnectPtr conn) +{ + + if (virConnectGetCapabilitiesEnsureACL(conn) < 0) + return NULL; + + return virCapabilitiesFormatXML(driver->caps); +} + + static int storageConnectNumOfDefinedStoragePools(virConnectPtr conn) { @@ -2850,6 +2866,7 @@ static virHypervisorDriver storageHypervisorDriver = =3D { .connectIsEncrypted =3D storageConnectIsEncrypted, /* 4.1.0 */ .connectIsSecure =3D storageConnectIsSecure, /* 4.1.0 */ .connectIsAlive =3D storageConnectIsAlive, /* 4.1.0 */ + .connectGetCapabilities =3D storageConnectGetCapabilities, /* 5.1.0 */ }; =20 static virConnectDriver storageConnectDriver =3D { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 09:53:11 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 1547601370334380.377491151409; Tue, 15 Jan 2019 17:16: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 5D93081F13; Wed, 16 Jan 2019 01:16: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 03D3F5C553; Wed, 16 Jan 2019 01:16: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 7177C3F7CD; Wed, 16 Jan 2019 01:16:07 +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 x0G1FwDB022762 for ; Tue, 15 Jan 2019 20:15:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5D1EA19940; Wed, 16 Jan 2019 01:15:58 +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 1732D19C7C for ; Wed, 16 Jan 2019 01:15:57 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 15 Jan 2019 20:15:49 -0500 Message-Id: <20190116011549.16309-8-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 7/7] storage: Add storage backend pool/vol API's to capability output 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.25]); Wed, 16 Jan 2019 01:16:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1581670 Add the Storage Pool and Volume API's defined for each generated capability output, such as: dir ... iscsi Signed-off-by: John Ferlan --- src/conf/capabilities.c | 49 ++++++++++++++++++++++++++++++-- src/conf/capabilities.h | 6 +++- src/storage/storage_backend.c | 53 +++++++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index c60743a38d..f7e9873f64 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -188,6 +188,8 @@ virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr po= ol) if (!pool) return; =20 + VIR_FREE(pool->poolapis); + VIR_FREE(pool->volapis); VIR_FREE(pool); } =20 @@ -811,7 +813,9 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, =20 int virCapabilitiesAddStoragePool(virCapsPtr caps, - int poolType) + int poolType, + const char *poolstr, + const char *volstr) { virCapsStoragePoolPtr pool; =20 @@ -823,7 +827,10 @@ virCapabilitiesAddStoragePool(virCapsPtr caps, if (VIR_RESIZE_N(caps->pools, caps->npools_max, caps->npools, 1) < 0) goto error; caps->pools[caps->npools++] =3D pool; - + if (VIR_STRDUP(pool->poolapis, poolstr) < 0) + goto error; + if (VIR_STRDUP(pool->volapis, volstr) < 0) + goto error; return 0; =20 error: @@ -1322,15 +1329,53 @@ virCapabilitiesFormatStoragePoolXML(virCapsStorageP= oolPtr *pools, virBufferPtr buf) { size_t i; + char **poolapis =3D NULL; + size_t npoolapis =3D 0; + char **volapis =3D NULL; + size_t nvolapis =3D 0; =20 for (i =3D 0; i < npools; i++) { + size_t j; + + if (!(poolapis =3D virStringSplitCount(pools[i]->poolapis, ",", + 0, &npoolapis)) || + !(volapis =3D virStringSplitCount(pools[i]->volapis, ",", + 0, &nvolapis))) + goto cleanup; + virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "%s\n", virStoragePoolTypeToString(pools[i]->type)); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < npoolapis; j++) + virBufferAsprintf(buf, "<%s/>\n", poolapis[j]); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < nvolapis; j++) + virBufferAsprintf(buf, "<%s/>\n", volapis[j]); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n\n"); + + virStringListFree(poolapis); + poolapis =3D NULL; + npoolapis =3D 0; + virStringListFree(volapis); + volapis =3D NULL; + nvolapis =3D 0; } + + cleanup: + virStringListFree(poolapis); + virStringListFree(volapis); } =20 =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index cca1a20949..525f19f195 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -215,6 +215,8 @@ typedef struct _virCapsStoragePool virCapsStoragePool; typedef virCapsStoragePool *virCapsStoragePoolPtr; struct _virCapsStoragePool { int type; + char *poolapis; + char *volapis; }; =20 =20 @@ -331,7 +333,9 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, =20 int virCapabilitiesAddStoragePool(virCapsPtr caps, - int poolType); + int poolType, + const char *poolstr, + const char *volstr); =20 int virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel, diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 0ccc616db4..95873c151f 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -193,13 +193,62 @@ virCapsPtr virStorageBackendGetCapabilities(void) { virCapsPtr caps; + virBuffer poolbuf =3D VIR_BUFFER_INITIALIZER; + virBuffer volbuf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 if (!(caps =3D virCapabilitiesNew(virArchFromHost(), false, false))) return NULL; =20 - for (i =3D 0; i < virStorageBackendsCount; i++) - virCapabilitiesAddStoragePool(caps, virStorageBackends[i]->type); +#define BUF_POOL_BACKEND(field) \ + if (backend->field) \ + virBufferAsprintf(&poolbuf, "%s,", #field); + +#define BUF_VOL_BACKEND(field) \ + if (backend->field) \ + virBufferAsprintf(&volbuf, "%s,", #field); + + for (i =3D 0; i < virStorageBackendsCount; i++) { + char *poolstr =3D NULL; + char *volstr =3D NULL; + virStorageBackendPtr backend =3D virStorageBackends[i]; + + /* NB: checkPool is an internal only mechanism each pool has */ + BUF_POOL_BACKEND(findPoolSources); + BUF_POOL_BACKEND(startPool); + BUF_POOL_BACKEND(buildPool); + BUF_POOL_BACKEND(refreshPool); + BUF_POOL_BACKEND(stopPool); + BUF_POOL_BACKEND(deletePool); + virBufferTrim(&poolbuf, ",", -1); + + BUF_VOL_BACKEND(buildVol); + BUF_VOL_BACKEND(buildVolFrom); + BUF_VOL_BACKEND(createVol); + BUF_VOL_BACKEND(refreshVol); + BUF_VOL_BACKEND(deleteVol); + BUF_VOL_BACKEND(resizeVol); + BUF_VOL_BACKEND(uploadVol); + BUF_VOL_BACKEND(downloadVol); + BUF_VOL_BACKEND(wipeVol); + virBufferTrim(&volbuf, ",", -1); + + if (virBufferCheckError(&poolbuf) < 0 || + virBufferCheckError(&volbuf) < 0) + goto error; + + poolstr =3D virBufferContentAndReset(&poolbuf); + volstr =3D virBufferContentAndReset(&volbuf); + virCapabilitiesAddStoragePool(caps, backend->type, poolstr, volstr= ); + VIR_FREE(poolstr); + VIR_FREE(volstr); + } =20 return caps; + + error: + virBufferFreeAndReset(&poolbuf); + virBufferFreeAndReset(&volbuf); + virObjectUnref(caps); + return NULL; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list