aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-07-03 10:53:41 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-07-03 23:18:56 +0200
commitb27314567d4cd8e204a18feba60d3341fb2d1aed (patch)
tree5efccc73b95fdd1497116990ae1a7045eb0265e5
parent05f7274c8bd4a958f6673d28bf9bca0a9cf09c76 (diff)
downloadqemu-b27314567d4cd8e204a18feba60d3341fb2d1aed.zip
qemu-b27314567d4cd8e204a18feba60d3341fb2d1aed.tar.gz
qemu-b27314567d4cd8e204a18feba60d3341fb2d1aed.tar.bz2
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>
-rw-r--r--monitor.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/monitor.c b/monitor.c
index 875647f..37ca4e7 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;
}
- 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)
+ trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id)
?: "");
- monitor_qmp_dispatch_one(req_obj);
+ 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;
+
/* Protect qmp_requests and fetching its length. */
qemu_mutex_lock(&mon->qmp.qmp_queue_lock);