aboutsummaryrefslogtreecommitdiff
path: root/include/monitor/monitor.h
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2018-10-09 14:27:13 +0800
committerMarkus Armbruster <armbru@redhat.com>2018-12-12 09:55:57 +0100
commit9ab84470ffc2781df3acd4607bc6d2ae64d6d7e3 (patch)
tree0096dc70b9747e76ee7d144f057fcabe626ab235 /include/monitor/monitor.h
parent34f1f3e06d8824740d3bc41556f8300f0fb463cf (diff)
monitor: Suspend monitor instead dropping commands
When a QMP client sends in-band commands more quickly that we can process them, we can either queue them without limit (QUEUE), drop commands when the queue is full (DROP), or suspend receiving commands when the queue is full (SUSPEND). None of them is ideal: * QUEUE lets a misbehaving client make QEMU eat memory without bounds. Not such a hot idea. * With DROP, the client has to cope with dropped in-band commands. To inform the client, we send a COMMAND_DROPPED event then. The event is flawed by design in two ways: it's ambiguous (see commit d621cfe0a17), and it brings back the "eat memory without bounds" problem. * With SUSPEND, the client has to manage the flow of in-band commands to keep the monitor available for out-of-band commands. We currently DROP. Switch to SUSPEND. Managing the flow of in-band commands to keep the monitor available for out-of-band commands isn't really hard: just count the number of "outstanding" in-band commands (commands sent minus replies received), and if it exceeds the limit, hold back additional ones until it drops below the limit again. Note that we need to be careful pairing the suspend with a resume, or else the monitor will hang, possibly forever. And here since we need to make sure both: (1) popping request from the req queue, and (2) reading length of the req queue will be in the same critical section, we let the pop function take the corresponding queue lock when there is a request, then we release the lock from the caller. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20181009062718.1914-2-peterx@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'include/monitor/monitor.h')
-rw-r--r--include/monitor/monitor.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 6fd2c53b09..0c0a37d8cb 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -15,6 +15,8 @@ extern __thread Monitor *cur_mon;
#define MONITOR_USE_PRETTY 0x08
#define MONITOR_USE_OOB 0x10
+#define QMP_REQ_QUEUE_LEN_MAX 8
+
bool monitor_cur_is_qmp(void);
void monitor_init_globals(void);