By separating it into a dedicated qemuMigrationSrcComplete function
which can be later called in other places.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_migration.c | 70 ++++++++++++++++++++++++---------------
src/qemu/qemu_migration.h | 5 +++
2 files changed, 48 insertions(+), 27 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index b62f7256c4..903c1dbf6b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3518,6 +3518,48 @@ qemuMigrationAnyPrepareDef(virQEMUDriver *driver,
}
+void
+qemuMigrationSrcComplete(virQEMUDriver *driver,
+ virDomainObj *vm,
+ virDomainAsyncJob asyncJob)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ virDomainJobData *jobData = priv->job.completed;
+ virObjectEvent *event;
+ int reason;
+
+ if (jobData) {
+ /* We need to refresh migration statistics after a completed post-copy
+ * migration since jobData contains obsolete data from the time we
+ * switched to post-copy mode.
+ */
+ if (virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
+ reason == VIR_DOMAIN_PAUSED_POSTCOPY) {
+ VIR_DEBUG("Refreshing migration statistics");
+ if (qemuMigrationAnyFetchStats(driver, vm, VIR_ASYNC_JOB_MIGRATION_OUT,
+ jobData, NULL) < 0)
+ VIR_WARN("Could not refresh migration statistics");
+ }
+
+ qemuDomainJobDataUpdateTime(jobData);
+ }
+
+ /* If guest uses SPICE and supports seamless migration we have to hold
+ * up domain shutdown until SPICE server transfers its data */
+ qemuMigrationSrcWaitForSpice(vm);
+
+ qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED, asyncJob,
+ VIR_QEMU_PROCESS_STOP_MIGRATED);
+ virDomainAuditStop(vm, "migrated");
+
+ event = virDomainEventLifecycleNewFromObj(vm,
+ VIR_DOMAIN_EVENT_STOPPED,
+ VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
+ virObjectEventStateQueue(driver->domainEventState, event);
+ qemuDomainEventEmitJobCompleted(driver, vm);
+}
+
+
static int
qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
virDomainObj *vm,
@@ -3527,7 +3569,6 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
int retcode)
{
g_autoptr(qemuMigrationCookie) mig = NULL;
- virObjectEvent *event;
qemuDomainObjPrivate *priv = vm->privateData;
qemuDomainJobPrivate *jobPriv = priv->job.privateData;
virDomainJobData *jobData = NULL;
@@ -3564,21 +3605,9 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
/* Update times with the values sent by the destination daemon */
if (mig->jobData && jobData) {
- int reason;
qemuDomainJobDataPrivate *privJob = jobData->privateData;
qemuDomainJobDataPrivate *privMigJob = mig->jobData->privateData;
- /* We need to refresh migration statistics after a completed post-copy
- * migration since priv->job.completed contains obsolete data from the
- * time we switched to post-copy mode.
- */
- if (virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
- reason == VIR_DOMAIN_PAUSED_POSTCOPY &&
- qemuMigrationAnyFetchStats(driver, vm, VIR_ASYNC_JOB_MIGRATION_OUT,
- jobData, NULL) < 0)
- VIR_WARN("Could not refresh migration statistics");
-
- qemuDomainJobDataUpdateTime(jobData);
jobData->timeDeltaSet = mig->jobData->timeDeltaSet;
jobData->timeDelta = mig->jobData->timeDelta;
privJob->stats.mig.downtime_set = privMigJob->stats.mig.downtime_set;
@@ -3592,20 +3621,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
* If something failed, resume CPUs, but only if we didn't use post-copy.
*/
if (retcode == 0) {
- /* If guest uses SPICE and supports seamless migration we have to hold
- * up domain shutdown until SPICE server transfers its data */
- qemuMigrationSrcWaitForSpice(vm);
-
- qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED,
- VIR_ASYNC_JOB_MIGRATION_OUT,
- VIR_QEMU_PROCESS_STOP_MIGRATED);
- virDomainAuditStop(vm, "migrated");
-
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STOPPED,
- VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
- virObjectEventStateQueue(driver->domainEventState, event);
- qemuDomainEventEmitJobCompleted(driver, vm);
+ qemuMigrationSrcComplete(driver, vm, VIR_ASYNC_JOB_MIGRATION_OUT);
} else {
virErrorPtr orig_err;
int reason;
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index ecb0ad6302..1d6051859b 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -205,6 +205,11 @@ qemuMigrationSrcConfirm(virQEMUDriver *driver,
unsigned int flags,
int cancelled);
+void
+qemuMigrationSrcComplete(virQEMUDriver *driver,
+ virDomainObj *vm,
+ virDomainAsyncJob asyncJob);
+
bool
qemuMigrationSrcIsAllowed(virQEMUDriver *driver,
virDomainObj *vm,
--
2.35.1