Blame SOURCES/libvirt-qemu-monitor-Add-monitor-API-for-device_add-supporting-JSON-objects.patch

6ae9ed
From 1d8021ecf7909b3d4cd1a3179c3bac8e9ec4d25b Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <1d8021ecf7909b3d4cd1a3179c3bac8e9ec4d25b@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:03 -0400
6ae9ed
Subject: [PATCH] qemu: monitor: Add monitor API for device_add supporting JSON
6ae9ed
 objects
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
Rather than formatting a string and splitting it back to a JSON object
6ae9ed
add API that will take a JSON object directly.
6ae9ed
6ae9ed
(cherry picked from commit 78806cd21b97aa56f37b0cffd6d4cfe306811107)
6ae9ed
---
6ae9ed
 src/qemu/qemu_monitor.c      | 18 ++++++++++++++++++
6ae9ed
 src/qemu/qemu_monitor.h      |  2 ++
6ae9ed
 src/qemu/qemu_monitor_json.c | 28 ++++++++++++++++++----------
6ae9ed
 src/qemu/qemu_monitor_json.h |  2 ++
6ae9ed
 4 files changed, 40 insertions(+), 10 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
6ae9ed
index e3a5e0b..2931f82 100644
6ae9ed
--- a/src/qemu/qemu_monitor.c
6ae9ed
+++ b/src/qemu/qemu_monitor.c
6ae9ed
@@ -2766,6 +2766,24 @@ qemuMonitorAddDevice(qemuMonitorPtr mon,
6ae9ed
 
6ae9ed
 
6ae9ed
 /**
6ae9ed
+ * qemuMonitorAddDeviceArgs:
6ae9ed
+ * @mon: monitor object
6ae9ed
+ * @args: arguments for device add, consumed on success or failure
6ae9ed
+ *
6ae9ed
+ * Adds a device described by @args. Requires JSON monitor.
6ae9ed
+ * Returns 0 on success -1 on error.
6ae9ed
+ */
6ae9ed
+int
6ae9ed
+qemuMonitorAddDeviceArgs(qemuMonitorPtr mon,
6ae9ed
+                         virJSONValuePtr args)
6ae9ed
+{
6ae9ed
+    QEMU_CHECK_MONITOR_JSON(mon);
6ae9ed
+
6ae9ed
+    return qemuMonitorJSONAddDeviceArgs(mon, args);
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+/**
6ae9ed
  * qemuMonitorAddObject:
6ae9ed
  * @mon: Pointer to monitor object
6ae9ed
  * @type: Type name of object to add
6ae9ed
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
6ae9ed
index 6e4e09d..b2f20e9 100644
6ae9ed
--- a/src/qemu/qemu_monitor.h
6ae9ed
+++ b/src/qemu/qemu_monitor.h
6ae9ed
@@ -683,6 +683,8 @@ int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
6ae9ed
                                        const char *bus,
6ae9ed
                                        virPCIDeviceAddress *guestAddr);
6ae9ed
 
6ae9ed
+int qemuMonitorAddDeviceArgs(qemuMonitorPtr mon,
6ae9ed
+                             virJSONValuePtr args);
6ae9ed
 int qemuMonitorAddDevice(qemuMonitorPtr mon,
6ae9ed
                          const char *devicestr);
6ae9ed
 
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
6ae9ed
index 74bbf75..fae589f 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.c
6ae9ed
+++ b/src/qemu/qemu_monitor_json.c
6ae9ed
@@ -3586,20 +3586,15 @@ int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
-int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
6ae9ed
-                             const char *devicestr)
6ae9ed
+int
6ae9ed
+qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon,
6ae9ed
+                             virJSONValuePtr args)
6ae9ed
 {
6ae9ed
     int ret = -1;
6ae9ed
-    virJSONValuePtr cmd;
6ae9ed
+    virJSONValuePtr cmd = NULL;
6ae9ed
     virJSONValuePtr reply = NULL;
6ae9ed
-    virJSONValuePtr args;
6ae9ed
 
6ae9ed
-    cmd = qemuMonitorJSONMakeCommand("device_add", NULL);
6ae9ed
-    if (!cmd)
6ae9ed
-        return -1;
6ae9ed
-
6ae9ed
-    args = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver");
6ae9ed
-    if (!args)
6ae9ed
+    if (!(cmd = qemuMonitorJSONMakeCommand("device_add", NULL)))
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
     if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
6ae9ed
@@ -3621,6 +3616,19 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
+int
6ae9ed
+qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
6ae9ed
+                         const char *devicestr)
6ae9ed
+{
6ae9ed
+    virJSONValuePtr args;
6ae9ed
+
6ae9ed
+    if (!(args = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver")))
6ae9ed
+        return -1;
6ae9ed
+
6ae9ed
+    return qemuMonitorJSONAddDeviceArgs(mon, args);
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
 int qemuMonitorJSONAddObject(qemuMonitorPtr mon,
6ae9ed
                              const char *type,
6ae9ed
                              const char *objalias,
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
6ae9ed
index 114b567..3fe5cf1 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.h
6ae9ed
+++ b/src/qemu/qemu_monitor_json.h
6ae9ed
@@ -215,6 +215,8 @@ int qemuMonitorJSONAttachPCIDiskController(qemuMonitorPtr mon,
6ae9ed
                                            const char *bus,
6ae9ed
                                            virPCIDeviceAddress *guestAddr);
6ae9ed
 
6ae9ed
+int qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon,
6ae9ed
+                                 virJSONValuePtr args);
6ae9ed
 int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
6ae9ed
                              const char *devicestr);
6ae9ed
 
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed