Revision | 920824165c49bfbd1e0e9e07fd92e0bbbf32aea3 (tree) |
---|---|
Zeit | 2019-06-18 15:14:17 |
Autor | Kevin Wolf <kwolf@redh...> |
Commiter | Markus Armbruster |
monitor: Split Monitor.flags into separate bools
Monitor.flags contains three different flags: One to distinguish HMP
from QMP; one specific to HMP (MONITOR_USE_READLINE) that is ignored
with QMP; and another one specific to QMP (MONITOR_USE_PRETTY) that is
ignored with HMP.
Split the flags field into three bools and move them to the right
subclass. Flags are still in use for the monitor_init() interface.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20190613153405.24769-14-kwolf@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
@@ -1398,12 +1398,12 @@ static void monitor_readline_flush(void *opaque) | ||
1398 | 1398 | void monitor_init_hmp(Chardev *chr, int flags) |
1399 | 1399 | { |
1400 | 1400 | MonitorHMP *mon = g_new0(MonitorHMP, 1); |
1401 | - bool use_readline = flags & MONITOR_USE_READLINE; | |
1402 | 1401 | |
1403 | - monitor_data_init(&mon->common, flags, false, false); | |
1402 | + monitor_data_init(&mon->common, false, false, false); | |
1404 | 1403 | qemu_chr_fe_init(&mon->common.chr, chr, &error_abort); |
1405 | 1404 | |
1406 | - if (use_readline) { | |
1405 | + mon->use_readline = flags & MONITOR_USE_READLINE; | |
1406 | + if (mon->use_readline) { | |
1407 | 1407 | mon->rs = readline_init(monitor_readline_printf, |
1408 | 1408 | monitor_readline_flush, |
1409 | 1409 | mon, |
@@ -121,7 +121,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, | ||
121 | 121 | Monitor *old_mon; |
122 | 122 | MonitorHMP hmp = {}; |
123 | 123 | |
124 | - monitor_data_init(&hmp.common, 0, true, false); | |
124 | + monitor_data_init(&hmp.common, false, true, false); | |
125 | 125 | |
126 | 126 | old_mon = cur_mon; |
127 | 127 | cur_mon = &hmp.common; |
@@ -86,8 +86,8 @@ typedef struct HMPCommand { | ||
86 | 86 | struct Monitor { |
87 | 87 | CharBackend chr; |
88 | 88 | int reset_seen; |
89 | - int flags; | |
90 | 89 | int suspend_cnt; /* Needs to be accessed atomically */ |
90 | + bool is_qmp; | |
91 | 91 | bool skip_flush; |
92 | 92 | bool use_io_thread; |
93 | 93 |
@@ -112,6 +112,7 @@ struct Monitor { | ||
112 | 112 | |
113 | 113 | struct MonitorHMP { |
114 | 114 | Monitor common; |
115 | + bool use_readline; | |
115 | 116 | /* |
116 | 117 | * State used only in the thread "owning" the monitor. |
117 | 118 | * If @use_io_thread, this is @mon_iothread. (This does not actually happen |
@@ -125,6 +126,7 @@ struct MonitorHMP { | ||
125 | 126 | typedef struct { |
126 | 127 | Monitor common; |
127 | 128 | JSONMessageParser parser; |
129 | + bool pretty; | |
128 | 130 | /* |
129 | 131 | * When a client connects, we're in capabilities negotiation mode. |
130 | 132 | * @commands is &qmp_cap_negotiation_commands then. When command |
@@ -148,7 +150,7 @@ typedef struct { | ||
148 | 150 | */ |
149 | 151 | static inline bool monitor_is_qmp(const Monitor *mon) |
150 | 152 | { |
151 | - return mon->flags & MONITOR_USE_CONTROL; | |
153 | + return mon->is_qmp; | |
152 | 154 | } |
153 | 155 | |
154 | 156 | typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList; |
@@ -165,7 +167,7 @@ void monitor_init_qmp(Chardev *chr, int flags); | ||
165 | 167 | void monitor_init_hmp(Chardev *chr, int flags); |
166 | 168 | |
167 | 169 | int monitor_puts(Monitor *mon, const char *str); |
168 | -void monitor_data_init(Monitor *mon, int flags, bool skip_flush, | |
170 | +void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, | |
169 | 171 | bool use_io_thread); |
170 | 172 | void monitor_data_destroy(Monitor *mon); |
171 | 173 | int monitor_can_read(void *opaque); |
@@ -78,14 +78,18 @@ bool monitor_cur_is_qmp(void) | ||
78 | 78 | * Note: not all HMP monitors use readline, e.g., gdbserver has a |
79 | 79 | * non-interactive HMP monitor, so readline is not used there. |
80 | 80 | */ |
81 | -static inline bool monitor_uses_readline(const Monitor *mon) | |
81 | +static inline bool monitor_uses_readline(const MonitorHMP *mon) | |
82 | 82 | { |
83 | - return mon->flags & MONITOR_USE_READLINE; | |
83 | + return mon->use_readline; | |
84 | 84 | } |
85 | 85 | |
86 | 86 | static inline bool monitor_is_hmp_non_interactive(const Monitor *mon) |
87 | 87 | { |
88 | - return !monitor_is_qmp(mon) && !monitor_uses_readline(mon); | |
88 | + if (monitor_is_qmp(mon)) { | |
89 | + return false; | |
90 | + } | |
91 | + | |
92 | + return !monitor_uses_readline(container_of(mon, MonitorHMP, common)); | |
89 | 93 | } |
90 | 94 | |
91 | 95 | static void monitor_flush_locked(Monitor *mon); |
@@ -521,17 +525,17 @@ static void monitor_iothread_init(void) | ||
521 | 525 | mon_iothread = iothread_create("mon_iothread", &error_abort); |
522 | 526 | } |
523 | 527 | |
524 | -void monitor_data_init(Monitor *mon, int flags, bool skip_flush, | |
528 | +void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, | |
525 | 529 | bool use_io_thread) |
526 | 530 | { |
527 | 531 | if (use_io_thread && !mon_iothread) { |
528 | 532 | monitor_iothread_init(); |
529 | 533 | } |
530 | 534 | qemu_mutex_init(&mon->mon_lock); |
535 | + mon->is_qmp = is_qmp; | |
531 | 536 | mon->outbuf = qstring_new(); |
532 | 537 | mon->skip_flush = skip_flush; |
533 | 538 | mon->use_io_thread = use_io_thread; |
534 | - mon->flags = flags; | |
535 | 539 | } |
536 | 540 | |
537 | 541 | void monitor_data_destroy(Monitor *mon) |
@@ -87,8 +87,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp) | ||
87 | 87 | const QObject *data = QOBJECT(rsp); |
88 | 88 | QString *json; |
89 | 89 | |
90 | - json = mon->common.flags & MONITOR_USE_PRETTY ? | |
91 | - qobject_to_json_pretty(data) : qobject_to_json(data); | |
90 | + json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data); | |
92 | 91 | assert(json != NULL); |
93 | 92 | |
94 | 93 | qstring_append_chr(json, '\n'); |
@@ -373,9 +372,11 @@ void monitor_init_qmp(Chardev *chr, int flags) | ||
373 | 372 | assert(!(flags & MONITOR_USE_READLINE)); |
374 | 373 | |
375 | 374 | /* Note: we run QMP monitor in I/O thread when @chr supports that */ |
376 | - monitor_data_init(&mon->common, flags, false, | |
375 | + monitor_data_init(&mon->common, true, false, | |
377 | 376 | qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT)); |
378 | 377 | |
378 | + mon->pretty = flags & MONITOR_USE_PRETTY; | |
379 | + | |
379 | 380 | qemu_mutex_init(&mon->qmp_queue_lock); |
380 | 381 | mon->qmp_requests = g_queue_new(); |
381 | 382 |