[libvirt PATCH v3 05/25] virDomainSnapshotAlignDisks: Allow overriding user-configured snapshot default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This new option will be used by external snapshot revert code.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/snapshot_conf.c | 15 ++++++++++++---
 src/conf/snapshot_conf.h |  3 ++-
 src/qemu/qemu_snapshot.c |  2 +-
 src/test/test_driver.c   |  2 +-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 8ecf311a17..67cec34920 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -581,6 +581,8 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def,
  * @default_snapshot: snapshot location to assign to disks which don't have any
  * @uniform_internal_snapshot: Require that for an internal snapshot all disks
  *                             take part in the internal snapshot
+ * @force_default_location: Always use @default_snapshot even if domain def
+ *                          has different default value
  *
  * Align snapdef->disks to domain definition, filling in any missing disks or
  * snapshot state defaults given by the domain, with a fallback to
@@ -598,6 +600,10 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def,
  * in the internal snapshot. This is for hypervisors where granularity of an
  * internal snapshot can't be controlled.
  *
+ * When @force_default_location is true we will always use @default_snapshot
+ * even if domain definition has different default set. This is required to
+ * create new snapshot definition when reverting external snapshots.
+ *
  * Convert paths to disk targets for uniformity.
  *
  * On error -1 is returned and a libvirt error is reported.
@@ -606,7 +612,8 @@ int
 virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapdef,
                             virDomainDef *existingDomainDef,
                             virDomainSnapshotLocation default_snapshot,
-                            bool uniform_internal_snapshot)
+                            bool uniform_internal_snapshot,
+                            bool force_default_location)
 {
     virDomainDef *domdef = snapdef->parent.dom;
     g_autoptr(GHashTable) map = virHashNew(NULL);
@@ -714,7 +721,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapdef,
         /* Don't snapshot empty drives */
         if (virStorageSourceIsEmpty(domdef->disks[i]->src))
             snapdisk->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
-        else
+        else if (!force_default_location)
             snapdisk->snapshot = domdef->disks[i]->snapshot;
 
         snapdisk->src->type = VIR_STORAGE_TYPE_FILE;
@@ -970,8 +977,10 @@ virDomainSnapshotRedefinePrep(virDomainObj *vm,
         virDomainSnapshotDefIsExternal(snapdef))
         align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
 
-    if (virDomainSnapshotAlignDisks(snapdef, otherDomDef, align_location, true) < 0)
+    if (virDomainSnapshotAlignDisks(snapdef, otherDomDef, align_location,
+                                    true, false) < 0) {
         return -1;
+    }
 
     return 0;
 }
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index ab76af604a..14254d1c86 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -126,7 +126,8 @@ char *virDomainSnapshotDefFormat(const char *uuidstr,
 int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapshot,
                                 virDomainDef *existingDomainDef,
                                 virDomainSnapshotLocation default_snapshot,
-                                bool uniform_internal_snapshot);
+                                bool uniform_internal_snapshot,
+                                bool force_default_location);
 
 bool virDomainSnapshotDefIsExternal(virDomainSnapshotDef *def);
 bool virDomainSnapshotIsExternal(virDomainMomentObj *snap);
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 91de8b0c31..844b02d427 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -1585,7 +1585,7 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
         else
             def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
     }
-    if (virDomainSnapshotAlignDisks(def, NULL, align_location, true) < 0)
+    if (virDomainSnapshotAlignDisks(def, NULL, align_location, true, false) < 0)
         return -1;
 
     return 0;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4b8e02c684..905be3853b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -8724,7 +8724,7 @@ testDomainSnapshotAlignDisks(virDomainObj *vm,
                       VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
     }
 
-    return virDomainSnapshotAlignDisks(def, NULL, align_location, true);
+    return virDomainSnapshotAlignDisks(def, NULL, align_location, true, false);
 }
 
 
-- 
2.41.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux