This is basically just saves checkpoints metadata on disk after name is changed
in memory as path to domain checkpoints directory depends on name. After that
old checkpoint directory is deleted with checkpoint metadata files.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/qemu/qemu_checkpoint.c | 2 +-
src/qemu/qemu_checkpoint.h | 6 ++++++
src/qemu/qemu_domain.c | 7 +++++++
src/qemu/qemu_driver.c | 23 +++++++++++++++++++++++
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index fb76c21..4a496d5 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -76,7 +76,7 @@ qemuCheckpointObjFromCheckpoint(virDomainObjPtr vm,
}
-static int
+int
qemuCheckpointWriteMetadata(virDomainObjPtr vm,
virDomainMomentObjPtr checkpoint,
virDomainXMLOptionPtr xmlopt,
diff --git a/src/qemu/qemu_checkpoint.h b/src/qemu/qemu_checkpoint.h
index 0d267a1..d58657e 100644
--- a/src/qemu/qemu_checkpoint.h
+++ b/src/qemu/qemu_checkpoint.h
@@ -79,3 +79,9 @@ qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
virJSONValuePtr actions,
const char *diskdst,
GSList **reopenimages);
+
+int
+qemuCheckpointWriteMetadata(virDomainObjPtr vm,
+ virDomainMomentObjPtr checkpoint,
+ virDomainXMLOptionPtr xmlopt,
+ const char *checkpointDir);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 258c8c5..422b534 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11104,10 +11104,12 @@ qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
g_autofree char *cfg_file = NULL;
g_autofree char *autostart_link = NULL;
g_autofree char *snap_dir = NULL;
+ g_autofree char *chk_dir = NULL;
cfg_file = virDomainConfigFile(cfg->configDir, name);
autostart_link = virDomainConfigFile(cfg->autostartDir, name);
snap_dir = g_strdup_printf("%s/%s", cfg->snapshotDir, name);
+ chk_dir = g_strdup_printf("%s/%s", cfg->checkpointDir, name);
if (virFileExists(cfg_file) &&
unlink(cfg_file) < 0) {
@@ -11128,5 +11130,10 @@ qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg,
!bestEffort)
return -1;
+ if (virFileIsDir(chk_dir) &&
+ virFileDeleteTree(chk_dir) < 0 &&
+ !bestEffort)
+ return -1;
+
return 0;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2664603..4e0186b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19126,6 +19126,24 @@ qemuDomainSnapshotWriteMetadataIter(void *payload,
static int
+qemuDomainCheckpointWriteMetadataIter(void *payload,
+ const char *name G_GNUC_UNUSED,
+ void *opaque)
+{
+ struct qemuDomainMomentWriteMetadataData *data = opaque;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(data->driver);
+ int ret;
+
+ ret = qemuCheckpointWriteMetadata(data->vm, payload,
+ data->driver->xmlopt,
+ cfg->snapshotDir);
+
+ virObjectUnref(cfg);
+ return ret;
+}
+
+
+static int
qemuDomainRenameCallback(virDomainObjPtr vm,
const char *new_name,
unsigned int flags,
@@ -19191,6 +19209,11 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
&data) < 0)
goto cleanup;
+ if (virDomainCheckpointForEach(vm->checkpoints,
+ qemuDomainCheckpointWriteMetadataIter,
+ &data) < 0)
+ goto cleanup;
+
if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0)
goto cleanup;
--
1.8.3.1