diff mbox

[13/24] monitor: add 'async' capability

Message ID 20161010092301.14974-14-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Oct. 10, 2016, 9:22 a.m. UTC
Declare that the server supports async.

Check if the client supports it: the following patch will suspend the
qmp monitor if an async command is ongoing.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 monitor.c        | 20 +++++++++++++++++---
 qapi-schema.json |  4 ++--
 2 files changed, 19 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index d7baa86..4a20d81 100644
--- a/monitor.c
+++ b/monitor.c
@@ -173,6 +173,7 @@  typedef struct {
      * mode.
      */
     bool in_command_mode;       /* are we in command mode? */
+    bool has_async;             /* the client has async capability */
     QmpClient client;
 } MonitorQMP;
 
@@ -570,9 +571,22 @@  static void monitor_qapi_event_init(void)
     qmp_event_set_func_emit(monitor_qapi_event_queue);
 }
 
-void qmp_qmp_capabilities(Error **errp)
+void qmp_qmp_capabilities(bool has_capabilities,
+                          QMPCapabilityList *capabilities, Error **errp)
 {
+    bool has_async = false;
+
+    if (has_capabilities) {
+        while (capabilities) {
+            if (capabilities->value == QMP_CAPABILITY_ASYNC) {
+                has_async = true;
+            }
+            capabilities = capabilities->next;
+        }
+    }
+
     cur_mon->qmp.in_command_mode = true;
+    cur_mon->qmp.has_async = has_async;
 }
 
 static void handle_hmp_command(Monitor *mon, const char *cmdline);
@@ -3852,8 +3866,8 @@  static QObject *get_qmp_greeting(void)
 
     qmp_marshal_query_version(NULL, &ver, NULL);
 
-    return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}}",
-                              ver);
+    return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': ["
+                              "'async']}}", ver);
 }
 
 static void monitor_qmp_event(void *opaque, int event)
diff --git a/qapi-schema.json b/qapi-schema.json
index 93b2929..95d3c72 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -37,7 +37,7 @@ 
 #
 # Enable QMP capabilities.
 #
-# Arguments: None.
+# @capabilities: #optional an array of QMPCapability (since 2.8)
 #
 # Example:
 #
@@ -51,7 +51,7 @@ 
 # Since: 0.13
 #
 ##
-{ 'command': 'qmp_capabilities' }
+{ 'command': 'qmp_capabilities', 'data': { '*capabilities': ['QMPCapability'] } }
 
 ##
 # @LostTickPolicy: