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 ff48744f39..0c4cb09158 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -16731,9 +16731,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)
@@ -16747,5 +16749,10 @@ qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
}
}
+ if (virFileIsDir(snap_dir) && virFileDeleteTree(snap_dir) < 0) {
+ if (reportError)
+ return -1;
+ }
+
return 0;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 70cad837f2..6bde4d3de0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21938,6 +21938,30 @@ qemuDomainSetUserPassword(virDomainPtr dom,
}
+struct qemuDomainMomentWriteMetadataData {
+ virQEMUDriverPtr driver;
+ virDomainObjPtr vm;
+};
+
+
+static int
+qemuDomainSnapshotWriteMetadataIter(void *payload,
+ const void *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,
@@ -21955,6 +21979,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);
@@ -21994,6 +22022,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;
--
2.23.0