ui/console: register console in QOM tree dynamically
Consoles created after init_displaystate() (e.g. hotplugged display devices) were never added to the /backend/console[N] QOM tree. Extract qemu_console_add_to_qom() and call it from qemu_console_register() when the display is already initialized. Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260623-b4-ui-v4-31-4656aec3398d@redhat.com>
Marc-André Lureau committed
Jun 23, 2026 at 11:44 UTC
a2e1f2dbed9eeacc33bbcb2418e75674fd444907
1 file changed
+17
-6
ui/console.c
+17
-6
@@ -68,6 +68,7 @@ struct DisplayState {
68
uint64_t last_update;
69
uint64_t update_interval;
70
bool refreshing;
71
+ bool initialized;
72
73
QLIST_HEAD(, DisplayChangeListener) listeners;
74
NotifierList console_notifiers;
@@ -376,6 +377,13 @@ void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len)
377
}
378
}
379
380
+static void qemu_console_add_to_qom(QemuConsole *con)
381
+{
382
+ g_autofree gchar *name = g_strdup_printf("console[%d]", con->index);
383
+ object_property_add_child(object_get_container("backend"),
384
+ name, OBJECT(con));
385
+}
386
+
387
static void
388
qemu_console_register(QemuConsole *c)
389
{
@@ -413,6 +421,10 @@ qemu_console_register(QemuConsole *c)
421
}
422
}
423
}
424
+
425
+ if (c->ds->initialized) {
426
+ qemu_console_add_to_qom(c);
427
+ }
428
}
429
430
static void
@@ -1089,20 +1101,19 @@ void qemu_console_remove_notifier(Notifier *notifier)
1101
*/
1102
DisplayState *init_displaystate(void)
1103
{
1092
- gchar *name;
1104
+ DisplayState *ds = get_alloc_displaystate();
1105
QemuConsole *con;
1106
1107
QTAILQ_FOREACH(con, &consoles, next) {
1108
/* Hook up into the qom tree here (not in object_new()), once
1109
* all QemuConsoles are created and the order / numbering
1110
* doesn't change any more */
1099
- name = g_strdup_printf("console[%d]", con->index);
1100
- object_property_add_child(object_get_container("backend"),
1101
- name, OBJECT(con));
1102
- g_free(name);
1111
+ qemu_console_add_to_qom(con);
1112
}
1113
1105
- return display_state;
1114
+ ds->initialized = true;
1115
+
1116
+ return ds;
1117
}
1118
1119
void qemu_graphic_console_set_hwops(QemuConsole *con,