From: Luiz Capitulino <lcapitulino@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH 6/6] monitor: protect event emission
Date: Tue, 10 Jun 2014 09:33:54 -0400 [thread overview]
Message-ID: <20140610093354.3e544bec@redhat.com> (raw)
In-Reply-To: <1401813551-6667-7-git-send-email-pbonzini@redhat.com>
On Tue, 3 Jun 2014 18:39:11 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:
> 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.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> monitor.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index ebc66fb..f7a4ccf 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -210,6 +210,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;
> @@ -531,10 +534,11 @@ static const char *monitor_event_names[] = {
> };
> QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
>
> -MonitorEventState monitor_event_state[QEVENT_MAX];
> +static MonitorEventState monitor_event_state[QEVENT_MAX];
>
> /*
> - * Emits the event to every monitor instance
> + * Emits the event to every monitor instance.
> + * Called with monitor_lock held.
> */
> static void
> monitor_protocol_event_emit(MonitorEvent event,
> @@ -571,6 +575,7 @@ monitor_protocol_event_queue(MonitorEvent event,
> now);
>
> /* Rate limit of 0 indicates no throttling */
> + qemu_mutex_lock(&monitor_lock);
> if (!evstate->rate) {
> monitor_protocol_event_emit(event, data);
> evstate->last = now;
> @@ -595,6 +600,7 @@ monitor_protocol_event_queue(MonitorEvent event,
> evstate->last = now;
> }
> }
> + qemu_mutex_unlock(&monitor_lock);
> }
>
>
> @@ -612,12 +618,14 @@ static void monitor_protocol_event_handler(void *opaque)
> evstate->data,
> evstate->last,
> now);
> + qemu_mutex_lock(&monitor_lock);
> if (evstate->data) {
> monitor_protocol_event_emit(evstate->event, evstate->data);
> qobject_decref(evstate->data);
> evstate->data = NULL;
> }
> evstate->last = now;
> + qemu_mutex_unlock(&monitor_lock);
> }
>
>
> @@ -5040,6 +5048,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;
> @@ -5077,7 +5090,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;
> }
next prev parent reply other threads:[~2014-06-10 14:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-03 16:39 [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Paolo Bonzini
2014-06-03 16:39 ` [Qemu-devel] [PATCH 1/6] qemu-char: introduce qemu_chr_alloc Paolo Bonzini
2014-06-11 6:28 ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 2/6] qemu-char: do not call chr_write directly Paolo Bonzini
2014-06-11 6:30 ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 3/6] qemu-char: move pty_chr_update_read_handler around Paolo Bonzini
2014-06-11 6:32 ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe Paolo Bonzini
2014-06-11 6:59 ` Fam Zheng
2014-06-11 8:16 ` Paolo Bonzini
2014-06-03 16:39 ` [Qemu-devel] [PATCH 5/6] monitor: protect outbuf with mutex Paolo Bonzini
2014-06-10 14:10 ` Luiz Capitulino
2014-06-10 14:24 ` Paolo Bonzini
2014-06-10 14:28 ` Luiz Capitulino
2014-06-03 16:39 ` [Qemu-devel] [PATCH 6/6] monitor: protect event emission Paolo Bonzini
2014-06-10 13:33 ` Luiz Capitulino [this message]
2014-06-27 9:43 ` [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Stefan Hajnoczi
2014-06-27 12:33 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140610093354.3e544bec@redhat.com \
--to=lcapitulino@redhat.com \
--cc=famz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.