diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-12-11 18:11:41 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-12-19 10:38:43 +0100 |
commit | d403d92dfc243f0fb7dec432f971961c522ba077 (patch) | |
tree | bb653a3a6d3bf71ccc9137c814ab19bab61e985e /monitor/qmp.c | |
parent | 80d71121b719c610c7f6e05c932c35ded4cc92d4 (diff) |
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>
Diffstat (limited to 'monitor/qmp.c')
-rw-r--r-- | monitor/qmp.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/monitor/qmp.c b/monitor/qmp.c index 374bb4b81c..8f91af32be 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -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; |