]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add a qemuMonitorGetObjectProps() method for QMP device-list-properties command
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 22 Aug 2012 09:48:41 +0000 (10:48 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 27 Sep 2012 10:05:16 +0000 (11:05 +0100)
Add a new qemuMonitorGetObjectProps() method to support invocation
of the 'device-list-properties' JSON monitor command. No HMP equivalent
is required, since this will only be present for QEMU >= 1.2

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 9c2923e86062fc4d2ba58c0b81f06ea6a85252e7..d253a4cf65280140b0c5ed863f30eeb586039508 100644 (file)
@@ -3163,3 +3163,26 @@ int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
 
     return qemuMonitorJSONGetObjectTypes(mon, types);
 }
+
+
+int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
+                              const char *type,
+                              char ***props)
+{
+    VIR_DEBUG("mon=%p type=%s props=%p",
+              mon, type, props);
+
+    if (!mon) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("monitor must not be NULL"));
+        return -1;
+    }
+
+    if (!mon->json) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("JSON monitor is required"));
+        return -1;
+    }
+
+    return qemuMonitorJSONGetObjectProps(mon, type, props);
+}
index 403a8b45ea78c108c1b7068d1a0c25e89747f173..e65a21843e84cb1a930c3d0de2a628b885a37197 100644 (file)
@@ -603,6 +603,9 @@ int qemuMonitorGetEvents(qemuMonitorPtr mon,
 
 int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
                               char ***types);
+int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
+                              const char *type,
+                              char ***props);
 
 
 /**
index b82a09f6729e1289cd554fa323fdfc97f1bd0ce1..b5f6b1aee75c37f0bb7662debc3c5e4a9d42301c 100644 (file)
@@ -4292,3 +4292,85 @@ cleanup:
     virJSONValueFree(reply);
     return ret;
 }
+
+
+int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
+                                  const char *type,
+                                  char ***props)
+{
+    int ret;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data;
+    char **proplist = NULL;
+    int n = 0;
+    size_t i;
+
+    *props = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
+                                           "s:typename", type,
+                                           NULL)))
+        return -1;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0 &&
+        qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
+        goto cleanup;
+    }
+
+    if (ret == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+    if (ret < 0)
+        goto cleanup;
+
+    ret = -1;
+
+    if (!(data = virJSONValueObjectGet(reply, "return"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("device-list-properties reply was missing return data"));
+        goto cleanup;
+    }
+
+    if ((n = virJSONValueArraySize(data)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("device-list-properties reply data was not an array"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(proplist, n) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    for (i = 0 ; i < n ; i++) {
+        virJSONValuePtr child = virJSONValueArrayGet(data, i);
+        const char *tmp;
+
+        if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("device-list-properties reply data was missing 'name'"));
+            goto cleanup;
+        }
+
+        if (!(proplist[i] = strdup(tmp))) {
+            virReportOOMError();
+            goto cleanup;
+        }
+    }
+
+    ret = n;
+    *props = proplist;
+
+cleanup:
+    if (ret < 0 && proplist) {
+        for (i = 0 ; i < n ; i++)
+            VIR_FREE(proplist[i]);
+        VIR_FREE(proplist);
+    }
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
index 3f804157c6e386b04e7f071e5b9a126a5f2b1687..dde02fe0e2cebd8299678b9f651a3a904d6d483c 100644 (file)
@@ -308,5 +308,9 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
 int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
                                   char ***types)
     ATTRIBUTE_NONNULL(2);
+int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
+                                  const char *type,
+                                  char ***props)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
 #endif /* QEMU_MONITOR_JSON_H */