This new option will be used by external snapshot revert code.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
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 f6725c0e7b..d8ebf786cf 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -578,6 +578,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
@@ -595,6 +597,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.
@@ -603,7 +609,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);
@@ -711,7 +718,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;
@@ -967,8 +974,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 e7fce053b4..83d97e629c 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -8721,7 +8721,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