qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, eblake@redhat.com, stefanha@redhat.com,
	dgilbert@redhat.com
Subject: [Qemu-devel] [PATCH 20/32] monitor: Peel off @mon_global wrapper
Date: Mon,  2 Jul 2018 18:22:06 +0200	[thread overview]
Message-ID: <20180702162218.13678-21-armbru@redhat.com> (raw)
In-Reply-To: <20180702162218.13678-1-armbru@redhat.com>

Wrapping global variables in a struct without a use for the wrapper
struct buys us nothing but longer lines.  Unwrap them.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 monitor.c | 60 +++++++++++++++++++++++++++----------------------------
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/monitor.c b/monitor.c
index 10b6634d3e..ef19562f65 100644
--- a/monitor.c
+++ b/monitor.c
@@ -210,7 +210,7 @@ struct Monitor {
 
     /*
      * State used only in the thread "owning" the monitor.
-     * If @use_io_thread, this is mon_global.mon_iothread.
+     * If @use_io_thread, this is @mon_iothread.
      * Else, it's the main thread.
      * These members can be safely accessed without locks.
      */
@@ -239,14 +239,13 @@ struct Monitor {
     int mux_out;
 };
 
-/* Let's add monitor global variables to this struct. */
-static struct {
-    IOThread *mon_iothread;
-    /* Bottom half to dispatch the requests received from I/O thread */
-    QEMUBH *qmp_dispatcher_bh;
-    /* Bottom half to deliver the responses back to clients */
-    QEMUBH *qmp_respond_bh;
-} mon_global;
+IOThread *mon_iothread;
+
+/* Bottom half to dispatch the requests received from I/O thread */
+QEMUBH *qmp_dispatcher_bh;
+
+/* Bottom half to deliver the responses back to clients */
+QEMUBH *qmp_respond_bh;
 
 struct QMPRequest {
     /* Owner of the request */
@@ -530,7 +529,7 @@ static void monitor_json_emitter(Monitor *mon, QObject *data)
         qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
         g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(data));
         qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
-        qemu_bh_schedule(mon_global.qmp_respond_bh);
+        qemu_bh_schedule(qmp_respond_bh);
     } else {
         /*
          * If not using monitor I/O thread, then we are in main thread.
@@ -4218,7 +4217,7 @@ static void monitor_qmp_bh_dispatcher(void *data)
     qmp_request_free(req_obj);
 
     /* Reschedule instead of looping so the main loop stays responsive */
-    qemu_bh_schedule(mon_global.qmp_dispatcher_bh);
+    qemu_bh_schedule(qmp_dispatcher_bh);
 }
 
 #define  QMP_REQ_QUEUE_LEN_MAX  (8)
@@ -4304,7 +4303,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
     qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
 
     /* Kick the dispatcher routine */
-    qemu_bh_schedule(mon_global.qmp_dispatcher_bh);
+    qemu_bh_schedule(qmp_dispatcher_bh);
 }
 
 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
@@ -4357,7 +4356,7 @@ int monitor_suspend(Monitor *mon)
          * Kick I/O thread to make sure this takes effect.  It'll be
          * evaluated again in prepare() of the watch object.
          */
-        aio_notify(iothread_get_aio_context(mon_global.mon_iothread));
+        aio_notify(iothread_get_aio_context(mon_iothread));
     }
 
     trace_monitor_suspend(mon, 1);
@@ -4377,7 +4376,7 @@ void monitor_resume(Monitor *mon)
              * kick the thread in case it's sleeping.
              */
             if (mon->use_io_thread) {
-                aio_notify(iothread_get_aio_context(mon_global.mon_iothread));
+                aio_notify(iothread_get_aio_context(mon_iothread));
             }
         } else {
             assert(mon->rs);
@@ -4515,36 +4514,35 @@ static void sortcmdlist(void)
 
 static GMainContext *monitor_get_io_context(void)
 {
-    return iothread_get_g_main_context(mon_global.mon_iothread);
+    return iothread_get_g_main_context(mon_iothread);
 }
 
 static AioContext *monitor_get_aio_context(void)
 {
-    return iothread_get_aio_context(mon_global.mon_iothread);
+    return iothread_get_aio_context(mon_iothread);
 }
 
 static void monitor_iothread_init(void)
 {
-    mon_global.mon_iothread = iothread_create("mon_iothread",
-                                              &error_abort);
+    mon_iothread = iothread_create("mon_iothread", &error_abort);
 
     /*
      * This MUST be on main loop thread since we have commands that
      * have assumption to be run on main loop thread.  It would be
      * nice that one day we can remove this assumption in the future.
      */
-    mon_global.qmp_dispatcher_bh = aio_bh_new(iohandler_get_aio_context(),
-                                              monitor_qmp_bh_dispatcher,
-                                              NULL);
+    qmp_dispatcher_bh = aio_bh_new(iohandler_get_aio_context(),
+                                   monitor_qmp_bh_dispatcher,
+                                   NULL);
 
     /*
      * Unlike the dispatcher BH, this must be run on the monitor I/O
      * thread, so that monitors that are using I/O thread will make
      * sure read/write operations are all done on the I/O thread.
      */
-    mon_global.qmp_respond_bh = aio_bh_new(monitor_get_aio_context(),
-                                           monitor_qmp_bh_responder,
-                                           NULL);
+    qmp_respond_bh = aio_bh_new(monitor_get_aio_context(),
+                                monitor_qmp_bh_responder,
+                                NULL);
 }
 
 void monitor_init_globals(void)
@@ -4701,7 +4699,7 @@ void monitor_cleanup(void)
      * we need to unregister from chardev below in
      * monitor_data_destroy(), and chardev is not thread-safe yet
      */
-    iothread_stop(mon_global.mon_iothread);
+    iothread_stop(mon_iothread);
 
     /*
      * After we have I/O thread to send responses, it's possible that
@@ -4722,13 +4720,13 @@ void monitor_cleanup(void)
     qemu_mutex_unlock(&monitor_lock);
 
     /* QEMUBHs needs to be deleted before destroying the I/O thread */
-    qemu_bh_delete(mon_global.qmp_dispatcher_bh);
-    mon_global.qmp_dispatcher_bh = NULL;
-    qemu_bh_delete(mon_global.qmp_respond_bh);
-    mon_global.qmp_respond_bh = NULL;
+    qemu_bh_delete(qmp_dispatcher_bh);
+    qmp_dispatcher_bh = NULL;
+    qemu_bh_delete(qmp_respond_bh);
+    qmp_respond_bh = NULL;
 
-    iothread_destroy(mon_global.mon_iothread);
-    mon_global.mon_iothread = NULL;
+    iothread_destroy(mon_iothread);
+    mon_iothread = NULL;
 }
 
 QemuOptsList qemu_mon_opts = {
-- 
2.17.1

  parent reply	other threads:[~2018-07-02 16:22 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 16:21 [Qemu-devel] [PATCH 00/32] qmp: Fixes and cleanups around OOB commands Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 01/32] qmp: Say "out-of-band" instead of "Out-Of-Band" Markus Armbruster
2018-07-02 20:46   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 02/32] monitor: Spell "I/O thread" consistently in comments Markus Armbruster
2018-07-02 20:48   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 03/32] docs/interop/qmp: Improve OOB documentation Markus Armbruster
2018-07-02 20:54   ` Eric Blake
2018-07-03  6:01     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 04/32] qmp: Document COMMAND_DROPPED design flaw Markus Armbruster
2018-07-02 20:58   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 05/32] qmp: Get rid of x-oob-test command Markus Armbruster
2018-07-02 21:08   ` Eric Blake
2018-07-03  6:05     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 06/32] tests/qmp-test: Test in-band command doesn't overtake Markus Armbruster
2018-07-02 21:09   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 07/32] qmp: Make "id" optional again even in "oob" monitors Markus Armbruster
2018-07-02 21:13   ` Eric Blake
2018-07-03  6:06     ` Markus Armbruster
2018-07-03  3:36   ` Peter Xu
2018-07-03  6:14     ` Markus Armbruster
2018-07-03  6:24       ` Peter Xu
2018-07-03  9:08       ` Daniel P. Berrangé
2018-07-02 16:21 ` [Qemu-devel] [PATCH 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id" Markus Armbruster
2018-07-02 21:15   ` Eric Blake
2018-07-03  6:27     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 09/32] qmp qemu-ga: Revert change that accidentally made qemu-ga accept "id" Markus Armbruster
2018-07-02 21:44   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 10/32] tests/test-qga: Demonstrate the guest-agent ignores "control" Markus Armbruster
2018-07-03  1:47   ` Eric Blake
2018-07-03  6:29     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 11/32] qmp qemu-ga: Fix qemu-ga not to accept "control" Markus Armbruster
2018-07-03  1:49   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 12/32] qmp: Redo how the client requests out-of-band execution Markus Armbruster
2018-07-03  1:57   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 13/32] qmp: Revert change to handle_qmp_command tracepoint Markus Armbruster
2018-07-03  1:58   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 14/32] qmp: Always free QMPRequest with qmp_request_free() Markus Armbruster
2018-07-03  2:01   ` Eric Blake
2018-07-03  6:38     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 15/32] qmp: Simplify code around monitor_qmp_dispatch_one() Markus Armbruster
2018-07-03  2:04   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 16/32] tests/qmp-test: Demonstrate QMP errors jumping the queue Markus Armbruster
2018-07-03  2:07   ` Eric Blake
2018-07-03  6:20   ` Peter Xu
2018-07-03  6:54     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 17/32] qmp: Don't let malformed in-band commands jump " Markus Armbruster
2018-07-03  2:11   ` Eric Blake
2018-07-03  6:46     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 18/32] qmp: Don't let JSON errors " Markus Armbruster
2018-07-03  2:13   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 19/32] monitor: Rename use_io_thr to use_io_thread Markus Armbruster
2018-07-03  2:13   ` Eric Blake
2018-07-02 16:22 ` Markus Armbruster [this message]
2018-07-03  2:15   ` [Qemu-devel] [PATCH 20/32] monitor: Peel off @mon_global wrapper Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 21/32] qobject: New qdict_from_jsonf_nofail() Markus Armbruster
2018-07-03  2:16   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 22/32] qmp: De-duplicate error response building Markus Armbruster
2018-07-03  2:18   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 23/32] qmp: Use QDict * instead of QObject * for response objects Markus Armbruster
2018-07-03  2:21   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 24/32] qmp: Replace monitor_json_emitter{, raw}() by qmp_{queue, send}_response() Markus Armbruster
2018-07-03  2:25   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 25/32] qmp: Replace get_qmp_greeting() by qmp_greeting() Markus Armbruster
2018-07-03  2:26   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 26/32] qmp: Simplify monitor_qmp_respond() Markus Armbruster
2018-07-03  2:28   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 27/32] qmp: Add some comments around null responses Markus Armbruster
2018-07-03  2:28   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 28/32] qmp: Switch timestamp_put() to qdict_from_jsonf_nofail() Markus Armbruster
2018-07-03  2:29   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 29/32] qobject: Let qobject_from_jsonf() fail instead of abort Markus Armbruster
2018-07-03  2:30   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 30/32] qmp: Clean up capability negotiation after commit 02130314d8c Markus Armbruster
2018-07-03  2:33   ` Eric Blake
2018-07-03  6:50     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 31/32] monitor: Improve some comments Markus Armbruster
2018-07-03  2:36   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 32/32] qapi: Polish command flags documentation in qapi-code-gen.txt Markus Armbruster
2018-07-03  2:38   ` Eric Blake
2018-07-03  5:35 ` [Qemu-devel] [PATCH 00/32] qmp: Fixes and cleanups around OOB commands Markus Armbruster
2018-07-03  6:36 ` Peter Xu
2018-07-03  6:57   ` Markus Armbruster
2018-07-03  7:05 ` Marc-André Lureau
2018-07-03  8:36   ` Markus Armbruster
2018-07-03  9:08     ` Markus Armbruster

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=20180702162218.13678-21-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=peterx@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 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).