summaryrefslogtreecommitdiffstats
path: root/hw/core
diff options
context:
space:
mode:
authorPaolo Bonzini2022-04-14 18:52:57 +0200
committerPaolo Bonzini2022-05-12 12:29:43 +0200
commit8c4da4b52186e9d0c7233b0ffc796e78fdf3e7b3 (patch)
tree377466afffcfdc86773fdc23e93e843566c82070 /hw/core
parentmachine: use QAPI struct for boot configuration (diff)
downloadqemu-8c4da4b52186e9d0c7233b0ffc796e78fdf3e7b3.tar.gz
qemu-8c4da4b52186e9d0c7233b0ffc796e78fdf3e7b3.tar.xz
qemu-8c4da4b52186e9d0c7233b0ffc796e78fdf3e7b3.zip
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>
Diffstat (limited to 'hw/core')
-rw-r--r--hw/core/machine.c98
1 files changed, 52 insertions, 46 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index b3deb8146f..8cea94537d 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -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;
+
+ 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;
- ms->boot_config = (BootConfiguration) {
- .has_order = true,
- .order = (char *)machine_class->default_boot_order,
- .has_strict = true,
- .strict = false,
- };
- if (!opts) {
+ 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;
}
- 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);
- }
+ machine_copy_boot_config(ms, config);
+ /* Strings live in ms->boot_config. */
+ free(config);
+ return;
- 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);