[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 15/32] qmp: Simplify code around monitor_qmp_disp
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 15/32] qmp: Simplify code around monitor_qmp_dispatch_one() |
Date: |
Tue, 3 Jul 2018 10:53:41 +0200 |
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
monitor.c | 58 +++++++++++++++++++++++--------------------------------
1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/monitor.c b/monitor.c
index 94f5660c3c..51ba1485ad 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4166,20 +4166,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;
@@ -4188,15 +4178,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);
}
/*
@@ -4240,12 +4222,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)
@@ -4291,20 +4281,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
- [Qemu-devel] [PATCH v2 00/32] ] qmp: Fixes and cleanups around OOB commands, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id", Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 10/32] tests/test-qga: Demonstrate the guest-agent ignores "control", Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 13/32] qmp: Revert change to handle_qmp_command tracepoint, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 16/32] tests/qmp-test: Demonstrate QMP errors jumping the queue, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 06/32] tests/qmp-test: Test in-band command doesn't overtake, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 03/32] docs/interop/qmp: Improve OOB documentation, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 28/32] qmp: Switch timestamp_put() to qdict_from_jsonf_nofail(), Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 15/32] qmp: Simplify code around monitor_qmp_dispatch_one(),
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 01/32] qmp: Say "out-of-band" instead of "Out-Of-Band", Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 02/32] monitor: Spell "I/O thread" consistently in comments, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 29/32] qobject: Let qobject_from_jsonf() fail instead of abort, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 26/32] qmp: Simplify monitor_qmp_respond(), Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 05/32] qmp: Get rid of x-oob-test command, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 18/32] qmp: Don't let JSON errors jump the queue, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 22/32] qmp: De-duplicate error response building, Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 09/32] qmp qemu-ga: Revert change that accidentally made qemu-ga accept "id", Markus Armbruster, 2018/07/03
- [Qemu-devel] [PATCH v2 25/32] qmp: Replace get_qmp_greeting() by qmp_greeting(), Markus Armbruster, 2018/07/03