From nobody Mon Feb 9 08:30:47 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=1664872695; cv=none; d=zohomail.com; s=zohoarc; b=nLNtARC9ic+/piM/MTHaj6GyiEREF8FJ3fQxoaJEPa8V7duQqOl5XcKWY9ElBEZMfbnY8IcNG1OaMiKjm7c2I+Sr1aqLcx9FD/Q/LJQcxN3n8avWFN5WjbGUolXP8uCuS0mNS1FQHovVwFl6h/f+3ETg+L89IqDeMdM1MRTMG4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664872695; 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=uF5VzHhdGOrYtYIIyblCT5zuuKpRsQYQBaYaZ6nDzgw=; b=eAmcGsEODivEQzcmEPx6zESFKzCCh+RAtr4FGommLEHmsv+esTKBkbNU6wQopNmwM2UARu2ysHwnWUGNeqchMLQGx11ZrIpvraKPupcPUIIESLcgwsi/ZCUqrEkwA7LQWJeTivt+zwAc3WejWim7qtWwgD9R2Wd8IoCcwJf58/o= 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 1664872695169818.2027580387207; Tue, 4 Oct 2022 01:38:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-536-rg05qDw7MaShRcKs0bJVDw-1; Tue, 04 Oct 2022 04:33:41 -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 98F59299E767; Tue, 4 Oct 2022 08:33:38 +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 82E2B492B09; Tue, 4 Oct 2022 08:33:38 +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 48F831947047; Tue, 4 Oct 2022 08:33:38 +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 D3A971947055 for ; Tue, 4 Oct 2022 08:33:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AE8A040C6EC3; Tue, 4 Oct 2022 08:33:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2735F40C6EC2 for ; Tue, 4 Oct 2022 08:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664872694; 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=uF5VzHhdGOrYtYIIyblCT5zuuKpRsQYQBaYaZ6nDzgw=; b=RPbWZ3MLBsoZ4vDoe43CfTwYym0L5kOV3f1I7whnREnfBpQZhjxDCrZKFfBPflfRwS233Z RQVNOSANWcgWQTdBZdagfw+/j4XYsaXxOqo3IFWfZrbZbN2u5OgXdBXMSyZ4lZQB91s0wU iaxLKBSL3IztCVuxVcvcIvflfo61uy4= X-MC-Unique: rg05qDw7MaShRcKs0bJVDw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/43] conf: snapshot: Remove virDomainSnapshotDefParseNode Date: Tue, 4 Oct 2022 10:32:52 +0200 Message-Id: <4957c38fe69508e3b23b40dc451403b0ac7c0916.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: 1664872696658100001 Content-Type: text/plain; charset="utf-8" Check the root XML node name and fetch XPath context by properly configuring virXMLParse. Callers can use virDomainSnapshotDefParse instead. Signed-off-by: Peter Krempa --- src/conf/snapshot_conf.c | 40 +++++++++------------------------------- src/conf/snapshot_conf.h | 13 +++++++------ src/test/test_driver.c | 18 ++++++++---------- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index a5974053f4..afdc11876d 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -197,7 +197,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, * If flags does not include * VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL, then current is ignored. */ -static virDomainSnapshotDef * +virDomainSnapshotDef * virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt, void *parseOpaque, @@ -389,27 +389,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, return g_steal_pointer(&def); } -virDomainSnapshotDef * -virDomainSnapshotDefParseNode(xmlDocPtr xml, - xmlNodePtr root, - virDomainXMLOption *xmlopt, - void *parseOpaque, - bool *current, - unsigned int flags) -{ - g_autoptr(xmlXPathContext) ctxt =3D NULL; - - if (!virXMLNodeNameEqual(root, "domainsnapshot")) { - virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot")); - return NULL; - } - - if (!(ctxt =3D virXMLXPathContextNew(xml))) - return NULL; - - ctxt->node =3D root; - return virDomainSnapshotDefParse(ctxt, xmlopt, parseOpaque, current, f= lags); -} virDomainSnapshotDef * virDomainSnapshotDefParseString(const char *xmlStr, @@ -418,21 +397,20 @@ virDomainSnapshotDefParseString(const char *xmlStr, bool *current, unsigned int flags) { - virDomainSnapshotDef *ret =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); bool validate =3D flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), - NULL, NULL, "domainsnapshot.rng", validate))) { - xmlKeepBlanksDefault(keepBlanksDefault); - ret =3D virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xm= l), - xmlopt, parseOpaque, - current, flags); - } + xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), + "domainsnapshot", &ctxt, "domainsnapshot.rng", valid= ate); + xmlKeepBlanksDefault(keepBlanksDefault); - return ret; + if (!xml) + return NULL; + + return virDomainSnapshotDefParse(ctxt, xmlopt, parseOpaque, current, f= lags); } diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 1f787f1a94..fec4a5a912 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -102,12 +102,13 @@ virDomainSnapshotDef *virDomainSnapshotDefParseString= (const char *xmlStr, void *parseOpaque, bool *current, unsigned int flags); -virDomainSnapshotDef *virDomainSnapshotDefParseNode(xmlDocPtr xml, - xmlNodePtr root, - virDomainXMLOption *xm= lopt, - void *parseOpaque, - bool *current, - unsigned int flags); +virDomainSnapshotDef * +virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, + virDomainXMLOption *xmlopt, + void *parseOpaque, + bool *current, + unsigned int flags); + virDomainSnapshotDef *virDomainSnapshotDefNew(void); char *virDomainSnapshotDefFormat(const char *uuidstr, virDomainSnapshotDef *def, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5a4e240d35..50c8a7e2be 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -961,25 +961,23 @@ testParseDomainSnapshots(testDriver *privconn, const char *file, xmlXPathContextPtr ctxt) { + VIR_XPATH_NODE_AUTORESTORE(ctxt) size_t i; testDomainNamespaceDef *nsdata =3D domobj->def->namespaceData; xmlNodePtr *nodes =3D nsdata->snap_nodes; - bool cur; for (i =3D 0; i < nsdata->num_snap_nodes; i++) { virDomainMomentObj *snap; g_autoptr(virDomainSnapshotDef) def =3D NULL; - xmlNodePtr node =3D testParseXMLDocFromFile(nodes[i], file); - if (!node) + unsigned int parseFlags =3D VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL | + VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE; + bool cur; + + if (!(ctxt->node =3D testParseXMLDocFromFile(nodes[i], file))) return -1; - def =3D virDomainSnapshotDefParseNode(ctxt->doc, node, - privconn->xmlopt, - NULL, - &cur, - VIR_DOMAIN_SNAPSHOT_PARSE_INTE= RNAL | - VIR_DOMAIN_SNAPSHOT_PARSE_REDE= FINE); - if (!def) + if (!(def =3D virDomainSnapshotDefParse(ctxt, privconn->xmlopt, NU= LL, + &cur, parseFlags))) return -1; if (!(snap =3D virDomainSnapshotAssignDef(domobj->snapshots, &def)= )) --=20 2.37.3