This is basically just saves snapshots metadata on disk after name is changed
in memory as path to domain snapshot directory depends on name. After that
old snapshot directory is deleted with snapshot metadata files.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/qemu/qemu_domain.c | 7 +++++++
src/qemu/qemu_driver.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7b2c165..258c8c5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11103,9 +11103,11 @@ qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
{
g_autofree char *cfg_file = NULL;
g_autofree char *autostart_link = NULL;
+ g_autofree char *snap_dir = NULL;
cfg_file = virDomainConfigFile(cfg->configDir, name);
autostart_link = virDomainConfigFile(cfg->autostartDir, name);
+ snap_dir = g_strdup_printf("%s/%s", cfg->snapshotDir, name);
if (virFileExists(cfg_file) &&
unlink(cfg_file) < 0) {
@@ -11121,5 +11123,10 @@ qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
return -1;
}
+ if (virFileIsDir(snap_dir) &&
+ virFileDeleteTree(snap_dir) < 0 &&
+ !bestEffort)
+ return -1;
+
return 0;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52c42cf..2664603 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19101,6 +19101,30 @@ qemuDomainSetUserPassword(virDomainPtr dom,
}
+struct qemuDomainMomentWriteMetadataData {
+ virQEMUDriverPtr driver;
+ virDomainObjPtr vm;
+};
+
+
+static int
+qemuDomainSnapshotWriteMetadataIter(void *payload,
+ const char *name G_GNUC_UNUSED,
+ void *opaque)
+{
+ struct qemuDomainMomentWriteMetadataData *data = opaque;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(data->driver);
+ int ret;
+
+ ret = qemuDomainSnapshotWriteMetadata(data->vm, payload,
+ data->driver->xmlopt,
+ cfg->snapshotDir);
+
+ virObjectUnref(cfg);
+ return ret;
+}
+
+
static int
qemuDomainRenameCallback(virDomainObjPtr vm,
const char *new_name,
@@ -19119,6 +19143,10 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
g_autofree char *old_dom_cfg_file = NULL;
g_autofree char *new_dom_autostart_link = NULL;
g_autofree char *old_dom_autostart_link = NULL;
+ struct qemuDomainMomentWriteMetadataData data = {
+ .driver = driver,
+ .vm = vm,
+ };
virCheckFlags(0, ret);
@@ -19158,6 +19186,11 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
vm->def->name = new_dom_name;
new_dom_name = NULL;
+ if (virDomainSnapshotForEach(vm->snapshots,
+ qemuDomainSnapshotWriteMetadataIter,
+ &data) < 0)
+ goto cleanup;
+
if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0)
goto cleanup;
--
1.8.3.1