Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/qemu/qemu_snapshot.c | 83 ++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 8656affa25..7e4dadb876 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1339,6 +1339,54 @@ qemuSnapshotCreateActiveExternalDisks(virDomainObj *vm, return 0; } +static int +qemuSnapshotSaveMemory(virQEMUDriver *driver, + virDomainObj *vm, + virDomainSnapshotDef *snapdef, + bool running, + virQEMUDriverConfig *cfg) +{ + qemuDomainObjPrivate *priv = vm->privateData; + g_autoptr(virCommand) compressor = NULL; + g_autoptr(virQEMUSaveData) data = NULL; + g_autofree char *xml = NULL; + int compressed; + + priv->job.current->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP; + + /* allow the migration job to be cancelled or the domain to be paused */ + qemuDomainObjSetAsyncJobMask(vm, (QEMU_JOB_DEFAULT_MASK | + JOB_MASK(QEMU_JOB_SUSPEND) | + JOB_MASK(QEMU_JOB_MIGRATION_OP))); + + if ((compressed = qemuSaveImageGetCompressionProgram(cfg->snapshotImageFormat, + &compressor, + "snapshot", false)) < 0) + return -1; + + if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, + vm->def, priv->origCPU, + true, true)) || + !(snapdef->cookie = (virObject *) qemuDomainSaveCookieNew(vm))) + return -1; + + if (!(data = virQEMUSaveDataNew(xml, + (qemuDomainSaveCookie *) snapdef->cookie, + running, compressed, driver->xmlopt))) + return -1; + xml = NULL; + + if (qemuSaveImageCreate(driver, vm, snapdef->memorysnapshotfile, + data, compressor, 0, + QEMU_ASYNC_JOB_SNAPSHOT) < 0) + return -1; + + /* forbid any further manipulation */ + qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_DEFAULT_MASK); + + return 0; +} + static int qemuSnapshotCreateActiveExternal(virQEMUDriver *driver, @@ -1351,16 +1399,12 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver, bool resume = false; int ret = -1; qemuDomainObjPrivate *priv = vm->privateData; - g_autofree char *xml = NULL; virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap); bool memory = snapdef->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; bool memory_unlink = false; bool memory_existing = false; bool thaw = false; bool pmsuspended = false; - int compressed; - g_autoptr(virCommand) compressor = NULL; - virQEMUSaveData *data = NULL; g_autoptr(GHashTable) blockNamedNodeData = NULL; /* check if migration is possible */ @@ -1425,43 +1469,15 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver, /* do the memory snapshot if necessary */ if (memory) { - priv->job.current->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP; - - /* allow the migration job to be cancelled or the domain to be paused */ - qemuDomainObjSetAsyncJobMask(vm, (QEMU_JOB_DEFAULT_MASK | - JOB_MASK(QEMU_JOB_SUSPEND) | - JOB_MASK(QEMU_JOB_MIGRATION_OP))); - - if ((compressed = qemuSaveImageGetCompressionProgram(cfg->snapshotImageFormat, - &compressor, - "snapshot", false)) < 0) - goto cleanup; - - if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps, - vm->def, priv->origCPU, - true, true)) || - !(snapdef->cookie = (virObject *) qemuDomainSaveCookieNew(vm))) - goto cleanup; - - if (!(data = virQEMUSaveDataNew(xml, - (qemuDomainSaveCookie *) snapdef->cookie, - resume, compressed, driver->xmlopt))) - goto cleanup; - xml = NULL; - memory_existing = virFileExists(snapdef->memorysnapshotfile); - if (qemuSaveImageCreate(driver, vm, snapdef->memorysnapshotfile, - data, compressor, 0, - QEMU_ASYNC_JOB_SNAPSHOT) < 0) + if (qemuSnapshotSaveMemory(driver, vm, snapdef, resume, cfg) < 0) goto cleanup; /* the memory image was created, remove it on errors */ if (!memory_existing) memory_unlink = true; - /* forbid any further manipulation */ - qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_DEFAULT_MASK); } /* the domain is now paused if a memory snapshot was requested */ @@ -1521,7 +1537,6 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver, qemuDomainObjEndAgentJob(vm); } - virQEMUSaveDataFree(data); if (memory_unlink && ret < 0) unlink(snapdef->memorysnapshotfile); -- 2.27.0