qemuMigrationFetchJobStatus is rather inconvinient. If we poll
stats for status only then we don't need to update elapsed time.
Next on some paths we use this function to get stats only we don't
what to unexpectedly update job status. So the common part
is only enter/exit which is too little to have a distinct function.
Let's open code getting stats and update elapsed time and status
where appropriate.
The patch also drops qemuMigrationUpdateJobStatus. It's value
is only in keeping job status on failures. Now we have option
not to update status when we want to.
---
src/qemu/qemu_driver.c | 27 ++++++++++++-----
src/qemu/qemu_migration.c | 74 ++++++++++++++++-------------------------------
src/qemu/qemu_migration.h | 5 ----
3 files changed, 44 insertions(+), 62 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d1a64d7..d3da18a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13062,17 +13062,28 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
}
*jobInfo = *info;
- 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 {
+ if (jobInfo->status != QEMU_DOMAIN_JOB_STATUS_ACTIVE &&
+ jobInfo->status != QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
ret = 0;
+ goto cleanup;
}
+ if (fetch) {
+ int rv;
+
+ qemuDomainObjEnterMonitor(driver, vm);
+
+ rv = qemuMonitorGetMigrationStats(priv->mon, &jobInfo->stats);
+
+ if (qemuDomainObjExitMonitor(driver, vm) < 0 || rv < 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 6ddc4bd..5be79df 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2583,28 +2583,6 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
}
-int
-qemuMigrationFetchJobStatus(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob,
- qemuDomainJobInfoPtr jobInfo)
-{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- int rv;
-
- if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
- return -1;
-
- rv = qemuMonitorGetMigrationStats(priv->mon, &jobInfo->stats);
-
- if (qemuDomainObjExitMonitor(driver, vm) < 0 || rv < 0)
- return -1;
-
- qemuMigrationUpdateJobType(jobInfo);
- return qemuDomainJobInfoUpdateTime(jobInfo);
-}
-
-
static const char *
qemuMigrationJobName(virDomainObjPtr vm)
{
@@ -2624,23 +2602,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)
@@ -2650,10 +2611,18 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
bool events = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT);
- if (events)
- qemuMigrationUpdateJobType(jobInfo);
- else if (qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
- return -1;
+ if (!events) {
+ int rv;
+
+ if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+ return -1;
+
+ rv = qemuMonitorGetMigrationStats(priv->mon, &jobInfo->stats);
+
+ if (qemuDomainObjExitMonitor(driver, vm) < 0 || rv < 0)
+ return -1;
+ }
+ qemuMigrationUpdateJobType(jobInfo);
switch (jobInfo->status) {
case QEMU_DOMAIN_JOB_STATUS_NONE:
@@ -2791,9 +2760,13 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
}
}
- if (events)
- ignore_value(qemuMigrationUpdateJobStatus(driver, vm, asyncJob));
+ if (events && qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) {
+ ignore_value(qemuMonitorGetMigrationStats(priv->mon,
&jobInfo->stats));
+ ignore_value(qemuDomainObjExitMonitor(driver, vm));
+ }
+
+ qemuDomainJobInfoUpdateTime(jobInfo);
qemuDomainJobInfoUpdateDowntime(jobInfo);
VIR_FREE(priv->job.completed);
if (VIR_ALLOC(priv->job.completed) == 0)
@@ -4229,10 +4202,13 @@ 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)
- VIR_WARN("Could not refresh migration statistics");
+ qemuDomainObjEnterMonitorAsync(driver, vm,
+ QEMU_ASYNC_JOB_MIGRATION_OUT) == 0) {
+
+ ignore_value(qemuMonitorGetMigrationStats(priv->mon,
&jobInfo->stats));
+
+ ignore_value(qemuDomainObjExitMonitor(driver, vm));
+ }
qemuDomainJobInfoUpdateTime(jobInfo);
jobInfo->timeDeltaSet = mig->jobInfo->timeDeltaSet;
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 14c6178..9293859 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -245,11 +245,6 @@ int qemuMigrationToFile(virQEMUDriverPtr driver,
int qemuMigrationCancel(virQEMUDriverPtr driver,
virDomainObjPtr vm);
-int qemuMigrationFetchJobStatus(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob,
- qemuDomainJobInfoPtr jobInfo);
-
int qemuMigrationErrorInit(virQEMUDriverPtr driver);
void qemuMigrationErrorSave(virQEMUDriverPtr driver,
const char *name,
--
1.8.3.1