qmp: Simplify code around monitor_qmp_dispatch_one()
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>
diff --git a/monitor.c b/monitor.c
index 875647f..37ca4e7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4167,20 +4167,10 @@
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 @@
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 @@
{
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 @@
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);