From: Markus Armbruster <armbru@redhat.com>
To: Denis Plotnikov <den-plotnikov@yandex-team.ru>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org,
yc-core@yandex-team.ru, dgilbert@redhat.com
Subject: Re: [PATCH v1 1/2] monitor: move monitor destruction to the very end of qemu cleanup
Date: Thu, 25 Nov 2021 10:26:19 +0100 [thread overview]
Message-ID: <87a6hsmvr8.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20211115094143.157399-2-den-plotnikov@yandex-team.ru> (Denis Plotnikov's message of "Mon, 15 Nov 2021 12:41:42 +0300")
Denis Plotnikov <den-plotnikov@yandex-team.ru> writes:
> This is needed to keep sending DEVICE_DELETED events on qemu cleanup.
> The event may happen in the rcu thread and we're going to flush the rcu queue
> explicitly before qemu exiting in the next patch. So move the monitor
> destruction to the very end of qemu cleanup to be able to send all the events.
>
> Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru>
> ---
> monitor/monitor.c | 6 ++++++
> softmmu/runstate.c | 2 +-
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/monitor/monitor.c b/monitor/monitor.c
> index 21c7a68758f5..b04ae4850db2 100644
> --- a/monitor/monitor.c
> +++ b/monitor/monitor.c
> @@ -605,11 +605,17 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
> mon->outbuf = g_string_new(NULL);
> mon->skip_flush = skip_flush;
> mon->use_io_thread = use_io_thread;
> + /*
> + * take an extra ref to prevent monitor's chardev
> + * from destroying in qemu_chr_cleanup()
> + */
> + object_ref(OBJECT(mon->chr.chr));
I'm not sure we need the comment in the long run.
Taking a reference changes mon->chr.chr from soft reference to hard
reference. Feels right to me.
Note that mon->chr.chr isn't set here, but earlier. Unlike the other
parts of @mon. Because of this it starts as a soft reference, and
hardens only here.
It's set in three places:
1. monitor_init_hmp():
if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) {
g_free(mon);
return;
}
monitor_data_init(&mon->common, false, false, false);
2. monitor_init_qmp():
if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) {
g_free(mon);
return;
}
qemu_chr_fe_set_echo(&mon->common.chr, true);
/* Note: we run QMP monitor in I/O thread when @chr supports that */
monitor_data_init(&mon->common, true, false,
qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
3. qmp_human_monitor_command()
MonitorHMP hmp = {};
monitor_data_init(&hmp.common, false, true, false);
hmp.common.chr.chr remains null here. Works, because
object_ref(OBJECT(NULL)) and object_unref(OBJECT(NULL)) do nothing.
Slightly cleaner, I think: pass the character device as an argument to
monitor_data_init(), take a reference and store it in mon->chr.chr
there.
> }
>
> void monitor_data_destroy(Monitor *mon)
> {
> g_free(mon->mon_cpu_path);
> + object_unref(OBJECT(mon->chr.chr));
> qemu_chr_fe_deinit(&mon->chr, false);
> if (monitor_is_qmp(mon)) {
> monitor_data_destroy_qmp(container_of(mon, MonitorQMP, common));
> diff --git a/softmmu/runstate.c b/softmmu/runstate.c
> index 10d9b7365aa7..8d29dd2c00e2 100644
> --- a/softmmu/runstate.c
> +++ b/softmmu/runstate.c
> @@ -819,8 +819,8 @@ void qemu_cleanup(void)
> tpm_cleanup();
> net_cleanup();
> audio_cleanup();
> - monitor_cleanup();
> qemu_chr_cleanup();
> user_creatable_cleanup();
> + monitor_cleanup();
> /* TODO: unref root container, check all devices are ok */
> }
Monitor cleanup now runs with character devices that have been
"unparented" from the QOM tree. Paolo, is that okay?
next prev parent reply other threads:[~2021-11-25 9:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 9:41 [PATCH v1 0/2] vl: flush all task from rcu queue before exiting Denis Plotnikov
2021-11-15 9:41 ` [PATCH v1 1/2] monitor: move monitor destruction to the very end of qemu cleanup Denis Plotnikov
2021-11-25 9:26 ` Markus Armbruster [this message]
2021-11-15 9:41 ` [PATCH v1 2/2] vl: flush all task from rcu queue before exiting Denis Plotnikov
2021-11-19 9:42 ` [Ping] [PATCH v1 0/2] " Denis Plotnikov
2021-11-25 7:09 ` [PING][Ping] " Denis Plotnikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a6hsmvr8.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=den-plotnikov@yandex-team.ru \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yc-core@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.