aboutsummaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2020-10-05 17:58:44 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-10-09 07:08:19 +0200
commit947e47448dcc4e4d7a8b7c42b43acb3435b3ad35 (patch)
tree855a18a7da785ee7dff7919ec9a02be34c6ff51c /monitor
parent87e6f4a4d6885006931b371771e2933c40700427 (diff)
monitor: Use getter/setter functions for cur_mon
cur_mon really needs to be coroutine-local as soon as we move monitor command handlers to coroutines and let them yield. As a first step, just remove all direct accesses to cur_mon so that we can implement this in the getter function later. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20201005155855.256490-4-kwolf@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r--monitor/hmp.c11
-rw-r--r--monitor/misc.c13
-rw-r--r--monitor/monitor.c24
-rw-r--r--monitor/qmp-cmds-control.c2
-rw-r--r--monitor/qmp-cmds.c2
-rw-r--r--monitor/qmp.c7
6 files changed, 40 insertions, 19 deletions
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 4ecdefd705..e0cc9e65dd 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1300,12 +1300,11 @@ cleanup:
static void monitor_read(void *opaque, const uint8_t *buf, int size)
{
- MonitorHMP *mon;
- Monitor *old_mon = cur_mon;
+ MonitorHMP *mon = container_of(opaque, MonitorHMP, common);
+ Monitor *old_mon;
int i;
- cur_mon = opaque;
- mon = container_of(cur_mon, MonitorHMP, common);
+ old_mon = monitor_set_cur(&mon->common);
if (mon->rs) {
for (i = 0; i < size; i++) {
@@ -1313,13 +1312,13 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
}
} else {
if (size == 0 || buf[size - 1] != 0) {
- monitor_printf(cur_mon, "corrupted command\n");
+ monitor_printf(&mon->common, "corrupted command\n");
} else {
handle_hmp_command(mon, (char *)buf);
}
}
- cur_mon = old_mon;
+ monitor_set_cur(old_mon);
}
static void monitor_event(void *opaque, QEMUChrEvent event)
diff --git a/monitor/misc.c b/monitor/misc.c
index 4ea575eea8..ee8db45094 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -125,13 +125,12 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
monitor_data_init(&hmp.common, false, true, false);
- old_mon = cur_mon;
- cur_mon = &hmp.common;
+ old_mon = monitor_set_cur(&hmp.common);
if (has_cpu_index) {
int ret = monitor_set_cpu(&hmp.common, cpu_index);
if (ret < 0) {
- cur_mon = old_mon;
+ monitor_set_cur(old_mon);
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
"a CPU number");
goto out;
@@ -139,7 +138,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
}
handle_hmp_command(&hmp, command_line);
- cur_mon = old_mon;
+ monitor_set_cur(old_mon);
WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
if (qstring_get_length(hmp.common.outbuf) > 0) {
@@ -297,7 +296,7 @@ static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
CPUState *mon_get_cpu(void)
{
- return mon_get_cpu_sync(cur_mon, true);
+ return mon_get_cpu_sync(monitor_cur(), true);
}
CPUArchState *mon_get_cpu_env(void)
@@ -1232,6 +1231,7 @@ static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
void qmp_getfd(const char *fdname, Error **errp)
{
+ Monitor *cur_mon = monitor_cur();
mon_fd_t *monfd;
int fd, tmp_fd;
@@ -1270,6 +1270,7 @@ void qmp_getfd(const char *fdname, Error **errp)
void qmp_closefd(const char *fdname, Error **errp)
{
+ Monitor *cur_mon = monitor_cur();
mon_fd_t *monfd;
int tmp_fd;
@@ -1356,7 +1357,7 @@ AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
const char *opaque, Error **errp)
{
int fd;
- Monitor *mon = cur_mon;
+ Monitor *mon = monitor_cur();
AddfdInfo *fdinfo;
fd = qemu_chr_fe_get_msgfd(&mon->chr);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 0f32892ad4..099c164c6d 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -66,13 +66,31 @@ MonitorList mon_list;
int mon_refcount;
static bool monitor_destroyed;
-__thread Monitor *cur_mon;
+static __thread Monitor *cur_monitor;
+
+Monitor *monitor_cur(void)
+{
+ return cur_monitor;
+}
+
+/**
+ * Sets a new current monitor and returns the old one.
+ */
+Monitor *monitor_set_cur(Monitor *mon)
+{
+ Monitor *old_monitor = cur_monitor;
+
+ cur_monitor = mon;
+ return old_monitor;
+}
/**
* Is the current monitor, if any, a QMP monitor?
*/
bool monitor_cur_is_qmp(void)
{
+ Monitor *cur_mon = monitor_cur();
+
return cur_mon && monitor_is_qmp(cur_mon);
}
@@ -209,6 +227,8 @@ int monitor_printf(Monitor *mon, const char *fmt, ...)
*/
int error_vprintf(const char *fmt, va_list ap)
{
+ Monitor *cur_mon = monitor_cur();
+
if (cur_mon && !monitor_cur_is_qmp()) {
return monitor_vprintf(cur_mon, fmt, ap);
}
@@ -217,6 +237,8 @@ int error_vprintf(const char *fmt, va_list ap)
int error_vprintf_unless_qmp(const char *fmt, va_list ap)
{
+ Monitor *cur_mon = monitor_cur();
+
if (!cur_mon) {
return vfprintf(stderr, fmt, ap);
}
diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 8f04cfa6e6..a456762f6a 100644
--- a/monitor/qmp-cmds-control.c
+++ b/monitor/qmp-cmds-control.c
@@ -69,6 +69,7 @@ static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list,
void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable,
Error **errp)
{
+ Monitor *cur_mon = monitor_cur();
MonitorQMP *mon;
assert(monitor_is_qmp(cur_mon));
@@ -119,6 +120,7 @@ static void query_commands_cb(const QmpCommand *cmd, void *opaque)
CommandInfoList *qmp_query_commands(Error **errp)
{
CommandInfoList *list = NULL;
+ Monitor *cur_mon = monitor_cur();
MonitorQMP *mon;
assert(monitor_is_qmp(cur_mon));
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 0ab5b78580..1abef70a89 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -328,7 +328,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
Chardev *s;
int fd;
- fd = monitor_get_fd(cur_mon, fdname, errp);
+ fd = monitor_get_fd(monitor_cur(), fdname, errp);
if (fd < 0) {
return;
}
diff --git a/monitor/qmp.c b/monitor/qmp.c
index d433ceae5b..bb2d9d0cc7 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -139,12 +139,9 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
QDict *rsp;
QDict *error;
- old_mon = cur_mon;
- cur_mon = &mon->common;
-
+ old_mon = monitor_set_cur(&mon->common);
rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon));
-
- cur_mon = old_mon;
+ monitor_set_cur(old_mon);
if (mon->commands == &qmp_cap_negotiation_commands) {
error = qdict_get_qdict(rsp, "error");