monitor rework
cover monitor rework
It started with a tiny patch to improve the various gdb pass-through proposals that have been posted here before. But the deeper I dug, the more issues of the monitor terminal concept and implementation showed up. So this ended up as a major rework. I'm not claiming its perfect but I think it's a significant improvement. Major contributions are:
o complete fix for disk passwords
o non-VM-blocking password retrieval
o unlimited and fully decoupled monitor terminals
o monitor pass-through via gdb
o improved usability of mux'ed monitor terminals
I know some patches are huge and probably hard to review, and I already worked hard on splitting things up into reasonable functional chunks. But if someone finds a patch that could be broken into more useful pieces, just let me know.
Thanks in advance for any review comments!
Find the patches also at git://git.kiszka.org/qemu.git queues/monitor
Jan Kiszka (17):
block: Polish error handling of brdv_open2
block: Improve bdrv_iterate
block: Introduce bdrv_get_encrypted_filename
monitor: Report encrypted disks in snapshot mode
monitor: Don't change VNC server when disabled
char-mux: Use separate input buffers
monitor: Introduce monitor.h and readline.h
monitor: Rework initial disk password retrieval
monitor: Simplify password input mode
monitor: Rework terminal management
monitor: Drop banner hiding
monitor: Rework modal password input
monitor: Introduce ReadLineState
monitor: Decouple terminals
monitor: Improve mux'ed console experience
monitor: Introduce MONITOR_USE_READLINE flag
monitor: Pass-through for gdbstub
audio/audio.c | 6 +- audio/wavcapture.c | 20 +- block.c | 157 ++++++++------ block.h | 8 +- block_int.h | 1 + console.h | 27 --- disas.c | 14 +- gdbstub.c | 54 +++++- hw/i8259.c | 16 +- hw/pc.c | 8 +- hw/pci.c | 22 +- hw/slavio_intctl.c | 14 +- hw/sun4c_intctl.c | 12 +- hw/usb-msd.c | 10 +- hw/usb.h | 4 + migration-exec.c | 13 +- migration-tcp.c | 13 +- migration.c | 34 ++- migration.h | 4 +- monitor.c | 624 ++++++++++++++++++++++++++++++---------------------- monitor.h | 24 ++ net.c | 12 +- qemu-char.c | 40 +++-- qemu-char.h | 8 +- qemu-tool.c | 6 +- readline.c | 406 +++++++++++++++++----------------- readline.h | 47 ++++ savevm.c | 70 +++--- slirp/misc.c | 4 +- usb-linux.c | 28 ++- vl.c | 113 ++++------ vnc.c | 21 +- 32 files changed, 1038 insertions(+), 802 deletions(-) create mode 100644 monitor.h create mode 100644 readline.h
PATCH 1/17 block: Polish error handling of brdv_open2
Make sure that we always delete temporary disk images on error, remove obsolete malloc error checks and return proper error codes.
---
block.c | 46 +++++++++++++++++++++------------------------- 1 files changed, 21 insertions(+), 25 deletions(-)
block.c +21 -25
@@ -311,8 +311,6 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)int ret; bs =bdrv_new ("" ); -if (!bs) -return -ENOMEM ; ret =bdrv_open2 (bs, filename, flags |BDRV_O_FILE ,NULL );if (ret <0 ) {bdrv_delete (bs);
@@ -348,12 +346,10 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,/* if there is a backing file, use it */ bs1 =bdrv_new ("" ); -if (!bs1) { -return -ENOMEM ; - } -if (bdrv_open (bs1, filename,0 ) <0 ) { + ret =bdrv_open (bs1, filename,0 ); +if (ret <0 ) {bdrv_delete (bs1); -return -1 ; +return ret; } total_size =bdrv_getlength (bs1) >>SECTOR_BITS ;
@@ -371,9 +367,10 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,else realpath (filename, backing_filename); -if (bdrv_create (&bdrv_qcow2, tmp_filename, - total_size, backing_filename,0 ) <0 ) { -return -1 ; + ret =bdrv_create (&bdrv_qcow2, tmp_filename, + total_size, backing_filename,0 ); +if (ret <0 ) { +return ret; } filename = tmp_filename; bs->is_temporary =1 ;
@@ -382,14 +379,12 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,pstrcpy (bs->filename,sizeof (bs->filename), filename);if (flags &BDRV_O_FILE ) { drv =find_protocol (filename); -if (!drv) -return -ENOENT ; - }else { -if (!drv) { - drv =find_image_format (filename); -if (!drv) -return -1 ; - } + }else if (!drv) { + drv =find_image_format (filename); + } +if (!drv) { + ret = -ENOENT ; + goto unlink_and_fail; } bs->drv = drv; bs->opaque =qemu_mallocz (drv->instance_size);
@@ -408,6 +403,9 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,qemu_free (bs->opaque); bs->opaque =NULL ; bs->drv =NULL ; + unlink_and_fail: +if (bs->is_temporary) +unlink (filename);return ret; }if (drv->bdrv_getlength) {
@@ -421,15 +419,13 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,if (bs->backing_file[0 ] !='\0' ) {/* if there is a backing file, use it */ bs->backing_hd =bdrv_new ("" ); -if (!bs->backing_hd) { - fail: -bdrv_close (bs); -return -ENOMEM ; - }path_combine (backing_filename,sizeof (backing_filename), filename, bs->backing_file); -if (bdrv_open (bs->backing_hd, backing_filename, open_flags) <0 ) - goto fail; + ret =bdrv_open (bs->backing_hd, backing_filename, open_flags); +if (ret <0 ) { +bdrv_close (bs); +return ret; + } }/* call the change callback */
PATCH 2/17 block: Improve bdrv_iterate
In reply to Jan KiszkaMake bdrv_iterate more useful by passing the BlockDriverState to the iterator instead of the device name.
---
block.c | 4 ++-- block.h | 3 ++- monitor.c | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-)
block.c +2 -2
@@ -966,12 +966,12 @@ BlockDriverState *bdrv_find(const char *name)return NULL ; } -void bdrv_iterate (void (*it)(void *opaque,const char *name),void *opaque) +void bdrv_iterate (void (*it)(void *opaque,BlockDriverState *bs),void *opaque) {BlockDriverState *bs;for (bs = bdrv_first; bs !=NULL ; bs = bs->next) { -it (opaque, bs->device_name); +it (opaque, bs); } }
block.h +2 -1
@@ -141,7 +141,8 @@ void bdrv_set_change_cb(BlockDriverState *bs, void (*change_cb)(void *opaque), void *opaque);void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size);BlockDriverState *bdrv_find (const char *name); -void bdrv_iterate (void (*it)(void *opaque,const char *name),void *opaque); +void bdrv_iterate (void (*it)(void *opaque,BlockDriverState *bs), +void *opaque);int bdrv_is_encrypted (BlockDriverState *bs);int bdrv_set_key (BlockDriverState *bs,const char *key); void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
monitor.c +2 -1
@@ -2633,8 +2633,9 @@ static void file_completion(const char *input)closedir (ffs); } -static void block_completion_it (void *opaque,const char *name) +static void block_completion_it (void *opaque,BlockDriverState *bs) { +const char *name =bdrv_get_device_name (bs);const char *input = opaque; if (input[0] == '\0' ||
Re: [Qemu-devel] [PATCH 02/17] block: Improve bdrv_iterate
Quoted 12 lines · Jan Kiszka
Make
bdrv_iteratemore useful by passing the BlockDriverState to the iterator instead of the device name.Signed-off-by Jan Kiszka <[email protected]>---
block.c | 4 ++-- block.h | 3 ++- monitor.c | 3 ++-
$ grep -l bdrv_iterate *.c hw/*.c block.c monitor.c qemu-img.c vl.c
So this patch will break the build.
Regards,
Anthony Liguori
[Qemu-devel] Re: [PATCH 02/17] block: Improve bdrv_iterate
Quoted 14 lines · Anthony Liguori
Quoted 12 lines · Jan Kiszka
Make
bdrv_iteratemore useful by passing the BlockDriverState to the iterator instead of the device name.Signed-off-by Jan Kiszka <[email protected]>---
block.c | 4 ++-- block.h | 3 ++- monitor.c | 3 ++-
Quoted 7 lines
$ grep -l bdrv_iterate *.c hw/*.c block.c monitor.c qemu-img.c vl.cSo this patch will break the build.
$ grep -l "bdrv_iterate(" *.c hw/*.c
block.c
monitor.cUnless I'm totally blind, all users have been converted (there's only one). And it still builds for all targets and tools.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] Re: [PATCH 02/17] block: Improve bdrv_iterate
Quoted 7 lines · Jan Kiszka
$ grep -l "bdrv_iterate(" *.c hw/*.c block.c monitor.cUnless I'm totally blind, all users have been converted (there's only one). And it still builds for all targets and tools.
You're right. Sorry for the noise.
Regards,
Anthony Liguori
Quoted 3 lines
Jan
PATCH 3/17 block: Introduce bdrv_get_encrypted_filename
In reply to Jan KiszkaIntroduce bdrv_get_encrypted_filename service to allow more informative password prompting.
---
block.c | 10 ++++++++++ block.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
block.c +10 -0
@@ -1089,6 +1089,16 @@ void bdrv_info_stats (void) } } +const char *bdrv_get_encrypted_filename (BlockDriverState *bs) +{ +if (bs->backing_hd && bs->backing_hd->encrypted) +return bs->backing_file; +else if (bs->encrypted) +return bs->filename; +else +return NULL ; +} +void bdrv_get_backing_filename (BlockDriverState *bs,char *filename,int filename_size) {
block.h +1 -0
@@ -152,6 +152,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors);int bdrv_get_info (BlockDriverState *bs,BlockDriverInfo *bdi); +const char *bdrv_get_encrypted_filename (BlockDriverState *bs);void bdrv_get_backing_filename (BlockDriverState *bs,char *filename,int filename_size); int bdrv_snapshot_create(BlockDriverState *bs,
PATCH 4/17 monitor: Report encrypted disks in snapshot mode
In reply to Jan KiszkaIf the backing file is encrypted, 'info block' currently does not report the disk as encrypted. Fix this by used the standard API to check disk encryption mode.
---
block.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
block.c +1 -1
@@ -1056,7 +1056,7 @@ void bdrv_info(void) }term_printf (" ro=%d" , bs->read_only);term_printf (" drv=%s" , bs->drv->format_name); -if (bs->encrypted) +if (bdrv_is_encrypted (bs))term_printf (" encrypted" ); }else {term_printf (" [not inserted]" );
Re: [Qemu-devel] [PATCH 04/17] monitor: Report encrypted disks in snapshot mode
Quoted 15 lines · Jan Kiszka
If the backing file is encrypted, 'info block' currently does not report the disk as encrypted. Fix this by used the standard API to check disk encryption mode.
Signed-off-by Jan Kiszka <[email protected]>---
block.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)block.c +0
-0
block.c void bdrv_info(void) · line 1061
Quoted 7 lines
block.c +1
-1@@ -1056,7 +1056,7 @@ void bdrv_info(void) }term_printf (" ro=%d" , bs->read_only);term_printf (" drv=%s" , bs->drv->format_name); -if (bs->encrypted) +if (bdrv_is_encrypted (bs))term_printf (" encrypted" );
It's a bit more easily parsable if it's in the format encrypted=[1|0].
Regards,
Anthony Liguori
Quoted 7 lines
block.c +0
-0}else {term_printf(" [not inserted]");
[Qemu-devel] Re: [PATCH 04/17] monitor: Report encrypted disks in snapshot mode
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
If the backing file is encrypted, 'info block' currently does not report the disk as encrypted. Fix this by used the standard API to check disk encryption mode.
Signed-off-by Jan Kiszka <[email protected]>---
block.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 15 lines
block.c void bdrv_info(void) · line 1061
Quoted 12 lines
block.c +1
-1@@ -1056,7 +1056,7 @@ void bdrv_info(void) }term_printf (" ro=%d" , bs->read_only);term_printf (" drv=%s" , bs->drv->format_name); -if (bs->encrypted) +if (bdrv_is_encrypted (bs))term_printf (" encrypted" );It's a bit more easily parsable if it's in the format encrypted=[1|0].
OK, will change this.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
PATCH 5/17 monitor: Don't change VNC server when disabled
In reply to Jan KiszkaAvoid a segfault when the user issues 'change vnc' without having vnc enabled on startup.
---
vnc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
vnc.c +4 -0
@@ -2333,6 +2333,8 @@ void vnc_display_close(DisplayState *ds) {VncState *vs = ds ? (VncState *)ds->opaque : vnc_state; +if (!vs) +return ;if (vs->display) {qemu_free (vs->display); vs->display =NULL ;
@@ -2392,6 +2394,8 @@ int vnc_display_open(DisplayState *ds, const char *display)int tls =0 , x509 =0 ;#endif +if (!vnc_state) +return -1 ;vnc_display_close (ds);if (strcmp (display,"none" ) ==0 )return 0 ;
Re: [Qemu-devel] [PATCH 05/17] monitor: Don't change VNC server when disabled
Quoted 5 lines · Jan Kiszka
Avoid a segfault when the user issues 'change vnc' without having vnc enabled on startup.
Signed-off-by Jan Kiszka <[email protected]>
It'd be easier on me if you split out these sort of fixes from the rest of the series (that clearly has nothing to do with improving the monitor).
Regards,
Anthony Liguori
Quoted 32 lines
---
vnc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)vnc.c +4
-0@@ -2333,6 +2333,8 @@ void vnc_display_close(DisplayState *ds) {VncState *vs = ds ? (VncState *)ds->opaque : vnc_state; +if (!vs) +return ;if (vs->display) {qemu_free (vs->display); vs->display =NULL ;@@ -2392,6 +2394,8 @@ int vnc_display_open(DisplayState *ds, const char *display)int tls =0 , x509 =0 ;#endif +if (!vnc_state) +return -1 ;vnc_display_close (ds);if (strcmp (display,"none" ) ==0 )return 0 ;
[Qemu-devel] Re: [PATCH 05/17] monitor: Don't change VNC server when disabled
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Jan Kiszka
Avoid a segfault when the user issues 'change vnc' without having vnc enabled on startup.
Signed-off-by Jan Kiszka <[email protected]>It'd be easier on me if you split out these sort of fixes from the rest of the series (that clearly has nothing to do with improving the monitor).
You are free to apply this whenever you want, it has no dependency. I'll drop it from the series when it's no longer needed.
[ Small fixes unfortunately tend to fall through the cracks, so I chose this path. ]
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] Re: [PATCH 05/17] monitor: Don't change VNC server when disabled
Quoted 14 lines · Jan Kiszka
Quoted 11 lines · Anthony Liguori
Quoted 6 lines · Jan Kiszka
Avoid a segfault when the user issues 'change vnc' without having vnc enabled on startup.
Signed-off-by Jan Kiszka <[email protected]>It'd be easier on me if you split out these sort of fixes from the rest of the series (that clearly has nothing to do with improving the monitor).
Quoted 6 lines
You are free to apply this whenever you want, it has no dependency. I'll drop it from the series when it's no longer needed.
[ Small fixes unfortunately tend to fall through the cracks, so I chose this path. ]
From a purely pragmatic sense, my patch series scripts verify that all patches in the series are present as some folks have issues with mailers or SMTP delay. That means for a patch like this, I'd have to apply it by hand if I wanted to apply it in the absence of the rest of the series. That means I'll simply wait until the rest of the series is ready to go.
BTW, I've now got something locally tracking patches on the list so hopefully we're past the days of stuff slipping through the cracks. I have some old patches in my queue still that I've been waiting for other maintainers to ack/commit but rest assured, they haven't been forgotten :-)
Regards,
Anthony Liguori
Quoted 3 lines
Jan
PATCH 6/17 char-mux: Use separate input buffers
In reply to Jan KiszkaCurrently, the intermediate input buffer of mux'ed character devices records data across all sub-devices. This has the side effect that we easily leak data recorded over one sub-devices to another once we switch the focus. Avoid data loss and confusion by defining exclusive buffers.
Note: In contrast to the original author's claim, the buffering concept still breaks down when the fifo of the currently active sub-device is full. As we cannot accept futher data from this point on without risking to loose it, we will also miss escape sequences, just like without all that buffering. In short: There is no reliable escape sequence handling without infinite buffers or the risk of loosing some data.
---
qemu-char.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
qemu-char.c +14 -10
@@ -209,12 +209,15 @@ typedef struct {IOEventHandler *chr_event[MAX_MUX ];void *ext_opaque[MAX_MUX ];CharDriverState *drv; -unsigned char buffer[MUX_BUFFER_SIZE ]; -int prod; -int cons;int mux_cnt;int term_got_escape;int max_size; +/* Intermediate input buffer allows to catch escape sequences even if the +currently active device is not accepting any input - but only until it +is full as well. */ +unsigned char buffer[MAX_MUX ][MUX_BUFFER_SIZE ]; +int prod[MAX_MUX ]; +int cons[MAX_MUX ]; } MuxDriver;
@@ -344,11 +347,11 @@ static void mux_chr_accept_input(CharDriverState *chr)int m = chr->focus;MuxDriver *d = chr->opaque; -while (d->prod != d->cons && +while (d->prod[m] != d->cons[m] && d->chr_can_read[m] && d->chr_can_read[m](d->ext_opaque[m])) { d->chr_read[m](d->ext_opaque[m], - &d->buffer[d->cons++ &MUX_BUFFER_MASK ],1 ); + &d->buffer[m][d->cons[m]++ &MUX_BUFFER_MASK ],1 ); } }
@@ -356,11 +359,12 @@ static int mux_chr_can_read(void *opaque) {CharDriverState *chr = opaque;MuxDriver *d = chr->opaque; +int m = chr->focus; -if ((d->prod - d->cons) <MUX_BUFFER_SIZE ) +if ((d->prod[m] - d->cons[m]) <MUX_BUFFER_SIZE )return 1 ; -if (d->chr_can_read[chr->focus]) -return d->chr_can_read[chr->focus](d->ext_opaque[chr->focus]); +if (d->chr_can_read[m]) +return d->chr_can_read[m](d->ext_opaque[m]);return 0 ; }
@@ -375,12 +379,12 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size)for (i =0 ; i < size; i++)if (mux_proc_byte (chr, d, buf[i])) { -if (d->prod == d->cons && +if (d->prod[m] == d->cons[m] && d->chr_can_read[m] && d->chr_can_read[m](d->ext_opaque[m])) d->chr_read[m](d->ext_opaque[m], &buf[i],1 );else - d->buffer[d->prod++ &MUX_BUFFER_MASK ] = buf[i]; + d->buffer[m][d->prod[m]++ &MUX_BUFFER_MASK ] = buf[i]; } }
PATCH 7/17 monitor: Introduce monitor.h and readline.h
In reply to Jan KiszkaPush monitor-related prototypes from console.h to a new monitor.h and update users. Do the same for readline types and function prototypes. To clarify that term_printf & friends work against the monitor terminal, change the prefix of those functions to 'monitor_'. This patch comes without functional changes.
---
audio/audio.c | 6 + audio/wavcapture.c | 20 ++- block.c | 62 +++++------ console.h | 27 ----- disas.c | 14 +- hw/i8259.c | 16 +-- hw/pc.c | 8 + hw/pci.c | 22 ++-- hw/slavio_intctl.c | 14 +- hw/sun4c_intctl.c | 12 +- migration-exec.c | 2 migration-tcp.c | 2 migration.c | 18 ++- monitor.c | 300 +++++++++++++++++++++++++++------------------------- monitor.h | 21 ++++ net.c | 12 +- qemu-char.c | 3 - qemu-tool.c | 6 + readline.c | 29 +++-- readline.h | 14 ++ savevm.c | 70 ++++++------ slirp/misc.c | 4 - usb-linux.c | 28 +++-- vl.c | 33 +++--- vnc.c | 17 ++- 25 files changed, 392 insertions(+), 368 deletions(-) create mode 100644 monitor.h create mode 100644 readline.h
audio/audio.c +3 -3
@@ -23,7 +23,7 @@*/ #include "hw/hw.h" #include "audio.h" -#include "console.h" +#include "monitor.h" #include "qemu-timer.h" #include "sysemu.h"
@@ -328,10 +328,10 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap) {if (conf.log_to_monitor) {if (cap) { -term_printf ("%s: " , cap); +monitor_printf ("%s: " , cap); } -term_vprintf (fmt, ap); +monitor_vprintf (fmt, ap); }else {if (cap) {
audio/wavcapture.c +10 -10
@@ -1,5 +1,5 @@#include "hw/hw.h" -#include "console.h" +#include "monitor.h" #include "audio.h" typedef struct {
@@ -71,9 +71,9 @@ static void wav_capture_info (void *opaque)WAVState *wav = opaque;char *path = wav->path; -term_printf ("Capturing audio(%d,%d,%d) to %s: %d bytes\n" , - wav->freq, wav->bits, wav->nchannels, - path ? path :"<not available>" , wav->bytes); +monitor_printf ("Capturing audio(%d,%d,%d) to %s: %d bytes\n" , + wav->freq, wav->bits, wav->nchannels, + path ? path :"<not available>" , wav->bytes); }static struct capture_ops wav_capture_ops = {
@@ -97,13 +97,13 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,CaptureVoiceOut *cap;if (bits !=8 && bits !=16 ) { -term_printf ("incorrect bit count %d, must be 8 or 16\n" , bits); +monitor_printf ("incorrect bit count %d, must be 8 or 16\n" , bits);return -1 ; }if (nchannels !=1 && nchannels !=2 ) { -term_printf ("incorrect channel count %d, must be 1 or 2\n" , - nchannels); +monitor_printf ("incorrect channel count %d, must be 1 or 2\n" , + nchannels);return -1 ; }
@@ -131,8 +131,8 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, wav->f =qemu_fopen (path,"wb" );if (!wav->f) { -term_printf ("Failed to open wave file `%s'\nReason: %s\n" , - path,strerror (errno)); +monitor_printf ("Failed to open wave file `%s'\nReason: %s\n" , + path,strerror (errno));qemu_free (wav);return -1 ; }
@@ -146,7 +146,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, cap =AUD_add_capture (NULL , &as, &ops, wav);if (!cap) { -term_printf ("Failed to add audio capture\n" ); +monitor_printf ("Failed to add audio capture\n" );qemu_free (wav->path);qemu_fclose (wav->f);qemu_free (wav);
block.c +31 -31
96 lines not on this page · raw message
console.h +0 -27
@@ -294,31 +294,4 @@ void curses_display_init(DisplayState *ds, int full_screen);/* x_keymap.c */ extern uint8_t _translate_keycode (const int key); - -/* FIXME: term_printf et al should probably go elsewhere so everything -does not need to include console.h */ -/* monitor.c */ -void monitor_init (CharDriverState *hd,int show_banner); -void term_puts (const char *str); -void term_vprintf (const char *fmt,va_list ap); -void term_printf (const char *fmt, ...) __attribute__ ((__format__ (__printf__,1 ,2 ))); -void term_print_filename (const char *filename); -void term_flush (void ); -void term_print_help (void ); -void monitor_readline (const char *prompt,int is_password, -char *buf,int buf_size); -void monitor_suspend (void ); -void monitor_resume (void ); - -/* readline.c */ -typedef void ReadLineFunc (void *opaque,const char *str); - -extern int completion_index; -void add_completion (const char *str); -void readline_handle_byte (int ch); -void readline_find_completion (const char *cmdline); -const char *readline_get_history (unsigned int index); -void readline_start (const char *prompt,int is_password, -ReadLineFunc *readline_func,void *opaque); -#endif
disas.c +7 -7
@@ -308,8 +308,8 @@ const char *lookup_symbol(target_ulong orig_addr)#if !defined(CONFIG_USER_ONLY ) -void term_vprintf (const char *fmt,va_list ap); -void term_printf (const char *fmt, ...); +void monitor_vprintf (const char *fmt,va_list ap); +void monitor_printf (const char *fmt, ...);static int monitor_disas_is_physical;static CPUState *monitor_disas_env;
@@ -330,7 +330,7 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...) {va_list ap;va_start (ap, fmt); -term_vprintf (fmt, ap); +monitor_vprintf (fmt, ap);va_end (ap);return 0 ; }
@@ -388,15 +388,15 @@ void monitor_disas(CPUState *env, print_insn = print_insn_little_mips;#endif #else -term_printf ("0x" TARGET_FMT_lx -": Asm output not supported on this arch\n" , pc); +monitor_printf ("0x" TARGET_FMT_lx +": Asm output not supported on this arch\n" , pc);return ;#endif for (i =0 ; i < nb_insn; i++) { -term_printf ("0x" TARGET_FMT_lx": " , pc); +monitor_printf ("0x" TARGET_FMT_lx": " , pc); count =print_insn (pc, &disasm_info); -term_printf ("\n" ); +monitor_printf ("\n" );if (count <0 )break ; pc += count;
hw/i8259.c +8 -8
@@ -24,7 +24,7 @@#include "hw.h" #include "pc.h" #include "isa.h" -#include "console.h" +#include "monitor.h" /* debug PIC */ //#define DEBUG_PIC
@@ -521,26 +521,26 @@ void pic_info(void)for (i=0 ;i<2 ;i++) { s = &isa_pic->pics[i]; -term_printf ("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n" , - i, s->irr, s->imr, s->isr, s->priority_add, - s->irq_base, s->read_reg_select, s->elcr, - s->special_fully_nested_mode); +monitor_printf ("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n" , + i, s->irr, s->imr, s->isr, s->priority_add, + s->irq_base, s->read_reg_select, s->elcr, + s->special_fully_nested_mode); } }void irq_info (void ) {#ifndef DEBUG_IRQ_COUNT -term_printf ("irq statistic code not compiled.\n" ); +monitor_printf ("irq statistic code not compiled.\n" );#else int i;int64_t count; -term_printf ("IRQ statistics:\n" ); +monitor_printf ("IRQ statistics:\n" );for (i =0 ; i <16 ; i++) { count = irq_count[i];if (count >0 ) -term_printf ("%2d: %" PRId64"\n" , i, count); +monitor_printf ("%2d: %" PRId64"\n" , i, count); }#endif }
hw/pc.c +4 -4
@@ -31,7 +31,7 @@#include "net.h" #include "smbus.h" #include "boards.h" -#include "console.h" +#include "monitor.h" #include "fw_cfg.h" #include "virtio-blk.h" #include "virtio-balloon.h"
@@ -211,14 +211,14 @@ static int pc_boot_set(void *opaque, const char *boot_device) nbds =strlen (boot_device);if (nbds >PC_MAX_BOOT_DEVICES ) { -term_printf ("Too many boot devices for PC\n" ); +monitor_printf ("Too many boot devices for PC\n" );return (1 ); }for (i =0 ; i < nbds; i++) { bds[i] =boot_device2nibble (boot_device[i]);if (bds[i] ==0 ) { -term_printf ("Invalid boot device for PC: '%c'\n" , - boot_device[i]); +monitor_printf ("Invalid boot device for PC: '%c'\n" , + boot_device[i]);return (1 ); } }
hw/pci.c +11 -11
@@ -23,7 +23,7 @@*/ #include "hw.h" #include "pci.h" -#include "console.h" +#include "monitor.h" #include "net.h" #include "virtio-net.h"
@@ -588,37 +588,37 @@ static void pci_info_device(PCIDevice *d)PCIIORegion *r;const pci_class_desc *desc; -term_printf (" Bus %2d, device %3d, function %d:\n" , +monitor_printf (" Bus %2d, device %3d, function %d:\n" , d->bus->bus_num, d->devfn >>3 , d->devfn &7 ); class =le16_to_cpu (*((uint16_t *)(d->config +PCI_CLASS_DEVICE ))); -term_printf (" " ); +monitor_printf (" " ); desc = pci_class_descriptions;while (desc->desc && class != desc->class) desc++;if (desc->desc) { -term_printf ("%s" , desc->desc); +monitor_printf ("%s" , desc->desc); }else { -term_printf ("Class %04x" , class); +monitor_printf ("Class %04x" , class); } -term_printf (": PCI device %04x:%04x\n" , +monitor_printf (": PCI device %04x:%04x\n" ,le16_to_cpu (*((uint16_t *)(d->config +PCI_VENDOR_ID ))),le16_to_cpu (*((uint16_t *)(d->config +PCI_DEVICE_ID ))));if (d->config[PCI_INTERRUPT_PIN ] !=0 ) { -term_printf (" IRQ %d.\n" , d->config[PCI_INTERRUPT_LINE ]); +monitor_printf (" IRQ %d.\n" , d->config[PCI_INTERRUPT_LINE ]); }if (class ==0x0604 ) { -term_printf (" BUS %d.\n" , d->config[0x19 ]); +monitor_printf (" BUS %d.\n" , d->config[0x19 ]); }for (i =0 ;i <PCI_NUM_REGIONS ; i++) { r = &d->io_regions[i];if (r->size !=0 ) { -term_printf (" BAR%d: " , i); +monitor_printf (" BAR%d: " , i);if (r->type &PCI_ADDRESS_SPACE_IO ) { -term_printf ("I/O at 0x%04x [0x%04x].\n" , +monitor_printf ("I/O at 0x%04x [0x%04x].\n" , r->addr, r->addr + r->size -1 ); }else { -term_printf ("32 bit memory at 0x%08x [0x%08x].\n" , +monitor_printf ("32 bit memory at 0x%08x [0x%08x].\n" , r->addr, r->addr + r->size -1 ); } }
hw/slavio_intctl.c +7 -7
@@ -23,7 +23,7 @@*/ #include "hw.h" #include "sun4m.h" -#include "console.h" +#include "monitor.h" //#define DEBUG_IRQ_COUNT //#define DEBUG_IRQ
@@ -225,27 +225,27 @@ void slavio_pic_info(void *opaque)int i;for (i =0 ; i <MAX_CPUS ; i++) { -term_printf ("per-cpu %d: pending 0x%08x\n" , i, +monitor_printf ("per-cpu %d: pending 0x%08x\n" , i, s->slaves[i]->intreg_pending); } -term_printf ("master: pending 0x%08x, disabled 0x%08x\n" , - s->intregm_pending, s->intregm_disabled); +monitor_printf ("master: pending 0x%08x, disabled 0x%08x\n" , + s->intregm_pending, s->intregm_disabled); }void slavio_irq_info (void *opaque) {#ifndef DEBUG_IRQ_COUNT -term_printf ("irq statistic code not compiled.\n" ); +monitor_printf ("irq statistic code not compiled.\n" );#else SLAVIO_INTCTLState *s = opaque;int i;int64_t count; -term_printf ("IRQ statistics:\n" ); +monitor_printf ("IRQ statistics:\n" );for (i =0 ; i <32 ; i++) { count = s->irq_count[i];if (count >0 ) -term_printf ("%2d: %" PRId64"\n" , i, count); +monitor_printf ("%2d: %" PRId64"\n" , i, count); }#endif }
hw/sun4c_intctl.c +6 -6
@@ -23,7 +23,7 @@*/ #include "hw.h" #include "sun4m.h" -#include "console.h" +#include "monitor.h" //#define DEBUG_IRQ_COUNT //#define DEBUG_IRQ
@@ -94,22 +94,22 @@ void sun4c_pic_info(void *opaque) {Sun4c_INTCTLState *s = opaque; -term_printf ("master: pending 0x%2.2x, enabled 0x%2.2x\n" , s->pending, - s->reg); +monitor_printf ("master: pending 0x%2.2x, enabled 0x%2.2x\n" , s->pending, + s->reg); }void sun4c_irq_info (void *opaque) {#ifndef DEBUG_IRQ_COUNT -term_printf ("irq statistic code not compiled.\n" ); +monitor_printf ("irq statistic code not compiled.\n" );#else Sun4c_INTCTLState *s = opaque;int64_t count; -term_printf ("IRQ statistics:\n" ); +monitor_printf ("IRQ statistics:\n" ); count = s->irq_count[i];if (count >0 ) -term_printf ("%2d: %" PRId64"\n" , i, count); +monitor_printf ("%2d: %" PRId64"\n" , i, count);#endif }
migration-exec.c +1 -1
@@ -18,7 +18,7 @@#include "migration.h" #include "qemu-char.h" #include "sysemu.h" -#include "console.h" +#include "monitor.h" #include "buffered_file.h" #include "block.h"
migration-tcp.c +1 -1
@@ -16,7 +16,7 @@#include "migration.h" #include "qemu-char.h" #include "sysemu.h" -#include "console.h" +#include "monitor.h" #include "buffered_file.h" #include "block.h"
migration.c +9 -9
@@ -13,7 +13,7 @@#include "qemu-common.h" #include "migration.h" -#include "console.h" +#include "monitor.h" #include "buffered_file.h" #include "sysemu.h" #include "block.h"
@@ -60,10 +60,10 @@ void do_migrate(int detach, const char *uri) s =exec_start_outgoing_migration (p, max_throttle, detach);#endif else - term_printf("unknown migration protocol: %s\n", uri); + monitor_printf("unknown migration protocol: %s\n", uri);if (s ==NULL ) -term_printf ("migration failed\n" ); +monitor_printf ("migration failed\n" );else {if (current_migration) current_migration->release (current_migration);
@@ -103,21 +103,21 @@ void do_migrate_set_speed(const char *value)void do_info_migrate (void ) {MigrationState *s = current_migration; - +if (s) { -term_printf ("Migration status: " ); +monitor_printf ("Migration status: " );switch (s->get_status (s)) {case MIG_STATE_ACTIVE : -term_printf ("active\n" ); +monitor_printf ("active\n" );break ;case MIG_STATE_COMPLETED : -term_printf ("completed\n" ); +monitor_printf ("completed\n" );break ;case MIG_STATE_ERROR : -term_printf ("failed\n" ); +monitor_printf ("failed\n" );break ;case MIG_STATE_CANCELLED : -term_printf ("cancelled\n" ); +monitor_printf ("cancelled\n" );break ; } }
monitor.c +155 -145
756 lines not on this page · raw message
monitor.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef MONITOR_H +#define MONITOR_H + +#include "qemu-char.h" +#include "block.h" + +void monitor_init (CharDriverState *hd,int show_banner); +void monitor_readline (const char *prompt,int is_password, +char *buf,int buf_size); +void monitor_suspend (void ); +void monitor_resume (void ); + +int monitor_read_bdrv_key (BlockDriverState *bs,const char *name); + +void monitor_vprintf (const char *fmt,va_list ap); +void monitor_printf (const char *fmt, ...) + __attribute__ ((__format__ (__printf__,1 ,2 ))); +void monitor_print_filename (const char *filename); +void monitor_flush (void ); + +#endif /* !MONITOR_H */
net.c +6 -6
@@ -23,7 +23,7 @@*/ #include "qemu-common.h" #include "net.h" -#include "console.h" +#include "monitor.h" #include "sysemu.h" #include "qemu-timer.h" #include "qemu-char.h"
@@ -1727,9 +1727,9 @@ void do_info_network(void)VLANClientState *vc;for (vlan = first_vlan; vlan !=NULL ; vlan = vlan->next) { -term_printf ("VLAN %d devices:\n" , vlan->id); +monitor_printf ("VLAN %d devices:\n" , vlan->id);for (vc = vlan->first_client; vc !=NULL ; vc = vc->next) -term_printf (" %s: %s\n" , vc->name, vc->info_str); +monitor_printf (" %s: %s\n" , vc->name, vc->info_str); } }
@@ -1745,7 +1745,7 @@ int do_set_link(const char *name, const char *up_or_down) done:if (!vc) { -term_printf ("could not find network device '%s'" , name); +monitor_printf ("could not find network device '%s'" , name);return 0 ; }
@@ -1754,8 +1754,8 @@ done:else if (strcmp (up_or_down,"down" ) ==0 ) vc->link_down =1 ;else -term_printf ("invalid link status '%s'; only 'up' or 'down' valid\n" , - up_or_down); +monitor_printf ("invalid link status '%s'; only 'up' or 'down' valid\n" , + up_or_down);if (vc->link_status_changed) vc->link_status_changed (vc);
qemu-char.c +2 -1
@@ -23,6 +23,7 @@*/ #include "qemu-common.h" #include "net.h" +#include "monitor.h" #include "console.h" #include "sysemu.h" #include "qemu-timer.h"
@@ -2174,6 +2175,6 @@ void qemu_chr_info(void)CharDriverState *chr; TAILQ_FOREACH(chr, &chardevs, next) { -term_printf ("%s: filename=%s\n" , chr->label, chr->filename); +monitor_printf ("%s: filename=%s\n" , chr->label, chr->filename); } }
qemu-tool.c +3 -3
@@ -12,7 +12,7 @@*/ #include "qemu-common.h" -#include "console.h" +#include "monitor.h" #include "sysemu.h" #include "qemu-timer.h"
@@ -30,11 +30,11 @@ void qemu_service_io(void) { } -void term_printf (const char *fmt, ...) +void monitor_printf (const char *fmt, ...) { } -void term_print_filename (const char *filename) +void monitor_print_filename (const char *filename) { }
readline.c +15 -14
@@ -22,7 +22,8 @@* THE SOFTWARE. */ #include "qemu-common.h" -#include "console.h" +#include "monitor.h" +#include "readline.h" #define TERM_CMD_BUF_SIZE 4095#define TERM_MAX_CMDS 64
@@ -59,8 +60,8 @@ static void *term_readline_opaque;static void term_show_prompt2 (void ) { -term_printf ("%s" , term_prompt); -term_flush (); +monitor_printf ("%s" , term_prompt); +monitor_flush (); term_last_cmd_buf_index =0 ; term_last_cmd_buf_size =0 ; term_esc_state =IS_NORM ;
@@ -81,17 +82,17 @@ static void term_update(void)if (term_cmd_buf_size != term_last_cmd_buf_size ||memcmp (term_cmd_buf, term_last_cmd_buf, term_cmd_buf_size) !=0 ) {for (i =0 ; i < term_last_cmd_buf_index; i++) { -term_printf ("\033[D" ); +monitor_printf ("\033[D" ); } term_cmd_buf[term_cmd_buf_size] ='\0' ;if (term_is_password) { len =strlen (term_cmd_buf);for (i =0 ; i < len; i++) -term_printf ("*" ); +monitor_printf ("*" ); }else { -term_printf ("%s" , term_cmd_buf); +monitor_printf ("%s" , term_cmd_buf); } -term_printf ("\033[K" ); +monitor_printf ("\033[K" );memcpy (term_last_cmd_buf, term_cmd_buf, term_cmd_buf_size); term_last_cmd_buf_size = term_cmd_buf_size; term_last_cmd_buf_index = term_cmd_buf_size;
@@ -100,17 +101,17 @@ static void term_update(void) delta = term_cmd_buf_index - term_last_cmd_buf_index;if (delta >0 ) {for (i =0 ;i < delta; i++) { -term_printf ("\033[C" ); +monitor_printf ("\033[C" ); } }else { delta = -delta;for (i =0 ;i < delta; i++) { -term_printf ("\033[D" ); +monitor_printf ("\033[D" ); } } term_last_cmd_buf_index = term_cmd_buf_index; } -term_flush (); +monitor_flush (); }static void term_insert_char (int ch)
@@ -324,7 +325,7 @@ static void term_completion(void)if (len >0 && completions[0 ][len -1 ] !='/' )term_insert_char (' ' ); }else { -term_printf ("\n" ); +monitor_printf ("\n" ); max_width =0 ; max_prefix =0 ;for (i =0 ; i < nb_completions; i++) {
@@ -354,9 +355,9 @@ static void term_completion(void) nb_cols =80 / max_width; j =0 ;for (i =0 ; i < nb_completions; i++) { -term_printf ("%-*s" , max_width, completions[i]); +monitor_printf ("%-*s" , max_width, completions[i]);if (++j == nb_cols || i == (nb_completions -1 )) { -term_printf ("\n" ); +monitor_printf ("\n" ); j =0 ; } }
@@ -387,7 +388,7 @@ void readline_handle_byte(int ch) term_cmd_buf[term_cmd_buf_size] ='\0' ;if (!term_is_password)term_hist_add (term_cmd_buf); -term_printf ("\n" ); +monitor_printf ("\n" ); term_cmd_buf_index =0 ; term_cmd_buf_size =0 ; term_last_cmd_buf_index =0 ;
readline.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef READLINE_H +#define READLINE_H + +typedef void ReadLineFunc (void *opaque,const char *str); + +extern int completion_index; +void add_completion (const char *str); +void readline_handle_byte (int ch); +void readline_find_completion (const char *cmdline); +const char *readline_get_history (unsigned int index); +void readline_start (const char *prompt,int is_password, +ReadLineFunc *readline_func,void *opaque); + +#endif /* !READLINE_H */
savevm.c +35 -35
181 lines not on this page · raw message
slirp/misc.c +2 -2
@@ -557,14 +557,14 @@ relay(s)#endif #ifdef CONFIG_QEMU -extern void term_vprintf (const char *fmt,va_list ap); +extern void monitor_vprintf (const char *fmt,va_list ap);void lprint (const char *format, ...) {va_list args;va_start (args, format); -term_vprintf (format, args); +monitor_vprintf (format, args);va_end (args); }#else
usb-linux.c +15 -13
@@ -32,7 +32,7 @@#include "qemu-common.h" #include "qemu-timer.h" -#include "console.h" +#include "monitor.h" #include <dirent.h> #include <sys/ioctl.h>
@@ -998,7 +998,8 @@ USBDevice *usb_host_device_open(const char *devname)return NULL ;if (hostdev_find (bus_num, addr)) { -term_printf ("husb: host usb device %d.%d is already open\n" , bus_num, addr); +monitor_printf ("husb: host usb device %d.%d is already open\n" , + bus_num, addr);return NULL ; }
@@ -1161,7 +1162,7 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_ffclose (f); ret =1 ; }else { -term_printf ("husb: could not open %s\n" , filename); +monitor_printf ("husb: could not open %s\n" , filename); }return ret;
@@ -1292,14 +1293,15 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) } found_devices:if (!usb_fs_type) { -term_printf ("husb: unable to access USB devices\n" ); +monitor_printf ("husb: unable to access USB devices\n" );return -ENOENT ; }/* the module setting (used later for opening devices) */ usb_host_device_path =qemu_mallocz (strlen (devpath)+1 );strcpy (usb_host_device_path, devpath); -term_printf ("husb: using %s file-system with %s\n" , fs_type[usb_fs_type], usb_host_device_path); +monitor_printf ("husb: using %s file-system with %s\n" , + fs_type[usb_fs_type], usb_host_device_path); }switch (usb_fs_type) {
@@ -1623,17 +1625,17 @@ static void usb_info_device(int bus_num, int addr, int class_id,break ; } -term_printf (" Device %d.%d, speed %s Mb/s\n" , +monitor_printf (" Device %d.%d, speed %s Mb/s\n" , bus_num, addr, speed_str); class_str =usb_class_str (class_id);if (class_str) -term_printf (" %s:" , class_str); +monitor_printf (" %s:" , class_str);else -term_printf (" Class %02x:" , class_id); -term_printf (" USB device %04x:%04x" , vendor_id, product_id); +monitor_printf (" Class %02x:" , class_id); +monitor_printf (" USB device %04x:%04x" , vendor_id, product_id);if (product_name[0 ] !='\0' ) -term_printf (", %s" , product_name); -term_printf ("\n" ); +monitor_printf (", %s" , product_name); +monitor_printf ("\n" ); } static int usb_host_info_device(void *opaque, int bus_num, int addr,
@@ -1670,13 +1672,13 @@ void usb_host_info(void)usb_host_scan (NULL , usb_host_info_device);if (usb_auto_filter) -term_printf (" Auto filters:\n" ); +monitor_printf (" Auto filters:\n" );for (f = usb_auto_filter; f; f = f->next) {char bus[10 ], addr[10 ], vid[10 ], pid[10 ];dec2str (f->bus_num, bus,sizeof (bus));dec2str (f->addr, addr,sizeof (addr));hex2str (f->vendor_id, vid,sizeof (vid));hex2str (f->product_id, pid,sizeof (pid)); -term_printf (" Device %s.%s ID %s:%s\n" , bus, addr, vid, pid); +monitor_printf (" Device %s.%s ID %s:%s\n" , bus, addr, vid, pid); } }
vl.c +17 -16
@@ -31,6 +31,7 @@#include "hw/baum.h" #include "hw/bt.h" #include "net.h" +#include "monitor.h" #include "console.h" #include "sysemu.h" #include "gdbstub.h"
@@ -651,16 +652,16 @@ void do_info_mice(void)int index =0 ;if (!qemu_put_mouse_event_head) { -term_printf ("No mouse devices connected\n" ); +monitor_printf ("No mouse devices connected\n" );return ; } -term_printf ("Mouse devices available:\n" ); +monitor_printf ("Mouse devices available:\n" ); cursor = qemu_put_mouse_event_head;while (cursor !=NULL ) { -term_printf ("%c Mouse #%d: %s\n" , - (cursor == qemu_put_mouse_event_current ?'*' :' ' ), - index, cursor->qemu_put_mouse_event_name); +monitor_printf ("%c Mouse #%d: %s\n" , + (cursor == qemu_put_mouse_event_current ?'*' :' ' ), + index, cursor->qemu_put_mouse_event_name); index++; cursor = cursor->next; }
@@ -672,7 +673,7 @@ void do_mouse_set(int index)int i =0 ;if (!qemu_put_mouse_event_head) { -term_printf ("No mouse devices connected\n" ); +monitor_printf ("No mouse devices connected\n" );return ; }
@@ -685,7 +686,7 @@ void do_mouse_set(int index)if (cursor !=NULL ) qemu_put_mouse_event_current = cursor;else -term_printf ("Mouse at given index not found\n" ); +monitor_printf ("Mouse at given index not found\n" ); }/* compute with 96 bit intermediate result: (a*b)/c */
@@ -2712,7 +2713,7 @@ void usb_info(void)const char *speed_str;if (!usb_enabled) { -term_printf ("USB support not enabled\n" ); +monitor_printf ("USB support not enabled\n" );return ; }
@@ -2734,8 +2735,8 @@ void usb_info(void) speed_str ="?" ;break ; } -term_printf (" Device %d.%d, Speed %s Mb/s, Product %s\n" , -0 , dev->addr, speed_str, dev->devname); +monitor_printf (" Device %d.%d, Speed %s Mb/s, Product %s\n" , +0 , dev->addr, speed_str, dev->devname); } }
@@ -2773,12 +2774,12 @@ void pcmcia_info(void) {struct pcmcia_socket_entry_s *iter;if (!pcmcia_sockets) -term_printf ("No PCMCIA sockets\n" ); +monitor_printf ("No PCMCIA sockets\n" );for (iter = pcmcia_sockets; iter; iter = iter->next) -term_printf ("%s: %s\n" , iter->socket->slot_string, - iter->socket->attached ? iter->socket->card_string : -"Empty" ); +monitor_printf ("%s: %s\n" , iter->socket->slot_string, + iter->socket->attached ? iter->socket->card_string : +"Empty" ); }/***********************************************************/
@@ -4272,12 +4273,12 @@ int qemu_key_check(BlockDriverState *bs, const char *name)if (!bdrv_is_encrypted (bs))return 0 ; -term_printf ("%s is encrypted.\n" , name); +monitor_printf ("%s is encrypted.\n" , name);for (i =0 ; i <3 ; i++) {monitor_readline ("Password: " ,1 , password,sizeof (password));if (bdrv_set_key (bs, password) ==0 )return 0 ; -term_printf ("invalid password\n" ); +monitor_printf ("invalid password\n" ); }return -EPERM ; }
vnc.c +9 -8
@@ -24,6 +24,7 @@*/ #include "qemu-common.h" +#include "monitor.h" #include "console.h" #include "sysemu.h" #include "qemu_socket.h"
@@ -157,16 +158,16 @@ static DisplayChangeListener *dcl;void do_info_vnc (void ) {if (vnc_state ==NULL || vnc_state->display ==NULL ) -term_printf ("VNC server disabled\n" ); +monitor_printf ("VNC server disabled\n" );else { -term_printf ("VNC server active on: " ); -term_print_filename (vnc_state->display); -term_printf ("\n" ); +monitor_printf ("VNC server active on: " ); +monitor_print_filename (vnc_state->display); +monitor_printf ("\n" );if (vnc_state->csock ==-1 ) -term_printf ("No client connected\n" ); +monitor_printf ("No client connected\n" );else -term_printf ("Client connected\n" ); +monitor_printf ("Client connected\n" ); } }
@@ -776,7 +777,7 @@ static void audio_add(VncState *vs)struct audio_capture_ops ops;if (vs->audio_cap) { -term_printf ("audio already running\n" ); +monitor_printf ("audio already running\n" );return ; }
@@ -786,7 +787,7 @@ static void audio_add(VncState *vs) vs->audio_cap =AUD_add_capture (NULL , &vs->as, &ops, vs);if (!vs->audio_cap) { -term_printf ("Failed to add audio capture\n" ); +monitor_printf ("Failed to add audio capture\n" ); } }
PATCH 8/17 monitor: Rework initial disk password retrieval
In reply to Jan KiszkaReading the passwords for encrypted hard disks during early startup is broken (I guess for quiet a while now):
- No monitor terminal is ready for input at this point
- Forcing all mux'ed terminals into monitor mode can confuse other users of that channels
To overcome these issues and to lay the ground for a clean decoupling of monitor terminals, this patch changes the initial password retrieval as follows:
- Prevent autostart if there is some encrypted disk
- Once the user tries to resume the VM, prompt for all missing passwords
- Only resume if all passwords were accepted
---
block.c | 14 ++++++++++- block.h | 4 ++- block_int.h | 1 + hw/usb-msd.c | 6 ++--- hw/usb.h | 5 +++- monitor.c | 44 ++++++++++++++++++++++++++++++++--- monitor.h | 4 +-- vl.c | 73 +++++++++++++++++----------------------------------------- 8 files changed, 85 insertions(+), 66 deletions(-)
block.c +13 -1
@@ -335,6 +335,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, bs->read_only =0 ; bs->is_temporary =0 ; bs->encrypted =0 ; + bs->valid_key =0 ;if (flags &BDRV_O_SNAPSHOT ) {BlockDriverState *bs1;
@@ -921,6 +922,15 @@ int bdrv_is_encrypted(BlockDriverState *bs)return bs->encrypted; } +int bdrv_key_required (BlockDriverState *bs) +{ +BlockDriverState *backing_hd = bs->backing_hd; + +if (backing_hd && backing_hd->encrypted && !backing_hd->valid_key) +return 1 ; +return (bs->encrypted && !bs->valid_key); +} +int bdrv_set_key (BlockDriverState *bs,const char *key) {int ret;
@@ -933,7 +943,9 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) }if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key)return -1 ; -return bs->drv->bdrv_set_key (bs, key); + ret = bs->drv->bdrv_set_key (bs, key); + bs->valid_key = (ret ==0 ); +return ret; }void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size)
block.h +2 -2
@@ -103,8 +103,6 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num, BlockDriverCompletionFunc *cb, void *opaque);void bdrv_aio_cancel (BlockDriverAIOCB *acb); -int qemu_key_check (BlockDriverState *bs,const char *name); -/* Ensure contents are flushed to disk. */ void bdrv_flush (BlockDriverState *bs);void bdrv_flush_all (void );
@@ -144,7 +142,9 @@ BlockDriverState *bdrv_find(const char *name);void bdrv_iterate (void (*it)(void *opaque,BlockDriverState *bs),void *opaque);int bdrv_is_encrypted (BlockDriverState *bs); +int bdrv_key_required (BlockDriverState *bs);int bdrv_set_key (BlockDriverState *bs,const char *key); +int bdrv_query_missing_keys (void );void bdrv_iterate_format (void (*it)(void *opaque,const char *name),void *opaque);const char *bdrv_get_device_name (BlockDriverState *bs);
block_int.h +1 -0
@@ -96,6 +96,7 @@ struct BlockDriverState {int removable;/* if true, the media can be removed */ int locked;/* if true, the media cannot temporarily be ejected */ int encrypted;/* if true, the media is encrypted */ +int valid_key;/* if true, a valid encryption key has been set */ int sg;/* if true, the device is a /dev/sg* */ /* event callback when inserting/removing */ void (*change_cb)(void *opaque);
hw/usb-msd.c +3 -3
@@ -11,6 +11,7 @@#include "usb.h" #include "block.h" #include "scsi-disk.h" +#include "monitor.h" //#define DEBUG_MSD
@@ -513,7 +514,7 @@ static void usb_msd_handle_destroy(USBDevice *dev)qemu_free (s); } -USBDevice *usb_msd_init (const char *filename) +USBDevice *usb_msd_init (const char *filename,BlockDriverState **pbs) {MSDState *s;BlockDriverState *bdrv;
@@ -552,9 +553,8 @@ USBDevice *usb_msd_init(const char *filename) bdrv =bdrv_new ("usb" );if (bdrv_open2 (bdrv, filename,0 , drv) <0 ) goto fail; -if (qemu_key_check (bdrv, filename)) - goto fail; s->bs = bdrv; + *pbs = bdrv; s->dev.speed =USB_SPEED_FULL ; s->dev.handle_packet = usb_generic_handle_packet;
hw/usb.h +4 -1
@@ -21,6 +21,9 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "block.h" +#define USB_TOKEN_SETUP 0x2d#define USB_TOKEN_IN 0x69/* device -> host */ #define USB_TOKEN_OUT 0xe1/* host -> device */
@@ -250,7 +253,7 @@ USBDevice *usb_keyboard_init(void);void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *));/* usb-msd.c */ -USBDevice *usb_msd_init (const char *filename); +USBDevice *usb_msd_init (const char *filename,BlockDriverState **pbs);/* usb-net.c */ USBDevice *usb_net_init (NICInfo *nd);
monitor.c +40 -4
73 lines not on this page · raw message
monitor.h +1 -3
@@ -5,12 +5,10 @@#include "block.h" void monitor_init (CharDriverState *hd,int show_banner); -void monitor_readline (const char *prompt,int is_password, -char *buf,int buf_size);void monitor_suspend (void );void monitor_resume (void ); -int monitor_read_bdrv_key (BlockDriverState *bs,const char *name); +int monitor_read_bdrv_key (BlockDriverState *bs);void monitor_vprintf (const char *fmt,va_list ap);void monitor_printf (const char *fmt, ...)
vl.c +21 -52
131 lines not on this page · raw message
PATCH 9/17 monitor: Simplify password input mode
In reply to Jan KiszkaDrop the hack to query passwords on all monitor terminals now that they are requested when the user initially enters 'continue'.
---
monitor.c | 20 -------------------- 1 files changed, 0 insertions(+), 20 deletions(-)
monitor.c +0 -20
@@ -2876,20 +2876,6 @@ static void monitor_readline_cb(void *opaque, const char *input)static void monitor_readline (const char *prompt,int is_password,char *buf,int buf_size) { -int i; -int old_focus[MAX_MON ]; - -if (is_password) { -for (i =0 ; i <MAX_MON ; i++) { - old_focus[i] =0 ; -if (monitor_hd[i]) { - old_focus[i] = monitor_hd[i]->focus; - monitor_hd[i]->focus =0 ; -qemu_chr_send_event (monitor_hd[i],CHR_EVENT_FOCUS ); - } - } - } -readline_start (prompt, is_password, monitor_readline_cb,NULL ); monitor_readline_buf = buf; monitor_readline_buf_size = buf_size;
@@ -2897,12 +2883,6 @@ static void monitor_readline(const char *prompt, int is_password,while (monitor_readline_started) {main_loop_wait (10 ); } -/* restore original focus */ -if (is_password) { -for (i =0 ; i <MAX_MON ; i++) -if (old_focus[i]) - monitor_hd[i]->focus = old_focus[i]; - } }int monitor_read_bdrv_key (BlockDriverState *bs)
PATCH 10/17 monitor: Rework terminal management
In reply to Jan KiszkaRemove the static MAX_MON limit by managing monitor terminals in a linked list.
---
monitor.c | 41 +++++++++++++++++++++-------------------- monitor.h | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-)
monitor.c +21 -20
@@ -67,8 +67,12 @@ typedef struct term_cmd_t {const char *help; } term_cmd_t; -#define MAX_MON 4 -static CharDriverState *monitor_hd[MAX_MON ]; +typedef struct MonitorTerm { +CharDriverState *chr; +LIST_ENTRY (MonitorTerm) entry; +}MonitorTerm ; + +static LIST_HEAD(term_list, MonitorTerm) term_list;static int hide_banner;static const term_cmd_t term_cmds[];
@@ -85,11 +89,13 @@ static CPUState *mon_cpu = NULL;void monitor_flush (void ) { -int i; +MonitorTerm *term; +if (term_outbuf_index >0 ) { -for (i =0 ; i <MAX_MON ; i++) -if (monitor_hd[i] && monitor_hd[i]->focus ==0 ) -qemu_chr_write (monitor_hd[i], term_outbuf, term_outbuf_index); + LIST_FOREACH(term, &term_list, entry) { +if (term->chr->focus ==0 ) +qemu_chr_write (term->chr, term_outbuf, term_outbuf_index); + } term_outbuf_index =0 ; } }
@@ -2834,29 +2840,24 @@ static void term_event(void *opaque, int event)static int is_first_init =1 ; -void monitor_init (CharDriverState *hd,int show_banner) +void monitor_init (CharDriverState *chr,int show_banner) { -int i; +MonitorTerm *term;if (is_first_init) { key_timer =qemu_new_timer (vm_clock, release_keys,NULL ); -if (!key_timer) -return ; -for (i =0 ; i <MAX_MON ; i++) { - monitor_hd[i] =NULL ; - } is_first_init =0 ; } -for (i =0 ; i <MAX_MON ; i++) { -if (monitor_hd[i] ==NULL ) { - monitor_hd[i] = hd; -break ; - } - } + + term =qemu_mallocz (sizeof (*term)); hide_banner = !show_banner; -qemu_chr_add_handlers (hd, term_can_read, term_read, term_event,NULL ); + term->chr = chr; + +qemu_chr_add_handlers (chr, term_can_read, term_read, term_event,NULL ); + +LIST_INSERT_HEAD (&term_list, term, entry);readline_start ("" ,0 , monitor_handle_command1,NULL ); }
monitor.h +1 -1
@@ -4,7 +4,7 @@#include "qemu-char.h" #include "block.h" -void monitor_init (CharDriverState *hd,int show_banner); +void monitor_init (CharDriverState *chr,int show_banner);void monitor_suspend (void );void monitor_resume (void );
PATCH 11/17 monitor: Drop banner hiding
In reply to Jan KiszkaThere is no use for the hide/show banner option, and it is applied inconsistently anyway (or what makes the difference between -serial mon:stdio and -nographic for the monitor?). So drop this mode.
---
monitor.c | 10 +++------- monitor.h | 2 +- qemu-char.c | 2 +- vl.c | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-)
monitor.c +3 -7
@@ -73,7 +73,6 @@ typedef struct MonitorTerm { } MonitorTerm; static LIST_HEAD(term_list, MonitorTerm) term_list; -static int hide_banner;static const term_cmd_t term_cmds[];static const term_cmd_t info_cmds[];
@@ -2832,15 +2831,14 @@ static void term_event(void *opaque, int event)if (event !=CHR_EVENT_RESET )return ; -if (!hide_banner) -monitor_printf ("QEMU %s monitor - type 'help' for more information\n" , -QEMU_VERSION ); +monitor_printf ("QEMU %s monitor - type 'help' for more information\n" , +QEMU_VERSION );monitor_start_input (); }static int is_first_init =1 ; -void monitor_init (CharDriverState *chr,int show_banner) +void monitor_init (CharDriverState *chr) {MonitorTerm *term;
@@ -2851,8 +2849,6 @@ void monitor_init(CharDriverState *chr, int show_banner) term =qemu_mallocz (sizeof (*term)); - hide_banner = !show_banner; - term->chr = chr;qemu_chr_add_handlers (chr, term_can_read, term_read, term_event,NULL );
monitor.h +1 -1
@@ -4,7 +4,7 @@#include "qemu-char.h" #include "block.h" -void monitor_init (CharDriverState *chr,int show_banner); +void monitor_init (CharDriverState *chr);void monitor_suspend (void );void monitor_resume (void );
qemu-char.c +1 -1
@@ -2095,7 +2095,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i chr =qemu_chr_open (label, p,NULL );if (chr) { chr =qemu_chr_open_mux (chr); -monitor_init (chr, !nographic); +monitor_init (chr); }else {printf ("Unable to open driver: %s\n" , p); }
vl.c +1 -1
@@ -5583,7 +5583,7 @@ int main(int argc, char **argv, char **envp)text_consoles_set_display (display_state);if (monitor_device && monitor_hd) -monitor_init (monitor_hd, !nographic); +monitor_init (monitor_hd);for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {const char *devname = serial_devices[i];
PATCH 12/17 monitor: Rework modal password input
In reply to Jan KiszkaCurrently, waiting for the user to type in some password blocks the whole VM because monitor_readline starts its own I/O loop. And this loop also screws up reading passwords from virtual console.
Patch below fixes the shortcomings by using normal I/O processing also for waiting on a password. To keep to modal property for the monitor terminal, the command handler is temporarily replaced by a password handler and a callback infrastructure is established to process the result before switching back to command mode.
---
block.c | 21 ++++++++--- hw/usb-msd.c | 10 ++++- hw/usb.h | 3 +- monitor.c | 111 ++++++++++++++++++++++++++++++++-------------------------- monitor.h | 4 ++ vl.c | 19 ++++++++-- 6 files changed, 105 insertions(+), 63 deletions(-)
block.c +15 -6
@@ -429,11 +429,12 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, } } -/* call the change callback */ - bs->media_changed =1 ; -if (bs->change_cb) - bs->change_cb (bs->change_opaque); - +if (!bdrv_key_required (bs)) { +/* call the change callback */ + bs->media_changed =1 ; +if (bs->change_cb) + bs->change_cb (bs->change_opaque); + }return 0 ; }
@@ -944,7 +945,15 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key)return -1 ; ret = bs->drv->bdrv_set_key (bs, key); - bs->valid_key = (ret ==0 ); +if (ret <0 ) { + bs->valid_key =0 ; + }else if (!bs->valid_key) { + bs->valid_key =1 ; +/* call the change callback now, we skipped it on open */ + bs->media_changed =1 ; +if (bs->change_cb) + bs->change_cb (bs->change_opaque); + }return ret; }
hw/usb-msd.c +8 -2
@@ -514,7 +514,7 @@ static void usb_msd_handle_destroy(USBDevice *dev)qemu_free (s); } -USBDevice *usb_msd_init (const char *filename,BlockDriverState **pbs) +USBDevice *usb_msd_init (const char *filename) {MSDState *s;BlockDriverState *bdrv;
@@ -554,7 +554,6 @@ USBDevice *usb_msd_init(const char *filename, BlockDriverState **pbs)if (bdrv_open2 (bdrv, filename,0 , drv) <0 ) goto fail; s->bs = bdrv; - *pbs = bdrv; s->dev.speed =USB_SPEED_FULL ; s->dev.handle_packet = usb_generic_handle_packet;
@@ -574,3 +573,10 @@ USBDevice *usb_msd_init(const char *filename, BlockDriverState **pbs)qemu_free (s);return NULL ; } + +BlockDriverState *usb_msd_get_bdrv (USBDevice *dev) +{ +MSDState *s = (MSDState *)dev; + +return s->bs; +}
hw/usb.h +2 -1
@@ -253,7 +253,8 @@ USBDevice *usb_keyboard_init(void);void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *));/* usb-msd.c */ -USBDevice *usb_msd_init (const char *filename,BlockDriverState **pbs); +USBDevice *usb_msd_init (const char *filename); +BlockDriverState *usb_msd_get_bdrv (USBDevice *dev);/* usb-net.c */ USBDevice *usb_net_init (NICInfo *nd);
monitor.c +62 -49
162 lines not on this page · raw message
monitor.h +3 -1
@@ -8,7 +8,9 @@ void monitor_init(CharDriverState *chr);void monitor_suspend (void );void monitor_resume (void ); -int monitor_read_bdrv_key (BlockDriverState *bs); +void monitor_read_bdrv_key_start (BlockDriverState *bs, +BlockDriverCompletionFunc *completion_cb, +void *opaque);void monitor_vprintf (const char *fmt,va_list ap);void monitor_printf (const char *fmt, ...)
vl.c +15 -4
@@ -2603,6 +2603,16 @@ int usb_device_add_dev(USBDevice *dev)return 0 ; } +static void usb_msd_password_cb (void *opaque,int err) +{ +USBDevice *dev = opaque; + +if (!err) +usb_device_add_dev (dev); +else + dev->handle_destroy (dev); +} +static int usb_device_add (const char *devname,int is_hotplug) {const char *p;
@@ -2622,14 +2632,15 @@ static int usb_device_add(const char *devname, int is_hotplug) }else if (strstart (devname,"disk:" , &p)) {BlockDriverState *bs; - dev =usb_msd_init (p, &bs); + dev =usb_msd_init (p);if (!dev)return -1 ; + bs =usb_msd_get_bdrv (dev);if (bdrv_key_required (bs)) { autostart =0 ; -if (is_hotplug &&monitor_read_bdrv_key (bs) <0 ) { - dev->handle_destroy (dev); -return -1 ; +if (is_hotplug) { +monitor_read_bdrv_key_start (bs, usb_msd_password_cb, dev); +return 0 ; } } }else if (!strcmp (devname,"wacom-tablet" )) {
PATCH 13/17 monitor: Introduce ReadLineState
In reply to Jan KiszkaAs another step towards decoupled monitor terminals encapsulate the state of the readline processor in a separate data structure called ReadLineState and adapt all interfaces appropriately. For now the monitor continues to instantiate just a single readline state.
---
monitor.c | 30 +++-- readline.c | 384 +++++++++++++++++++++++++++++------------------------------- readline.h | 44 ++++++- 3 files changed, 241 insertions(+), 217 deletions(-)
monitor.c +16 -14
@@ -81,6 +81,7 @@ static uint8_t term_outbuf[1024];static int term_outbuf_index;static BlockDriverCompletionFunc *password_completion_cb;static void *password_opaque; +ReadLineState *rs;static void monitor_start_input (void );
@@ -88,7 +89,7 @@ static CPUState *mon_cpu = NULL;static void monitor_read_password (ReadLineFunc *readline_func,void *opaque) { -readline_start ("Password: " ,1 , readline_func, opaque); +readline_start (rs,"Password: " ,1 , readline_func, opaque); }void monitor_flush (void )
@@ -376,7 +377,7 @@ static void do_info_history (void) i =0 ;for (;;) { - str =readline_get_history (i); + str =readline_get_history (rs, i);if (!str)break ;monitor_printf ("%d: '%s'\n" , i, str);
@@ -2628,7 +2629,7 @@ static void cmd_completion(const char *name, const char *list)memcpy (cmd, pstart, len); cmd[len] ='\0' ;if (name[0 ] =='\0' || !strncmp (name, cmd,strlen (name))) { -add_completion (cmd); +readline_add_completion (rs, cmd); }if (*p =='\0' )break ;
@@ -2681,7 +2682,7 @@ static void file_completion(const char *input)stat (file, &sb);if (S_ISDIR (sb.st_mode))pstrcat (file,sizeof (file),"/" ); -add_completion (file); +readline_add_completion (rs, file); } }closedir (ffs);
@@ -2694,7 +2695,7 @@ static void block_completion_it(void *opaque, BlockDriverState *bs)if (input[0 ] =='\0' || !strncmp (name, (char *)input,strlen (input))) { -add_completion (name); +readline_add_completion (rs, name); } }
@@ -2724,7 +2725,7 @@ static void parse_cmdline(const char *cmdline, *pnb_args = nb_args; } -void readline_find_completion (const char *cmdline) +static void monitor_find_completion (const char *cmdline) {const char *cmdname;char *args[MAX_ARGS ];
@@ -2754,7 +2755,7 @@ void readline_find_completion(const char *cmdline) cmdname ="" ; else cmdname = args[0 ]; - completion_index =strlen (cmdname); +readline_set_completion_index (rs,strlen (cmdname));for (cmd = term_cmds; cmd->name !=NULL ; cmd++) {cmd_completion (cmdname, cmd->name); }
@@ -2778,23 +2779,23 @@ void readline_find_completion(const char *cmdline)switch (*ptype) {case 'F' :/* file completion */ - completion_index =strlen (str); +readline_set_completion_index (rs,strlen (str));file_completion (str);break ;case 'B' :/* block device name completion */ - completion_index =strlen (str); +readline_set_completion_index (rs,strlen (str));bdrv_iterate (block_completion_it, (void *)str);break ;case 's' :/* XXX: more generic ? */ if (!strcmp (cmd->name,"info" )) { - completion_index =strlen (str); +readline_set_completion_index (rs,strlen (str));for (cmd = info_cmds; cmd->name !=NULL ; cmd++) {cmd_completion (str, cmd->name); } }else if (!strcmp (cmd->name,"sendkey" )) { - completion_index =strlen (str); +readline_set_completion_index (rs,strlen (str));for (key = key_defs; key->name !=NULL ; key++) {cmd_completion (str, key->name); }
@@ -2817,7 +2818,7 @@ static void term_read(void *opaque, const uint8_t *buf, int size) {int i;for (i =0 ; i < size; i++) -readline_handle_byte (buf[i]); +readline_handle_byte (rs, buf[i]); }static int monitor_suspended;
@@ -2845,7 +2846,7 @@ void monitor_resume(void)static void monitor_start_input (void ) { -readline_start ("(qemu) " ,0 , monitor_handle_command1,NULL ); +readline_start (rs,"(qemu) " ,0 , monitor_handle_command1,NULL ); }static void term_event (void *opaque,int event)
@@ -2872,12 +2873,13 @@ void monitor_init(CharDriverState *chr) term =qemu_mallocz (sizeof (*term)); term->chr = chr; + rs =readline_init (monitor_find_completion);qemu_chr_add_handlers (chr, term_can_read, term_read, term_event,NULL );LIST_INSERT_HEAD (&term_list, term, entry); -readline_start ("" ,0 , monitor_handle_command1,NULL ); +readline_start (rs,"" ,0 , monitor_handle_command1,NULL ); }static void bdrv_password_cb (void *opaque,const char *password)
readline.c +187 -197
636 lines not on this page · raw message
readline.h +38 -6
52 lines not on this page · raw message
PATCH 14/17 monitor: Decouple terminals
In reply to Jan KiszkaCurrently all registered (and activate) monitor terminals work in broadcast mode: Everyone sees what someone else types on some other terminal and what the monitor reports back. This model is broken when you have a management monitor terminal that is automatically operated and some other terminal used for independent guest inspection. Such an additional terminal can be a multiplexed device channel or a gdb frontend connected to QEMU's stub.
Therefor, this patch decouples the buffers and states of all monitor terminals, allowing the user to operate them independently. The basic idea is stolen from Jason Wessel: When starting to handle a monitor command or some terminal event, the current monitor terminal is set to the one associated with the underlying char device, letting all succeeding monitor_printf show up on only this selected terminal.
There are still two asynchronous monitor writers: some error reporting in VNC's audio_add and the log-to-monitor feature of the audio subsystem. In order to keep them happy, the concept of a default monitor terminal is used, which is either the dedicated monitor terminal or the first registered mux. If we can agree on converting or dropping asynchronous monitor users, we would also be able to drop the default terminal concept again.
As the patch requires to rework the monitor suspension interface, it also takes the freedom to make it "truely suspending" now (so far suspending meant suppressing the prompt, but inputs were still processed).
---
migration-exec.c | 11 +--- migration-tcp.c | 11 +--- migration.c | 12 +++- migration.h | 4 + monitor.c | 159 +++++++++++++++++++++++++++++++----------------------- monitor.h | 8 ++- qemu-char.c | 2 - readline.c | 3 - readline.h | 1 vl.c | 2 - 10 files changed, 119 insertions(+), 94 deletions(-)
migration-exec.c +4 -7
@@ -55,7 +55,7 @@ static int exec_close(FdMigrationState *s)MigrationState *exec_start_outgoing_migration (const char *command,int64_t bandwidth_limit, -int async) +int detach) {FdMigrationState *s;FILE *f;
@@ -89,14 +89,11 @@ MigrationState *exec_start_outgoing_migration(const char *command, s->mig_state.release = migrate_fd_release; s->state =MIG_STATE_ACTIVE ; - s->detach = !async; + s->mon_resume_handle =NULL ; s->bandwidth_limit = bandwidth_limit; -if (s->detach ==1 ) { -dprintf ("detaching from monitor\n" ); -monitor_suspend (); - s->detach =2 ; - } +if (!detach) +migrate_fd_monitor_suspend (s);migrate_fd_connect (s);return &s->mig_state;
migration-tcp.c +4 -7
@@ -79,7 +79,7 @@ static void tcp_wait_for_connect(void *opaque)MigrationState *tcp_start_outgoing_migration (const char *host_port,int64_t bandwidth_limit, -int async) +int detach) {struct sockaddr_in addr;FdMigrationState *s;
@@ -98,7 +98,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port, s->mig_state.release = migrate_fd_release; s->state =MIG_STATE_ACTIVE ; - s->detach = !async; + s->mon_resume_handle =NULL ; s->bandwidth_limit = bandwidth_limit; s->fd =socket (PF_INET ,SOCK_STREAM ,0 );if (s->fd ==-1 ) {
@@ -108,11 +108,8 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,socket_set_nonblock (s->fd); -if (s->detach ==1 ) { -dprintf ("detaching from monitor\n" ); -monitor_suspend (); - s->detach =2 ; - } +if (!detach) +migrate_fd_monitor_suspend (s); do { ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr));
migration.c +8 -4
@@ -125,6 +125,12 @@ void do_info_migrate(void)/* shared migration helpers */ +void migrate_fd_monitor_suspend (FdMigrationState *s) +{ + s->mon_resume_handle =monitor_suspend (); +dprintf ("suspending monitor\n" ); +} +void migrate_fd_error (FdMigrationState *s) {dprintf ("setting error state\n" );
@@ -145,10 +151,8 @@ void migrate_fd_cleanup(FdMigrationState *s)close (s->fd);/* Don't resume monitor until we've flushed all of the buffers */ -if (s->detach ==2 ) { -monitor_resume (); - s->detach =0 ; - } +if (s->mon_resume_handle) +monitor_resume (s->mon_resume_handle); s->fd =-1 ; }
migration.h +3 -1
@@ -37,7 +37,7 @@ struct FdMigrationStateint64_t bandwidth_limit;QEMUFile *file;int fd; -int detach; +void *mon_resume_handle;int state;int (*get_error)(struct FdMigrationState *);int (*close)(struct FdMigrationState *);
@@ -67,6 +67,8 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,int64_t bandwidth_limit, int detach); +void migrate_fd_monitor_suspend (FdMigrationState *s); +void migrate_fd_error (FdMigrationState *s);void migrate_fd_cleanup (FdMigrationState *s);
monitor.c +91 -68
323 lines not on this page · raw message
monitor.h +5 -3
@@ -4,10 +4,12 @@#include "qemu-char.h" #include "block.h" -void monitor_init (CharDriverState *chr); -void monitor_suspend (void ); -void monitor_resume (void ); +/* flags for monitor_init */ +#define MONITOR_IS_DEFAULT 0x01 +void monitor_init (CharDriverState *chr,int flags); +void *monitor_suspend (void ); +void monitor_resume (void *handle);void monitor_read_bdrv_key_start (BlockDriverState *bs,BlockDriverCompletionFunc *completion_cb,void *opaque);
qemu-char.c +1 -1
@@ -2095,7 +2095,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i chr =qemu_chr_open (label, p,NULL );if (chr) { chr =qemu_chr_open_mux (chr); -monitor_init (chr); +monitor_init (chr,0 ); }else {printf ("Unable to open driver: %s\n" , p); }
readline.c +1 -2
@@ -31,7 +31,7 @@#define printf do_not_use_printf -static void readline_show_prompt (ReadLineState *rs) +void readline_show_prompt (ReadLineState *rs) {monitor_printf ("%s" , rs->prompt);monitor_flush ();
@@ -445,7 +445,6 @@ void readline_start(ReadLineState *rs, const char *prompt, int read_password, rs->readline_opaque = opaque; rs->read_password = read_password;readline_restart (rs); -readline_show_prompt (rs); }void readline_restart (ReadLineState *rs)
readline.h +1 -0
@@ -41,6 +41,7 @@ const char *readline_get_history(ReadLineState *rs, unsigned int index);void readline_start (ReadLineState *rs,const char *prompt,int read_password,ReadLineFunc *readline_func,void *opaque);void readline_restart (ReadLineState *rs); +void readline_show_prompt (ReadLineState *rs);ReadLineState *readline_init (ReadLineCompletionFunc *completion_finder);#endif /* !READLINE_H */
vl.c +1 -1
@@ -5594,7 +5594,7 @@ int main(int argc, char **argv, char **envp)text_consoles_set_display (display_state);if (monitor_device && monitor_hd) -monitor_init (monitor_hd); +monitor_init (monitor_hd,MONITOR_IS_DEFAULT );for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {const char *devname = serial_devices[i];
Re: [Qemu-devel] [PATCH 14/17] monitor: Decouple terminals
Quoted 15 lines · Jan Kiszka
Currently all registered (and activate) monitor terminals work in broadcast mode: Everyone sees what someone else types on some other terminal and what the monitor reports back. This model is broken when you have a management monitor terminal that is automatically operated and some other terminal used for independent guest inspection. Such an additional terminal can be a multiplexed device channel or a gdb frontend connected to QEMU's stub.
Therefor, this patch decouples the buffers and states of all monitor terminals, allowing the user to operate them independently. The basic idea is stolen from Jason Wessel: When starting to handle a monitor command or some terminal event, the current monitor terminal is set to the one associated with the underlying char device, letting all succeeding
monitor_printfshow up on only this selected terminal.
Quoted 3 lines
There are still two asynchronous monitor writers: some error reporting in VNC's
audio_addand the log-to-monitor feature of the audio subsystem.
That concerns me. Nothing should output to the monitor asychronously.
I'd like to see a few changes to make things a bit closer to the long term goals for the monitor (having proper multiple monitors devoid of global state).
Here's what I'd suggest:
1) Make monitor_printf() take a monitor state. The easiest thing to do would be to introduce this in your previous rename patch making everything use current_monitor.
2) Introduce current_monitor and default_monitor global variables. They map to what you describe above and should be maintained as such.
3) Make all monitor callbacks take a monitor state
4) Convert monitor_printf()s called from monitor callbacks to use the passed monitor state
5) Eliminate all uses of current_monitor/default_monitor.
I'd say, 1 and 2 are required for this patchset. I think 3 and 4 would be pretty easy to add to your patchset. I think 5 is probably tougher and could wait for another day.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 14/17] monitor: Decouple terminals
Quoted 9 lines · Anthony Liguori
I'd like to see a few changes to make things a bit closer to the long term goals for the monitor (having proper multiple monitors devoid of global state).
Here's what I'd suggest:
1) Make
monitor_printf()take a monitor state. The easiest thing to do would be to introduce this in your previous rename patch making everything usecurrent_monitor.
2) Introducecurrent_monitoranddefault_monitorglobal variables. They map to what you describe above and should be maintained as such.
3) Make all monitor callbacks take a monitor state
4) Convert monitor_printf()s called from monitor callbacks to use the passed monitor state
5) Eliminate all uses of current_monitor/default_monitor.
6) Make monitor callbacks return an error value
7) Convert all monitor callbacks to return error values instead of printing error messages
8) Introduce greater structure to monitor_printf()s. For instance, we have a number of monitor commands that essentially print dictionaries (set of key value pairs). We should introduce a higher level function like monitor_print_list("hd", "locked=false", "file=foo.img", NULL).
9) Introduce computer mode to monitor that makes monitor very parsable to a non-human user.
10) Introduce library that interacts with monitor over any supported character device.
Just to fill out more of my long term thinking about the monitor.
Regards,
Anthony Liguori
Quoted 8 lines
I'd say, 1 and 2 are required for this patchset. I think 3 and 4 would be pretty easy to add to your patchset. I think 5 is probably tougher and could wait for another day.
Regards,
Anthony Liguori
[Qemu-devel] Re: [PATCH 14/17] monitor: Decouple terminals
In reply to Anthony LiguoriQuoted 16 lines · Anthony Liguori
Quoted 15 lines · Jan Kiszka
Currently all registered (and activate) monitor terminals work in broadcast mode: Everyone sees what someone else types on some other terminal and what the monitor reports back. This model is broken when you have a management monitor terminal that is automatically operated and some other terminal used for independent guest inspection. Such an additional terminal can be a multiplexed device channel or a gdb frontend connected to QEMU's stub.
Therefor, this patch decouples the buffers and states of all monitor terminals, allowing the user to operate them independently. The basic idea is stolen from Jason Wessel: When starting to handle a monitor command or some terminal event, the current monitor terminal is set to the one associated with the underlying char device, letting all succeeding
monitor_printfshow up on only this selected terminal.
Quoted 5 lines
Quoted 3 lines
There are still two asynchronous monitor writers: some error reporting in VNC's
audio_addand the log-to-monitor feature of the audio subsystem.That concerns me. Nothing should output to the monitor asychronously.
Indeed.
Quoted 10 lines
I'd like to see a few changes to make things a bit closer to the long term goals for the monitor (having proper multiple monitors devoid of global state).
Here's what I'd suggest:
1) Make
monitor_printf()take a monitor state. The easiest thing to do would be to introduce this in your previous rename patch making everything usecurrent_monitor.
Lazy /me was hoping to get around this...
Quoted 10 lines
2) Introduce
current_monitoranddefault_monitorglobal variables. They map to what you describe above and should be maintained as such.
3) Make all monitor callbacks take a monitor state
4) Convert monitor_printf()s called from monitor callbacks to use the passed monitor state
5) Eliminate all uses of current_monitor/default_monitor.I'd say, 1 and 2 are required for this patchset. I think 3 and 4 would be pretty easy to add to your patchset. I think 5 is probably tougher and could wait for another day.
My feeling is (though I have not sound stats at hand) that a lot of functions all over the place will have to be extended in order to pass the target monitor around: From the command callbacks, through all the subsystems, finally reaching the monitor API. Some use cases only consist of the command callback itself, OK, but the others worry me a bit. All doable, for sure, but I just want to make sure that we all agree on the result before starting this "tough" endeavor. :)
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] Re: [PATCH 14/17] monitor: Decouple terminals
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Anthony Liguori
1) Make
monitor_printf()take a monitor state. The easiest thing to do would be to introduce this in your previous rename patch making everything usecurrent_monitor.Lazy /me was hoping to get around this...
You are already changing every instance of term_printf(). How hard can it be to add another parameter that gets completely ignored for now :-)
The reason I want to see this in this changeset is that you're touching every term_printf(). Adjusting it to the right interface means we don't have to churn again and we don't have the hurdle of touching every term_printf() to get started.
Quoted 12 lines
Quoted 11 lines
2) Introduce
current_monitoranddefault_monitorglobal variables. They map to what you describe above and should be maintained as such.
3) Make all monitor callbacks take a monitor state
4) Convert monitor_printf()s called from monitor callbacks to use the passed monitor state
5) Eliminate all uses of current_monitor/default_monitor.I'd say, 1 and 2 are required for this patchset. I think 3 and 4 would be pretty easy to add to your patchset. I think 5 is probably tougher and could wait for another day.
Quoted 4 lines
My feeling is (though I have not sound stats at hand) that a lot of functions all over the place will have to be extended in order to pass the target monitor around: From the command callbacks, through all the subsystems, finally reaching the monitor API.
Yes, my feeling is the same. That's why I suggest an incremental approach. You already have introduced a concept of an active and default terminal. You hide this behind the monitor_printf() function. I'm simply suggesting making it an explicit part of the interface.
Quoted 2 lines
Some use cases only
consist of the command callback itself, OK,
Yes, these are the low hanging fruit for conversion.
Quoted 4 lines
but the others worry me a
bit. All doable, for sure, but I just want to make sure that we all agree on the result before starting this "tough" endeavor. :)
It's been discussed a lot and there's a strong desire to make the monitor interface better for management tools. I don't expect you to address the whole problem in this one series but, as I said earlier, since you're already making changes everywhere, let's make the right changes at least :-)
Regards,
Anthony Liguori
Quoted 3 lines
Jan
PATCH 15/17 monitor: Improve mux'ed console experience
In reply to Jan KiszkaUp to now, you never really knew if you already switched the console after pressing CTRL-A C or if you mistyped it again. This patch clarifies the situation by providing a prompt in a new line and injecting a linebreak when switching away again. For this purpose, the two events CHR_EVENT_MUX_IN and CHR_EVENT_MUX_OUT are introduced and distributed on focus switches.
---
monitor.c | 26 ++++++++++++++++++++------ qemu-char.c | 11 +++++++++-- qemu-char.h | 8 +++++--- 3 files changed, 34 insertions(+), 11 deletions(-)
monitor.c +20 -6
@@ -2868,15 +2868,29 @@ static void term_event(void *opaque, int event) {MonitorTerm *old_term = cur_term; -if (event !=CHR_EVENT_RESET ) -return ; - cur_term = opaque; -monitor_printf ("QEMU %s monitor - type 'help' for more information\n" , -QEMU_VERSION ); -monitor_resume (cur_term); +switch (event) { +case CHR_EVENT_MUX_IN : +readline_restart (cur_term->rs); +monitor_resume (cur_term); +monitor_flush (); +break ; +case CHR_EVENT_MUX_OUT : +if (cur_term->suspend_cnt ==0 ) +monitor_printf ("\n" ); +monitor_flush (); +monitor_suspend (); +break ; + +case CHR_EVENT_RESET : +monitor_printf ("QEMU %s monitor - type 'help' for more information\n" , +QEMU_VERSION ); +if (cur_term->chr->focus ==0 ) +monitor_resume (cur_term); +break ; + } cur_term = old_term; }
qemu-char.c +9 -2
@@ -294,6 +294,12 @@ static void mux_print_help(CharDriverState *chr) } } +static void mux_chr_send_event (MuxDriver *d,int mux_nr,int event) +{ +if (d->chr_event[mux_nr]) + d->chr_event[mux_nr](d->ext_opaque[mux_nr], event); +} +static int mux_proc_byte (CharDriverState *chr,MuxDriver *d,int ch) {if (d->term_got_escape) {
@@ -325,9 +331,11 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)break ;case 'c' :/* Switch to the next registered device */ +mux_chr_send_event (d, chr->focus,CHR_EVENT_MUX_OUT ); chr->focus++;if (chr->focus >= d->mux_cnt) chr->focus =0 ; +mux_chr_send_event (d, chr->focus,CHR_EVENT_MUX_IN );break ;case 't' : term_timestamps = !term_timestamps;
@@ -397,8 +405,7 @@ static void mux_chr_event(void *opaque, int event)/* Send the event to all registered listeners */ for (i =0 ; i < d->mux_cnt; i++) -if (d->chr_event[i]) - d->chr_event[i](d->ext_opaque[i], event); +mux_chr_send_event (d, i, event); }static void mux_chr_update_read_handler (CharDriverState *chr)
qemu-char.h +5 -3
@@ -4,9 +4,11 @@#include "sys-queue.h" /* character device */ -#define CHR_EVENT_BREAK 0/* serial break char */ -#define CHR_EVENT_FOCUS 1/* focus to this terminal (modal input needed) */ -#define CHR_EVENT_RESET 2/* new connection established */ +#define CHR_EVENT_BREAK 0/* serial break char */ +#define CHR_EVENT_FOCUS 1/* focus to this terminal (modal input needed) */ +#define CHR_EVENT_RESET 2/* new connection established */ +#define CHR_EVENT_MUX_IN 3/* mux-focus was set to this terminal */ +#define CHR_EVENT_MUX_OUT 4/* mux-focus will move on */ #define CHR_IOCTL_SERIAL_SET_PARAMS 1
PATCH 16/17 monitor: Introduce MONITOR_USE_READLINE flag
In reply to Jan KiszkaThis allows to create monitor terminals that do not make use of the interactive readline back-end but rather send complete commands. The pass-through monitor interface of the gdbstub will be an example for such terminals.
---
migration.c | 6 +++++- monitor.c | 50 +++++++++++++++++++++++++++++++++++++++----------- monitor.h | 1 + qemu-char.c | 2 +- vl.c | 2 +- 5 files changed, 47 insertions(+), 14 deletions(-)
migration.c +5 -1
@@ -128,7 +128,11 @@ void do_info_migrate(void)void migrate_fd_monitor_suspend (FdMigrationState *s) { s->mon_resume_handle =monitor_suspend (); -dprintf ("suspending monitor\n" ); +if (s->mon_resume_handle) +dprintf ("suspending monitor\n" ); +else +monitor_printf ("terminal does not allow synchronous migration, " +"continuing detached\n" ); }void migrate_fd_error (FdMigrationState *s)
monitor.c +39 -11
98 lines not on this page · raw message
monitor.h +1 -0
@@ -6,6 +6,7 @@/* flags for monitor_init */ #define MONITOR_IS_DEFAULT 0x01 +#define MONITOR_USE_READLINE 0x02void monitor_init (CharDriverState *chr,int flags);void *monitor_suspend (void );
qemu-char.c +1 -1
@@ -2102,7 +2102,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i chr =qemu_chr_open (label, p,NULL );if (chr) { chr =qemu_chr_open_mux (chr); -monitor_init (chr,0 ); +monitor_init (chr,MONITOR_USE_READLINE ); }else {printf ("Unable to open driver: %s\n" , p); }
vl.c +1 -1
@@ -5594,7 +5594,7 @@ int main(int argc, char **argv, char **envp)text_consoles_set_display (display_state);if (monitor_device && monitor_hd) -monitor_init (monitor_hd,MONITOR_IS_DEFAULT ); +monitor_init (monitor_hd,MONITOR_USE_READLINE |MONITOR_IS_DEFAULT );for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {const char *devname = serial_devices[i];
PATCH 17/17 monitor: Pass-through for gdbstub
In reply to Jan KiszkaCreate a monitor terminal and pass it through the gdbstub. This allows to use gdb's monitor command to access the QEMU monitor. Works for all commands except for non-detached migration and password retrieval (user will receive error messages instead).
---
gdbstub.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 1 deletions(-)
gdbstub.c +53 -1
@@ -30,6 +30,7 @@#include "qemu.h" #else +#include "monitor.h" #include "qemu-char.h" #include "sysemu.h" #include "gdbstub.h"
@@ -285,6 +286,7 @@ typedef struct GDBState {int running_state;#else CharDriverState *chr; +CharDriverState *mon_chr;#endif } GDBState;
@@ -1819,7 +1821,22 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) put_packet(s, buf); break; } -#endif +#else /* !CONFIG_LINUX_USER */ + else if (strncmp(p, "Rcmd,", 5) == 0) { +int len =strlen (p +5 ); + +if ((len %2 ) !=0 ) { +put_packet (s,"E01" ); +break ; + } +hextomem (mem_buf, p +5 , len); + len = len /2 ; + mem_buf[len++] =0 ; +qemu_chr_read (s->mon_chr, mem_buf, len); +put_packet (s,"OK" ); +break ; + } +#endif /* !CONFIG_LINUX_USER */ if (strncmp (p,"Supported" ,9 ) ==0 ) {snprintf (buf,sizeof (buf),"PacketSize=%x" ,MAX_PACKET_LENGTH );#ifdef GDB_CORE_XML
@@ -2282,6 +2299,35 @@ static void gdb_chr_event(void *opaque, int event) } } +static void gdb_monitor_output (GDBState *s,const char *msg,int len) +{ +char buf[MAX_PACKET_LENGTH ]; + + buf[0 ] ='O' ; +if (len > (MAX_PACKET_LENGTH /2 ) -1 ) + len = (MAX_PACKET_LENGTH /2 ) -1 ; +memtohex (buf +1 , (uint8_t *)msg, len); +put_packet (s, buf); +} + +static int gdb_monitor_write (CharDriverState *chr,const uint8_t *buf,int len) +{ +const char *p = (const char *)buf; +int max_sz; + + max_sz = (sizeof (gdbserver_state->last_packet) -2 ) /2 ; +for (;;) { +if (len <= max_sz) { +gdb_monitor_output (gdbserver_state, p, len); +break ; + } +gdb_monitor_output (gdbserver_state, p, max_sz); + p += max_sz; + len -= max_sz; + } +return len; +} +int gdbserver_start (const char *port) {GDBState *s;
@@ -2313,6 +2359,12 @@ int gdbserver_start(const char *port)qemu_chr_add_handlers (chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event,NULL );qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL ); + +/* Initialize a monitor terminal for gdb */ + s->mon_chr =qemu_mallocz (sizeof (*s->mon_chr)); + s->mon_chr->chr_write = gdb_monitor_write; +monitor_init (s->mon_chr,0 ); + return 0; }#endif