update names in option tables to match with actual command-line spelling
PATCH v3 1/1 update names in option tables to match with actual command-line spelling
We want to establish a mapping between option name and option table, then we can search related option table by option name.
This patch makes all the member name of QemuOptsList to match with actual command-line spelling(option name).
[ Important Note ]
The QemuOptsList member name values are ABI, changing them can break existing -readconfig configuration files.
This patch changes:
from to introduced in
acpi acpitable 0c764a9 v1.5.0
boot-opts boot 3d3b830 v1.0
smp-opts smp 12b7f57 v1.6.0All three have calcified into ABI already.
I have updated the release note of 2.0
http://wiki.qemu.org/ChangeLog/2.0#ABI_breaking
---
V2: fix name in acpi option table
V3: mention ABI break in commitlog (Markus)
--- hw/acpi/core.c | 8 ++++---- hw/nvram/fw_cfg.c | 4 ++-- include/qemu/option.h | 2 +- vl.c | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-)
hw/acpi/core.c +4 -4
@@ -54,16 +54,16 @@ static const char unsigned dfl_hdr[ACPI_TABLE_HDR_SIZE - ACPI_TABLE_PFX_SIZE] =char unsigned *acpi_tables;size_t acpi_tables_len; -static QemuOptsList qemu_acpi_opts = { - .name ="acpi" , +static QemuOptsList qemu_acpitable_opts = { + .name ="acpitable" , .implied_opt_name ="data" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_acpi_opts.head), + .head =QTAILQ_HEAD_INITIALIZER (qemu_acpitable_opts.head), .desc = { {0 } }/* validated with OptsVisitor */ };static void acpi_register_config (void ) { -qemu_add_opts (&qemu_acpi_opts); +qemu_add_opts (&qemu_acpitable_opts); }machine_init (acpi_register_config);
hw/nvram/fw_cfg.c +2 -2
@@ -125,7 +125,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)const char *temp;/* get user configuration */ -QemuOptsList *plist =qemu_find_opts ("boot-opts" ); +QemuOptsList *plist =qemu_find_opts ("boot" );QemuOpts *opts =QTAILQ_FIRST (&plist->head);if (opts !=NULL ) { temp =qemu_opt_get (opts,"splash" );
@@ -191,7 +191,7 @@ static void fw_cfg_reboot(FWCfgState *s)const char *temp;/* get user configuration */ -QemuOptsList *plist =qemu_find_opts ("boot-opts" ); +QemuOptsList *plist =qemu_find_opts ("boot" );QemuOpts *opts =QTAILQ_FIRST (&plist->head);if (opts !=NULL ) { temp =qemu_opt_get (opts,"reboot-timeout" );
include/qemu/option.h +1 -1
@@ -102,7 +102,7 @@ typedef struct QemuOptDesc { } QemuOptDesc;struct QemuOptsList { -const char *name; +const char *name;/* option name */ const char *implied_opt_name;bool merge_lists;/* Merge multiple uses of option into a single list? */ QTAILQ_HEAD(, QemuOpts) head;
vl.c +7 -7
@@ -388,7 +388,7 @@ static QemuOptsList qemu_machine_opts = { };static QemuOptsList qemu_boot_opts = { - .name ="boot-opts" , + .name ="boot" , .implied_opt_name ="order" , .merge_lists = true, .head =QTAILQ_HEAD_INITIALIZER (qemu_boot_opts.head),
@@ -1357,7 +1357,7 @@ static void numa_add(const char *optarg) }static QemuOptsList qemu_smp_opts = { - .name ="smp-opts" , + .name ="smp" , .implied_opt_name ="cpus" , .merge_lists = true, .head =QTAILQ_HEAD_INITIALIZER (qemu_smp_opts.head),
@@ -3245,7 +3245,7 @@ int main(int argc, char **argv, char **envp)drive_add (IF_DEFAULT ,2 , optarg,CDROM_OPTS );break ;case QEMU_OPTION_boot: - opts =qemu_opts_parse (qemu_find_opts ("boot-opts" ), optarg,1 ); + opts =qemu_opts_parse (qemu_find_opts ("boot" ), optarg,1 );if (!opts) {exit (1 ); }
@@ -3614,7 +3614,7 @@ int main(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_acpitable: - opts =qemu_opts_parse (qemu_find_opts ("acpi" ), optarg,1 ); + opts =qemu_opts_parse (qemu_find_opts ("acpitable" ), optarg,1 );if (!opts) {exit (1 ); }
@@ -3681,7 +3681,7 @@ int main(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_smp: -if (!qemu_opts_parse (qemu_find_opts ("smp-opts" ), optarg,1 )) { +if (!qemu_opts_parse (qemu_find_opts ("smp" ), optarg,1 )) {exit (1 ); }break ;
@@ -4006,7 +4006,7 @@ int main(int argc, char **argv, char **envp) data_dir[data_dir_idx++] =CONFIG_QEMU_DATADIR ; } -smp_parse (qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL )); +smp_parse (qemu_opts_find (qemu_find_opts ("smp" ),NULL )); machine->max_cpus = machine->max_cpus ?:1 ;/* Default to UP */ if (smp_cpus > machine->max_cpus) {
@@ -4190,7 +4190,7 @@ int main(int argc, char **argv, char **envp) bios_name =qemu_opt_get (machine_opts,"firmware" ); boot_order = machine->default_boot_order; - opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL ); + opts =qemu_opts_find (qemu_find_opts ("boot" ),NULL );if (opts) {char *normal_boot_order;const char *order, *once;
Signature · 1 line
1.8.5.3
Quoted 18 lines · Amos Kong
We want to establish a mapping between option name and option table, then we can search related option table by option name.
This patch makes all the member name of QemuOptsList to match with actual command-line spelling(option name).
[ Important Note ]
The QemuOptsList member name values are ABI, changing them can break existing -readconfig configuration files.
This patch changes:
from to introduced in acpi acpitable 0c764a9 v1.5.0 boot-opts boot 3d3b830 v1.0 smp-opts smp 12b7f57 v1.6.0
Quoted 7 lines
All three have calcified into ABI already.
I have updated the release note of 2.0
http://wiki.qemu.org/ChangeLog/2.0#ABI_breakingSigned-off-by Amos Kong <[email protected]>---
The benefit of this patch is that 'query-command-line-options' gains a fix where three bogus entries are replaced by their actual command line spelling. The drawback is that anyone that doesn't pay attention to the ABI break announcement, and expects -readconfig and friends to work while using the old spelling, is in for a surprise. But since we have prominently documented the change, and since consistency makes life nicer, I'm in favor of this patch.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 35 lines · Eric Blake
Quoted 18 lines · Amos Kong
We want to establish a mapping between option name and option table, then we can search related option table by option name.
This patch makes all the member name of QemuOptsList to match with actual command-line spelling(option name).
[ Important Note ]
The QemuOptsList member name values are ABI, changing them can break existing -readconfig configuration files.
This patch changes:
from to introduced in acpi acpitable 0c764a9 v1.5.0 boot-opts boot 3d3b830 v1.0 smp-opts smp 12b7f57 v1.6.0Quoted 7 lines
All three have calcified into ABI already.
I have updated the release note of 2.0
http://wiki.qemu.org/ChangeLog/2.0#ABI_breakingSigned-off-by Amos Kong <[email protected]>---
The benefit of this patch is that 'query-command-line-options' gains a fix where three bogus entries are replaced by their actual command line spelling. The drawback is that anyone that doesn't pay attention to the ABI break announcement, and expects -readconfig and friends to work while using the old spelling, is in for a surprise. But since we have prominently documented the change, and since consistency makes life nicer, I'm in favor of this patch.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
I'm not thrilled about the ABI break, but avoiding it would probably take too much code for too little gain.
How can we prevent future violations of the convention "QemuOptsList member name matches the name of the (primary) option using it for its argument"? Right now, all we have is /* option name */ tacked to the member. Which is at best a reminder for those who already know.
I'd ask for a test catching violations if I could think of an easy way to code it.
Quoted 37 lines · Markus Armbruster
Quoted 35 lines · Eric Blake
Quoted 18 lines · Amos Kong
We want to establish a mapping between option name and option table, then we can search related option table by option name.
This patch makes all the member name of QemuOptsList to match with actual command-line spelling(option name).
[ Important Note ]
The QemuOptsList member name values are ABI, changing them can break existing -readconfig configuration files.
This patch changes:
from to introduced in acpi acpitable 0c764a9 v1.5.0 boot-opts boot 3d3b830 v1.0 smp-opts smp 12b7f57 v1.6.0Quoted 7 lines
All three have calcified into ABI already.
I have updated the release note of 2.0
http://wiki.qemu.org/ChangeLog/2.0#ABI_breakingSigned-off-by Amos Kong <[email protected]>---
The benefit of this patch is that 'query-command-line-options' gains a fix where three bogus entries are replaced by their actual command line spelling. The drawback is that anyone that doesn't pay attention to the ABI break announcement, and expects -readconfig and friends to work while using the old spelling, is in for a surprise. But since we have prominently documented the change, and since consistency makes life nicer, I'm in favor of this patch.
Quoted 4 lines
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>I'm not thrilled about the ABI break, but avoiding it would probably take too much code for too little gain.
We can add an 'alias_index' field to QemuOptsList, and init it to -1 in qemu_add_opts().
And we only re-set 'alias_index' to 'popt->index' in vl.c(option parsing part) then we can find opts by qemu_options[i].index.
We also need to give a warning () if it's group name of added QemuOptsList doesn't match with defined option name.
If someone add a new QemuOpts and the group name doesn't match, he/she will get a warning, and call a help function to re-set 'alias_index'.
I can send a RFC patch for this.
Quoted 4 lines
How can we prevent future violations of the convention "QemuOptsList member name matches the name of the (primary) option using it for its argument"? Right now, all we have is /* option name */ tacked to the member. Which is at best a reminder for those who already know.
It's absolutely necessary!
Quoted 2 lines
I'd ask for a test catching violations if I could think of an easy way to code it.
Currently I prefer this option, so I will send a V3 with strict checking.
Signature · 1 line
Amos.
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Eric Blake <[email protected]> writes:
...
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>I'm not thrilled about the ABI break, but avoiding it would probably take too much code for too little gain.
Hi Markus, Eric
Quoted 6 lines
We can add an '
alias_index' field to QemuOptsList, and init it to -1 inqemu_add_opts().And we only re-set '
alias_index' to 'popt->index' invl.c(option parsing part)then we can find opts by qemu_options[i].index.
Quoted 7 lines
We also need to give a warning () if it's group name of added QemuOptsList doesn't match with defined option name.
If someone add a new QemuOpts and the group name doesn't match, he/she will get a warning, and call a help function to re-set '
alias_index'.I can send a RFC patch for this.
* Option 1
Attached two RFC patches, it added a new field ('alias_index') to QemuOptsList, and record QEMU_OPTION enum-index to it when group name of option table doesn't match option name.
And try to find list by index before find list by option name in qmp_query_command_line_options().
This can avoid the ABI breaking, it also introduced some trouble. We also need to check if alias_index of unmatched option is set to a positive number, and report error (option name doesn't match, and alias_index isn't set) in error state.
* Option 2
OR pass enum-index to qemu_add_opts(), and set enum-index for all the options.
-void qemu_add_opts(QemuOptsList *list)
+void qemu_add_opts(QemuOptsList *list, int index)
* Option 3 break ABI
Let's make a decision.
Quoted 11 lines
Quoted 4 lines
How can we prevent future violations of the convention "QemuOptsList member name matches the name of the (primary) option using it for its argument"? Right now, all we have is /* option name */ tacked to the member. Which is at best a reminder for those who already know.
It's absolutely necessary!
Quoted 2 lines
I'd ask for a test catching violations if I could think of an easy way to code it.
Currently I prefer this option, so I will send a V3 with strict checking.
Signature · 1 line
Amos.
Quoted 1 line
From
7e5f08331fdcc074027de0767bcbbc4d3af9a546Mon Sep 17 00:00:00 2001
From: Amos Kong <[email protected]>
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.
--- 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(+)
hw/acpi/core.c +2 -0
@@ -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);
include/qapi/qmp/qerror.h +3 -0
@@ -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'"
include/qemu/config-file.h +1 -0
@@ -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);
include/qemu/option.h +1 -0
@@ -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;
util/qemu-config.c +16 -0
@@ -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 ; } }
vl.c +2 -0
@@ -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);
Signature · 1 line
1.8.5.3
Quoted 1 line
From
5d0308014bbee9b5753a8f432b3a751033b98458Mon Sep 17 00:00:00 2001
From: Amos Kong <[email protected]>
Date: Tue, 28 Jan 2014 11:17:09 +0800
Subject: [PATCH RFC 2/2] query-command-line-options: query all the options in
qemu-options.hx
vm_config_groups[] only contains part of the options which have parameters, and all options which have no parameter aren't added to vm_config_groups[]. Current query-command-line-options only checks options from vm_config_groups[], so some options will be lost.
We have macro in qemu-options.hx to generate a table that contains all the options. This patch tries to query options from the table.
Then we won't lose the legacy options that weren't added to vm_config_groups[] (eg: -vnc, -smbios). The options that have no parameter will also be returned (eg: -enable-fips)
Some options that have parameters have a NULL desc list, some options don't have parameters, and "parameters" is mandatory in the past. So we add a new field "unspecified-parameters" to present if the option takes unspecified parameters.
Some group names('smp-opts', 'boot-opts', 'acpi') of option tables don't match their actual command-line spelling, we will try to find the QemuOptsList by index.
--- qapi-schema.json | 10 ++++++++-- qemu-options.h | 12 ++++++++++++ util/qemu-config.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ vl.c | 19 ++----------------- 4 files changed, 65 insertions(+), 25 deletions(-)
qapi-schema.json +8 -2
@@ -4102,12 +4102,18 @@ # # @option: option name # -# @parameters: an array of @CommandLineParameterInfo +# @parameters: array of @CommandLineParameterInfo, possibly empty +# +# @unspecified-parameters: @optional present if the @parameters array is empty. +# If true, then the option takes unspecified +# parameters, if false, then the option takes no +# parameter (since 2.1) # # Since 1.5 ## { 'type': 'CommandLineOptionInfo', - 'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } } + 'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'], + '*unspecified-parameters': 'bool' } } ## # @query-command-line-options:
qemu-options.h +12 -0
@@ -28,9 +28,21 @@#ifndef _QEMU_OPTIONS_H_#define _QEMU_OPTIONS_H_ +#include "sysemu/arch_init.h" + enum { #define QEMU_OPTIONS_GENERATE_ENUM#include "qemu-options-wrapper.h" }; +#define HAS_ARG 0x0001 + +typedef struct QEMUOption { +const char *name; +int flags; +int index; +uint32_t arch_mask; +}QEMUOption ; + +extern const QEMUOption qemu_options[];#endif
util/qemu-config.c +43 -6
79 lines not on this page · raw message
vl.c +2 -17
@@ -111,7 +111,6 @@ int main(int argc, char **argv)#include "trace/control.h" #include "qemu/queue.h" #include "sysemu/cpus.h" -#include "sysemu/arch_init.h" #include "qemu/osdep.h" #include "ui/qemu-spice.h"
@@ -2080,22 +2079,6 @@ static void help(int exitcode)exit (exitcode); } -#define HAS_ARG 0x0001 - -typedef struct QEMUOption { -const char *name; -int flags; -int index; -uint32_t arch_mask; -}QEMUOption ; - -static const QEMUOption qemu_options[] = { - {"h" ,0 , QEMU_OPTION_h,QEMU_ARCH_ALL }, -#define QEMU_OPTIONS_GENERATE_OPTIONS -#include "qemu-options-wrapper.h" - {NULL }, -}; -static bool vga_available (void ) {return object_class_by_name ("VGA" ) ||object_class_by_name ("isa-vga" );
@@ -2840,6 +2823,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv,return popt; } +#undef HAS_ARG +static gpointer malloc_and_trace (gsize n_bytes) {void *ptr =malloc (n_bytes);
Signature · 1 line
1.8.5.3