]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: pull TPM capabilities probing out of main init method
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 24 Nov 2021 13:30:19 +0000 (13:30 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 1 Dec 2021 12:14:03 +0000 (12:14 +0000)
Many methods merely want to know that the swtpm binaries have been
found, and don't care about probing for capabilities. Even when
starting a guest, the QEMU driver may not need the capabilities.

Skipping probing ensures the VM startup path is as fast as possible
when capabilities are not required. It also removes various error
scenarios from the main init method.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virtpm.c

index 7e75c74d67811a21d473550ff3e36ac2f9434e20..ec51c0efb331e8812ca1e1de4de28eb617938dd1 100644 (file)
@@ -310,14 +310,8 @@ virTPMEmulatorInit(void)
                 return -1;
             }
             swtpmBinaries[i].path = g_steal_pointer(&path);
-
-            if (swtpmBinaries[i].capsParse) {
-                swtpmBinaries[i].caps = virTPMGetCaps(swtpmBinaries[i].capsParse,
-                                                      swtpmBinaries[i].path,
-                                                      swtpmBinaries[i].parm);
-                if (!swtpmBinaries[i].caps)
-                    return -1;
-            }
+            virBitmapFree(swtpmBinaries[i].caps);
+            swtpmBinaries[i].caps = NULL;
         }
     }
 
@@ -334,7 +328,16 @@ virTPMBinaryGetCaps(virTPMBinary binary,
 
     if (virTPMEmulatorInit() < 0)
         goto cleanup;
-    ret = virBitmapIsBitSet(swtpmBinaries[binary].caps, cap);
+
+    if (!swtpmBinaries[binary].caps &&
+        swtpmBinaries[binary].capsParse) {
+        swtpmBinaries[binary].caps = virTPMGetCaps(
+            swtpmBinaries[binary].capsParse,
+            swtpmBinaries[binary].path,
+            swtpmBinaries[binary].parm);
+    }
+    if (swtpmBinaries[binary].caps)
+        ret = virBitmapIsBitSet(swtpmBinaries[binary].caps, cap);
 
  cleanup:
     virMutexUnlock(&swtpm_tools_lock);