From nobody Thu May 15 00:16:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518620437147356.09858183671133; Wed, 14 Feb 2018 07:00:37 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C759C024FE1; Wed, 14 Feb 2018 15:00:34 +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 6AF8A5D971; Wed, 14 Feb 2018 15:00:34 +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 2D04C4A475; Wed, 14 Feb 2018 15:00:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1EEwAlq017133 for ; Wed, 14 Feb 2018 09:58:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4A4A9B3015; Wed, 14 Feb 2018 14:58:10 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9D02B3034; Wed, 14 Feb 2018 14:58:09 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 14 Feb 2018 15:57:26 +0100 Message-Id: <829454ad2ac69d17ae59551f016592cd80de398a.1518618392.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/3] virsh: Remove sub-element in virshFindDisk 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Feb 2018 15:00:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Previously we've removed the data only in virshUpdateDiskXML when changing the disk source for the CDROM since the backing store would be invalid. Move the code into a separate function and callit from virshFindDisk which is also used when detaching disk. The detaching code does not necessarily need to get the full backing chain since it will need to act on the one managed by libvirt anyways and this also takes care of problems when parts of the backing store were invalid due to buggy RBD detection code. Signed-off-by: Peter Krempa --- tools/virsh-domain.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c10bf184f9..d158327bd7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12151,6 +12151,26 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *= cmd) return ret; } + +static void +virshDiskDropBackingStore(xmlNodePtr disk_node) +{ + xmlNodePtr tmp; + + for (tmp =3D disk_node->children; tmp; tmp =3D tmp->next) { + if (tmp->type !=3D XML_ELEMENT_NODE) + continue; + + if (virXMLNodeNameEqual(tmp, "backingStore")) { + xmlUnlinkNode(tmp); + xmlFreeNode(tmp); + + return; + } + } +} + + typedef enum { VIRSH_FIND_DISK_NORMAL, VIRSH_FIND_DISK_CHANGEABLE, @@ -12228,6 +12248,8 @@ virshFindDisk(const char *doc, if (STREQ_NULLABLE(tmp, path)) { ret =3D xmlCopyNode(obj->nodesetval->nodeTab[i], 1); + /* drop backing store since they are not needed here */ + virshDiskDropBackingStore(ret); VIR_FREE(tmp); goto cleanup; } @@ -12266,7 +12288,6 @@ virshUpdateDiskXML(xmlNodePtr disk_node, { xmlNodePtr tmp =3D NULL; xmlNodePtr source =3D NULL; - xmlNodePtr backingStore =3D NULL; xmlNodePtr target_node =3D NULL; xmlNodePtr text_node =3D NULL; char *device_type =3D NULL; @@ -12307,22 +12328,13 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (virXMLNodeNameEqual(tmp, "target")) target_node =3D tmp; - if (virXMLNodeNameEqual(tmp, "backingStore")) - backingStore =3D tmp; - /* * We've found all we needed. */ - if (source && target_node && backingStore) + if (source && target_node) break; } - /* drop the subtree since it would become invalid */ - if (backingStore) { - xmlUnlinkNode(backingStore); - xmlFreeNode(backingStore); - } - if (type =3D=3D VIRSH_UPDATE_DISK_XML_EJECT) { if (!source) { vshError(NULL, _("The disk device '%s' doesn't have media"), t= arget); --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list