[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/36] monitor: send event when command queue full
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 27/36] monitor: send event when command queue full |
Date: |
Mon, 12 Mar 2018 13:36:18 -0500 |
From: Peter Xu <address@hidden>
Set maximum QMP command queue length to 8. If the queue is full,
instead of queuing the command, we directly return a "command-dropped"
event, telling the client that a 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 drops
messages).
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
[eblake: commit message grammar, abort on failure to send event]
Signed-off-by: Eric Blake <address@hidden>
---
monitor.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/monitor.c b/monitor.c
index 07446d6b879..d28457d60d7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4007,6 +4007,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;
@@ -4040,6 +4042,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 the current monitor, we'll emulate the
* old behavior that we won't process the current monitor any more
@@ -4049,6 +4054,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,
+ &error_abort);
+ qobject_decref(id);
+ qobject_decref(req);
+ g_free(req_obj);
+ return;
+ }
}
/*
@@ -4056,7 +4073,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] [PULL 20/36] monitor: allow using IO thread for parsing, (continued)
- [Qemu-devel] [PULL 20/36] monitor: allow using IO thread for parsing, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 24/36] monitor: let suspend/resume work even with QMPs, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 29/36] qmp: support out-of-band (oob) execution, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 32/36] qmp: add command "x-oob-test", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 34/36] tests: qmp-test: add oob test, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 28/36] qapi: introduce new cmd option "allow-oob", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 21/36] qmp: introduce QMPCapability, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 30/36] qmp: isolate responses into io thread, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 15/36] qobject: let object_property_get_str() use new API, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 23/36] monitor: let suspend_cnt be thread safe, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 27/36] monitor: send event when command queue full,
Eric Blake <=
- [Qemu-devel] [PULL 25/36] monitor: separate QMP parser and dispatcher, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 31/36] monitor: enable IO thread for (qmp & !mux) typed, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 33/36] tests: qmp-test: verify command batching, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 35/36] block/accounting: introduce latency histogram, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 36/36] qapi: add block latency histogram interface, Eric Blake, 2018/03/12