>From 7e5f08331fdcc074027de0767bcbbc4d3af9a546 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Thu, 27 Mar 2014 07:37:24 +0800 Subject: [PATCH RFC 1/2] add alias_index to QemuOptsList If group name of option table doesn't match with option name, we will save the index of QEMU_OPTION index to alias_index. Then we can try to find QemuOptsList by index for unmatched options. alias_index of matched options will be set to -1. Signed-off-by: Amos Kong --- hw/acpi/core.c | 2 ++ include/qapi/qmp/qerror.h | 3 +++ include/qemu/config-file.h | 1 + include/qemu/option.h | 1 + util/qemu-config.c | 16 ++++++++++++++++ vl.c | 2 ++ 6 files changed, 25 insertions(+) diff --git a/hw/acpi/core.c b/hw/acpi/core.c index 79414b4..1f459fc 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -27,6 +27,7 @@ #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" #include "qapi-visit.h" +#include "qemu-options.h" struct acpi_table_header { uint16_t _length; /* our length, not actual part of the hdr */ @@ -64,6 +65,7 @@ static QemuOptsList qemu_acpi_opts = { static void acpi_register_config(void) { qemu_add_opts(&qemu_acpi_opts); + qemu_set_opt_index(qemu_acpi_opts.name, QEMU_OPTION_acpitable, NULL); } machine_init(acpi_register_config); diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index da75abf..cfbd29d 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -134,6 +134,9 @@ void qerror_report_err(Error *err); #define QERR_INVALID_OPTION_GROUP \ ERROR_CLASS_GENERIC_ERROR, "There is no option group '%s'" +#define QERR_INVALID_OPTION_INDEX \ + ERROR_CLASS_GENERIC_ERROR, "There is no option index '%d'" + #define QERR_INVALID_PARAMETER \ ERROR_CLASS_GENERIC_ERROR, "Invalid parameter '%s'" diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index dbd97c4..1884313 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -8,6 +8,7 @@ QemuOptsList *qemu_find_opts(const char *group); QemuOptsList *qemu_find_opts_err(const char *group, Error **errp); +void qemu_set_opt_index(const char *group, int index, Error **errp); void qemu_add_opts(QemuOptsList *list); void qemu_add_drive_opts(QemuOptsList *list); int qemu_set_option(const char *str); diff --git a/include/qemu/option.h b/include/qemu/option.h index 8c0ac34..0d63ec9 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -103,6 +103,7 @@ typedef struct QemuOptDesc { struct QemuOptsList { const char *name; + int alias_index; const char *implied_opt_name; bool merge_lists; /* Merge multiple uses of option into a single list? */ QTAILQ_HEAD(, QemuOpts) head; diff --git a/util/qemu-config.c b/util/qemu-config.c index 508adbc..877d0e9 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -184,6 +184,21 @@ void qemu_add_drive_opts(QemuOptsList *list) abort(); } +void qemu_set_opt_index(const char *group, int index, Error **errp) +{ + int i; + + for (i = 0; vm_config_groups[i] != NULL; i++) { + if (strcmp(vm_config_groups[i]->name, group) == 0) { + vm_config_groups[i]->alias_index = index; + break; + } + } + if (vm_config_groups[i] == NULL) { + error_set(errp, QERR_INVALID_OPTION_GROUP, group); + } +} + void qemu_add_opts(QemuOptsList *list) { int entries, i; @@ -193,6 +208,7 @@ void qemu_add_opts(QemuOptsList *list) for (i = 0; i < entries; i++) { if (vm_config_groups[i] == NULL) { vm_config_groups[i] = list; + list->alias_index = -1; return; } } diff --git a/vl.c b/vl.c index 2355227..6457d6d 100644 --- a/vl.c +++ b/vl.c @@ -2988,7 +2988,9 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_option_rom_opts); qemu_add_opts(&qemu_machine_opts); qemu_add_opts(&qemu_smp_opts); + qemu_set_opt_index(qemu_smp_opts.name, QEMU_OPTION_smp, NULL); qemu_add_opts(&qemu_boot_opts); + qemu_set_opt_index(qemu_boot_opts.name, QEMU_OPTION_boot, NULL); qemu_add_opts(&qemu_sandbox_opts); qemu_add_opts(&qemu_add_fd_opts); qemu_add_opts(&qemu_object_opts); -- 1.8.5.3