On Mon, Aug 22, 2022 at 08:05:53AM -0400, Stefan Berger wrote: > 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. I think our current undefine behaviour is probably flawed. We go to the trouble of refusing to remove the firmware NVRAM when undefining because it contains important VM state, but then happily blow away the TPM state. Totally inconsistent behaviour :-( Its too late to change the default behaviour, but we likely ought to add a flag VIR_DOMAIN_UNDEFINE_KEEP_TPM and plumb that through the varius code paths, which would remove the need for this specific 'qemuDomainUndefineReason' enum. > > 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 > With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|