From 3ad5186ed3a511b53cd55c36feff8b2f98df61e7 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 28 Jul 2015 15:34:58 +0200 Subject: [PATCH] virsh: Remove when changing cdrom media source Since the code is changing the source image path by modifying the existing XML snippet the stays in place. As is relevant to the part of the image, the update of that part makes the element invalid. CD/floppy images usually don't have a backing chain and the element is currently ignored though but it might start being used in the future so let's start behaving correctly. Drop the subtree once we want to update the XML. Before this patch, you'd get: $ virsh change-media --eject --print-xml 10 hdc ... After: $ virsh change-media --eject --print-xml 10 hdc ... --- tools/virsh-domain.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6dd75e224d..7a8162bf7a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11054,6 +11054,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, { xmlNodePtr tmp = NULL; xmlNodePtr source = NULL; + xmlNodePtr backingStore = NULL; xmlNodePtr target_node = NULL; xmlNodePtr text_node = NULL; char *device_type = NULL; @@ -11094,13 +11095,22 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (xmlStrEqual(tmp->name, BAD_CAST "target")) target_node = tmp; + if (xmlStrEqual(tmp->name, BAD_CAST "backingStore")) + backingStore = tmp; + /* * We've found all we needed. */ - if (source && target_node) + if (source && target_node && backingStore) break; } + /* drop the subtree since it would become invalid */ + if (backingStore) { + xmlUnlinkNode(backingStore); + xmlFreeNode(backingStore); + } + if (type == VIRSH_UPDATE_DISK_XML_EJECT) { if (!source) { vshError(NULL, _("The disk device '%s' doesn't have media"), target);