Skip to contentSkip to conversation

fixup default device handling.

PATCH In review Gerd Hoffmann 5 participants 23 messages Nov 17, 2009 – Dec 2, 2009

lore
Share & tools
lore
#0 lore raw

cover fixup default device handling.

Hi,

qemu silently creates default devices for you if you didn't specify one on the command line, i.e. you'll get a vga, a serial port, a nic, ... created by default. Right now this doesn't integrate with qdev at all, i.e. if you try to add -- for example -- a serial line the new qdev way using '-device isa-serial,chardev=something' it will conflict with the automagically created serial port. This patch series addresses this problem.

cheers,
Gerd

#1 lore raw

PATCH 1/9 chardev: add greeting

Add a greeting string to CharDriverState which is printed after initialization. Used to have the qemu vc consoles labeled. This way we can avoid walking all the chardevs a second time after initialization just to print the greeting.

---
 qemu-char.c |    2 ++
 qemu-char.h |    1 +
 vl.c        |   36 ++++++++++++------------------------
 3 files changed, 15 insertions(+), 24 deletions(-)
qemu-char.c +2 -0
index 40bd7e8..19be58f 100644
@@ -132,6 +132,8 @@ void qemu_chr_initial_reset(void)
 
     QTAILQ_FOREACH(chr, &chardevs, next) {
         qemu_chr_reset(chr);
+        if (chr->greeting)
+            qemu_chr_printf(chr, "%s", chr->greeting);
     }
 }
 
qemu-char.h +1 -0
index 05fe15d..e50a4f3 100644
@@ -66,6 +66,7 @@ struct CharDriverState {
     QEMUBH *bh;
     char *label;
     char *filename;
+    char *greeting;
     QTAILQ_ENTRY(CharDriverState) next;
 };
 
vl.c +12 -24
index fff8e8d..095aff6 100644
@@ -5657,6 +5657,10 @@ int main(int argc, char **argv, char **envp)
                         devname, strerror(errno));
                 exit(1);
             }
+            if (strstart(devname, "vc", 0)) {
+                snprintf(label, sizeof(label), "serial%d console\r\n", i);
+                serial_hds[i]->greeting = qemu_strdup(label);
+            }
         }
     }
 
@@ -5671,6 +5675,10 @@ int main(int argc, char **argv, char **envp)
                         devname, strerror(errno));
                 exit(1);
             }
+            if (strstart(devname, "vc", 0)) {
+                snprintf(label, sizeof(label), "parallel%d console\r\n", i);
+                parallel_hds[i]->greeting = qemu_strdup(label);
+            }
         }
     }
 
@@ -5685,6 +5693,10 @@ int main(int argc, char **argv, char **envp)
                         devname, strerror(errno));
                 exit(1);
             }
+            if (strstart(devname, "vc", 0)) {
+                snprintf(label, sizeof(label), "virtio console%d\r\n", i);
+                virtcon_hds[i]->greeting = qemu_strdup(label);
+            }
         }
     }
 
@@ -5800,30 +5812,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
#2 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 4 lines · Gerd Hoffmann

Add a greeting string to CharDriverState which is printed after initialization. Used to have the qemu vc consoles labeled. This way we can avoid walking all the chardevs a second time after initialization just to print the greeting.

I doubt this would be worthwhile on its own, but it enables getting rid of serial_devices[] and parallel_devices[] later in the series, which I like.

#3 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

In reply to Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann

Add a greeting string to CharDriverState which is printed after initialization. Used to have the qemu vc consoles labeled. This way we can avoid walking all the chardevs a second time after initialization just to print the greeting.

I think "greeting" is propagating a bad idea into new code. Much better would be some form of ID and/or human readable description that can also be used elsewhere.

Paul

#4 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 9 lines · Paul Brook
Quoted 4 lines · Gerd Hoffmann

Add a greeting string to CharDriverState which is printed after initialization. Used to have the qemu vc consoles labeled. This way we can avoid walking all the chardevs a second time after initialization just to print the greeting.

I think "greeting" is propagating a bad idea into new code. Much better would be some form of ID and/or human readable description that can also be used elsewhere.

The naming is only one part of the problem. The second part is that the greeting is printed only for the 'vc' backend (where you really need it because there is no other way to figure what chardev you are looking at when switching screens via Ctrl-Alt-<nr>).

There already is a 'label' field. So we could add a flag instead of a string, then do:

   if (chr->want_greeting)
       qemu_chr_printf(chr, "%s console\n", chr->label);

How about this?

cheers,
Gerd

#5 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 16 lines · Gerd Hoffmann
Quoted 9 lines · Paul Brook
Quoted 4 lines · Gerd Hoffmann

Add a greeting string to CharDriverState which is printed after initialization. Used to have the qemu vc consoles labeled. This way we can avoid walking all the chardevs a second time after initialization just to print the greeting.

I think "greeting" is propagating a bad idea into new code. Much better would be some form of ID and/or human readable description that can also be used elsewhere.

The naming is only one part of the problem. The second part is that the greeting is printed only for the 'vc' backend (where you really need it because there is no other way to figure what chardev you are looking at when switching screens via Ctrl-Alt-<nr>).

Quoted 7 lines

There already is a 'label' field. So we could add a flag instead of a string, then do:

    if (chr->want_greeting)
        qemu_chr_printf(chr, "%s console\n", chr->label);

How about this?

I thinking more that this should be done by the character backend itself. For example, the "graphical" consoles should probably be putting this as part of the window title rather than having the interface layer randomly send extra characters in connect.

Paul

#6 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 3 lines · Paul Brook

I thinking more that this should be done by the character backend itself. For example, the "graphical" consoles should probably be putting this as part of the window title

Doesn't work with vnc.

cheers,
Gerd

#7 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 6 lines · Gerd Hoffmann
Quoted 3 lines · Paul Brook

I thinking more that this should be done by the character backend itself.
For example, the "graphical" consoles should probably be putting this as
part of the window title

Doesn't work with vnc.

That's why it needs to be a backend decision. The VNC devices should display his information however is most appropriate.

Paul

#8 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann
Quoted 5 lines · Paul Brook

I thinking more that this should be done by the character backend itself. For
example, the "graphical" consoles should probably be putting this as part of
the window title

Doesn't work with vnc.

It could be made to actually, there's a VNC extension for sending updates to the desktop name

http://www.tigervnc.org/cgi-bin/rfbproto#desktopname-pseudo-encoding

I'd happily implement that in GTK-VNC if QEMU had the server side

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#9 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann
Quoted 3 lines · Paul Brook

I thinking more that this should be done by the character backend itself. For example, the "graphical" consoles should probably be putting this as part of the window title

Doesn't work with vnc.

A vc is what renders the for VNC so if the "vc" did this, it would just work for VNC and SDL.

Quoted 5 lines

cheers,
Gerd

#10 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Gerd Hoffmann
Quoted 5 lines · Paul Brook

I thinking more that this should be done by the character backend itself. For
example, the "graphical" consoles should probably be putting this as part of
the window title

Quoted 4 lines
Quoted 1 line

Doesn't work with vnc.

A vc is what renders the for VNC so if the "vc" did this, it would just work for VNC and SDL.

Yea, right, as vc is the only user we can easily make this local to console.c. Good idea. We can even colorize it then ;)

What I was referring to is that updating the window title of the vnc client isn't going to work. Well, at least not that easy. As Daniel points out a extension for that exists, but I'd tend to not depend on a optional vnc client feature for this.

cheers,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH 1/9] chardev: add greeting

Quoted 9 lines · Gerd Hoffmann
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Gerd Hoffmann
Quoted 5 lines · Paul Brook

I thinking more that this should be done by the character backend itself. For
example, the "graphical" consoles should probably be putting this as part of
the window title

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Doesn't work with vnc.

A vc is what renders the for VNC so if the "vc" did this, it would just work for VNC and SDL.

Yea, right, as vc is the only user we can easily make this local to console.c. Good idea. We can even colorize it then ;)

What I was referring to is that updating the window title of the vnc client isn't going to work. Well, at least not that easy. As Daniel points out a extension for that exists, but I'd tend to not depend on a optional vnc client feature for this.

It will at least be updated on reconnect.

Regards,

Anthony Liguori

#12 lore raw

PATCH 2/9 default devices: core code & serial lines.

In reply to 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_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.

---
 vl.c |  126 ++++++++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 81 insertions(+), 45 deletions(-)
vl.c +81 -45
index 095aff6..967d499 100644
@@ -270,6 +270,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;
+    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;
+    }
+    if (strstart(devname, "vc", 0)) {
+        snprintf(label, sizeof(label), "serial%d console\r\n", index);
+        serial_hds[index]->greeting = qemu_strdup(label);
+    }
+    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;
@@ -5116,12 +5178,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) {
@@ -5422,14 +5480,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
@@ -5572,19 +5635,7 @@ int main(int argc, char **argv, char **envp)
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, 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;
@@ -5646,23 +5697,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 (strstart(devname, "vc", 0)) {
-                snprintf(label, sizeof(label), "serial%d console\r\n", i);
-                serial_hds[i]->greeting = qemu_strdup(label);
-            }
-        }
-    }
+    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
#13 lore raw

Re: [Qemu-devel] [PATCH 2/9] default devices: core code & serial lines.

Quoted 19 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_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.

---
 vl.c |  126 ++++++++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 81 insertions(+), 45 deletions(-)
vl.c +0 -0
index 095aff6..967d499 100644

vl.c uint8_t qemu_uuid[16]; · line 279

Quoted 10 lines
vl.c +7 -0
@@ -270,6 +270,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 }

If you respin the patch anyway, consider adding a trailing comma here, so the next patch in the series doesn't have to touch the line again.

Quoted 53 lines
vl.c +39 -0
+};
+
+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;
+        }
+    }
+}

vl.c static int foreach_device_config(int type, int (*func)(const char *cmdline)) · line 4632

Quoted 10 lines
vl.c +10 -0
+
+static int serial_parse(const char *devname)
+{
+    static int index = 0;
+    char label[32];
+
+    if (strcmp(devname, "none") == 0)
+        return 0;
+    snprintf(label, sizeof(label), "serial%d", index);
+    serial_hds[index] = qemu_chr_open(label, devname, NULL);

Don't you have to catch index >= MAX_SERIAL_PORTS here?

Quoted 121 lines
vl.c +25 -45
+    if (!serial_hds[index]) {
+        fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
+                devname, strerror(errno));
+        return -1;
+    }
+    if (strstart(devname, "vc", 0)) {
+        snprintf(label, sizeof(label), "serial%d console\r\n", index);
+        serial_hds[index]->greeting = qemu_strdup(label);
+    }
+    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;
@@ -5116,12 +5178,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) {
@@ -5422,14 +5480,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
@@ -5572,19 +5635,7 @@ int main(int argc, char **argv, char **envp)
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, 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;
@@ -5646,23 +5697,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 (strstart(devname, "vc", 0)) {
-                snprintf(label, sizeof(label), "serial%d console\r\n", i);
-                serial_hds[i]->greeting = qemu_strdup(label);
-            }
-        }
-    }
+    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];
#14 lore raw

PATCH 3/9 default devices: parallel port

In reply to Gerd Hoffmann

Switch over parallel ports to the new default device system.

Disable default parallel port for both '-parallel' and '-device isa-parallel' cases.

---
 vl.c |   68 +++++++++++++++++++++++++++++++++---------------------------------
 1 files changed, 34 insertions(+), 34 deletions(-)
vl.c +34 -34
index 967d499..739c3a7 100644
@@ -271,12 +271,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;
+    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;
+    }
+    if (strstart(devname, "vc", 0)) {
+        snprintf(label, sizeof(label), "parallel%d console\r\n", index);
+        parallel_hds[index]->greeting = qemu_strdup(label);
+    }
+    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;
@@ -5204,12 +5222,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;
@@ -5485,14 +5499,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
@@ -5699,24 +5715,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 (strstart(devname, "vc", 0)) {
-                snprintf(label, sizeof(label), "parallel%d console\r\n", i);
-                parallel_hds[i]->greeting = qemu_strdup(label);
-            }
-        }
-    }
+    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
#15 lore raw

Re: [Qemu-devel] [PATCH 3/9] default devices: parallel port

Quoted 4 lines · Gerd Hoffmann

Switch over parallel ports to the new default device system.

Disable default parallel port for both '-parallel' and '-device isa-parallel' cases.

This feels a bit terse to me. What about a suitably edited copy of PATCH 2/9's message?

Quoted 37 lines
---
 vl.c |   68 +++++++++++++++++++++++++++++++++---------------------------------
 1 files changed, 34 insertions(+), 34 deletions(-)
vl.c +4 -1
index 967d499..739c3a7 100644
@@ -271,12 +271,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;
 }

vl.c static int serial_parse(const char *devname) · line 4657

Quoted 10 lines
vl.c +9 -0
 
+static int parallel_parse(const char *devname)
+{
+    static int index = 0;
+    char label[32];
+
+    if (strcmp(devname, "none") == 0)
+        return 0;
+    snprintf(label, sizeof(label), "parallel%d", index);
+    parallel_hds[index] = qemu_chr_open(label, devname, NULL);

Like for serial_parse(): don't you have to catch index >= MAX_PARALLEL_PORTS here?

Quoted 17 lines
vl.c +13 -0
+    if (!parallel_hds[index]) {
+        fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
+                devname, strerror(errno));
+        return -1;
+    }
+    if (strstart(devname, "vc", 0)) {
+        snprintf(label, sizeof(label), "parallel%d console\r\n", index);
+        parallel_hds[index]->greeting = qemu_strdup(label);
+    }
+    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)

[...]

#16 lore raw

PATCH 4/9 default devices: monitor

In reply to Gerd Hoffmann

Switch over monitor to the new defaults system.

---
 vl.c |   90 +++++++++++++++++++++++++++++++++--------------------------------
 1 files changed, 46 insertions(+), 44 deletions(-)
vl.c +46 -44
index 739c3a7..4edc4a3 100644
@@ -210,6 +210,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;
@@ -272,6 +273,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,28 @@ 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 == 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 +4713,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 +4784,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;
@@ -5178,12 +5199,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");
@@ -5501,14 +5518,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
@@ -5651,7 +5669,7 @@ int main(int argc, char **argv, char **envp)
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);
 
     /* Maintain compatibility with multiple stdio monitors */
-    serial_monitor_mux(monitor_devices);
+    serial_monitor_mux();
 
     if (nb_numa_nodes > 0) {
         int i;
@@ -5695,24 +5713,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)
@@ -5841,7 +5843,7 @@ int main(int argc, char **argv, char **envp)
     qemu_chr_initial_reset();
 
     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
#17 lore raw

Re: [Qemu-devel] [PATCH 4/9] default devices: monitor

Quoted 1 line · Gerd Hoffmann

Switch over monitor to the new defaults system.

Even terser.

Quoted 75 lines
---
 vl.c |   90 +++++++++++++++++++++++++++++++++--------------------------------
 1 files changed, 46 insertions(+), 44 deletions(-)
vl.c +17 -6
index 739c3a7..4edc4a3 100644
@@ -210,6 +210,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;
@@ -272,6 +273,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,28 @@ static int parallel_parse(const char *devname)
     return 0;
 }
 
+static int monitor_parse(const char *devname)
+{
+    static int index = 0;

vl.c static int parallel_parse(const char *devname) · line 4691

Quoted 10 lines
vl.c +10 -0
+    char label[32];
+
+    if (strcmp(devname, "none") == 0)
+        return 0;
+    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);

Like for serial_parse(): don't you have to catch index >= MAX_MONITOR_DEVICES here?

Quoted 12 lines
vl.c +9 -0
+    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;

[...]

#18 lore raw

PATCH 5/9 zap serial_monitor_mux

In reply to Gerd Hoffmann

The 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. Doing just that is alot easier now ;)

---
 vl.c |   42 ++++++++----------------------------------
 1 files changed, 8 insertions(+), 34 deletions(-)
vl.c +8 -34
index 4edc4a3..cd10b46 100644
@@ -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;
@@ -5514,12 +5487,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");
@@ -5668,9 +5645,6 @@ int main(int argc, char **argv, char **envp)
     vmstate_register(0, &vmstate_timers ,&timers_state);
     register_savevm_live("ram", 0, 3, 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
#19 lore raw

PATCH 6/9 default devices: vga

In reply to Gerd Hoffmann

Switch over vga to the new default device system.

Disable default vga for both '-vga' and
'-device VGA|Cirrus VGA|QEMUware SVGA)' cases.

'-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
index cd10b46..23afcc9 100644
@@ -192,7 +192,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;
@@ -274,6 +274,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;
@@ -281,6 +282,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;
@@ -5505,6 +5510,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 _WIN32
     if (daemonize) {
Signature · 1 line
1.6.2.5
#20 lore raw

PATCH 7/9 default devices: net

In reply to Gerd Hoffmann

Switch over network to the new defaults system.

---
 net.c |    5 ++++-
 net.h |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
net.c +4 -1
index 9ea66e3..9375351 100644
@@ -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
index 4ffce91..3611d10 100644
@@ -133,6 +133,7 @@ struct NICInfo {
 
 extern int nb_nics;
 extern NICInfo nd_table[MAX_NICS];
+extern int default_net;
 
 /* BT HCI info */
 
Signature · 1 line
1.6.2.5
#21 lore raw

PATCH 8/9 default devices: drives

In reply to Gerd Hoffmann

Add defaults variable for drives.

---
 vl.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
vl.c +9 -6
index 23afcc9..eb07a5b 100644
@@ -275,6 +275,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;
@@ -5634,14 +5635,16 @@ int main(int argc, char **argv, char **envp)
 
     bdrv_init_with_whitelist();
 
-    /* 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
#22 lore raw

PATCH 9/9 default devices: global switch.

In reply to Gerd Hoffmann

Add global switch to turn off all default devices.

---
 qemu-options.hx |    5 +++++
 vl.c            |    8 ++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
qemu-options.hx +5 -0
index b65fd74..70929fa 100644
@@ -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 +8 -0
index eb07a5b..5954de0 100644
@@ -5412,6 +5412,14 @@ 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;
+                default_net = 0;
+                default_drive = 0;
+                break;
 #ifndef _WIN32
             case QEMU_OPTION_chroot:
                 chroot_dir = optarg;
Signature · 1 line
1.6.2.5