qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v1 03/13] blockdev: Introduce QEMUMachine->defau


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH v1 03/13] blockdev: Introduce QEMUMachine->default_drive_if
Date: Tue, 30 Oct 2012 14:08:41 -0500
User-agent: Notmuch/0.13.2+93~ged93d79 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu)

Jason Baron <address@hidden> writes:

> From: Jason Baron <address@hidden>
>
> The current QEMUMachine definition has a 'use_scsi' field to indicate if a
> machine type should use scsi by default. However, Q35 wants to use ahci by
> default. Thus, introdue a new field in the QEMUMachine defintion,
> default_drive_if.
>
> Please use 'static inline int get_default_drive_if(int default_drive_if)', 
> when
> accesssing the new default_drive_if field. The field should be initialized by 
> the
> machine type to the default interface type which it wants to use
> (IF_SCSI, IF_AHCI, etc.). If no default_drive_if is specified, we assume 
> IF_IDE.
> In the future, we should go through all of the machines types and explicitly
> define their desired default interface, thus eliminating the need for
> get_default_drive_if() interface.
>
> Reviewed-by: Paolo Bonzini <address@hidden>
> Signed-off-by: Jason Baron <address@hidden>

I think having a storage machine option is a bit nicer here but I'll
defer to Kevin/Markus.

Regards,

Anthony Liguori

> ---
>  blockdev.c          |    4 ++--
>  blockdev.h          |   20 ++++++++++++++++++++
>  hw/boards.h         |    2 +-
>  hw/device-hotplug.c |    2 +-
>  hw/highbank.c       |    2 +-
>  hw/leon3.c          |    1 -
>  hw/mips_jazz.c      |    4 ++--
>  hw/pc_sysfw.c       |    2 +-
>  hw/puv3.c           |    1 -
>  hw/realview.c       |    6 +++---
>  hw/spapr.c          |    2 +-
>  hw/sun4m.c          |   24 ++++++++++++------------
>  hw/versatilepb.c    |    4 ++--
>  hw/vexpress.c       |    4 ++--
>  hw/xilinx_zynq.c    |    2 +-
>  vl.c                |   20 +++++++++++---------
>  16 files changed, 60 insertions(+), 40 deletions(-)
>
> diff --git a/blockdev.c b/blockdev.c
> index 99828ad..2977e2f 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -275,7 +275,7 @@ static bool do_check_io_limits(BlockIOLimit *io_limits)
>      return true;
>  }
>  
> -DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
> +DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType default_drive_if)
>  {
>      const char *buf;
>      const char *file = NULL;
> @@ -325,7 +325,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
>              return NULL;
>       }
>      } else {
> -        type = default_to_scsi ? IF_SCSI : IF_IDE;
> +        type = get_default_drive_if(default_drive_if);
>      }
>  
>      max_devs = if_max_devs[type];
> diff --git a/blockdev.h b/blockdev.h
> index 5f27b64..658380d 100644
> --- a/blockdev.h
> +++ b/blockdev.h
> @@ -40,6 +40,26 @@ struct DriveInfo {
>      int refcount;
>  };
>  
> +/*
> + * Each qemu machine type defines a default_drive_if field for its default
> + * interface type. When accessing the default_drive_if field, please make use
> + * of get_default_drive_if(). If default_drive_if is unspecified, we set it 
> to
> + * IF_IDE.
> + *
> + * Left as a 'todo': We should convert those that are unspecified to their
> + * proper default values, thus eliminating the need for 
> get_default_drive_if().
> + */
> +static inline int get_default_drive_if(int default_drive_if)
> +{
> +    assert(default_drive_if < IF_COUNT);
> +    assert(default_drive_if >= IF_NONE);
> +
> +    if (default_drive_if == 0) {
> +        return IF_IDE;
> +    }
> +    return default_drive_if;
> +}
> +
>  DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
>  DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
>  int drive_get_max_bus(BlockInterfaceType type);
> diff --git a/hw/boards.h b/hw/boards.h
> index 813d0e5..cd3f79f 100644
> --- a/hw/boards.h
> +++ b/hw/boards.h
> @@ -24,7 +24,7 @@ typedef struct QEMUMachine {
>      const char *desc;
>      QEMUMachineInitFunc *init;
>      QEMUMachineResetFunc *reset;
> -    int use_scsi;
> +    int default_drive_if;
>      int max_cpus;
>      unsigned int no_serial:1,
>          no_parallel:1,
> diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c
> index eec0fe3..53ee6c3 100644
> --- a/hw/device-hotplug.c
> +++ b/hw/device-hotplug.c
> @@ -39,7 +39,7 @@ DriveInfo *add_init_drive(const char *optstr)
>      if (!opts)
>          return NULL;
>  
> -    dinfo = drive_init(opts, current_machine->use_scsi);
> +    dinfo = drive_init(opts, current_machine->default_drive_if);
>      if (!dinfo) {
>          qemu_opts_del(opts);
>          return NULL;
> diff --git a/hw/highbank.c b/hw/highbank.c
> index afbb005..03ae3d8 100644
> --- a/hw/highbank.c
> +++ b/hw/highbank.c
> @@ -326,7 +326,7 @@ static QEMUMachine highbank_machine = {
>      .name = "highbank",
>      .desc = "Calxeda Highbank (ECX-1000)",
>      .init = highbank_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> diff --git a/hw/leon3.c b/hw/leon3.c
> index 7742738..ef83dff 100644
> --- a/hw/leon3.c
> +++ b/hw/leon3.c
> @@ -212,7 +212,6 @@ static QEMUMachine leon3_generic_machine = {
>      .name     = "leon3_generic",
>      .desc     = "Leon-3 generic",
>      .init     = leon3_generic_hw_init,
> -    .use_scsi = 0,
>  };
>  
>  static void leon3_machine_init(void)
> diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
> index 0847427..f72358c 100644
> --- a/hw/mips_jazz.c
> +++ b/hw/mips_jazz.c
> @@ -324,14 +324,14 @@ static QEMUMachine mips_magnum_machine = {
>      .name = "magnum",
>      .desc = "MIPS Magnum",
>      .init = mips_magnum_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine mips_pica61_machine = {
>      .name = "pica61",
>      .desc = "Acer Pica 61",
>      .init = mips_pica61_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static void mips_jazz_machine_init(void)
> diff --git a/hw/pc_sysfw.c b/hw/pc_sysfw.c
> index 9d7c5f4..b294f91 100644
> --- a/hw/pc_sysfw.c
> +++ b/hw/pc_sysfw.c
> @@ -98,7 +98,7 @@ static void pc_fw_add_pflash_drv(void)
>        return;
>      }
>  
> -    drive_init(opts, machine->use_scsi);
> +    drive_init(opts, machine->default_drive_if);
>  }
>  
>  static void pc_system_flash_init(MemoryRegion *rom_memory,
> diff --git a/hw/puv3.c b/hw/puv3.c
> index 764799c..3d77349 100644
> --- a/hw/puv3.c
> +++ b/hw/puv3.c
> @@ -122,7 +122,6 @@ static QEMUMachine puv3_machine = {
>      .desc = "PKUnity Version-3 based on UniCore32",
>      .init = puv3_init,
>      .is_default = 1,
> -    .use_scsi = 0,
>  };
>  
>  static void puv3_machine_init(void)
> diff --git a/hw/realview.c b/hw/realview.c
> index b5cb08c..129c181 100644
> --- a/hw/realview.c
> +++ b/hw/realview.c
> @@ -394,14 +394,14 @@ static QEMUMachine realview_eb_machine = {
>      .name = "realview-eb",
>      .desc = "ARM RealView Emulation Baseboard (ARM926EJ-S)",
>      .init = realview_eb_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine realview_eb_mpcore_machine = {
>      .name = "realview-eb-mpcore",
>      .desc = "ARM RealView Emulation Baseboard (ARM11MPCore)",
>      .init = realview_eb_mpcore_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> @@ -415,7 +415,7 @@ 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,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> diff --git a/hw/spapr.c b/hw/spapr.c
> index 8d0ad3c..ee5346b 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -924,7 +924,7 @@ static QEMUMachine spapr_machine = {
>      .reset = ppc_spapr_reset,
>      .max_cpus = MAX_CPUS,
>      .no_parallel = 1,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static void spapr_machine_init(void)
> diff --git a/hw/sun4m.c b/hw/sun4m.c
> index 02673b2..dc2a7c1 100644
> --- a/hw/sun4m.c
> +++ b/hw/sun4m.c
> @@ -1426,7 +1426,7 @@ static QEMUMachine ss5_machine = {
>      .name = "SS-5",
>      .desc = "Sun4m platform, SPARCstation 5",
>      .init = ss5_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .is_default = 1,
>  };
>  
> @@ -1434,7 +1434,7 @@ static QEMUMachine ss10_machine = {
>      .name = "SS-10",
>      .desc = "Sun4m platform, SPARCstation 10",
>      .init = ss10_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> @@ -1442,7 +1442,7 @@ static QEMUMachine ss600mp_machine = {
>      .name = "SS-600MP",
>      .desc = "Sun4m platform, SPARCserver 600MP",
>      .init = ss600mp_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> @@ -1450,7 +1450,7 @@ static QEMUMachine ss20_machine = {
>      .name = "SS-20",
>      .desc = "Sun4m platform, SPARCstation 20",
>      .init = ss20_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> @@ -1458,35 +1458,35 @@ static QEMUMachine voyager_machine = {
>      .name = "Voyager",
>      .desc = "Sun4m platform, SPARCstation Voyager",
>      .init = vger_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine ss_lx_machine = {
>      .name = "LX",
>      .desc = "Sun4m platform, SPARCstation LX",
>      .init = ss_lx_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine ss4_machine = {
>      .name = "SS-4",
>      .desc = "Sun4m platform, SPARCstation 4",
>      .init = ss4_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine scls_machine = {
>      .name = "SPARCClassic",
>      .desc = "Sun4m platform, SPARCClassic",
>      .init = scls_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine sbook_machine = {
>      .name = "SPARCbook",
>      .desc = "Sun4m platform, SPARCbook",
>      .init = sbook_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static const struct sun4d_hwdef sun4d_hwdefs[] = {
> @@ -1709,7 +1709,7 @@ static QEMUMachine ss1000_machine = {
>      .name = "SS-1000",
>      .desc = "Sun4d platform, SPARCserver 1000",
>      .init = ss1000_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 8,
>  };
>  
> @@ -1717,7 +1717,7 @@ static QEMUMachine ss2000_machine = {
>      .name = "SS-2000",
>      .desc = "Sun4d platform, SPARCcenter 2000",
>      .init = ss2000_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 20,
>  };
>  
> @@ -1896,7 +1896,7 @@ static QEMUMachine ss2_machine = {
>      .name = "SS-2",
>      .desc = "Sun4c platform, SPARCstation 2",
>      .init = ss2_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static void sun4m_register_types(void)
> diff --git a/hw/versatilepb.c b/hw/versatilepb.c
> index e85f982..86c18aa 100644
> --- a/hw/versatilepb.c
> +++ b/hw/versatilepb.c
> @@ -380,14 +380,14 @@ static QEMUMachine versatilepb_machine = {
>      .name = "versatilepb",
>      .desc = "ARM Versatile/PB (ARM926EJ-S)",
>      .init = vpb_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static QEMUMachine versatileab_machine = {
>      .name = "versatileab",
>      .desc = "ARM Versatile/AB (ARM926EJ-S)",
>      .init = vab_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>  };
>  
>  static void versatile_machine_init(void)
> diff --git a/hw/vexpress.c b/hw/vexpress.c
> index 3f7cb66..8fb9905 100644
> --- a/hw/vexpress.c
> +++ b/hw/vexpress.c
> @@ -497,7 +497,7 @@ static QEMUMachine vexpress_a9_machine = {
>      .name = "vexpress-a9",
>      .desc = "ARM Versatile Express for Cortex-A9",
>      .init = vexpress_a9_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> @@ -505,7 +505,7 @@ static QEMUMachine vexpress_a15_machine = {
>      .name = "vexpress-a15",
>      .desc = "ARM Versatile Express for Cortex-A15",
>      .init = vexpress_a15_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 4,
>  };
>  
> diff --git a/hw/xilinx_zynq.c b/hw/xilinx_zynq.c
> index c55dafb..a4f2c1b 100644
> --- a/hw/xilinx_zynq.c
> +++ b/hw/xilinx_zynq.c
> @@ -181,7 +181,7 @@ static QEMUMachine zynq_machine = {
>      .name = "xilinx-zynq-a9",
>      .desc = "Xilinx Zynq Platform Baseboard for Cortex-A9",
>      .init = zynq_init,
> -    .use_scsi = 1,
> +    .default_drive_if = IF_SCSI,
>      .max_cpus = 1,
>      .no_sdcard = 1
>  };
> diff --git a/vl.c b/vl.c
> index 6dd767c..824d8ae 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -812,9 +812,9 @@ bool usb_enabled(bool default_usb)
>  
>  static int drive_init_func(QemuOpts *opts, void *opaque)
>  {
> -    int *use_scsi = opaque;
> +    int *default_drive_if = opaque;
>  
> -    return drive_init(opts, *use_scsi) == NULL;
> +    return drive_init(opts, *default_drive_if) == NULL;
>  }
>  
>  static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
> @@ -825,14 +825,14 @@ static int drive_enable_snapshot(QemuOpts *opts, void 
> *opaque)
>      return 0;
>  }
>  
> -static void default_drive(int enable, int snapshot, int use_scsi,
> +static void default_drive(int enable, int snapshot, int default_drive_if,
>                            BlockInterfaceType type, int index,
>                            const char *optstr)
>  {
>      QemuOpts *opts;
>  
>      if (type == IF_DEFAULT) {
> -        type = use_scsi ? IF_SCSI : IF_IDE;
> +        type = get_default_drive_if(default_drive_if);
>      }
>  
>      if (!enable || drive_get_by_index(type, index)) {
> @@ -843,7 +843,7 @@ static void default_drive(int enable, int snapshot, int 
> use_scsi,
>      if (snapshot) {
>          drive_enable_snapshot(opts, NULL);
>      }
> -    if (!drive_init(opts, use_scsi)) {
> +    if (!drive_init(opts, default_drive_if)) {
>          exit(1);
>      }
>  }
> @@ -3565,14 +3565,16 @@ int main(int argc, char **argv, char **envp)
>      /* open the virtual block devices */
>      if (snapshot)
>          qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, 
> NULL, 0);
> -    if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, 
> &machine->use_scsi, 1) != 0)
> +    if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
> +                          &machine->default_drive_if, 1) != 0) {
>          exit(1);
> +    }
>  
> -    default_drive(default_cdrom, snapshot, machine->use_scsi,
> +    default_drive(default_cdrom, snapshot, machine->default_drive_if,
>                    IF_DEFAULT, 2, CDROM_OPTS);
> -    default_drive(default_floppy, snapshot, machine->use_scsi,
> +    default_drive(default_floppy, snapshot, machine->default_drive_if,
>                    IF_FLOPPY, 0, FD_OPTS);
> -    default_drive(default_sdcard, snapshot, machine->use_scsi,
> +    default_drive(default_sdcard, snapshot, machine->default_drive_if,
>                    IF_SD, 0, SD_OPTS);
>  
>      register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
> -- 
> 1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]