From feaeab09eac371b9c2abe2471fa86a52bf8cc918 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Sat, 25 Sep 2021 09:08:05 +0200 Subject: [PATCH] qemu: command: Introduce helper for building JSON props of -device into commandline MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The helper converts the JSON object to a string and adds it to the current command as arguments of '-device'. The helper also prepares for '-device' taking JSON directly. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f1c67d1e61..3bacb95090 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -221,6 +221,33 @@ qemuBuildNetdevCommandlineFromJSON(virCommand *cmd, } +static G_GNUC_UNUSED int +qemuBuildDeviceCommandlineFromJSON(virCommand *cmd, + virJSONValue *props, + virQEMUCaps *qemuCaps) +{ + g_autofree char *arg = NULL; + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_JSON)) { + if (!(arg = virJSONValueToString(props, false))) + return -1; + } else { + const char *driver = virJSONValueObjectGetString(props, "driver"); + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s,", driver); + + if (virQEMUBuildCommandLineJSON(props, &buf, "driver", NULL) < 0) + return -1; + + arg = virBufferContentAndReset(&buf); + } + + virCommandAddArgList(cmd, "-device", arg, NULL); + return 0; +} + + /** * qemuBuildMasterKeyCommandLine: * @cmd: the command to modify -- 2.47.2