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>
{
xmlNodePtr tmp = NULL;
xmlNodePtr source = NULL;
+ xmlNodePtr backingStore = NULL;
xmlNodePtr target_node = NULL;
xmlNodePtr text_node = NULL;
char *device_type = NULL;
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);