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>
---
src/qemu/qemu_tpm.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index bf07b86793..a7eee501bf 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -608,6 +608,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:
*
@@ -691,19 +710,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)
--
2.47.0