Since the code is changing the source image path by modifying the existing XML snippet the <backingStore> stays in place. As <backingStore> is relevant to the <source> 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 <backingStore> subtree once we want to update the XML. Before this patch, you'd get: $ virsh change-media --eject --print-xml 10 hdc <disk type="file" device="cdrom"> <driver name="qemu" type="qcow2"/> <backingStore type="file" index="1"> <format type="qcow2"/> <source file="/var/lib/libvirt/images/vm.1436949097"/> <backingStore/> </backingStore> <target dev="hdc" bus="ide"/> ... </disk> After: $ virsh change-media --eject --print-xml 10 hdc <disk type="file" device="cdrom"> <driver name="qemu" type="qcow2"/> <target dev="hdc" bus="ide"/> ... </disk> --- Notes: v2: - adapted to new version of code - fixed use after free from previous version - added more text to commit message 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 bf65a60..83edb21 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11052,6 +11052,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; @@ -11092,13 +11093,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 <backingStore> 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); -- 2.6.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list