Patchwork [3/4] machine: add default_devices field to QEMUMachine

login
register
mail settings
Submitter Anthony Liguori
Date Oct. 26, 2012, 5:21 p.m.
Message ID <1351272088-7942-4-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/194541/
State New
Headers show

Comments

Anthony Liguori - Oct. 26, 2012, 5:21 p.m.
This allows a machine to describe default devices that are only available
when -nodefaults is not present.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/boards.h |  6 ++++++
 vl.c        | 13 +++++++++++++
 2 files changed, 19 insertions(+)
Markus Armbruster - Nov. 5, 2012, 12:27 p.m.
Anthony Liguori <aliguori@us.ibm.com> writes:

> This allows a machine to describe default devices that are only available
> when -nodefaults is not present.
>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  hw/boards.h |  6 ++++++
>  vl.c        | 13 +++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/hw/boards.h b/hw/boards.h
> index 813d0e5..85b2887 100644
> --- a/hw/boards.h
> +++ b/hw/boards.h
> @@ -18,6 +18,11 @@ typedef void QEMUMachineInitFunc(QEMUMachineInitArgs *args);
>  
>  typedef void QEMUMachineResetFunc(void);
>  
> +typedef struct DeviceDescription {
> +    const char *description;
> +} DeviceDescription;

A comment explaning syntax of @description (just like argument of
-device, as far as I can tell) would be nice.

Not sure wrapping in a struct is worth it.

> +
> +
>  typedef struct QEMUMachine {
>      const char *name;
>      const char *alias;
> @@ -37,6 +42,7 @@ typedef struct QEMUMachine {
>      GlobalProperty *compat_props;
>      struct QEMUMachine *next;
>      const char *hw_version;
> +    DeviceDescription *default_devices;
>  } QEMUMachine;
>  
>  int qemu_register_machine(QEMUMachine *m);
[...]

Patch

diff --git a/hw/boards.h b/hw/boards.h
index 813d0e5..85b2887 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -18,6 +18,11 @@  typedef void QEMUMachineInitFunc(QEMUMachineInitArgs *args);
 
 typedef void QEMUMachineResetFunc(void);
 
+typedef struct DeviceDescription {
+    const char *description;
+} DeviceDescription;
+
+
 typedef struct QEMUMachine {
     const char *name;
     const char *alias;
@@ -37,6 +42,7 @@  typedef struct QEMUMachine {
     GlobalProperty *compat_props;
     struct QEMUMachine *next;
     const char *hw_version;
+    DeviceDescription *default_devices;
 } QEMUMachine;
 
 int qemu_register_machine(QEMUMachine *m);
diff --git a/vl.c b/vl.c
index ffadbb6..f1285b8 100644
--- a/vl.c
+++ b/vl.c
@@ -276,6 +276,7 @@  static int default_floppy = 1;
 static int default_cdrom = 1;
 static int default_sdcard = 1;
 static int default_vga = 1;
+static int nodefaults = 0;
 
 static struct {
     const char *driver;
@@ -3275,6 +3276,7 @@  int main(int argc, char **argv, char **envp)
                 default_cdrom = 0;
                 default_sdcard = 0;
                 default_vga = 0;
+                nodefaults = 1;
                 break;
             case QEMU_OPTION_xen_domid:
                 if (!(xen_available())) {
@@ -3692,6 +3694,17 @@  int main(int argc, char **argv, char **envp)
     }
     qemu_add_globals();
 
+    if (!nodefaults && machine->default_devices) {
+        int i;
+
+        for (i = 0; machine->default_devices[i].description; i++) {
+            if (!qemu_opts_parse(qemu_find_opts("device"),
+                                 machine->default_devices[i].description, 1)) {
+                exit(1);
+            }
+        }
+    }
+
     qdev_machine_init();
 
     QEMUMachineInitArgs args = { .ram_size = ram_size,