[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 16/23] monitor: send event when command queue ful
From: |
Peter Xu |
Subject: |
[Qemu-devel] [PATCH v7 16/23] monitor: send event when command queue full |
Date: |
Wed, 24 Jan 2018 13:39:50 +0800 |
Set maximum QMP command queue length to 8. If queue full, instead of
queue the command, we directly return a "command-dropped" event, telling
client that specific command is dropped.
Note that this flow control mechanism is only valid if OOB is enabled.
If it's not, the effective queue length will always be 1, which strictly
follows original behavior of QMP command handling (which never drop
messages).
Signed-off-by: Peter Xu <address@hidden>
---
monitor.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/monitor.c b/monitor.c
index 51d12412fa..bf0f3d1662 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4055,6 +4055,8 @@ static void monitor_qmp_bh_dispatcher(void *data)
}
}
+#define QMP_REQ_QUEUE_LEN_MAX (8)
+
static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
{
QObject *req, *id = NULL;
@@ -4088,6 +4090,9 @@ static void handle_qmp_command(JSONMessageParser *parser,
GQueue *tokens)
req_obj->req = req;
req_obj->need_resume = false;
+ /* Protect qmp_requests and fetching its length. */
+ qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
+
/*
* If OOB is not enabled on current monitor, we'll emulate the old
* behavior that we won't process current monitor any more until
@@ -4097,6 +4102,18 @@ static void handle_qmp_command(JSONMessageParser
*parser, GQueue *tokens)
if (!qmp_oob_enabled(mon)) {
monitor_suspend(mon);
req_obj->need_resume = true;
+ } else {
+ /* Drop the request if queue is full. */
+ if (mon->qmp.qmp_requests->length >= QMP_REQ_QUEUE_LEN_MAX) {
+ qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
+ qapi_event_send_command_dropped(id,
+ COMMAND_DROP_REASON_QUEUE_FULL,
+ NULL);
+ qobject_decref(id);
+ qobject_decref(req);
+ g_free(req_obj);
+ return;
+ }
}
/*
@@ -4104,7 +4121,6 @@ static void handle_qmp_command(JSONMessageParser *parser,
GQueue *tokens)
* handled in time order. Ownership for req_obj, req, id,
* etc. will be delivered to the handler side.
*/
- qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
g_queue_push_tail(mon->qmp.qmp_requests, req_obj);
qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
--
2.14.3
- [Qemu-devel] [PATCH v7 06/23] monitor: move the cur_mon hack deeper for QMP, (continued)
- [Qemu-devel] [PATCH v7 06/23] monitor: move the cur_mon hack deeper for QMP, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 07/23] monitor: unify global init, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 08/23] monitor: let mon_list be tail queue, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 09/23] monitor: allow using IO thread for parsing, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 10/23] qmp: introduce QMPCapability, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 11/23] monitor: introduce monitor_qmp_respond(), Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 12/23] monitor: let suspend_cnt be thread safe, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 13/23] monitor: let suspend/resume work even with QMPs, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 14/23] monitor: separate QMP parser and dispatcher, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 15/23] qmp: add new event "command-dropped", Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 16/23] monitor: send event when command queue full,
Peter Xu <=
- [Qemu-devel] [PATCH v7 17/23] qapi: introduce new cmd option "allow-oob", Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 18/23] qmp: support out-of-band (oob) execution, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 19/23] qmp: isolate responses into io thread, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 20/23] monitor: enable IO thread for (qmp & !mux) typed, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 21/23] qmp: add command "x-oob-test", Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 22/23] tests: qmp-test: verify command batching, Peter Xu, 2018/01/24
- [Qemu-devel] [PATCH v7 23/23] tests: qmp-test: add oob test, Peter Xu, 2018/01/24
- Re: [Qemu-devel] [PATCH v7 00/23] QMP: out-of-band (OOB) execution support, Peter Xu, 2018/01/24