mirror of https://github.com/xemu-project/xemu.git
machine: add boot compound property
Make -boot syntactic sugar for a compound property "-machine boot.{order,menu,...}". machine_boot_parse is replaced by the setter for the property. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20220414165300.555321-3-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
97ec4d21e0
commit
8c4da4b521
|
@ -784,66 +784,63 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,
|
|||
machine_parse_smp_config(ms, config, errp);
|
||||
}
|
||||
|
||||
void machine_boot_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||
static void machine_get_boot(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
MachineState *ms = MACHINE(obj);
|
||||
BootConfiguration *config = &ms->boot_config;
|
||||
visit_type_BootConfiguration(v, name, &config, &error_abort);
|
||||
}
|
||||
|
||||
static void machine_free_boot_config(MachineState *ms)
|
||||
{
|
||||
g_free(ms->boot_config.order);
|
||||
g_free(ms->boot_config.once);
|
||||
g_free(ms->boot_config.splash);
|
||||
}
|
||||
|
||||
static void machine_copy_boot_config(MachineState *ms, BootConfiguration *config)
|
||||
{
|
||||
MachineClass *machine_class = MACHINE_GET_CLASS(ms);
|
||||
const char *s;
|
||||
ERRP_GUARD();
|
||||
|
||||
ms->boot_config = (BootConfiguration) {
|
||||
.has_order = true,
|
||||
.order = (char *)machine_class->default_boot_order,
|
||||
.has_strict = true,
|
||||
.strict = false,
|
||||
};
|
||||
if (!opts) {
|
||||
machine_free_boot_config(ms);
|
||||
ms->boot_config = *config;
|
||||
if (!config->has_order) {
|
||||
ms->boot_config.has_order = true;
|
||||
ms->boot_config.order = g_strdup(machine_class->default_boot_order);
|
||||
}
|
||||
}
|
||||
|
||||
static void machine_set_boot(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
MachineState *ms = MACHINE(obj);
|
||||
BootConfiguration *config = NULL;
|
||||
|
||||
if (!visit_type_BootConfiguration(v, name, &config, errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
s = qemu_opt_get(opts, "order");
|
||||
if (s) {
|
||||
validate_bootdevices(s, errp);
|
||||
if (config->has_order) {
|
||||
validate_bootdevices(config->order, errp);
|
||||
if (*errp) {
|
||||
return;
|
||||
goto out_free;
|
||||
}
|
||||
ms->boot_config.order = (char *)s;
|
||||
}
|
||||
|
||||
s = qemu_opt_get(opts, "once");
|
||||
if (s) {
|
||||
validate_bootdevices(s, errp);
|
||||
if (config->has_once) {
|
||||
validate_bootdevices(config->once, errp);
|
||||
if (*errp) {
|
||||
return;
|
||||
goto out_free;
|
||||
}
|
||||
ms->boot_config.has_once = true;
|
||||
ms->boot_config.once = (char *)s;
|
||||
}
|
||||
|
||||
s = qemu_opt_get(opts, "splash");
|
||||
if (s) {
|
||||
ms->boot_config.has_splash = true;
|
||||
ms->boot_config.splash = (char *)s;
|
||||
}
|
||||
machine_copy_boot_config(ms, config);
|
||||
/* Strings live in ms->boot_config. */
|
||||
free(config);
|
||||
return;
|
||||
|
||||
s = qemu_opt_get(opts, "splash-time");
|
||||
if (s) {
|
||||
ms->boot_config.has_splash_time = true;
|
||||
ms->boot_config.splash_time = qemu_opt_get_number(opts, "splash-time", -1);
|
||||
}
|
||||
|
||||
s = qemu_opt_get(opts, "reboot-timeout");
|
||||
if (s) {
|
||||
ms->boot_config.has_reboot_timeout = true;
|
||||
ms->boot_config.reboot_timeout = qemu_opt_get_number(opts, "reboot-timeout", -1);
|
||||
}
|
||||
|
||||
s = qemu_opt_get(opts, "menu");
|
||||
if (s) {
|
||||
ms->boot_config.has_menu = true;
|
||||
ms->boot_config.menu = qemu_opt_get_bool(opts, "menu", false);
|
||||
}
|
||||
|
||||
ms->boot_config.strict = qemu_opt_get_bool(opts, "strict", false);
|
||||
out_free:
|
||||
qapi_free_BootConfiguration(config);
|
||||
}
|
||||
|
||||
static void machine_class_init(ObjectClass *oc, void *data)
|
||||
|
@ -884,6 +881,12 @@ static void machine_class_init(ObjectClass *oc, void *data)
|
|||
object_class_property_set_description(oc, "dumpdtb",
|
||||
"Dump current dtb to a file and quit");
|
||||
|
||||
object_class_property_add(oc, "boot", "BootConfiguration",
|
||||
machine_get_boot, machine_set_boot,
|
||||
NULL, NULL);
|
||||
object_class_property_set_description(oc, "boot",
|
||||
"Boot configuration");
|
||||
|
||||
object_class_property_add(oc, "smp", "SMPConfiguration",
|
||||
machine_get_smp, machine_set_smp,
|
||||
NULL, NULL);
|
||||
|
@ -1017,12 +1020,15 @@ static void machine_initfn(Object *obj)
|
|||
ms->smp.clusters = 1;
|
||||
ms->smp.cores = 1;
|
||||
ms->smp.threads = 1;
|
||||
|
||||
machine_copy_boot_config(ms, &(BootConfiguration){ 0 });
|
||||
}
|
||||
|
||||
static void machine_finalize(Object *obj)
|
||||
{
|
||||
MachineState *ms = MACHINE(obj);
|
||||
|
||||
machine_free_boot_config(ms);
|
||||
g_free(ms->kernel_filename);
|
||||
g_free(ms->initrd_filename);
|
||||
g_free(ms->kernel_cmdline);
|
||||
|
|
|
@ -26,7 +26,6 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)
|
|||
extern MachineState *current_machine;
|
||||
|
||||
void machine_run_board_init(MachineState *machine);
|
||||
void machine_boot_parse(MachineState *ms, QemuOpts *opts, Error **errp);
|
||||
bool machine_usb(MachineState *machine);
|
||||
int machine_phandle_start(MachineState *machine);
|
||||
bool machine_dump_guest_core(MachineState *machine);
|
||||
|
|
16
softmmu/vl.c
16
softmmu/vl.c
|
@ -1884,16 +1884,11 @@ static bool object_create_early(const char *type)
|
|||
|
||||
static void qemu_apply_machine_options(QDict *qdict)
|
||||
{
|
||||
QemuOpts *opts;
|
||||
|
||||
object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal);
|
||||
current_machine->ram_size = ram_size;
|
||||
current_machine->maxram_size = maxram_size;
|
||||
current_machine->ram_slots = ram_slots;
|
||||
|
||||
opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
|
||||
machine_boot_parse(current_machine, opts, &error_fatal);
|
||||
|
||||
if (semihosting_enabled() && !semihosting_get_argc()) {
|
||||
/* fall back to the -kernel/-append */
|
||||
semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline);
|
||||
|
@ -2189,7 +2184,8 @@ static bool is_qemuopts_group(const char *group)
|
|||
{
|
||||
if (g_str_equal(group, "object") ||
|
||||
g_str_equal(group, "machine") ||
|
||||
g_str_equal(group, "smp-opts")) {
|
||||
g_str_equal(group, "smp-opts") ||
|
||||
g_str_equal(group, "boot-opts")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -2211,6 +2207,8 @@ static void qemu_record_config_group(const char *group, QDict *dict,
|
|||
keyval_merge(machine_opts_dict, dict, errp);
|
||||
} else if (g_str_equal(group, "smp-opts")) {
|
||||
machine_merge_property("smp", dict, &error_fatal);
|
||||
} else if (g_str_equal(group, "boot-opts")) {
|
||||
machine_merge_property("boot", dict, &error_fatal);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
@ -2956,11 +2954,7 @@ void qemu_init(int argc, char **argv, char **envp)
|
|||
drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
|
||||
break;
|
||||
case QEMU_OPTION_boot:
|
||||
opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
|
||||
optarg, true);
|
||||
if (!opts) {
|
||||
exit(1);
|
||||
}
|
||||
machine_parse_property_opt(qemu_find_opts("boot-opts"), "boot", optarg);
|
||||
break;
|
||||
case QEMU_OPTION_fda:
|
||||
case QEMU_OPTION_fdb:
|
||||
|
|
Loading…
Reference in New Issue