From nobody Mon Feb 9 17:06:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1594749679; cv=none; d=zohomail.com; s=zohoarc; b=av+g6m0YFhxOlNcw2OEqgqtrweVuHC9fvW4jSQdnpwe01/xtYJRSTgkBcHx64NA9AIQS/jo8b9NuNGIjJlZ5W6X4U6+1HKXvYeXAtR0ADVoquj71/FFZt+NMaIKdlVvtJlKKkT/LmAX4u8BOjQYnuUwyFid/NSxQGWt0qdNeMaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594749679; 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=BcREbi2vFMDoGRAOiCNBVUeVJKfmUEdXuKs1sLmkLeQ=; b=NL6G1WZM4k1tx2giNAd7qZec2D9oVEuUmnV2k/KZ0pJeiefd8HmBNx85s7biRPlCVaqRhVL+nufzMyPjd2GW+/boOOmhpeoQ+jaMfsSfTjgUmVPqEPF5CPkEp6y6KYzbjM98haxVGOfh/bxxGSrXHeR4c595v4yiz2cecgEk1Z4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594749679300910.2159632480228; Tue, 14 Jul 2020 11:01:19 -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-166-jEXEvi4OOVCgzm5rSkkMxw-1; Tue, 14 Jul 2020 14:01:15 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B047B10A51FA; Tue, 14 Jul 2020 18:00:32 +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 8E4161024889; Tue, 14 Jul 2020 18:00:31 +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 428FF18006D3; Tue, 14 Jul 2020 18:00:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06EI0T57024015 for ; Tue, 14 Jul 2020 14:00:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29F7A5FC30; Tue, 14 Jul 2020 18:00:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DE9A61474 for ; Tue, 14 Jul 2020 18:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594749678; 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=BcREbi2vFMDoGRAOiCNBVUeVJKfmUEdXuKs1sLmkLeQ=; b=hh67WQgWbVThIDNcB54DEV05qmnUOIdqYyVNyizwQcQqYXs8vQNHXzauMQLZtOh6PG+tMP ijLWGAWWpIyCSYPX+uIqMopXvDL+lTc4t1deXWDCI8cJbTZ341CCx/SFhJcIpeoSLqJtxZ o6JHZQar93vZtc7CUAGhlmj8MXi6t28= X-MC-Unique: jEXEvi4OOVCgzm5rSkkMxw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/11] virDomainHostdevSubsysSCSIiSCSIDefParseXML: Use XPath to fetch elements Date: Tue, 14 Jul 2020 20:00:14 +0200 Message-Id: <4a81fd5ab768130ed99430a66377271a2cc82778.1594749375.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.84 on 10.5.11.22 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" Conver the code to the new approach which uses XPath to fetch known elements rather than looping through all XML children. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 51 ++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c8ac4380c4..5988a13986 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8295,9 +8295,12 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePt= r sourcenode, virDomainXMLOptionPtr xmlopt) { int auth_secret_usage =3D -1; - xmlNodePtr cur; virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =3D &def->u.iscsi; g_autoptr(virStorageAuthDef) authdef =3D NULL; + xmlNodePtr node; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + + ctxt->node =3D sourcenode; /* For the purposes of command line creation, this needs to look * like a disk storage source */ @@ -8328,42 +8331,26 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodeP= tr sourcenode, return -1; } - cur =3D sourcenode->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "auth")) { - if (iscsisrc->src->auth) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("an definition already found for " - "the iSCSI definition")); - return -1; - } - if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) - return -1; - if ((auth_secret_usage =3D - virSecretUsageTypeFromString(authdef->secrettype)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid secret type %s"), - authdef->secrettype); - return -1; - } - if (auth_secret_usage !=3D VIR_SECRET_USAGE_TYPE_ISCSI) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("hostdev invalid secret type '%s'"), - authdef->secrettype); - return -1; - } - iscsisrc->src->auth =3D g_steal_pointer(&authdef); + if ((node =3D virXPathNode("./auth", ctxt))) { + if (!(authdef =3D virStorageAuthDefParse(node, ctxt))) + return -1; + if ((auth_secret_usage =3D virSecretUsageTypeFromString(authdef->s= ecrettype)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid secret type %s"), + authdef->secrettype); + return -1; } - cur =3D cur->next; + if (auth_secret_usage !=3D VIR_SECRET_USAGE_TYPE_ISCSI) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("hostdev invalid secret type '%s'"), + authdef->secrettype); + return -1; + } + iscsisrc->src->auth =3D g_steal_pointer(&authdef); } if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && xmlopt && xmlopt->privateData.storageParse) { - VIR_XPATH_NODE_AUTORESTORE(ctxt); - - ctxt->node =3D sourcenode; - if ((ctxt->node =3D virXPathNode("./privateData", ctxt)) && xmlopt->privateData.storageParse(ctxt, iscsisrc->src) < 0) return -1; --=20 2.26.2