From nobody Mon Feb 9 19:30:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1615553153; cv=none; d=zohomail.com; s=zohoarc; b=lYltYTQJg8K2xzP2jfSJzjhWXkjj51PfuEdcDe8PZ2YxlbKG7uwNArAriPD216L/dYFAi65qHhO3Uslcfl/u7U4AdsUXu5/awuU8VoDgMrD0ACebaHGtArUpClgdU7jezJro6xzPjLtBC7i6vnfqA33TLvsOm9KabbbNph1iJlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615553153; 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=y2Pkf/qin4I0Jl804EmIuJzYIYMa7JIPvtJrf/DRhIU=; b=f9ALgGaA+sqQHlTERtw69Uxo7laR1KqZ8Wbuskf/jo2ZN/svn4JcSp1Vpu9PcFCrpH/3jrT+xXU9ApoEa8J9qJGd3UV5wbnqBp3Mw5U0x3tnxR0G3zTIuwrVWhSOI3H7UUVOYCdkGVOAcukGxCevQLY9sFZmYTCoLNg1wRAiTvE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 161555315335640.22379726388306; Fri, 12 Mar 2021 04:45:53 -0800 (PST) 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-145-VQzy4Xg2MzCADB9KJVqMuA-1; Fri, 12 Mar 2021 07:45:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8C591085958; Fri, 12 Mar 2021 12:45:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A80717A42F; Fri, 12 Mar 2021 12:45: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 59BCD18006DF; Fri, 12 Mar 2021 12:45:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12CCjV9A031241 for ; Fri, 12 Mar 2021 07:45:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4A0B65D761; Fri, 12 Mar 2021 12:45:31 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.194.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 839805D6D7 for ; Fri, 12 Mar 2021 12:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615553152; 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=y2Pkf/qin4I0Jl804EmIuJzYIYMa7JIPvtJrf/DRhIU=; b=eN7KvofZ19SPB/qWmMgI1lkymYeTm6T6MUgubrgWxYfQdeH3AUBXrDMcZpWrvPTdgbtHRB h3KJ1M5JvglSGTod49uvGmFrpUPHnLE1NjNuRtoOqfUJ/1dMQV5/2knh1jw9qs50P6dr2J ytUfNB8Wl5xtjjlpLMzHCnyuzwtzGEw= X-MC-Unique: VQzy4Xg2MzCADB9KJVqMuA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 2/2] refactoring virDomainDeviceInfoParseXML to use XPath Date: Fri, 12 Mar 2021 13:44:49 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.13 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 | 50 ++++++++++-------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3153dec45..843cbe6e84 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6637,77 +6637,51 @@ virDomainDeviceAliasIsUserAlias(const char *aliasSt= r) static int virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, + xmlXPathContextPtr ctxt, virDomainDeviceInfoPtr info, unsigned int flags) { - xmlNodePtr cur; xmlNodePtr address =3D NULL; xmlNodePtr master =3D NULL; - xmlNodePtr alias =3D NULL; xmlNodePtr boot =3D NULL; xmlNodePtr rom =3D NULL; int ret =3D -1; g_autofree char *romenabled =3D NULL; g_autofree char *rombar =3D NULL; g_autofree char *aliasStr =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 virDomainDeviceInfoClear(info); + ctxt->node =3D node; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (alias =3D=3D NULL && - virXMLNodeNameEqual(cur, "alias")) { - alias =3D cur; - } else if (address =3D=3D NULL && - virXMLNodeNameEqual(cur, "address")) { - address =3D cur; - } else if (master =3D=3D NULL && - virXMLNodeNameEqual(cur, "master")) { - master =3D cur; - } else if (boot =3D=3D NULL && - (flags & VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) && - virXMLNodeNameEqual(cur, "boot")) { - boot =3D cur; - } else if (rom =3D=3D NULL && - (flags & VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) && - virXMLNodeNameEqual(cur, "rom")) { - rom =3D cur; - } - } - cur =3D cur->next; - } - - if (alias) { - aliasStr =3D virXMLPropString(alias, "name"); - + if ((aliasStr =3D virXPathString("string(./alias/@name)", ctxt))) if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) || (xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_USER_ALIAS && virDomainDeviceAliasIsUserAlias(aliasStr) && strspn(aliasStr, USER_ALIAS_CHARS) =3D=3D strlen(aliasStr))) info->alias =3D g_steal_pointer(&aliasStr); - } =20 - if (master) { + if ((master =3D virXPathNode("./master", ctxt))) { info->mastertype =3D VIR_DOMAIN_CONTROLLER_MASTER_USB; if (virDomainDeviceUSBMasterParseXML(master, &info->master.usb) < = 0) goto cleanup; } =20 - if (boot) { + if (flags & VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT && + (boot =3D virXPathNode("./boot", ctxt))) { if (virDomainDeviceBootParseXML(boot, info)) goto cleanup; } =20 - if (rom) { - if ((romenabled =3D virXMLPropString(rom, "enabled")) && + if ((flags & VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) && + (rom =3D virXPathNode("./rom", ctxt))) { + if ((romenabled =3D virXPathString("string(./rom/@enabled)", ctxt)= ) && ((info->romenabled =3D virTristateBoolTypeFromString(romenable= d)) <=3D 0)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown rom enabled value '%s'"), romenabled= ); goto cleanup; } - if ((rombar =3D virXMLPropString(rom, "bar")) && + if ((rombar =3D virXPathString("string(./rom/@bar)", ctxt)) && ((info->rombar =3D virTristateSwitchTypeFromString(rombar)) <= =3D 0)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown rom bar value '%s'"), rombar); @@ -6723,7 +6697,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xml= opt, } } =20 - if (address && + if ((address =3D virXPathNode("./address", ctxt)) && virDomainDeviceAddressParseXML(address, info) < 0) goto cleanup; =20 --=20 2.29.2