]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Remove <backingStore> when changing cdrom media source
authorPeter Krempa <pkrempa@redhat.com>
Tue, 28 Jul 2015 13:34:58 +0000 (15:34 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 18 Feb 2016 08:50:45 +0000 (09:50 +0100)
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>

tools/virsh-domain.c

index 6dd75e224d2e5668ebc24e15498905c50fc616b7..7a8162bf7ae3af785df8f2c83e55494dcb3840f5 100644 (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);