[PATCH v2 1/3] qemu: Detect support for HMP passthrough

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
Notes:
    Version 2:
    - optionally log that HMP passthrough cannot be used for a given command

 src/qemu/qemu_monitor.c      |   22 ++++++++++++++++++++--
 src/qemu/qemu_monitor.h      |    2 ++
 src/qemu/qemu_monitor_json.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |    2 ++
 4 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index dc08594..d7ca934 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -72,6 +72,7 @@ struct _qemuMonitor {
     int lastErrno;
 
     unsigned json: 1;
+    unsigned json_hmp: 1;
 };
 
 
@@ -924,15 +925,32 @@ 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)
 {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 7bea083..55d7590 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -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);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 152afba..43245a6 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -747,6 +747,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)
 {
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 9d039dd..086f0e1 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -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);
-- 
1.7.4.1

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]