When share storage for the TPM state files has been setup betwen hosts then remove the TPM state files and directory only when undefining a VM and only if the attribute persistent_state is not set. Avoid removing the TPM state files and directory structure when a VM is migrated and shared storage is used since this would also remove those files and directory structure on the destination side. Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx> --- src/qemu/qemu_tpm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 20c7e92766..d1639318e7 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -728,10 +728,20 @@ qemuTPMEmulatorInitPaths(virDomainTPMDef *tpm, */ static void qemuTPMEmulatorCleanupHost(virDomainTPMDef *tpm, - qemuDomainUndefineReason undefReason G_GNUC_UNUSED) + qemuDomainUndefineReason undefReason) { - if (!tpm->data.emulator.persistent_state) + if (tpm->data.emulator.shared_storage) { + /* When using shared storage remove the domain only if this is due to + * a 'virsh undefine' type of command and only if persistent_state == + * false. Avoid removal of the state files/directory during migration. + */ + if (undefReason == QEMU_DOMAIN_UNDEFINE_DOMAIN && + !tpm->data.emulator.persistent_state) { + qemuTPMEmulatorDeleteStorage(tpm); + } + } else if (!tpm->data.emulator.persistent_state) { qemuTPMEmulatorDeleteStorage(tpm); + } } -- 2.37.1