]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move adding --tpmstate to swtpm command line into own function
authorStefan Berger <stefanb@linux.ibm.com>
Wed, 13 Nov 2024 17:39:50 +0000 (12:39 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Nov 2024 07:46:44 +0000 (08:46 +0100)
Factor-out code related to adding the --tpmstate option to the swtpm
command line into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_tpm.c

index d8c1e96a2ae78aef8a23903def4e87d39c44eea5..6d56a845a4e380d5444be716471976b7877ba525 100644 (file)
@@ -609,6 +609,25 @@ qemuTPMVirCommandSwtpmAddEncryption(virCommand *cmd,
     return 0;
 }
 
+static void
+qemuTPMVirCommandSwtpmAddTPMState(virCommand *cmd,
+                                  const virDomainTPMEmulatorDef *emulator)
+{
+    virCommandAddArg(cmd, "--tpmstate");
+    switch (emulator->source_type) {
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_FILE:
+        virCommandAddArgFormat(cmd, "backend-uri=file://%s",
+                               emulator->source_path);
+        break;
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_DIR:
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT:
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_LAST:
+        virCommandAddArgFormat(cmd, "dir=%s,mode=0600",
+                               emulator->source_path);
+        break;
+    }
+}
+
 /*
  * qemuTPMEmulatorBuildCommand:
  *
@@ -692,19 +711,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
     virCommandAddArgFormat(cmd, "type=unixio,path=%s,mode=0600",
                            tpm->data.emulator.source->data.nix.path);
 
-    virCommandAddArg(cmd, "--tpmstate");
-    switch (tpm->data.emulator.source_type) {
-    case VIR_DOMAIN_TPM_SOURCE_TYPE_FILE:
-        virCommandAddArgFormat(cmd, "backend-uri=file://%s",
-                               tpm->data.emulator.source_path);
-        break;
-    case VIR_DOMAIN_TPM_SOURCE_TYPE_DIR:
-    case VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT:
-    case VIR_DOMAIN_TPM_SOURCE_TYPE_LAST:
-        virCommandAddArgFormat(cmd, "dir=%s,mode=0600",
-                               tpm->data.emulator.source_path);
-        break;
-    }
+    qemuTPMVirCommandSwtpmAddTPMState(cmd, &tpm->data.emulator);
 
     virCommandAddArg(cmd, "--log");
     if (tpm->data.emulator.debug != 0)