qemuMigrationFetchJobStatus is rather inconvinient. Some of its
callers don't need status to be updated, some don't need to update
elapsed time right away. So let's update status or elapsed time
in callers instead.
In qemuMigrationConfirmPhase we should fetch stats with copy
flag set as stats variable refers to domain object not the stack.
This patch drops updating job status on getting job stats by
client. This way we will not provide status 'completed' while
it is not yet updated by migration routine.
---
src/qemu/qemu_driver.c | 16 ++++++++-------
src/qemu/qemu_migration.c | 52 +++++++++++++++++++----------------------------
src/qemu/qemu_migration.h | 9 ++++----
3 files changed, 35 insertions(+), 42 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 48029be..f23503a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12789,15 +12789,17 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
- if (fetch)
- ret = qemuMigrationFetchJobStatus(driver, vm, QEMU_ASYNC_JOB_NONE,
- jobInfo);
- else
- ret = qemuDomainJobInfoUpdateTime(jobInfo);
- } else {
- ret = 0;
+ if (fetch &&
+ qemuMigrationFetchMigrationStats(driver, vm, QEMU_ASYNC_JOB_NONE,
+ &jobInfo->stats, false) < 0)
+ goto cleanup;
+
+ if (qemuDomainJobInfoUpdateTime(jobInfo) < 0)
+ goto cleanup;
}
+ ret = 0;
+
cleanup:
if (fetch)
qemuDomainObjEndJob(driver, vm);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 022fad0..1760908 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1344,24 +1344,28 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
int
-qemuMigrationFetchJobStatus(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob,
- qemuDomainJobInfoPtr jobInfo)
+qemuMigrationFetchMigrationStats(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ qemuDomainAsyncJob asyncJob,
+ qemuMonitorMigrationStatsPtr stats,
+ bool copy)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
+ qemuMonitorMigrationStats statsCopy;
int rv;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
- rv = qemuMonitorGetMigrationStats(priv->mon, &jobInfo->stats);
+ rv = qemuMonitorGetMigrationStats(priv->mon, copy ? &statsCopy : stats);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rv < 0)
return -1;
- qemuMigrationUpdateJobType(jobInfo);
- return qemuDomainJobInfoUpdateTime(jobInfo);
+ if (copy)
+ *stats = statsCopy;
+
+ return 0;
}
@@ -1384,23 +1388,6 @@ qemuMigrationJobName(virDomainObjPtr vm)
static int
-qemuMigrationUpdateJobStatus(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob)
-{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- qemuDomainJobInfoPtr jobInfo = priv->job.current;
- qemuDomainJobInfo newInfo = *jobInfo;
-
- if (qemuMigrationFetchJobStatus(driver, vm, asyncJob, &newInfo) < 0)
- return -1;
-
- *jobInfo = newInfo;
- return 0;
-}
-
-
-static int
qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob asyncJob)
@@ -1410,11 +1397,12 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
bool events = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT);
- if (events)
- qemuMigrationUpdateJobType(jobInfo);
- else if (qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
+ if (!events && qemuMigrationFetchMigrationStats(driver, vm, asyncJob,
+ &jobInfo->stats, true) <
0)
return -1;
+ qemuMigrationUpdateJobType(jobInfo);
+
switch (jobInfo->status) {
case QEMU_DOMAIN_JOB_STATUS_NONE:
virReportError(VIR_ERR_OPERATION_FAILED, _("%s: %s"),
@@ -1552,8 +1540,10 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
}
if (events)
- ignore_value(qemuMigrationUpdateJobStatus(driver, vm, asyncJob));
+ ignore_value(qemuMigrationFetchMigrationStats(driver, vm, asyncJob,
+ &jobInfo->stats, true));
+ qemuDomainJobInfoUpdateTime(jobInfo);
qemuDomainJobInfoUpdateDowntime(jobInfo);
VIR_FREE(priv->job.completed);
if (VIR_ALLOC(priv->job.completed) == 0)
@@ -3140,9 +3130,9 @@ qemuMigrationConfirmPhase(virQEMUDriverPtr driver,
*/
if (virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
reason == VIR_DOMAIN_PAUSED_POSTCOPY &&
- qemuMigrationFetchJobStatus(driver, vm,
- QEMU_ASYNC_JOB_MIGRATION_OUT,
- jobInfo) < 0)
+ qemuMigrationFetchMigrationStats(driver, vm,
+ QEMU_ASYNC_JOB_MIGRATION_OUT,
+ &jobInfo->stats, true) < 0)
VIR_WARN("Could not refresh migration statistics");
qemuDomainJobInfoUpdateTime(jobInfo);
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 6c51f5f..1f6ddba 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -279,10 +279,11 @@ qemuMigrationCancel(virQEMUDriverPtr driver,
virDomainObjPtr vm);
int
-qemuMigrationFetchJobStatus(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob,
- qemuDomainJobInfoPtr jobInfo);
+qemuMigrationFetchMigrationStats(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ qemuDomainAsyncJob asyncJob,
+ qemuMonitorMigrationStatsPtr stats,
+ bool copy);
int
qemuMigrationErrorInit(virQEMUDriverPtr driver);
--
1.8.3.1