2016-01-29 18:49:55 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-14 21:14:28 +02:00
|
|
|
#include "block/qdict.h" /* for qdict_extract_subqdict() */
|
2018-02-01 12:18:31 +01:00
|
|
|
#include "qapi/error.h"
|
2018-02-27 00:13:27 +01:00
|
|
|
#include "qapi/qapi-commands-misc.h"
|
2021-05-24 12:57:50 +02:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2018-02-01 12:18:39 +01:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2018-02-01 12:18:38 +01:00
|
|
|
#include "qapi/qmp/qlist.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/option.h"
|
|
|
|
#include "qemu/config-file.h"
|
2009-07-31 12:25:35 +02:00
|
|
|
|
2015-05-29 14:37:54 +02:00
|
|
|
static QemuOptsList *vm_config_groups[48];
|
2016-10-06 11:33:17 +02:00
|
|
|
static QemuOptsList *drive_config_groups[5];
|
2009-07-31 12:25:36 +02:00
|
|
|
|
2012-03-28 19:14:17 +02:00
|
|
|
static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
|
|
|
|
Error **errp)
|
2009-10-14 10:39:25 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2021-05-18 15:08:17 +02:00
|
|
|
qemu_load_module_for_opts(group);
|
2009-10-14 10:39:25 +02:00
|
|
|
for (i = 0; lists[i] != NULL; i++) {
|
|
|
|
if (strcmp(lists[i]->name, group) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (lists[i] == NULL) {
|
2014-03-22 00:42:26 +01:00
|
|
|
error_setg(errp, "There is no option group '%s'", group);
|
2009-10-14 10:39:25 +02:00
|
|
|
}
|
|
|
|
return lists[i];
|
|
|
|
}
|
|
|
|
|
2010-03-05 18:21:56 +01:00
|
|
|
QemuOptsList *qemu_find_opts(const char *group)
|
|
|
|
{
|
2012-03-28 19:14:17 +02:00
|
|
|
QemuOptsList *ret;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
ret = find_list(vm_config_groups, group, &local_err);
|
2014-01-30 15:07:28 +01:00
|
|
|
if (local_err) {
|
2015-02-12 13:55:05 +01:00
|
|
|
error_report_err(local_err);
|
2012-03-28 19:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2010-03-05 18:21:56 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 10:39:24 +01:00
|
|
|
QemuOpts *qemu_find_opts_singleton(const char *group)
|
|
|
|
{
|
|
|
|
QemuOptsList *list;
|
|
|
|
QemuOpts *opts;
|
|
|
|
|
|
|
|
list = qemu_find_opts(group);
|
|
|
|
assert(list);
|
|
|
|
opts = qemu_opts_find(list, NULL);
|
|
|
|
if (!opts) {
|
|
|
|
opts = qemu_opts_create(list, NULL, 0, &error_abort);
|
|
|
|
}
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
2013-04-25 11:50:35 +02:00
|
|
|
static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
|
|
|
|
{
|
2020-11-13 02:13:37 +01:00
|
|
|
CommandLineParameterInfoList *param_list = NULL;
|
2013-04-25 11:50:35 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc[i].help) {
|
|
|
|
info->has_help = true;
|
|
|
|
info->help = g_strdup(desc[i].help);
|
|
|
|
}
|
2014-06-05 11:20:43 +02:00
|
|
|
if (desc[i].def_value_str) {
|
|
|
|
info->has_q_default = true;
|
|
|
|
info->q_default = g_strdup(desc[i].def_value_str);
|
|
|
|
}
|
2013-04-25 11:50:35 +02:00
|
|
|
|
2020-11-13 02:13:37 +01:00
|
|
|
QAPI_LIST_PREPEND(param_list, info);
|
2013-04-25 11:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return param_list;
|
|
|
|
}
|
|
|
|
|
2013-11-09 05:15:47 +01:00
|
|
|
/* 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;
|
2018-01-04 17:05:18 +01:00
|
|
|
del_entry->next = NULL;
|
|
|
|
qapi_free_CommandLineParameterInfoList(del_entry);
|
2013-11-09 05:15:47 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-01 18:47:21 +02:00
|
|
|
/* restore machine options that are now machine's properties */
|
|
|
|
static QemuOptsList machine_opts = {
|
|
|
|
.merge_lists = true,
|
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(machine_opts.head),
|
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "type",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "emulated machine"
|
|
|
|
},{
|
|
|
|
.name = "accel",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "accelerator list",
|
|
|
|
},{
|
|
|
|
.name = "kernel_irqchip",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "use KVM in-kernel irqchip",
|
|
|
|
},{
|
|
|
|
.name = "kvm_shadow_mem",
|
|
|
|
.type = QEMU_OPT_SIZE,
|
|
|
|
.help = "KVM shadow MMU size",
|
|
|
|
},{
|
|
|
|
.name = "kernel",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Linux kernel image file",
|
|
|
|
},{
|
|
|
|
.name = "initrd",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Linux initial ramdisk file",
|
|
|
|
},{
|
|
|
|
.name = "append",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Linux kernel command line",
|
|
|
|
},{
|
|
|
|
.name = "dtb",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Linux kernel device tree file",
|
|
|
|
},{
|
|
|
|
.name = "dumpdtb",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Dump current dtb to a file and quit",
|
|
|
|
},{
|
|
|
|
.name = "phandle_start",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
.help = "The first phandle ID we may generate dynamically",
|
|
|
|
},{
|
|
|
|
.name = "dt_compatible",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Overrides the \"compatible\" property of the dt root node",
|
|
|
|
},{
|
|
|
|
.name = "dump-guest-core",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "Include guest memory in a core dump",
|
|
|
|
},{
|
|
|
|
.name = "mem-merge",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "enable/disable memory merge support",
|
|
|
|
},{
|
|
|
|
.name = "usb",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "Set on/off to enable/disable usb",
|
|
|
|
},{
|
|
|
|
.name = "firmware",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "firmware image",
|
|
|
|
},{
|
|
|
|
.name = "iommu",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "Set on/off to enable/disable Intel IOMMU (VT-d)",
|
|
|
|
},{
|
|
|
|
.name = "suppress-vmdesc",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "Set on to disable self-describing migration",
|
2015-10-12 17:36:21 +02:00
|
|
|
},{
|
|
|
|
.name = "aes-key-wrap",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "enable/disable AES key wrapping using the CPACF wrapping key",
|
|
|
|
},{
|
|
|
|
.name = "dea-key-wrap",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "enable/disable DEA key wrapping using the CPACF wrapping key",
|
2016-12-15 19:44:29 +01:00
|
|
|
},{
|
|
|
|
.name = "loadparm",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Up to 8 chars in set of [A-Za-z0-9. ](lower case chars"
|
|
|
|
" converted to upper case) to pass to machine"
|
|
|
|
" loader, boot manager, and guest kernel",
|
2022-09-02 19:27:37 +02:00
|
|
|
},{
|
|
|
|
.name = "zpcii-disable",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
.help = "disable zPCI interpretation facilities",
|
2015-04-01 18:47:21 +02:00
|
|
|
},
|
|
|
|
{ /* End of list */ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-25 11:50:35 +02:00
|
|
|
CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
|
|
|
|
const char *option,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-11-13 02:13:37 +01:00
|
|
|
CommandLineOptionInfoList *conf_list = NULL;
|
2013-04-25 11:50:35 +02:00
|
|
|
CommandLineOptionInfo *info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; vm_config_groups[i] != NULL; i++) {
|
|
|
|
if (!has_option || !strcmp(option, vm_config_groups[i]->name)) {
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->option = g_strdup(vm_config_groups[i]->name);
|
2013-11-09 05:15:47 +01:00
|
|
|
if (!strcmp("drive", vm_config_groups[i]->name)) {
|
|
|
|
info->parameters = get_drive_infolist();
|
|
|
|
} else {
|
|
|
|
info->parameters =
|
|
|
|
query_option_descs(vm_config_groups[i]->desc);
|
|
|
|
}
|
2020-11-13 02:13:37 +01:00
|
|
|
QAPI_LIST_PREPEND(conf_list, info);
|
2013-04-25 11:50:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 17:10:55 +02:00
|
|
|
if (!has_option || !strcmp(option, "machine")) {
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->option = g_strdup("machine");
|
|
|
|
info->parameters = query_option_descs(machine_opts.desc);
|
|
|
|
QAPI_LIST_PREPEND(conf_list, info);
|
|
|
|
}
|
|
|
|
|
2013-04-25 11:50:35 +02:00
|
|
|
if (conf_list == NULL) {
|
|
|
|
error_setg(errp, "invalid option name: %s", option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf_list;
|
|
|
|
}
|
|
|
|
|
2012-03-28 19:16:37 +02:00
|
|
|
QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
|
|
|
|
{
|
|
|
|
return find_list(vm_config_groups, group, errp);
|
|
|
|
}
|
|
|
|
|
2013-11-09 05:15:47 +01:00
|
|
|
void qemu_add_drive_opts(QemuOptsList *list)
|
|
|
|
{
|
|
|
|
int entries, i;
|
|
|
|
|
|
|
|
entries = ARRAY_SIZE(drive_config_groups);
|
|
|
|
entries--; /* keep list NULL terminated */
|
|
|
|
for (i = 0; i < entries; i++) {
|
|
|
|
if (drive_config_groups[i] == NULL) {
|
|
|
|
drive_config_groups[i] = list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "ran out of space in drive_config_groups");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2010-08-20 13:52:00 +02:00
|
|
|
void qemu_add_opts(QemuOptsList *list)
|
|
|
|
{
|
|
|
|
int entries, i;
|
|
|
|
|
|
|
|
entries = ARRAY_SIZE(vm_config_groups);
|
|
|
|
entries--; /* keep list NULL terminated */
|
|
|
|
for (i = 0; i < entries; i++) {
|
|
|
|
if (vm_config_groups[i] == NULL) {
|
|
|
|
vm_config_groups[i] = list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "ran out of space in vm_config_groups");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2017-10-04 04:50:42 +02:00
|
|
|
/* Returns number of config groups on success, -errno on error */
|
2021-05-24 12:57:50 +02:00
|
|
|
static int qemu_config_foreach(FILE *fp, QEMUConfigCB *cb, void *opaque,
|
|
|
|
const char *fname, Error **errp)
|
2009-10-14 10:39:27 +02:00
|
|
|
{
|
2021-05-24 12:57:50 +02:00
|
|
|
char line[1024], prev_group[64], group[64], arg[64], value[1024];
|
2010-02-18 19:48:33 +01:00
|
|
|
Location loc;
|
2012-03-28 19:14:17 +02:00
|
|
|
Error *local_err = NULL;
|
2021-05-24 12:57:50 +02:00
|
|
|
QDict *qdict = NULL;
|
2017-10-04 04:50:42 +02:00
|
|
|
int res = -EINVAL, lno = 0;
|
|
|
|
int count = 0;
|
2009-10-14 10:39:27 +02:00
|
|
|
|
2010-02-18 19:48:33 +01:00
|
|
|
loc_push_none(&loc);
|
2009-10-14 10:39:27 +02:00
|
|
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
2021-05-24 12:57:50 +02:00
|
|
|
++lno;
|
2009-10-14 10:39:27 +02:00
|
|
|
if (line[0] == '\n') {
|
|
|
|
/* skip empty lines */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (line[0] == '#') {
|
|
|
|
/* comment */
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-24 12:57:50 +02:00
|
|
|
if (line[0] == '[') {
|
|
|
|
QDict *prev = qdict;
|
|
|
|
if (sscanf(line, "[%63s \"%63[^\"]\"]", group, value) == 2) {
|
|
|
|
qdict = qdict_new();
|
|
|
|
qdict_put_str(qdict, "id", value);
|
|
|
|
count++;
|
|
|
|
} else if (sscanf(line, "[%63[^]]]", group) == 1) {
|
|
|
|
qdict = qdict_new();
|
|
|
|
count++;
|
2012-03-28 19:14:17 +02:00
|
|
|
}
|
2021-05-24 12:57:50 +02:00
|
|
|
if (qdict != prev) {
|
|
|
|
if (prev) {
|
|
|
|
cb(prev_group, prev, opaque, &local_err);
|
|
|
|
qobject_unref(prev);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(prev_group, group);
|
|
|
|
continue;
|
2012-03-28 19:14:17 +02:00
|
|
|
}
|
2009-10-14 10:39:27 +02:00
|
|
|
}
|
2021-05-24 12:57:50 +02:00
|
|
|
loc_set_file(fname, lno);
|
2015-04-08 19:57:31 +02:00
|
|
|
value[0] = '\0';
|
|
|
|
if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2 ||
|
|
|
|
sscanf(line, " %63s = \"\"", arg) == 1) {
|
2009-10-14 10:39:27 +02:00
|
|
|
/* arg = value */
|
2021-05-24 12:57:50 +02:00
|
|
|
if (qdict == NULL) {
|
2021-02-26 18:08:16 +01:00
|
|
|
error_setg(errp, "no group defined");
|
2010-02-18 19:48:33 +01:00
|
|
|
goto out;
|
2009-10-14 10:39:27 +02:00
|
|
|
}
|
2021-05-24 12:57:50 +02:00
|
|
|
qdict_put_str(qdict, arg, value);
|
2009-10-14 10:39:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-02-26 18:08:16 +01:00
|
|
|
error_setg(errp, "parse error");
|
2010-02-18 19:48:33 +01:00
|
|
|
goto out;
|
2009-10-14 10:39:27 +02:00
|
|
|
}
|
2010-02-18 19:56:01 +01:00
|
|
|
if (ferror(fp)) {
|
2021-02-26 18:08:16 +01:00
|
|
|
loc_pop(&loc);
|
|
|
|
error_setg_errno(errp, errno, "Cannot read config file");
|
2021-07-05 19:14:37 +02:00
|
|
|
goto out_no_loc;
|
2010-02-18 19:56:01 +01:00
|
|
|
}
|
2017-10-04 04:50:42 +02:00
|
|
|
res = count;
|
2021-05-24 12:57:50 +02:00
|
|
|
if (qdict) {
|
|
|
|
cb(group, qdict, opaque, errp);
|
|
|
|
}
|
2021-07-05 19:14:37 +02:00
|
|
|
out:
|
2010-02-18 19:48:33 +01:00
|
|
|
loc_pop(&loc);
|
2021-07-05 19:14:37 +02:00
|
|
|
out_no_loc:
|
2021-07-05 19:14:37 +02:00
|
|
|
qobject_unref(qdict);
|
2010-02-18 19:48:33 +01:00
|
|
|
return res;
|
2009-10-14 10:39:27 +02:00
|
|
|
}
|
2010-03-05 17:25:55 +01:00
|
|
|
|
2021-05-24 12:57:50 +02:00
|
|
|
void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
QemuOptsList **lists = opaque;
|
|
|
|
QemuOptsList *list;
|
|
|
|
|
|
|
|
list = find_list(lists, group, errp);
|
|
|
|
if (!list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:34:35 +02:00
|
|
|
qemu_opts_from_qdict(list, qdict, errp);
|
2021-05-24 12:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp)
|
|
|
|
{
|
|
|
|
return qemu_config_foreach(fp, qemu_config_do_parse, lists, fname, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemu_read_config_file(const char *filename, QEMUConfigCB *cb, Error **errp)
|
2010-03-05 17:25:55 +01:00
|
|
|
{
|
|
|
|
FILE *f = fopen(filename, "r");
|
2010-05-17 10:36:47 +02:00
|
|
|
int ret;
|
|
|
|
|
2010-03-05 17:25:55 +01:00
|
|
|
if (f == NULL) {
|
2021-02-26 18:08:16 +01:00
|
|
|
error_setg_file_open(errp, errno, filename);
|
2010-03-05 17:25:55 +01:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2021-05-24 12:57:50 +02:00
|
|
|
ret = qemu_config_foreach(f, cb, vm_config_groups, filename, errp);
|
2010-03-05 17:25:55 +01:00
|
|
|
fclose(f);
|
2017-10-04 04:50:42 +02:00
|
|
|
return ret;
|
2010-03-05 17:25:55 +01:00
|
|
|
}
|
2013-12-20 19:28:05 +01:00
|
|
|
|
|
|
|
static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
QemuOpts *subopts;
|
|
|
|
QDict *subqdict;
|
|
|
|
QList *list = NULL;
|
|
|
|
size_t orig_size, enum_size;
|
|
|
|
char *prefix;
|
|
|
|
|
|
|
|
prefix = g_strdup_printf("%s.", opts->name);
|
|
|
|
qdict_extract_subqdict(options, &subqdict, prefix);
|
|
|
|
g_free(prefix);
|
|
|
|
orig_size = qdict_size(subqdict);
|
|
|
|
if (!orig_size) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-07-07 18:05:35 +02:00
|
|
|
subopts = qemu_opts_create(opts, NULL, 0, errp);
|
|
|
|
if (!subopts) {
|
2013-12-20 19:28:05 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!qemu_opts_absorb_qdict(subopts, subqdict, errp)) {
|
2013-12-20 19:28:05 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum_size = qdict_size(subqdict);
|
|
|
|
if (enum_size < orig_size && enum_size) {
|
|
|
|
error_setg(errp, "Unknown option '%s' for [%s]",
|
|
|
|
qdict_first(subqdict)->key, opts->name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enum_size) {
|
|
|
|
/* Multiple, enumerated sections */
|
|
|
|
QListEntry *list_entry;
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
/* Not required anymore */
|
|
|
|
qemu_opts_del(subopts);
|
|
|
|
|
|
|
|
qdict_array_split(subqdict, &list);
|
|
|
|
if (qdict_size(subqdict)) {
|
|
|
|
error_setg(errp, "Unused option '%s' for [%s]",
|
|
|
|
qdict_first(subqdict)->key, opts->name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLIST_FOREACH_ENTRY(list, list_entry) {
|
2018-02-24 16:40:29 +01:00
|
|
|
QDict *section = qobject_to(QDict, qlist_entry_obj(list_entry));
|
2013-12-20 19:28:05 +01:00
|
|
|
char *opt_name;
|
|
|
|
|
2014-02-21 19:11:39 +01:00
|
|
|
if (!section) {
|
|
|
|
error_setg(errp, "[%s] section (index %u) does not consist of "
|
|
|
|
"keys", opts->name, i);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:28:05 +01:00
|
|
|
opt_name = g_strdup_printf("%s.%u", opts->name, i++);
|
2020-07-07 18:05:35 +02:00
|
|
|
subopts = qemu_opts_create(opts, opt_name, 1, errp);
|
2013-12-20 19:28:05 +01:00
|
|
|
g_free(opt_name);
|
2020-07-07 18:05:35 +02:00
|
|
|
if (!subopts) {
|
2013-12-20 19:28:05 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!qemu_opts_absorb_qdict(subopts, section, errp)) {
|
2013-12-20 19:28:05 +01:00
|
|
|
qemu_opts_del(subopts);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qdict_size(section)) {
|
|
|
|
error_setg(errp, "[%s] section doesn't support the option '%s'",
|
|
|
|
opts->name, qdict_first(section)->key);
|
|
|
|
qemu_opts_del(subopts);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2018-04-19 17:01:43 +02:00
|
|
|
qobject_unref(subqdict);
|
|
|
|
qobject_unref(list);
|
2013-12-20 19:28:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
for (i = 0; lists[i]; i++) {
|
|
|
|
config_parse_qdict_section(options, lists[i], &local_err);
|
2014-01-30 15:07:28 +01:00
|
|
|
if (local_err) {
|
2013-12-20 19:28:05 +01:00
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|