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

Andrea Bolognani posted 8 patches 7 years, 2 months ago
[libvirt] [PATCH 5/8] qemu: Extract generic part from qemuMonitorJSONGetDeviceProps()
Posted by Andrea Bolognani 7 years, 2 months ago
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@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 5/8] qemu: Extract generic part from qemuMonitorJSONGetDeviceProps()
Posted by John Ferlan 7 years, 1 month ago

On 03/09/2018 10:07 AM, Andrea Bolognani wrote:
> 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@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,

Is perhaps this name too generic?  How about JSONGetListProps where
currently it's "device-list-properties", but shortly there will be
"qom-list-properties".

With some sort of API name adjustment,

Reviewed-by: John Ferlan <jferlan@redhat.com>

John


> +                        const char *type,
> +                        char ***props,
> +                        const char *impl)
>  {
>      int ret = -1;
>      virJSONValuePtr cmd;

[...]

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