[libvirt] [PATCH v6 0/3] fix query-command-line-options

This patchset fixed some issues of query-command-line-options: * some new options that haven't argument can't be queried. (eg: -enable-fips) * some legacy options that have argument can't be queried. (eg: -vnc display) More discussion: http://marc.info/?l=qemu-devel&m=139081830416684&w=2 https://www.redhat.com/archives/libvir-list/2014-March/msg00318.html V2: remove duplicate option tables, update schema (eric) V3: fix typo in commitlog and export qemu_options talbe (eric) V4: avoid the duplicate static table (eric) V5: rename new field, other fix (markus) V6: add implied-name (eric, markus) Thanks for your review! Amos Kong (3): qmp: rename query_option_descs() to get_param_info() query-command-line-options: expose implicit parameter name query-command-line-options: query all the options in qemu-options.hx qapi-schema.json | 16 +++++++++++++--- qemu-options.h | 12 ++++++++++++ util/qemu-config.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- vl.c | 19 ++----------------- 4 files changed, 65 insertions(+), 34 deletions(-) -- 1.8.5.3

Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> --- util/qemu-config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/qemu-config.c b/util/qemu-config.c index f610101..508adbc 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -39,7 +39,7 @@ QemuOptsList *qemu_find_opts(const char *group) return ret; } -static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) +static CommandLineParameterInfoList *get_param_info(const QemuOptDesc *desc) { CommandLineParameterInfoList *param_list = NULL, *entry; CommandLineParameterInfo *info; @@ -120,9 +120,9 @@ static CommandLineParameterInfoList *get_drive_infolist(void) for (i = 0; drive_config_groups[i] != NULL; i++) { if (!head) { - head = query_option_descs(drive_config_groups[i]->desc); + head = get_param_info(drive_config_groups[i]->desc); } else { - cur = query_option_descs(drive_config_groups[i]->desc); + cur = get_param_info(drive_config_groups[i]->desc); connect_infolist(head, cur); } } @@ -147,7 +147,7 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, info->parameters = get_drive_infolist(); } else { info->parameters = - query_option_descs(vm_config_groups[i]->desc); + get_param_info(vm_config_groups[i]->desc); } entry = g_malloc0(sizeof(*entry)); entry->value = info; -- 1.8.5.3

This patch added a new field to expose implicit parameter name, we make it optional for compatibility. Suggested-by: Eric Blake <eblake@redhat.com> Signed-off-by: Amos Kong <akong@redhat.com> --- qapi-schema.json | 6 +++++- util/qemu-config.c | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 391356f..9341033 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4088,12 +4088,16 @@ # # @help: #optional human readable text string, not suitable for parsing. # +# @implied-name: #optional, if present and true, the parameter can be +# specified as '-option value' instead of the preferred +# spelling of '-option name=value' (since 2.1) +# # Since 1.5 ## { 'type': 'CommandLineParameterInfo', 'data': { 'name': 'str', 'type': 'CommandLineParameterType', - '*help': 'str' } } + '*help': 'str', '*implied-name': 'bool' } } ## # @CommandLineOptionInfo: diff --git a/util/qemu-config.c b/util/qemu-config.c index 508adbc..85bb0c8 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -39,17 +39,23 @@ QemuOptsList *qemu_find_opts(const char *group) return ret; } -static CommandLineParameterInfoList *get_param_info(const QemuOptDesc *desc) +static CommandLineParameterInfoList *get_param_info(const QemuOptsList *list) { CommandLineParameterInfoList *param_list = NULL, *entry; CommandLineParameterInfo *info; int i; - for (i = 0; desc[i].name != NULL; i++) { + for (i = 0; list->desc[i].name != NULL; i++) { info = g_malloc0(sizeof(*info)); - info->name = g_strdup(desc[i].name); + info->name = g_strdup(list->desc[i].name); - switch (desc[i].type) { + info->has_implied_name = true; + if (list->implied_opt_name && !strcmp(list->desc[i].name, + list->implied_opt_name)) { + info->implied_name = true; + } + + switch (list->desc[i].type) { case QEMU_OPT_STRING: info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; break; @@ -64,9 +70,9 @@ static CommandLineParameterInfoList *get_param_info(const QemuOptDesc *desc) break; } - if (desc[i].help) { + if (list->desc[i].help) { info->has_help = true; - info->help = g_strdup(desc[i].help); + info->help = g_strdup(list->desc[i].help); } entry = g_malloc0(sizeof(*entry)); @@ -120,9 +126,9 @@ static CommandLineParameterInfoList *get_drive_infolist(void) for (i = 0; drive_config_groups[i] != NULL; i++) { if (!head) { - head = get_param_info(drive_config_groups[i]->desc); + head = get_param_info(drive_config_groups[i]); } else { - cur = get_param_info(drive_config_groups[i]->desc); + cur = get_param_info(drive_config_groups[i]); connect_infolist(head, cur); } } @@ -147,7 +153,7 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, info->parameters = get_drive_infolist(); } else { info->parameters = - get_param_info(vm_config_groups[i]->desc); + get_param_info(vm_config_groups[i]); } entry = g_malloc0(sizeof(*entry)); entry->value = info; -- 1.8.5.3

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. This patch also fixes options to match their actual command-line spelling rather than an alternate name associated with the option table in use by the command. Signed-off-by: Amos Kong <akong@redhat.com> --- qapi-schema.json | 10 ++++++++-- qemu-options.h | 12 ++++++++++++ util/qemu-config.c | 30 ++++++++++++++++++++++++------ vl.c | 19 ++----------------- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 9341033..36812d4 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4106,12 +4106,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: diff --git a/qemu-options.h b/qemu-options.h index 89a009e..4024487 100644 --- a/qemu-options.h +++ b/qemu-options.h @@ -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 diff --git a/util/qemu-config.c b/util/qemu-config.c index 85bb0c8..0697cb9 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -6,6 +6,14 @@ #include "hw/qdev.h" #include "qapi/error.h" #include "qmp-commands.h" +#include "qemu-options.h" + +const QEMUOption qemu_options[] = { + { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, +#define QEMU_OPTIONS_GENERATE_OPTIONS +#include "qemu-options-wrapper.h" + { NULL }, +}; static QemuOptsList *vm_config_groups[32]; static QemuOptsList *drive_config_groups[4]; @@ -143,18 +151,26 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, { CommandLineOptionInfoList *conf_list = NULL, *entry; CommandLineOptionInfo *info; + QemuOptsList *list; int i; - for (i = 0; vm_config_groups[i] != NULL; i++) { - if (!has_option || !strcmp(option, vm_config_groups[i]->name)) { + for (i = 0; qemu_options[i].name; i++) { + if (!has_option || !strcmp(option, qemu_options[i].name)) { info = g_malloc0(sizeof(*info)); - info->option = g_strdup(vm_config_groups[i]->name); - if (!strcmp("drive", vm_config_groups[i]->name)) { + info->option = g_strdup(qemu_options[i].name); + + if (!strcmp("drive", qemu_options[i].name)) { info->parameters = get_drive_infolist(); } else { - info->parameters = - get_param_info(vm_config_groups[i]); + list = qemu_find_opts_err(qemu_options[i].name, NULL); + info->parameters = list ? get_param_info(list) : NULL; } + + if (!info->parameters) { + info->has_unspecified_parameters = true; + info->unspecified_parameters = qemu_options[i].flags & HAS_ARG; + } + entry = g_malloc0(sizeof(*entry)); entry->value = info; entry->next = conf_list; @@ -169,6 +185,8 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, return conf_list; } +#undef HAS_ARG + QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp); diff --git a/vl.c b/vl.c index a64dd0a..5bfcff9 100644 --- a/vl.c +++ b/vl.c @@ -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); -- 1.8.5.3

On Thu, Mar 27, 2014 at 02:57:00PM +0800, Amos Kong wrote:
This patchset fixed some issues of query-command-line-options: * some new options that haven't argument can't be queried. (eg: -enable-fips) * some legacy options that have argument can't be queried. (eg: -vnc display)
More discussion: http://marc.info/?l=qemu-devel&m=139081830416684&w=2 https://www.redhat.com/archives/libvir-list/2014-March/msg00318.html
V2: remove duplicate option tables, update schema (eric) V3: fix typo in commitlog and export qemu_options talbe (eric) V4: avoid the duplicate static table (eric) V5: rename new field, other fix (markus) V6: add implied-name (eric, markus)
Thanks for your review!
Attached query output file, ([1] was additionally applied) [1] https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg05175.html [PATCH 0/3] ABI change: change group name of option table to match with option name ---------------------- { "name": "order", "implied-name": true, <-- optional 'implied-name' was added "type": "string" \-boot c,menu=on / -boot order=c,menu=on } ], "option": "boot" <---- "boot-opts" was fixed by [1] }, ----------------------- { "parameters": [ ], "option": "enable-fips", <-- lost enable-fips was queried \ from qemu-options.hx "unspecified-parameters": false <-- -enable-fips (bool option) }, ----------------------- { "parameters": [ <----- desc table is NULL ], "option": "cdrom", "unspecified-parameters": true <---- but it can accept argument }, ------------------------ See the detail in the attachment. Thanks, Amos
Amos Kong (3): qmp: rename query_option_descs() to get_param_info() query-command-line-options: expose implicit parameter name query-command-line-options: query all the options in qemu-options.hx
participants (1)
-
Amos Kong