render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From a1c6dd1700b461d84c6db3d62468c60f4e3b0a55 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <a1c6dd1700b461d84c6db3d62468c60f4e3b0a55@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 14:45:38 +0200
3e5111
Subject: [PATCH] qemu: snapshot: Load data necessary for relative block commit
3e5111
 to work
3e5111
3e5111
Commit 7456c4f5f introduced a regression by not reloading the backing
3e5111
chain of a disk after snapshot. The regression was caused as
3e5111
src->relPath was not set and thus the block commit code could not
3e5111
determine the relative path.
3e5111
3e5111
This patch adds code that will load the backing store string if
3e5111
VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT and store it in the correct place
3e5111
when a snapshot is successfully completed.
3e5111
3e5111
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1461303
3e5111
(cherry picked from commit e20853e1d32ff517e6feec3146066ec433fc39e6)
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_driver.c | 19 +++++++++++++++++--
3e5111
 1 file changed, 17 insertions(+), 2 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
3e5111
index c7c5e28ca3..a2fb41b91a 100644
3e5111
--- a/src/qemu/qemu_driver.c
3e5111
+++ b/src/qemu/qemu_driver.c
3e5111
@@ -14094,6 +14094,7 @@ struct _qemuDomainSnapshotDiskData {
3e5111
     bool created; /* @src was created by the snapshot code */
3e5111
     bool prepared; /* @src was prepared using qemuDomainDiskChainElementPrepare */
3e5111
     virDomainDiskDefPtr disk;
3e5111
+    char *relPath; /* relative path component to fill into original disk */
3e5111
 
3e5111
     virStorageSourcePtr persistsrc;
3e5111
     virDomainDiskDefPtr persistdisk;
3e5111
@@ -14127,6 +14128,7 @@ qemuDomainSnapshotDiskDataFree(qemuDomainSnapshotDiskDataPtr data,
3e5111
             virStorageSourceFree(data[i].src);
3e5111
         }
3e5111
         virStorageSourceFree(data[i].persistsrc);
3e5111
+        VIR_FREE(data[i].relPath);
3e5111
     }
3e5111
 
3e5111
     VIR_FREE(data);
3e5111
@@ -14142,11 +14144,13 @@ qemuDomainSnapshotDiskDataFree(qemuDomainSnapshotDiskDataPtr data,
3e5111
 static qemuDomainSnapshotDiskDataPtr
3e5111
 qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
3e5111
                                   virDomainObjPtr vm,
3e5111
-                                  virDomainSnapshotObjPtr snap)
3e5111
+                                  virDomainSnapshotObjPtr snap,
3e5111
+                                  bool reuse)
3e5111
 {
3e5111
     size_t i;
3e5111
     qemuDomainSnapshotDiskDataPtr ret;
3e5111
     qemuDomainSnapshotDiskDataPtr dd;
3e5111
+    char *backingStoreStr;
3e5111
 
3e5111
     if (VIR_ALLOC_N(ret, snap->def->ndisks) < 0)
3e5111
         return NULL;
3e5111
@@ -14170,6 +14174,16 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
3e5111
 
3e5111
         dd->initialized = true;
3e5111
 
3e5111
+        /* relative backing store paths need to be updated so that relative
3e5111
+         * block commit still works */
3e5111
+        if (reuse &&
3e5111
+            (backingStoreStr = virStorageFileGetBackingStoreStr(dd->src))) {
3e5111
+            if (virStorageIsRelative(backingStoreStr))
3e5111
+                VIR_STEAL_PTR(dd->relPath, backingStoreStr);
3e5111
+            else
3e5111
+                VIR_FREE(backingStoreStr);
3e5111
+        }
3e5111
+
3e5111
         /* Note that it's unsafe to assume that the disks in the persistent
3e5111
          * definition match up with the disks in the live definition just by
3e5111
          * checking that the target name is the same. We've done that
3e5111
@@ -14213,6 +14227,7 @@ qemuDomainSnapshotUpdateDiskSources(qemuDomainSnapshotDiskDataPtr dd,
3e5111
     if (dd->initialized)
3e5111
         virStorageFileDeinit(dd->src);
3e5111
 
3e5111
+    VIR_STEAL_PTR(dd->disk->src->relPath, dd->relPath);
3e5111
     VIR_STEAL_PTR(dd->src->backingStore, dd->disk->src);
3e5111
     VIR_STEAL_PTR(dd->disk->src, dd->src);
3e5111
 
3e5111
@@ -14326,7 +14341,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
3e5111
 
3e5111
     /* prepare a list of objects to use in the vm definition so that we don't
3e5111
      * have to roll back later */
3e5111
-    if (!(diskdata = qemuDomainSnapshotDiskDataCollect(driver, vm, snap)))
3e5111
+    if (!(diskdata = qemuDomainSnapshotDiskDataCollect(driver, vm, snap, reuse)))
3e5111
         goto cleanup;
3e5111
 
3e5111
     cfg = virQEMUDriverGetConfig(driver);
3e5111
-- 
3e5111
2.13.1
3e5111