From: Christian Brauner <brauner@kernel.org>
The monitor_accept_input API is called from a bottom half, and will
invoke qemu_chr_fe_accept_input().
When a following patch introduces the ability to delete monitors, it
will be neccesary to delete the bottom half. Protecting the call to
qemu_chr_fe_accept_input with the monitor lock will allow for
synchronization with the deletion process.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
[DB: extracted from a larger commit and refactored to apply
to the new monitor class structure]
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
monitor/hmp.c | 2 ++
monitor/monitor.c | 6 +-----
monitor/qmp.c | 9 +++++++++
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 75b93f29a3..71a1888249 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -116,9 +116,11 @@ static void monitor_hmp_accept_input(Monitor *mon)
MonitorHMP *hmp = MONITOR_HMP(mon);
assert(hmp->rs);
readline_restart(hmp->rs);
+ qemu_chr_fe_accept_input(&mon->chr);
qemu_mutex_unlock(&mon->mon_lock);
readline_show_prompt(hmp->rs);
} else {
+ qemu_chr_fe_accept_input(&mon->chr);
qemu_mutex_unlock(&mon->mon_lock);
}
}
diff --git a/monitor/monitor.c b/monitor/monitor.c
index de1f761041..4a45c15a36 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -562,11 +562,7 @@ static void monitor_accept_input(void *opaque)
Monitor *mon = opaque;
MonitorClass *cls = MONITOR_GET_CLASS(mon);
- if (cls->accept_input) {
- cls->accept_input(mon);
- }
-
- qemu_chr_fe_accept_input(&mon->chr);
+ cls->accept_input(mon);
}
void monitor_resume(Monitor *mon)
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 1c67f40e4a..dc15809145 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -107,6 +107,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict);
static bool monitor_qmp_requires_iothread(const Monitor *mon);
static void monitor_qmp_complete(UserCreatable *uc, Error **errp);
static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp);
+static void monitor_qmp_accept_input(Monitor *mon);
static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
{
@@ -119,6 +120,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
moncls->emit_event = monitor_qmp_emit_event;
moncls->requires_iothread = monitor_qmp_requires_iothread;
+ moncls->accept_input = monitor_qmp_accept_input;
ucc->complete = monitor_qmp_complete;
ucc->prepare_delete = monitor_qmp_prepare_delete;
@@ -665,3 +667,10 @@ static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
error_setg(errp, "Deleting QMP monitors is not supported");
return false;
}
+
+static void monitor_qmp_accept_input(Monitor *mon)
+{
+ WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
+ qemu_chr_fe_accept_input(&mon->chr);
+ }
+}
--
2.55.0