]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: Use 'qemuBuildChrChardevCommand' to build TPM backend
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Nov 2021 16:12:37 +0000 (17:12 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 10 Dec 2021 15:37:42 +0000 (16:37 +0100)
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>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args
tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args
tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args
tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args
tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args

index 3ca7da9d5d5e28ef8069319bcdf83c5131866561..613f7a5d2afcad21a067f054294f890709f9529d 100644 (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)))
-        return -1;
+    if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
+        if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtpm", qemuCaps) < 0)
+            return -1;
+    }
 
-    virCommandAddArgList(cmd, "-tpmdev", optstr, NULL);
-    VIR_FREE(optstr);
+    if (!(tpmdevstr = qemuBuildTPMBackendStr(cmd, tpm, &tpmfd, &cancelfd)))
+        return -1;
 
-    if (chardev)
-        virCommandAddArgList(cmd, "-chardev", chardev, NULL);
+    virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL);
 
     if (tpmfd >= 0) {
         fdset = qemuVirCommandGetFDSet(cmd, tpmfd);
index 77687b1d05172738c6b46abbade65b2f79f2283d..3125460a95e9c8504145d00d5dfd5000f35abe4e 100644 (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 \
index 104a5ef28c6d24a57db37e47c097f4ab28a74643..90a27ca1a85c5f07d0b86d805f33a257ad96e7fd 100644 (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"}' \
index 90c207d544dd020d586bfba31ea060e75215d388..97d310d8dcc121986f8c51ad182e6b2f33eed226 100644 (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 \
index 89a577d657ce72c08193ee05c279f6d540796335..3b418917f3287829366af68ba5bad0f4490e26cc 100644 (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"}' \
index 89a577d657ce72c08193ee05c279f6d540796335..3b418917f3287829366af68ba5bad0f4490e26cc 100644 (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"}' \
index 89a577d657ce72c08193ee05c279f6d540796335..3b418917f3287829366af68ba5bad0f4490e26cc 100644 (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"}' \
index 89a577d657ce72c08193ee05c279f6d540796335..3b418917f3287829366af68ba5bad0f4490e26cc 100644 (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"}' \