[PATCH 24/24] qemu: command: Use 'qemuBuildChrChardevCommand' to build TPM backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                       | 25 +++++++------------
 .../aarch64-tpm.aarch64-latest.args           |  2 +-
 .../ppc64-tpmproxy-with-tpm.ppc64-latest.args |  2 +-
 .../tpm-emulator-spapr.ppc64-latest.args      |  2 +-
 .../tpm-emulator-tpm2-enc.x86_64-latest.args  |  2 +-
 ...pm-emulator-tpm2-pstate.x86_64-latest.args |  2 +-
 .../tpm-emulator-tpm2.x86_64-latest.args      |  2 +-
 .../tpm-emulator.x86_64-latest.args           |  2 +-
 8 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3ca7da9d5d..613f7a5d2a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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);
diff --git a/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args b/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args
index 77687b1d05..3125460a95 100644
--- a/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args
+++ b/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
index 104a5ef28c..90a27ca1a8 100644
--- a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
@@ -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"}' \
diff --git a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args b/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
index 90c207d544..97d310d8dc 100644
--- a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args b/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args
index 89a577d657..3b418917f3 100644
--- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args
@@ -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"}' \
diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args
index 89a577d657..3b418917f3 100644
--- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args
@@ -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"}' \
diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args b/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args
index 89a577d657..3b418917f3 100644
--- a/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args
@@ -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"}' \
diff --git a/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args b/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args
index 89a577d657..3b418917f3 100644
--- a/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args
@@ -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"}' \
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux