From nobody Mon Feb 9 00:30:09 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 1550763765034666.1310157816872; Thu, 21 Feb 2019 07:42:45 -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 923DA3097061; Thu, 21 Feb 2019 15:42:42 +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 59ACA6015C; Thu, 21 Feb 2019 15:42:42 +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 639AE41F3D; Thu, 21 Feb 2019 15:42:41 +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 x1LFgciE008307 for ; Thu, 21 Feb 2019 10:42:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69D4B282C9; Thu, 21 Feb 2019 15:42:38 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5DB51A837 for ; Thu, 21 Feb 2019 15:42:37 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 21 Feb 2019 16:42:26 +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 4/8] Use virQEMUCapsSetFromNodes where possible 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-Type: text/plain; charset="utf-8" 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.43]); Thu, 21 Feb 2019 15:42:43 +0000 (UTC) Remove some code duplication. Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_capabilities.h | 4 ++++ src/qemu/qemu_domain.c | 16 ++-------------- tests/qemucaps2xmltest.c | 17 +++-------------- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a355ee2e37..b12f5914aa 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3442,7 +3442,7 @@ virQEMUCapsParseSEVInfo(virQEMUCapsPtr qemuCaps, xmlX= PathContextPtr ctxt) } =20 =20 -static int +int virQEMUCapsSetFromNodes(virQEMUCapsPtr qemuCaps, xmlNodePtr *nodes, size_t n) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 6fa402a846..d1303da3cf 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -516,6 +516,10 @@ virQEMUCapsPtr virQEMUCapsNew(void); =20 void virQEMUCapsSet(virQEMUCapsPtr qemuCaps, virQEMUCapsFlags flag) ATTRIBUTE_NONNULL(1); +int virQEMUCapsSetFromNodes(virQEMUCapsPtr qemuCaps, + xmlNodePtr *nodes, + size_t nnodes) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 void virQEMUCapsSetList(virQEMUCapsPtr qemuCaps, ...) ATTRIBUTE_NONNULL(1); =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bbd4a5efe8..ef44252cba 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2995,20 +2995,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, if (!(qemuCaps =3D virQEMUCapsNew())) goto error; =20 - for (i =3D 0; i < n; i++) { - char *str =3D virXMLPropString(nodes[i], "name"); - if (str) { - int flag =3D virQEMUCapsTypeFromString(str); - if (flag < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown qemu capabilities flag %s"),= str); - VIR_FREE(str); - goto error; - } - VIR_FREE(str); - virQEMUCapsSet(qemuCaps, flag); - } - } + if (virQEMUCapsSetFromNodes(qemuCaps, nodes, n) < 0) + goto error; =20 VIR_STEAL_PTR(priv->qemuCaps, qemuCaps); } diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index 0d9b4e679a..3e96c643da 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -38,7 +38,7 @@ testQemuGetCaps(char *caps) virQEMUCapsPtr qemuCaps =3D NULL; xmlDocPtr xml; xmlXPathContextPtr ctxt =3D NULL; - ssize_t i, n; + ssize_t n; xmlNodePtr *nodes =3D NULL; =20 if (!(xml =3D virXMLParseStringCtxt(caps, "(test caps)", &ctxt))) @@ -52,19 +52,8 @@ testQemuGetCaps(char *caps) if (!(qemuCaps =3D virQEMUCapsNew())) goto error; =20 - for (i =3D 0; i < n; i++) { - char *str =3D virXMLPropString(nodes[i], "name"); - if (str) { - int flag =3D virQEMUCapsTypeFromString(str); - if (flag < 0) { - fprintf(stderr, "Unknown qemu capabilities flag %s", str); - VIR_FREE(str); - goto error; - } - VIR_FREE(str); - virQEMUCapsSet(qemuCaps, flag); - } - } + if (virQEMUCapsSetFromNodes(qemuCaps, nodes, n) < 0) + goto error; =20 VIR_FREE(nodes); xmlFreeDoc(xml); --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list