From nobody Mon Feb 9 13:59:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1599835186; cv=none; d=zohomail.com; s=zohoarc; b=UR31cFIxKNa9LmtwVZdt2FafmUwz0dsJM11cr4o/cJeh3KTMGZNPNjByHnnM+xi5NDxDZWKs1qK43PgqLkVyeLVUtm/X2R1AqPKQ9M/BVuacNDsFYr4dG6KRL7LfEXaRs7QQUXfWnO5gFNtGLMbkUnim3lVTcSd2f6NWSh0azm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599835186; 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=4s5as1A5vUCadr0MpzjODB3hZaW4T3gLJtgqzFIV++Q=; b=SdglSl/QQZUKdljPkiWSUvNUhwmHfnjPxqBiOAmW+XHXQj3i3/9gNqzzS58ZzUyupE5KQ+uk3brxdUbdDhuSGqTEt9rlSGFmQfvBix7s9UeypVUjC9B351GHcc09tIjh8+H7t+JrnYEccTsp3BKqMoD516VylKwtr0ow1ol0onM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599835186770281.7561280849411; Fri, 11 Sep 2020 07:39:46 -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-571-L22uSPYLPNGVu026tV0Tfg-1; Fri, 11 Sep 2020 10:39:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 922178030D2; Fri, 11 Sep 2020 14:39:35 +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 6FAE55C22A; Fri, 11 Sep 2020 14:39: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 3C26092310; Fri, 11 Sep 2020 14:39:35 +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 08BEbjFh002327 for ; Fri, 11 Sep 2020 10:37:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C1468FCA3; Fri, 11 Sep 2020 14:37:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF9318FCA1 for ; Fri, 11 Sep 2020 14:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599835183; 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=4s5as1A5vUCadr0MpzjODB3hZaW4T3gLJtgqzFIV++Q=; b=fzdV9upiVvQUWl18bWyds03+p90v19j4qniYSwsf4xoVFq01IjRrb9wW8tAK3W2JC2aHjz ydc+f8deOBlDKj1cI0/o1ymASCPVDffuT71cVyhYl87Dsgv3xpLSptUH2Lax94CV18iJsh 3bnzGbzTQqUxWFoebhX1MflNMq7w49w= X-MC-Unique: L22uSPYLPNGVu026tV0Tfg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/17] virDomainHostdevSubsysSCSIHostDefParseXML: Switch to a more modern XML parsing approach Date: Fri, 11 Sep 2020 16:37:21 +0200 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use XPath instead of iterating through the nodes. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 98 +++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 63 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ae7cb1e1c5..05c2c63f58 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8262,89 +8262,61 @@ virDomainStorageNetworkParseHosts(xmlNodePtr node, static int virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, + xmlXPathContextPtr ctxt, virDomainHostdevSubsysSCSIPtr sc= sisrc) { - bool got_address =3D false, got_adapter =3D false; - xmlNodePtr cur; virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; g_autofree char *bus =3D NULL; g_autofree char *target =3D NULL; g_autofree char *unit =3D NULL; + xmlNodePtr addressnode =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); - cur =3D sourcenode->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "address")) { - if (got_address) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("more than one source addresses is " - "specified for scsi hostdev")); - return -1; - } - - if (!(bus =3D virXMLPropString(cur, "bus")) || - !(target =3D virXMLPropString(cur, "target")) || - !(unit =3D virXMLPropString(cur, "unit"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'bus', 'target', and 'unit' must be = specified " - "for scsi hostdev source address")); - return -1; - } + ctxt->node =3D sourcenode; - if (virStrToLong_uip(bus, NULL, 0, &scsihostsrc->bus) < 0)= { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse bus '%s'"), bus); - return -1; - } + if (!(addressnode =3D virXPathNode("./address", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'address' must be specified for scsi hostdev sou= rce")); + return -1; + } - if (virStrToLong_uip(target, NULL, 0, - &scsihostsrc->target) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse target '%s'"), target); - return -1; - } + if (!(bus =3D virXMLPropString(addressnode, "bus")) || + !(target =3D virXMLPropString(addressnode, "target")) || + !(unit =3D virXMLPropString(addressnode, "unit"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'bus', 'target', and 'unit' must be specified " + "for scsi hostdev source address")); + return -1; + } - if (virStrToLong_ullp(unit, NULL, 0, &scsihostsrc->unit) <= 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse unit '%s'"), unit); - return -1; - } + if (virStrToLong_uip(bus, NULL, 0, &scsihostsrc->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse bus '%s'"), bus); + return -1; + } - got_address =3D true; - } else if (virXMLNodeNameEqual(cur, "adapter")) { - if (got_adapter) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("more than one adapters is specified " - "for scsi hostdev source")); - return -1; - } - if (!(scsihostsrc->adapter =3D virXMLPropString(cur, "name= "))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'adapter' must be specified for scsi= hostdev source")); - return -1; - } + if (virStrToLong_uip(target, NULL, 0, &scsihostsrc->target) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse target '%s'"), target); + return -1; + } - got_adapter =3D true; - } else { - virReportError(VIR_ERR_XML_ERROR, - _("unsupported element '%s' of scsi hostdev= source"), - cur->name); - return -1; - } - } - cur =3D cur->next; + if (virStrToLong_ullp(unit, NULL, 0, &scsihostsrc->unit) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse unit '%s'"), unit); + return -1; } - if (!got_address || !got_adapter) { + if (!(scsihostsrc->adapter =3D virXPathString("string(./adapter/@name)= ", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("'adapter' and 'address' must be specified for sc= si " - "hostdev source")); + _("'adapter' name must be specified for scsi hostde= v source")); return -1; } return 0; } + static int virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr d= ef, @@ -8441,7 +8413,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sour= cenode, switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: - return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsis= rc); + return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt,= scsisrc); case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: return virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsi= src, ctxt, --=20 2.26.2