]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Setup infrastructure for HMP passthrough
authorJiri Denemark <jdenemar@redhat.com>
Wed, 9 Mar 2011 20:24:04 +0000 (21:24 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 10 Mar 2011 13:36:04 +0000 (14:36 +0100)
JSON monitor command implementation can now just directly call text
monitor implementation and it will be automatically encapsulated into
QMP's human-monitor-command.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
src/qemu/qemu_monitor_text.c
src/qemu/qemu_monitor_text.h

index dfb1aadc9d8e16706ddd3b05f3cb7fa4d311cae4..2d5124e52a85dfddc8d2864d8577831aa770b029 100644 (file)
@@ -742,6 +742,18 @@ cleanup:
 }
 
 
+int qemuMonitorCommandWithFd(qemuMonitorPtr mon,
+                             const char *cmd,
+                             int scm_fd,
+                             char **reply)
+{
+    if (mon->json)
+        return qemuMonitorJSONHumanCommandWithFd(mon, cmd, scm_fd, reply);
+    else
+        return qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply);
+}
+
+
 int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
                              virConnectPtr conn,
                              const char *path,
index 0ea1330de034447783ac4ec58f2af0946a41a946..7200db800391cf469717e594d97be7dfff8f378f 100644 (file)
@@ -133,9 +133,15 @@ void qemuMonitorUnlock(qemuMonitorPtr mon);
 int qemuMonitorRef(qemuMonitorPtr mon);
 int qemuMonitorUnref(qemuMonitorPtr mon);
 
-/* This API is for use by the internal Text/JSON monitor impl code only */
+/* These APIs are for use by the internal Text/JSON monitor impl code only */
 int qemuMonitorSend(qemuMonitorPtr mon,
                     qemuMonitorMessagePtr msg);
+int qemuMonitorCommandWithFd(qemuMonitorPtr mon,
+                             const char *cmd,
+                             int scm_fd,
+                             char **reply);
+# define qemuMonitorCommand(mon, cmd, reply) \
+    qemuMonitorCommandWithFd(mon, cmd, -1, reply)
 
 /* XXX same comment about virConnectPtr as above */
 int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
index e6903a1c874d721614622022e6c3743b3907db3b..918591eb98195811ccec2051ad9fd0b88e397647 100644 (file)
@@ -675,6 +675,56 @@ static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValueP
 }
 
 
+int
+qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
+                                  const char *cmd_str,
+                                  int scm_fd,
+                                  char **reply_str)
+{
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr obj;
+    int ret = -1;
+
+    cmd = qemuMonitorJSONMakeCommand("human-monitor-command",
+                                     "s:command-line", cmd_str,
+                                     NULL);
+
+    if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, scm_fd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply))
+        goto cleanup;
+
+    if (!(obj = virJSONValueObjectGet(reply, "return"))) {
+        qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("human monitor command was missing return data"));
+        goto cleanup;
+    }
+
+    if (reply_str) {
+        const char *data;
+
+        if ((data = virJSONValueGetString(obj)))
+            *reply_str = strdup(data);
+        else
+            *reply_str = strdup("");
+
+        if (!*reply_str) {
+            virReportOOMError();
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 int
 qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
 {
@@ -2464,36 +2514,17 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
     virJSONValuePtr reply = NULL;
     int ret = -1;
 
-    if (!hmp) {
-        cmd = virJSONValueFromString(cmd_str);
+    if (hmp) {
+        return qemuMonitorJSONHumanCommandWithFd(mon, cmd_str, -1, reply_str);
     } else {
-        cmd = qemuMonitorJSONMakeCommand("human-monitor-command",
-                                         "s:command-line", cmd_str,
-                                         NULL);
-    }
-
-    if (!cmd)
-        return -1;
+        if (!(cmd = virJSONValueFromString(cmd_str)))
+            goto cleanup;
 
-    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
-        goto cleanup;
+        if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+            goto cleanup;
 
-    if (!hmp) {
         if (!(*reply_str = virJSONValueToString(reply)))
             goto cleanup;
-    } else if (qemuMonitorJSONCheckError(cmd, reply)) {
-        goto cleanup;
-    } else {
-        const char *data;
-        if (!(data = virJSONValueObjectGetString(reply, "return"))) {
-            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("human monitor command was missing return data"));
-            goto cleanup;
-        }
-        if (!(*reply_str = strdup(data))) {
-            virReportOOMError();
-            goto cleanup;
-        }
     }
 
     ret = 0;
index 4ae472a720551b0bff179e9397abba3a0ed78c82..3e0624d0910fba63714b744325722bffde737470 100644 (file)
@@ -34,6 +34,11 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
                              size_t len,
                              qemuMonitorMessagePtr msg);
 
+int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
+                                      const char *cmd,
+                                      int scm_fd,
+                                      char **reply);
+
 int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
 
 int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
index 0aed690ed6324b84ac6838f30e0d5133fd48a4d8..694938496bbbace7b96fd9dd712c72c48ab74fd2 100644 (file)
@@ -259,21 +259,15 @@ qemuMonitorCommandWithHandler(qemuMonitorPtr mon,
     return ret;
 }
 
-static int
-qemuMonitorCommandWithFd(qemuMonitorPtr mon,
-                          const char *cmd,
-                          int scm_fd,
-                          char **reply) {
+int
+qemuMonitorTextCommandWithFd(qemuMonitorPtr mon,
+                             const char *cmd,
+                             int scm_fd,
+                             char **reply)
+{
     return qemuMonitorCommandWithHandler(mon, cmd, NULL, NULL, scm_fd, reply);
 }
 
-static int
-qemuMonitorCommand(qemuMonitorPtr mon,
-                    const char *cmd,
-                    char **reply) {
-    return qemuMonitorCommandWithFd(mon, cmd, -1, reply);
-}
-
 
 static int
 qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon,
index b29dbcc846ef3f2b3d5d64e8c7d766c7d7732bb8..e6b27eca08559ea8dc08e1f568ef67fc65b257e5 100644 (file)
@@ -35,6 +35,11 @@ int qemuMonitorTextIOProcess(qemuMonitorPtr mon,
                              size_t len,
                              qemuMonitorMessagePtr msg);
 
+int qemuMonitorTextCommandWithFd(qemuMonitorPtr mon,
+                                 const char *cmd,
+                                 int scm_fd,
+                                 char **reply);
+
 int qemuMonitorTextStartCPUs(qemuMonitorPtr mon,
                              virConnectPtr conn);
 int qemuMonitorTextStopCPUs(qemuMonitorPtr mon);