qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL v2 15/32] qmp: Simplify code around monitor_qmp_dispatch_one()
Date: Tue,  3 Jul 2018 23:35:39 +0200	[thread overview]
Message-ID: <20180703213556.20619-16-armbru@redhat.com> (raw)
In-Reply-To: <20180703213556.20619-1-armbru@redhat.com>

Change monitor_qmp_dispatch_one() to take its parameters unwrapped,
move monitor_resume() to the one caller that needs it, rename the
function to monitor_qmp_dispatch().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-16-armbru@redhat.com>
---
 monitor.c | 58 +++++++++++++++++++++++--------------------------------
 1 file changed, 24 insertions(+), 34 deletions(-)

diff --git a/monitor.c b/monitor.c
index 875647f992..37ca4e798d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4167,20 +4167,10 @@ static void monitor_qmp_respond(Monitor *mon, QObject *rsp,
     qobject_unref(rsp);
 }
 
-/*
- * Dispatch one single QMP request. The function will free the req_obj
- * and objects inside it before return.
- */
-static void monitor_qmp_dispatch_one(QMPRequest *req_obj)
+static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id)
 {
-    Monitor *mon, *old_mon;
-    QObject *req, *rsp = NULL, *id;
-    bool need_resume;
-
-    req = req_obj->req;
-    mon = req_obj->mon;
-    id = req_obj->id;
-    need_resume = req_obj->need_resume;
+    Monitor *old_mon;
+    QObject *rsp;
 
     old_mon = cur_mon;
     cur_mon = mon;
@@ -4189,15 +4179,7 @@ static void monitor_qmp_dispatch_one(QMPRequest *req_obj)
 
     cur_mon = old_mon;
 
-    /* Respond if necessary */
     monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id));
-
-    /* This pairs with the monitor_suspend() in handle_qmp_command(). */
-    if (need_resume) {
-        monitor_resume(mon);
-    }
-
-    qmp_request_free(req_obj);
 }
 
 /*
@@ -4241,12 +4223,20 @@ static void monitor_qmp_bh_dispatcher(void *data)
 {
     QMPRequest *req_obj = monitor_qmp_requests_pop_any();
 
-    if (req_obj) {
-        trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: "");
-        monitor_qmp_dispatch_one(req_obj);
-        /* Reschedule instead of looping so the main loop stays responsive */
-        qemu_bh_schedule(mon_global.qmp_dispatcher_bh);
+    if (!req_obj) {
+        return;
     }
+
+    trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: "");
+    monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
+    if (req_obj->need_resume) {
+        /* Pairs with the monitor_suspend() in handle_qmp_command() */
+        monitor_resume(req_obj->mon);
+    }
+    qmp_request_free(req_obj);
+
+    /* Reschedule instead of looping so the main loop stays responsive */
+    qemu_bh_schedule(mon_global.qmp_dispatcher_bh);
 }
 
 #define  QMP_REQ_QUEUE_LEN_MAX  (8)
@@ -4292,20 +4282,20 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
         goto err;
     }
 
+    if (qmp_is_oob(qdict)) {
+        /* Out-of-band (OOB) requests are executed directly in parser. */
+        trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id)
+                                          ?: "");
+        monitor_qmp_dispatch(mon, req, id);
+        return;
+    }
+
     req_obj = g_new0(QMPRequest, 1);
     req_obj->mon = mon;
     req_obj->id = id;
     req_obj->req = req;
     req_obj->need_resume = false;
 
-    if (qmp_is_oob(qdict)) {
-        /* Out-of-band (OOB) requests are executed directly in parser. */
-        trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(req_obj->id)
-                                          ?: "");
-        monitor_qmp_dispatch_one(req_obj);
-        return;
-    }
-
     /* Protect qmp_requests and fetching its length. */
     qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
 
-- 
2.17.1

  parent reply	other threads:[~2018-07-03 21:36 UTC|newest]

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

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=20180703213556.20619-16-armbru@redhat.com \
    --to=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).