2009-03-06 02:01:23 +03:00
|
|
|
#ifndef MONITOR_H
|
|
|
|
#define MONITOR_H
|
|
|
|
|
2012-12-17 21:19:44 +04:00
|
|
|
#include "block/block.h"
|
2018-02-27 02:13:27 +03:00
|
|
|
#include "qapi/qapi-types-misc.h"
|
2013-11-14 14:54:15 +04:00
|
|
|
#include "qemu/readline.h"
|
2021-05-16 23:50:34 +03:00
|
|
|
#include "exec/hwaddr.h"
|
2009-03-06 02:01:23 +03:00
|
|
|
|
2019-06-13 18:33:54 +03:00
|
|
|
typedef struct MonitorHMP MonitorHMP;
|
2020-02-24 17:30:04 +03:00
|
|
|
typedef struct MonitorOptions MonitorOptions;
|
2009-03-06 02:01:23 +03:00
|
|
|
|
monitor: Suspend monitor instead dropping commands
When a QMP client sends in-band commands more quickly that we can
process them, we can either queue them without limit (QUEUE), drop
commands when the queue is full (DROP), or suspend receiving commands
when the queue is full (SUSPEND). None of them is ideal:
* QUEUE lets a misbehaving client make QEMU eat memory without bounds.
Not such a hot idea.
* With DROP, the client has to cope with dropped in-band commands. To
inform the client, we send a COMMAND_DROPPED event then. The event is
flawed by design in two ways: it's ambiguous (see commit d621cfe0a17),
and it brings back the "eat memory without bounds" problem.
* With SUSPEND, the client has to manage the flow of in-band commands to
keep the monitor available for out-of-band commands.
We currently DROP. Switch to SUSPEND.
Managing the flow of in-band commands to keep the monitor available for
out-of-band commands isn't really hard: just count the number of
"outstanding" in-band commands (commands sent minus replies received),
and if it exceeds the limit, hold back additional ones until it drops
below the limit again.
Note that we need to be careful pairing the suspend with a resume, or
else the monitor will hang, possibly forever. And here since we need to
make sure both:
(1) popping request from the req queue, and
(2) reading length of the req queue
will be in the same critical section, we let the pop function take the
corresponding queue lock when there is a request, then we release the
lock from the caller.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20181009062718.1914-2-peterx@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-10-09 09:27:13 +03:00
|
|
|
#define QMP_REQ_QUEUE_LEN_MAX 8
|
|
|
|
|
2020-01-29 13:22:36 +03:00
|
|
|
extern QemuOptsList qemu_mon_opts;
|
|
|
|
|
2020-10-05 18:58:44 +03:00
|
|
|
Monitor *monitor_cur(void);
|
2020-10-05 18:58:48 +03:00
|
|
|
Monitor *monitor_set_cur(Coroutine *co, Monitor *mon);
|
2015-03-06 22:01:05 +03:00
|
|
|
bool monitor_cur_is_qmp(void);
|
2010-02-11 19:05:43 +03:00
|
|
|
|
2018-03-09 11:59:50 +03:00
|
|
|
void monitor_init_globals(void);
|
2019-06-13 18:34:02 +03:00
|
|
|
void monitor_init_globals_core(void);
|
2020-02-24 17:30:05 +03:00
|
|
|
void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
|
2020-02-24 17:30:06 +03:00
|
|
|
void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp);
|
2020-02-24 17:30:07 +03:00
|
|
|
int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp);
|
2020-01-29 13:22:36 +03:00
|
|
|
int monitor_init_opts(QemuOpts *opts, Error **errp);
|
monitor: fix crash when leaving qemu with spice audio
Since aa5cb7f5e, the chardevs are being cleaned up when leaving
qemu. However, the monitor has still references to them, which may
lead to crashes when running atexit() and trying to send monitor
events:
#0 0x00007fffdb18f6f5 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007fffdb1912fa in __GI_abort () at abort.c:89
#2 0x0000555555c263e7 in error_exit (err=22, msg=0x555555d47980 <__func__.13537> "qemu_mutex_lock") at util/qemu-thread-posix.c:39
#3 0x0000555555c26488 in qemu_mutex_lock (mutex=0x5555567a2420) at util/qemu-thread-posix.c:66
#4 0x00005555558c52db in qemu_chr_fe_write (s=0x5555567a2420, buf=0x55555740dc40 "{\"timestamp\": {\"seconds\": 1470041716, \"microseconds\": 989699}, \"event\": \"SPICE_DISCONNECTED\", \"data\": {\"server\": {\"port\": \"5900\", \"family\": \"ipv4\", \"host\": \"127.0.0.1\"}, \"client\": {\"port\": \"40272\", \"f"..., len=240) at qemu-char.c:280
#5 0x0000555555787cad in monitor_flush_locked (mon=0x5555567bd9e0) at /home/elmarco/src/qemu/monitor.c:311
#6 0x0000555555787e46 in monitor_puts (mon=0x5555567bd9e0, str=0x5555567a44ef "") at /home/elmarco/src/qemu/monitor.c:353
#7 0x00005555557880fe in monitor_json_emitter (mon=0x5555567bd9e0, data=0x5555567c73a0) at /home/elmarco/src/qemu/monitor.c:401
#8 0x00005555557882d2 in monitor_qapi_event_emit (event=QAPI_EVENT_SPICE_DISCONNECTED, qdict=0x5555567c73a0) at /home/elmarco/src/qemu/monitor.c:472
#9 0x000055555578838f in monitor_qapi_event_queue (event=QAPI_EVENT_SPICE_DISCONNECTED, qdict=0x5555567c73a0, errp=0x7fffffffca88) at /home/elmarco/src/qemu/monitor.c:497
#10 0x0000555555c15541 in qapi_event_send_spice_disconnected (server=0x5555571139d0, client=0x5555570d0db0, errp=0x5555566c0428 <error_abort>) at qapi-event.c:1038
#11 0x0000555555b11bc6 in channel_event (event=3, info=0x5555570d6c00) at ui/spice-core.c:248
#12 0x00007fffdcc9983a in adapter_channel_event (event=3, info=0x5555570d6c00) at reds.c:120
#13 0x00007fffdcc99a25 in reds_handle_channel_event (reds=0x5555567a9d60, event=3, info=0x5555570d6c00) at reds.c:324
#14 0x00007fffdcc7d4c4 in main_dispatcher_self_handle_channel_event (self=0x5555567b28b0, event=3, info=0x5555570d6c00) at main-dispatcher.c:175
#15 0x00007fffdcc7d5b1 in main_dispatcher_channel_event (self=0x5555567b28b0, event=3, info=0x5555570d6c00) at main-dispatcher.c:194
#16 0x00007fffdcca7674 in reds_stream_push_channel_event (s=0x5555570d9910, event=3) at reds-stream.c:354
#17 0x00007fffdcca749b in reds_stream_free (s=0x5555570d9910) at reds-stream.c:323
#18 0x00007fffdccb5dad in snd_disconnect_channel (channel=0x5555576a89a0) at sound.c:229
#19 0x00007fffdccb9e57 in snd_detach_common (worker=0x555557739720) at sound.c:1589
#20 0x00007fffdccb9f0e in snd_detach_playback (sin=0x5555569fe3f8) at sound.c:1602
#21 0x00007fffdcca3373 in spice_server_remove_interface (sin=0x5555569fe3f8) at reds.c:3387
#22 0x00005555558ff6e2 in line_out_fini (hw=0x5555569fe370) at audio/spiceaudio.c:152
#23 0x00005555558f909e in audio_atexit () at audio/audio.c:1754
#24 0x00007fffdb1941e8 in __run_exit_handlers (status=0, listp=0x7fffdb5175d8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82
#25 0x00007fffdb194235 in __GI_exit (status=<optimized out>) at exit.c:104
#26 0x00007fffdb17b738 in __libc_start_main (main=0x5555558d7874 <main>, argc=67, argv=0x7fffffffcf48, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffcf38) at ../csu/libc-start.c:323
Add a monitor_cleanup() functions to remove all the monitors before
cleaning up the chardev. Note that we are "losing" some events that
used to be sent during atexit().
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20160801112343.29082-2-marcandre.lureau@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-08-01 14:23:42 +03:00
|
|
|
void monitor_cleanup(void);
|
2009-03-06 02:01:23 +03:00
|
|
|
|
2009-03-06 02:01:51 +03:00
|
|
|
int monitor_suspend(Monitor *mon);
|
2009-03-06 02:01:23 +03:00
|
|
|
void monitor_resume(Monitor *mon);
|
|
|
|
|
2012-09-20 18:50:32 +04:00
|
|
|
int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
|
2015-02-09 16:03:19 +03:00
|
|
|
int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
|
2009-07-22 12:11:41 +04:00
|
|
|
|
2022-09-29 14:42:12 +03:00
|
|
|
int monitor_puts(Monitor *mon, const char *str);
|
2019-04-17 22:06:36 +03:00
|
|
|
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
2022-02-20 19:39:25 +03:00
|
|
|
G_GNUC_PRINTF(2, 0);
|
|
|
|
int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
2023-01-24 15:19:41 +03:00
|
|
|
void monitor_printc(Monitor *mon, int ch);
|
2009-03-06 02:01:23 +03:00
|
|
|
void monitor_flush(Monitor *mon);
|
2020-10-05 18:58:42 +03:00
|
|
|
int monitor_set_cpu(Monitor *mon, int cpu_index);
|
2020-10-05 18:58:43 +03:00
|
|
|
int monitor_get_cpu_index(Monitor *mon);
|
2009-03-06 02:01:23 +03:00
|
|
|
|
2023-05-17 15:46:49 +03:00
|
|
|
int monitor_puts_locked(Monitor *mon, const char *str);
|
|
|
|
void monitor_flush_locked(Monitor *mon);
|
|
|
|
|
2020-10-27 20:03:03 +03:00
|
|
|
void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp);
|
|
|
|
|
2019-06-13 18:33:54 +03:00
|
|
|
void monitor_read_command(MonitorHMP *mon, int show_prompt);
|
|
|
|
int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
|
2011-09-02 21:34:50 +04:00
|
|
|
void *opaque);
|
2010-02-17 12:52:26 +03:00
|
|
|
|
2012-10-18 23:19:32 +04:00
|
|
|
AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
|
2022-11-04 19:06:59 +03:00
|
|
|
const char *opaque, Error **errp);
|
2024-06-17 21:57:24 +03:00
|
|
|
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp);
|
2014-08-17 13:45:17 +04:00
|
|
|
void monitor_fdset_dup_fd_remove(int dup_fd);
|
2012-08-15 00:43:47 +04:00
|
|
|
|
2021-06-24 13:38:32 +03:00
|
|
|
void monitor_register_hmp(const char *name, bool info,
|
|
|
|
void (*cmd)(Monitor *mon, const QDict *qdict));
|
2021-10-08 17:09:00 +03:00
|
|
|
void monitor_register_hmp_info_hrt(const char *name,
|
|
|
|
HumanReadableText *(*handler)(Error **errp));
|
2021-06-24 13:38:32 +03:00
|
|
|
|
2022-04-20 16:26:13 +03:00
|
|
|
int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
|
|
|
|
int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
|
|
|
|
|
2016-06-29 16:29:06 +03:00
|
|
|
#endif /* MONITOR_H */
|