Il 05/09/2012 21:52, Anthony Liguori ha scritto: > Signed-off-by: Anthony Liguori <aligu...@us.ibm.com> > --- > arch_init.c | 10 +++++----- > arch_init.h | 2 +- > hw/smbios.c | 53 +++++++++++++++++++++++++++++++---------------------- > hw/smbios.h | 2 +- > qemu-config.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ > vl.c | 4 +++- > 6 files changed, 91 insertions(+), 30 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index 5a1173e..e43ace9 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -1033,13 +1033,13 @@ void do_acpitable_option(const char *optarg) > #endif > } > > -void do_smbios_option(const char *optarg) > +int do_smbios_option(QemuOpts *opts, void *opaque) > { > #ifdef TARGET_I386 > - if (smbios_entry_add(optarg) < 0) { > - fprintf(stderr, "Wrong smbios provided\n"); > - exit(1); > - } > + return smbios_entry_add(opts); > +#else > + fprintf(stderr, "-smbios option not supported on this platform\n"); > + return -ENOSYS; > #endif > } > > diff --git a/arch_init.h b/arch_init.h > index d9c572a..2dce578 100644 > --- a/arch_init.h > +++ b/arch_init.h > @@ -26,7 +26,7 @@ extern const uint32_t arch_type; > > void select_soundhw(const char *optarg); > void do_acpitable_option(const char *optarg); > -void do_smbios_option(const char *optarg); > +int do_smbios_option(QemuOpts *opts, void *opaque); > void cpudef_init(void); > int audio_available(void); > void audio_init(ISABus *isa_bus, PCIBus *pci_bus); > diff --git a/hw/smbios.c b/hw/smbios.c > index c57237d..095bccc 100644 > --- a/hw/smbios.c > +++ b/hw/smbios.c > @@ -124,21 +124,24 @@ void smbios_add_field(int type, int offset, int len, > void *data) > cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1); > } > > -static void smbios_build_type_0_fields(const char *t) > +static void smbios_build_type_0_fields(QemuOpts *opts) > { > char buf[1024]; > > - if (get_param_value(buf, sizeof(buf), "vendor", t)) > + if ((buf = qemu_opt_get(opts, "vendor"))) { > smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "version", t)) > + } > + if ((buf = qemu_opt_get(opts, "version"))) { > smbios_add_field(0, offsetof(struct smbios_type_0, bios_version_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "date", t)) > + } > + if ((buf = qemu_opt_get(opts, "date"))) { > smbios_add_field(0, offsetof(struct smbios_type_0, > bios_release_date_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "release", t)) { > + } > + if ((buf = qemu_opt_get(opts, "release"))) { > int major, minor; > sscanf(buf, "%d.%d", &major, &minor); > smbios_add_field(0, offsetof(struct smbios_type_0, > @@ -148,41 +151,47 @@ static void smbios_build_type_0_fields(const char *t) > } > } > > -static void smbios_build_type_1_fields(const char *t) > +static void smbios_build_type_1_fields(QemuOpts *opts) > { > - char buf[1024]; > + const char *buf; > > - if (get_param_value(buf, sizeof(buf), "manufacturer", t)) > + if ((buf = qemu_opt_get(opts, "manufacturer"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, manufacturer_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "product", t)) > + } > + if ((buf = qemu_opt_get(opts, "product"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, product_name_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "version", t)) > + } > + if ((buf = qemu_opt_get(opts, "version"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, version_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "serial", t)) > + } > + if ((buf = qemu_opt_get(opts, "serial"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, > serial_number_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "uuid", t)) { > + } > + if ((buf = qemu_opt_get(opts, "uuid"))) { > if (qemu_uuid_parse(buf, qemu_uuid) != 0) { > fprintf(stderr, "Invalid SMBIOS UUID string\n"); > exit(1); > } > } > - if (get_param_value(buf, sizeof(buf), "sku", t)) > + if ((buf = qemu_opt_get(opts, "sku"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, sku_number_str), > strlen(buf) + 1, buf); > - if (get_param_value(buf, sizeof(buf), "family", t)) > + } > + if ((buf = qemu_opt_get(opts, "family"))) { > smbios_add_field(1, offsetof(struct smbios_type_1, family_str), > strlen(buf) + 1, buf); > + } > } > > -int smbios_entry_add(const char *t) > +int smbios_entry_add(QemuOpts *opts) > { > - char buf[1024]; > + const char *buf; > > - if (get_param_value(buf, sizeof(buf), "file", t)) { > + if ((buf = qemu_opt_get(opts, "file"))) { > struct smbios_structure_header *header; > struct smbios_table *table; > int size = get_image_size(buf); > @@ -203,7 +212,7 @@ int smbios_entry_add(const char *t) > table->header.type = SMBIOS_TABLE_ENTRY; > table->header.length = cpu_to_le16(sizeof(*table) + size); > > - if (load_image(buf, table->data) != size) { > + if (load_image(filename, table->data) != size) { > fprintf(stderr, "Failed to load smbios file %s", buf); > exit(1); > } > @@ -220,14 +229,14 @@ int smbios_entry_add(const char *t) > return 0; > } > > - if (get_param_value(buf, sizeof(buf), "type", t)) { > - unsigned long type = strtoul(buf, NULL, 0); > + if (qemu_opt_get(opts, "type")) { > + unsigned long type = qemu_opt_get_number(opts, "type"); > switch (type) { > case 0: > - smbios_build_type_0_fields(t); > + smbios_build_type_0_fields(opts); > return 0; > case 1: > - smbios_build_type_1_fields(t); > + smbios_build_type_1_fields(opts); > return 0; > default: > fprintf(stderr, "Don't know how to build fields for SMBIOS type " > diff --git a/hw/smbios.h b/hw/smbios.h > index 94e3641..6392fbe 100644 > --- a/hw/smbios.h > +++ b/hw/smbios.h > @@ -13,7 +13,7 @@ > * > */ > > -int smbios_entry_add(const char *t); > +int smbios_entry_add(QemuOpts *opts); > void smbios_add_field(int type, int offset, int len, void *data); > uint8_t *smbios_get_table(size_t *length); > > diff --git a/qemu-config.c b/qemu-config.c > index c05ffbc..3031012 100644 > --- a/qemu-config.c > +++ b/qemu-config.c > @@ -643,6 +643,55 @@ QemuOptsList qemu_boot_opts = { > }, > }; > > +QemuOptsList qemu_smbios_opts = { > + .name = "smbios", > + .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head), > + .desc = { > + { > + .name = "file", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "type", > + .type = QEMU_OPT_NUMBER, > + }, { > + .name = "manufacturer", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "product", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "version", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "serial", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "uuid", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "sku", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "family", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "vendor", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "version", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "date", > + .type = QEMU_OPT_STRING, > + }, { > + .name = "release", > + .type = QEMU_OPT_STRING, > + }, { > + /* End of list */ > + } > + }, > +}; > + > static QemuOptsList *vm_config_groups[32] = { > &qemu_drive_opts, > &qemu_chardev_opts, > @@ -659,6 +708,7 @@ static QemuOptsList *vm_config_groups[32] = { > &qemu_boot_opts, > &qemu_iscsi_opts, > &qemu_sandbox_opts, > + &qemu_smbios_opts, > NULL, > }; > > diff --git a/vl.c b/vl.c > index 47c5974..ba56cee 100644 > --- a/vl.c > +++ b/vl.c > @@ -3050,7 +3050,7 @@ int main(int argc, char **argv, char **envp) > do_acpitable_option(optarg); > break; > case QEMU_OPTION_smbios: > - do_smbios_option(optarg); > + opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 1); > break; > case QEMU_OPTION_enable_kvm: > olist = qemu_find_opts("machine"); > @@ -3368,6 +3368,8 @@ int main(int argc, char **argv, char **envp) > exit(1); > } > > + qemu_opts_foreach(qemu_find_opts("smbios"), do_smbios_option, NULL, 0); > + > /* > * Get the default machine options from the machine if it is not already > * specified either by the configuration file or by the command line. >
Looks good. Paolo