mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 12:53:53 -06:00
vl: fix [memory] section with -readconfig
The -M memory.* options do not have magic applied to them like the -m
option, namely no "M" (for mebibytes) is tacked at the end of a suffixless
value for "-M memory.size".
This magic is performed by parse_memory_options, and we have to do it for
both "-m" and the [memory] section of a config file. Storing [memory]
sections directly to machine_opts_dict changed the meaning of
[memory]
size = "1024"
in a -readconfig file from 1024MiB to 8KiB (1024 Bytes rounded up to
8KiB silently). To avoid this, the [memory] section has to be changed
back to QemuOpts (combining [memory] and "-m" will work fine thanks to
.merge_lists being true).
Change parse_memory_options() so that, similar to the older function
set_memory_options(), it operates after command line parsing is done;
and also call it where set_memory_options() used to be.
Note, the parsing code uses exit(1) instead of exit(EXIT_FAILURE) to
match neighboring code.
Reported-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Fixes: ce9d03fb3f
("machine: add mem compound property", 2022-05-12)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
55794c904d
commit
e12f0685e8
1 changed files with 14 additions and 11 deletions
25
softmmu/vl.c
25
softmmu/vl.c
|
@ -1947,16 +1947,15 @@ static void qemu_resolve_machine_memdev(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_memory_options(const char *arg)
|
static void parse_memory_options(void)
|
||||||
{
|
{
|
||||||
QemuOpts *opts;
|
QemuOpts *opts = qemu_find_opts_singleton("memory");
|
||||||
QDict *dict, *prop;
|
QDict *dict, *prop;
|
||||||
const char *mem_str;
|
const char *mem_str;
|
||||||
|
Location loc;
|
||||||
|
|
||||||
opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), arg, true);
|
loc_push_none(&loc);
|
||||||
if (!opts) {
|
qemu_opts_loc_restore(opts);
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
prop = qdict_new();
|
prop = qdict_new();
|
||||||
|
|
||||||
|
@ -1987,6 +1986,7 @@ static void parse_memory_options(const char *arg)
|
||||||
qdict_put(dict, "memory", prop);
|
qdict_put(dict, "memory", prop);
|
||||||
keyval_merge(machine_opts_dict, dict, &error_fatal);
|
keyval_merge(machine_opts_dict, dict, &error_fatal);
|
||||||
qobject_unref(dict);
|
qobject_unref(dict);
|
||||||
|
loc_pop(&loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qemu_create_machine(QDict *qdict)
|
static void qemu_create_machine(QDict *qdict)
|
||||||
|
@ -2053,8 +2053,7 @@ static bool is_qemuopts_group(const char *group)
|
||||||
if (g_str_equal(group, "object") ||
|
if (g_str_equal(group, "object") ||
|
||||||
g_str_equal(group, "machine") ||
|
g_str_equal(group, "machine") ||
|
||||||
g_str_equal(group, "smp-opts") ||
|
g_str_equal(group, "smp-opts") ||
|
||||||
g_str_equal(group, "boot-opts") ||
|
g_str_equal(group, "boot-opts")) {
|
||||||
g_str_equal(group, "memory")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2078,8 +2077,6 @@ static void qemu_record_config_group(const char *group, QDict *dict,
|
||||||
machine_merge_property("smp", dict, &error_fatal);
|
machine_merge_property("smp", dict, &error_fatal);
|
||||||
} else if (g_str_equal(group, "boot-opts")) {
|
} else if (g_str_equal(group, "boot-opts")) {
|
||||||
machine_merge_property("boot", dict, &error_fatal);
|
machine_merge_property("boot", dict, &error_fatal);
|
||||||
} else if (g_str_equal(group, "memory")) {
|
|
||||||
machine_merge_property("memory", dict, &error_fatal);
|
|
||||||
} else {
|
} else {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
@ -2882,7 +2879,10 @@ void qemu_init(int argc, char **argv, char **envp)
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case QEMU_OPTION_m:
|
case QEMU_OPTION_m:
|
||||||
parse_memory_options(optarg);
|
opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg, true);
|
||||||
|
if (opts == NULL) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef CONFIG_TPM
|
#ifdef CONFIG_TPM
|
||||||
case QEMU_OPTION_tpmdev:
|
case QEMU_OPTION_tpmdev:
|
||||||
|
@ -3515,6 +3515,9 @@ void qemu_init(int argc, char **argv, char **envp)
|
||||||
|
|
||||||
configure_rtc(qemu_find_opts_singleton("rtc"));
|
configure_rtc(qemu_find_opts_singleton("rtc"));
|
||||||
|
|
||||||
|
/* Transfer QemuOpts options into machine options */
|
||||||
|
parse_memory_options();
|
||||||
|
|
||||||
qemu_create_machine(machine_opts_dict);
|
qemu_create_machine(machine_opts_dict);
|
||||||
|
|
||||||
suspend_mux_open();
|
suspend_mux_open();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue