]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: snapshot: Don't modify persistent XML if disk source is different
authorPeter Krempa <pkrempa@redhat.com>
Fri, 9 Aug 2019 13:15:07 +0000 (15:15 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Aug 2019 11:49:17 +0000 (13:49 +0200)
While the VM is running the persistent source of a disk might differ
e.g. as the 'newDef' was redefined. Our snapshot code would blindly
rewrite the source of such disk if it shared the 'target'. Fix this by
checking whether the source is the same in the first place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c

index 1b051a94244e0218836a4671124eed5cdc4bec94..87a3a13ef82086f9ac1f5d69e1d40564b85fe35d 100644 (file)
@@ -15318,6 +15318,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
     qemuDomainSnapshotDiskDataPtr dd;
     char *backingStoreStr;
     virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
+    virDomainDiskDefPtr persistdisk;
     int ret = -1;
 
     if (VIR_ALLOC_N(data, snapdef->ndisks) < 0)
@@ -15338,13 +15339,12 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
         if (virStorageSourceInitChainElement(dd->src, dd->disk->src, false) < 0)
             goto cleanup;
 
-        /* Note that it's unsafe to assume that the disks in the persistent
-         * definition match up with the disks in the live definition just by
-         * checking that the target name is the same. We've done that
-         * historically this way though. */
+        /* modify disk in persistent definition only when the source is the same */
         if (vm->newDef &&
-            (dd->persistdisk = virDomainDiskByName(vm->newDef, dd->disk->dst,
-                                                   false))) {
+            (persistdisk = virDomainDiskByName(vm->newDef, dd->disk->dst, false)) &&
+            virStorageSourceIsSameLocation(dd->disk->src, persistdisk->src)) {
+
+            dd->persistdisk = persistdisk;
 
             if (!(dd->persistsrc = virStorageSourceCopy(dd->src, false)))
                 goto cleanup;