[PATCH 2/4] monitor: allow calling monitor_resume under mon_lock

Paolo Bonzini posted 4 patches 2 years, 8 months ago
Maintainers: "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
[PATCH 2/4] monitor: allow calling monitor_resume under mon_lock
Posted by Paolo Bonzini 2 years, 8 months ago
Move monitor_resume()'s call to readline_show_prompt() outside the
potentially locked section.  Reuse the existing monitor_accept_input()
bottom half for this purpose.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 monitor/monitor.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index 4b11bca2a21d..7080d2da8ec6 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -567,6 +567,12 @@ static void monitor_accept_input(void *opaque)
 {
     Monitor *mon = opaque;
 
+    if (!monitor_is_qmp(mon)) {
+        MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
+        assert(hmp_mon->rs);
+        readline_show_prompt(hmp_mon->rs);
+    }
+
     qemu_chr_fe_accept_input(&mon->chr);
 }
 
@@ -585,12 +591,6 @@ void monitor_resume(Monitor *mon)
             ctx = qemu_get_aio_context();
         }
 
-        if (!monitor_is_qmp(mon)) {
-            MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
-            assert(hmp_mon->rs);
-            readline_show_prompt(hmp_mon->rs);
-        }
-
         aio_bh_schedule_oneshot(ctx, monitor_accept_input, mon);
     }
 
-- 
2.40.1
Re: [PATCH 2/4] monitor: allow calling monitor_resume under mon_lock
Posted by Markus Armbruster 2 years, 8 months ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> Move monitor_resume()'s call to readline_show_prompt() outside the
> potentially locked section.  Reuse the existing monitor_accept_input()
> bottom half for this purpose.

This describes what the patch changes, but not why we want the change.
Could you elaborate a bit?

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  monitor/monitor.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/monitor/monitor.c b/monitor/monitor.c
> index 4b11bca2a21d..7080d2da8ec6 100644
> --- a/monitor/monitor.c
> +++ b/monitor/monitor.c
> @@ -567,6 +567,12 @@ static void monitor_accept_input(void *opaque)
>  {
>      Monitor *mon = opaque;
>  
> +    if (!monitor_is_qmp(mon)) {
> +        MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
> +        assert(hmp_mon->rs);
> +        readline_show_prompt(hmp_mon->rs);
> +    }
> +
>      qemu_chr_fe_accept_input(&mon->chr);
>  }
>  
> @@ -585,12 +591,6 @@ void monitor_resume(Monitor *mon)
>              ctx = qemu_get_aio_context();
>          }
>  
> -        if (!monitor_is_qmp(mon)) {
> -            MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
> -            assert(hmp_mon->rs);
> -            readline_show_prompt(hmp_mon->rs);
> -        }
> -
>          aio_bh_schedule_oneshot(ctx, monitor_accept_input, mon);
>      }