Received: from eggs.gnu.org ([2001:4830:134:3::10]:56570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWoY-0002ei-6H for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWoS-0003Wd-Tu for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWoS-0003WJ-ON for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:00 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 523A731B320 for ; Mon, 10 Oct 2016 09:24:00 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 10 Oct 2016 13:22:52 +0400 Message-Id: <20161010092301.14974-16-marcandre.lureau@redhat.com> In-Reply-To: <20161010092301.14974-1-marcandre.lureau@redhat.com> References: <20161010092301.14974-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 15/24] monitor: suspend when running async and client has no async List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: eblake@redhat.com, berrange@redhat.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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=C3=A9 Lureau --- 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; =20 @@ -3683,9 +3684,10 @@ static int monitor_can_read(void *opaque) { Monitor *mon =3D opaque; =20 - return (mon->suspend_cnt =3D=3D 0) ? 1 : 0; + return (mon->suspend_cnt =3D=3D 0 && !mon->qmp.suspended) ? 1 : 0; } =20 + 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; } =20 +static void monitor_qmp_suspend(Monitor *mon, QObject *req) +{ + assert(monitor_is_qmp(mon)); + assert(!mon->qmp.suspended); + + qobject_incref(req); + mon->qmp.suspended =3D 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 =3D NULL; +} + static void qmp_dispatch_return(QmpClient *client, QObject *rsp) { Monitor *mon =3D container_of(client, Monitor, qmp.client); =20 monitor_json_emitter(mon, rsp); + + if (mon->qmp.suspended) { + monitor_qmp_resume(mon); + } } =20 static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens= ) @@ -3805,6 +3829,12 @@ static void handle_qmp_command(JSONMessageParser *= parser, GQueue *tokens) } =20 qmp_dispatch(&mon->qmp.client, req, rqdict); + + /* suspend if the command is on-going and client doesn't support asy= nc */ + if (!QLIST_EMPTY(&mon->qmp.client.pending) && !mon->qmp.has_async) { + monitor_qmp_suspend(mon, req); + } + qobject_decref(req); return; =20 --=20 2.10.0