[libvirt PATCH 1/4] conf: Drop virDomainJobOperation parameter from virDomainObjIsPostcopy

Jiri Denemark jdenemar at redhat.com
Thu Dec 15 14:37:41 UTC 2022


The parameter was only used to select which states correspond to an
active or failed post-copy migration. But these states are either
applicable to both operations or the check would just paper over a code
bug in case of an impossible combination of state and operation. By
dropping the check we can make the code simpler and also reuse existing
virDomainObjIsFailedPostcopy function and only check for active
post-copy states.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/conf/domain_conf.c    | 23 +++++++----------------
 src/conf/domain_conf.h    |  3 +--
 src/qemu/qemu_driver.c    |  4 ++--
 src/qemu/qemu_migration.c |  6 +++---
 src/qemu/qemu_process.c   |  6 +++---
 5 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a180398b14..d1def730a4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27883,24 +27883,15 @@ virDomainObjIsFailedPostcopy(virDomainObj *dom)
 
 
 bool
-virDomainObjIsPostcopy(virDomainObj *dom,
-                       virDomainJobOperation op)
+virDomainObjIsPostcopy(virDomainObj *dom)
 {
-    if (op != VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN &&
-        op != VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT)
-        return false;
-
-    if (op == VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN) {
-        return (dom->state.state == VIR_DOMAIN_PAUSED &&
-                dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY_FAILED) ||
-               (dom->state.state == VIR_DOMAIN_RUNNING &&
-                (dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY ||
-                 dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY_FAILED));
-    }
+    if (virDomainObjIsFailedPostcopy(dom))
+        return true;
 
-    return dom->state.state == VIR_DOMAIN_PAUSED &&
-           (dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY ||
-            dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY_FAILED);
+    return (dom->state.state == VIR_DOMAIN_PAUSED &&
+            dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY) ||
+           (dom->state.state == VIR_DOMAIN_RUNNING &&
+            dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY);
 }
 
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c19dfc5470..3abf018574 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3933,8 +3933,7 @@ bool
 virDomainObjIsFailedPostcopy(virDomainObj *obj)
         ATTRIBUTE_NONNULL(1);
 bool
-virDomainObjIsPostcopy(virDomainObj *dom,
-                       virDomainJobOperation op)
+virDomainObjIsPostcopy(virDomainObj *dom)
         ATTRIBUTE_NONNULL(1);
 
 virSecurityLabelDef *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d509582719..dea3d65b57 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12614,7 +12614,7 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
 
     if (flags & VIR_DOMAIN_ABORT_JOB_POSTCOPY &&
         (vm->job->asyncJob != VIR_ASYNC_JOB_MIGRATION_OUT ||
-         !virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT))) {
+         !virDomainObjIsPostcopy(vm))) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("current job is not outgoing migration in post-copy mode"));
         goto endjob;
@@ -12639,7 +12639,7 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
         break;
 
     case VIR_ASYNC_JOB_MIGRATION_OUT:
-        if (virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT))
+        if (virDomainObjIsPostcopy(vm))
             ret = qemuDomainAbortJobPostcopy(vm, flags);
         else
             ret = qemuDomainAbortJobMigration(vm);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f4441d61ae..fd8583ca34 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2294,7 +2294,7 @@ qemuMigrationAnyConnectionClosed(virDomainObj *vm,
         break;
 
     case QEMU_MIGRATION_PHASE_PERFORM3_DONE:
-        if (virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT)) {
+        if (virDomainObjIsPostcopy(vm)) {
             VIR_DEBUG("Migration protocol interrupted in post-copy mode");
             postcopy = true;
         } else {
@@ -2683,7 +2683,7 @@ qemuMigrationAnyCanResume(virDomainObj *vm,
         return false;
     }
 
-    if (!virDomainObjIsPostcopy(vm, vm->job->current->operation)) {
+    if (!virDomainObjIsPostcopy(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("migration of domain %s is not in post-copy phase"),
                        vm->def->name);
@@ -3911,7 +3911,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
     if (retcode != 0 &&
-        virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT) &&
+        virDomainObjIsPostcopy(vm) &&
         currentData->stats.mig.status == QEMU_MONITOR_MIGRATION_STATUS_COMPLETED) {
         VIR_DEBUG("Finish phase failed, but QEMU reports post-copy migration is completed; forcing success");
         retcode = 0;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b6adcf2f2a..2e989256ff 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1503,7 +1503,7 @@ qemuProcessHandleMigrationStatus(qemuMonitor *mon G_GNUC_UNUSED,
          * watching it in any thread. Let's make sure the migration is properly
          * finished in case we get a "completed" event.
          */
-        if (virDomainObjIsPostcopy(vm, vm->job->current->operation) &&
+        if (virDomainObjIsPostcopy(vm) &&
             vm->job->phase == QEMU_MIGRATION_PHASE_POSTCOPY_FAILED &&
             vm->job->asyncOwner == 0) {
             qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION,
@@ -3476,7 +3476,7 @@ qemuProcessRecoverMigrationIn(virQEMUDriver *driver,
         /* migration finished, we started resuming the domain but didn't
          * confirm success or failure yet; killing it seems safest unless
          * we already started guest CPUs or we were in post-copy mode */
-        if (virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN))
+        if (virDomainObjIsPostcopy(vm))
             return 1;
 
         if (state != VIR_DOMAIN_RUNNING) {
@@ -3511,7 +3511,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriver *driver,
                                int reason,
                                unsigned int *stopFlags)
 {
-    bool postcopy = virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT);
+    bool postcopy = virDomainObjIsPostcopy(vm);
     bool resume = false;
 
     VIR_DEBUG("Active outgoing migration in phase %s",
-- 
2.39.0



More information about the libvir-list mailing list