From nobody Mon Feb 9 08:30:44 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=1669990744; cv=none; d=zohomail.com; s=zohoarc; b=Xarfv0L2LgeYqQxOyW3Ygloi6dt1LPcRVzV7m8whAnjeb1RPZkhzfXjCMntOqw3DZm5Y77FkH8IshUljZYYOVaFjaylZ8qM4hX+7FLdxNYj/G4qgeCVYDKL+iyDtAptTIa9NiO2TsXiLmGZzSL5lN07WaHAwAjX6SPD1m6ouplE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669990744; 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=9kpkuNAcDWj7oMNlCuCKjPcRXodIpq8A/NrTsBHDaPA=; b=jsjlf7xbIM8oikx7GtWEWqhCbfawD0X2lTRsIMeDoIEI/pltDsMALYRER4V7SH54pQe20nn7JQrq87qMSsbOdZmjbYNU+smsSgo86ay2RCccplSQ1xtgnuGEZqBkI6vbsBPTjcsdtwCpgFoj9OZ0PBuaiH/efKNED6ww66mJJwQ= 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) 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 16699907447981022.0903351876763; Fri, 2 Dec 2022 06:19:04 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-FtxemdbXORWfmIjVsEQxYQ-1; Fri, 02 Dec 2022 09:17:16 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E1563810D3C; Fri, 2 Dec 2022 14:17:11 +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 2C059403165; Fri, 2 Dec 2022 14:17:11 +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 1A85319465A8; Fri, 2 Dec 2022 14:17:11 +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 236BC19465B8 for ; Fri, 2 Dec 2022 14:17:09 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 13C6A40E9788; Fri, 2 Dec 2022 14:17:09 +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 29CEB40E9785 for ; Fri, 2 Dec 2022 14:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669990743; 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=9kpkuNAcDWj7oMNlCuCKjPcRXodIpq8A/NrTsBHDaPA=; b=ZyOyyegkemcy+LJdljtr3NrGpnSGkZYgQAaC4XnxzeawnX2hP55/TJKaLfFTdIEYb4ZzU2 32TTTZYhVdWq0a3zLyHjQtl2ZZUrtgBGy/Iye9opaDK8X4IKPBtt7BFo7dZVRZoaqTldU2 Z4LksSygdUuVbwcQ0mZv0oJRl4f6yaw= X-MC-Unique: FtxemdbXORWfmIjVsEQxYQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/13] virsh: virshMakeCloneXML: Use virXPathNode instead of xmlXPathEval Date: Fri, 2 Dec 2022 15:16:51 +0100 Message-Id: <160ce46c1730ad3492da60a0ada7b971e9d9c867.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.10 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: 1669990745292100001 Content-Type: text/plain; charset="utf-8" Refactor the code to use the XPath helpers instead of open-coding them. Signed-off-by: Peter Krempa --- tools/virsh-volume.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index adfea570be..2a7809140e 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -505,28 +505,22 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) return true; } -static xmlChar * +static char * virshMakeCloneXML(const char *origxml, const char *newname) { g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; - g_autoptr(xmlXPathObject) obj =3D NULL; - xmlChar *newxml =3D NULL; - int size; + xmlNodePtr node; - doc =3D virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt= ); - if (!doc) + if (!(doc =3D virXMLParseStringCtxt(origxml, _("(volume_definition)"),= &ctxt))) return NULL; - obj =3D xmlXPathEval(BAD_CAST "/volume/name", ctxt); - if (obj =3D=3D NULL || obj->nodesetval =3D=3D NULL || - obj->nodesetval->nodeTab =3D=3D NULL) + if (!(node =3D virXPathNode("/volume/name", ctxt))) return NULL; - xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newnam= e); - xmlDocDumpMemory(doc, &newxml, &size); + xmlNodeSetContent(node, (const xmlChar *)newname); - return newxml; + return virXMLNodeToString(doc, doc->children); } /* @@ -574,7 +568,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) newvol =3D NULL; const char *name =3D NULL; g_autofree char *origxml =3D NULL; - g_autofree xmlChar *newxml =3D NULL; + g_autofree char *newxml =3D NULL; unsigned int flags =3D 0; if (!(origvol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) @@ -608,8 +602,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) return true; } - if (!(newvol =3D virStorageVolCreateXMLFrom(origpool, (char *) newxml, - origvol, flags))) { + if (!(newvol =3D virStorageVolCreateXMLFrom(origpool, newxml, origvol,= flags))) { vshError(ctl, _("Failed to clone vol from %s"), virStorageVolGetName(origvol)); return false; --=20 2.38.1