qemu: command: Use 'qemuBuildChrChardevCommand' to build TPM backend

Since the backend of the TPM is a chardev we can use the common helper
to instantiate it.

This commit also ensures proper ordering so that the backend chardev is
formatted before it's being referenced.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-11-05 17:12:37 +01:00
parent 5c62df7e78
commit 1ee3314c10
8 changed files with 16 additions and 23 deletions

View File

@ -9734,8 +9734,7 @@ static char *
qemuBuildTPMBackendStr(virCommand *cmd,
virDomainTPMDef *tpm,
int *tpmfd,
int *cancelfd,
char **chardev)
int *cancelfd)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *cancel_path = NULL;
@ -9774,10 +9773,6 @@ qemuBuildTPMBackendStr(virCommand *cmd,
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
virBufferAddLit(&buf, ",chardev=chrtpm");
*chardev = g_strdup_printf("socket,id=chrtpm,path=%s",
tpm->data.emulator.source->data.nix.path);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
return NULL;
@ -9793,22 +9788,20 @@ qemuBuildTPMCommandLine(virCommand *cmd,
virDomainTPMDef *tpm,
virQEMUCaps *qemuCaps)
{
char *optstr;
g_autofree char *chardev = NULL;
g_autofree char *tpmdevstr = NULL;
int tpmfd = -1;
int cancelfd = -1;
char *fdset;
if (!(optstr = qemuBuildTPMBackendStr(cmd, tpm,
&tpmfd, &cancelfd,
&chardev)))
if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtpm", qemuCaps) < 0)
return -1;
}
if (!(tpmdevstr = qemuBuildTPMBackendStr(cmd, tpm, &tpmfd, &cancelfd)))
return -1;
virCommandAddArgList(cmd, "-tpmdev", optstr, NULL);
VIR_FREE(optstr);
if (chardev)
virCommandAddArgList(cmd, "-chardev", chardev, NULL);
virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL);
if (tpmfd >= 0) {
fdset = qemuVirCommandGetFDSet(cmd, tpmfd);

View File

@ -27,8 +27,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-aarch64test/.config \
-no-shutdown \
-no-acpi \
-boot strict=on \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-tis-device","tpmdev":"tpm-tpm0","id":"tpm0"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \

View File

@ -28,8 +28,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
-boot strict=on \
-device '{"driver":"pci-ohci","id":"usb","bus":"pci.0","addr":"0x1"}' \
-device '{"driver":"spapr-tpm-proxy","id":"tpm0","host-path":"/dev/tpmrm0"}' \
-tpmdev emulator,id=tpm-tpm1,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm1,chardev=chrtpm \
-device '{"driver":"tpm-spapr","tpmdev":"tpm-tpm1","id":"tpm1","reg":16384}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x6"}' \

View File

@ -36,8 +36,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-device '{"driver":"spapr-vty","chardev":"charserial0","id":"serial0","reg":805306368}' \
-chardev pty,id=charserial1 \
-device '{"driver":"spapr-vty","chardev":"charserial1","id":"serial1","reg":805310464}' \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-spapr","tpmdev":"tpm-tpm0","id":"tpm0","reg":20480}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-global spapr-nvram.reg=0x4000 \

View File

@ -27,8 +27,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-no-shutdown \
-boot menu=on,strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \

View File

@ -27,8 +27,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-no-shutdown \
-boot menu=on,strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \

View File

@ -27,8 +27,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-no-shutdown \
-boot menu=on,strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \

View File

@ -27,8 +27,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-no-shutdown \
-boot menu=on,strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \
-audiodev '{"id":"audio1","driver":"none"}' \
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \