conf: Drop virDomainJobOperation parameter from virDomainObjIsPostcopy

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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jiri Denemark 2022-12-07 14:46:25 +01:00
parent 608c4b249e
commit b92cba67c6
5 changed files with 16 additions and 26 deletions

View File

@ -27931,24 +27931,15 @@ virDomainObjIsFailedPostcopy(virDomainObj *dom)
bool bool
virDomainObjIsPostcopy(virDomainObj *dom, virDomainObjIsPostcopy(virDomainObj *dom)
virDomainJobOperation op)
{ {
if (op != VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN && if (virDomainObjIsFailedPostcopy(dom))
op != VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT) return true;
return false;
if (op == VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN) { return (dom->state.state == VIR_DOMAIN_PAUSED &&
return (dom->state.state == VIR_DOMAIN_PAUSED && dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY) ||
dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY_FAILED) || (dom->state.state == VIR_DOMAIN_RUNNING &&
(dom->state.state == VIR_DOMAIN_RUNNING && dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY);
(dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY ||
dom->state.reason == VIR_DOMAIN_RUNNING_POSTCOPY_FAILED));
}
return dom->state.state == VIR_DOMAIN_PAUSED &&
(dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY ||
dom->state.reason == VIR_DOMAIN_PAUSED_POSTCOPY_FAILED);
} }

View File

@ -3962,8 +3962,7 @@ bool
virDomainObjIsFailedPostcopy(virDomainObj *obj) virDomainObjIsFailedPostcopy(virDomainObj *obj)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
bool bool
virDomainObjIsPostcopy(virDomainObj *dom, virDomainObjIsPostcopy(virDomainObj *dom)
virDomainJobOperation op)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
virSecurityLabelDef * virSecurityLabelDef *

View File

@ -12609,7 +12609,7 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
if (flags & VIR_DOMAIN_ABORT_JOB_POSTCOPY && if (flags & VIR_DOMAIN_ABORT_JOB_POSTCOPY &&
(vm->job->asyncJob != VIR_ASYNC_JOB_MIGRATION_OUT || (vm->job->asyncJob != VIR_ASYNC_JOB_MIGRATION_OUT ||
!virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT))) { !virDomainObjIsPostcopy(vm))) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("current job is not outgoing migration in post-copy mode")); _("current job is not outgoing migration in post-copy mode"));
goto endjob; goto endjob;
@ -12634,7 +12634,7 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
break; break;
case VIR_ASYNC_JOB_MIGRATION_OUT: case VIR_ASYNC_JOB_MIGRATION_OUT:
if (virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT)) if (virDomainObjIsPostcopy(vm))
ret = qemuDomainAbortJobPostcopy(vm, flags); ret = qemuDomainAbortJobPostcopy(vm, flags);
else else
ret = qemuDomainAbortJobMigration(vm); ret = qemuDomainAbortJobMigration(vm);

View File

@ -2292,7 +2292,7 @@ qemuMigrationAnyConnectionClosed(virDomainObj *vm,
break; break;
case QEMU_MIGRATION_PHASE_PERFORM3_DONE: 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"); VIR_DEBUG("Migration protocol interrupted in post-copy mode");
postcopy = true; postcopy = true;
} else { } else {
@ -2681,7 +2681,7 @@ qemuMigrationAnyCanResume(virDomainObj *vm,
return false; return false;
} }
if (!virDomainObjIsPostcopy(vm, vm->job->current->operation)) { if (!virDomainObjIsPostcopy(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
_("migration of domain %s is not in post-copy phase"), _("migration of domain %s is not in post-copy phase"),
vm->def->name); vm->def->name);
@ -3902,7 +3902,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
virCheckFlags(QEMU_MIGRATION_FLAGS, -1); virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
if (retcode != 0 && if (retcode != 0 &&
virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT) && virDomainObjIsPostcopy(vm) &&
currentData->stats.mig.status == QEMU_MONITOR_MIGRATION_STATUS_COMPLETED) { currentData->stats.mig.status == QEMU_MONITOR_MIGRATION_STATUS_COMPLETED) {
VIR_DEBUG("Finish phase failed, but QEMU reports post-copy migration is completed; forcing success"); VIR_DEBUG("Finish phase failed, but QEMU reports post-copy migration is completed; forcing success");
retcode = 0; retcode = 0;

View File

@ -1503,7 +1503,7 @@ qemuProcessHandleMigrationStatus(qemuMonitor *mon G_GNUC_UNUSED,
* watching it in any thread. Let's make sure the migration is properly * watching it in any thread. Let's make sure the migration is properly
* finished in case we get a "completed" event. * 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->phase == QEMU_MIGRATION_PHASE_POSTCOPY_FAILED &&
vm->job->asyncOwner == 0) { vm->job->asyncOwner == 0) {
qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION, qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION,
@ -3476,7 +3476,7 @@ qemuProcessRecoverMigrationIn(virQEMUDriver *driver,
/* migration finished, we started resuming the domain but didn't /* migration finished, we started resuming the domain but didn't
* confirm success or failure yet; killing it seems safest unless * confirm success or failure yet; killing it seems safest unless
* we already started guest CPUs or we were in post-copy mode */ * 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; return 1;
if (state != VIR_DOMAIN_RUNNING) { if (state != VIR_DOMAIN_RUNNING) {
@ -3511,7 +3511,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriver *driver,
int reason, int reason,
unsigned int *stopFlags) unsigned int *stopFlags)
{ {
bool postcopy = virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT); bool postcopy = virDomainObjIsPostcopy(vm);
bool resume = false; bool resume = false;
VIR_DEBUG("Active outgoing migration in phase %s", VIR_DEBUG("Active outgoing migration in phase %s",