From nobody Mon Feb 9 17:56:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637326308119184.67926175553237; Fri, 19 Nov 2021 04:51:48 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-324-lliMki5kPgKckH8CmtWh2A-1; Fri, 19 Nov 2021 07:51:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 516741017965; Fri, 19 Nov 2021 12:51:37 +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 585335D740; Fri, 19 Nov 2021 12:51:35 +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 572214A703; Fri, 19 Nov 2021 12:51:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1AJCmis7004193 for ; Fri, 19 Nov 2021 07:48:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 27CE9404727A; Fri, 19 Nov 2021 12:48:44 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23AC44047279 for ; Fri, 19 Nov 2021 12:48:44 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A35A85A5A8 for ; Fri, 19 Nov 2021 12:48:44 +0000 (UTC) Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-99-AyMriX9BPYeKjG9bHXnP0Q-1; Fri, 19 Nov 2021 07:48:42 -0500 Received: by mail-ua1-f48.google.com with SMTP id p2so20902008uad.11 for ; Fri, 19 Nov 2021 04:48:42 -0800 (PST) Received: from rekt.ibmuc.com ([152.250.208.89]) by smtp.gmail.com with ESMTPSA id s27sm1570629vkl.24.2021.11.19.04.48.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 04:48:41 -0800 (PST) X-MC-Unique: lliMki5kPgKckH8CmtWh2A-1 X-MC-Unique: AyMriX9BPYeKjG9bHXnP0Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oJpvLV09oBMdEAkcMZJTQwzM8o+FpowfT1ZoOBRas5c=; b=zdJ07rOXA96EEz5EdG+Xtx2CHbsPLI3jwh1t9FeNs2C4CSwLRQerqJSGqL7XtgrKVw ANJobuKQUvB1GFmeKmXUgOm1ZbKsPqbtfVQn6xhdUVfVNNStzFeU0FZamB+a69TU/pCA jo1QLyL3BhWe0Kj8d1DXEbLgv09F39327nhxpKxqpr5Wd7UvHoBtMh9py7HQMO+lOhdq p/5nBQL184bi/87bWbkrkeZKIzUaMeTLuFVD4HE8tiK7YQTFrSoFwxQPcbbF4TZzHzMD BxLw5N0LLi1io/ufNIQbJHFguF2JwvMz2c2joqN1KVSqU1v8zwQKQ3M9g4v8DHrondvv ExnQ== X-Gm-Message-State: AOAM531whZcI+1jYqPlWFTKVSrJSzs2kMtORfJ/GU+V90XBPiLyUGUBd Q58EWs6gV1zSKxwGj406VLWFdN8091qI/A== X-Google-Smtp-Source: ABdhPJwI/A1xBS978uz6IxTfpgVXcks0eJ0HLkoFjqcFmCqYc5xIb+2VnRQU15c9y78sILaVI/bEmA== X-Received: by 2002:ab0:7095:: with SMTP id m21mr49008080ual.82.1637326121619; Fri, 19 Nov 2021 04:48:41 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 2/8] qemu_capabilities.c: add virQEMUCapsParseGIC() Date: Fri, 19 Nov 2021 09:48:24 -0300 Message-Id: <20211119124830.569230-3-danielhb413@gmail.com> In-Reply-To: <20211119124830.569230-1-danielhb413@gmail.com> References: <20211119124830.569230-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-loop: libvir-list@redhat.com Cc: danielhb413@gmail.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1637326309681100002 Content-Type: text/plain; charset="utf-8" Create a new helper to remove the GIC parse logic from the body of virQEMUCapsLoadCache(). Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_capabilities.c | 142 +++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 65 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 61ec0727cb..38558a9ee0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4136,6 +4136,82 @@ virQEMUCapsParseFlags(virQEMUCaps *qemuCaps, xmlXPat= hContextPtr ctxt) } =20 =20 +static int +virQEMUCapsParseGIC(virQEMUCaps *qemuCaps, xmlXPathContextPtr ctxt) +{ + g_autofree xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + + if ((n =3D virXPathNodeSet("./gic", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to parse qemu capabilities gic")); + return -1; + } + + if (n > 0) { + unsigned int uintValue; + bool boolValue; + + qemuCaps->ngicCapabilities =3D n; + qemuCaps->gicCapabilities =3D g_new0(virGICCapability, n); + + for (i =3D 0; i < n; i++) { + virGICCapability *cap =3D &qemuCaps->gicCapabilities[i]; + g_autofree char *version =3D NULL; + g_autofree char *kernel =3D NULL; + g_autofree char *emulated =3D NULL; + + if (!(version =3D virXMLPropString(nodes[i], "version"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing GIC version " + "in QEMU capabilities cache")); + return -1; + } + if (virStrToLong_ui(version, NULL, 10, &uintValue) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed GIC version " + "in QEMU capabilities cache")); + return -1; + } + cap->version =3D uintValue; + + if (!(kernel =3D virXMLPropString(nodes[i], "kernel"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing in-kernel GIC information " + "in QEMU capabilities cache")); + return -1; + } + if (!(boolValue =3D STREQ(kernel, "yes")) && STRNEQ(kernel, "n= o")) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed in-kernel GIC information " + "in QEMU capabilities cache")); + return -1; + } + if (boolValue) + cap->implementation |=3D VIR_GIC_IMPLEMENTATION_KERNEL; + + if (!(emulated =3D virXMLPropString(nodes[i], "emulated"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing emulated GIC information " + "in QEMU capabilities cache")); + return -1; + } + if (!(boolValue =3D STREQ(emulated, "yes")) && STRNEQ(emulated= , "no")) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed emulated GIC information " + "in QEMU capabilities cache")); + return -1; + } + if (boolValue) + cap->implementation |=3D VIR_GIC_IMPLEMENTATION_EMULATED; + } + } + + return 0; +} + + /* * Parsing a doc that looks like * @@ -4164,8 +4240,6 @@ virQEMUCapsLoadCache(virArch hostArch, { g_autoptr(xmlDoc) doc =3D NULL; int ret =3D -1; - size_t i; - int n; xmlNodePtr *nodes =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; char *str =3D NULL; @@ -4293,70 +4367,8 @@ virQEMUCapsLoadCache(virArch hostArch, virQEMUCapsLoadAccel(qemuCaps, ctxt, VIR_DOMAIN_VIRT_QEMU) < 0) goto cleanup; =20 - if ((n =3D virXPathNodeSet("./gic", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities gic")); + if (virQEMUCapsParseGIC(qemuCaps, ctxt) < 0) goto cleanup; - } - if (n > 0) { - unsigned int uintValue; - bool boolValue; - - qemuCaps->ngicCapabilities =3D n; - qemuCaps->gicCapabilities =3D g_new0(virGICCapability, n); - - for (i =3D 0; i < n; i++) { - virGICCapability *cap =3D &qemuCaps->gicCapabilities[i]; - - if (!(str =3D virXMLPropString(nodes[i], "version"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing GIC version " - "in QEMU capabilities cache")); - goto cleanup; - } - if (virStrToLong_ui(str, NULL, 10, &uintValue) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed GIC version " - "in QEMU capabilities cache")); - goto cleanup; - } - cap->version =3D uintValue; - VIR_FREE(str); - - if (!(str =3D virXMLPropString(nodes[i], "kernel"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing in-kernel GIC information " - "in QEMU capabilities cache")); - goto cleanup; - } - if (!(boolValue =3D STREQ(str, "yes")) && STRNEQ(str, "no")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed in-kernel GIC information " - "in QEMU capabilities cache")); - goto cleanup; - } - if (boolValue) - cap->implementation |=3D VIR_GIC_IMPLEMENTATION_KERNEL; - VIR_FREE(str); - - if (!(str =3D virXMLPropString(nodes[i], "emulated"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing emulated GIC information " - "in QEMU capabilities cache")); - goto cleanup; - } - if (!(boolValue =3D STREQ(str, "yes")) && STRNEQ(str, "no")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed emulated GIC information " - "in QEMU capabilities cache")); - goto cleanup; - } - if (boolValue) - cap->implementation |=3D VIR_GIC_IMPLEMENTATION_EMULATED; - VIR_FREE(str); - } - } - VIR_FREE(nodes); =20 if (virQEMUCapsParseSEVInfo(qemuCaps, ctxt) < 0) goto cleanup; --=20 2.31.1