]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: add qemuMonitorGetDumpGuestMemoryCapability
authorQiao Nuohan <qiaonuohan@cn.fujitsu.com>
Sun, 23 Mar 2014 03:51:13 +0000 (11:51 +0800)
committerEric Blake <eblake@redhat.com>
Mon, 24 Mar 2014 20:14:14 +0000 (14:14 -0600)
This patch adds qemuMonitorGetDumpGuestMemoryCapability, which is used to check
whether the specified dump-guest-memory format is supported by qemu.

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 357c9709fc9210e93378afb744e23966d81cbceb..976a95453e08b246320a0e6a9242aa1fd7bc5074 100644 (file)
@@ -2368,6 +2368,27 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
     return ret;
 }
 
+/**
+ * Returns 1 if @capability is supported, 0 if it's not, or -1 on error.
+ */
+int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
+                                            const char *capability)
+{
+    VIR_DEBUG("mon=%p capability=%s", mon, capability);
+
+    if (!mon) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("monitor must not be NULL"));
+        return -1;
+    }
+
+    /* No capability is supported without JSON monitor */
+    if (!mon->json)
+        return 0;
+
+    return qemuMonitorJSONGetDumpGuestMemoryCapability(mon, capability);
+}
+
 int
 qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
 {
index d8f1d10c32586cfbf39b1579fedc0635d3201cde..e8969111072eeba16901bc0ca402ff9a9dfb205b 100644 (file)
@@ -506,6 +506,9 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
 
 int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
 
+int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
+                                            const char *capability);
+
 int qemuMonitorDumpToFd(qemuMonitorPtr mon,
                         int fd);
 
index 7a6aac0afef41ffd22b077479b9ba19158f5a547..ab5890babfb07fd18b5542c5239143e8787eee19 100644 (file)
@@ -2657,6 +2657,71 @@ int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
     return ret;
 }
 
+int
+qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
+                                            const char *capability)
+{
+    int ret;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr caps;
+    virJSONValuePtr formats;
+    size_t i;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-dump-guest-memory-capability",
+                                           NULL)))
+        return -1;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0) {
+        if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
+            goto cleanup;
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+    }
+
+    if (ret < 0)
+        goto cleanup;
+
+    ret = -1;
+
+    caps = virJSONValueObjectGet(reply, "return");
+    if (!caps || caps->type != VIR_JSON_TYPE_OBJECT) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing dump guest memory capabilities"));
+        goto cleanup;
+    }
+
+    formats = virJSONValueObjectGet(caps, "formats");
+    if (!formats || formats->type != VIR_JSON_TYPE_ARRAY) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing supported dump formats"));
+        goto cleanup;
+    }
+
+    for (i = 0; i < virJSONValueArraySize(formats); i++) {
+        virJSONValuePtr dumpformat = virJSONValueArrayGet(formats, i);
+
+        if (!dumpformat || dumpformat->type != VIR_JSON_TYPE_STRING) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("missing entry in supported dump formats"));
+            goto cleanup;
+        }
+
+        if (STREQ(virJSONValueGetString(dumpformat), capability)) {
+            ret = 1;
+            goto cleanup;
+        }
+
+        ret = 0;
+    }
+
+cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
 int
 qemuMonitorJSONDump(qemuMonitorPtr mon,
                     const char *protocol)
index ef71588269b06853b2d4959ac49d438c1a927eac..631b9e4ec639d801c887e3af4ce4ece3cb2682ef 100644 (file)
@@ -147,6 +147,9 @@ int qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitorPtr mon,
 
 int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
 
+int qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
+                                                const char *capability);
+
 int qemuMonitorJSONDump(qemuMonitorPtr mon,
                         const char *protocol);
 
index d7da5a83903e6946991eb6eef227e1d7ac30ed83..d21e1ce9e92a58da5dbc03971d91516cf4680d02 100644 (file)
@@ -1959,6 +1959,48 @@ cleanup:
     return ret;
 }
 
+static int
+testQemuMonitorJSONqemuMonitorJSONGetDumpGuestMemoryCapability(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+    int ret = -1;
+    int cap;
+    const char *reply =
+        "{"
+        "    \"return\": {"
+        "        \"formats\": ["
+        "            \"elf\","
+        "            \"kdump-zlib\","
+        "            \"kdump-lzo\","
+        "            \"kdump-snappy\""
+        "        ]"
+        "    },"
+        "    \"id\": \"libvirt-9\""
+        "}";
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddItem(test, "query-dump-guest-memory-capability",
+                               reply) < 0)
+        goto cleanup;
+
+    cap = qemuMonitorJSONGetDumpGuestMemoryCapability(
+                                    qemuMonitorTestGetMonitor(test), "elf");
+
+    if (cap != 1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Unexpected capability: %d, expecting 1",
+                       cap);
+        goto cleanup;
+    }
+
+    ret = 0;
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
 
 struct testCPUData {
     const char *name;
@@ -2187,6 +2229,7 @@ mymain(void)
     DO_TEST(qemuMonitorJSONGetCPUInfo);
     DO_TEST(qemuMonitorJSONGetVirtType);
     DO_TEST(qemuMonitorJSONSendKey);
+    DO_TEST(qemuMonitorJSONGetDumpGuestMemoryCapability);
 
     DO_TEST_CPU_DATA("host");
     DO_TEST_CPU_DATA("full");