[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full
From: |
Peter Xu |
Subject: |
[Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full |
Date: |
Tue, 19 Dec 2017 16:45:48 +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 | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/monitor.c b/monitor.c
index ed9a741d06..b571866659 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4038,6 +4038,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;
@@ -4071,6 +4073,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
@@ -4080,6 +4085,17 @@ 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) {
+ qapi_event_send_command_dropped(id,
+ COMMAND_DROP_REASON_QUEUE_FULL,
+ NULL);
+ qobject_decref(id);
+ qobject_decref(req);
+ g_free(req_obj);
+ return;
+ }
}
/*
@@ -4087,7 +4103,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] [RFC v6 13/27] monitor: introduce monitor_qmp_respond(), (continued)
- [Qemu-devel] [RFC v6 13/27] monitor: introduce monitor_qmp_respond(), Peter Xu, 2017/12/19
- [Qemu-devel] [RFC v6 14/27] monitor: let suspend_cnt be thread safe, Peter Xu, 2017/12/19
- [Qemu-devel] [RFC v6 15/27] monitor: let suspend/resume work even with QMPs, Peter Xu, 2017/12/19
- [Qemu-devel] [RFC v6 16/27] monitor: separate QMP parser and dispatcher, Peter Xu, 2017/12/19
- [Qemu-devel] [RFC v6 17/27] qmp: add new event "command-dropped", Peter Xu, 2017/12/19
- [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full,
Peter Xu <=
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Fam Zheng, 2017/12/21
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Peter Xu, 2017/12/25
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Fam Zheng, 2017/12/25
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Peter Xu, 2017/12/25
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Fam Zheng, 2017/12/25
- Re: [Qemu-devel] [RFC v6 18/27] monitor: send event when command queue full, Peter Xu, 2017/12/25
[Qemu-devel] [RFC v6 19/27] qapi: introduce new cmd option "allow-oob", Peter Xu, 2017/12/19
[Qemu-devel] [RFC v6 20/27] qmp: export qmp_dispatch_check_obj and allow "id", Peter Xu, 2017/12/19