mirror of https://gitee.com/openkylin/qemu.git
qmp: Simplify monitor_qmp_respond()
monitor_qmp_respond() takes both a response object and an error object. If an error object is non-null, the response object must be null, and the response is built from the error object. Of the two callers, one always passes a null response object, and one a null error object. Move building the response object from the error object to the latter, and drop the error object parameter. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180703085358.13941-27-armbru@redhat.com>
This commit is contained in:
parent
1816604b62
commit
7cb2123f22
26
monitor.c
26
monitor.c
|
@ -4100,18 +4100,12 @@ static int monitor_can_read(void *opaque)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. This function takes ownership of rsp, err, and id.
|
* Emit QMP response @rsp with ID @id to @mon.
|
||||||
* 2. rsp, err, and id may be NULL.
|
* Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
|
||||||
* 3. If err != NULL then rsp must be NULL.
|
* Nothing is emitted then.
|
||||||
*/
|
*/
|
||||||
static void monitor_qmp_respond(Monitor *mon, QDict *rsp,
|
static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id)
|
||||||
Error *err, QObject *id)
|
|
||||||
{
|
{
|
||||||
if (err) {
|
|
||||||
assert(!rsp);
|
|
||||||
rsp = qmp_error_response(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsp) {
|
if (rsp) {
|
||||||
if (id) {
|
if (id) {
|
||||||
qdict_put_obj(rsp, "id", qobject_ref(id));
|
qdict_put_obj(rsp, "id", qobject_ref(id));
|
||||||
|
@ -4119,9 +4113,6 @@ static void monitor_qmp_respond(Monitor *mon, QDict *rsp,
|
||||||
|
|
||||||
qmp_queue_response(mon, rsp);
|
qmp_queue_response(mon, rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
qobject_unref(id);
|
|
||||||
qobject_unref(rsp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id)
|
static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id)
|
||||||
|
@ -4149,8 +4140,8 @@ static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Respond if necessary */
|
monitor_qmp_respond(mon, rsp, id);
|
||||||
monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id));
|
qobject_unref(rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -4193,6 +4184,7 @@ static QMPRequest *monitor_qmp_requests_pop_any(void)
|
||||||
static void monitor_qmp_bh_dispatcher(void *data)
|
static void monitor_qmp_bh_dispatcher(void *data)
|
||||||
{
|
{
|
||||||
QMPRequest *req_obj = monitor_qmp_requests_pop_any();
|
QMPRequest *req_obj = monitor_qmp_requests_pop_any();
|
||||||
|
QDict *rsp;
|
||||||
|
|
||||||
if (!req_obj) {
|
if (!req_obj) {
|
||||||
return;
|
return;
|
||||||
|
@ -4203,7 +4195,9 @@ static void monitor_qmp_bh_dispatcher(void *data)
|
||||||
monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
|
monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
|
||||||
} else {
|
} else {
|
||||||
assert(req_obj->err);
|
assert(req_obj->err);
|
||||||
monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL);
|
rsp = qmp_error_response(req_obj->err);
|
||||||
|
monitor_qmp_respond(req_obj->mon, rsp, NULL);
|
||||||
|
qobject_unref(rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req_obj->need_resume) {
|
if (req_obj->need_resume) {
|
||||||
|
|
Loading…
Reference in New Issue