virsh: Remove <backingStore> when changing cdrom media source

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>
This commit is contained in:
Peter Krempa 2015-07-28 15:34:58 +02:00
parent 71eb431c63
commit 3ad5186ed3

View File

@ -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 <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);