From nobody Mon Feb 9 12:29:05 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=1669990652; cv=none; d=zohomail.com; s=zohoarc; b=D9M/Du+PH285ybqLjjWbcMI58VV/mgivqWmS5tHoBxylX45QT3PUG31t2bO+37ujWfclvq48XUaASIz2zupA/V5kpOCiY5sIf5aNdLSmAO6rruFsv+i3cyzIOYk3m4EONmxqPOp9aLSLx98DgwvyI54sTAZP94sRBltqBqI0s6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669990652; 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=CMn5CupqJXMKdyjB441T/I+n2fhY3YtUCbAd/0+Q+gw=; b=DSSLMJHlejnnfbd2effVfg0dzc457B4Pm9EXI7hhe4nDC5gjhKg/nthVclkDeFqKTda9Zxv+sgfid8yJsk+ZLMv00NJU+jII9V37/X6hm3Tjwni2HC4eIZdsBzYCcNO13/Bs/KnzUBtz445h5KkkgCFn/GPfZHVGIQ6G3hUieLk= 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 166999065238239.18776103637981; Fri, 2 Dec 2022 06:17:32 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-3R2l15zWOg-dKGeqbDztiA-1; Fri, 02 Dec 2022 09:17:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2528894E96; Fri, 2 Dec 2022 14:17:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8FB040AE336; Fri, 2 Dec 2022 14:17:19 +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 8BF1B1946A48; Fri, 2 Dec 2022 14:17:19 +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 4488319465B8 for ; Fri, 2 Dec 2022 14:17:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2AA0340E9785; Fri, 2 Dec 2022 14:17:18 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B97C40E9788 for ; Fri, 2 Dec 2022 14:17:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669990650; 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=CMn5CupqJXMKdyjB441T/I+n2fhY3YtUCbAd/0+Q+gw=; b=Ed+h/xC/Yl1ncSQPoOzeVnA5Ro2HvD563PhSJzesas0YNsgMrY3xuZUSfYxyozLeDBc6wr 1lQ1qZ7ZoOrA3TIxOfLRcoDG7Plnlvad11pVLAlySgDrJQaNRybxXGJ5w3IzBTDEbgpbmc H1eDZAb35+sAMu8sMUaHChBI8gqqRN0= X-MC-Unique: 3R2l15zWOg-dKGeqbDztiA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/13] virshFindDisk: Use virXPathNodeSet instead of xmlXPathEval Date: Fri, 2 Dec 2022 15:16:54 +0100 Message-Id: <872387161399500d28d6a9f8cb3b85468e3b7d67.1669990545.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.1 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: 1669990654561100002 Content-Type: text/plain; charset="utf-8" Don't open-code the XPath lookup. Signed-off-by: Peter Krempa --- tools/virsh-domain.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c4cf7aa95e..1beaacd5e9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12639,8 +12639,9 @@ virshFindDisk(const char *doc, int type) { g_autoptr(xmlDoc) xml =3D NULL; - g_autoptr(xmlXPathObject) obj =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; + ssize_t nnodes; xmlNodePtr cur =3D NULL; size_t i; @@ -12650,21 +12651,17 @@ virshFindDisk(const char *doc, return NULL; } - obj =3D xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); - if (obj =3D=3D NULL || - obj->type !=3D XPATH_NODESET || - obj->nodesetval =3D=3D NULL || - obj->nodesetval->nodeNr =3D=3D 0) { + if ((nnodes =3D virXPathNodeSet("/domain/devices/disk", ctxt, &nodes))= <=3D 0) { vshError(NULL, "%s", _("Failed to get disk information")); return NULL; } /* search disk using @path */ - for (i =3D 0; i < obj->nodesetval->nodeNr; i++) { + for (i =3D 0; i < nnodes; i++) { bool is_supported =3D true; if (type =3D=3D VIRSH_FIND_DISK_CHANGEABLE) { - xmlNodePtr n =3D obj->nodesetval->nodeTab[i]; + xmlNodePtr n =3D nodes[i]; is_supported =3D false; /* Check if the disk is CDROM or floppy disk */ @@ -12680,7 +12677,7 @@ virshFindDisk(const char *doc, continue; } - cur =3D obj->nodesetval->nodeTab[i]->children; + cur =3D nodes[i]->children; while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { g_autofree char *tmp =3D NULL; @@ -12696,7 +12693,7 @@ virshFindDisk(const char *doc, } if (STREQ_NULLABLE(tmp, path)) { - xmlNodePtr ret =3D xmlCopyNode(obj->nodesetval->nodeTa= b[i], 1); + xmlNodePtr ret =3D xmlCopyNode(nodes[i], 1); /* drop backing store since they are not needed here */ virshDiskDropBackingStore(ret); return ret; --=20 2.38.1