[PATCH 2/2] qemu_tpm: Try harder to create emulator state

Ján Tomko jtomko at redhat.com
Fri Jul 21 12:49:04 UTC 2023


On a Friday in 2023, Michal Privoznik wrote:
>If a per-domain SWTPM state directory exists but is empty our
>code still considers it a valid state and skips running
>'swtpm_setup' (handled in qemuTPMEmulatorRunSetup()).
>While we should not try to inspect individual files created by
>swtpm, we can still consider empty folder as non-existent state.
>
>Resolves: https://gitlab.com/libvirt/libvirt/-/issues/320
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/qemu/qemu_tpm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
>index 0b77ce2bc7..121f98174c 100644
>--- a/src/qemu/qemu_tpm.c
>+++ b/src/qemu/qemu_tpm.c
>@@ -186,7 +186,8 @@ qemuTPMEmulatorCreateStorage(virDomainTPMDef *tpm,
>
>     *created = false;
>
>-    if (!virFileExists(storagepath))
>+    if (!virFileExists(storagepath) ||
>+        virDirIsEmpty(storagepath, false) > 0)
>         *created = true;
>

This means we will possibly delete a directory we did not create on
error in qemuTPMEmulatorBuildCommand. That is possibly harmless,
but I would call virDirIsEmpty with hidden=true, to make sure
we don't delete a non-empty directory.

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano


>     if (virDirCreate(storagepath, 0700, swtpm_user, swtpm_group,
>-- 
>2.41.0
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20230721/dd990892/attachment.sig>


More information about the libvir-list mailing list