]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add a qemuMonitorGetObjectTypes() method for QMP qom-list-types 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:00 +0000 (11:05 +0100)
Add a new qemuMonitorGetObjectTypes() method to support invocation
of the 'qom-list-types' 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 ee0672d09a1d6714f375b8962f99b240ad66987b..9c2923e86062fc4d2ba58c0b81f06ea6a85252e7 100644 (file)
@@ -3141,3 +3141,25 @@ int qemuMonitorGetEvents(qemuMonitorPtr mon,
 
     return qemuMonitorJSONGetEvents(mon, events);
 }
+
+
+int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
+                              char ***types)
+{
+    VIR_DEBUG("mon=%p types=%p",
+              mon, types);
+
+    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 qemuMonitorJSONGetObjectTypes(mon, types);
+}
index 73c80ada4d5cda05e38ea6d6261e7831a2475437..403a8b45ea78c108c1b7068d1a0c25e89747f173 100644 (file)
@@ -601,6 +601,9 @@ int qemuMonitorGetCommands(qemuMonitorPtr mon,
 int qemuMonitorGetEvents(qemuMonitorPtr mon,
                          char ***events);
 
+int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
+                              char ***types);
+
 
 /**
  * When running two dd process and using <> redirection, we need a
index e135cca3561fae313757e5b7031b722dc91fb3fb..b82a09f6729e1289cd554fa323fdfc97f1bd0ce1 100644 (file)
@@ -4218,3 +4218,77 @@ cleanup:
     virJSONValueFree(reply);
     return ret;
 }
+
+
+int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
+                                  char ***types)
+{
+    int ret;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data;
+    char **typelist = NULL;
+    int n = 0;
+    size_t i;
+
+    *types = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("qom-list-types", NULL)))
+        return -1;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    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",
+                       _("qom-list-types reply was missing return data"));
+        goto cleanup;
+    }
+
+    if ((n = virJSONValueArraySize(data)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("qom-list-types reply data was not an array"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(typelist, 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",
+                           _("qom-list-types reply data was missing 'name'"));
+            goto cleanup;
+        }
+
+        if (!(typelist[i] = strdup(tmp))) {
+            virReportOOMError();
+            goto cleanup;
+        }
+    }
+
+    ret = n;
+    *types = typelist;
+
+cleanup:
+    if (ret < 0 && typelist) {
+        for (i = 0 ; i < n ; i++)
+            VIR_FREE(typelist[i]);
+        VIR_FREE(typelist);
+    }
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
index 19c03a98d8bb90cde6e182a8409fa1998f0e4a4a..3f804157c6e386b04e7f071e5b9a126a5f2b1687 100644 (file)
@@ -305,4 +305,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
                              char ***events)
     ATTRIBUTE_NONNULL(2);
 
+int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
+                                  char ***types)
+    ATTRIBUTE_NONNULL(2);
+
 #endif /* QEMU_MONITOR_JSON_H */