Skip to content

Commit ff04108

Browse files
kevmwMarkus Armbruster
authored and
Markus Armbruster
committed
hmp: Update current monitor only in handle_hmp_command()
The current monitor is updated relatively early in the command handling code even though only the command handler actually needs it. The current monitor will become coroutine-local later, so we can only update it when we know in which coroutine the command will be exectued. Move it to handle_hmp_command() where this information will be available. Signed-off-by: Kevin Wolf <[email protected]> Reviewed-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Markus Armbruster <[email protected]>
1 parent 947e474 commit ff04108

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

Diff for: monitor/hmp.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
10611061
QDict *qdict;
10621062
const HMPCommand *cmd;
10631063
const char *cmd_start = cmdline;
1064+
Monitor *old_mon;
10641065

10651066
trace_handle_hmp_command(mon, cmdline);
10661067

@@ -1079,7 +1080,11 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
10791080
return;
10801081
}
10811082

1083+
/* old_mon is non-NULL when called from qmp_human_monitor_command() */
1084+
old_mon = monitor_set_cur(&mon->common);
10821085
cmd->cmd(&mon->common, qdict);
1086+
monitor_set_cur(old_mon);
1087+
10831088
qobject_unref(qdict);
10841089
}
10851090

@@ -1301,11 +1306,8 @@ static void monitor_find_completion(void *opaque,
13011306
static void monitor_read(void *opaque, const uint8_t *buf, int size)
13021307
{
13031308
MonitorHMP *mon = container_of(opaque, MonitorHMP, common);
1304-
Monitor *old_mon;
13051309
int i;
13061310

1307-
old_mon = monitor_set_cur(&mon->common);
1308-
13091311
if (mon->rs) {
13101312
for (i = 0; i < size; i++) {
13111313
readline_handle_byte(mon->rs, buf[i]);
@@ -1317,8 +1319,6 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
13171319
handle_hmp_command(mon, (char *)buf);
13181320
}
13191321
}
1320-
1321-
monitor_set_cur(old_mon);
13221322
}
13231323

13241324
static void monitor_event(void *opaque, QEMUChrEvent event)

Diff for: monitor/misc.c

-5
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,20 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
120120
int64_t cpu_index, Error **errp)
121121
{
122122
char *output = NULL;
123-
Monitor *old_mon;
124123
MonitorHMP hmp = {};
125124

126125
monitor_data_init(&hmp.common, false, true, false);
127126

128-
old_mon = monitor_set_cur(&hmp.common);
129-
130127
if (has_cpu_index) {
131128
int ret = monitor_set_cpu(&hmp.common, cpu_index);
132129
if (ret < 0) {
133-
monitor_set_cur(old_mon);
134130
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
135131
"a CPU number");
136132
goto out;
137133
}
138134
}
139135

140136
handle_hmp_command(&hmp, command_line);
141-
monitor_set_cur(old_mon);
142137

143138
WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
144139
if (qstring_get_length(hmp.common.outbuf) > 0) {

0 commit comments

Comments
 (0)