Patchwork [11/22] machine: replace compat_props with opts_default

login
register
mail settings
Submitter Anthony Liguori
Date June 7, 2010, 11:51 p.m.
Message ID <1275954730-8196-12-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/54912/
State New
Headers show

Comments

Anthony Liguori - June 7, 2010, 11:51 p.m.
Right now, machine structs can hard code GlobalProperty lists of default qdev
global properties.  This doesn't generalize well to a config file though because
there are three parameters: driver, property, value.

This patch moves this data to the generic machine opts default list.  In the
process, it converts the form to driver.property=value.  Now any option with
a '.' in the name is treated as a compat global property.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Patch

diff --git a/hw/boards.h b/hw/boards.h
index 06b9f73..c7358ae 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -24,7 +24,6 @@  struct QEMUMachine {
         no_cdrom:1,
         no_sdcard:1;
     int is_default;
-    GlobalProperty *compat_props;
     QemuOptDesc *opts_desc;
     QemuOptValue *opts_default;
     struct QEMUMachine *next;
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 0ad1145..28c1408 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -225,20 +225,15 @@  static QEMUMachine pc_machine_v0_12 = {
             .name = "cpu",
             .value = PC_DEFAULT_CPU_MODEL,
         },
-        { /* end of list */ }
-    },
-    .compat_props = (GlobalProperty[]) {
         {
-            .driver   = "virtio-serial-pci",
-            .property = "max_nr_ports",
-            .value    = stringify(1),
+            .name = "virtio-serial-pci.max_nr_ports",
+            .value = stringify(1),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-serial-pci.vectors",
+            .value = stringify(0),
         },
         { /* end of list */ }
-    }
+    },
 };
 
 static QEMUMachine pc_machine_v0_11 = {
@@ -260,33 +255,24 @@  static QEMUMachine pc_machine_v0_11 = {
             .name = "cpu",
             .value = PC_DEFAULT_CPU_MODEL,
         },
-        { /* end of list */ }
-    },
-    .compat_props = (GlobalProperty[]) {
         {
-            .driver   = "virtio-blk-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-blk-pci.vectors",
+            .value = stringify(0),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "max_nr_ports",
-            .value    = stringify(1),
+            .name = "virtio-serial-pci.max_nr_ports",
+            .value = stringify(1),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-serial-pci.vectors",
+            .value = stringify(0),
         },{
-            .driver   = "ide-drive",
-            .property = "ver",
-            .value    = "0.11",
+            .name = "ide-drive.ver",
+            .value = "0.11",
         },{
-            .driver   = "scsi-disk",
-            .property = "ver",
-            .value    = "0.11",
+            .name = "scsi-disk.ver",
+            .value = "0.11",
         },{
-            .driver   = "PCI",
-            .property = "rombar",
-            .value    = stringify(0),
+            .name = "PCI.rombar",
+            .value = stringify(0),
         },
         { /* end of list */ }
     }
@@ -311,45 +297,33 @@  static QEMUMachine pc_machine_v0_10 = {
             .name = "cpu",
             .value = PC_DEFAULT_CPU_MODEL,
         },
-        { /* end of list */ }
-    },
-    .compat_props = (GlobalProperty[]) {
         {
-            .driver   = "virtio-blk-pci",
-            .property = "class",
-            .value    = stringify(PCI_CLASS_STORAGE_OTHER),
+            .name = "virtio-blk-pci.class",
+            .value = stringify(PCI_CLASS_STORAGE_OTHER),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "class",
-            .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
+            .name = "virtio-serial-pci.class",
+            .value = stringify(PCI_CLASS_DISPLAY_OTHER),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "max_nr_ports",
-            .value    = stringify(1),
+            .name = "virtio-serial-pci.max_nr_ports",
+            .value = stringify(1),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-serial-pci.vectors",
+            .value = stringify(0),
         },{
-            .driver   = "virtio-net-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-net-pci.vectors",
+            .value = stringify(0),
         },{
-            .driver   = "virtio-blk-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-blk-pci.vectors",
+            .value = stringify(0),
         },{
-            .driver   = "ide-drive",
-            .property = "ver",
-            .value    = "0.10",
+            .name = "ide-drive.ver",
+            .value = "0.10",
         },{
-            .driver   = "scsi-disk",
-            .property = "ver",
-            .value    = "0.10",
+            .name = "scsi-disk.ver",
+            .value = "0.10",
         },{
-            .driver   = "PCI",
-            .property = "rombar",
-            .value    = stringify(0),
+            .name = "PCI.rombar",
+            .value = stringify(0),
         },
         { /* end of list */ }
     },
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index ddbefb7..8ed4632 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -183,15 +183,13 @@  static QEMUMachine bamboo_machine_v0_12 = {
     .name = "bamboo-0.12",
     .desc = "bamboo",
     .init = bamboo_init,
-    .compat_props = (GlobalProperty[]) {
+    .opts_default = (QemuOptValue[]) {
         {
-            .driver   = "virtio-serial-pci",
-            .property = "max_nr_ports",
-            .value    = stringify(1),
+            .name = "virtio-serial-pci.max_nr_ports",
+            .value = stringify(1),
         },{
-            .driver   = "virtio-serial-pci",
-            .property = "vectors",
-            .value    = stringify(0),
+            .name = "virtio-serial-pci.vectors",
+            .value = stringify(0),
         },
         { /* end of list */ }
     },
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 9ffdba7..edd5ebd 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -661,7 +661,7 @@  void qdev_prop_set_defaults(DeviceState *dev, Property *props)
 
 static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props);
 
-static void qdev_prop_register_global(GlobalProperty *prop)
+void qdev_prop_register_global(GlobalProperty *prop)
 {
     QTAILQ_INSERT_TAIL(&global_props, prop, next);
 }
diff --git a/hw/qdev.h b/hw/qdev.h
index a44060e..9700b7a 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -277,6 +277,7 @@  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_global(GlobalProperty *props);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
 
diff --git a/vl.c b/vl.c
index a7f0a3d..0a31a45 100644
--- a/vl.c
+++ b/vl.c
@@ -2558,7 +2558,42 @@  static QemuOptDesc common_machine_opts[] = {
 static int machine_combine_opt(const char *name, const char *value, void *opaque)
 {
     QemuOpts *base_opts = opaque;
-    qemu_opt_set(base_opts, name, value);
+    char *ptr;
+
+    ptr = strchr(name, '.');
+    if (ptr) {
+        GlobalProperty *prop;
+        char *driver, *property;
+
+        prop = qemu_mallocz(sizeof(*prop));
+        driver = qemu_mallocz(strlen(name) + 1);
+        property = qemu_mallocz(strlen(name) + 1);
+
+        memcpy(driver, name, (ptr - name));
+        driver[(ptr - name)] = 0;
+        strcpy(property, ptr + 1);
+
+        prop->driver = driver;
+        prop->property = property;
+        prop->value = strdup(value);
+
+        qdev_prop_register_global(prop);
+    } else {
+        qemu_opt_set(base_opts, name, value);
+    }
+    return 0;
+}
+
+static int machine_find(QemuOpts *opts, void *opaque)
+{
+    QEMUMachine **machinep = opaque;
+    const char *driver;
+
+    driver = qemu_opt_get(opts, "driver");
+    if (driver) {
+        *machinep = find_machine(driver);
+    }
+
     return 0;
 }
 
@@ -3428,20 +3463,20 @@  int main(int argc, char **argv, char **envp)
         data_dir = CONFIG_QEMU_SHAREDIR;
     }
 
-    /* Combine all -machine options into one option group */
-    machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0);
-    qemu_opts_foreach(&qemu_machine_opts, machine_combine_opts, machine_opts, 0);
-
-    if (!qemu_opt_get(machine_opts, "driver")) {
+    qemu_opts_foreach(&qemu_machine_opts, machine_find, &machine, 0);
+    if (!machine) {
         machine = find_default_machine();
-    } else {
-        machine = find_machine(qemu_opt_get(machine_opts, "driver"));
     }
 
     if (machine->opts_default) {
-        qemu_opts_set_defaults(machine_opts, machine->opts_default);
+        opts = qemu_opts_create(&qemu_machine_opts, NULL, 0);
+        qemu_opts_set_defaults(opts, machine->opts_default);
     }
 
+    /* Combine all -machine options into one option group */
+    machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0);
+    qemu_opts_foreach(&qemu_machine_opts, machine_combine_opts, machine_opts, 0);
+
     if (machine->opts_desc) {
         if (qemu_opts_validate(machine_opts, machine->opts_desc) < 0) {
             exit(1);
@@ -3746,9 +3781,6 @@  int main(int argc, char **argv, char **envp)
             exit (i == 1 ? 1 : 0);
     }
 
-    if (machine->compat_props) {
-        qdev_prop_register_global_list(machine->compat_props);
-    }
     qemu_add_globals();
 
     qemu_opt_set(machine_opts, "boot_device", boot_devices);