]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Detect support for HMP passthrough
authorJiri Denemark <jdenemar@redhat.com>
Wed, 16 Mar 2011 19:34:01 +0000 (20:34 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 22 Mar 2011 14:03:57 +0000 (15:03 +0100)
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 00f63042ae5606b4deaba18ca0c0482a420baa47..5f6d532030dd80d2264dbf7bfebd6bd79e6c4fd3 100644 (file)
@@ -72,6 +72,7 @@ struct _qemuMonitor {
     int lastErrno;
 
     unsigned json: 1;
+    unsigned json_hmp: 1;
 };
 
 
@@ -924,14 +925,31 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
         return -1;
     }
 
-    if (mon->json)
+    if (mon->json) {
         ret = qemuMonitorJSONSetCapabilities(mon);
-    else
+        mon->json_hmp = qemuMonitorJSONCheckHMP(mon);
+    } else {
         ret = 0;
+    }
     return ret;
 }
 
 
+int
+qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd)
+{
+    if (!mon->json || mon->json_hmp)
+        return 1;
+
+    if (cmd) {
+        VIR_DEBUG("HMP passthrough not supported by qemu process;"
+                  " not trying HMP for command %s", cmd);
+    }
+
+    return 0;
+}
+
+
 int
 qemuMonitorStartCPUs(qemuMonitorPtr mon,
                      virConnectPtr conn)
index e933af113894fb5da529af400129309182c0f833..1566a6d268b34ac76ce441f81ae8ead5d9c442d2 100644 (file)
@@ -127,6 +127,8 @@ void qemuMonitorClose(qemuMonitorPtr mon);
 
 int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
 
+int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);
+
 void qemuMonitorLock(qemuMonitorPtr mon);
 void qemuMonitorUnlock(qemuMonitorPtr mon);
 
index 152afbac76a91a1b676c33ec9c0882d52f0117c4..43245a61c2332eb9bbe71406dce62a73e2743878 100644 (file)
@@ -746,6 +746,48 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
 }
 
 
+int
+qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
+{
+    int ret = 0;
+    virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data;
+    int i, n;
+
+    if (!cmd)
+        return ret;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 ||
+        qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    if (!(data = virJSONValueObjectGet(reply, "return")) ||
+        data->type != VIR_JSON_TYPE_ARRAY ||
+        (n = virJSONValueArraySize(data)) <= 0)
+        goto cleanup;
+
+    for (i = 0; i < n; i++) {
+        virJSONValuePtr entry;
+        const char *name;
+
+        if (!(entry = virJSONValueArrayGet(data, i)) ||
+            !(name = virJSONValueObjectGetString(entry, "name")))
+            goto cleanup;
+
+        if (STREQ(name, "human-monitor-command")) {
+            ret = 1;
+            goto cleanup;
+        }
+    }
+
+cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 int
 qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
                          virConnectPtr conn ATTRIBUTE_UNUSED)
index 9d039dd4b0fa80cdafebc69f285481ce91379a0b..086f0e15ab21af53d66d986f3f3920e47b9b5a34 100644 (file)
@@ -41,6 +41,8 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
 
+int qemuMonitorJSONCheckHMP(qemuMonitorPtr mon);
+
 int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
                              virConnectPtr conn);
 int qemuMonitorJSONStopCPUs(qemuMonitorPtr mon);