From 947e47448dcc4e4d7a8b7c42b43acb3435b3ad35 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 5 Oct 2020 17:58:44 +0200 Subject: 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 Message-Id: <20201005155855.256490-4-kwolf@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Markus Armbruster --- stubs/monitor-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'stubs') diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 6cff1c4..0cd2d86 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -3,7 +3,10 @@ #include "qemu-common.h" #include "qapi/qapi-emit-events.h" -__thread Monitor *cur_mon; +Monitor *monitor_cur(void) +{ + return NULL; +} void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { -- cgit v1.1 From 41725fa7eda1d97576fc8c79b58d04a61629f40e Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 5 Oct 2020 17:58:47 +0200 Subject: qmp: Call monitor_set_cur() only in qmp_dispatch() The correct way to set the current monitor for a coroutine handler will be different than for a blocking handler, so monitor_set_cur() needs to be called in qmp_dispatch(). Signed-off-by: Kevin Wolf Message-Id: <20201005155855.256490-7-kwolf@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Markus Armbruster --- stubs/monitor-core.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'stubs') diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 0cd2d86..dc1748b 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -8,6 +8,11 @@ Monitor *monitor_cur(void) return NULL; } +Monitor *monitor_set_cur(Monitor *mon) +{ + return NULL; +} + void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { } -- cgit v1.1 From e69ee454b5f9dff3af48bcfc3d9691b3edb02fe2 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 5 Oct 2020 17:58:48 +0200 Subject: monitor: Make current monitor a per-coroutine property This way, a monitor command handler will still be able to access the current monitor, but when it yields, all other code code will correctly get NULL from monitor_cur(). This uses a hash table to map the coroutine pointer to the current monitor of that coroutine. Outside of coroutine context, we associate the current monitor with the leader coroutine of the current thread. Approaches to implement some form of coroutine local storage directly in the coroutine core code have been considered and discarded because they didn't end up being much more generic than the hash table and their performance impact on coroutines not using coroutine local storage was unclear. As the block layer uses a coroutine per I/O request, this is a fast path and we have to be careful. It's safest to just stay out of this path with code only used by the monitor. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Message-Id: <20201005155855.256490-8-kwolf@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Markus Armbruster --- stubs/monitor-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stubs') diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index dc1748b..d058a2a 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -8,7 +8,7 @@ Monitor *monitor_cur(void) return NULL; } -Monitor *monitor_set_cur(Monitor *mon) +Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { return NULL; } -- cgit v1.1