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.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
monitor/monitor-internal.h | 4 ++--
monitor/hmp-cmds.c | 17 ++++++++++-------
monitor/hmp.c | 5 +++--
monitor/monitor.c | 16 +++++++++++-----
4 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index a5c4aba306e..e071ad3e2e8 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -108,7 +108,6 @@ struct Monitor {
bool skip_flush;
bool use_io_thread;
- char *mon_cpu_path;
QTAILQ_ENTRY(Monitor) entry;
/*
@@ -124,7 +123,6 @@ struct Monitor {
GString *outbuf;
guint out_watch;
int mux_out;
- int reset_seen;
};
struct MonitorHMP {
@@ -138,6 +136,8 @@ struct MonitorHMP {
* These members can be safely accessed without locks.
*/
ReadLineState *rs;
+ char *mon_cpu_path;
+ int reset_seen;
};
typedef struct {
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 521ab8a641c..e7a02b1fddb 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -496,31 +496,34 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
/* Set the current CPU defined by the user. Callers must hold BQL. */
int monitor_set_cpu(Monitor *mon, int cpu_index)
{
+ assert(!monitor_is_qmp(mon));
+ MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
CPUState *cpu;
cpu = qemu_get_cpu(cpu_index);
if (cpu == NULL) {
return -1;
}
- g_free(mon->mon_cpu_path);
- mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
+ g_free(hmp_mon->mon_cpu_path);
+ hmp_mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
return 0;
}
/* Callers must hold BQL. */
static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
{
+ MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
CPUState *cpu = NULL;
- if (mon->mon_cpu_path) {
- cpu = (CPUState *) object_resolve_path_type(mon->mon_cpu_path,
+ if (hmp_mon->mon_cpu_path) {
+ cpu = (CPUState *) object_resolve_path_type(hmp_mon->mon_cpu_path,
TYPE_CPU, NULL);
if (!cpu) {
- g_free(mon->mon_cpu_path);
- mon->mon_cpu_path = NULL;
+ g_free(hmp_mon->mon_cpu_path);
+ hmp_mon->mon_cpu_path = NULL;
}
}
- if (!mon->mon_cpu_path) {
+ if (!hmp_mon->mon_cpu_path) {
if (!first_cpu) {
return NULL;
}
diff --git a/monitor/hmp.c b/monitor/hmp.c
index cc4390486e1..de8804af51a 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1453,6 +1453,7 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
static void monitor_event(void *opaque, QEMUChrEvent event)
{
Monitor *mon = opaque;
+ MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
switch (event) {
case CHR_EVENT_MUX_IN:
@@ -1467,7 +1468,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
case CHR_EVENT_MUX_OUT:
qemu_mutex_lock(&mon->mon_lock);
if (!mon->mux_out) {
- if (mon->reset_seen && !mon->suspend_cnt) {
+ if (hmp_mon->reset_seen && !mon->suspend_cnt) {
monitor_puts_locked(mon, "\n");
} else {
monitor_flush_locked(mon);
@@ -1482,7 +1483,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
"information\n", QEMU_VERSION);
qemu_mutex_lock(&mon->mon_lock);
- mon->reset_seen = 1;
+ hmp_mon->reset_seen = 1;
if (!mon->mux_out) {
/* Suspend-resume forces the prompt to be printed. */
monitor_suspend(mon);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 00b93ed6124..2dec0e299af 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -541,12 +541,17 @@ static void monitor_accept_input(void *opaque)
Monitor *mon = opaque;
qemu_mutex_lock(&mon->mon_lock);
- if (!monitor_is_qmp(mon) && mon->reset_seen) {
+ if (!monitor_is_qmp(mon)) {
MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
assert(hmp_mon->rs);
- readline_restart(hmp_mon->rs);
+ bool reset_seen = hmp_mon->reset_seen;
+ if (reset_seen) {
+ readline_restart(hmp_mon->rs);
+ }
qemu_mutex_unlock(&mon->mon_lock);
- readline_show_prompt(hmp_mon->rs);
+ if (reset_seen) {
+ readline_show_prompt(hmp_mon->rs);
+ }
} else {
qemu_mutex_unlock(&mon->mon_lock);
}
@@ -622,12 +627,13 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
void monitor_data_destroy(Monitor *mon)
{
- g_free(mon->mon_cpu_path);
qemu_chr_fe_deinit(&mon->chr, false);
if (monitor_is_qmp(mon)) {
monitor_data_destroy_qmp(container_of(mon, MonitorQMP, common));
} else {
- readline_free(container_of(mon, MonitorHMP, common)->rs);
+ MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
+ readline_free(hmp_mon->rs);
+ g_free(hmp_mon->mon_cpu_path);
}
g_string_free(mon->outbuf, true);
qemu_mutex_destroy(&mon->mon_lock);
--
2.54.0