qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 15/24] monitor: suspend when running async and clien


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH 15/24] monitor: suspend when running async and client has no async
Date: Mon, 10 Oct 2016 13:22:52 +0400

When the client doesn't support 'async' capability, let's suspend the
monitor until the on-going async command completes. That way, the client
will be able to use -async commands, but will get only in order
reply. (it won't be able to do concurrent commands)

Signed-off-by: Marc-André Lureau <address@hidden>
---
 monitor.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/monitor.c b/monitor.c
index 61abb86..0b47f83 100644
--- a/monitor.c
+++ b/monitor.c
@@ -174,6 +174,7 @@ typedef struct {
      */
     bool in_command_mode;       /* are we in command mode? */
     bool has_async;             /* the client has async capability */
+    QObject *suspended;
     QmpClient client;
 } MonitorQMP;
 
@@ -3683,9 +3684,10 @@ static int monitor_can_read(void *opaque)
 {
     Monitor *mon = opaque;
 
-    return (mon->suspend_cnt == 0) ? 1 : 0;
+    return (mon->suspend_cnt == 0 && !mon->qmp.suspended) ? 1 : 0;
 }
 
+
 static bool invalid_qmp_mode(const Monitor *mon, const char *cmd,
                              Error **errp)
 {
@@ -3762,11 +3764,33 @@ static QDict *qmp_check_input_obj(QObject *input_obj, 
Error **errp)
     return input_dict;
 }
 
+static void monitor_qmp_suspend(Monitor *mon, QObject *req)
+{
+    assert(monitor_is_qmp(mon));
+    assert(!mon->qmp.suspended);
+
+    qobject_incref(req);
+    mon->qmp.suspended = req;
+}
+
+static void monitor_qmp_resume(Monitor *mon)
+{
+    assert(monitor_is_qmp(mon));
+    assert(mon->qmp.suspended);
+
+    qobject_decref(mon->qmp.suspended);
+    mon->qmp.suspended = NULL;
+}
+
 static void qmp_dispatch_return(QmpClient *client, QObject *rsp)
 {
     Monitor *mon = container_of(client, Monitor, qmp.client);
 
     monitor_json_emitter(mon, rsp);
+
+    if (mon->qmp.suspended) {
+        monitor_qmp_resume(mon);
+    }
 }
 
 static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
@@ -3805,6 +3829,12 @@ static void handle_qmp_command(JSONMessageParser 
*parser, GQueue *tokens)
     }
 
     qmp_dispatch(&mon->qmp.client, req, rqdict);
+
+    /* suspend if the command is on-going and client doesn't support async */
+    if (!QLIST_EMPTY(&mon->qmp.client.pending) && !mon->qmp.has_async) {
+        monitor_qmp_suspend(mon, req);
+    }
+
     qobject_decref(req);
     return;
 
-- 
2.10.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]