qemu: Move adding --tpmstate to swtpm command line into own function

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>
This commit is contained in:
Stefan Berger 2024-11-13 12:39:50 -05:00 committed by Michal Privoznik
parent fc9a333f37
commit 957bda01c8

View File

@ -609,6 +609,25 @@ qemuTPMVirCommandSwtpmAddEncryption(virCommand *cmd,
return 0; 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: * qemuTPMEmulatorBuildCommand:
* *
@ -692,19 +711,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
virCommandAddArgFormat(cmd, "type=unixio,path=%s,mode=0600", virCommandAddArgFormat(cmd, "type=unixio,path=%s,mode=0600",
tpm->data.emulator.source->data.nix.path); tpm->data.emulator.source->data.nix.path);
virCommandAddArg(cmd, "--tpmstate"); qemuTPMVirCommandSwtpmAddTPMState(cmd, &tpm->data.emulator);
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;
}
virCommandAddArg(cmd, "--log"); virCommandAddArg(cmd, "--log");
if (tpm->data.emulator.debug != 0) if (tpm->data.emulator.debug != 0)