[libvirt] [PATCH 5/8] qemu: Extract generic part from qemuMonitorJSONGetDeviceProps()

Andrea Bolognani abologna at redhat.com
Fri Mar 9 15:07:51 UTC 2018


Querying properties for devices and objects is identical except
for the specific QMP command that needs to be called.

Take the existing qemuMonitorJSONGetDeviceProps(), scrub all the
device-specific parts, thus turning it into the generic helper
qemuMonitorJSONGetProps(), which is then used to reimplement the
original function and will be used again once object properties
are needed.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/qemu/qemu_monitor_json.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index eb32811cd1..141873a705 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6058,9 +6058,11 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
 #undef MAKE_SET_CMD
 
 
-int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
-                                  const char *type,
-                                  char ***props)
+static int
+qemuMonitorJSONGetProps(qemuMonitorPtr mon,
+                        const char *type,
+                        char ***props,
+                        const char *impl)
 {
     int ret = -1;
     virJSONValuePtr cmd;
@@ -6072,7 +6074,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 
     *props = NULL;
 
-    if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
+    if (!(cmd = qemuMonitorJSONMakeCommand(impl,
                                            "s:typename", type,
                                            NULL)))
         return -1;
@@ -6090,8 +6092,9 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 
     if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
         (n = virJSONValueArraySize(data)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("device-list-properties reply data was not an array"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s reply data was not an array"),
+                       impl);
         goto cleanup;
     }
 
@@ -6104,8 +6107,9 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
         const char *tmp;
 
         if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("device-list-properties reply data was missing 'name'"));
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("%s reply data was missing 'name'"),
+                           impl);
             goto cleanup;
         }
 
@@ -6125,6 +6129,16 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
+                              const char *type,
+                              char ***props)
+{
+    return qemuMonitorJSONGetProps(mon, type, props,
+                                   "device-list-properties");
+}
+
+
 char *
 qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
 {
-- 
2.14.3




More information about the libvir-list mailing list