[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 40/40] monitor: protect event emission
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 40/40] monitor: protect event emission |
Date: |
Thu, 19 Jun 2014 15:39:52 -0400 |
From: Paolo Bonzini <address@hidden>
Event emission must be protected by a mutex because of access to
the shared rate-limiting state, and to guard against concurrent
monitor "hot-plug" by means of human-monitor-command.
Reviewed-by: Luiz Capitulino <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/monitor.c b/monitor.c
index 2b97e4e..38a64a3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -217,6 +217,9 @@ struct Monitor {
/* QMP checker flags */
#define QMP_ACCEPT_UNKNOWNS 1
+/* Protects mon_list, monitor_event_state. */
+static QemuMutex monitor_lock;
+
static QLIST_HEAD(mon_list, Monitor) mon_list;
static QLIST_HEAD(mon_fdsets, MonFdset) mon_fdsets;
static int mon_refcount;
@@ -465,6 +468,7 @@ static MonitorQAPIEventState
monitor_qapi_event_state[QAPI_EVENT_MAX];
/*
* Emits the event to every monitor instance, @event is only used for trace
+ * Called with monitor_lock held.
*/
static void monitor_qapi_event_emit(QAPIEvent event, QObject *data)
{
@@ -497,6 +501,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *data,
Error **errp)
now);
/* Rate limit of 0 indicates no throttling */
+ qemu_mutex_lock(&monitor_lock);
if (!evstate->rate) {
monitor_qapi_event_emit(event, QOBJECT(data));
evstate->last = now;
@@ -521,6 +526,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *data,
Error **errp)
evstate->last = now;
}
}
+ qemu_mutex_unlock(&monitor_lock);
}
/*
@@ -536,12 +542,14 @@ static void monitor_qapi_event_handler(void *opaque)
evstate->data,
evstate->last,
now);
+ qemu_mutex_lock(&monitor_lock);
if (evstate->data) {
monitor_qapi_event_emit(evstate->event, evstate->data);
qobject_decref(evstate->data);
evstate->data = NULL;
}
evstate->last = now;
+ qemu_mutex_unlock(&monitor_lock);
}
/*
@@ -5285,6 +5293,11 @@ static void monitor_readline_flush(void *opaque)
monitor_flush(opaque);
}
+static void __attribute__((constructor)) monitor_lock_init(void)
+{
+ qemu_mutex_init(&monitor_lock);
+}
+
void monitor_init(CharDriverState *chr, int flags)
{
static int is_first_init = 1;
@@ -5322,7 +5335,10 @@ void monitor_init(CharDriverState *chr, int flags)
monitor_event, mon);
}
+ qemu_mutex_lock(&monitor_lock);
QLIST_INSERT_HEAD(&mon_list, mon, entry);
+ qemu_mutex_unlock(&monitor_lock);
+
if (!default_mon || (flags & MONITOR_IS_DEFAULT))
default_mon = mon;
}
--
1.9.3
- [Qemu-devel] [PULL 34/40] qapi event: clean up, (continued)
- [Qemu-devel] [PULL 34/40] qapi event: clean up, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 28/40] qapi event: convert NIC_RX_FILTER_CHANGED, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 35/40] qemu-char: introduce qemu_chr_alloc, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 29/40] qapi event: convert VNC events, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 32/40] qapi event: convert GUEST_PANICKED, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 31/40] qapi event: convert BALLOON_CHANGE, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 37/40] qemu-char: move pty_chr_update_read_handler around, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 33/40] qapi event: convert QUORUM events, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 38/40] qemu-char: make writes thread-safe, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 36/40] qemu-char: do not call chr_write directly, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 40/40] monitor: protect event emission,
Luiz Capitulino <=
- [Qemu-devel] [PULL 39/40] monitor: protect outbuf and mux_out with mutex, Luiz Capitulino, 2014/06/19
- [Qemu-devel] [PULL 12/40] qapi: add new schema file qapi-event.json, Luiz Capitulino, 2014/06/19
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Peter Maydell, 2014/06/20
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Luiz Capitulino, 2014/06/20
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Paolo Bonzini, 2014/06/20
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Paolo Bonzini, 2014/06/20
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Eric Blake, 2014/06/20
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Wenchao Xia, 2014/06/24
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Eric Blake, 2014/06/24
- Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue, Peter Maydell, 2014/06/24