Patchwork [14/22] machine: replace QEMUMachine.use_scsi with -machine default_drive

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

Comments

Anthony Liguori - June 7, 2010, 11:52 p.m.
Some boards only support scsi and there's some ugliness to accomodate this.

This patch removes that and introduces a default_drive common option for
machines.  The absence of this option assumes ide.  It can be explicitly set
to scsi and this is used to replace all current occurrances of use_scsi.

As fall out to this patch, current_machine disappears because it's actually
not needed since we no longer access the machine state to check for use_scsi.

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

Patch

diff --git a/hw/boards.h b/hw/boards.h
index f33c44b..887487e 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -14,7 +14,6 @@  struct QEMUMachine {
     const char *alias;
     const char *desc;
     QEMUMachineInitFunc *init;
-    int use_scsi;
     int max_cpus;
     int is_default;
     QemuOptDesc *opts_desc;
@@ -75,6 +74,9 @@  extern QEMUMachine *current_machine;
     },{                                 \
         .name = "sdcard",               \
         .type = QEMU_OPT_BOOL,          \
+    },{                                 \
+        .name = "default_drive",        \
+        .type = QEMU_OPT_STRING,        \
     }
 
 
diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c
index 9cc8376..feb8aa3 100644
--- a/hw/device-hotplug.c
+++ b/hw/device-hotplug.c
@@ -38,7 +38,7 @@  DriveInfo *add_init_drive(const char *optstr)
     if (!opts)
         return NULL;
 
-    dinfo = drive_init(opts, current_machine, &fatal_error);
+    dinfo = drive_init(opts, NULL, &fatal_error);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 1ba9475..7e1e119 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -319,14 +319,20 @@  static QEMUMachine mips_magnum_machine = {
     .name = "magnum",
     .desc = "MIPS Magnum",
     .init = mips_magnum_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine mips_pica61_machine = {
     .name = "pica61",
     .desc = "Acer Pica 61",
     .init = mips_pica61_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static void mips_jazz_machine_init(void)
diff --git a/hw/realview.c b/hw/realview.c
index 4364b7b..a36bdbe 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -432,14 +432,20 @@  static QEMUMachine realview_eb_machine = {
     .name = "realview-eb",
     .desc = "ARM RealView Emulation Baseboard (ARM926EJ-S)",
     .init = realview_eb_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine realview_eb_mpcore_machine = {
     .name = "realview-eb-mpcore",
     .desc = "ARM RealView Emulation Baseboard (ARM11MPCore)",
     .init = realview_eb_mpcore_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 4,
 };
 
@@ -453,7 +459,10 @@  static QEMUMachine realview_pbx_a9_machine = {
     .name = "realview-pbx-a9",
     .desc = "ARM RealView Platform Baseboard Explore for Cortex-A9",
     .init = realview_pbx_a9_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 4,
 };
 
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 5aa3de1..a400530 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -1319,7 +1319,10 @@  static QEMUMachine ss5_machine = {
     .name = "SS-5",
     .desc = "Sun4m platform, SPARCstation 5",
     .init = ss5_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .is_default = 1,
 };
 
@@ -1327,7 +1330,10 @@  static QEMUMachine ss10_machine = {
     .name = "SS-10",
     .desc = "Sun4m platform, SPARCstation 10",
     .init = ss10_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 4,
 };
 
@@ -1335,7 +1341,10 @@  static QEMUMachine ss600mp_machine = {
     .name = "SS-600MP",
     .desc = "Sun4m platform, SPARCserver 600MP",
     .init = ss600mp_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 4,
 };
 
@@ -1343,7 +1352,10 @@  static QEMUMachine ss20_machine = {
     .name = "SS-20",
     .desc = "Sun4m platform, SPARCstation 20",
     .init = ss20_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 4,
 };
 
@@ -1351,35 +1363,50 @@  static QEMUMachine voyager_machine = {
     .name = "Voyager",
     .desc = "Sun4m platform, SPARCstation Voyager",
     .init = vger_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine ss_lx_machine = {
     .name = "LX",
     .desc = "Sun4m platform, SPARCstation LX",
     .init = ss_lx_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine ss4_machine = {
     .name = "SS-4",
     .desc = "Sun4m platform, SPARCstation 4",
     .init = ss4_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine scls_machine = {
     .name = "SPARCClassic",
     .desc = "Sun4m platform, SPARCClassic",
     .init = scls_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine sbook_machine = {
     .name = "SPARCbook",
     .desc = "Sun4m platform, SPARCbook",
     .init = sbook_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static const struct sun4d_hwdef sun4d_hwdefs[] = {
@@ -1599,7 +1626,10 @@  static QEMUMachine ss1000_machine = {
     .name = "SS-1000",
     .desc = "Sun4d platform, SPARCserver 1000",
     .init = ss1000_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 8,
 };
 
@@ -1607,7 +1637,10 @@  static QEMUMachine ss2000_machine = {
     .name = "SS-2000",
     .desc = "Sun4d platform, SPARCcenter 2000",
     .init = ss2000_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
     .max_cpus = 20,
 };
 
@@ -1782,7 +1815,10 @@  static QEMUMachine ss2_machine = {
     .name = "SS-2",
     .desc = "Sun4c platform, SPARCstation 2",
     .init = ss2_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static void ss2_machine_init(void)
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index 59b66d7..f407669 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -321,14 +321,20 @@  static QEMUMachine versatilepb_machine = {
     .name = "versatilepb",
     .desc = "ARM Versatile/PB (ARM926EJ-S)",
     .init = vpb_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static QEMUMachine versatileab_machine = {
     .name = "versatileab",
     .desc = "ARM Versatile/AB (ARM926EJ-S)",
     .init = vab_init,
-    .use_scsi = 1,
+    .opts_default = (QemuOptValue[]) {
+        QOPT_VALUE("default_drive", "scsi"),
+        { /* end of list */ }
+    },
 };
 
 static void versatile_machine_init(void)
diff --git a/vl.c b/vl.c
index 553da4d..1065233 100644
--- a/vl.c
+++ b/vl.c
@@ -783,7 +783,7 @@  DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
     BlockDriver *drv = NULL;
-    QEMUMachine *machine = opaque;
+    const char *default_drive = opaque;
     int max_devs;
     int index;
     int ro = 0;
@@ -797,10 +797,14 @@  DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 
     translation = BIOS_ATA_TRANSLATION_AUTO;
 
-    if (machine && machine->use_scsi) {
+    if (default_drive && strcmp(default_drive, "scsi") == 0) {
         type = IF_SCSI;
         max_devs = MAX_SCSI_DEVS;
         pstrcpy(devname, sizeof(devname), "scsi");
+    } else if (default_drive && strcmp(default_drive, "virtio") == 0) {
+        type = IF_VIRTIO;
+        max_devs = MAX_DRIVES;
+        pstrcpy(devname, sizeof(devname), "virtio");
     } else {
         type = IF_IDE;
         max_devs = MAX_IDE_DEVS;
@@ -1136,10 +1140,10 @@  DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 
 static int drive_init_func(QemuOpts *opts, void *opaque)
 {
-    QEMUMachine *machine = opaque;
+    const char *default_drive = opaque;
     int fatal_error = 0;
 
-    if (drive_init(opts, machine, &fatal_error) == NULL) {
+    if (drive_init(opts, (void *)default_drive, &fatal_error) == NULL) {
         if (fatal_error)
             return 1;
     }
@@ -1582,7 +1586,6 @@  void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
 /* machine registration */
 
 static QEMUMachine *first_machine = NULL;
-QEMUMachine *current_machine = NULL;
 
 int qemu_register_machine(QEMUMachine *m)
 {
@@ -3709,8 +3712,18 @@  int main(int argc, char **argv, char **envp)
     /* open the virtual block devices */
     if (snapshot)
         qemu_opts_foreach(&qemu_drive_opts, drive_enable_snapshot, NULL, 0);
-    if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, machine, 1) != 0)
-        exit(1);
+
+    {
+        int ret;
+        const char *default_drive;
+
+        default_drive = qemu_opt_get(machine_opts, "default_drive");
+        ret = qemu_opts_foreach(&qemu_drive_opts, drive_init_func,
+                                (void *)default_drive, 1);
+        if (ret != 0) {
+            exit(1);
+        }
+    }
 
     register_savevm_live("ram", 0, 3, NULL, ram_save_live, NULL, 
                          ram_load, NULL);
@@ -3813,8 +3826,6 @@  int main(int argc, char **argv, char **envp)
 
     set_numa_modes();
 
-    current_machine = machine;
-
     /* init USB devices */
     if (usb_enabled) {
         if (foreach_device_config(DEV_USB, usb_parse) < 0)