@samitouri / QOSamiQemu / commits / 271df1b5d0

monitor: move HMP-only fields from Monitor to MonitorHMP

mon_cpu_path and reset_seen are only used by HMP monitors; move them from the base Monitor struct into MonitorHMP to properly encapsulate HMP-specific state. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-8-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC 271df1b5d0c24ee6d49533bb11faf087a87acb18
4 files changed +16 -14
monitor/hmp-cmds.c
+9 -7
@@ -499,31 +499,33 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
499 /* Set the current CPU defined by the user. Callers must hold BQL. */
500 int monitor_set_cpu(Monitor *mon, int cpu_index)
501 {
502 + MonitorHMP *hmp = MONITOR_HMP(mon);
503 CPUState *cpu;
504
505 cpu = qemu_get_cpu(cpu_index);
506 if (cpu == NULL) {
507 return -1;
508 }
508 - g_free(mon->mon_cpu_path);
509 - mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
509 + g_free(hmp->mon_cpu_path);
510 + hmp->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
511 return 0;
512 }
513
514 /* Callers must hold BQL. */
515 static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
516 {
517 + MonitorHMP *hmp = MONITOR_HMP(mon);
518 CPUState *cpu = NULL;
519
518 - if (mon->mon_cpu_path) {
519 - cpu = (CPUState *) object_resolve_path_type(mon->mon_cpu_path,
520 + if (hmp->mon_cpu_path) {
521 + cpu = (CPUState *) object_resolve_path_type(hmp->mon_cpu_path,
522 TYPE_CPU, NULL);
523 if (!cpu) {
522 - g_free(mon->mon_cpu_path);
523 - mon->mon_cpu_path = NULL;
524 + g_free(hmp->mon_cpu_path);
525 + hmp->mon_cpu_path = NULL;
526 }
527 }
526 - if (!mon->mon_cpu_path) {
528 + if (!hmp->mon_cpu_path) {
529 if (!first_cpu) {
530 return NULL;
531 }
monitor/hmp.c
+5 -4
@@ -50,6 +50,7 @@ OBJECT_DEFINE_TYPE(MonitorHMP, monitor_hmp, MONITOR_HMP, MONITOR);
50 static void monitor_hmp_finalize(Object *obj)
51 {
52 MonitorHMP *hmp = MONITOR_HMP(obj);
53 + g_free(hmp->mon_cpu_path);
54 if (hmp->rs) {
55 readline_free(hmp->rs);
56 }
@@ -112,8 +113,8 @@ int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap)
113 static void monitor_hmp_accept_input(Monitor *mon)
114 {
115 qemu_mutex_lock(&mon->mon_lock);
115 - if (mon->reset_seen) {
116 - MonitorHMP *hmp = MONITOR_HMP(mon);
116 + MonitorHMP *hmp = MONITOR_HMP(mon);
117 + if (hmp->reset_seen) {
118 assert(hmp->rs);
119 readline_restart(hmp->rs);
120 qemu_chr_fe_accept_input(&mon->chr);
@@ -1556,7 +1557,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
1557 case CHR_EVENT_MUX_OUT:
1558 qemu_mutex_lock(&mon->mon_lock);
1559 if (!mon->mux_out) {
1559 - if (mon->reset_seen && !mon->suspend_cnt) {
1560 + if (hmp->reset_seen && !mon->suspend_cnt) {
1561 monitor_puts_locked(mon, "\n");
1562 } else {
1563 monitor_flush_locked(mon);
@@ -1573,7 +1574,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
1574 monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
1575 "information\n", QEMU_VERSION);
1576 qemu_mutex_lock(&mon->mon_lock);
1576 - mon->reset_seen = 1;
1577 + hmp->reset_seen = 1;
1578 if (!mon->mux_out && hmp->use_readline) {
1579 /* Suspend-resume forces the prompt to be printed. */
1580 monitor_suspend(mon);
monitor/monitor-internal.h
+2 -2
@@ -137,7 +137,6 @@ struct Monitor {
137 CharFrontend chr;
138 int suspend_cnt; /* Needs to be accessed atomically */
139 QEMUBH *accept_input_bh; /* persistent BH for monitor_accept_input */
140 - char *mon_cpu_path;
140 QTAILQ_ENTRY(Monitor) entry;
141
142 /*
@@ -153,7 +152,6 @@ struct Monitor {
152 GString *outbuf;
153 guint out_watch;
154 int mux_out;
156 - int reset_seen;
155 };
156
157 struct MonitorHMPClass {
@@ -170,6 +168,8 @@ struct MonitorHMP {
168 * These members can be safely accessed without locks.
169 */
170 ReadLineState *rs;
171 + char *mon_cpu_path;
172 + int reset_seen;
173 };
174
175 struct MonitorQMPClass {
monitor/monitor.c
-1
@@ -89,7 +89,6 @@ static void monitor_finalize(Object *obj)
89 qemu_bh_delete(mon->accept_input_bh);
90 }
91 g_free(mon->chardev_id);
92 - g_free(mon->mon_cpu_path);
92 qemu_chr_fe_deinit(&mon->chr, false);
93 g_string_free(mon->outbuf, true);
94 qemu_mutex_destroy(&mon->mon_lock);