[PATCH 01/10] qemu: monitor: Add monitor API for device_add supporting JSON objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than formating a string and splitting it back to a JSON object
add API that will take a JSON object directly.
---
 src/qemu/qemu_monitor.c      | 18 ++++++++++++++++++
 src/qemu/qemu_monitor.h      |  2 ++
 src/qemu/qemu_monitor_json.c | 29 +++++++++++++++++++----------
 src/qemu/qemu_monitor_json.h |  2 ++
 4 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 58c04d5..b58c412 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2771,6 +2771,24 @@ qemuMonitorAddDevice(qemuMonitorPtr mon,


 /**
+ * qemuMonitorAddDeviceArgs:
+ * @mon: monitor object
+ * @args: arguments for device add, consumed on success or failure
+ *
+ * Adds a device described by @args. Requires JSON monitor.
+ * Returns 0 on success -1 on error.
+ */
+int
+qemuMonitorAddDeviceArgs(qemuMonitorPtr mon,
+                         virJSONValuePtr args)
+{
+    QEMU_CHECK_MONITOR_JSON(mon);
+
+    return qemuMonitorJSONAddDeviceArgs(mon, args);
+}
+
+
+/**
  * qemuMonitorAddObject:
  * @mon: Pointer to monitor object
  * @type: Type name of object to add
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index ae0954d..805656b 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -685,6 +685,8 @@ int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
                                        const char *bus,
                                        virPCIDeviceAddress *guestAddr);

+int qemuMonitorAddDeviceArgs(qemuMonitorPtr mon,
+                                 virJSONValuePtr args);
 int qemuMonitorAddDevice(qemuMonitorPtr mon,
                          const char *devicestr);

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5283024..cf55a61 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3583,20 +3583,15 @@ int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
 }


-int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
-                             const char *devicestr)
+int
+qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon,
+                             virJSONValuePtr args)
 {
     int ret = -1;
-    virJSONValuePtr cmd;
+    virJSONValuePtr cmd = NULL;
     virJSONValuePtr reply = NULL;
-    virJSONValuePtr args;

-    cmd = qemuMonitorJSONMakeCommand("device_add", NULL);
-    if (!cmd)
-        return -1;
-
-    args = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver");
-    if (!args)
+    if (!(cmd = qemuMonitorJSONMakeCommand("device_add", NULL)))
         goto cleanup;

     if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
@@ -3618,6 +3613,20 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
 }


+int
+qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
+                         const char *devicestr)
+{
+    virJSONValuePtr args;
+
+    if (!(args = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver")))
+        return -1;
+
+    /* qemuMonitorJSONAddDeviceArgs always consumes @args */
+    return qemuMonitorJSONAddDeviceArgs(mon, args);
+}
+
+
 int qemuMonitorJSONAddObject(qemuMonitorPtr mon,
                              const char *type,
                              const char *objalias,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 0b3d898..7f3222a 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -215,6 +215,8 @@ int qemuMonitorJSONAttachPCIDiskController(qemuMonitorPtr mon,
                                            const char *bus,
                                            virPCIDeviceAddress *guestAddr);

+int qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon,
+                                 virJSONValuePtr args);
 int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
                              const char *devicestr);

-- 
2.9.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]