qmp: Fix tracing of non-string command IDs

Tracepoints monitor_qmp_cmd_in_band and
monitor_qmp_cmd_out_of_band (commit cf869d5317 "qmp: support
out-of-band (oob) execution") treat non-string "id" like absent "id".
Fix that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201211171152.146877-10-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-12-11 18:11:41 +01:00
parent 80d71121b7
commit d403d92dfc

View File

@ -31,7 +31,6 @@
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qstring.h"
#include "trace.h"
struct QMPRequest {
@ -276,9 +275,15 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1;
qemu_mutex_unlock(&mon->qmp_queue_lock);
if (req_obj->req) {
QDict *qdict = qobject_to(QDict, req_obj->req);
QObject *id = qdict ? qdict_get(qdict, "id") : NULL;
trace_monitor_qmp_cmd_in_band(qobject_get_try_str(id) ?: "");
if (trace_event_get_state(TRACE_MONITOR_QMP_CMD_IN_BAND)) {
QDict *qdict = qobject_to(QDict, req_obj->req);
QObject *id = qdict ? qdict_get(qdict, "id") : NULL;
GString *id_json;
id_json = id ? qobject_to_json(id) : g_string_new(NULL);
trace_monitor_qmp_cmd_in_band(id_json->str);
g_string_free(id_json, true);
}
monitor_qmp_dispatch(mon, req_obj->req);
} else {
assert(req_obj->err);
@ -308,17 +313,11 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
static void handle_qmp_command(void *opaque, QObject *req, Error *err)
{
MonitorQMP *mon = opaque;
QObject *id = NULL;
QDict *qdict;
QDict *qdict = qobject_to(QDict, req);
QMPRequest *req_obj;
assert(!req != !err);
qdict = qobject_to(QDict, req);
if (qdict) {
id = qdict_get(qdict, "id");
} /* else will fail qmp_dispatch() */
if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) {
GString *req_json = qobject_to_json(req);
trace_handle_qmp_command(mon, req_json->str);
@ -327,7 +326,14 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
if (qdict && qmp_is_oob(qdict)) {
/* OOB commands are executed immediately */
trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) ?: "");
if (trace_event_get_state(TRACE_MONITOR_QMP_CMD_OUT_OF_BAND)) {
QObject *id = qdict_get(qdict, "id");
GString *id_json;
id_json = id ? qobject_to_json(id) : g_string_new(NULL);
trace_monitor_qmp_cmd_out_of_band(id_json->str);
g_string_free(id_json, true);
}
monitor_qmp_dispatch(mon, req);
qobject_unref(req);
return;