default devices: qdev integration.
cover default devices: qdev integration.
Hi,
Qemu creates a bunch of default devices (serial, parallel, vga, ...) if the user didn't specify one on the command line. Unfortunaly this doesn't work well with the qdev way of doing things because this logic is tied to the -serial, -parallel, ... command line switches. Devices created via -device are ignored. This patch set fixes this. It also adds a command line switch to disable all default devices and does a few cleanups in the code touched anyway.
cheers,
Gerd
PATCH 1/10 chardev: move greeting into vc backend.
Make the 'vc' chardev backend print a title line with the chardev name after initialization, using CharDriverState->label.
This replaces the banner printing code in vl.c.
--- console.c | 8 ++++++++ vl.c | 24 ------------------------ 2 files changed, 8 insertions(+), 24 deletions(-)
console.c +8 -0
@@ -1384,6 +1384,14 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, QemuOpt s->t_attrib = s->t_attrib_default;text_console_resize (s); +if (chr->label) { +char msg[128 ]; +int len; + + len =snprintf (msg,sizeof (msg),"%s console\r\n" , chr->label); +console_puts (chr, (uint8_t *)msg, len); + } +qemu_chr_generic_open (chr);if (chr->init) chr->init (chr);
vl.c +0 -24
@@ -5800,30 +5800,6 @@ int main(int argc, char **argv, char **envp) } } -for (i =0 ; i <MAX_SERIAL_PORTS ; i++) { -const char *devname = serial_devices[i]; -if (devname &&strcmp (devname,"none" )) { -if (strstart (devname,"vc" ,0 )) -qemu_chr_printf (serial_hds[i],"serial%d console\r\n" , i); - } - } - -for (i =0 ; i <MAX_PARALLEL_PORTS ; i++) { -const char *devname = parallel_devices[i]; -if (devname &&strcmp (devname,"none" )) { -if (strstart (devname,"vc" ,0 )) -qemu_chr_printf (parallel_hds[i],"parallel%d console\r\n" , i); - } - } - -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) { -const char *devname = virtio_consoles[i]; -if (virtcon_hds[i] && devname) { -if (strstart (devname,"vc" ,0 )) -qemu_chr_printf (virtcon_hds[i],"virtio console%d\r\n" , i); - } - } -if (gdbstub_dev &&gdbserver_start (gdbstub_dev) <0 ) {fprintf (stderr,"qemu: could not open gdbserver on device '%s'\n" , gdbstub_dev);
Signature · 1 line
1.6.2.5
PATCH 2/10 vc: colorize chardev title line with blue background.
In reply to Gerd Hoffmann--- console.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
console.c +2 -0
@@ -1388,8 +1388,10 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, QemuOptchar msg[128 ];int len; + s->t_attrib.bgcol =COLOR_BLUE ; len =snprintf (msg,sizeof (msg),"%s console\r\n" , chr->label);console_puts (chr, (uint8_t *)msg, len); + s->t_attrib = s->t_attrib_default; }qemu_chr_generic_open (chr);
Signature · 1 line
1.6.2.5
PATCH 3/10 default devices: core code & serial lines.
In reply to Gerd HoffmannQemu creates a default serial line for you in case you didn't specify one on the command line. Right now this is tied to the '-serial <chardev>' command line switch, which in turn causes trouble if you are creating your serial line via '-device isa-serial,<props>'.
This patch adds a variable default_serial which says whenever a default serial line should be added. It is enabled by default. It is cleared when qemu finds '-serial' or '-device isa-serial' on the command line.
Part of the patch is some infrastructure for the '-device $driver' checking (default_driver_check function) which will also be used by the other patches of this series.
--- vl.c | 122 +++++++++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 81 insertions(+), 41 deletions(-)
vl.c +81 -41
@@ -272,6 +272,30 @@ uint8_t qemu_uuid[16];static QEMUBootSetHandler *boot_set_handler;static void *boot_set_opaque; +static int default_serial =1 ; + +static struct { +const char *driver; +int *flag; +} default_list[] = { + { .driver ="isa-serial" , .flag = &default_serial }, +}; + +static int default_driver_check (QemuOpts *opts,void *opaque) +{ +const char *driver =qemu_opt_get (opts,"driver" ); +int i; + +if (!driver) +return 0 ; +for (i =0 ; i <ARRAY_SIZE (default_list); i++) { +if (strcmp (default_list[i].driver, driver) !=0 ) +continue ; + *(default_list[i].flag) =0 ; + } +return 0 ; +} +/***********************************************************/ /* x86 ISA bus support */
@@ -4543,6 +4567,7 @@ struct device_config {enum {DEV_USB ,/* -usbdevice */ DEV_BT ,/* -bt */ +DEV_SERIAL ,/* -serial */ } type;const char *cmdline;QTAILQ_ENTRY (device_config) next;
@@ -4574,6 +4599,50 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))return 0 ; } +static void serial_monitor_mux (const char *monitor_devices[]) +{ +struct device_config *serial; +const char *devname; + +if (strcmp (monitor_devices[0 ],"stdio" ) !=0 ) +return ; + QTAILQ_FOREACH(serial, &device_configs, next) { +if (serial->type !=DEV_SERIAL ) +continue ; + devname = serial->cmdline; +if (devname && !strcmp (devname,"mon:stdio" )) { + monitor_devices[0 ] =NULL ; +break ; + }else if (devname && !strcmp (devname,"stdio" )) { + monitor_devices[0 ] =NULL ; + serial->cmdline ="mon:stdio" ; +break ; + } + } +} + +static int serial_parse (const char *devname) +{ +static int index =0 ; +char label[32 ]; + +if (strcmp (devname,"none" ) ==0 ) +return 0 ; +if (index ==MAX_SERIAL_PORTS ) { +fprintf (stderr,"qemu: too many serial ports\n" ); +exit (1 ); + } +snprintf (label,sizeof (label),"serial%d" , index); + serial_hds[index] =qemu_chr_open (label, devname,NULL ); +if (!serial_hds[index]) { +fprintf (stderr,"qemu: could not open serial device '%s': %s\n" , + devname,strerror (errno)); +return -1 ; + } + index++; +return 0 ; +} +int main (int argc,char **argv,char **envp) {const char *gdbstub_dev =NULL ;
@@ -4592,8 +4661,6 @@ int main(int argc, char **argv, char **envp)CharDriverState *monitor_hds[MAX_MONITOR_DEVICES ];const char *monitor_devices[MAX_MONITOR_DEVICES ];int monitor_device_index; -const char *serial_devices[MAX_SERIAL_PORTS ]; -int serial_device_index;const char *parallel_devices[MAX_PARALLEL_PORTS ];int parallel_device_index;const char *virtio_consoles[MAX_VIRTIO_CONSOLES ];
@@ -4663,11 +4730,6 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; - serial_devices[0 ] ="vc:80Cx24C" ; -for (i =1 ; i <MAX_SERIAL_PORTS ; i++) - serial_devices[i] =NULL ; - serial_device_index =0 ; - parallel_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_PARALLEL_PORTS ; i++) parallel_devices[i] =NULL ;
@@ -5114,12 +5176,8 @@ int main(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_serial: -if (serial_device_index >=MAX_SERIAL_PORTS ) { -fprintf (stderr,"qemu: too many serial ports\n" ); -exit (1 ); - } - serial_devices[serial_device_index] = optarg; - serial_device_index++; +add_device_config (DEV_SERIAL , optarg); + default_serial =0 ;break ;case QEMU_OPTION_watchdog:if (watchdog) {
@@ -5420,14 +5478,19 @@ int main(int argc, char **argv, char **envp)exit (1 ); } +qemu_opts_foreach (&qemu_device_opts, default_driver_check,NULL ,0 ); +if (display_type ==DT_NOGRAPHIC ) { -if (serial_device_index ==0 ) - serial_devices[0 ] ="stdio" ; +if (default_serial) +add_device_config (DEV_SERIAL ,"stdio" );if (parallel_device_index ==0 ) parallel_devices[0 ] ="null" ;if (strncmp (monitor_devices[0 ],"vc" ,2 ) ==0 ) { monitor_devices[0 ] ="stdio" ; } + }else { +if (default_serial) +add_device_config (DEV_SERIAL ,"vc:80Cx24C" ); }#ifndef _WIN32
@@ -5573,19 +5636,7 @@ int main(int argc, char **argv, char **envp) ram_load, NULL);/* Maintain compatibility with multiple stdio monitors */ -if (!strcmp (monitor_devices[0 ],"stdio" )) { -for (i =0 ; i <MAX_SERIAL_PORTS ; i++) { -const char *devname = serial_devices[i]; -if (devname && !strcmp (devname,"mon:stdio" )) { - monitor_devices[0 ] =NULL ; -break ; - }else if (devname && !strcmp (devname,"stdio" )) { - monitor_devices[0 ] =NULL ; - serial_devices[i] ="mon:stdio" ; -break ; - } - } - } +serial_monitor_mux (monitor_devices);if (nb_numa_nodes >0 ) {int i;
@@ -5647,19 +5698,8 @@ int main(int argc, char **argv, char **envp) } } -for (i =0 ; i <MAX_SERIAL_PORTS ; i++) { -const char *devname = serial_devices[i]; -if (devname &&strcmp (devname,"none" )) { -char label[32 ]; -snprintf (label,sizeof (label),"serial%d" , i); - serial_hds[i] =qemu_chr_open (label, devname,NULL ); -if (!serial_hds[i]) { -fprintf (stderr,"qemu: could not open serial device '%s': %s\n" , - devname,strerror (errno)); -exit (1 ); - } - } - } +if (foreach_device_config (DEV_SERIAL , serial_parse) <0 ) +exit (1 );for (i =0 ; i <MAX_PARALLEL_PORTS ; i++) {const char *devname = parallel_devices[i];
Signature · 1 line
1.6.2.5
PATCH 4/10 default devices: parallel port.
In reply to Gerd HoffmannQemu creates a default parallel port for you in case you didn't specify one on the command line. Right now this is tied to the '-parallel <chardev>' command line switch, which in turn causes trouble if you are creating your parallel port via '-device isa-parallel,<props>'.
This patch adds a variable default_parallel which says whenever a default parallel port should be added. It is enabled by default. It is cleared when qemu finds '-parallel' or '-device isa-parallel' on the command line.
--- vl.c | 64 ++++++++++++++++++++++++++++++++++------------------------------ 1 files changed, 34 insertions(+), 30 deletions(-)
vl.c +34 -30
@@ -273,12 +273,14 @@ static QEMUBootSetHandler *boot_set_handler;static void *boot_set_opaque;static int default_serial =1 ; +static int default_parallel =1 ;static struct {const char *driver;int *flag; } default_list[] = { - { .driver ="isa-serial" , .flag = &default_serial }, + { .driver ="isa-serial" , .flag = &default_serial }, + { .driver ="isa-parallel" , .flag = &default_parallel }, };static int default_driver_check (QemuOpts *opts,void *opaque)
@@ -4568,6 +4570,7 @@ struct device_config {DEV_USB ,/* -usbdevice */ DEV_BT ,/* -bt */ DEV_SERIAL ,/* -serial */ +DEV_PARALLEL ,/* -parallel */ } type;const char *cmdline;QTAILQ_ENTRY (device_config) next;
@@ -4643,6 +4646,28 @@ static int serial_parse(const char *devname)return 0 ; } +static int parallel_parse (const char *devname) +{ +static int index =0 ; +char label[32 ]; + +if (strcmp (devname,"none" ) ==0 ) +return 0 ; +if (index ==MAX_PARALLEL_PORTS ) { +fprintf (stderr,"qemu: too many parallel ports\n" ); +exit (1 ); + } +snprintf (label,sizeof (label),"parallel%d" , index); + parallel_hds[index] =qemu_chr_open (label, devname,NULL ); +if (!parallel_hds[index]) { +fprintf (stderr,"qemu: could not open parallel device '%s': %s\n" , + devname,strerror (errno)); +return -1 ; + } + index++; +return 0 ; +} +int main (int argc,char **argv,char **envp) {const char *gdbstub_dev =NULL ;
@@ -4661,8 +4686,6 @@ int main(int argc, char **argv, char **envp)CharDriverState *monitor_hds[MAX_MONITOR_DEVICES ];const char *monitor_devices[MAX_MONITOR_DEVICES ];int monitor_device_index; -const char *parallel_devices[MAX_PARALLEL_PORTS ]; -int parallel_device_index;const char *virtio_consoles[MAX_VIRTIO_CONSOLES ];int virtio_console_index;const char *loadvm =NULL ;
@@ -4730,11 +4753,6 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; - parallel_devices[0 ] ="vc:80Cx24C" ; -for (i =1 ; i <MAX_PARALLEL_PORTS ; i++) - parallel_devices[i] =NULL ; - parallel_device_index =0 ; -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) virtio_consoles[i] =NULL ; virtio_console_index =0 ;
@@ -5202,12 +5220,8 @@ int main(int argc, char **argv, char **envp) virtio_console_index++;break ;case QEMU_OPTION_parallel: -if (parallel_device_index >=MAX_PARALLEL_PORTS ) { -fprintf (stderr,"qemu: too many parallel ports\n" ); -exit (1 ); - } - parallel_devices[parallel_device_index] = optarg; - parallel_device_index++; +add_device_config (DEV_PARALLEL , optarg); + default_parallel =0 ;break ;case QEMU_OPTION_loadvm: loadvm = optarg;
@@ -5483,14 +5497,16 @@ int main(int argc, char **argv, char **envp)if (display_type ==DT_NOGRAPHIC ) {if (default_serial)add_device_config (DEV_SERIAL ,"stdio" ); -if (parallel_device_index ==0 ) - parallel_devices[0 ] ="null" ; +if (default_parallel) +add_device_config (DEV_PARALLEL ,"null" );if (strncmp (monitor_devices[0 ],"vc" ,2 ) ==0 ) { monitor_devices[0 ] ="stdio" ; } }else {if (default_serial)add_device_config (DEV_SERIAL ,"vc:80Cx24C" ); +if (default_parallel) +add_device_config (DEV_PARALLEL ,"vc:80Cx24C" ); }#ifndef _WIN32
@@ -5700,20 +5716,8 @@ int main(int argc, char **argv, char **envp)if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )exit (1 ); - -for (i =0 ; i <MAX_PARALLEL_PORTS ; i++) { -const char *devname = parallel_devices[i]; -if (devname &&strcmp (devname,"none" )) { -char label[32 ]; -snprintf (label,sizeof (label),"parallel%d" , i); - parallel_hds[i] =qemu_chr_open (label, devname,NULL ); -if (!parallel_hds[i]) { -fprintf (stderr,"qemu: could not open parallel device '%s': %s\n" , - devname,strerror (errno)); -exit (1 ); - } - } - } +if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 ) +exit (1 );for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) {const char *devname = virtio_consoles[i];
Signature · 1 line
1.6.2.5
PATCH 5/10 default devices: qemu monitor.
In reply to Gerd HoffmannThis patch makes the monitor default device configuration work like the default serial and parallel port devices. It adds a variable default_monitor which says whenever a default monitor should be added. It is enabled by default. It is cleared when qemu finds '-monitor' on the command line.
--- vl.c | 94 +++++++++++++++++++++++++++++++++++------------------------------- 1 files changed, 50 insertions(+), 44 deletions(-)
vl.c +50 -44
@@ -212,6 +212,7 @@ int no_quit = 0;CharDriverState *serial_hds[MAX_SERIAL_PORTS ];CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ];CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; +CharDriverState *monitor_hds[MAX_MONITOR_DEVICES ];#ifdef TARGET_I386 int win2k_install_hack =0 ;int rtc_td_hack =0 ;
@@ -274,6 +275,7 @@ static void *boot_set_opaque;static int default_serial =1 ;static int default_parallel =1 ; +static int default_monitor =1 ; static struct { const char *driver;
@@ -4571,6 +4573,7 @@ struct device_config {DEV_BT ,/* -bt */ DEV_SERIAL ,/* -serial */ DEV_PARALLEL ,/* -parallel */ +DEV_MONITOR ,/* -monitor */ } type;const char *cmdline;QTAILQ_ENTRY (device_config) next;
@@ -4602,22 +4605,27 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))return 0 ; } -static void serial_monitor_mux (const char *monitor_devices[]) +static void serial_monitor_mux (void ) { -struct device_config *serial; +struct device_config *mon0, *serial;const char *devname; -if (strcmp (monitor_devices[0 ],"stdio" ) !=0 ) -return ; + QTAILQ_FOREACH(mon0, &device_configs, next) { +if (mon0->type !=DEV_MONITOR ) +continue ; +if (strcmp (mon0->cmdline,"stdio" ) !=0 ) +return ; +break ; + } QTAILQ_FOREACH(serial, &device_configs, next) {if (serial->type !=DEV_SERIAL )continue ; devname = serial->cmdline;if (devname && !strcmp (devname,"mon:stdio" )) { - monitor_devices[0 ] =NULL ; +QTAILQ_REMOVE (&device_configs, mon0, next);break ; }else if (devname && !strcmp (devname,"stdio" )) { - monitor_devices[0 ] =NULL ; +QTAILQ_REMOVE (&device_configs, mon0, next); serial->cmdline ="mon:stdio" ;break ; }
@@ -4668,6 +4676,32 @@ static int parallel_parse(const char *devname)return 0 ; } +static int monitor_parse (const char *devname) +{ +static int index =0 ; +char label[32 ]; + +if (strcmp (devname,"none" ) ==0 ) +return 0 ; +if (index ==MAX_MONITOR_DEVICES ) { +fprintf (stderr,"qemu: too many monitor devices\n" ); +exit (1 ); + } +if (index ==0 ) { +snprintf (label,sizeof (label),"monitor" ); + }else { +snprintf (label,sizeof (label),"monitor%d" , index); + } + monitor_hds[index] =qemu_chr_open (label, devname,NULL ); +if (!monitor_hds[index]) { +fprintf (stderr,"qemu: could not open monitor device '%s'\n" , + devname); +return -1 ; + } + index++; +return 0 ; +} +int main (int argc,char **argv,char **envp) {const char *gdbstub_dev =NULL ;
@@ -4683,9 +4717,6 @@ int main(int argc, char **argv, char **envp)QemuOpts *hda_opts =NULL , *opts;int optind;const char *r, *optarg; -CharDriverState *monitor_hds[MAX_MONITOR_DEVICES ]; -const char *monitor_devices[MAX_MONITOR_DEVICES ]; -int monitor_device_index;const char *virtio_consoles[MAX_VIRTIO_CONSOLES ];int virtio_console_index;const char *loadvm =NULL ;
@@ -4757,12 +4788,6 @@ int main(int argc, char **argv, char **envp) virtio_consoles[i] =NULL ; virtio_console_index =0 ; - monitor_devices[0 ] ="vc:80Cx24C" ; -for (i =1 ; i <MAX_MONITOR_DEVICES ; i++) { - monitor_devices[i] =NULL ; - } - monitor_device_index =0 ; -for (i =0 ; i <MAX_NODES ; i++) { node_mem[i] =0 ; node_cpumask[i] =0 ;
@@ -5176,12 +5201,8 @@ int main(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_monitor: -if (monitor_device_index >=MAX_MONITOR_DEVICES ) { -fprintf (stderr,"qemu: too many monitor devices\n" ); -exit (1 ); - } - monitor_devices[monitor_device_index] = optarg; - monitor_device_index++; +add_device_config (DEV_MONITOR , optarg); + default_monitor =0 ;break ;case QEMU_OPTION_chardev: opts =qemu_opts_parse (&qemu_chardev_opts, optarg,"backend" );
@@ -5499,14 +5520,15 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_SERIAL ,"stdio" );if (default_parallel)add_device_config (DEV_PARALLEL ,"null" ); -if (strncmp (monitor_devices[0 ],"vc" ,2 ) ==0 ) { - monitor_devices[0 ] ="stdio" ; - } +if (default_monitor) +add_device_config (DEV_MONITOR ,"stdio" ); }else {if (default_serial)add_device_config (DEV_SERIAL ,"vc:80Cx24C" );if (default_parallel)add_device_config (DEV_PARALLEL ,"vc:80Cx24C" ); +if (default_monitor) +add_device_config (DEV_MONITOR ,"vc:80Cx24C" ); }#ifndef _WIN32
@@ -5652,7 +5674,7 @@ int main(int argc, char **argv, char **envp) ram_load, NULL);/* Maintain compatibility with multiple stdio monitors */ -serial_monitor_mux (monitor_devices); +serial_monitor_mux ();if (nb_numa_nodes >0 ) {int i;
@@ -5696,24 +5718,8 @@ int main(int argc, char **argv, char **envp) } } -for (i =0 ; i <MAX_MONITOR_DEVICES ; i++) { -const char *devname = monitor_devices[i]; -if (devname &&strcmp (devname,"none" )) { -char label[32 ]; -if (i ==0 ) { -snprintf (label,sizeof (label),"monitor" ); - }else { -snprintf (label,sizeof (label),"monitor%d" , i); - } - monitor_hds[i] =qemu_chr_open (label, devname,NULL ); -if (!monitor_hds[i]) { -fprintf (stderr,"qemu: could not open monitor device '%s'\n" , - devname); -exit (1 ); - } - } - } - +if (foreach_device_config (DEV_MONITOR , monitor_parse) <0 ) +exit (1 );if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )exit (1 );if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 )
@@ -5837,7 +5843,7 @@ int main(int argc, char **argv, char **envp)text_consoles_set_display (display_state);for (i =0 ; i <MAX_MONITOR_DEVICES ; i++) { -if (monitor_devices[i] && monitor_hds[i]) { +if (monitor_hds[i]) {monitor_init (monitor_hds[i],MONITOR_USE_READLINE | ((i ==0 ) ?MONITOR_IS_DEFAULT :0 ));
Signature · 1 line
1.6.2.5
PATCH 6/10 zap serial_monitor_mux
In reply to Gerd HoffmannThe logic in this code obviously predates the multiple monitor capability of qemu and looks increasingly silly these days.
I think the intention of this piece of code is to get a reasonable default for the -nographic case: have monitor and serial line muxed on stdio.
With the new default_serial and default_monitor variables we have now doing just that became much easier ;)
--- vl.c | 42 ++++++++---------------------------------- 1 files changed, 8 insertions(+), 34 deletions(-)
vl.c +8 -34
@@ -4605,33 +4605,6 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))return 0 ; } -static void serial_monitor_mux (void ) -{ -struct device_config *mon0, *serial; -const char *devname; - - QTAILQ_FOREACH(mon0, &device_configs, next) { -if (mon0->type !=DEV_MONITOR ) -continue ; -if (strcmp (mon0->cmdline,"stdio" ) !=0 ) -return ; -break ; - } - QTAILQ_FOREACH(serial, &device_configs, next) { -if (serial->type !=DEV_SERIAL ) -continue ; - devname = serial->cmdline; -if (devname && !strcmp (devname,"mon:stdio" )) { -QTAILQ_REMOVE (&device_configs, mon0, next); -break ; - }else if (devname && !strcmp (devname,"stdio" )) { -QTAILQ_REMOVE (&device_configs, mon0, next); - serial->cmdline ="mon:stdio" ; -break ; - } - } -} -static int serial_parse (const char *devname) {static int index =0 ;
@@ -5516,12 +5489,16 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (&qemu_device_opts, default_driver_check,NULL ,0 );if (display_type ==DT_NOGRAPHIC ) { -if (default_serial) -add_device_config (DEV_SERIAL ,"stdio" );if (default_parallel)add_device_config (DEV_PARALLEL ,"null" ); -if (default_monitor) -add_device_config (DEV_MONITOR ,"stdio" ); +if (default_serial && default_monitor) { +add_device_config (DEV_SERIAL ,"mon:stdio" ); + }else { +if (default_serial) +add_device_config (DEV_SERIAL ,"stdio" ); +if (default_monitor) +add_device_config (DEV_MONITOR ,"stdio" ); + } }else {if (default_serial)add_device_config (DEV_SERIAL ,"vc:80Cx24C" );
@@ -5673,9 +5650,6 @@ int main(int argc, char **argv, char **envp)register_savevm_live ("ram" ,0 ,3 ,NULL , ram_save_live,NULL , ram_load,NULL ); -/* Maintain compatibility with multiple stdio monitors */ -serial_monitor_mux (); -if (nb_numa_nodes >0 ) {int i;
Signature · 1 line
1.6.2.5
PATCH 7/10 default devices: vga adapter.
In reply to Gerd HoffmannQemu creates a vga display for you in case you didn't specify one on the command line. Right now this is tied to the '-vga <type>' command line switch, which in turn causes trouble if you are creating your gfx card using '-device VGA,<props>'.
This patch adds a variable default_vga which says whenever a default serial line should be added. It is enabled by default. It is cleared when qemu finds '-vga' or '-device {VGA,Cirrus VGA,QEMUware SVGA}' on the command line.
'-device VGA' still doesn't work though due to a initialization order issue (vga must init before calling i440fx_init_memory_mappings).
--- vl.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
vl.c +8 -1
@@ -194,7 +194,7 @@ int autostart;static int rtc_utc =1 ;static int rtc_date_offset =-1 ;/* -1 means no change */ QEMUClock *rtc_clock; -int vga_interface_type =VGA_CIRRUS ; +int vga_interface_type =VGA_NONE ;#ifdef TARGET_SPARC int graphic_width =1024 ;int graphic_height =768 ;
@@ -276,6 +276,7 @@ static void *boot_set_opaque;static int default_serial =1 ;static int default_parallel =1 ;static int default_monitor =1 ; +static int default_vga =1 ; static struct { const char *driver;
@@ -283,6 +284,9 @@ static struct { } default_list[] = { { .driver = "isa-serial", .flag = &default_serial }, { .driver = "isa-parallel", .flag = &default_parallel }, + { .driver = "VGA", .flag = &default_vga }, + { .driver = "Cirrus VGA", .flag = &default_vga }, + { .driver = "QEMUware SVGA", .flag = &default_vga }, }; static int default_driver_check(QemuOpts *opts, void *opaque)
@@ -4326,6 +4330,7 @@ static void select_vgahw (const char *p) {const char *opts; + default_vga =0 ; vga_interface_type =VGA_NONE ;if (strstart (p,"std" , &opts)) { vga_interface_type =VGA_STD ;
@@ -5507,6 +5512,8 @@ int main(int argc, char **argv, char **envp)if (default_monitor)add_device_config (DEV_MONITOR ,"vc:80Cx24C" ); } +if (default_vga) + vga_interface_type =VGA_CIRRUS ;#ifndef _WIN32if (daemonize) {
Signature · 1 line
1.6.2.5
PATCH 8/10 default devices: add global cmd line option.
In reply to Gerd HoffmannAdd global command line option to disable default devices.
--- qemu-options.hx | 5 +++++ vl.c | 6 ++++++ 2 files changed, 11 insertions(+), 0 deletions(-)
qemu-options.hx +5 -0
@@ -1878,6 +1878,11 @@ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ STEXI ETEXI +DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \ + "-nodefaults don't create default devices.\n") +STEXI +ETEXI + #ifndef _WIN32 DEF("chroot", HAS_ARG, QEMU_OPTION_chroot, \ "-chroot dir Chroot to dir just before starting the VM.\n")
vl.c +6 -0
@@ -5413,6 +5413,12 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_incoming: incoming = optarg;break ; +case QEMU_OPTION_nodefaults: + default_serial =0 ; + default_parallel =0 ; + default_monitor =0 ; + default_vga =0 ; +break ;#ifndef _WIN32case QEMU_OPTION_chroot: chroot_dir = optarg;
Signature · 1 line
1.6.2.5
PATCH 9/10 default devices: network
In reply to Gerd HoffmannAdd a default_net variable which specified whenever a default network should be created. It is cleared in case any -net option is specified and it is also added to the new -nodefaults switch.
--- net.c | 5 ++++- net.h | 1 + vl.c | 1 + 3 files changed, 6 insertions(+), 1 deletions(-)
net.c +4 -1
@@ -112,6 +112,8 @@ static QTAILQ_HEAD(, VLANState) vlans; static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; +int default_net =1 ; +/***********************************************************/ /* network device redirectors */
@@ -2834,7 +2836,7 @@ static int net_init_netdev(QemuOpts *opts, void *dummy)int net_init_clients (void ) { -if (QTAILQ_EMPTY (&qemu_net_opts.head)) { +if (default_net) {/* if no clients, we use a default config */ qemu_opts_set (&qemu_net_opts,NULL ,"type" ,"nic" );#ifdef CONFIG_SLIRP
@@ -2887,5 +2889,6 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg)return -1 ; } + default_net =0 ;return 0 ; }
net.h +1 -0
@@ -133,6 +133,7 @@ struct NICInfo {extern int nb_nics;extern NICInfo nd_table[MAX_NICS ]; +extern int default_net;/* BT HCI info */
vl.c +1 -0
@@ -5418,6 +5418,7 @@ int main(int argc, char **argv, char **envp) default_parallel =0 ; default_monitor =0 ; default_vga =0 ; + default_net =0 ;break ;#ifndef _WIN32case QEMU_OPTION_chroot:
Signature · 1 line
1.6.2.5
PATCH 10/10 default devices: drives
In reply to Gerd HoffmannAdd a default_drive variable which specified whenever the default drives (cdrom, floppy, sd) should be created. It is cleared when the new -nodefaults switch is specified on the command line.
--- vl.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
vl.c +10 -6
@@ -277,6 +277,7 @@ static int default_serial = 1;static int default_parallel =1 ;static int default_monitor =1 ;static int default_vga =1 ; +static int default_drive =1 ; static struct { const char *driver;
@@ -5419,6 +5420,7 @@ int main(int argc, char **argv, char **envp) default_monitor =0 ; default_vga =0 ; default_net =0 ; + default_drive =0 ;break ;#ifndef _WIN32case QEMU_OPTION_chroot:
@@ -5645,14 +5647,16 @@ int main(int argc, char **argv, char **envp)blk_mig_init (); -/* we always create the cdrom drive, even if no disk is there */ -drive_add (NULL ,CDROM_ALIAS ); +if (default_drive) { +/* we always create the cdrom drive, even if no disk is there */ +drive_add (NULL ,CDROM_ALIAS ); -/* we always create at least one floppy */ -drive_add (NULL ,FD_ALIAS ,0 ); +/* we always create at least one floppy */ +drive_add (NULL ,FD_ALIAS ,0 ); -/* we always create one sd slot, even if no card is in it */ -drive_add (NULL ,SD_ALIAS ); +/* we always create one sd slot, even if no card is in it */ +drive_add (NULL ,SD_ALIAS ); + }/* open the virtual block devices */ if (snapshot)
Signature · 1 line
1.6.2.5
Quoted 10 lines · Gerd Hoffmann
Hi,
Qemu creates a bunch of default devices (serial, parallel, vga, ...) if the user didn't specify one on the command line. Unfortunaly this doesn't work well with the qdev way of doing things because this logic is tied to the -serial, -parallel, ... command line switches. Devices created via -device are ignored. This patch set fixes this. It also adds a command line switch to disable all default devices and does a few cleanups in the code touched anyway.
Quoted 2 lines
cheers,
Gerd
Looks good.