From nobody Mon Feb 9 06:02:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664872424; cv=none; d=zohomail.com; s=zohoarc; b=KgPUGfFrdbWJNnRDaoJdVoNjT9n3z+O2TN0YXpnFkoNgxIe53x26y9zAP8ZkUvgft8Z1pLGdP9jaHsoPXKqs6ezo4NTgwQYp1FJ/KA0eB/VYtKz+JuaQ3Y6Dp3DtV4K3zgwOiAvIhxLCBbEt+XmGH846CKP4xd+8R1E5QNyu9gI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664872424; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/VZCDn2h7VcnaJ/DjN/ZOHieJwoLgiV9Ke4RzmU73SY=; b=jY6V9JwKeSETDZYJLHUnB+pxdlpCMrJVWQ57nRxeDVhI7HSFsxe9zDSYomPm584VtYRziVCM9ANNMyP3rIC0ykK6YyaaMxa4w7Px1AR+hcbN42SuzTPCpMLUyDt47k4fbNr/jTTYgddUXLQtzhSN8cEM6C2mkI0oXjs0zR7jUks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 166487242445522.03886765250877; Tue, 4 Oct 2022 01:33:44 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-hCI1y9CIMbizTb54vyFA_g-1; Tue, 04 Oct 2022 04:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65AE3100F809; Tue, 4 Oct 2022 08:33:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17839492B04; Tue, 4 Oct 2022 08:33:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 111DF1947060; Tue, 4 Oct 2022 08:33:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 35B2A1947040 for ; Tue, 4 Oct 2022 08:33:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 17ABD40C6EC3; Tue, 4 Oct 2022 08:33:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8499D40C6EC2 for ; Tue, 4 Oct 2022 08:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664872423; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/VZCDn2h7VcnaJ/DjN/ZOHieJwoLgiV9Ke4RzmU73SY=; b=MsvE9TVSc8oBBgfW5Mm/YgAYwQwUmFmLem3zCdzxRjHGIFgEEC/KGAuFuc8FICtUN2KGhj 67IGgHdJq0JWZB6I4t9QdAY0HjTFqB8N8d4Hwoui88ZnB9Hldk5PZS5AqfADQo9xLCOEJX rzVeD7vGIP6hIE9XAfkv8U+Bi7yDCj4= X-MC-Unique: hCI1y9CIMbizTb54vyFA_g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/43] conf: storage: Remove virStoragePoolDefParseNode Date: Tue, 4 Oct 2022 10:32:48 +0200 Message-Id: <5130c2243e2d8e73f45e1dd2c50aee7e9699cb71.1664870258.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664872425209100001 Content-Type: text/plain; charset="utf-8" Replace it by proper use of virXMLParse to validate the root node and allocate the context. The use in the test driver can be directly replaced by virStoragePoolDefParseXML as both are validated. The change to the storage driver isn't trivial though as it requires careful xpath context juggling to parse the nested volumes properly. Signed-off-by: Peter Krempa --- src/conf/storage_conf.c | 34 ++++++---------------------------- src/conf/storage_conf.h | 4 ---- src/libvirt_private.syms | 1 - src/test/test_driver.c | 19 +++++++------------ 4 files changed, 13 insertions(+), 45 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index d7375a5160..c11f40488d 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -972,43 +972,21 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) } -virStoragePoolDef * -virStoragePoolDefParseNode(xmlDocPtr xml, - xmlNodePtr root) -{ - g_autoptr(xmlXPathContext) ctxt =3D NULL; - - if (!virXMLNodeNameEqual(root, "pool")) { - virReportError(VIR_ERR_XML_ERROR, - _("unexpected root element <%s>, " - "expecting "), - root->name); - return NULL; - } - - if (!(ctxt =3D virXMLXPathContextNew(xml))) - return NULL; - - ctxt->node =3D root; - return virStoragePoolDefParseXML(ctxt); -} - - static virStoragePoolDef * virStoragePoolDefParse(const char *xmlStr, const char *filename, unsigned int flags) { - virStoragePoolDef *ret =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; bool validate =3D flags & VIR_STORAGE_POOL_DEFINE_VALIDATE; - if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )"), - NULL, NULL, "storagepool.rng", validate))) { - ret =3D virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml)); - } - return ret; + if (!(xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definitio= n)"), + "pool", &ctxt, "storagepool.rng", validate))) + return NULL; + + return virStoragePoolDefParseXML(ctxt); } diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index a1bf243935..5eee5b6881 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -278,10 +278,6 @@ virStoragePoolDefParseString(const char *xml, virStoragePoolDef * virStoragePoolDefParseFile(const char *filename); -virStoragePoolDef * -virStoragePoolDefParseNode(xmlDocPtr xml, - xmlNodePtr root); - char * virStoragePoolDefFormat(virStoragePoolDef *def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3ef3210184..ddc2394fb9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1054,7 +1054,6 @@ virStoragePartedFsTypeToString; virStoragePoolDefFormat; virStoragePoolDefFree; virStoragePoolDefParseFile; -virStoragePoolDefParseNode; virStoragePoolDefParseSourceString; virStoragePoolDefParseString; virStoragePoolFormatDiskTypeFromString; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5eae22f591..27cf3ced43 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1145,20 +1145,15 @@ testParseInterfaces(testDriver *privconn, static int testOpenVolumesForPool(const char *file, xmlXPathContextPtr ctxt, - virStoragePoolObj *obj, - int objidx) + virStoragePoolObj *obj) { virStoragePoolDef *def =3D virStoragePoolObjGetDef(obj); size_t i; int num; - g_autofree char *vol_xpath =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; g_autoptr(virStorageVolDef) volDef =3D NULL; - /* Find storage volumes */ - vol_xpath =3D g_strdup_printf("/node/pool[%d]/volume", objidx); - - num =3D virXPathNodeSet(vol_xpath, ctxt, &nodes); + num =3D virXPathNodeSet("/pool/volume", ctxt, &nodes); if (num < 0) return -1; @@ -1195,6 +1190,7 @@ testParseStorage(testDriver *privconn, const char *file, xmlXPathContextPtr ctxt) { + VIR_XPATH_NODE_AUTORESTORE(ctxt) int num; size_t i; virStoragePoolObj *obj; @@ -1206,12 +1202,11 @@ testParseStorage(testDriver *privconn, for (i =3D 0; i < num; i++) { virStoragePoolDef *def; - xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file); - if (!node) + + if (!(ctxt->node =3D testParseXMLDocFromFile(nodes[i], file))) return -1; - def =3D virStoragePoolDefParseNode(ctxt->doc, node); - if (!def) + if (!(def =3D virStoragePoolDefParseXML(ctxt))) return -1; if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, &def, 0)))= { @@ -1226,7 +1221,7 @@ testParseStorage(testDriver *privconn, virStoragePoolObjSetActive(obj, true); /* Find storage volumes */ - if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) { + if (testOpenVolumesForPool(file, ctxt, obj) < 0) { virStoragePoolObjEndAPI(&obj); return -1; } --=20 2.37.3