]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Properly propagate migration state to TPM cleanup code
authorJiri Denemark <jdenemar@redhat.com>
Wed, 9 Apr 2025 13:35:20 +0000 (15:35 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 10 Apr 2025 12:15:13 +0000 (14:15 +0200)
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 <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/qemu/qemu_process.c

index 6ce949dd07402532ab393d3ed94bd175cfc864eb..ebdec2c6fad00e393217baf51108b1a77471821e 100644 (file)
@@ -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);
 }
 
index e6056e9abc45178c4c86d6f11b6df00c3e4c1cf2..bb4d74a65d2603a1f32b409174a84776edbf9557 100644 (file)
@@ -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);
 }
 
 
index 015a98d035dbff12d04f73248b8b0f4806c41e59..809029cefcc1ca860e268f3de0c518e6437667e7 100644 (file)
@@ -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);