[PATCH 054/103] qemu: command: Introduce helper for building JSON props of -device into commandline

Peter Krempa pkrempa at redhat.com
Thu Oct 7 15:17:42 UTC 2021


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 <pkrempa at redhat.com>
---
 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 d27e8b2648..9c8a3a85af 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.31.1




More information about the libvir-list mailing list