[PATCH v2 7/9] qemu: tpm: Determine whether to remove TPM state during migration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement functions to determine whether to remove the TPM state
upon migration failure on the destination side or migration success
on the source side. In both cases always keep the state when shared
storage is used and always remove the state if no shared storage
is used.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
---
 src/qemu/qemu_migration.c | 13 ++++++++++---
 src/qemu/qemu_tpm.h       | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 431b1b0bcb..44e0488303 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3996,6 +3996,7 @@ qemuMigrationSrcConfirm(virQEMUDriver *driver,
 {
     qemuMigrationJobPhase phase;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    virDomainUndefineFlagsValues undefFlags = 0;
     int ret = -1;
 
     VIR_DEBUG("vm=%p, flags=0x%x, cancelled=%d", vm, flags, cancelled);
@@ -4044,7 +4045,9 @@ qemuMigrationSrcConfirm(virQEMUDriver *driver,
             virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
             vm->persistent = 0;
         }
-        qemuDomainRemoveInactive(driver, vm, VIR_DOMAIN_UNDEFINE_TPM);
+        if (!qemuTPMCheckKeepTPMStateMigrationSrcSuccess(flags))
+            undefFlags |= VIR_DOMAIN_UNDEFINE_TPM;
+        qemuDomainRemoveInactive(driver, vm, undefFlags);
     }
 
  cleanup:
@@ -6633,6 +6636,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver,
     virObjectEvent *event;
     bool inPostCopy = false;
     bool doKill = vm->job->phase != QEMU_MIGRATION_PHASE_FINISH_RESUME;
+    virDomainUndefineFlagsValues undefFlags = 0;
     int rc;
 
     VIR_DEBUG("vm=%p, flags=0x%lx, retcode=%d",
@@ -6709,8 +6713,11 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver,
                                  jobPriv->migParams, vm->job->apiFlags);
     }
 
-    if (!virDomainObjIsActive(vm))
-        qemuDomainRemoveInactive(driver, vm, VIR_DOMAIN_UNDEFINE_TPM);
+    if (!virDomainObjIsActive(vm)) {
+        if (!qemuTPMCheckKeepTPMStateMigrationDstFailure(flags))
+            undefFlags |= VIR_DOMAIN_UNDEFINE_TPM;
+        qemuDomainRemoveInactive(driver, vm, undefFlags);
+    }
 
     virErrorRestore(&orig_err);
     return NULL;
diff --git a/src/qemu/qemu_tpm.h b/src/qemu/qemu_tpm.h
index 630fa7074f..0cee08cd5c 100644
--- a/src/qemu/qemu_tpm.h
+++ b/src/qemu/qemu_tpm.h
@@ -60,3 +60,21 @@ int qemuExtTPMSetupCgroup(virQEMUDriver *driver,
 
 bool qemuTPMCanMigrateSharedStorage(virDomainDef *def)
     ATTRIBUTE_NONNULL(1);
+
+static inline bool
+qemuTPMCheckKeepTPMStateMigrationSrcSuccess(virDomainMigrateFlags flags)
+{
+    /* always keep state when migrating across shared storage */
+    if ((flags & VIR_MIGRATE_TPM_SHARED_STORAGE))
+        return true;
+    return false;
+}
+
+static inline bool
+qemuTPMCheckKeepTPMStateMigrationDstFailure(virDomainMigrateFlags flags)
+{
+    /* always keep state when migrating across shared storage */
+    if ((flags & VIR_MIGRATE_TPM_SHARED_STORAGE))
+        return true;
+    return false;
+}
-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux