From 89ba187943b0e3ca0ef0440541105d76be9e2459 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 5 Oct 2021 18:51:54 +0200 Subject: [PATCH] qemuBuildTPMCommandLine: Generate via JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We control only the 'tpmdev' property of TPM devices which is a string. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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 1376c5c34e..0361fc5657 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9948,24 +9948,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; } @@ -10092,12 +10101,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 \