default devices: qdev integration.
v3 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.
New in v3: Rebased against latest master. Two patches (qmp monitor + s390 console) came into the way. Because the way how serial lines and the monitor are initialized changes quite heavily it looked alot cleaner to me just revert those patches, apply the v2 patches, then reimplement the two patches on top of that.
For the snake of simplifying testing of this series three patches where added (patches 13,14,15) which are already in staging. They can just be dropped when merging. When needed I can create a v4 without them (after they got merged into master).
Luiz + Alex, please have a closer look at this.
http://repo.or.cz/w/qemu/kraxel.git/shortlog/refs/heads/default.v3
thanks,
Gerd
PATCH v3 1/21 Revert "monitor: Command-line flag to enable control mode"
This reverts commit adcb181afe5a951c521411c7a8e9d9b791aa6742.
Conflicts:
monitor.h
--- monitor.c | 18 ------------------ monitor.h | 1 - qemu-options.hx | 5 ++--- vl.c | 11 ++++------- 4 files changed, 6 insertions(+), 29 deletions(-)
monitor.c +0 -18
@@ -4008,24 +4008,6 @@ static void monitor_event(void *opaque, int event)* End: */ -const char *monitor_cmdline_parse (const char *cmdline,int *flags) -{ -const char *dev; - -if (strstart (cmdline,"control," , &dev)) { -if (strstart (dev,"vc" ,NULL )) { -fprintf (stderr,"qemu: control mode is for low-level interaction " ); -fprintf (stderr,"cannot be used with device 'vc'\n" ); -exit (1 ); - } - *flags &= ~MONITOR_USE_READLINE ; - *flags |=MONITOR_USE_CONTROL ; -return dev; - } - -return cmdline; -} -void monitor_init (CharDriverState *chr,int flags) {static int is_first_init =1 ;
monitor.h +0 -1
@@ -24,7 +24,6 @@ typedef enum MonitorEvent { } MonitorEvent;void monitor_protocol_event (MonitorEvent event,QObject *data); -const char *monitor_cmdline_parse (const char *cmdline,int *flags);void monitor_init (CharDriverState *chr,int flags);int monitor_suspend (Monitor *mon);
qemu-options.hx +2 -3
@@ -1577,14 +1577,13 @@ Use @code{-parallel none} to disable all parallel ports. ETEXI DEF("monitor", HAS_ARG, QEMU_OPTION_monitor, \ - "-monitor [control,]dev redirect the monitor to char device 'dev'\n") + "-monitor dev redirect the monitor to char device 'dev'\n") STEXI -@item -monitor [@var{control},]@var{dev} +@item -monitor @var{dev} Redirect the monitor to host device @var{dev} (same devices as the serial port). The default device is @code{vc} in graphical mode and @code{stdio} in non graphical mode. -The option @var{control} enables the QEMU Monitor Protocol. ETEXI DEF("pidfile", HAS_ARG, QEMU_OPTION_pidfile, \
vl.c +4 -7
@@ -4638,7 +4638,6 @@ int main(int argc, char **argv, char **envp)const char *r, *optarg;CharDriverState *monitor_hds[MAX_MONITOR_DEVICES ];const char *monitor_devices[MAX_MONITOR_DEVICES ]; -int monitor_flags[MAX_MONITOR_DEVICES ];int monitor_device_index;const char *serial_devices[MAX_SERIAL_PORTS ];int serial_device_index;
@@ -4741,10 +4740,8 @@ int main(int argc, char **argv, char **envp)#endif monitor_devices[0 ] ="vc:80Cx24C" ; - monitor_flags[0 ] =MONITOR_IS_DEFAULT |MONITOR_USE_READLINE ;for (i =1 ; i <MAX_MONITOR_DEVICES ; i++) { monitor_devices[i] =NULL ; - monitor_flags[i] =MONITOR_USE_READLINE ; } monitor_device_index =0 ;
@@ -5165,9 +5162,7 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"qemu: too many monitor devices\n" );exit (1 ); } - monitor_devices[monitor_device_index] = -monitor_cmdline_parse (optarg, - &monitor_flags[monitor_device_index]); + monitor_devices[monitor_device_index] = optarg; monitor_device_index++;break ;case QEMU_OPTION_chardev:
@@ -5875,7 +5870,9 @@ int main(int argc, char **argv, char **envp)for (i =0 ; i <MAX_MONITOR_DEVICES ; i++) {if (monitor_devices[i] && monitor_hds[i]) { -monitor_init (monitor_hds[i], monitor_flags[i]); +monitor_init (monitor_hds[i], +MONITOR_USE_READLINE | + ((i ==0 ) ?MONITOR_IS_DEFAULT :0 )); } }
Signature · 1 line
1.6.5.2
PATCH v3 2/21 Revert "Set default console to virtio on S390x"
In reply to Gerd HoffmannThis reverts commit 93d434b4aec0702b87ebf52449a3cdf2c3596825.
--- vl.c | 26 -------------------------- 1 files changed, 0 insertions(+), 26 deletions(-)
vl.c +0 -26
@@ -4710,20 +4710,6 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; -#ifdef TARGET_S390X -for (i =0 ; i <MAX_SERIAL_PORTS ; i++) - serial_devices[i] =NULL ; - serial_device_index =0 ; - -for (i =0 ; i <MAX_PARALLEL_PORTS ; i++) - parallel_devices[i] =NULL ; - parallel_device_index =0 ; - - virtio_consoles[0 ] ="mon:stdio" ; -for (i =1 ; i <MAX_VIRTIO_CONSOLES ; i++) - virtio_consoles[i] =NULL ; - virtio_console_index =0 ; -#else serial_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_SERIAL_PORTS ; i++) serial_devices[i] =NULL ;
@@ -4737,7 +4723,6 @@ int main(int argc, char **argv, char **envp)for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) virtio_consoles[i] =NULL ; virtio_console_index =0 ; -#endif monitor_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_MONITOR_DEVICES ; i++) {
@@ -5650,17 +5635,6 @@ int main(int argc, char **argv, char **envp)break ; } } -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) { -const char *devname = virtio_consoles[i]; -if (devname && !strcmp (devname,"mon:stdio" )) { - monitor_devices[0 ] =NULL ; -break ; - }else if (devname && !strcmp (devname,"stdio" )) { - monitor_devices[0 ] =NULL ; - virtio_consoles[i] ="mon:stdio" ; -break ; - } - } }if (nb_numa_nodes >0 ) {
Signature · 1 line
1.6.5.2
PATCH v3 3/21 chardev: move greeting into vc backend.
In reply to Gerd HoffmannMake 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
@@ -5850,30 +5850,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.5.2
PATCH v3 4/21 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.5.2
PATCH v3 5/21 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
@@ -271,6 +271,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 */
@@ -4590,6 +4614,7 @@ struct device_config {enum {DEV_USB ,/* -usbdevice */ DEV_BT ,/* -bt */ +DEV_SERIAL ,/* -serial */ } type;const char *cmdline;QTAILQ_ENTRY (device_config) next;
@@ -4621,6 +4646,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 ;
@@ -4639,8 +4708,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 ];
@@ -4710,11 +4777,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 ;
@@ -5161,12 +5223,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) {
@@ -5467,14 +5525,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
@@ -5623,19 +5686,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;
@@ -5697,19 +5748,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.5.2
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 23 lines · Gerd Hoffmann
Qemu 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_serialwhich 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_checkfunction) which will also be used by the other patches of this series.Signed-off-by Gerd Hoffmann <[email protected]>---
vl.c| 122 +++++++++++++++++++++++++++++++++++++++++++----------------------1 files changed, 81 insertions(+), 41 deletions(-)vl.c +0
-0
vl.c uint8_t qemu_uuid[16]; · line 274
Quoted 4 lines
vl.c +1
-0@@ -271,6 +271,30 @@ uint8_t qemu_uuid[16];static QEMUBootSetHandler *boot_set_handler;static void *boot_set_opaque; +static int default_serial =1 ;
Default variables belong in the machine description IMHO. On S390, we can't create serial, parallel or vga (or any MMIO/PIO requiring) devices.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 10 lines · Alexander Graf
Quoted 6 lines
vl.c index 24d5d92..eca4eee 100644 --- a/vl.c renamed from vl.c +1
-0+++ b/vl.c @@ -271,6 +271,30 @@ uint8_t qemu_uuid[16]; staticQEMUBootSetHandler
*boot_set_handler; static void*boot_set_opaque;+static int
default_serial= 1;Default variables belong in the machine description IMHO. On S390, we can't create serial, parallel or vga (or any MMIO/PIO requiring) devices.
See last patch of this series. Moving that into the machine description is certainly worth looking at. For now I'm happy that the #ifdef S390 code for the default virtio console is down to just two lines.
cheers
Gerd
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Alexander Graf
Quoted 5 lines
vl.c index 24d5d92..eca4eee 100644 --- a/vl.c renamed from vl.c +1
-0+++ b/vl.c @@ -271,6 +271,30 @@ uint8_t qemu_uuid[16]; staticQEMUBootSetHandler
*boot_set_handler; static void*boot_set_opaque;
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
+static int
default_serial= 1;Default variables belong in the machine description IMHO. On S390, we can't create serial, parallel or vga (or any MMIO/PIO requiring) devices.
See last patch of this series. Moving that into the machine description is certainly worth looking at. For now I'm happy that the #ifdef S390 code for the default virtio console is down to just two lines.
Would it be that hard to move the list of default devices to the machine description? You could probably still keep the default_xxx variables in vl.c, but access them from e.g. pc.c.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines
Default variables belong in the machine description IMHO. On S390, we can't create serial, parallel or vga (or any MMIO/PIO requiring) devices.
Quoted 8 lines
Quoted 4 lines
See last patch of this series. Moving that into the machine description is certainly worth looking at. For now I'm happy that the #ifdef S390 code for the default virtio console is down to just two lines.
Would it be that hard to move the list of default devices to the machine description? You could probably still keep the
default_xxxvariables invl.c, but access them from e.g.pc.c.
Hmm? access from pc.c? What exactly do you have in mind?
I think we could add flags to QEMUMachine to disable default devices not supported anyway, i.e. add no_parallel variable, then in vl.c do
if (machine->no_parallel)
default_parallel = 0;So qemu would stop creating a useless parallel0 chardev which isn't used because the machine in question can't support parallel ports anyway.
cheers,
Gerd
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 21 lines · Gerd Hoffmann
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines
Default variables belong in the machine description IMHO. On S390, we can't create serial, parallel or vga (or any MMIO/PIO requiring) devices.
Quoted 8 lines
Quoted 4 lines
See last patch of this series. Moving that into the machine description is certainly worth looking at. For now I'm happy that the #ifdef S390 code for the default virtio console is down to just two lines.
Would it be that hard to move the list of default devices to the machine description? You could probably still keep the
default_xxxvariables invl.c, but access them from e.g.pc.c.Hmm? access from
pc.c? What exactly do you have in mind?
Quoted 6 lines
I think we could add flags to QEMUMachine to disable default devices not supported anyway, i.e. add
no_parallelvariable, then invl.cdoif (machine->no_parallel) default_parallel = 0;So qemu would stop creating a useless parallel0 chardev which isn't used because the machine in question can't support parallel ports anyway.
Well I was basically thinking of moving default_list inside the machine description. That way you can easily choose what default devices there are available.
Then make default_serial and friends visible to pc.c and just put the same code you have now in there. For other machines the default device list surely looks different.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 3 lines · Alexander Graf
Well I was basically thinking of moving
default_listinside the machine description. That way you can easily choose what default devices there are available.
Doesn't make sense. The list is not about *creating* default devices, but about *not* creating them.
Quoted 3 lines
Then make
default_serialand friends visible topc.cand just put the same code you have now in there. For other machines the default device list surely looks different.
ppc, sparc and x86 serial devices can happily live together in this list without causing any harm.
cheers,
Gerd
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 6 lines · Gerd Hoffmann
Quoted 3 lines · Alexander Graf
Well I was basically thinking of moving
default_listinside the machine description. That way you can easily choose what default devices there are available.Doesn't make sense. The list is not about *creating* default devices, but about *not* creating them.
Why do we need a negative list? Wouldn't it be a lot more useful to have positive lists? Maybe I'm just missing the whole point of your patchset though.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Hi,
Quoted 3 lines
Quoted 1 line
Doesn't make sense. The list is not about *creating* default devices, but about *not* creating them.
Why do we need a negative list? Wouldn't it be a lot more useful to have positive lists? Maybe I'm just missing the whole point of your patchset though.
Probably the latter ;)
The situation we have right is (with the serial lines as example, the same applies to some other devices as well):
(1) If you start qemu without any arguments, it will automagically
create a chardev for the serial line (serial_hds[]), which then
will be used by machine->init() to create the (board-specific)
serial lines.
(2) If you start qemu with -serial <something> the specified chardev
will be created and assigned to serial_hds[], which again will be
used by machine->init() ...Worked fine before qdev appeared. Now we also can create serial lines like this:
(3) Start qemu with '-device isa-serial,...'.
Problem is this clashes with (1) and qemu will attempt to create the serial port twice. So this patchset introduces default_serial (+friends) to fix this issue. The new workflow is:
* default_serial defaults to enabled, when qemu finds it still enabled after processing all command line the automagic default serial line is actually created.
* If qemu finds '-serial <something>' it clears default_serial.
* If qemu finds '-device isa-serial,...' it clears default_serial.
- this fixes the conflict mentioned above.
- other serial drivers can be added to the list if needed to solve the same conflict for them.
* If qemu finds '-nodefaults' it clears default_serial (and the others).
- new feature, figured this could be useful.
What we could do on top of the above is:
* If the board has the machine->no_serial flag set, clear default_serial.
s390 could set that flag then and qemu would stop creating a chardev for a serial line nobody will ever use because s390 has no serial ports.
/me hopes the whole picture is more clear now.
cheers,
Gerd
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
In reply to Gerd HoffmannQuoted 23 lines · Gerd Hoffmann
Qemu 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_serialwhich 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_checkfunction) which will also be used by the other patches of this series.Signed-off-by Gerd Hoffmann <[email protected]>---
vl.c| 122 +++++++++++++++++++++++++++++++++++++++++++----------------------1 files changed, 81 insertions(+), 41 deletions(-)vl.c +0
-0
vl.c uint8_t qemu_uuid[16]; · line 280
Quoted 10 lines
vl.c +7
-0@@ -271,6 +271,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 },
What is the "isa-serial" driver supposed to say here? Is that the qdev driver name? If so, that's just plain wrong. PPC for example uses the ESCC chip to export its serial port.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 05/21] default devices: core code & serial lines.
Quoted 8 lines · Alexander Graf
Quoted 4 lines · Gerd Hoffmann
Qemu 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>'.
Quoted 10 lines
vl.c uint8_t qemu_uuid[16];
Quoted 7 lines
vl.c +7
-0+static int default_serial =1 ; + +static struct { +const char *driver; +int *flag; +} default_list[] = { + { .driver ="isa-serial" , .flag =&default_serial },What is the "isa-serial" driver supposed to say here?
Yes.
Quoted 1 line
Is that the qdev driver name? If so, that's just plain wrong. PPC for example uses the ESCC chip to export its serial port.
Just add the driver name to the list then, so '-device ESCC,...' (or however it is named in qdev) will stop conflicting with the automagically created -serial port too.
cheers,
Gerd
PATCH v3 6/21 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
@@ -272,12 +272,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)
@@ -4615,6 +4617,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;
@@ -4690,6 +4693,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 ;
@@ -4708,8 +4733,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 ;
@@ -4777,11 +4800,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 ;
@@ -5249,12 +5267,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;
@@ -5530,14 +5544,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
@@ -5750,20 +5766,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.5.2
PATCH v3 7/21 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
@@ -211,6 +211,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 ;
@@ -273,6 +274,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;
@@ -4618,6 +4620,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;
@@ -4649,22 +4652,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 ; }
@@ -4715,6 +4723,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 ;
@@ -4730,9 +4764,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 ;
@@ -4804,12 +4835,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 ;
@@ -5223,12 +5248,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" );
@@ -5546,14 +5567,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
@@ -5702,7 +5724,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;
@@ -5746,24 +5768,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 )
@@ -5887,7 +5893,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.5.2
PATCH v3 8/21 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
@@ -4652,33 +4652,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 ;
@@ -5563,12 +5536,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" );
@@ -5723,9 +5700,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.5.2
PATCH v3 9/21 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
@@ -193,7 +193,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 ;
@@ -275,6 +275,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;
@@ -282,6 +283,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)
@@ -4373,6 +4377,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 ;
@@ -5554,6 +5559,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.5.2
PATCH v3 10/21 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
@@ -5460,6 +5460,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.5.2
[Qemu-devel] Re: [FOR 0.12 PATCH v3 10/21] default devices: add global cmd line option.
Quoted 1 line · Gerd Hoffmann
Add global command line option to disable default devices.
Should -readconfig imply this?
Paolo
Re: [Qemu-devel] Re: [FOR 0.12 PATCH v3 10/21] default devices: add global cmd line option.
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Gerd Hoffmann
Add global command line option to disable default devices.
Should -readconfig imply this?
Hmm, not sure. Why do you think this would be useful?
cheers,
Gerd
PATCH v3 11/21 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
@@ -39,6 +39,8 @@ static QTAILQ_HEAD(, VLANState) vlans; static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; +int default_net =1 ; +/***********************************************************/ /* network device redirectors */
@@ -1317,7 +1319,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
@@ -1353,5 +1355,6 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg)return -1 ; } + default_net =0 ;return 0 ; }
net.h +1 -0
@@ -139,6 +139,7 @@ struct NICInfo {extern int nb_nics;extern NICInfo nd_table[MAX_NICS ]; +extern int default_net;/* BT HCI info */
vl.c +1 -0
@@ -5465,6 +5465,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.5.2
PATCH v3 12/21 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
@@ -276,6 +276,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;
@@ -5466,6 +5467,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:
@@ -5695,14 +5697,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.5.2
PATCH v3 13/21 qdev: make compat stuff more generic
In reply to Gerd HoffmannThis patch renames the compat properties into global properties and makes them more generic. The compatibility stuff is only one of multiple possible users now.
--- hw/boards.h | 2 +- hw/pc.c | 2 +- hw/qdev-properties.c | 22 ++++++++++++++-------- hw/qdev.c | 2 +- hw/qdev.h | 10 ++++++---- vl.c | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-)
hw/boards.h +1 -1
@@ -20,7 +20,7 @@ typedef struct QEMUMachine {int use_scsi;int max_cpus;int is_default; -CompatProperty *compat_props; +GlobalProperty *compat_props;struct QEMUMachine *next; } QEMUMachine;
hw/pc.c +1 -1
@@ -1298,7 +1298,7 @@ static QEMUMachine pc_machine_v0_10 = { .desc = "Standard PC, qemu 0.10", .init = pc_init_pci, .max_cpus = 255, - .compat_props = (CompatProperty []) { + .compat_props = (GlobalProperty []) { { .driver ="virtio-blk-pci" , .property ="class" ,
hw/qdev-properties.c +14 -8
@@ -593,21 +593,27 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props) } } -static CompatProperty *compat_props; +static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props); -void qdev_prop_register_compat (CompatProperty *props) +void qdev_prop_register_global (GlobalProperty *prop) { - compat_props = props; +QTAILQ_INSERT_TAIL (&global_props, prop, next); } -void qdev_prop_set_compat (DeviceState *dev) +void qdev_prop_register_global_list (GlobalProperty *props) { -CompatProperty *prop; +int i; -if (!compat_props) { -return ; +for (i =0 ; props[i].driver !=NULL ; i++) { +qdev_prop_register_global (props+i); } -for (prop = compat_props; prop->driver !=NULL ; prop++) { +} + +void qdev_prop_set_globals (DeviceState *dev) +{ +GlobalProperty *prop; + + QTAILQ_FOREACH(prop, &global_props, next) {if (strcmp (dev->info->name, prop->driver) !=0 ) {continue ; }
hw/qdev.c +1 -1
@@ -103,7 +103,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev->parent_bus = bus;qdev_prop_set_defaults (dev, dev->info->props);qdev_prop_set_defaults (dev, dev->parent_bus->info->props); -qdev_prop_set_compat (dev); +qdev_prop_set_globals (dev);QLIST_INSERT_HEAD (&bus->children, dev, sibling);if (qdev_hotplug) {assert (bus->allow_hotplug);
hw/qdev.h +6 -4
@@ -92,11 +92,12 @@ struct PropertyInfo {int (*print)(DeviceState *dev,Property *prop,char *dest,size_t len); }; -struct CompatProperty { +typedef struct GlobalProperty {const char *driver;const char *property;const char *value; -}; +QTAILQ_ENTRY (GlobalProperty) next; +}GlobalProperty ;/*** Board API. This should go away once we have a machine config file. ***/
@@ -256,8 +257,9 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);void qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value);void qdev_prop_set_defaults (DeviceState *dev,Property *props); -void qdev_prop_register_compat (CompatProperty *props); -void qdev_prop_set_compat (DeviceState *dev); +void qdev_prop_register_global (GlobalProperty *prop); +void qdev_prop_register_global_list (GlobalProperty *props); +void qdev_prop_set_globals (DeviceState *dev);/* This is a nasty hack to allow passing a NULL bus to qdev_create. */ extern struct BusInfo system_bus_info;
vl.c +1 -1
@@ -5790,7 +5790,7 @@ int main(int argc, char **argv, char **envp) }if (machine->compat_props) { -qdev_prop_register_compat (machine->compat_props); +qdev_prop_register_global_list (machine->compat_props); } machine->init (ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
Signature · 1 line
1.6.5.2
PATCH v3 14/21 qdev: add command line option to set global defaults for properties.
In reply to Gerd HoffmannThis patch adds infrastructure and command line option for setting global defaults for device properties, i.e. you can for example use
-global virtio-blk-pci.vectors=0
to turn off msi by default for all virtio block devices. The config file syntax is:
[global]
driver = "virtio-blk-pci"
property = "vectors"
value = "0"
This can also be used to set properties for devices which are not created via -device but implicitly via machine init, i.e.
-global isa-fdc,driveA=<name>
This patch uses the mechanism which configures properties for the compatibility machine types (pc-0.10 & friends). The command line takes precedence over the machine type values.
--- qemu-config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config.h | 2 + qemu-options.hx | 3 ++ vl.c | 6 +++++ 4 files changed, 67 insertions(+), 0 deletions(-)
qemu-config.c +56 -0
@@ -2,6 +2,7 @@#include "qemu-option.h" #include "qemu-config.h" #include "sysemu.h" +#include "hw/qdev.h" QemuOptsList qemu_drive_opts = { .name ="drive" ,
@@ -205,6 +206,24 @@ QemuOptsList qemu_rtc_opts = { }, }; +QemuOptsList qemu_global_opts = { + .name ="global" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_global_opts.head), + .desc = { + { + .name ="driver" , + .type =QEMU_OPT_STRING , + },{ + .name ="property" , + .type =QEMU_OPT_STRING , + },{ + .name ="value" , + .type =QEMU_OPT_STRING , + }, + {/* end if list */ } + }, +}; +static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts,
@@ -212,6 +231,7 @@ static QemuOptsList *lists[] = { &qemu_netdev_opts, &qemu_net_opts, &qemu_rtc_opts, + &qemu_global_opts, NULL, };
@@ -260,6 +280,42 @@ int qemu_set_option(const char *str)return 0 ; } +int qemu_global_option (const char *str) +{ +char driver[64 ], property[64 ]; +QemuOpts *opts; +int rc, offset; + + rc =sscanf (str,"%63[^.].%63[^=]%n" , driver, property, &offset); +if (rc <2 || str[offset] !='=' ) { +qemu_error ("can't parse: \"%s\"\n" , str); +return -1 ; + } + + opts =qemu_opts_create (&qemu_global_opts,NULL ,0 ); +qemu_opt_set (opts,"driver" , driver); +qemu_opt_set (opts,"property" , property); +qemu_opt_set (opts,"value" , str+offset+1 ); +return 0 ; +} + +static int qemu_add_one_global (QemuOpts *opts,void *opaque) +{ +GlobalProperty *g; + + g =qemu_mallocz (sizeof (*g)); + g->driver =qemu_opt_get (opts,"driver" ); + g->property =qemu_opt_get (opts,"property" ); + g->value =qemu_opt_get (opts,"value" ); +qdev_prop_register_global (g); +return 0 ; +} + +void qemu_add_globals (void ) +{ +qemu_opts_foreach (&qemu_global_opts, qemu_add_one_global,NULL ,0 ); +} +struct ConfigWriteData {QemuOptsList *list;FILE *fp;
qemu-config.h +2 -0
@@ -9,6 +9,8 @@ extern QemuOptsList qemu_net_opts;extern QemuOptsList qemu_rtc_opts;int qemu_set_option (const char *str); +int qemu_global_option (const char *str); +void qemu_add_globals (void );void qemu_config_write (FILE *fp);int qemu_config_parse (FILE *fp);
qemu-options.hx +3 -0
@@ -109,6 +109,9 @@ DEF("set", HAS_ARG, QEMU_OPTION_set, "-set group.id.arg=value\n" " set <arg> parameter for item <id> of type <group>\n" " i.e. -set drive.$id.file=/path/to/image\n") +DEF("global", HAS_ARG, QEMU_OPTION_global, + "-global driver.property=value\n" + " set a global default for a driver property\n") STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
vl.c +6 -0
@@ -4917,6 +4917,10 @@ int main(int argc, char **argv, char **envp)if (qemu_set_option (optarg) !=0 )exit (1 );break ; +case QEMU_OPTION_global: +if (qemu_global_option (optarg) !=0 ) +exit (1 ); +break ;case QEMU_OPTION_mtdblock:drive_add (optarg,MTD_ALIAS );break ;
@@ -5792,6 +5796,8 @@ int main(int argc, char **argv, char **envp)if (machine->compat_props) {qdev_prop_register_global_list (machine->compat_props); } +qemu_add_globals (); + machine->init (ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
Signature · 1 line
1.6.5.2
PATCH v3 15/21 chardev: make chardevs specified in config file work.
In reply to Gerd HoffmannThe patch decuples the -chardev switch and the actual chardev initialization. Without this patch qemu ignores chardev entries coming via -readconfig.
--- vl.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
vl.c +13 -3
@@ -4620,6 +4620,16 @@ static int device_init_func(QemuOpts *opts, void *opaque)return 0 ; } +static int chardev_init_func (QemuOpts *opts,void *opaque) +{ +CharDriverState *chr; + + chr =qemu_chr_open_opts (opts,NULL ); +if (!chr) +return -1 ; +return 0 ; +} +struct device_config {enum {DEV_USB ,/* -usbdevice */
@@ -5240,9 +5250,6 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"parse error: %s\n" , optarg);exit (1 ); } -if (qemu_chr_open_opts (opts,NULL ) ==NULL ) { -exit (1 ); - }break ;case QEMU_OPTION_serial:add_device_config (DEV_SERIAL , optarg);
@@ -5553,6 +5560,9 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (&qemu_device_opts, default_driver_check,NULL ,0 ); +if (qemu_opts_foreach (&qemu_chardev_opts, chardev_init_func,NULL ,1 ) !=0 ) +exit (1 ); +if (display_type ==DT_NOGRAPHIC ) {if (default_parallel)add_device_config (DEV_PARALLEL ,"null" );
Signature · 1 line
1.6.5.2
PATCH v3 16/21 un-static qemu_chr_parse_compat()
In reply to Gerd Hoffmann--- qemu-char.c | 2 +- qemu-char.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
qemu-char.c +1 -1
@@ -2231,7 +2231,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)return NULL ; } -static QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename) +QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename) {char host[65 ], port[33 ], width[8 ], height[8 ];int pos;
qemu-char.h +1 -0
@@ -69,6 +69,7 @@ struct CharDriverState {QTAILQ_ENTRY (CharDriverState) next; }; +QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename);CharDriverState *qemu_chr_open_opts (QemuOpts *opts,void (*init)(struct CharDriverState *s));CharDriverState *qemu_chr_open (const char *label,const char *filename,void (*init)(struct CharDriverState *s));
Signature · 1 line
1.6.5.2
PATCH v3 17/21 rework -monitor handling, switch to QemuOpts
In reply to Gerd HoffmannThis patch reworks the -monitor handling:
- It adds a new "mon" QemuOpts list for the monitor(s).
- It adds a monitor_parse() function to parse the -monitor switch.
- It adds a mon_init function to initialize the monitor(s) from the "mon" QemuOpts list.
- It winds up everything and removes the old bits.
--- qemu-config.c | 19 +++++++++ qemu-config.h | 1 + vl.c | 121 ++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 98 insertions(+), 43 deletions(-)
qemu-config.c +19 -0
@@ -224,6 +224,24 @@ QemuOptsList qemu_global_opts = { }, }; +QemuOptsList qemu_mon_opts = { + .name ="mon" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_mon_opts.head), + .desc = { + { + .name ="mode" , + .type =QEMU_OPT_STRING , + },{ + .name ="chardev" , + .type =QEMU_OPT_STRING , + },{ + .name ="default" , + .type =QEMU_OPT_BOOL , + }, + {/* end if list */ } + }, +}; +static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts,
@@ -232,6 +250,7 @@ static QemuOptsList *lists[] = { &qemu_net_opts, &qemu_rtc_opts, &qemu_global_opts, + &qemu_mon_opts, NULL, };
qemu-config.h +1 -0
@@ -7,6 +7,7 @@ extern QemuOptsList qemu_device_opts;extern QemuOptsList qemu_netdev_opts;extern QemuOptsList qemu_net_opts;extern QemuOptsList qemu_rtc_opts; +extern QemuOptsList qemu_mon_opts;int qemu_set_option (const char *str);int qemu_global_option (const char *str);
vl.c +78 -43
181 lines not on this page · raw message
Signature · 1 line
1.6.5.2
[Qemu-devel] Re: [FOR 0.12 PATCH v3 17/21] rework -monitor handling, switch to QemuOpts
Quoted 21 lines · On Mon, 7 Dec 2009 13:42:49 +0100 Gerd Hoffmann <[email protected]> wrote:
vl.c +21
-0+static int mon_init_func (QemuOpts *opts,void *opaque) +{ +CharDriverState *chr; +const char *chardev; +const char *mode; +int flags; + +qemu_opts_print (opts,NULL ); + + mode =qemu_opt_get (opts,"mode" ); +if (mode ==NULL ) { + mode ="readline" ; + } +if (strcmp (mode,"readline" ) ==0 ) { + flags =MONITOR_USE_READLINE ; + }else if (strcmp (mode,"control" ) ==0 ) { + flags =MONITOR_USE_CONTROL ; + }else { +fprintf (stderr,"unknown monitor mode \"%s\"\n" , mode); +exit (1 ); + }
vl.c static int chardev_init_func(QemuOpts *opts, void *opaque) · line 4659
Quoted 10 lines
vl.c +10
-0+ +if (qemu_opt_get_bool (opts,"default" ,0 )) + flags |=MONITOR_IS_DEFAULT ; + + chardev =qemu_opt_get (opts,"chardev" ); + chr =qemu_chr_find (chardev); +if (chardev ==NULL ) { +fprintf (stderr,"chardev \"%s\" not found\n" , chardev); +exit (1 ); + }
We should check for NULL before calling qemu_chr_find().
Also, I'm getting a segfault when running QEMU w/o any monitor cmd-line,
like:
$ qemu -hda disks/fedora-11-kratos-i386.img -m 1G
The reason for the segfault is that the chardev 'monitor' is not found,
so qemu_chr_find() returns NULL, passing it down to:
vl.c static int chardev_init_func(QemuOpts *opts, void *opaque) · line 4664
Quoted 5 lines
vl.c +5
-0+ +monitor_init (chr, flags); +return 0 ; +} +
Apart from that, monitor changes seem ok to me.
[Qemu-devel] Re: [FOR 0.12 PATCH v3 17/21] rework -monitor handling, switch to QemuOpts
Quoted 8 lines · Luiz Capitulino
vl.c static int chardev_init_func(QemuOpts *opts, void *opaque) · line 4659
Quoted 6 lines
vl.c +6
-0+ chardev =qemu_opt_get (opts,"chardev" ); + chr =qemu_chr_find (chardev); +if (chardev ==NULL ) { +fprintf (stderr,"chardev \"%s\" not found\n" , chardev); +exit (1 ); + }We should check for NULL before calling
qemu_chr_find().
No. qemu_chr_find() can deal with NULL just fine. We should check the return value (chr) instead though. When fixing that it prints the error message and exits as it should. Well, almost, because ...
Quoted 2 lines
The reason for the segfault is that the chardev 'monitor' is not found,
soqemu_chr_find()returns NULL, passing it down to:
... 'monitor' should be there, there is a default for the monitor device. Hmm, checking why ...
cheers,
Gerd
Re: [Qemu-devel] [FOR 0.12 PATCH v3 17/21] rework -monitor handling, switch to QemuOpts
In reply to Gerd HoffmannQuoted 10 lines · Gerd Hoffmann
This patch reworks the -monitor handling:
- It adds a new "mon" QemuOpts list for the monitor(s).
- It adds amonitor_parse()function to parse the -monitor switch.
- It adds amon_initfunction to initialize the monitor(s) from the "mon" QemuOpts list.
- It winds up everything and removes the old bits.Signed-off-by Gerd Hoffmann <[email protected]>
This SEGVs as Luiz has reported, but it also has some debugging noise in it:
vl.c static int chardev_init_func(QemuOpts *opts, void *opaque) · line 4636
Quoted 9 lines
vl.c +8
-0+static int mon_init_func (QemuOpts *opts,void *opaque) +{ +CharDriverState *chr; +const char *chardev; +const char *mode; +int flags; + +qemu_opts_print (opts,NULL );
Right here.
vl.c static int chardev_init_func(QemuOpts *opts, void *opaque) · line 4650
Quoted 13 lines
vl.c +13
-0+ mode =qemu_opt_get (opts,"mode" ); +if (mode ==NULL ) { + mode ="readline" ; + } +if (strcmp (mode,"readline" ) ==0 ) { + flags =MONITOR_USE_READLINE ; + }else if (strcmp (mode,"control" ) ==0 ) { + flags =MONITOR_USE_CONTROL ; + }else { +fprintf (stderr,"unknown monitor mode \"%s\"\n" , mode); +exit (1 ); + } +
Regards,
Anthony Liguori
PATCH v3 18/21 add new -mon switch
In reply to Gerd Hoffmann--- qemu-options.hx | 7 +++++++ vl.c | 8 ++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
qemu-options.hx +7 -0
@@ -1589,6 +1589,13 @@ The default device is @code{vc} in graphical mode and @code{stdio} in non graphical mode. ETEXI +DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ + "-mon chardev=[name][,mode=readline|control][,default]\n") +STEXI +@item -mon chardev=[name][,mode=readline|control][,default] +Setup monitor on chardev @var{name}. +ETEXI + DEF("pidfile", HAS_ARG, QEMU_OPTION_pidfile, \ "-pidfile file write PID to 'file'\n") STEXI
vl.c +8 -0
@@ -5286,6 +5286,14 @@ int main(int argc, char **argv, char **envp)monitor_parse (optarg); default_monitor =0 ;break ; +case QEMU_OPTION_mon: + opts =qemu_opts_parse (&qemu_mon_opts, optarg,"chardev" ); +if (!opts) { +fprintf (stderr,"parse error: %s\n" , optarg); +exit (1 ); + } + default_monitor =0 ; +break ;case QEMU_OPTION_chardev: opts =qemu_opts_parse (&qemu_chardev_opts, optarg,"backend" );if (!opts) {
Signature · 1 line
1.6.5.2
PATCH v3 19/21 add -qmp convinience switch
In reply to Gerd Hoffmann--- qemu-options.hx | 2 ++ vl.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-)
qemu-options.hx +2 -0
@@ -1588,6 +1588,8 @@ serial port). The default device is @code{vc} in graphical mode and @code{stdio} in non graphical mode. ETEXI +DEF("qmp", HAS_ARG, QEMU_OPTION_qmp, \ + "-qmp dev like -monitor but opens in 'control' mode.\n") DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ "-mon chardev=[name][,mode=readline|control][,default]\n")
vl.c +9 -5
@@ -4662,7 +4662,7 @@ static int mon_init_func(QemuOpts *opts, void *opaque)return 0 ; } -static void monitor_parse (const char *optarg) +static void monitor_parse (const char *optarg,const char *mode) {static int monitor_device_index =0 ;QemuOpts *opts;
@@ -4692,7 +4692,7 @@ static void monitor_parse(const char *optarg)fprintf (stderr,"fixme #2\n" );exit (1 ); } -qemu_opt_set (opts,"mode" ,"readline" ); +qemu_opt_set (opts,"mode" , mode);qemu_opt_set (opts,"chardev" , label);if (def)qemu_opt_set (opts,"default" ,"on" );
@@ -5283,7 +5283,11 @@ int main(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_monitor: -monitor_parse (optarg); +monitor_parse (optarg,"readline" ); + default_monitor =0 ; +break ; +case QEMU_OPTION_qmp: +monitor_parse (optarg,"control" ); default_monitor =0 ;break ;case QEMU_OPTION_mon:
@@ -5622,7 +5626,7 @@ int main(int argc, char **argv, char **envp)if (default_serial)add_device_config (DEV_SERIAL ,"stdio" );if (default_monitor) -monitor_parse ("stdio" ); +monitor_parse ("stdio" ,"readline" ); } }else {if (default_serial)
@@ -5630,7 +5634,7 @@ int main(int argc, char **argv, char **envp)if (default_parallel)add_device_config (DEV_PARALLEL ,"vc:80Cx24C" );if (default_monitor) -monitor_parse ("vc:80Cx24C" ); +monitor_parse ("vc:80Cx24C" ,"readline" ); }if (default_vga) vga_interface_type =VGA_CIRRUS ;
Signature · 1 line
1.6.5.2
PATCH v3 20/21 default devices: virtio consoles.
In reply to Gerd HoffmannThis patch adds a variable default_virtcon which says whenever a default virtio console should be added. It is disabled by default, followup patch will enable it for s390. It is cleared when qemu finds '-virtiocon', '-device virtio-console-s390' or '-device virtio-console-pci' on the command line.
--- vl.c | 64 ++++++++++++++++++++++++++++++++++------------------------------ 1 files changed, 34 insertions(+), 30 deletions(-)
vl.c +34 -30
@@ -270,6 +270,7 @@ static void *boot_set_opaque;static int default_serial =1 ;static int default_parallel =1 ; +static int default_virtcon =1 ;static int default_monitor =1 ;static int default_vga =1 ;static int default_drive =1 ;
@@ -280,6 +281,8 @@ static struct { } default_list[] = { { .driver = "isa-serial", .flag = &default_serial }, { .driver = "isa-parallel", .flag = &default_parallel }, + { .driver = "virtio-console-pci", .flag = &default_virtcon }, + { .driver = "virtio-console-s390", .flag = &default_virtcon }, { .driver = "VGA", .flag = &default_vga }, { .driver = "Cirrus VGA", .flag = &default_vga }, { .driver = "QEMUware SVGA", .flag = &default_vga },
@@ -4701,10 +4704,11 @@ static void monitor_parse(const char *optarg, const char *mode)struct device_config {enum { -DEV_USB ,/* -usbdevice */ -DEV_BT ,/* -bt */ -DEV_SERIAL ,/* -serial */ -DEV_PARALLEL ,/* -parallel */ +DEV_USB ,/* -usbdevice */ +DEV_BT ,/* -bt */ +DEV_SERIAL ,/* -serial */ +DEV_PARALLEL ,/* -parallel */ +DEV_VIRTCON ,/* -virtioconsole */ } type;const char *cmdline;QTAILQ_ENTRY (device_config) next;
@@ -4780,6 +4784,28 @@ static int parallel_parse(const char *devname)return 0 ; } +static int virtcon_parse (const char *devname) +{ +static int index =0 ; +char label[32 ]; + +if (strcmp (devname,"none" ) ==0 ) +return 0 ; +if (index ==MAX_VIRTIO_CONSOLES ) { +fprintf (stderr,"qemu: too many virtio consoles\n" ); +exit (1 ); + } +snprintf (label,sizeof (label),"virtcon%d" , index); + virtcon_hds[index] =qemu_chr_open (label, devname,NULL ); +if (!virtcon_hds[index]) { +fprintf (stderr,"qemu: could not open virtio console '%s': %s\n" , + devname,strerror (errno)); +return -1 ; + } + index++; +return 0 ; +} +int main (int argc,char **argv,char **envp) {const char *gdbstub_dev =NULL ;
@@ -4795,8 +4821,6 @@ int main(int argc, char **argv, char **envp)QemuOpts *hda_opts =NULL , *opts;int optind;const char *r, *optarg; -const char *virtio_consoles[MAX_VIRTIO_CONSOLES ]; -int virtio_console_index;const char *loadvm =NULL ;QEMUMachine *machine;const char *cpu_model;
@@ -4862,10 +4886,6 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; -for (i =0 ; i <MAX_VIRTIO_CONSOLES ; i++) - virtio_consoles[i] =NULL ; - virtio_console_index =0 ; -for (i =0 ; i <MAX_NODES ; i++) { node_mem[i] =0 ; node_cpumask[i] =0 ;
@@ -5324,12 +5344,8 @@ int main(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_virtiocon: -if (virtio_console_index >=MAX_VIRTIO_CONSOLES ) { -fprintf (stderr,"qemu: too many virtio consoles\n" ); -exit (1 ); - } - virtio_consoles[virtio_console_index] = optarg; - virtio_console_index++; +add_device_config (DEV_VIRTCON , optarg); + default_virtcon =0 ;break ;case QEMU_OPTION_parallel:add_device_config (DEV_PARALLEL , optarg);
@@ -5832,20 +5848,8 @@ int main(int argc, char **argv, char **envp)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]; -if (devname &&strcmp (devname,"none" )) { -char label[32 ]; -snprintf (label,sizeof (label),"virtcon%d" , i); - virtcon_hds[i] =qemu_chr_open (label, devname,NULL ); -if (!virtcon_hds[i]) { -fprintf (stderr,"qemu: could not open virtio console '%s': %s\n" , - devname,strerror (errno)); -exit (1 ); - } - } - } +if (foreach_device_config (DEV_VIRTCON , virtcon_parse) <0 ) +exit (1 );module_call_init (MODULE_INIT_DEVICE );
Signature · 1 line
1.6.5.2
[Qemu-devel] Re: [FOR 0.12 PATCH v3 20/21] default devices: virtio consoles.
Quoted 24 lines · Gerd Hoffmann
This patch adds a variable
default_virtconwhich says whenever a default virtio console should be added. It is disabled by default, followup patch will enable it for s390. It is cleared when qemu finds '-virtiocon', '-device virtio-console-s390' or '-device virtio-console-pci' on the command line.Signed-off-by Gerd Hoffmann <[email protected]>---
vl.c| 64 ++++++++++++++++++++++++++++++++++------------------------------1 files changed, 34 insertions(+), 30 deletions(-)vl.c +1
-0@@ -270,6 +270,7 @@ static void *boot_set_opaque;static int default_serial =1 ;static int default_parallel =1 ; +static int default_virtcon =1 ;static int default_monitor =1 ;static int default_vga =1 ;static int default_drive =1 ;
vl.c static struct { · line 285
Quoted 5 lines
vl.c +2
-0@@ -280,6 +281,8 @@ static struct { } default_list[] = { { .driver = "isa-serial", .flag = &default_serial }, { .driver = "isa-parallel", .flag = &default_parallel }, + { .driver = "virtio-console-pci", .flag = &default_virtcon }, + { .driver = "virtio-console-s390", .flag = &default_virtcon },
Hm, what does this do? Create both virtio-console-pci and virtio-console-s390 when default_virtcon=1? Then I'm pretty sure this will break when (if) we ever get PCI support on S390.
Defaults really belong in the machine definition.
Alex
[Qemu-devel] Re: [FOR 0.12 PATCH v3 20/21] default devices: virtio consoles.
Quoted 3 lines · Alexander Graf
Quoted 1 line
+static int
default_virtcon= 1;Hm, what does this do? Create both virtio-console-pci and virtio-console-s390 when default_virtcon=1?
No. Make qemu *not* create a default virtio console in case one was added via '-device virtio-console-pci'.
cheers,
Gerd
PATCH v3 21/21 Set default console to virtio on S390x
In reply to Gerd HoffmannAll "normal" system emulation targets in qemu I'm aware of display output on either VGA or serial output.
Our S390x virtio machine doesn't have such kind of legacy hardware. So instead we need to default to a virtio console.
--- vl.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
vl.c +10 -1
@@ -268,9 +268,14 @@ uint8_t qemu_uuid[16];static QEMUBootSetHandler *boot_set_handler;static void *boot_set_opaque; +#ifdef TARGET_S390X +static int default_serial =0 ; +static int default_virtcon =1 ; +#else static int default_serial =1 ; +static int default_virtcon =0 ; +#endif static int default_parallel =1 ; -static int default_virtcon =1 ;static int default_monitor =1 ;static int default_vga =1 ;static int default_drive =1 ;
@@ -5638,9 +5643,13 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_PARALLEL ,"null" );if (default_serial && default_monitor) {add_device_config (DEV_SERIAL ,"mon:stdio" ); + }else if (default_virtcon && default_monitor) { +add_device_config (DEV_VIRTCON ,"mon:stdio" ); }else {if (default_serial)add_device_config (DEV_SERIAL ,"stdio" ); +if (default_virtcon) +add_device_config (DEV_VIRTCON ,"stdio" );if (default_monitor)monitor_parse ("stdio" ,"readline" ); }
Signature · 1 line
1.6.5.2