We control only the 'tpmdev' property of TPM devices which is a string.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 32 +++++++++++--------
.../ppc64-tpmproxy-with-tpm.ppc64-latest.args | 2 +-
.../tpm-emulator-spapr.ppc64-latest.args | 2 +-
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 306dcc6b8c..53f38ff306 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9912,24 +9912,33 @@ qemuBuildDomainLoaderCommandLine(virCommand *cmd,
}
-static char *
-qemuBuildTPMDevStr(const virDomainDef *def,
+static int
+qemuBuildTPMDevCmd(virCommand *cmd,
+ const virDomainDef *def,
virDomainTPMDef *tpm,
- virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+ virQEMUCaps *qemuCaps)
{
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_autoptr(virJSONValue) props = NULL;
const char *model = virDomainTPMModelTypeToString(tpm->model);
+ g_autofree char *tpmdev = g_strdup_printf("tpm-%s", tpm->info.alias);
if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && def->os.arch ==
VIR_ARCH_AARCH64)
model = "tpm-tis-device";
- virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
- model, tpm->info.alias, tpm->info.alias);
+ if (virJSONValueObjectCreate(&props,
+ "s:driver", model,
+ "s:tpmdev", tpmdev,
+ "s:id", tpm->info.alias,
+ NULL) < 0)
+ return -1;
- if (qemuBuildDeviceAddressStr(&buf, def, &tpm->info) < 0)
- return NULL;
+ if (qemuBuildDeviceAddressProps(props, def, &tpm->info) < 0)
+ return -1;
- return virBufferContentAndReset(&buf);
+ if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0)
+ return -1;
+
+ return 0;
}
@@ -10056,12 +10065,9 @@ qemuBuildTPMCommandLine(virCommand *cmd,
VIR_FREE(fdset);
}
- if (!(optstr = qemuBuildTPMDevStr(def, tpm, qemuCaps)))
+ if (qemuBuildTPMDevCmd(cmd, def, tpm, qemuCaps) < 0)
return -1;
- virCommandAddArgList(cmd, "-device", optstr, NULL);
- VIR_FREE(optstr);
-
return 0;
}
diff --git a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
index d72f7efe06..e20fe53b3c 100644
--- a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args
@@ -29,7 +29,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
-device spapr-tpm-proxy,id=tpm0,host-path=/dev/tpmrm0 \
-tpmdev emulator,id=tpm-tpm1,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
--device tpm-spapr,tpmdev=tpm-tpm1,id=tpm1,reg=0x00004000 \
+-device tpm-spapr,tpmdev=tpm-tpm1,id=tpm1,reg=16384 \
-audiodev id=audio1,driver=none \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
diff --git a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
b/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
index c8dc4c74fe..8875b38ad5 100644
--- a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
+++ b/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args
@@ -37,7 +37,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
-device spapr-vty,chardev=charserial1,id=serial1,reg=805310464 \
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
-chardev socket,id=chrtpm,path=/dev/test \
--device tpm-spapr,tpmdev=tpm-tpm0,id=tpm0,reg=0x00005000 \
+-device tpm-spapr,tpmdev=tpm-tpm0,id=tpm0,reg=20480 \
-audiodev id=audio1,driver=none \
-global spapr-nvram.reg=0x4000 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
--
2.31.1