From: Jiri Denemark <jdene...@redhat.com> When migrating a domain with TPM state on a shared disk, we need to skip TPM cleanup on both ends. So far the code only handled successful migration and skipped the cleanup on the source host. But if the migration failed for some reason, the cleanup would be incorrectly called on the destination host removing the TPM files even though the domain was still running on the source host.
https://issues.redhat.com/browse/RHEL-82411 Signed-off-by: Jiri Denemark <jdene...@redhat.com> --- src/qemu/qemu_driver.c | 7 +++++-- src/qemu/qemu_migration.c | 6 +++--- src/qemu/qemu_process.c | 8 ++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6ce949dd07..ebdec2c6fa 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3845,6 +3845,7 @@ processMonitorEOFEvent(virQEMUDriver *driver, const char *auditReason = "shutdown"; unsigned int stopFlags = 0; virObjectEvent *event = NULL; + bool migration; if (vm->def->id != domid) { VIR_DEBUG("Domain %s was restarted, ignoring EOF", @@ -3855,6 +3856,8 @@ processMonitorEOFEvent(virQEMUDriver *driver, if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, true) < 0) return; + migration = vm->job->asyncJob == VIR_ASYNC_JOB_MIGRATION_IN; + if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain %p '%s' is not active, ignoring EOF", vm, vm->def->name); @@ -3869,7 +3872,7 @@ processMonitorEOFEvent(virQEMUDriver *driver, auditReason = "failed"; } - if (vm->job->asyncJob == VIR_ASYNC_JOB_MIGRATION_IN) { + if (migration) { stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED; qemuMigrationDstErrorSave(driver, vm->def->name, qemuMonitorLastError(priv->mon)); @@ -3882,7 +3885,7 @@ processMonitorEOFEvent(virQEMUDriver *driver, virObjectEventStateQueue(driver->domainEventState, event); endjob: - qemuDomainRemoveInactive(driver, vm, 0, false); + qemuDomainRemoveInactive(driver, vm, 0, migration); qemuProcessEndStopJob(vm); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index e6056e9abc..bb4d74a65d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3609,7 +3609,7 @@ qemuMigrationDstPrepareFresh(virQEMUDriver *driver, * and there is no 'goto cleanup;' in the middle of those */ VIR_FREE(priv->origname); virDomainObjRemoveTransientDef(vm); - qemuDomainRemoveInactive(driver, vm, 0, false); + qemuDomainRemoveInactive(driver, vm, 0, true); } virDomainObjEndAPI(&vm); virErrorRestore(&origErr); @@ -6977,7 +6977,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver, } if (!qemuDomainObjIsActive(vm)) - qemuDomainRemoveInactive(driver, vm, VIR_DOMAIN_UNDEFINE_TPM, false); + qemuDomainRemoveInactive(driver, vm, VIR_DOMAIN_UNDEFINE_TPM, true); virErrorRestore(&orig_err); return NULL; @@ -7113,7 +7113,7 @@ qemuMigrationProcessUnattended(virQEMUDriver *driver, qemuMigrationJobFinish(vm); if (!virDomainObjIsActive(vm)) - qemuDomainRemoveInactive(driver, vm, 0, false); + qemuDomainRemoveInactive(driver, vm, 0, true); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 015a98d035..809029cefc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8913,7 +8913,6 @@ void qemuProcessStop(virQEMUDriver *driver, size_t i; g_autofree char *timestamp = NULL; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); - bool outgoingMigration; VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%lld, " "reason=%s, asyncJob=%s, flags=0x%x", @@ -8989,10 +8988,7 @@ void qemuProcessStop(virQEMUDriver *driver, qemuDomainCleanupRun(driver, vm); - outgoingMigration = (flags & VIR_QEMU_PROCESS_STOP_MIGRATED) && - (asyncJob == VIR_ASYNC_JOB_MIGRATION_OUT); - - qemuExtDevicesStop(driver, vm, outgoingMigration); + qemuExtDevicesStop(driver, vm, !!(flags & VIR_QEMU_PROCESS_STOP_MIGRATED)); qemuDBusStop(driver, vm); @@ -9258,7 +9254,7 @@ qemuProcessAutoDestroy(virDomainObj *dom, VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED_DESTROYED); - qemuDomainRemoveInactive(driver, dom, 0, false); + qemuDomainRemoveInactive(driver, dom, 0, !!(stopFlags & VIR_QEMU_PROCESS_STOP_MIGRATED)); qemuProcessEndStopJob(dom); -- 2.49.0