From: Zhang Chen <zhangckid@gmail.com>
To: qemu-devel <qemu-devel@nongnu.org>,
"Dr . David Alan Gilbert" <dave@treblig.org>,
Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Jason Wang <jasowang@redhat.com>,
Fam Zheng <fam@euphon.net>
Cc: Zhang Chen <zhangckid@gmail.com>
Subject: [PATCH V9 06/17] monitor: refactor monitor_data_init() to pass ID
Date: Wed, 24 Jun 2026 15:08:40 +0800 [thread overview]
Message-ID: <20260624070851.13342-7-zhangckid@gmail.com> (raw)
In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com>
Anonymous monitors (e.g., '-monitor stdio' or GDB stub) leave their 'id'
field as NULL. To allow downstream subsystems (like iothread tracking) to
identify these instances later, the initialization paths must propagate
the context.
Refactor monitor_data_init() to accept the 'id' parameters, and
update all internal QMP/HMP paths to pass these identifiers.
For anonymous monitors, 'mon->id' remains NULL at this stage to avoid
namespace pollution, setting up infrastructure for subsequent patches.
Signed-off-by: Zhang Chen <zhangckid@gmail.com>
---
chardev/char.c | 2 +-
gdbstub/system.c | 3 ++-
include/monitor/monitor.h | 5 +++--
monitor/hmp.c | 5 +++--
monitor/monitor-internal.h | 4 +++-
monitor/monitor.c | 9 ++++++---
monitor/qmp-cmds.c | 2 +-
monitor/qmp.c | 5 +++--
stubs/monitor-internal.c | 3 ++-
9 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/chardev/char.c b/chardev/char.c
index ca8b37ed8d..f057247001 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -805,7 +805,7 @@ static Chardev *qemu_chr_new_from_name(const char *label, const char *filename,
if (qemu_opt_get_bool(opts, "mux", 0)) {
assert(permit_mux_mon);
- monitor_init_hmp(chr, true, &err);
+ monitor_init_hmp(chr, true, NULL, &err);
if (err) {
error_report_err(err);
object_unparent(OBJECT(chr));
diff --git a/gdbstub/system.c b/gdbstub/system.c
index e86c5870ab..50f934fde3 100644
--- a/gdbstub/system.c
+++ b/gdbstub/system.c
@@ -388,7 +388,8 @@ bool gdbserver_start(const char *device, Error **errp)
/* Initialize a monitor terminal for gdb */
mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
NULL, NULL, &error_abort);
- monitor_init_hmp(mon_chr, false, &error_abort);
+
+ monitor_init_hmp(mon_chr, false, NULL, &error_abort);
} else {
qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
mon_chr = gdbserver_system_state.mon_chr;
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 55649a8664..4a5eb20bea 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -19,8 +19,9 @@ bool monitor_cur_is_qmp(void);
void monitor_init_globals(void);
void monitor_init_globals_core(void);
-void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
-void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp);
+void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **errp);
+void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id,
+ Error **errp);
int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp);
int monitor_init_opts(QemuOpts *opts, Error **errp);
void monitor_cleanup(void);
diff --git a/monitor/hmp.c b/monitor/hmp.c
index cc4390486e..4ee8cb58d1 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1522,7 +1522,8 @@ static void monitor_readline_flush(void *opaque)
monitor_flush(&mon->common);
}
-void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
+void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id,
+ Error **errp)
{
MonitorHMP *mon = g_new0(MonitorHMP, 1);
@@ -1531,7 +1532,7 @@ void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
return;
}
- monitor_data_init(&mon->common, false, false, false);
+ monitor_data_init(&mon->common, false, false, false, id);
mon->use_readline = use_readline;
if (mon->use_readline) {
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index a5c4aba306..f651ba6a90 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -108,6 +108,8 @@ struct Monitor {
bool skip_flush;
bool use_io_thread;
+ char *id;
+
char *mon_cpu_path;
QTAILQ_ENTRY(Monitor) entry;
@@ -179,7 +181,7 @@ extern QemuMutex monitor_lock;
extern MonitorList mon_list;
void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
- bool use_io_thread);
+ bool use_io_thread, const char *id);
void monitor_data_destroy(Monitor *mon);
int monitor_can_read(void *opaque);
void monitor_list_append(Monitor *mon);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 00b93ed612..65749f931e 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -608,8 +608,10 @@ static void monitor_iothread_init(void)
}
void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
- bool use_io_thread)
+ bool use_io_thread, const char *id)
{
+ mon->id = id ? g_strdup(id) : NULL;
+
if (use_io_thread && !mon_iothread) {
monitor_iothread_init();
}
@@ -629,6 +631,7 @@ void monitor_data_destroy(Monitor *mon)
} else {
readline_free(container_of(mon, MonitorHMP, common)->rs);
}
+ g_free(mon->id);
g_string_free(mon->outbuf, true);
qemu_mutex_destroy(&mon->mon_lock);
}
@@ -732,7 +735,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
switch (opts->mode) {
case MONITOR_MODE_CONTROL:
- monitor_init_qmp(chr, opts->pretty, errp);
+ monitor_init_qmp(chr, opts->pretty, opts->id, errp);
break;
case MONITOR_MODE_READLINE:
if (!allow_hmp) {
@@ -743,7 +746,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
error_setg(errp, "'pretty' is not compatible with HMP monitors");
return -1;
}
- monitor_init_hmp(chr, true, errp);
+ monitor_init_hmp(chr, true, opts->id, errp);
break;
default:
g_assert_not_reached();
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 0c409c27dc..e49b9cbf8b 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -168,7 +168,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
char *output = NULL;
MonitorHMP hmp = {};
- monitor_data_init(&hmp.common, false, true, false);
+ monitor_data_init(&hmp.common, false, true, false, NULL);
if (has_cpu_index) {
int ret = monitor_set_cpu(&hmp.common, cpu_index);
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 687019811f..8fd71386e8 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -513,7 +513,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
monitor_list_append(&mon->common);
}
-void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
+void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **errp)
{
MonitorQMP *mon = g_new0(MonitorQMP, 1);
@@ -525,7 +525,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
/* 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));
+ qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT),
+ id);
mon->pretty = pretty;
diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c
index 4fece49d53..325a559e62 100644
--- a/stubs/monitor-internal.c
+++ b/stubs/monitor-internal.c
@@ -8,6 +8,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
return -1;
}
-void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
+void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id,
+ Error **errp)
{
}
--
2.49.0
next prev parent reply other threads:[~2026-06-24 7:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 7:08 [PATCH V9 00/17] iothread: Support tracking and querying IOThread holders Zhang Chen
2026-06-24 7:08 ` [PATCH V9 01/17] qapi/misc: Fix missed query-iothreads items Zhang Chen
2026-06-24 7:08 ` [PATCH V9 02/17] iothread: introduce iothread_ref/unref to track attached devices Zhang Chen
2026-06-24 15:51 ` Stefan Hajnoczi
2026-06-24 7:08 ` [PATCH V9 03/17] iothread: tracking iothread users with holder name Zhang Chen
2026-06-24 17:10 ` Stefan Hajnoczi
2026-06-24 7:08 ` [PATCH V9 04/17] iothread: introduce iothread_unsafe_get_aio_context() Zhang Chen
2026-06-24 17:19 ` Stefan Hajnoczi
2026-06-24 7:08 ` [PATCH V9 05/17] block/export: track IOThread reference in BlockExport Zhang Chen
2026-06-24 17:51 ` Stefan Hajnoczi
2026-06-24 7:08 ` Zhang Chen [this message]
2026-06-24 7:08 ` [PATCH V9 07/17] monitor: support iothread ref/unref for anonymous monitors Zhang Chen
2026-06-24 7:08 ` [PATCH V9 08/17] monitor: switch to iothread_unsafe_get_aio_context() Zhang Chen
2026-06-24 7:08 ` [PATCH V9 09/17] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-06-24 7:08 ` [PATCH V9 10/17] virtio: use iothread_get/put_aio_context for thread pinning Zhang Chen
2026-06-24 7:08 ` [PATCH V9 11/17] net/colo: track IOThread references using path-based holder Zhang Chen
2026-06-24 7:08 ` [PATCH V9 12/17] virtio-balloon: Update tracking iothread users with holder Zhang Chen
2026-06-24 7:08 ` [PATCH V9 13/17] vfio-user/proxy: Update tracking iothread users with holder name Zhang Chen
2026-06-24 7:08 ` [PATCH V9 14/17] xen-block: " Zhang Chen
2026-06-24 7:08 ` [PATCH V9 15/17] qapi: examine IOThread attachment status via query-iothreads Zhang Chen
2026-06-24 7:08 ` [PATCH V9 16/17] iothread: simplify API by merging iothread_get_aio_context variants Zhang Chen
2026-06-24 7:08 ` [PATCH V9 17/17] tests/unit/iothread: Update the iothread_get_aio_context Zhang Chen
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=20260624070851.13342-7-zhangckid@gmail.com \
--to=zhangckid@gmail.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=eblake@redhat.com \
--cc=fam@euphon.net \
--cc=jasowang@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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.