qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: peterx@redhat.com
Subject: [Qemu-devel] [RFC 1/3] monitor: allow monitor_qapi_event_emit specify mon
Date: Wed,  4 Jul 2018 17:10:36 +0800	[thread overview]
Message-ID: <20180704091038.29449-2-peterx@redhat.com> (raw)
In-Reply-To: <20180704091038.29449-1-peterx@redhat.com>

This is an internal change to allow monitor_qapi_event_emit() to pass in
specific monitor to send the event.  No functional change.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 monitor.c    | 37 ++++++++++++++++++++++++++-----------
 trace-events |  2 +-
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/monitor.c b/monitor.c
index 9eb9f06599..94ae7f1c79 100644
--- a/monitor.c
+++ b/monitor.c
@@ -637,20 +637,35 @@ static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
     [QAPI_EVENT_VSERPORT_CHANGE]   = { 1000 * SCALE_MS },
 };
 
+static bool monitor_allows_events(Monitor *mon)
+{
+    return monitor_is_qmp(mon) &&
+        mon->qmp.commands != &qmp_cap_negotiation_commands;
+}
+
+static void monitor_queue_event(Monitor *mon, QDict *qdict)
+{
+    if (monitor_allows_events(mon)) {
+        qmp_queue_response(mon, qdict);
+    }
+}
+
 /*
- * Broadcast an event to all monitors.
+ * Broadcast an event to the monitor specified by @mon, or all
+ * monitors if @mon is NULL.
  * @qdict is the event object.  Its member "event" must match @event.
  * Caller must hold monitor_lock.
  */
-static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict)
+static void monitor_qapi_event_emit(Monitor *mon, QAPIEvent event,
+                                    QDict *qdict)
 {
-    Monitor *mon;
+    trace_monitor_protocol_event_emit(mon, event, qdict);
 
-    trace_monitor_protocol_event_emit(event, qdict);
-    QTAILQ_FOREACH(mon, &mon_list, entry) {
-        if (monitor_is_qmp(mon)
-            && mon->qmp.commands != &qmp_cap_negotiation_commands) {
-            qmp_queue_response(mon, qdict);
+    if (mon) {
+        monitor_queue_event(mon, qdict);
+    } else {
+        QTAILQ_FOREACH(mon, &mon_list, entry) {
+            monitor_queue_event(mon, qdict);
         }
     }
 }
@@ -675,7 +690,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict)
 
     if (!evconf->rate) {
         /* Unthrottled event */
-        monitor_qapi_event_emit(event, qdict);
+        monitor_qapi_event_emit(NULL, event, qdict);
     } else {
         QDict *data = qobject_to(QDict, qdict_get(qdict, "data"));
         MonitorQAPIEventState key = { .event = event, .data = data };
@@ -700,7 +715,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict)
              */
             int64_t now = qemu_clock_get_ns(monitor_get_event_clock());
 
-            monitor_qapi_event_emit(event, qdict);
+            monitor_qapi_event_emit(NULL, event, qdict);
 
             evstate = g_new(MonitorQAPIEventState, 1);
             evstate->event = event;
@@ -733,7 +748,7 @@ static void monitor_qapi_event_handler(void *opaque)
     if (evstate->qdict) {
         int64_t now = qemu_clock_get_ns(monitor_get_event_clock());
 
-        monitor_qapi_event_emit(evstate->event, evstate->qdict);
+        monitor_qapi_event_emit(NULL, evstate->event, evstate->qdict);
         qobject_unref(evstate->qdict);
         evstate->qdict = NULL;
         timer_mod_ns(evstate->timer, now + evconf->rate);
diff --git a/trace-events b/trace-events
index c445f54773..d8074bb721 100644
--- a/trace-events
+++ b/trace-events
@@ -43,7 +43,7 @@ qemu_system_powerdown_request(void) ""
 
 # monitor.c
 monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
-monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
+monitor_protocol_event_emit(void *mon, uint32_t event, void *data) "mon=%p event=%d data=%p"
 monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
 handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
 handle_qmp_command(void *mon, const char *req) "mon %p req: %s"
-- 
2.17.1

  reply	other threads:[~2018-07-04  9:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  9:10 [Qemu-devel] [RFC 0/3] monitor: allow per-monitor events Peter Xu
2018-07-04  9:10 ` Peter Xu [this message]
2018-07-04  9:10 ` [Qemu-devel] [RFC 2/3] monitor: let QMPEventFuncEmit take a monitor arg Peter Xu
2018-07-04  9:10 ` [Qemu-devel] [RFC 3/3] qapi: provide send/bcast interface for events Peter Xu
2018-07-04  9:19 ` [Qemu-devel] [RFC 0/3] monitor: allow per-monitor events Peter Xu

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=20180704091038.29449-2-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).