From nobody Mon Feb 9 12:11:29 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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=1620128644; cv=none; d=zohomail.com; s=zohoarc; b=kQVrure1ApL2VvO97c5IlXu4ZYtRCuR+zshJVP6XBecKzOLIXETcqnGE9gltVqBYwuS8C7Fg52MBQLQ9Itp4JQ0+I4UMxMDuu8EjGwVs+6BZat4qF84J+rTQp2P/zMVqsodQohj42yeZlxkPkEpeKb9nKzCMN4p0PurJNFQx7sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128644; 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=NbqcnL2Tp/3lNW1UIVWLHLHV2QNPtmSXvcvSPpXkLH0=; b=EiKRlOFycTTIdW6jnHS4YrmtziDFLvwXZ9vAee1NmyQgPCselHmDOngwbRkWuH0j+crwOOCpZGxTjisHoS3SEMu4QkCZvvRvu504539QQKaRABvEi9Vac8iDyLcKwI0TtUmaJTxkS3TKGxCsqCvFbIapvAoz8D+0+ZVquNSTKbo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= 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 1620128644199142.52470621003317; Tue, 4 May 2021 04:44:04 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-0rYCb4TlOIen_78M04evtw-1; Tue, 04 May 2021 07:41:20 -0400 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 02EB4107ACFE; Tue, 4 May 2021 11:41:13 +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 D5CE15B685; Tue, 4 May 2021 11:41:12 +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 9D5A555352; Tue, 4 May 2021 11:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BetkM000774 for ; Tue, 4 May 2021 07:40:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 565D15D9D0; Tue, 4 May 2021 11:40:55 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AFD55D9C0 for ; Tue, 4 May 2021 11:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128643; 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=NbqcnL2Tp/3lNW1UIVWLHLHV2QNPtmSXvcvSPpXkLH0=; b=NkGpPtUsvzrHDKDQ30GAggGpv6vroPgLwW07Pu3lcSiHw9NrVr+K/Oni3QP7jdCFojFxal bJf3UV+3UVcp8uGfzcfUKWwGYJE73LRTxujFlSIWQJoV0b5Ly0usUYwi6ioBEqFpuFH6nJ 4x5Y4HqN0ayGOJIXcC0gGGWl7KTgO7E= X-MC-Unique: 0rYCb4TlOIen_78M04evtw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 08/19] Refactoring virDomainLeaseDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:02 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.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-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 189 ++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 107 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1142b1214a..365879ea98 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8085,48 +8085,34 @@ virSecurityDeviceLabelDefParseXML(virSecurityDevice= LabelDef ***seclabels_rtn, */ static virDomainLeaseDef * virDomainLeaseDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED) + xmlXPathContextPtr ctxt) { virDomainLeaseDef *def; - xmlNodePtr cur; g_autofree char *lockspace =3D NULL; g_autofree char *key =3D NULL; g_autofree char *path =3D NULL; g_autofree char *offset =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 + ctxt->node =3D node; def =3D g_new0(virDomainLeaseDef, 1); =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!key && virXMLNodeNameEqual(cur, "key")) { - if (!(key =3D virXMLNodeContentString(cur))) - goto error; - } else if (!lockspace && - virXMLNodeNameEqual(cur, "lockspace")) { - if (!(lockspace =3D virXMLNodeContentString(cur))) - goto error; - } else if (!path && - virXMLNodeNameEqual(cur, "target")) { - path =3D virXMLPropString(cur, "path"); - offset =3D virXMLPropString(cur, "offset"); - } - } - cur =3D cur->next; - } - - if (!key) { + if (!(key =3D virXPathString("string(./key)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'key' element for lease")); goto error; } - if (!path) { + + if (!(lockspace =3D virXPathString("string(./lockspace)", ctxt))) + goto error; + + if (!(path =3D virXPathString("string(./target/@path)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'target' element for lease")); goto error; } =20 - if (offset && + if ((offset =3D virXPathString("string(./target/@offset)", ctxt)) && virStrToLong_ull(offset, NULL, 10, &def->offset) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Malformed lease target offset %s"), offset); @@ -9464,9 +9450,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, { g_autoptr(virDomainControllerDef) def =3D NULL; virDomainControllerType type =3D 0; - xmlNodePtr cur =3D NULL; - bool processedModel =3D false; - bool processedTarget =3D false; + xmlNodePtr driver =3D NULL; + xmlNodePtr target =3D NULL; int numaNode =3D -1; int ports =3D -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -9502,94 +9487,84 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, def->idx =3D idxVal; } =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "driver")) { - if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, - &def->queues) < 0) - return NULL; + if ((driver =3D virXPathNode("./driver", ctxt)) && + (virDomainVirtioOptionsParseXML(driver, &def->virtio) < 0)) + return NULL; =20 - if (virXMLPropUInt(cur, "cmd_per_lun", 10, VIR_XML_PROP_NO= NE, - &def->cmd_per_lun) < 0) - return NULL; + if (virXMLPropUInt(driver, "queues", 10, VIR_XML_PROP_NONE, + &def->queues) < 0) + return NULL; =20 - if (virXMLPropUInt(cur, "max_sectors", 10, VIR_XML_PROP_NO= NE, - &def->max_sectors) < 0) - return NULL; + if (virXMLPropUInt(driver, "cmd_per_lun", 10, VIR_XML_PROP_NONE, + &def->cmd_per_lun) < 0) + return NULL; =20 - if (virXMLPropTristateSwitch(cur, "ioeventfd", - VIR_XML_PROP_NONE, - &def->ioeventfd) < 0) - return NULL; + if (virXMLPropUInt(driver, "max_sectors", 10, VIR_XML_PROP_NONE, + &def->max_sectors) < 0) + return NULL; =20 - if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONE, - &def->iothread) < 0) - return NULL; + if (virXMLPropTristateSwitch(driver, "ioeventfd", + VIR_XML_PROP_NONE, + &def->ioeventfd) < 0) + return NULL; =20 - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - return NULL; - } else if (virXMLNodeNameEqual(cur, "model")) { - if (processedModel) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); - return NULL; - } + if (virXMLPropUInt(driver, "iothread", 10, VIR_XML_PROP_NONE, + &def->iothread) < 0) + return NULL; =20 - if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { - if (virXMLPropEnum(cur, "name", - virDomainControllerPCIModelNameType= FromString, - VIR_XML_PROP_NONE, - &def->opts.pciopts.modelName) < 0) - return NULL; - } + if (virXPathBoolean("boolean(count(./model) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Multiple elements in " + "controller definition not allowed")); + return NULL; + } =20 - processedModel =3D true; - } else if (virXMLNodeNameEqual(cur, "target")) { - if (processedTarget) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); - return NULL; - } - if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { - if (virXMLPropInt(cur, "chassisNr", 0, VIR_XML_PROP_NO= NE, - &def->opts.pciopts.chassisNr) < 0) - return NULL; - - if (virXMLPropInt(cur, "chassis", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.chassis) < 0) - return NULL; - - if (virXMLPropInt(cur, "port", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.port) < 0) - return NULL; - - if (virXMLPropInt(cur, "busNr", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.busNr) < 0) - return NULL; - - if (virXMLPropTristateSwitch(cur, "hotplug", - VIR_XML_PROP_NONE, - &def->opts.pciopts.hotplu= g) < 0) - return NULL; - - if ((rc =3D virXMLPropInt(cur, "index", 0, VIR_XML_PRO= P_NONE, - &def->opts.pciopts.targetIndex)) < 0) - return NULL; - - if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D= =3D -1) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid target index '%i' in PCI= controller"), - def->opts.pciopts.targetIndex); - } - } + if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropEnum(virXPathNode("./model", ctxt), "name", + virDomainControllerPCIModelNameTypeFromString, + VIR_XML_PROP_NONE, + &def->opts.pciopts.modelName) < 0) + return NULL; + } =20 - processedTarget =3D true; - } - } - cur =3D cur->next; + if (virXPathBoolean("boolean(count(./target) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Multiple elements in " + "controller definition not allowed")); + return NULL; + } + + if ((target =3D virXPathNode("./target", ctxt)) && + def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropInt(target, "chassisNr", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.chassisNr) < 0) + return NULL; + + if (virXMLPropInt(target, "chassis", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.chassis) < 0) + return NULL; + + if (virXMLPropInt(target, "port", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.port) < 0) + return NULL; + + if (virXMLPropInt(target, "busNr", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.busNr) < 0) + return NULL; + + if (virXMLPropTristateSwitch(target, "hotplug", + VIR_XML_PROP_NONE, + &def->opts.pciopts.hotplug) < 0) + return NULL; + + if ((rc =3D virXMLPropInt(target, "index", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.targetIndex)) < 0) + return NULL; + + if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D=3D -1) + virReportError(VIR_ERR_XML_ERROR, + _("Invalid target index '%i' in PCI controller"= ), + def->opts.pciopts.targetIndex); } =20 /* node is parsed differently from target attributes because --=20 2.30.2