config-file: move -set implementation to vl.c

We want to make it independent of QemuOpts.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2020-11-12 08:16:22 -05:00
parent 4b7acd2ac8
commit ed7fa564cb
3 changed files with 33 additions and 34 deletions

View File

@ -8,7 +8,6 @@ QemuOpts *qemu_find_opts_singleton(const char *group);
void qemu_add_opts(QemuOptsList *list); void qemu_add_opts(QemuOptsList *list);
void qemu_add_drive_opts(QemuOptsList *list); void qemu_add_drive_opts(QemuOptsList *list);
int qemu_set_option(const char *str);
int qemu_global_option(const char *str); int qemu_global_option(const char *str);
void qemu_config_write(FILE *fp); void qemu_config_write(FILE *fp);

View File

@ -2797,6 +2797,39 @@ static int qemu_read_default_config_file(void)
return 0; return 0;
} }
static int qemu_set_option(const char *str)
{
Error *local_err = NULL;
char group[64], id[64], arg[64];
QemuOptsList *list;
QemuOpts *opts;
int rc, offset;
rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
if (rc < 3 || str[offset] != '=') {
error_report("can't parse: \"%s\"", str);
return -1;
}
list = qemu_find_opts(group);
if (list == NULL) {
return -1;
}
opts = qemu_opts_find(list, id);
if (!opts) {
error_report("there is no %s \"%s\" defined",
list->name, id);
return -1;
}
if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) {
error_report_err(local_err);
return -1;
}
return 0;
}
static void user_register_global_props(void) static void user_register_global_props(void)
{ {
qemu_opts_foreach(qemu_find_opts("global"), qemu_opts_foreach(qemu_find_opts("global"),

View File

@ -313,39 +313,6 @@ void qemu_add_opts(QemuOptsList *list)
abort(); abort();
} }
int qemu_set_option(const char *str)
{
Error *local_err = NULL;
char group[64], id[64], arg[64];
QemuOptsList *list;
QemuOpts *opts;
int rc, offset;
rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
if (rc < 3 || str[offset] != '=') {
error_report("can't parse: \"%s\"", str);
return -1;
}
list = qemu_find_opts(group);
if (list == NULL) {
return -1;
}
opts = qemu_opts_find(list, id);
if (!opts) {
error_report("there is no %s \"%s\" defined",
list->name, id);
return -1;
}
if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) {
error_report_err(local_err);
return -1;
}
return 0;
}
struct ConfigWriteData { struct ConfigWriteData {
QemuOptsList *list; QemuOptsList *list;
FILE *fp; FILE *fp;