]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: Introduce helper for building JSON props of -device into commandline
authorPeter Krempa <pkrempa@redhat.com>
Sat, 25 Sep 2021 07:08:05 +0000 (09:08 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:26:03 +0000 (10:26 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c

index f1c67d1e61dc2785d74aec79707f14f3974c69ac..3bacb950906973856bdd7b3d099c71ff89ab3884 100644 (file)
@@ -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