From nobody Mon Feb 9 09:28:50 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=1664872412; cv=none; d=zohomail.com; s=zohoarc; b=OjsK6MyXOjQ15KRH1+qWOIRuvwuZ6vuIWEkNFp4PeeQNnhowMFcImFyLYMr9Ebf0aBNYLvyaUsm70Yr1Omtk/mMNAoaRZ4VjIkLiMVi23bTUnLbRPt1QUDx5XkG+mQFVwqCPJr4wWqAK80kUwAOifhr7uN7y+pDuwQdcB2NQ64s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664872412; 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=Gv+9LeLANq7p89o+d+ysU4obQJRlR0Ce5KWgEEOWRpU=; b=nllzA5uPfrI/J9zWBaWudpyfIh8tK7IXYbl9X9THieXZC8ngo2b/bd1QkbhVSRlfMB37XVWDzTSAF9n/AiMg4IDpua65WgKnj3jSPhNmZNHJJd72mQSq0Pq+/k9AVPdjNSYLYl4K5lYB7JGVAGK5hKseYE1Hle/Eo6EETGeazO0= 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 1664872412511250.58227406204674; Tue, 4 Oct 2022 01:33:32 -0700 (PDT) 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-128-Pc0WLqV1NGyJJ7QXgkBPZQ-1; Tue, 04 Oct 2022 04:33:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F76B88282C; Tue, 4 Oct 2022 08:33:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DC0F1121315; Tue, 4 Oct 2022 08:33:25 +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 0886D19465A2; Tue, 4 Oct 2022 08:33:25 +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 1BB721946588 for ; Tue, 4 Oct 2022 08:33:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0CF9640C6EC3; Tue, 4 Oct 2022 08:33:24 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FABA40C6EC2 for ; Tue, 4 Oct 2022 08:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664872411; 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=Gv+9LeLANq7p89o+d+ysU4obQJRlR0Ce5KWgEEOWRpU=; b=glmvzIFcfd6C1zl+ZhjCd8z7GQiAu9ald761Bz0qU1TIKK4ff1beYAGeN4L2MVH/RlSwvP Nu6uLChNdorQnMCNtXBAQwBag4T2FJgohLaJVYJxUGJHKccIaySRhBjnCFHxUiHw3BL9Pc sXS9TC09gh4x7KHs1cx0WgvYUQbtOM8= X-MC-Unique: Pc0WLqV1NGyJJ7QXgkBPZQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/43] virVBoxSnapshotConfGet(RW|RO)DisksPathsFromLibvirtXML: Refactor Date: Tue, 4 Oct 2022 10:32:39 +0200 Message-Id: <526d9a35e3a44be59bc40126d247767033761676.1664870258.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.3 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: 1664872413160100008 Content-Type: text/plain; charset="utf-8" virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML and virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML were doing the same thing, except for one XPath query. Factor out the common code into a helper and bring it up to modern standard. Signed-off-by: Peter Krempa --- src/vbox/vbox_snapshot_conf.c | 116 +++++++++++----------------------- 1 file changed, 36 insertions(+), 80 deletions(-) diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index e175f1964e..2f3f48d688 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -1187,60 +1187,55 @@ virVBoxSnapshotConfIsCurrentSnapshot(virVBoxSnapsho= tConfMachine *machine, return STREQ(snapshot->uuid, machine->currentSnapshot); } -/* - *getRWDisksPathsFromLibvirtXML: Parse a libvirt XML snapshot file, alloca= tes and - *fills a list of read-write disk paths. - *return array length on success, -1 on failure. - */ -int -virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath, - char ***rwDisksPath) +static int +virVBoxSnapshotConfGetDisksPathsFromLibvirtXML(const char *filePath, + char ***disksPath, + const char *xpath) { - int result =3D -1; size_t i =3D 0; - g_auto(GStrv) ret =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) xPathContext =3D NULL; - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; int nodeSize =3D 0; - *rwDisksPath =3D NULL; + + *disksPath =3D NULL; + if (filePath =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("filePath is null")); - goto cleanup; - } - xml =3D virXMLParse(filePath, NULL, NULL, NULL, &xPathContext, NULL, f= alse); - if (xml =3D=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Unable to parse the xml")); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("filePath is null")= ); + return -1; } - if ((nodeSize =3D virXPathNodeSet("/domainsnapshot/disks/disk", - xPathContext, &nodes)) < 0) - goto cleanup; + if (!(xml =3D virXMLParse(filePath, NULL, NULL, NULL, &xPathContext, N= ULL, false))) + return -1; + + if ((nodeSize =3D virXPathNodeSet(xpath, xPathContext, &nodes)) < 0) + return -1; - ret =3D g_new0(char *, nodeSize); + *disksPath =3D g_new0(char *, nodeSize); for (i =3D 0; i < nodeSize; i++) { - xmlNodePtr node =3D nodes[i]; - xmlNodePtr sourceNode; - - xPathContext->node =3D node; - sourceNode =3D virXPathNode("./source", xPathContext); - if (sourceNode) - ret[i] =3D virXMLPropString(sourceNode, "file"); + xPathContext->node =3D nodes[i]; + (*disksPath)[i] =3D virXPathString("string(./source/@file)", xPath= Context); } - *rwDisksPath =3D g_steal_pointer(&ret); - result =3D 0; - cleanup: - if (result < 0) - nodeSize =3D -1; - VIR_FREE(nodes); return nodeSize; } + +/* + *getRWDisksPathsFromLibvirtXML: Parse a libvirt XML snapshot file, alloca= tes and + *fills a list of read-write disk paths. + *return array length on success, -1 on failure. + */ +int +virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath, + char ***rwDisksPath) +{ + return virVBoxSnapshotConfGetDisksPathsFromLibvirtXML(filePath, rwDisk= sPath, + "/domainsnapshot= /disks/disk"); +} + + /* *getRODisksPathsFromLibvirtXML: *Parse a libvirt XML snapshot file, alloc= ates and fills *a list of read-only disk paths (the parents of the read-write disks). @@ -1250,50 +1245,11 @@ int virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath, char ***roDisksPath) { - int result =3D -1; - size_t i =3D 0; - g_auto(GStrv) ret =3D NULL; - g_autoptr(xmlDoc) xml =3D NULL; - g_autoptr(xmlXPathContext) xPathContext =3D NULL; - xmlNodePtr *nodes =3D NULL; - int nodeSize =3D 0; - if (filePath =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("filePath is null")); - goto cleanup; - } - xml =3D virXMLParse(filePath, NULL, NULL, NULL, &xPathContext, NULL, f= alse); - if (xml =3D=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Unable to parse the xml")); - goto cleanup; - } - - if ((nodeSize =3D virXPathNodeSet("/domainsnapshot/domain/devices/disk= ", - xPathContext, - &nodes)) < 0) - goto cleanup; - ret =3D g_new0(char *, nodeSize); - - for (i =3D 0; i < nodeSize; i++) { - xmlNodePtr node =3D nodes[i]; - xmlNodePtr sourceNode; - - xPathContext->node =3D node; - sourceNode =3D virXPathNode("./source", xPathContext); - if (sourceNode) - ret[i] =3D virXMLPropString(sourceNode, "file"); - } - *roDisksPath =3D g_steal_pointer(&ret); - result =3D 0; - - cleanup: - if (result < 0) - nodeSize =3D -1; - VIR_FREE(nodes); - return nodeSize; + return virVBoxSnapshotConfGetDisksPathsFromLibvirtXML(filePath, roDisk= sPath, + "/domainsnapshot= /domain/devices/disk"); } + /* *hardDiskUuidByLocation: Return the uuid of the hard disk whose location = is 'location' *return a valid uuid, or NULL on failure --=20 2.37.3