Message ID | 20240404194757.9343-5-philmd@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | buildsys: Start shrinking qemu-user build process | expand |
On Thu, Apr 4, 2024 at 9:48 PM Philippe Mathieu-Daudé <philmd@linaro.org> wrote: > > QMP is irrelevant for user emulation. Extract the code > related to QMP in a different source file, which won't > be build for user emulation binaries. This avoid pulling > pointless code. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/qemu/config-file.h | 3 + > util/qemu-config-qmp.c | 206 +++++++++++++++++++++++++++++++++++++ This should go under monitor/. Queued all except patch 2, please resubmit that and send it to qemu-block@nongnu.org. > util/qemu-config.c | 204 +----------------------------------- > util/meson.build | 1 + > 4 files changed, 212 insertions(+), 202 deletions(-) > create mode 100644 util/qemu-config-qmp.c > > diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h > index b82a778123..8b9d6df173 100644 > --- a/include/qemu/config-file.h > +++ b/include/qemu/config-file.h > @@ -8,6 +8,9 @@ QemuOptsList *qemu_find_opts(const char *group); > QemuOptsList *qemu_find_opts_err(const char *group, Error **errp); > QemuOpts *qemu_find_opts_singleton(const char *group); > > +extern QemuOptsList *vm_config_groups[48]; > +extern QemuOptsList *drive_config_groups[5]; > + > void qemu_add_opts(QemuOptsList *list); > void qemu_add_drive_opts(QemuOptsList *list); > int qemu_global_option(const char *str); > diff --git a/util/qemu-config-qmp.c b/util/qemu-config-qmp.c > new file mode 100644 > index 0000000000..24477a0e44 > --- /dev/null > +++ b/util/qemu-config-qmp.c > @@ -0,0 +1,206 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +#include "qemu/osdep.h" > +#include "qapi/error.h" > +#include "qapi/qapi-commands-misc.h" > +#include "qapi/qmp/qlist.h" > +#include "qemu/option.h" > +#include "qemu/config-file.h" > +#include "hw/boards.h" > + > +static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) > +{ > + CommandLineParameterInfoList *param_list = NULL; > + CommandLineParameterInfo *info; > + int i; > + > + for (i = 0; desc[i].name != NULL; i++) { > + info = g_malloc0(sizeof(*info)); > + info->name = g_strdup(desc[i].name); > + > + switch (desc[i].type) { > + case QEMU_OPT_STRING: > + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > + break; > + case QEMU_OPT_BOOL: > + info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; > + break; > + case QEMU_OPT_NUMBER: > + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; > + break; > + case QEMU_OPT_SIZE: > + info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; > + break; > + } > + > + info->help = g_strdup(desc[i].help); > + info->q_default = g_strdup(desc[i].def_value_str); > + > + QAPI_LIST_PREPEND(param_list, info); > + } > + > + return param_list; > +} > + > +/* remove repeated entry from the info list */ > +static void cleanup_infolist(CommandLineParameterInfoList *head) > +{ > + CommandLineParameterInfoList *pre_entry, *cur, *del_entry; > + > + cur = head; > + while (cur->next) { > + pre_entry = head; > + while (pre_entry != cur->next) { > + if (!strcmp(pre_entry->value->name, cur->next->value->name)) { > + del_entry = cur->next; > + cur->next = cur->next->next; > + del_entry->next = NULL; > + qapi_free_CommandLineParameterInfoList(del_entry); > + break; > + } > + pre_entry = pre_entry->next; > + } > + cur = cur->next; > + } > +} > + > +/* merge the description items of two parameter infolists */ > +static void connect_infolist(CommandLineParameterInfoList *head, > + CommandLineParameterInfoList *new) > +{ > + CommandLineParameterInfoList *cur; > + > + cur = head; > + while (cur->next) { > + cur = cur->next; > + } > + cur->next = new; > +} > + > +/* access all the local QemuOptsLists for drive option */ > +static CommandLineParameterInfoList *get_drive_infolist(void) > +{ > + CommandLineParameterInfoList *head = NULL, *cur; > + int i; > + > + for (i = 0; drive_config_groups[i] != NULL; i++) { > + if (!head) { > + head = query_option_descs(drive_config_groups[i]->desc); > + } else { > + cur = query_option_descs(drive_config_groups[i]->desc); > + connect_infolist(head, cur); > + } > + } > + cleanup_infolist(head); > + > + return head; > +} > + > +static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) > +{ > + CommandLineParameterInfo *info; > + > + info = g_malloc0(sizeof(*info)); > + info->name = g_strdup(prop->name); > + > + if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) { > + info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; > + } else if (g_str_equal(prop->type, "int")) { > + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; > + } else if (g_str_equal(prop->type, "size")) { > + info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; > + } else { > + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > + } > + > + if (prop->description) { > + info->help = g_strdup(prop->description); > + } > + > + return info; > +} > + > +static CommandLineParameterInfoList *query_all_machine_properties(void) > +{ > + CommandLineParameterInfoList *params = NULL, *clpiter; > + CommandLineParameterInfo *info; > + GSList *machines, *curr_mach; > + ObjectPropertyIterator op_iter; > + ObjectProperty *prop; > + bool is_new; > + > + machines = object_class_get_list(TYPE_MACHINE, false); > + assert(machines); > + > + /* Loop over all machine classes */ > + for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) { > + object_class_property_iter_init(&op_iter, curr_mach->data); > + /* ... and over the properties of each machine: */ > + while ((prop = object_property_iter_next(&op_iter))) { > + if (!prop->set) { > + continue; > + } > + /* > + * Check whether the property has already been put into the list > + * (via another machine class) > + */ > + is_new = true; > + for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) { > + if (g_str_equal(clpiter->value->name, prop->name)) { > + is_new = false; > + break; > + } > + } > + /* If it hasn't been added before, add it now to the list */ > + if (is_new) { > + info = objprop_to_cmdline_prop(prop); > + QAPI_LIST_PREPEND(params, info); > + } > + } > + } > + > + g_slist_free(machines); > + > + /* Add entry for the "type" parameter */ > + info = g_malloc0(sizeof(*info)); > + info->name = g_strdup("type"); > + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > + info->help = g_strdup("machine type"); > + QAPI_LIST_PREPEND(params, info); > + > + return params; > +} > + > +CommandLineOptionInfoList *qmp_query_command_line_options(const char *option, > + Error **errp) > +{ > + CommandLineOptionInfoList *conf_list = NULL; > + CommandLineOptionInfo *info; > + int i; > + > + for (i = 0; vm_config_groups[i] != NULL; i++) { > + if (!option || !strcmp(option, vm_config_groups[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->parameters = get_drive_infolist(); > + } else { > + info->parameters = > + query_option_descs(vm_config_groups[i]->desc); > + } > + QAPI_LIST_PREPEND(conf_list, info); > + } > + } > + > + if (!option || !strcmp(option, "machine")) { > + info = g_malloc0(sizeof(*info)); > + info->option = g_strdup("machine"); > + info->parameters = query_all_machine_properties(); > + QAPI_LIST_PREPEND(conf_list, info); > + } > + > + if (conf_list == NULL) { > + error_setg(errp, "invalid option name: %s", option); > + } > + > + return conf_list; > +} > diff --git a/util/qemu-config.c b/util/qemu-config.c > index 42076efe1e..a90c18dad2 100644 > --- a/util/qemu-config.c > +++ b/util/qemu-config.c > @@ -1,16 +1,14 @@ > #include "qemu/osdep.h" > #include "block/qdict.h" /* for qdict_extract_subqdict() */ > #include "qapi/error.h" > -#include "qapi/qapi-commands-misc.h" > #include "qapi/qmp/qdict.h" > #include "qapi/qmp/qlist.h" > #include "qemu/error-report.h" > #include "qemu/option.h" > #include "qemu/config-file.h" > -#include "hw/boards.h" > > -static QemuOptsList *vm_config_groups[48]; > -static QemuOptsList *drive_config_groups[5]; > +QemuOptsList *vm_config_groups[48]; > +QemuOptsList *drive_config_groups[5]; > > static QemuOptsList *find_list(QemuOptsList **lists, const char *group, > Error **errp) > @@ -55,204 +53,6 @@ QemuOpts *qemu_find_opts_singleton(const char *group) > return opts; > } > > -static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) > -{ > - CommandLineParameterInfoList *param_list = NULL; > - CommandLineParameterInfo *info; > - int i; > - > - for (i = 0; desc[i].name != NULL; i++) { > - info = g_malloc0(sizeof(*info)); > - info->name = g_strdup(desc[i].name); > - > - switch (desc[i].type) { > - case QEMU_OPT_STRING: > - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > - break; > - case QEMU_OPT_BOOL: > - info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; > - break; > - case QEMU_OPT_NUMBER: > - info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; > - break; > - case QEMU_OPT_SIZE: > - info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; > - break; > - } > - > - info->help = g_strdup(desc[i].help); > - info->q_default = g_strdup(desc[i].def_value_str); > - > - QAPI_LIST_PREPEND(param_list, info); > - } > - > - return param_list; > -} > - > -/* remove repeated entry from the info list */ > -static void cleanup_infolist(CommandLineParameterInfoList *head) > -{ > - CommandLineParameterInfoList *pre_entry, *cur, *del_entry; > - > - cur = head; > - while (cur->next) { > - pre_entry = head; > - while (pre_entry != cur->next) { > - if (!strcmp(pre_entry->value->name, cur->next->value->name)) { > - del_entry = cur->next; > - cur->next = cur->next->next; > - del_entry->next = NULL; > - qapi_free_CommandLineParameterInfoList(del_entry); > - break; > - } > - pre_entry = pre_entry->next; > - } > - cur = cur->next; > - } > -} > - > -/* merge the description items of two parameter infolists */ > -static void connect_infolist(CommandLineParameterInfoList *head, > - CommandLineParameterInfoList *new) > -{ > - CommandLineParameterInfoList *cur; > - > - cur = head; > - while (cur->next) { > - cur = cur->next; > - } > - cur->next = new; > -} > - > -/* access all the local QemuOptsLists for drive option */ > -static CommandLineParameterInfoList *get_drive_infolist(void) > -{ > - CommandLineParameterInfoList *head = NULL, *cur; > - int i; > - > - for (i = 0; drive_config_groups[i] != NULL; i++) { > - if (!head) { > - head = query_option_descs(drive_config_groups[i]->desc); > - } else { > - cur = query_option_descs(drive_config_groups[i]->desc); > - connect_infolist(head, cur); > - } > - } > - cleanup_infolist(head); > - > - return head; > -} > - > -static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) > -{ > - CommandLineParameterInfo *info; > - > - info = g_malloc0(sizeof(*info)); > - info->name = g_strdup(prop->name); > - > - if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) { > - info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; > - } else if (g_str_equal(prop->type, "int")) { > - info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; > - } else if (g_str_equal(prop->type, "size")) { > - info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; > - } else { > - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > - } > - > - if (prop->description) { > - info->help = g_strdup(prop->description); > - } > - > - return info; > -} > - > -static CommandLineParameterInfoList *query_all_machine_properties(void) > -{ > - CommandLineParameterInfoList *params = NULL, *clpiter; > - CommandLineParameterInfo *info; > - GSList *machines, *curr_mach; > - ObjectPropertyIterator op_iter; > - ObjectProperty *prop; > - bool is_new; > - > - machines = object_class_get_list(TYPE_MACHINE, false); > - assert(machines); > - > - /* Loop over all machine classes */ > - for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) { > - object_class_property_iter_init(&op_iter, curr_mach->data); > - /* ... and over the properties of each machine: */ > - while ((prop = object_property_iter_next(&op_iter))) { > - if (!prop->set) { > - continue; > - } > - /* > - * Check whether the property has already been put into the list > - * (via another machine class) > - */ > - is_new = true; > - for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) { > - if (g_str_equal(clpiter->value->name, prop->name)) { > - is_new = false; > - break; > - } > - } > - /* If it hasn't been added before, add it now to the list */ > - if (is_new) { > - info = objprop_to_cmdline_prop(prop); > - QAPI_LIST_PREPEND(params, info); > - } > - } > - } > - > - g_slist_free(machines); > - > - /* Add entry for the "type" parameter */ > - info = g_malloc0(sizeof(*info)); > - info->name = g_strdup("type"); > - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; > - info->help = g_strdup("machine type"); > - QAPI_LIST_PREPEND(params, info); > - > - return params; > -} > - > -CommandLineOptionInfoList *qmp_query_command_line_options(const char *option, > - Error **errp) > -{ > - CommandLineOptionInfoList *conf_list = NULL; > - CommandLineOptionInfo *info; > - int i; > - > - for (i = 0; vm_config_groups[i] != NULL; i++) { > - if (!option || !strcmp(option, vm_config_groups[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->parameters = get_drive_infolist(); > - } else { > - info->parameters = > - query_option_descs(vm_config_groups[i]->desc); > - } > - QAPI_LIST_PREPEND(conf_list, info); > - } > - } > - > - if (!option || !strcmp(option, "machine")) { > - info = g_malloc0(sizeof(*info)); > - info->option = g_strdup("machine"); > - info->parameters = query_all_machine_properties(); > - QAPI_LIST_PREPEND(conf_list, info); > - } > - > - if (conf_list == NULL) { > - error_setg(errp, "invalid option name: %s", option); > - } > - > - return conf_list; > -} > - > QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) > { > return find_list(vm_config_groups, group, errp); > diff --git a/util/meson.build b/util/meson.build > index 247f55a80d..636b17a414 100644 > --- a/util/meson.build > +++ b/util/meson.build > @@ -75,6 +75,7 @@ if have_system > if host_os == 'linux' > util_ss.add(files('userfaultfd.c')) > endif > + util_ss.add(files('qemu-config-qmp.c')) > util_ss.add(files('yank.c')) > endif > > -- > 2.41.0 >
diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index b82a778123..8b9d6df173 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -8,6 +8,9 @@ QemuOptsList *qemu_find_opts(const char *group); QemuOptsList *qemu_find_opts_err(const char *group, Error **errp); QemuOpts *qemu_find_opts_singleton(const char *group); +extern QemuOptsList *vm_config_groups[48]; +extern QemuOptsList *drive_config_groups[5]; + void qemu_add_opts(QemuOptsList *list); void qemu_add_drive_opts(QemuOptsList *list); int qemu_global_option(const char *str); diff --git a/util/qemu-config-qmp.c b/util/qemu-config-qmp.c new file mode 100644 index 0000000000..24477a0e44 --- /dev/null +++ b/util/qemu-config-qmp.c @@ -0,0 +1,206 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-misc.h" +#include "qapi/qmp/qlist.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "hw/boards.h" + +static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) +{ + CommandLineParameterInfoList *param_list = NULL; + CommandLineParameterInfo *info; + int i; + + for (i = 0; desc[i].name != NULL; i++) { + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(desc[i].name); + + switch (desc[i].type) { + case QEMU_OPT_STRING: + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; + break; + case QEMU_OPT_BOOL: + info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; + break; + case QEMU_OPT_NUMBER: + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; + break; + case QEMU_OPT_SIZE: + info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; + break; + } + + info->help = g_strdup(desc[i].help); + info->q_default = g_strdup(desc[i].def_value_str); + + QAPI_LIST_PREPEND(param_list, info); + } + + return param_list; +} + +/* remove repeated entry from the info list */ +static void cleanup_infolist(CommandLineParameterInfoList *head) +{ + CommandLineParameterInfoList *pre_entry, *cur, *del_entry; + + cur = head; + while (cur->next) { + pre_entry = head; + while (pre_entry != cur->next) { + if (!strcmp(pre_entry->value->name, cur->next->value->name)) { + del_entry = cur->next; + cur->next = cur->next->next; + del_entry->next = NULL; + qapi_free_CommandLineParameterInfoList(del_entry); + break; + } + pre_entry = pre_entry->next; + } + cur = cur->next; + } +} + +/* merge the description items of two parameter infolists */ +static void connect_infolist(CommandLineParameterInfoList *head, + CommandLineParameterInfoList *new) +{ + CommandLineParameterInfoList *cur; + + cur = head; + while (cur->next) { + cur = cur->next; + } + cur->next = new; +} + +/* access all the local QemuOptsLists for drive option */ +static CommandLineParameterInfoList *get_drive_infolist(void) +{ + CommandLineParameterInfoList *head = NULL, *cur; + int i; + + for (i = 0; drive_config_groups[i] != NULL; i++) { + if (!head) { + head = query_option_descs(drive_config_groups[i]->desc); + } else { + cur = query_option_descs(drive_config_groups[i]->desc); + connect_infolist(head, cur); + } + } + cleanup_infolist(head); + + return head; +} + +static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) +{ + CommandLineParameterInfo *info; + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(prop->name); + + if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) { + info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; + } else if (g_str_equal(prop->type, "int")) { + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; + } else if (g_str_equal(prop->type, "size")) { + info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; + } else { + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; + } + + if (prop->description) { + info->help = g_strdup(prop->description); + } + + return info; +} + +static CommandLineParameterInfoList *query_all_machine_properties(void) +{ + CommandLineParameterInfoList *params = NULL, *clpiter; + CommandLineParameterInfo *info; + GSList *machines, *curr_mach; + ObjectPropertyIterator op_iter; + ObjectProperty *prop; + bool is_new; + + machines = object_class_get_list(TYPE_MACHINE, false); + assert(machines); + + /* Loop over all machine classes */ + for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) { + object_class_property_iter_init(&op_iter, curr_mach->data); + /* ... and over the properties of each machine: */ + while ((prop = object_property_iter_next(&op_iter))) { + if (!prop->set) { + continue; + } + /* + * Check whether the property has already been put into the list + * (via another machine class) + */ + is_new = true; + for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) { + if (g_str_equal(clpiter->value->name, prop->name)) { + is_new = false; + break; + } + } + /* If it hasn't been added before, add it now to the list */ + if (is_new) { + info = objprop_to_cmdline_prop(prop); + QAPI_LIST_PREPEND(params, info); + } + } + } + + g_slist_free(machines); + + /* Add entry for the "type" parameter */ + info = g_malloc0(sizeof(*info)); + info->name = g_strdup("type"); + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; + info->help = g_strdup("machine type"); + QAPI_LIST_PREPEND(params, info); + + return params; +} + +CommandLineOptionInfoList *qmp_query_command_line_options(const char *option, + Error **errp) +{ + CommandLineOptionInfoList *conf_list = NULL; + CommandLineOptionInfo *info; + int i; + + for (i = 0; vm_config_groups[i] != NULL; i++) { + if (!option || !strcmp(option, vm_config_groups[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->parameters = get_drive_infolist(); + } else { + info->parameters = + query_option_descs(vm_config_groups[i]->desc); + } + QAPI_LIST_PREPEND(conf_list, info); + } + } + + if (!option || !strcmp(option, "machine")) { + info = g_malloc0(sizeof(*info)); + info->option = g_strdup("machine"); + info->parameters = query_all_machine_properties(); + QAPI_LIST_PREPEND(conf_list, info); + } + + if (conf_list == NULL) { + error_setg(errp, "invalid option name: %s", option); + } + + return conf_list; +} diff --git a/util/qemu-config.c b/util/qemu-config.c index 42076efe1e..a90c18dad2 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -1,16 +1,14 @@ #include "qemu/osdep.h" #include "block/qdict.h" /* for qdict_extract_subqdict() */ #include "qapi/error.h" -#include "qapi/qapi-commands-misc.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/config-file.h" -#include "hw/boards.h" -static QemuOptsList *vm_config_groups[48]; -static QemuOptsList *drive_config_groups[5]; +QemuOptsList *vm_config_groups[48]; +QemuOptsList *drive_config_groups[5]; static QemuOptsList *find_list(QemuOptsList **lists, const char *group, Error **errp) @@ -55,204 +53,6 @@ QemuOpts *qemu_find_opts_singleton(const char *group) return opts; } -static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) -{ - CommandLineParameterInfoList *param_list = NULL; - CommandLineParameterInfo *info; - int i; - - for (i = 0; desc[i].name != NULL; i++) { - info = g_malloc0(sizeof(*info)); - info->name = g_strdup(desc[i].name); - - switch (desc[i].type) { - case QEMU_OPT_STRING: - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; - break; - case QEMU_OPT_BOOL: - info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; - break; - case QEMU_OPT_NUMBER: - info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; - break; - case QEMU_OPT_SIZE: - info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; - break; - } - - info->help = g_strdup(desc[i].help); - info->q_default = g_strdup(desc[i].def_value_str); - - QAPI_LIST_PREPEND(param_list, info); - } - - return param_list; -} - -/* remove repeated entry from the info list */ -static void cleanup_infolist(CommandLineParameterInfoList *head) -{ - CommandLineParameterInfoList *pre_entry, *cur, *del_entry; - - cur = head; - while (cur->next) { - pre_entry = head; - while (pre_entry != cur->next) { - if (!strcmp(pre_entry->value->name, cur->next->value->name)) { - del_entry = cur->next; - cur->next = cur->next->next; - del_entry->next = NULL; - qapi_free_CommandLineParameterInfoList(del_entry); - break; - } - pre_entry = pre_entry->next; - } - cur = cur->next; - } -} - -/* merge the description items of two parameter infolists */ -static void connect_infolist(CommandLineParameterInfoList *head, - CommandLineParameterInfoList *new) -{ - CommandLineParameterInfoList *cur; - - cur = head; - while (cur->next) { - cur = cur->next; - } - cur->next = new; -} - -/* access all the local QemuOptsLists for drive option */ -static CommandLineParameterInfoList *get_drive_infolist(void) -{ - CommandLineParameterInfoList *head = NULL, *cur; - int i; - - for (i = 0; drive_config_groups[i] != NULL; i++) { - if (!head) { - head = query_option_descs(drive_config_groups[i]->desc); - } else { - cur = query_option_descs(drive_config_groups[i]->desc); - connect_infolist(head, cur); - } - } - cleanup_infolist(head); - - return head; -} - -static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) -{ - CommandLineParameterInfo *info; - - info = g_malloc0(sizeof(*info)); - info->name = g_strdup(prop->name); - - if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) { - info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; - } else if (g_str_equal(prop->type, "int")) { - info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; - } else if (g_str_equal(prop->type, "size")) { - info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; - } else { - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; - } - - if (prop->description) { - info->help = g_strdup(prop->description); - } - - return info; -} - -static CommandLineParameterInfoList *query_all_machine_properties(void) -{ - CommandLineParameterInfoList *params = NULL, *clpiter; - CommandLineParameterInfo *info; - GSList *machines, *curr_mach; - ObjectPropertyIterator op_iter; - ObjectProperty *prop; - bool is_new; - - machines = object_class_get_list(TYPE_MACHINE, false); - assert(machines); - - /* Loop over all machine classes */ - for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) { - object_class_property_iter_init(&op_iter, curr_mach->data); - /* ... and over the properties of each machine: */ - while ((prop = object_property_iter_next(&op_iter))) { - if (!prop->set) { - continue; - } - /* - * Check whether the property has already been put into the list - * (via another machine class) - */ - is_new = true; - for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) { - if (g_str_equal(clpiter->value->name, prop->name)) { - is_new = false; - break; - } - } - /* If it hasn't been added before, add it now to the list */ - if (is_new) { - info = objprop_to_cmdline_prop(prop); - QAPI_LIST_PREPEND(params, info); - } - } - } - - g_slist_free(machines); - - /* Add entry for the "type" parameter */ - info = g_malloc0(sizeof(*info)); - info->name = g_strdup("type"); - info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; - info->help = g_strdup("machine type"); - QAPI_LIST_PREPEND(params, info); - - return params; -} - -CommandLineOptionInfoList *qmp_query_command_line_options(const char *option, - Error **errp) -{ - CommandLineOptionInfoList *conf_list = NULL; - CommandLineOptionInfo *info; - int i; - - for (i = 0; vm_config_groups[i] != NULL; i++) { - if (!option || !strcmp(option, vm_config_groups[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->parameters = get_drive_infolist(); - } else { - info->parameters = - query_option_descs(vm_config_groups[i]->desc); - } - QAPI_LIST_PREPEND(conf_list, info); - } - } - - if (!option || !strcmp(option, "machine")) { - info = g_malloc0(sizeof(*info)); - info->option = g_strdup("machine"); - info->parameters = query_all_machine_properties(); - QAPI_LIST_PREPEND(conf_list, info); - } - - if (conf_list == NULL) { - error_setg(errp, "invalid option name: %s", option); - } - - return conf_list; -} - QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp); diff --git a/util/meson.build b/util/meson.build index 247f55a80d..636b17a414 100644 --- a/util/meson.build +++ b/util/meson.build @@ -75,6 +75,7 @@ if have_system if host_os == 'linux' util_ss.add(files('userfaultfd.c')) endif + util_ss.add(files('qemu-config-qmp.c')) util_ss.add(files('yank.c')) endif
QMP is irrelevant for user emulation. Extract the code related to QMP in a different source file, which won't be build for user emulation binaries. This avoid pulling pointless code. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/qemu/config-file.h | 3 + util/qemu-config-qmp.c | 206 +++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 204 +----------------------------------- util/meson.build | 1 + 4 files changed, 212 insertions(+), 202 deletions(-) create mode 100644 util/qemu-config-qmp.c