From nobody Sun Feb 8 16:24:12 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 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