From nobody Mon Feb 9 05:41:18 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 1532467446671870.2986136313589; Tue, 24 Jul 2018 14:24:06 -0700 (PDT) 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 EA36FC0587F8; Tue, 24 Jul 2018 21:24: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 A000816E27; Tue, 24 Jul 2018 21:24: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 38F524A469; Tue, 24 Jul 2018 21:24:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6OLNpmw018726 for ; Tue, 24 Jul 2018 17:23:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 894F92026E18; Tue, 24 Jul 2018 21:23:51 +0000 (UTC) Received: from worklaptop.bos.redhat.com (wlan-196-187.bos.redhat.com [10.16.196.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DC602026D68; Tue, 24 Jul 2018 21:23:51 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 24 Jul 2018 17:23:43 -0400 Message-Id: <1a4c1a045146524152f4d06fe8740504cef38d8b.1532467269.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] conf: Clean up virDomainDefParseCaps 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: , MIME-Version: 1.0 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.32]); Tue, 24 Jul 2018 21:24:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Convert to 'cleanup' label naming - Use more than one 'tmp' string and do all freeing at the end - Make the code easier to follow Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 76 ++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7eb5ffc718..5a90429cd6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19121,43 +19121,45 @@ virDomainDefParseCaps(virDomainDefPtr def, unsigned int flags) { int ret =3D -1; - int virtType; - char *tmp =3D NULL; + char *virttype =3D NULL; + char *arch =3D NULL; + char *ostype =3D NULL; + virCapsDomainDataPtr capsdata =3D NULL; =20 - /* Find out what type of virtualization to use */ - if (!(tmp =3D virXMLPropString(ctxt->node, "type"))) { + virttype =3D virXPathString("string(./@type)", ctxt); + ostype =3D virXPathString("string(./os/type[1])", ctxt); + arch =3D virXPathString("string(./os/type[1]/@arch)", ctxt); + + def->os.bootloader =3D virXPathString("string(./bootloader)", ctxt); + def->os.bootloaderArgs =3D virXPathString("string(./bootloader_args)",= ctxt); + def->os.machine =3D virXPathString("string(./os/type[1]/@machine)", ct= xt); + def->emulator =3D virXPathString("string(./devices/emulator[1])", ctxt= ); + + if (!virttype) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain type attribute")); - goto error; + goto cleanup; } - - if ((virtType =3D virDomainVirtTypeFromString(tmp)) < 0) { + if ((def->virtType =3D virDomainVirtTypeFromString(virttype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid domain type %s"), tmp); - goto error; + _("invalid domain type %s"), virttype); + goto cleanup; } - def->virtType =3D virtType; - VIR_FREE(tmp); - - def->os.bootloader =3D virXPathString("string(./bootloader)", ctxt); - def->os.bootloaderArgs =3D virXPathString("string(./bootloader_args)",= ctxt); =20 - tmp =3D virXPathString("string(./os/type[1])", ctxt); - if (!tmp) { + if (!ostype) { if (def->os.bootloader) { def->os.type =3D VIR_DOMAIN_OSTYPE_XEN; } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("an os must be specified")); - goto error; + goto cleanup; } } else { - if ((def->os.type =3D virDomainOSTypeFromString(tmp)) < 0) { + if ((def->os.type =3D virDomainOSTypeFromString(ostype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown OS type '%s'"), tmp); - goto error; + _("unknown OS type '%s'"), ostype); + goto cleanup; } - VIR_FREE(tmp); } =20 /* @@ -19170,17 +19172,11 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.type =3D VIR_DOMAIN_OSTYPE_XEN; } =20 - tmp =3D virXPathString("string(./os/type[1]/@arch)", ctxt); - if (tmp && !(def->os.arch =3D virArchFromString(tmp))) { + if (arch && !(def->os.arch =3D virArchFromString(arch))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown architecture %s"), - tmp); - goto error; + _("Unknown architecture %s"), arch); + goto cleanup; } - VIR_FREE(tmp); - - def->os.machine =3D virXPathString("string(./os/type[1]/@machine)", ct= xt); - def->emulator =3D virXPathString("string(./devices/emulator[1])", ctxt= ); =20 if ((!def->os.arch || !def->os.machine) && !(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) { @@ -19191,26 +19187,28 @@ virDomainDefParseCaps(virDomainDefPtr def, * in numerous minor ways. */ bool use_virttype =3D ((def->os.arch =3D=3D VIR_ARCH_NONE) || !def->os.machine); - virCapsDomainDataPtr capsdata =3D NULL; =20 - if (!(capsdata =3D virCapabilitiesDomainDataLookup(caps, def->os.t= ype, - def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VI= RT_NONE, + if (!(capsdata =3D virCapabilitiesDomainDataLookup(caps, + def->os.type, + def->os.arch, + use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, NULL, NULL))) - goto error; + goto cleanup; =20 if (!def->os.arch) def->os.arch =3D capsdata->arch; if ((!def->os.machine && VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) { - VIR_FREE(capsdata); - goto error; + goto cleanup; } - VIR_FREE(capsdata); } =20 ret =3D 0; - error: - VIR_FREE(tmp); + cleanup: + VIR_FREE(virttype); + VIR_FREE(ostype); + VIR_FREE(arch); + VIR_FREE(capsdata); return ret; } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list