cleanup qemu_init and make sense of command line processing
cover cleanup qemu_init and make sense of command line processing
This series cleans up qemu_init, grouping together code that does a similar function. In particular:
* generic initialization of various subsystemd is placed in separate functions
* code that was randomly placed in vl.c is moved to machine.c
* early options that affect the whole program are grouped together (-sandbox, -name, -trace, -L)
* pure syntactic sugar options (-mem-prealloc, -watchdog) are grouped together
* the creation of backends is split into an "early" (before -machine) and a "late" (after -machine) part
The remaining code that I have not split deals mostly with setting up the machine object; this includes -smp, -boot, -m, -numa. With this refactoring, one can (almost) see some clearly delimited phases:
* before the machine is created, only backends can be created (e.g. early -object processing). In principle more initialization could be moved before the machine is created: the machine class is available and it can be used to decide which default devices to create.
* after the machine is created, the accelerator needs to be established
* after the accelerator is established, board setup can proceed and devices can be created
Apart from the obvious absence of commands like machine-set and accel-set (and making chardev-add, blockdev-add etc. available in preconfig mode), the following complications are the blockers for pure-QMP configuration of machines:
* as usual, there is no hook into board creation code to communicate the backends for on-board devices. This is because serial_hd, nd_table etc. don't have a QAPI/QMP representation.
* the current "preconfig" loop does not let you configure enough, since it ends before devices can be created and the regular monitor loop only starts after qdev_machine_creation_done. Perhaps x-exit-preconfig would execute everything up to (and excluding) qdev_machine_creation_done, while the rest would be deferred to the first "cont" command using a vm state change notifier.
Paolo
Paolo Bonzini (22):
semihosting: fix order of initialization functions
machine: remove deprecated -machine enforce-config-section option
machine: move UP defaults to class_base_init
machine: move SMP initialization from vl.c
vl: extract validation of -smp to machine.c
vl: remove bogus check
trace: remove argument from trace_init_file
vl: split various early command line options to a separate function
vl: move various initialization routines out of qemu_init
vl: extract qemu_init_subsystems
vl: move prelaunch part of qemu_init to a new function
vl: move bios_name out of softmmu/vl.c
vl: extract various command line validation snippets to a new function
vl: preconfig and loadvm are mutually exclusive
vl: extract various command line desugaring snippets to a new function
vl: create "-net nic -net user" default earlier
vl: load plugins as late as possible
vl: move semihosting command line fallback to qemu_finish_machine_init
vl: extract default devices to separate functions
vl: move CHECKPOINT_INIT after preconfig
vl: separate qemu_create_early_backends
vl: separate qemu_create_late_backends
bsd-user/main.c | 6 +- docs/system/deprecated.rst | 12 +- hw/core/machine.c | 68 +- include/hw/boards.h | 2 +- include/hw/qdev-core.h | 8 - include/sysemu/sysemu.h | 1 + linux-user/main.c | 6 +- migration/migration.c | 12 +- qemu-img.c | 6 +- qemu-io.c | 6 +- qemu-nbd.c | 6 +- qemu-options.hx | 8 - scsi/qemu-pr-helper.c | 6 +- softmmu/qdev-monitor.c | 6 - softmmu/vl.c | 1249 +++++++++++++------------- storage-daemon/qemu-storage-daemon.c | 9 +- trace/control.c | 10 +- trace/control.h | 12 +- 18 files changed, 704 insertions(+), 729 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/22 semihosting: fix order of initialization functions
qemu_semihosting_console_init uses semihosting.chardev which is set by qemu_semihosting_connect_chardevs. Thus qemu_semihosting_connect_chardevs has to be called first.
--- softmmu/vl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
softmmu/vl.c +2 -4
@@ -4288,7 +4288,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL , &error_fatal); -/* connect semihosting console input if requested */ +/* now chardevs have been created we may have semihosting to connect */ +qemu_semihosting_connect_chardevs ();qemu_semihosting_console_init ();if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )
@@ -4298,9 +4299,6 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); -/* now chardevs have been created we may have semihosting to connect */ -qemu_semihosting_connect_chardevs (); -/* If no default VGA is requested, the default is "none". */ if (default_vga) { vga_model =get_default_vga_model (machine_class);
Signature · 1 line
2.26.2
Re: [PATCH 01/22] semihosting: fix order of initialization functions
Quoted 3 lines · Paolo Bonzini
qemu_semihosting_console_inituses semihosting.chardev which is set byqemu_semihosting_connect_chardevs. Thusqemu_semihosting_connect_chardevshas to be called first.
It looks like this is reverting 619985e9 ("semihosting: defer connect_chardevs a little more to use serialx"). Looking back at the history it seems the two calls had different results:
Right - can confirm the difference between:
./aarch64-softmmu/qemu-system-aarch64 -cpu max -serial mon:stdio -M virt -display none -semihosting -kernel ./tests/tcg/aarch64-softmmu/memory
and
./aarch64-softmmu/qemu-system-aarch64 -cpu max -serial mon:stdio -M virt -display none -semihosting-config chardev=serial0 -kernel ./tests/tcg/aarch64-softmmu/memory
With this patch applied it breaks the later invocation:
./aarch64-softmmu/qemu-system-aarch64 -cpu max -serial mon:stdio -M virt -display none -semihosting-config chardev=serial0 -kernel ./tests/tcg/aarch64-softmmu/memory
qemu-system-aarch64: semihosting chardev 'serial0' not found
Quoted 11 lines
Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/vl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)softmmu/vl.c +0
-0
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4293
Quoted 7 lines
softmmu/vl.c +2
-1@@ -4288,7 +4288,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL , &error_fatal); -/* connect semihosting console input if requested */ +/* now chardevs have been created we may have semihosting to connect */ +qemu_semihosting_connect_chardevs ();qemu_semihosting_console_init ();
Maybe instead of this we should:
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4303
Quoted 9 lines
softmmu/vl.c +0
-3if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )@@ -4298,9 +4299,6 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); -/* now chardevs have been created we may have semihosting to connect */ -qemu_semihosting_connect_chardevs (); -
Move both here:
if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
exit(1);
/* now chardevs have been created we may have semihosting to connect */
qemu_semihosting_connect_chardevs();
qemu_semihosting_console_init();Quoted 3 lines
softmmu/vl.c +0
-0/* If no default VGA is requested, the default is "none". */ if (default_vga) { vga_model =get_default_vga_model (machine_class);
Signature · 1 line
Alex Bennée
Re: [PATCH 01/22] semihosting: fix order of initialization functions
Quoted 4 lines · Alex Bennée
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4303
Quoted 4 lines
softmmu/vl.c +0
-3-/* now chardevs have been created we may have semihosting to connect */ -qemu_semihosting_connect_chardevs (); -
Quoted 10 lines
Move both here:
if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) exit(1); /* now chardevs have been created we may have semihosting to connect */ qemu_semihosting_connect_chardevs(); qemu_semihosting_console_init();
Sounds good, thanks!
Paolo
PATCH 2/22 machine: remove deprecated -machine enforce-config-section option
In reply to Paolo BonziniDeprecated since 3.1 and complicates the initialization sequence, remove it.
--- docs/system/deprecated.rst | 12 ++++++------ hw/core/machine.c | 24 +----------------------- include/hw/boards.h | 1 - migration/migration.c | 10 ---------- qemu-options.hx | 8 -------- 5 files changed, 7 insertions(+), 48 deletions(-)
docs/system/deprecated.rst +6 -6
@@ -21,12 +21,6 @@ deprecated. System emulator command line arguments -------------------------------------- -``-machine enforce-config-section=on|off`` (since 3.1) -'''''''''''''''''''''''''''''''''''''''''''''''''''''' - -The ``enforce-config-section`` parameter is replaced by the -``-global migration.send-configuration={on|off}`` option. - ``-usbdevice`` (since 2.10.0) '''''''''''''''''''''''''''''
@@ -689,6 +683,12 @@ Support for invalid topologies is removed, the user must ensure topologies described with -smp include all possible cpus, i.e. *sockets* * *cores* * *threads* = *maxcpus*. +``-machine enforce-config-section=on|off`` (removed 5.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +The ``enforce-config-section`` property was replaced by the +``-global migration.send-configuration={on|off}`` option. + Block devices -------------
hw/core/machine.c +1 -23
@@ -26,6 +26,7 @@#include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "migration/misc.h" #include "migration/vmstate.h" GlobalProperty hw_compat_5_1[] = {
@@ -411,24 +412,6 @@ static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)return ms->suppress_vmdesc; } -static void machine_set_enforce_config_section (Object *obj,bool value, -Error **errp) -{ -MachineState *ms =MACHINE (obj); - -warn_report ("enforce-config-section is deprecated, please use " -"-global migration.send-configuration=on|off instead" ); - - ms->enforce_config_section = value; -} - -static bool machine_get_enforce_config_section (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->enforce_config_section; -} -static char *machine_get_memory_encryption (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -857,11 +840,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"suppress-vmdesc" ,"Set on to disable self-describing migration" ); -object_class_property_add_bool (oc,"enforce-config-section" , - machine_get_enforce_config_section, machine_set_enforce_config_section); -object_class_property_set_description (oc,"enforce-config-section" , -"Set on to enforce configuration section migration" ); -object_class_property_add_str (oc,"memory-encryption" , machine_get_memory_encryption, machine_set_memory_encryption); object_class_property_set_description(oc, "memory-encryption",
include/hw/boards.h +0 -1
@@ -268,7 +268,6 @@ struct MachineState {char *firmware;bool iommu;bool suppress_vmdesc; -bool enforce_config_section;bool enable_graphics;char *memory_encryption;char *ram_memdev_id;
migration/migration.c +0 -10
@@ -145,7 +145,6 @@ static void migrate_fd_cancel(MigrationState *s);void migration_object_init (void ) { -MachineState *ms =MACHINE (qdev_get_machine ());Error *err =NULL ;/* This can only be called once. */
@@ -170,15 +169,6 @@ void migration_object_init(void)error_report_err (err);exit (1 ); } - -/* -* We cannot really do this in migration_instance_init() since at -* that time global properties are not yet applied, then this -* value will be definitely replaced by something else. -*/ -if (ms->enforce_config_section) { - current_migration->send_configuration = true; - } }void migration_shutdown (void )
qemu-options.hx +0 -8
@@ -34,7 +34,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n" " nvdimm=on|off controls NVDIMM support (default=off)\n" - " enforce-config-section=on|off enforce configuration section migration (default=off)\n" " memory-encryption=@var{} memory encryption object to use (default=none)\n" " hmat=on|off controls ACPI HMAT support (default=off)\n", QEMU_ARCH_ALL)
@@ -91,13 +90,6 @@ SRST ``nvdimm=on|off`` Enables or disables NVDIMM support. The default is off. - ``enforce-config-section=on|off`` - If ``enforce-config-section`` is set to on, force migration code - to send configuration section even if the machine-type sets the - ``migration.send-configuration`` property to off. NOTE: this - parameter is deprecated. Please use ``-global`` - ``migration.send-configuration``\ =on\|off instead. - ``memory-encryption=`` Memory encryption object to use. The default is none.
Signature · 1 line
2.26.2
Re: [PATCH 02/22] machine: remove deprecated -machine enforce-config-section option
Quoted 47 lines · Paolo Bonzini
Deprecated since 3.1 and complicates the initialization sequence, remove it.
Signed-off-by Paolo Bonzini <[email protected]>--- docs/system/deprecated.rst | 12 ++++++------ hw/core/machine.c | 24 +----------------------- include/hw/boards.h | 1 - migration/migration.c | 10 ---------- qemu-options.hx | 8 -------- 5 files changed, 7 insertions(+), 48 deletions(-)docs/system/deprecated.rst +6
-6@@ -21,12 +21,6 @@ deprecated. System emulator command line arguments -------------------------------------- -``-machine enforce-config-section=on|off`` (since 3.1) -'''''''''''''''''''''''''''''''''''''''''''''''''''''' - -The ``enforce-config-section`` parameter is replaced by the -``-global migration.send-configuration={on|off}`` option. - ``-usbdevice`` (since 2.10.0) '''''''''''''''''''''''''''''@@ -689,6 +683,12 @@ Support for invalid topologies is removed, the user must ensure topologies described with -smp include all possible cpus, i.e. *sockets* * *cores* * *threads* = *maxcpus*. +``-machine enforce-config-section=on|off`` (removed 5.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +The ``enforce-config-section`` property was replaced by the +``-global migration.send-configuration={on|off}`` option. + Block devices -------------hw/core/machine.c +0
-0
hw/core/machine.c line 29
Quoted 4 lines
hw/core/machine.c +1
-0@@ -26,6 +26,7 @@#include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "migration/misc.h"
This new include does not make much sense to me, if all you did was removing code from this file. Why did you add this here?
With this hunk removed:
Re: [PATCH 02/22] machine: remove deprecated -machine enforce-config-section option
Quoted 3 lines · Thomas Huth
Quoted 1 line
+#include "
migration/misc.h"This new include does not make much sense to me, if all you did was removing code from this file. Why did you add this here?
Yeah, it's not needed anymore. It's part of a different patch that I threw away when I noticed the deprecation.
Paolo
Quoted 3 lines
With this hunk removed:
Reviewed-by Thomas Huth <[email protected]>
PATCH 3/22 machine: move UP defaults to class_base_init
In reply to Paolo BonziniClean up vl.c, default min/max/default_cpus to uniprocessor directly in the QOM class initialization code.
--- hw/core/machine.c | 6 +++++- softmmu/vl.c | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-)
hw/core/machine.c +5 -1
@@ -854,8 +854,12 @@ static void machine_class_init(ObjectClass *oc, void *data)static void machine_class_base_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->max_cpus = mc->max_cpus ?:1 ; + mc->min_cpus = mc->min_cpus ?:1 ; + mc->default_cpus = mc->default_cpus ?:1 ; +if (!object_class_is_abstract (oc)) { -MachineClass *mc =MACHINE_CLASS (oc);const char *cname =object_class_get_name (oc);assert (g_str_has_suffix (cname,TYPE_MACHINE_SUFFIX )); mc->name = g_strndup(cname,
softmmu/vl.c +0 -5
@@ -3966,11 +3966,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (0 ); } -/* machine_class: default to UP */ - machine_class->max_cpus = machine_class->max_cpus ?:1 ; - machine_class->min_cpus = machine_class->min_cpus ?:1 ; - machine_class->default_cpus = machine_class->default_cpus ?:1 ; -/* default to machine_class->default_cpus */ current_machine->smp.cpus = machine_class->default_cpus; current_machine->smp.max_cpus = machine_class->default_cpus;
Signature · 1 line
2.26.2
Re: [PATCH 03/22] machine: move UP defaults to class_base_init
Quoted 34 lines · Paolo Bonzini
Clean up
vl.c, default min/max/default_cpus to uniprocessor directly in the QOM class initialization code.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 6 +++++- softmmu/vl.c | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +5
-1@@ -854,8 +854,12 @@ static void machine_class_init(ObjectClass *oc, void *data)static void machine_class_base_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->max_cpus = mc->max_cpus ?:1 ; + mc->min_cpus = mc->min_cpus ?:1 ; + mc->default_cpus = mc->default_cpus ?:1 ; +if (!object_class_is_abstract (oc)) { -MachineClass *mc =MACHINE_CLASS (oc);const char *cname =object_class_get_name (oc);assert (g_str_has_suffix (cname,TYPE_MACHINE_SUFFIX )); mc->name = g_strndup(cname,softmmu/vl.c +0
-0@@ -3966,11 +3966,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (0 );
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3971
Quoted 10 lines
softmmu/vl.c +0
-5} -/* machine_class: default to UP */ - machine_class->max_cpus = machine_class->max_cpus ?:1 ; - machine_class->min_cpus = machine_class->min_cpus ?:1 ; - machine_class->default_cpus = machine_class->default_cpus ?:1 ; -/* default to machine_class->default_cpus */ current_machine->smp.cpus = machine_class->default_cpus; current_machine->smp.max_cpus = machine_class->default_cpus;
PATCH 4/22 machine: move SMP initialization from vl.c
In reply to Paolo BonziniInitialize the object's values from the class when the object is created, no need to have vl.c do it for us.
--- hw/core/machine.c | 7 +++++++ softmmu/vl.c | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)
hw/core/machine.c +7 -0
@@ -908,6 +908,13 @@ static void machine_initfn(Object *obj)/* Register notifier when init is done for sysbus sanity checks */ ms->sysbus_notifier.notify = machine_init_notify;qemu_add_machine_init_done_notifier (&ms->sysbus_notifier); + +/* default to mc->default_cpus */ + ms->smp.cpus = mc->default_cpus; + ms->smp.max_cpus = mc->default_cpus; + ms->smp.cores =1 ; + ms->smp.threads =1 ; + ms->smp.sockets =1 ; }static void machine_finalize (Object *obj)
softmmu/vl.c +0 -7
@@ -3966,13 +3966,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (0 ); } -/* default to machine_class->default_cpus */ - current_machine->smp.cpus = machine_class->default_cpus; - current_machine->smp.max_cpus = machine_class->default_cpus; - current_machine->smp.cores =1 ; - current_machine->smp.threads =1 ; - current_machine->smp.sockets =1 ; - machine_class->smp_parse (current_machine,qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL ));
Signature · 1 line
2.26.2
Re: [PATCH 04/22] machine: move SMP initialization from vl.c
Quoted 8 lines · Paolo Bonzini
Initialize the object's values from the class when the object is created, no need to have
vl.cdo it for us.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 7 +++++++ softmmu/vl.c | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-)
PATCH 5/22 vl: extract validation of -smp to machine.c
In reply to Paolo BonziniOnce smp_parse is done, the validation operates on the MachineState. There is no reason for that code to be in vl.c.
--- hw/core/machine.c | 23 +++++++++++++++++++++++ include/hw/boards.h | 1 + softmmu/vl.c | 20 ++------------------ 3 files changed, 26 insertions(+), 18 deletions(-)
hw/core/machine.c +23 -0
@@ -1073,6 +1073,29 @@ MemoryRegion *machine_consume_memdev(MachineState *machine,return ret; } +bool machine_smp_parse (MachineState *ms,QemuOpts *opts,Error **errp) +{ +MachineClass *mc =MACHINE_GET_CLASS (ms); + + mc->smp_parse (ms, opts); + +/* sanity-check smp_cpus and max_cpus against mc */ +if (ms->smp.cpus < mc->min_cpus) { +error_setg (errp,"Invalid SMP CPUs %d. The min CPUs " +"supported by machine '%s' is %d" , + ms->smp.cpus, + mc->name, mc->min_cpus); +return false; + }else if (ms->smp.max_cpus > mc->max_cpus) { +error_setg (errp,"Invalid SMP CPUs %d. The max CPUs " +"supported by machine '%s' is %d" , + current_machine->smp.max_cpus, + mc->name, mc->max_cpus); +return false; + } +return true; +} +void machine_run_board_init (MachineState *machine) {MachineClass *machine_class =MACHINE_GET_CLASS (machine);
include/hw/boards.h +1 -0
@@ -26,6 +26,7 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)extern MachineState *current_machine;void machine_run_board_init (MachineState *machine); +bool machine_smp_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);
softmmu/vl.c +2 -18
@@ -3966,24 +3966,8 @@ void qemu_init(int argc, char **argv, char **envp)exit (0 ); } - machine_class->smp_parse (current_machine, -qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL )); - -/* sanity-check smp_cpus and max_cpus against machine_class */ -if (current_machine->smp.cpus < machine_class->min_cpus) { -error_report ("Invalid SMP CPUs %d. The min CPUs " -"supported by machine '%s' is %d" , - current_machine->smp.cpus, - machine_class->name, machine_class->min_cpus); -exit (1 ); - } -if (current_machine->smp.max_cpus > machine_class->max_cpus) { -error_report ("Invalid SMP CPUs %d. The max CPUs " -"supported by machine '%s' is %d" , - current_machine->smp.max_cpus, - machine_class->name, machine_class->max_cpus); -exit (1 ); - } +machine_smp_parse (current_machine, +qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL ), &error_fatal);if (mem_prealloc) {char *val;
Signature · 1 line
2.26.2
PATCH 6/22 vl: remove bogus check
In reply to Paolo BonziniThere is no reason to prevent -preconfig -daemonize. Of course if no monitor is defined there will be no way to start the VM, but that is a user error.
--- softmmu/vl.c | 6 ------ 1 file changed, 6 deletions(-)
softmmu/vl.c +0 -6
@@ -4022,12 +4022,6 @@ void qemu_init(int argc, char **argv, char **envp) }if (is_daemonized ()) { -if (!preconfig_exit_requested) { -error_report ("'preconfig' and 'daemonize' options are " -"mutually exclusive" ); -exit (EXIT_FAILURE ); - } -/* According to documentation and historically, -nographic redirects * serial port, parallel port and monitor to stdio, which does not work * with -daemonize. We can redirect these to null instead, but since
Signature · 1 line
2.26.2
PATCH 7/22 trace: remove argument from trace_init_file
In reply to Paolo BonziniIt is not needed, all the callers are just saving what was retrieved from -trace and trace_init_file can retrieve it on its own.
--- bsd-user/main.c | 6 ++---- linux-user/main.c | 6 ++---- qemu-img.c | 6 ++---- qemu-io.c | 6 ++---- qemu-nbd.c | 6 ++---- scsi/qemu-pr-helper.c | 6 ++---- softmmu/vl.c | 6 ++---- storage-daemon/qemu-storage-daemon.c | 9 +++------ trace/control.c | 10 ++++------ trace/control.h | 12 +++--------- 10 files changed, 24 insertions(+), 49 deletions(-)
bsd-user/main.c +2 -4
@@ -745,7 +745,6 @@ int main(int argc, char **argv)const char *gdbstub =NULL ;char **target_environ, **wrk;envlist_t *envlist =NULL ; -char *trace_file =NULL ; bsd_type = target_openbsd;if (argc <=1 )
@@ -851,8 +850,7 @@ int main(int argc, char **argv) }else if (!strcmp (r,"strace" )) { do_strace =1 ; }else if (!strcmp (r,"trace" )) { -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg); }else {usage (); }
@@ -880,7 +878,7 @@ int main(int argc, char **argv)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
linux-user/main.c +2 -4
@@ -386,11 +386,9 @@ static void handle_arg_version(const char *arg)exit (EXIT_SUCCESS ); } -static char *trace_file;static void handle_arg_trace (const char *arg) { -g_free (trace_file); - trace_file =trace_opt_parse (arg); +trace_opt_parse (arg); }#if defined(TARGET_XTENSA )
@@ -672,7 +670,7 @@ int main(int argc, char **argv, char **envp)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();if (qemu_plugin_load_list (&plugins)) {exit (1 ); }
qemu-img.c +2 -4
@@ -5434,7 +5434,6 @@ int main(int argc, char **argv)const img_cmd_t *cmd;const char *cmdname;Error *local_error =NULL ; -char *trace_file =NULL ;int c;static const struct option long_options[] = { {"help" , no_argument,0 ,'h' },
@@ -5484,8 +5483,7 @@ int main(int argc, char **argv)printf (QEMU_IMG_VERSION );return 0 ;case 'T' : -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg);break ; } }
@@ -5503,7 +5501,7 @@ int main(int argc, char **argv)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();qemu_set_log (LOG_TRACE );/* find the command */
qemu-io.c +2 -4
@@ -536,7 +536,6 @@ int main(int argc, char **argv)Error *local_error =NULL ;QDict *opts =NULL ;const char *format =NULL ; -char *trace_file =NULL ;bool force_share = false;#ifdef CONFIG_POSIX
@@ -601,8 +600,7 @@ int main(int argc, char **argv) }break ;case 'T' : -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg);break ;case 'V' : printf("%s version " QEMU_FULL_VERSION "\n"
@@ -653,7 +651,7 @@ int main(int argc, char **argv)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();qemu_set_log (LOG_TRACE );/* initialize commands */
qemu-nbd.c +2 -4
@@ -573,7 +573,6 @@ int main(int argc, char **argv)const char *tlscredsid =NULL ;bool imageOpts = false;bool writethrough = true; -char *trace_file =NULL ;bool fork_process = false;bool list = false;int old_stderr =-1 ;
@@ -767,8 +766,7 @@ int main(int argc, char **argv) imageOpts = true;break ;case 'T' : -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg);break ;case QEMU_NBD_OPT_TLSAUTHZ : tlsauthz = optarg;
@@ -815,7 +813,7 @@ int main(int argc, char **argv)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();qemu_set_log (LOG_TRACE ); socket_activation =check_socket_activation ();
scsi/qemu-pr-helper.c +2 -4
@@ -884,7 +884,6 @@ int main(int argc, char **argv)int quiet =0 ;int ch;Error *local_err =NULL ; -char *trace_file =NULL ;bool daemonize = false;bool pidfile_specified = false;bool socket_path_specified = false;
@@ -968,8 +967,7 @@ int main(int argc, char **argv) ++loglevel;break ;case 'T' : -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg);break ;case 'V' :version (argv[0 ]);
@@ -992,7 +990,7 @@ int main(int argc, char **argv)if (!trace_init_backends ()) {exit (EXIT_FAILURE ); } -trace_init_file (trace_file); +trace_init_file ();qemu_set_log (LOG_TRACE );#ifdef CONFIG_MPATH
softmmu/vl.c +2 -4
@@ -2883,7 +2883,6 @@ void qemu_init(int argc, char **argv, char **envp)int display_remote =0 ;const char *log_mask =NULL ;const char *log_file =NULL ; -char *trace_file =NULL ;ram_addr_t maxram_size;uint64_t ram_slots =0 ;FILE *vmstate_dump_file =NULL ;
@@ -3684,8 +3683,7 @@ void qemu_init(int argc, char **argv, char **envp) xen_domid_restrict = true;break ;case QEMU_OPTION_trace: -g_free (trace_file); - trace_file =trace_opt_parse (optarg); +trace_opt_parse (optarg);break ;case QEMU_OPTION_plugin:qemu_plugin_opt_parse (optarg, &plugin_list);
@@ -3931,7 +3929,7 @@ void qemu_init(int argc, char **argv, char **envp)if (!trace_init_backends ()) {exit (1 ); } -trace_init_file (trace_file); +trace_init_file ();/* Open the logfile at this point and set the log mask if necessary. */
storage-daemon/qemu-storage-daemon.c +3 -6
@@ -180,12 +180,9 @@ static void process_options(int argc, char *argv[])help ();exit (EXIT_SUCCESS );case 'T' : - { -char *trace_file =trace_opt_parse (optarg); -trace_init_file (trace_file); -g_free (trace_file); -break ; - } +trace_opt_parse (optarg); +trace_init_file (); +break ;case 'V' :printf ("qemu-storage-daemon version " QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n" );
trace/control.c +4 -6
@@ -221,8 +221,10 @@ static void trace_init_events(const char *fname)loc_pop (&loc); } -void trace_init_file (const char *file) +void trace_init_file (void ) { +QemuOpts *opts =qemu_find_opts_singleton ("trace" ); +const char *file =qemu_opt_get (opts,"file" );#ifdef CONFIG_TRACE_SIMPLE st_set_trace_file (file);st_set_trace_file_enabled (true);
@@ -286,9 +288,8 @@ bool trace_init_backends(void)return true; } -char *trace_opt_parse (const char *optarg) +void trace_opt_parse (const char *optarg) { -char *trace_file;QemuOpts *opts =qemu_opts_parse_noisily (qemu_find_opts ("trace" ), optarg, true);if (!opts) {
@@ -298,10 +299,7 @@ char *trace_opt_parse(const char *optarg)trace_enable_events (qemu_opt_get (opts,"enable" )); }trace_init_events (qemu_opt_get (opts,"events" )); - trace_file =g_strdup (qemu_opt_get (opts,"file" ));qemu_opts_del (opts); - -return trace_file; }uint32_t trace_get_vcpu_event_count (void )
trace/control.h +3 -9
@@ -167,8 +167,6 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,/** * trace_init_backends: -* @file: Name of trace output file; may be NULL. -* Corresponds to commandline option "--trace file=...". * * Initialize the tracing backend. *
@@ -178,14 +176,12 @@ bool trace_init_backends(void);/** * trace_init_file: -* @file: Name of trace output file; may be NULL. -* Corresponds to commandline option "--trace file=...". * * Record the name of the output file for the tracing backend. * Exits if no selected backend does not support specifying the -* output file, and a non-NULL file was passed. +* output file, and a file was specified with "-trace file=...". */ -void trace_init_file (const char *file); +void trace_init_file (void );/** * trace_init_vcpu:
@@ -229,10 +225,8 @@ extern QemuOptsList qemu_trace_opts;* @optarg: A string argument of --trace command line argument * * Initialize tracing subsystem. -* -* Returns the filename to save trace to. It must be freed with g_free(). */ -char *trace_opt_parse (const char *optarg); +void trace_opt_parse (const char *optarg);/** * trace_get_vcpu_event_count:
Signature · 1 line
2.26.2
PATCH 8/22 vl: split various early command line options to a separate function
In reply to Paolo BonziniVarious options affect the global state of QEMU including the rest of qemu_init, and they need to be called very early. Group them together in a function that is called at the beginning.
--- softmmu/vl.c | 202 ++++++++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 89 deletions(-)
softmmu/vl.c +113 -89
@@ -117,6 +117,7 @@#define MAX_VIRTIO_CONSOLES 1 +static const char *cpu_option;static const char *data_dir[16 ];static int data_dir_idx;const char *bios_name =NULL ;
@@ -143,6 +144,9 @@ int vga_interface_type = VGA_NONE;static DisplayOptions dpy;static int num_serial_hds;static Chardev **serial_hds; +static const char *log_mask =NULL ; +static const char *log_file =NULL ; +static bool list_data_dirs = false;Chardev *parallel_hds[MAX_PARALLEL_PORTS ];int win2k_install_hack =0 ;int singlestep =0 ;
@@ -2859,6 +2863,106 @@ static char *find_datadir(void)return get_relocated_path (CONFIG_QEMU_DATADIR ); } +static void qemu_process_early_options (void ) +{ +char **dirs; +int i; + +#ifdef CONFIG_SECCOMP +QemuOptsList *olist =qemu_find_opts_err ("sandbox" ,NULL ); +if (olist) { +qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); + } +#endif + +qemu_opts_foreach (qemu_find_opts ("name" ), + parse_name,NULL , &error_fatal); + +#ifndef _WIN32 +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + parse_add_fd,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + cleanup_add_fd,NULL , &error_fatal); +#endif + +if (!trace_init_backends ()) { +exit (1 ); + } +trace_init_file (); + +/* Open the logfile at this point and set the log mask if necessary. +*/ +qemu_set_log_filename (log_file, &error_fatal); +if (log_mask) { +int mask; + mask =qemu_str_to_log_mask (log_mask); +if (!mask) { +qemu_print_log_usage (stdout); +exit (1 ); + } +qemu_set_log (mask); + }else { +qemu_set_log (0 ); + } + +/* add configured firmware directories */ + dirs =g_strsplit (CONFIG_QEMU_FIRMWAREPATH ,G_SEARCHPATH_SEPARATOR_S ,0 ); +for (i =0 ; dirs[i] !=NULL ; i++) { +qemu_add_data_dir (get_relocated_path (dirs[i])); + } +g_strfreev (dirs); + +/* try to find datadir relative to the executable path */ +qemu_add_data_dir (find_datadir ()); +} + +static void qemu_process_help_options (void ) +{ +int i; + +/* +* Check for -cpu help and -device help before we call select_machine(), +* which will return an error if the architecture has no default machine +* type and the user did not specify one, so that the user doesn't need +* to say '-cpu help -machine something'. +*/ +if (cpu_option &&is_help_option (cpu_option)) { +list_cpus (cpu_option); +exit (0 ); + } + +if (qemu_opts_foreach (qemu_find_opts ("device" ), + device_help_func,NULL ,NULL )) { +exit (0 ); + } + +/* -L help lists the data directories and exits. */ +if (list_data_dirs) { +for (i =0 ; i < data_dir_idx; i++) { +printf ("%s\n" , data_dir[i]); + } +exit (0 ); + } +} + +static void qemu_maybe_daemonize (const char *pid_file) +{ +Error *err; + +os_daemonize (); +rcu_disable_atfork (); + +if (pid_file && !qemu_write_pidfile (pid_file, &err)) { +error_reportf_err (err,"cannot create PID file: " ); +exit (1 ); + } + + qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; +qemu_add_exit_notifier (&qemu_unlink_pidfile_notifier); +} + +void qemu_init (int argc,char **argv,char **envp) {int i;
@@ -2875,21 +2979,16 @@ void qemu_init(int argc, char **argv, char **envp)const char *optarg;const char *loadvm =NULL ;MachineClass *machine_class; -const char *cpu_option;const char *vga_model =NULL ;const char *incoming =NULL ;bool userconfig = true;bool nographic = false;int display_remote =0 ; -const char *log_mask =NULL ; -const char *log_file =NULL ;ram_addr_t maxram_size;uint64_t ram_slots =0 ;FILE *vmstate_dump_file =NULL ;Error *main_loop_err =NULL ;Error *err =NULL ; -bool list_data_dirs = false; -char **dirs;const char *mem_path =NULL ;bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);
@@ -3833,20 +3932,17 @@ void qemu_init(int argc, char **argv, char **envp)*/ loc_set_none (); -/* -* Check for -cpu help and -device help before we call select_machine(), -* which will return an error if the architecture has no default machine -* type and the user did not specify one, so that the user doesn't need -* to say '-cpu help -machine something'. +/* These options affect everything else and should be processed +* before daemonizing. */ -if (cpu_option &&is_help_option (cpu_option)) { -list_cpus (cpu_option); -exit (0 ); - } +qemu_process_early_options (); -if (qemu_opts_foreach (qemu_find_opts ("device" ), - device_help_func,NULL ,NULL )) { -exit (0 ); +qemu_process_help_options (); +qemu_maybe_daemonize (pid_file); + +if (qemu_init_main_loop (&main_loop_err)) { +error_report_err (main_loop_err); +exit (1 ); }user_register_global_props ();
@@ -3867,40 +3963,6 @@ void qemu_init(int argc, char **argv, char **envp) have_custom_ram_size =set_memory_options (&ram_slots, &maxram_size, machine_class); -os_daemonize (); -rcu_disable_atfork (); - -if (pid_file && !qemu_write_pidfile (pid_file, &err)) { -error_reportf_err (err,"cannot create PID file: " ); -exit (1 ); - } - - qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; -qemu_add_exit_notifier (&qemu_unlink_pidfile_notifier); - -if (qemu_init_main_loop (&main_loop_err)) { -error_report_err (main_loop_err); -exit (1 ); - } - -#ifdef CONFIG_SECCOMP - olist =qemu_find_opts_err ("sandbox" ,NULL ); -if (olist) { -qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); - } -#endif - -qemu_opts_foreach (qemu_find_opts ("name" ), - parse_name,NULL , &error_fatal); - -#ifndef _WIN32 -qemu_opts_foreach (qemu_find_opts ("add-fd" ), - parse_add_fd,NULL , &error_fatal); - -qemu_opts_foreach (qemu_find_opts ("add-fd" ), - cleanup_add_fd,NULL , &error_fatal); -#endif - current_machine =MACHINE (object_new_with_class (OBJECT_CLASS (machine_class)));if (machine_help_func (qemu_get_machine_opts (), current_machine)) {exit (0 );
@@ -3926,44 +3988,6 @@ void qemu_init(int argc, char **argv, char **envp)qemu_set_hw_version (machine_class->hw_version); } -if (!trace_init_backends ()) { -exit (1 ); - } -trace_init_file (); - -/* Open the logfile at this point and set the log mask if necessary. -*/ -qemu_set_log_filename (log_file, &error_fatal); -if (log_mask) { -int mask; - mask =qemu_str_to_log_mask (log_mask); -if (!mask) { -qemu_print_log_usage (stdout); -exit (1 ); - } -qemu_set_log (mask); - }else { -qemu_set_log (0 ); - } - -/* add configured firmware directories */ - dirs =g_strsplit (CONFIG_QEMU_FIRMWAREPATH ,G_SEARCHPATH_SEPARATOR_S ,0 ); -for (i =0 ; dirs[i] !=NULL ; i++) { -qemu_add_data_dir (get_relocated_path (dirs[i])); - } -g_strfreev (dirs); - -/* try to find datadir relative to the executable path */ -qemu_add_data_dir (find_datadir ()); - -/* -L help lists the data directories and exits. */ -if (list_data_dirs) { -for (i =0 ; i < data_dir_idx; i++) { -printf ("%s\n" , data_dir[i]); - } -exit (0 ); - } -machine_smp_parse (current_machine,qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL ), &error_fatal);
Signature · 1 line
2.26.2
PATCH 9/22 vl: move various initialization routines out of qemu_init
In reply to Paolo BonziniSome very simple initialization routines can be nested in existing subsystem-level functions, do that to simplify qemu_init.
--- hw/core/machine.c | 3 +++ include/hw/qdev-core.h | 8 -------- migration/migration.c | 4 ++++ softmmu/qdev-monitor.c | 6 ------ softmmu/vl.c | 5 ----- 5 files changed, 7 insertions(+), 19 deletions(-)
hw/core/machine.c +3 -0
@@ -873,6 +873,9 @@ static void machine_initfn(Object *obj)MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj); +container_get (obj,"/peripheral" ); +container_get (obj,"/peripheral-anon" ); + ms->dump_guest_core = true; ms->mem_merge = true; ms->enable_graphics = true;
include/hw/qdev-core.h +0 -8
@@ -769,14 +769,6 @@ BusState *sysbus_get_default(void);char *qdev_get_fw_dev_path (DeviceState *dev);char *qdev_get_own_fw_dev_path_from_handler (BusState *bus,DeviceState *dev); -/** -* @qdev_machine_init -* -* Initialize platform devices before machine init. This is a hack until full -* support for composition is added. -*/ -void qdev_machine_init (void ); -/** * device_legacy_reset: *
migration/migration.c +4 -0
@@ -169,6 +169,10 @@ void migration_object_init(void)error_report_err (err);exit (1 ); } + +blk_mig_init (); +ram_mig_init (); +dirty_bitmap_mig_init (); }void migration_shutdown (void )
softmmu/qdev-monitor.c +0 -6
@@ -943,12 +943,6 @@ BlockBackend *blk_by_qdev_id(const char *id, Error **errp)return blk; } -void qdev_machine_init (void ) -{ -qdev_get_peripheral_anon (); -qdev_get_peripheral (); -} -QemuOptsList qemu_device_opts = { .name ="device" , .implied_opt_name ="driver" ,
softmmu/vl.c +0 -5
@@ -4269,10 +4269,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (1 ); } -blk_mig_init (); -ram_mig_init (); -dirty_bitmap_mig_init (); -qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL , &error_fatal);
@@ -4305,7 +4301,6 @@ void qemu_init(int argc, char **argv, char **envp)reading from the other reads, because timer polling functions query clock values from the log. */ replay_checkpoint (CHECKPOINT_INIT ); -qdev_machine_init (); current_machine->boot_order = boot_order;
Signature · 1 line
2.26.2
PATCH 10/22 vl: extract qemu_init_subsystems
In reply to Paolo BonziniGroup a bunch of subsystem initializations that can be done right after command line parsing. Remove initializations that can be done simply as global variable initializers.
--- softmmu/vl.c | 94 ++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 51 deletions(-)
softmmu/vl.c +43 -51
@@ -129,7 +129,7 @@ bool enable_mlock = false;bool enable_cpu_pm = false;int nb_nics;NICInfo nd_table[MAX_NICS ]; -int autostart; +int autostart =1 ; static enum { RTC_BASE_UTC, RTC_BASE_LOCALTIME,
@@ -1229,7 +1229,8 @@ struct VMChangeStateEntry {int priority; }; -static QTAILQ_HEAD(, VMChangeStateEntry) vm_change_state_head; +static QTAILQ_HEAD(, VMChangeStateEntry) vm_change_state_head = +QTAILQ_HEAD_INITIALIZER (vm_change_state_head);/** * qemu_add_vm_change_state_handler_prio:
@@ -2962,11 +2963,45 @@ static void qemu_maybe_daemonize(const char *pid_file)qemu_add_exit_notifier (&qemu_unlink_pidfile_notifier); } +static void qemu_init_subsystems (void ) +{ +Error *err; + +os_set_line_buffering (); + +module_call_init (MODULE_INIT_TRACE ); + +qemu_init_cpu_list (); +qemu_init_cpu_loop (); +qemu_mutex_lock_iothread (); + +atexit (qemu_run_exit_notifiers); + +module_call_init (MODULE_INIT_QOM ); +module_call_init (MODULE_INIT_MIGRATION ); + +runstate_init (); +precopy_infrastructure_init (); +postcopy_infrastructure_init (); +monitor_init_globals (); + +if (qcrypto_init (&err) <0 ) { +error_reportf_err (err,"cannot initialize crypto: " ); +exit (1 ); + } + +os_setup_early_signal_handling (); + +bdrv_init_with_whitelist (); +page_size_init (); +socket_init (); +}void qemu_init (int argc,char **argv,char **envp) {int i; -int snapshot, linux_boot; +int snapshot =0 ; +int linux_boot;const char *initrd_filename;const char *kernel_filename, *kernel_cmdline;const char *boot_order =NULL ;
@@ -2987,7 +3022,6 @@ void qemu_init(int argc, char **argv, char **envp)ram_addr_t maxram_size;uint64_t ram_slots =0 ;FILE *vmstate_dump_file =NULL ; -Error *main_loop_err =NULL ;Error *err =NULL ;const char *mem_path =NULL ;bool have_custom_ram_size;
@@ -2995,22 +3029,6 @@ void qemu_init(int argc, char **argv, char **envp)QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);int mem_prealloc =0 ;/* force preallocation of physical target memory */ -os_set_line_buffering (); - -error_init (argv[0 ]); -module_call_init (MODULE_INIT_TRACE ); - -qemu_init_cpu_list (); -qemu_init_cpu_loop (); - -qemu_mutex_lock_iothread (); - -atexit (qemu_run_exit_notifiers); -qemu_init_exec_dir (argv[0 ]); - -module_call_init (MODULE_INIT_QOM ); -module_call_init (MODULE_INIT_MIGRATION ); -qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);qemu_add_drive_opts (&qemu_common_drive_opts);
@@ -3045,27 +3063,10 @@ void qemu_init(int argc, char **argv, char **envp)qemu_add_opts (&qemu_fw_cfg_opts);module_call_init (MODULE_INIT_OPTS ); -runstate_init (); -precopy_infrastructure_init (); -postcopy_infrastructure_init (); -monitor_init_globals (); - -if (qcrypto_init (&err) <0 ) { -error_reportf_err (err,"cannot initialize crypto: " ); -exit (1 ); - } - -QTAILQ_INIT (&vm_change_state_head); -os_setup_early_signal_handling (); - - cpu_option =NULL ; - snapshot =0 ; - - nb_nics =0 ; - -bdrv_init_with_whitelist (); +error_init (argv[0 ]); +qemu_init_exec_dir (argv[0 ]); - autostart =1 ; +qemu_init_subsystems ();/* first pass of option parsing */ optind =1 ;
@@ -3940,13 +3941,10 @@ void qemu_init(int argc, char **argv, char **envp)qemu_process_help_options ();qemu_maybe_daemonize (pid_file); -if (qemu_init_main_loop (&main_loop_err)) { -error_report_err (main_loop_err); -exit (1 ); - } +qemu_init_main_loop (&error_fatal); +cpu_timers_init ();user_register_global_props (); -replay_configure (icount_opts);if (incoming && !preconfig_exit_requested) {
@@ -4125,9 +4123,6 @@ void qemu_init(int argc, char **argv, char **envp)exit (1 ); } -page_size_init (); -socket_init (); -qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_add_opts_foreach, object_create_initial, &error_fatal);
@@ -4245,9 +4240,6 @@ void qemu_init(int argc, char **argv, char **envp)semihosting_arg_fallback (kernel_filename, kernel_cmdline); } -/* initialize cpu timers and VCPU throttle modules */ -cpu_timers_init (); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);
Signature · 1 line
2.26.2
PATCH 11/22 vl: move prelaunch part of qemu_init to a new function
In reply to Paolo BonziniThe final part of qemu_init, starting with the completion of board init, is already relatively clean. Split it out of qemu_init so that qemu_init keeps only the messy parts.
--- include/sysemu/sysemu.h | 1 + softmmu/vl.c | 238 +++++++++++++++++++++------------------- 2 files changed, 124 insertions(+), 115 deletions(-)
include/sysemu/sysemu.h +1 -0
@@ -112,6 +112,7 @@ QemuOpts *qemu_get_machine_opts(void);bool defaults_enabled (void );void qemu_init (int argc,char **argv,char **envp); +void qemu_finish_machine_init (void );void qemu_main_loop (void );void qemu_cleanup (void );
softmmu/vl.c +123 -115
275 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 12/22 vl: move bios_name out of softmmu/vl.c
In reply to Paolo Bonzinibios_name is a legacy variable used by machine code. Hide it from softmmu/vl.c.
--- hw/core/machine.c | 5 +++++ softmmu/vl.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-)
hw/core/machine.c +5 -0
@@ -212,6 +212,8 @@ GlobalProperty hw_compat_2_1[] = { };const size_t hw_compat_2_1_len =G_N_ELEMENTS (hw_compat_2_1); +const char *bios_name =NULL ; +static char *machine_get_kernel (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -396,6 +398,9 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)g_free (ms->firmware); ms->firmware =g_strdup (value); + +/* HACK */ + bios_name = ms->firmware; }static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp)
softmmu/vl.c +0 -2
@@ -123,7 +123,6 @@ static int data_dir_idx;static const char *mem_path;static const char *boot_order;static const char *boot_once; -const char *bios_name =NULL ;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int display_opengl;const char * keyboard_layout =NULL ;
@@ -4314,7 +4313,6 @@ void qemu_init(int argc, char **argv, char **envp) kernel_filename =qemu_opt_get (machine_opts,"kernel" ); initrd_filename =qemu_opt_get (machine_opts,"initrd" ); kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - bios_name =qemu_opt_get (machine_opts,"firmware" ); opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL );if (opts) {
Signature · 1 line
2.26.2
Re: [PATCH 12/22] vl: move bios_name out of softmmu/vl.c
Quoted 14 lines · Paolo Bonzini
bios_nameis a legacy variable used by machine code. Hide it fromsoftmmu/vl.c.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 5 +++++ softmmu/vl.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-)hw/core/machine.c +0
-0
hw/core/machine.c GlobalProperty hw_compat_2_1[] = { · line 215
Quoted 4 lines
hw/core/machine.c +1
-0@@ -212,6 +212,8 @@ GlobalProperty hw_compat_2_1[] = { };const size_t hw_compat_2_1_len =G_N_ELEMENTS (hw_compat_2_1); +const char *bios_name =NULL ;
I expect checkpatch.pl to complain "do not zero-initialize global".
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 402
Quoted 10 lines
hw/core/machine.c +3
-0+static char *machine_get_kernel (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);@@ -396,6 +398,9 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)g_free (ms->firmware); ms->firmware =g_strdup (value); + +/* HACK */
With a slightly better rationale explanation:
Quoted 25 lines
hw/core/machine.c +1
-0+ bios_name = ms->firmware; }static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp)softmmu/vl.c +0
-2@@ -123,7 +123,6 @@ static int data_dir_idx;static const char *mem_path;static const char *boot_order;static const char *boot_once; -const char *bios_name =NULL ;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int display_opengl;const char * keyboard_layout =NULL ;@@ -4314,7 +4313,6 @@ void qemu_init(int argc, char **argv, char **envp) kernel_filename =qemu_opt_get (machine_opts,"kernel" ); initrd_filename =qemu_opt_get (machine_opts,"initrd" ); kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - bios_name =qemu_opt_get (machine_opts,"firmware" ); opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL );if (opts) {
PATCH 13/22 vl: extract various command line validation snippets to a new function
In reply to Paolo Bonzini--- softmmu/vl.c | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-)
softmmu/vl.c +39 -39
@@ -123,6 +123,7 @@ static int data_dir_idx;static const char *mem_path;static const char *boot_order;static const char *boot_once; +static const char *incoming;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int display_opengl;const char * keyboard_layout =NULL ;
@@ -2866,6 +2867,39 @@ static char *find_datadir(void)return get_relocated_path (CONFIG_QEMU_DATADIR ); } +static void qemu_validate_options (void ) +{ +QemuOpts *machine_opts =qemu_get_machine_opts (); +const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); +const char *initrd_filename =qemu_opt_get (machine_opts,"initrd" ); +const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ); + +if (kernel_filename ==NULL ) { +if (kernel_cmdline !=NULL ) { +error_report ("-append only allowed with -kernel option" ); +exit (1 ); + } + +if (initrd_filename !=NULL ) { +error_report ("-initrd only allowed with -kernel option" ); +exit (1 ); + } + } + +if (incoming && !preconfig_exit_requested) { +error_report ("'preconfig' and 'incoming' options are " +"mutually exclusive" ); +exit (EXIT_FAILURE ); + } + +#ifdef CONFIG_CURSES +if (is_daemonized () && dpy.type ==DISPLAY_TYPE_CURSES ) { +error_report ("curses display cannot be used with -daemonize" ); +exit (1 ); + } +#endif +} +static void qemu_process_early_options (void ) {char **dirs;
@@ -3122,9 +3156,6 @@ void qemu_init(int argc, char **argv, char **envp) {int i;int snapshot =0 ; -int linux_boot; -const char *initrd_filename; -const char *kernel_filename, *kernel_cmdline;QemuOpts *opts, *machine_opts;QemuOpts *icount_opts =NULL , *accel_opts =NULL ;QemuOptsList *olist;
@@ -3133,7 +3164,6 @@ void qemu_init(int argc, char **argv, char **envp)const char *loadvm =NULL ;MachineClass *machine_class;const char *vga_model =NULL ; -const char *incoming =NULL ;bool userconfig = true;bool nographic = false;int display_remote =0 ;
@@ -4050,6 +4080,8 @@ void qemu_init(int argc, char **argv, char **envp)*/ loc_set_none (); +qemu_validate_options (); +/* These options affect everything else and should be processed * before daemonizing. */
@@ -4064,12 +4096,6 @@ void qemu_init(int argc, char **argv, char **envp)user_register_global_props ();replay_configure (icount_opts); -if (incoming && !preconfig_exit_requested) { -error_report ("'preconfig' and 'incoming' options are " -"mutually exclusive" ); -exit (EXIT_FAILURE ); - } -configure_rtc (qemu_find_opts_singleton ("rtc" )); machine_class =select_machine ();
@@ -4173,12 +4199,6 @@ void qemu_init(int argc, char **argv, char **envp)error_report ("-nographic cannot be used with -daemonize" );exit (1 ); } -#ifdef CONFIG_CURSES -if (dpy.type ==DISPLAY_TYPE_CURSES ) { -error_report ("curses display cannot be used with -daemonize" ); -exit (1 ); - } -#endif }if (nographic) {
@@ -4309,11 +4329,6 @@ void qemu_init(int argc, char **argv, char **envp)qtest_server_init (qtest_chrdev, qtest_log, &error_fatal); } - machine_opts =qemu_get_machine_opts (); - kernel_filename =qemu_opt_get (machine_opts,"kernel" ); - initrd_filename =qemu_opt_get (machine_opts,"initrd" ); - kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL );if (opts) { boot_order =qemu_opt_get (opts,"order" );
@@ -4334,24 +4349,9 @@ void qemu_init(int argc, char **argv, char **envp) boot_order = machine_class->default_boot_order; } -if (!kernel_cmdline) { - kernel_cmdline ="" ; - current_machine->kernel_cmdline = (char *)kernel_cmdline; - } - - linux_boot = (kernel_filename !=NULL ); - -if (!linux_boot && *kernel_cmdline !='\0' ) { -error_report ("-append only allowed with -kernel option" ); -exit (1 ); - } - -if (!linux_boot && initrd_filename !=NULL ) { -error_report ("-initrd only allowed with -kernel option" ); -exit (1 ); - } - -if (semihosting_enabled () && !semihosting_get_argc () && kernel_filename) { +if (semihosting_enabled () && !semihosting_get_argc ()) { +const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); +const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" );/* fall back to the -kernel/-append */ semihosting_arg_fallback (kernel_filename, kernel_cmdline); }
Signature · 1 line
2.26.2
PATCH 14/22 vl: preconfig and loadvm are mutually exclusive
In reply to Paolo BonziniJust like -incoming.
--- softmmu/vl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
softmmu/vl.c +6 -1
@@ -124,6 +124,7 @@ static const char *mem_path;static const char *boot_order;static const char *boot_once;static const char *incoming; +static const char *loadvm;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int display_opengl;const char * keyboard_layout =NULL ;
@@ -2886,6 +2887,11 @@ static void qemu_validate_options(void) } } +if (loadvm && !preconfig_exit_requested) { +error_report ("'preconfig' and 'loadvm' options are " +"mutually exclusive" ); +exit (EXIT_FAILURE ); + }if (incoming && !preconfig_exit_requested) {error_report ("'preconfig' and 'incoming' options are " "mutually exclusive" );
@@ -3161,7 +3167,6 @@ void qemu_init(int argc, char **argv, char **envp)QemuOptsList *olist;int optind;const char *optarg; -const char *loadvm =NULL ;MachineClass *machine_class;const char *vga_model =NULL ;bool userconfig = true;
Signature · 1 line
2.26.2
PATCH 15/22 vl: extract various command line desugaring snippets to a new function
In reply to Paolo Bonzini--- softmmu/vl.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-)
softmmu/vl.c +21 -18
@@ -126,6 +126,7 @@ static const char *boot_once;static const char *incoming;static const char *loadvm;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ; +int mem_prealloc;/* force preallocation of physical target memory */ int display_opengl;const char * keyboard_layout =NULL ;ram_addr_t ram_size;
@@ -159,7 +160,7 @@ int fd_bootchk = 1;static int no_reboot;int no_shutdown =0 ;int graphic_rotate =0 ; -const char *watchdog; +static const char *watchdog;QEMUOptionRom option_rom[MAX_OPTION_ROMS ];int nb_option_roms;int old_param =0 ;
@@ -2906,6 +2907,24 @@ static void qemu_validate_options(void)#endif } +static void qemu_process_sugar_options (void ) +{ +if (mem_prealloc) { +char *val; + + val =g_strdup_printf ("%ld" ,qemu_opt_get_number (qemu_find_opts_singleton ("smp-opts" ),"cpus" ,1 )); +object_register_sugar_prop ("memory-backend" ,"prealloc-threads" , val); +g_free (val); +object_register_sugar_prop ("memory-backend" ,"prealloc" ,"on" ); + } + +if (watchdog) { +int i =select_watchdog (watchdog); +if (i >0 ) +exit (i ==1 ?1 :0 ); + } +} +static void qemu_process_early_options (void ) {char **dirs;
@@ -3160,7 +3179,6 @@ void qemu_finish_machine_init(void)void qemu_init (int argc,char **argv,char **envp) { -int i;int snapshot =0 ;QemuOpts *opts, *machine_opts;QemuOpts *icount_opts =NULL , *accel_opts =NULL ;
@@ -3179,7 +3197,6 @@ void qemu_init(int argc, char **argv, char **envp)bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list); -int mem_prealloc =0 ;/* force preallocation of physical target memory */ qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);
@@ -4086,6 +4103,7 @@ void qemu_init(int argc, char **argv, char **envp)loc_set_none ();qemu_validate_options (); +qemu_process_sugar_options ();/* These options affect everything else and should be processed * before daemonizing.
@@ -4137,15 +4155,6 @@ void qemu_init(int argc, char **argv, char **envp)machine_smp_parse (current_machine,qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL ), &error_fatal); -if (mem_prealloc) { -char *val; - - val =g_strdup_printf ("%d" , current_machine->smp.cpus); -object_register_sugar_prop ("memory-backend" ,"prealloc-threads" , val); -g_free (val); -object_register_sugar_prop ("memory-backend" ,"prealloc" ,"on" ); - } -/* * Get the default machine options from the machine if it is not already * specified either by the configuration file or by the command line.
@@ -4404,12 +4413,6 @@ void qemu_init(int argc, char **argv, char **envp)select_vgahw (machine_class, vga_model); } -if (watchdog) { - i =select_watchdog (watchdog); -if (i >0 ) -exit (i ==1 ?1 :0 ); - } -/* This checkpoint is required by replay to separate prior clock reading from the other reads, because timer polling functions query clock values from the log. */
Signature · 1 line
2.26.2
PATCH 16/22 vl: create "-net nic -net user" default earlier
In reply to Paolo BonziniCreate it together with other default backends, even though the processing is done later.
--- softmmu/vl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
softmmu/vl.c +8 -8
@@ -4235,6 +4235,14 @@ void qemu_init(int argc, char **argv, char **envp)monitor_parse ("vc:80Cx24C" ,"readline" , false); } +if (default_net) { +QemuOptsList *net =qemu_find_opts ("net" ); +qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort); +#ifdef CONFIG_SLIRP +qemu_opts_set (net,NULL ,"type" ,"user" , &error_abort); +#endif + } +#if defined(CONFIG_VNC )if (!QTAILQ_EMPTY (&(qemu_find_opts ("vnc" )->head))) { display_remote++;
@@ -4370,14 +4378,6 @@ void qemu_init(int argc, char **argv, char **envp)semihosting_arg_fallback (kernel_filename, kernel_cmdline); } -if (default_net) { -QemuOptsList *net =qemu_find_opts ("net" ); -qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort); -#ifdef CONFIG_SLIRP -qemu_opts_set (net,NULL ,"type" ,"user" , &error_abort); -#endif - } -if (net_init_clients (&err) <0 ) {error_report_err (err);exit (1 );
Signature · 1 line
2.26.2
PATCH 17/22 vl: load plugins as late as possible
In reply to Paolo BonziniThere is no need to load plugins in the middle of default device processing, move -plugin handling just before preconfig is entered.
--- softmmu/vl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
softmmu/vl.c +8 -7
@@ -125,6 +125,7 @@ static const char *boot_order;static const char *boot_once;static const char *incoming;static const char *loadvm; +static QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int mem_prealloc;/* force preallocation of physical target memory */ int display_opengl;
@@ -3064,12 +3065,18 @@ void qemu_finish_machine_init(void)MachineClass *machine_class =MACHINE_GET_CLASS (current_machine);DisplayState *ds; +/* from here on runstate is RUN_STATE_PRELAUNCH */ +if (machine_class->default_ram_id && current_machine->ram_size &&numa_uses_legacy_mem () && !current_machine->ram_memdev_id) {create_default_memdev (current_machine, mem_path); } -/* from here on runstate is RUN_STATE_PRELAUNCH */ +/* process plugin before CPUs are created, but once -smp has been parsed */ +if (qemu_plugin_load_list (&plugin_list)) { +exit (1 ); + } +machine_run_board_init (current_machine);/*
@@ -3196,7 +3203,6 @@ void qemu_init(int argc, char **argv, char **envp)Error *err =NULL ;bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue); -QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);
@@ -4164,11 +4170,6 @@ void qemu_init(int argc, char **argv, char **envp) machine_class->default_machine_opts, 0); } -/* process plugin before CPUs are created, but once -smp has been parsed */ -if (qemu_plugin_load_list (&plugin_list)) { -exit (1 ); - } -qemu_opts_foreach (qemu_find_opts ("device" ), default_driver_check,NULL ,NULL ); qemu_opts_foreach(qemu_find_opts("global"),
Signature · 1 line
2.26.2
Re: [PATCH 17/22] vl: load plugins as late as possible
Quoted 21 lines · Paolo Bonzini
There is no need to load plugins in the middle of default device processing, move -plugin handling just before preconfig is entered.
Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/vl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)softmmu/vl.c +1
-0@@ -125,6 +125,7 @@ static const char *boot_order;static const char *boot_once;static const char *incoming;static const char *loadvm; +static QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int mem_prealloc;/* force preallocation of physical target memory */ int display_opengl;
softmmu/vl.c void qemu_finish_machine_init(void) · line 3069
Quoted 5 lines
softmmu/vl.c +2
-0@@ -3064,12 +3065,18 @@ void qemu_finish_machine_init(void)MachineClass *machine_class =MACHINE_GET_CLASS (current_machine);DisplayState *ds; +/* from here on runstate is RUN_STATE_PRELAUNCH */ +
Please move this comment in your patch #11:
"vl: move prelaunch part of qemu_init to a new function"
Then:
Quoted 35 lines
softmmu/vl.c +5
-7if (machine_class->default_ram_id && current_machine->ram_size &&numa_uses_legacy_mem () && !current_machine->ram_memdev_id) {create_default_memdev (current_machine, mem_path); } -/* from here on runstate is RUN_STATE_PRELAUNCH */ +/* process plugin before CPUs are created, but once -smp has been parsed */ +if (qemu_plugin_load_list (&plugin_list)) { +exit (1 ); + } +machine_run_board_init (current_machine);/* @@ -3196,7 +3203,6 @@ void qemu_init(int argc, char **argv, char **envp)Error *err =NULL ;bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue); -QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);@@ -4164,11 +4170,6 @@ void qemu_init(int argc, char **argv, char **envp) machine_class->default_machine_opts, 0); } -/* process plugin before CPUs are created, but once -smp has been parsed */ -if (qemu_plugin_load_list (&plugin_list)) { -exit (1 ); - } -qemu_opts_foreach (qemu_find_opts ("device" ), default_driver_check,NULL ,NULL ); qemu_opts_foreach(qemu_find_opts("global"),
PATCH 18/22 vl: move semihosting command line fallback to qemu_finish_machine_init
In reply to Paolo BonziniMove more sane parts of the huge qemu_init function out of it.
--- softmmu/vl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
softmmu/vl.c +5 -7
@@ -3067,6 +3067,11 @@ void qemu_finish_machine_init(void)/* from here on runstate is RUN_STATE_PRELAUNCH */ +if (semihosting_enabled () && !semihosting_get_argc () && current_machine->kernel_filename) { +/* fall back to the -kernel/-append */ +semihosting_arg_fallback (current_machine->kernel_filename, current_machine->kernel_cmdline); + } +if (machine_class->default_ram_id && current_machine->ram_size &&numa_uses_legacy_mem () && !current_machine->ram_memdev_id) {create_default_memdev (current_machine, mem_path);
@@ -4372,13 +4377,6 @@ void qemu_init(int argc, char **argv, char **envp) boot_order = machine_class->default_boot_order; } -if (semihosting_enabled () && !semihosting_get_argc ()) { -const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); -const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ); -/* fall back to the -kernel/-append */ -semihosting_arg_fallback (kernel_filename, kernel_cmdline); - } -if (net_init_clients (&err) <0 ) {error_report_err (err);exit (1 );
Signature · 1 line
2.26.2
PATCH 19/22 vl: extract default devices to separate functions
In reply to Paolo Bonzini--- softmmu/vl.c | 216 +++++++++++++++++++++++++++------------------------ 1 file changed, 114 insertions(+), 102 deletions(-)
softmmu/vl.c +114 -102
@@ -125,7 +125,9 @@ static const char *boot_order;static const char *boot_once;static const char *incoming;static const char *loadvm; +static int display_remote;static QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list); +static bool nographic = false;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int mem_prealloc;/* force preallocation of physical target memory */ int display_opengl;
@@ -147,6 +149,7 @@ static int rtc_host_datetime_offset = -1; /* valid & used only withRTC_BASE_DATETIME */ QEMUClockType rtc_clock;int vga_interface_type =VGA_NONE ; +static const char *vga_model =NULL ;static DisplayOptions dpy;static int num_serial_hds;static Chardev **serial_hds;
@@ -2224,6 +2227,115 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))return 0 ; } +static void qemu_disable_default_devices (void ) +{ +MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); + +qemu_opts_foreach (qemu_find_opts ("device" ), + default_driver_check,NULL ,NULL ); +qemu_opts_foreach (qemu_find_opts ("global" ), + default_driver_check,NULL ,NULL ); + +if (!vga_model && !default_vga) { + vga_interface_type =VGA_DEVICE ; + } +if (!has_defaults || machine_class->no_serial) { + default_serial =0 ; + } +if (!has_defaults || machine_class->no_parallel) { + default_parallel =0 ; + } +if (!has_defaults || machine_class->no_floppy) { + default_floppy =0 ; + } +if (!has_defaults || machine_class->no_cdrom) { + default_cdrom =0 ; + } +if (!has_defaults || machine_class->no_sdcard) { + default_sdcard =0 ; + } +if (!has_defaults) { + default_monitor =0 ; + default_net =0 ; + default_vga =0 ; + } +} + +static void qemu_create_default_devices (void ) +{ +MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); + +if (is_daemonized ()) { +/* According to documentation and historically, -nographic redirects +* serial port, parallel port and monitor to stdio, which does not work +* with -daemonize. We can redirect these to null instead, but since +* -nographic is legacy, let's just error out. +* We disallow -nographic only if all other ports are not redirected +* explicitly, to not break existing legacy setups which uses +* -nographic _and_ redirects all ports explicitly - this is valid +* usage, -nographic is just a no-op in this case. +*/ +if (nographic + && (default_parallel || default_serial || default_monitor)) { +error_report ("-nographic cannot be used with -daemonize" ); +exit (1 ); + } + } + +if (nographic) { +if (default_parallel) +add_device_config (DEV_PARALLEL ,"null" ); +if (default_serial && default_monitor) { +add_device_config (DEV_SERIAL ,"mon:stdio" ); + }else { +if (default_serial) +add_device_config (DEV_SERIAL ,"stdio" ); +if (default_monitor) +monitor_parse ("stdio" ,"readline" , false); + } + }else { +if (default_serial) +add_device_config (DEV_SERIAL ,"vc:80Cx24C" ); +if (default_parallel) +add_device_config (DEV_PARALLEL ,"vc:80Cx24C" ); +if (default_monitor) +monitor_parse ("vc:80Cx24C" ,"readline" , false); + } + +if (default_net) { +QemuOptsList *net =qemu_find_opts ("net" ); +qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort); +#ifdef CONFIG_SLIRP +qemu_opts_set (net,NULL ,"type" ,"user" , &error_abort); +#endif + } + +#if defined(CONFIG_VNC ) +if (!QTAILQ_EMPTY (&(qemu_find_opts ("vnc" )->head))) { + display_remote++; + } +#endif +if (dpy.type ==DISPLAY_TYPE_DEFAULT && !display_remote) { +if (!qemu_display_find_default (&dpy)) { + dpy.type =DISPLAY_TYPE_NONE ; +#if defined(CONFIG_VNC ) +vnc_parse ("localhost:0,to=99,id=default" , &error_abort); +#endif + } + } +if (dpy.type ==DISPLAY_TYPE_DEFAULT ) { + dpy.type =DISPLAY_TYPE_NONE ; + } + +/* If no default VGA is requested, the default is "none". */ +if (default_vga) { + vga_model =get_default_vga_model (machine_class); + } +if (vga_model) { +select_vgahw (machine_class, vga_model); + } +} +static int serial_parse (const char *devname) {int index = num_serial_hds;
@@ -3198,10 +3310,7 @@ void qemu_init(int argc, char **argv, char **envp)int optind;const char *optarg;MachineClass *machine_class; -const char *vga_model =NULL ;bool userconfig = true; -bool nographic = false; -int display_remote =0 ;ram_addr_t maxram_size;uint64_t ram_slots =0 ;FILE *vmstate_dump_file =NULL ;
@@ -4175,97 +4284,8 @@ void qemu_init(int argc, char **argv, char **envp) machine_class->default_machine_opts, 0); } -qemu_opts_foreach (qemu_find_opts ("device" ), - default_driver_check,NULL ,NULL ); -qemu_opts_foreach (qemu_find_opts ("global" ), - default_driver_check,NULL ,NULL ); - -if (!vga_model && !default_vga) { - vga_interface_type =VGA_DEVICE ; - } -if (!has_defaults || machine_class->no_serial) { - default_serial =0 ; - } -if (!has_defaults || machine_class->no_parallel) { - default_parallel =0 ; - } -if (!has_defaults || machine_class->no_floppy) { - default_floppy =0 ; - } -if (!has_defaults || machine_class->no_cdrom) { - default_cdrom =0 ; - } -if (!has_defaults || machine_class->no_sdcard) { - default_sdcard =0 ; - } -if (!has_defaults) { - default_monitor =0 ; - default_net =0 ; - default_vga =0 ; - } - -if (is_daemonized ()) { -/* According to documentation and historically, -nographic redirects -* serial port, parallel port and monitor to stdio, which does not work -* with -daemonize. We can redirect these to null instead, but since -* -nographic is legacy, let's just error out. -* We disallow -nographic only if all other ports are not redirected -* explicitly, to not break existing legacy setups which uses -* -nographic _and_ redirects all ports explicitly - this is valid -* usage, -nographic is just a no-op in this case. -*/ -if (nographic - && (default_parallel || default_serial || default_monitor)) { -error_report ("-nographic cannot be used with -daemonize" ); -exit (1 ); - } - } - -if (nographic) { -if (default_parallel) -add_device_config (DEV_PARALLEL ,"null" ); -if (default_serial && default_monitor) { -add_device_config (DEV_SERIAL ,"mon:stdio" ); - }else { -if (default_serial) -add_device_config (DEV_SERIAL ,"stdio" ); -if (default_monitor) -monitor_parse ("stdio" ,"readline" , false); - } - }else { -if (default_serial) -add_device_config (DEV_SERIAL ,"vc:80Cx24C" ); -if (default_parallel) -add_device_config (DEV_PARALLEL ,"vc:80Cx24C" ); -if (default_monitor) -monitor_parse ("vc:80Cx24C" ,"readline" , false); - } - -if (default_net) { -QemuOptsList *net =qemu_find_opts ("net" ); -qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort); -#ifdef CONFIG_SLIRP -qemu_opts_set (net,NULL ,"type" ,"user" , &error_abort); -#endif - } - -#if defined(CONFIG_VNC ) -if (!QTAILQ_EMPTY (&(qemu_find_opts ("vnc" )->head))) { - display_remote++; - } -#endif -if (dpy.type ==DISPLAY_TYPE_DEFAULT && !display_remote) { -if (!qemu_display_find_default (&dpy)) { - dpy.type =DISPLAY_TYPE_NONE ; -#if defined(CONFIG_VNC ) -vnc_parse ("localhost:0,to=99,id=default" , &error_abort); -#endif - } - } -if (dpy.type ==DISPLAY_TYPE_DEFAULT ) { - dpy.type =DISPLAY_TYPE_NONE ; - } - +qemu_disable_default_devices (); +qemu_create_default_devices ();if ((alt_grab || ctrl_grab) && dpy.type !=DISPLAY_TYPE_SDL ) {error_report ("-alt-grab and -ctrl-grab are only valid " "for SDL, ignoring option" );
@@ -4404,14 +4424,6 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); -/* If no default VGA is requested, the default is "none". */ -if (default_vga) { - vga_model =get_default_vga_model (machine_class); - } -if (vga_model) { -select_vgahw (machine_class, vga_model); - } -/* This checkpoint is required by replay to separate prior clock reading from the other reads, because timer polling functions query clock values from the log. */
Signature · 1 line
2.26.2
PATCH 20/22 vl: move CHECKPOINT_INIT after preconfig
In reply to Paolo BonziniMove CHECKPOINT_INIT right before the machine initialization is completed. Everything before is essentially an extension of command line parsing.
--- softmmu/vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
softmmu/vl.c +5 -5
@@ -3194,6 +3194,11 @@ void qemu_finish_machine_init(void)exit (1 ); } +/* This checkpoint is required by replay to separate prior clock +reading from the other reads, because timer polling functions query +clock values from the log. */ +replay_checkpoint (CHECKPOINT_INIT ); +machine_run_board_init (current_machine);/*
@@ -4424,11 +4429,6 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); -/* This checkpoint is required by replay to separate prior clock -reading from the other reads, because timer polling functions query -clock values from the log. */ -replay_checkpoint (CHECKPOINT_INIT ); - current_machine->boot_order = boot_order;/* parse features once if machine provides default cpu_type */
Signature · 1 line
2.26.2
Re: [PATCH 20/22] vl: move CHECKPOINT_INIT after preconfig
Quoted 5 lines · Paolo Bonzini
Move
CHECKPOINT_INITright before the machine initialization is completed. Everything before is essentially an extension of command line parsing.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 33 lines
--- softmmu/vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)softmmu/vl.c +5
-5@@ -3194,6 +3194,11 @@ void qemu_finish_machine_init(void)exit (1 ); } +/* This checkpoint is required by replay to separate prior clock +reading from the other reads, because timer polling functions query +clock values from the log. */ +replay_checkpoint (CHECKPOINT_INIT ); +machine_run_board_init (current_machine);/* @@ -4424,11 +4429,6 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); -/* This checkpoint is required by replay to separate prior clock -reading from the other reads, because timer polling functions query -clock values from the log. */ -replay_checkpoint (CHECKPOINT_INIT ); - current_machine->boot_order = boot_order;/* parse features once if machine provides default cpu_type */
PATCH 21/22 vl: separate qemu_create_early_backends
In reply to Paolo Bonzini"Early" backends are created before the machine and can be used as machine options.
--- softmmu/vl.c | 123 +++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 58 deletions(-)
softmmu/vl.c +65 -58
@@ -117,6 +117,14 @@#define MAX_VIRTIO_CONSOLES 1 +typedef struct BlockdevOptionsQueueEntry { +BlockdevOptions *bdo; +Location loc; +QSIMPLEQ_ENTRY (BlockdevOptionsQueueEntry) entry; +}BlockdevOptionsQueueEntry ; + +typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; +static const char *cpu_option;static const char *data_dir[16 ];static int data_dir_idx;
@@ -126,7 +134,9 @@ static const char *boot_once;static const char *incoming;static const char *loadvm;static int display_remote; +static int snapshot;static QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list); +static BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);static bool nographic = false;enum vga_retrace_method vga_retrace_method =VGA_RETRACE_DUMB ;int mem_prealloc;/* force preallocation of physical target memory */
@@ -1043,14 +1053,6 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type, } -typedef struct BlockdevOptionsQueueEntry { -BlockdevOptions *bdo; -Location loc; -QSIMPLEQ_ENTRY (BlockdevOptionsQueueEntry) entry; -}BlockdevOptionsQueueEntry ; - -typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; -static void configure_blockdev (BlockdevOptionsQueue *bdo_queue,MachineClass *machine_class,int snapshot) {
@@ -2640,7 +2642,7 @@ static int machine_set_property(void *opaque,* cannot be created here, as it depends on the chardev * already existing. */ -static bool object_create_initial (const char *type,QemuOpts *opts) +static bool object_create_early (const char *type,QemuOpts *opts) {if (user_creatable_print_help (type, opts)) {exit (0 );
@@ -2692,6 +2694,58 @@ static bool object_create_initial(const char *type, QemuOpts *opts)return true; } +static void qemu_create_early_backends (void ) +{ +MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); + +if ((alt_grab || ctrl_grab) && dpy.type !=DISPLAY_TYPE_SDL ) { +error_report ("-alt-grab and -ctrl-grab are only valid " +"for SDL, ignoring option" ); + } +if (dpy.has_window_close && + (dpy.type !=DISPLAY_TYPE_GTK && dpy.type !=DISPLAY_TYPE_SDL )) { +error_report ("-no-quit is only valid for GTK and SDL, " +"ignoring option" ); + } + +qemu_display_early_init (&dpy); +qemu_console_early_init (); + +if (dpy.has_gl && dpy.gl !=DISPLAYGL_MODE_OFF && display_opengl ==0 ) { +#if defined(CONFIG_OPENGL ) +error_report ("OpenGL is not supported by the display" ); +#else +error_report ("OpenGL support is disabled" ); +#endif +exit (1 ); + } + +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_early, &error_fatal); + +/* spice needs the timers to be initialized by this point */ +/* spice must initialize before audio as it changes the default auiodev */ +/* spice must initialize before chardevs (for spicevmc and spiceport) */ +qemu_spice_init (); + +qemu_opts_foreach (qemu_find_opts ("chardev" ), + chardev_init_func,NULL , &error_fatal); + +#ifdef CONFIG_VIRTFS +qemu_opts_foreach (qemu_find_opts ("fsdev" ), + fsdev_init_func,NULL , &error_fatal); +#endif + +/* +* Note: we need to create audio and block backends before +* machine_set_property(), so machine properties can refer to +* them. +*/ +configure_blockdev (&bdo_queue, machine_class, snapshot); +audio_init_audiodevs (); +} +/* * The remainder of object creation happens after the
@@ -2699,7 +2753,7 @@ static bool object_create_initial(const char *type, QemuOpts *opts)*/ static bool object_create_delayed (const char *type,QemuOpts *opts) { -return !object_create_initial (type, opts); +return !object_create_early (type, opts); }
@@ -3308,7 +3362,6 @@ void qemu_finish_machine_init(void)void qemu_init (int argc,char **argv,char **envp) { -int snapshot =0 ;QemuOpts *opts, *machine_opts;QemuOpts *icount_opts =NULL , *accel_opts =NULL ;QemuOptsList *olist;
@@ -3321,7 +3374,6 @@ void qemu_init(int argc, char **argv, char **envp)FILE *vmstate_dump_file =NULL ;Error *err =NULL ;bool have_custom_ram_size; -BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);
@@ -4291,52 +4343,7 @@ void qemu_init(int argc, char **argv, char **envp)qemu_disable_default_devices ();qemu_create_default_devices (); -if ((alt_grab || ctrl_grab) && dpy.type !=DISPLAY_TYPE_SDL ) { -error_report ("-alt-grab and -ctrl-grab are only valid " -"for SDL, ignoring option" ); - } -if (dpy.has_window_close && - (dpy.type !=DISPLAY_TYPE_GTK && dpy.type !=DISPLAY_TYPE_SDL )) { -error_report ("-no-quit is only valid for GTK and SDL, " -"ignoring option" ); - } - -qemu_display_early_init (&dpy); -qemu_console_early_init (); - -if (dpy.has_gl && dpy.gl !=DISPLAYGL_MODE_OFF && display_opengl ==0 ) { -#if defined(CONFIG_OPENGL ) -error_report ("OpenGL is not supported by the display" ); -#else -error_report ("OpenGL support is disabled" ); -#endif -exit (1 ); - } - -qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_initial, &error_fatal); - -/* spice needs the timers to be initialized by this point */ -/* spice must initialize before audio as it changes the default auiodev */ -/* spice must initialize before chardevs (for spicevmc and spiceport) */ -qemu_spice_init (); - -qemu_opts_foreach (qemu_find_opts ("chardev" ), - chardev_init_func,NULL , &error_fatal); - -#ifdef CONFIG_VIRTFS -qemu_opts_foreach (qemu_find_opts ("fsdev" ), - fsdev_init_func,NULL , &error_fatal); -#endif - -/* -* Note: we need to create audio and block backends before -* machine_set_property(), so machine properties can refer to -* them. -*/ -configure_blockdev (&bdo_queue, machine_class, snapshot); -audio_init_audiodevs (); +qemu_create_early_backends (); machine_opts =qemu_get_machine_opts (); qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
Signature · 1 line
2.26.2
PATCH 22/22 vl: separate qemu_create_late_backends
In reply to Paolo Bonzini"Late" backends are created after the machine.
--- softmmu/vl.c | 64 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-)
softmmu/vl.c +32 -32
@@ -2751,11 +2751,41 @@ static void qemu_create_early_backends(void)* The remainder of object creation happens after the * creation of chardev, fsdev, net clients and device data types. */ -static bool object_create_delayed (const char *type,QemuOpts *opts) +static bool object_create_late (const char *type,QemuOpts *opts) {return !object_create_early (type, opts); } +static void qemu_create_late_backends (void ) +{ +if (qtest_chrdev) { +qtest_server_init (qtest_chrdev, qtest_log, &error_fatal); + } + +net_init_clients (&error_fatal); + +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_late, &error_fatal); + +if (tpm_init () <0 ) { +exit (1 ); + } + +qemu_opts_foreach (qemu_find_opts ("mon" ), + mon_init_func,NULL , &error_fatal); + +/* now chardevs have been created we may have semihosting to connect */ +qemu_semihosting_connect_chardevs (); +qemu_semihosting_console_init (); + +if (foreach_device_config (DEV_SERIAL , serial_parse) <0 ) +exit (1 ); +if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 ) +exit (1 ); +if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 ) +exit (1 ); +}static bool set_memory_options (uint64_t *ram_slots,ram_addr_t *maxram_size,MachineClass *mc)
@@ -3372,7 +3402,6 @@ void qemu_init(int argc, char **argv, char **envp)ram_addr_t maxram_size;uint64_t ram_slots =0 ;FILE *vmstate_dump_file =NULL ; -Error *err =NULL ;bool have_custom_ram_size;qemu_add_opts (&qemu_drive_opts);
@@ -4385,10 +4414,6 @@ void qemu_init(int argc, char **argv, char **envp)*/ migration_object_init (); -if (qtest_chrdev) { -qtest_server_init (qtest_chrdev, qtest_log, &error_fatal); - } - opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL );if (opts) { boot_order =qemu_opt_get (opts,"order" );
@@ -4409,32 +4434,7 @@ void qemu_init(int argc, char **argv, char **envp) boot_order = machine_class->default_boot_order; } -if (net_init_clients (&err) <0 ) { -error_report_err (err); -exit (1 ); - } - -qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_delayed, &error_fatal); - -if (tpm_init () <0 ) { -exit (1 ); - } - -qemu_opts_foreach (qemu_find_opts ("mon" ), - mon_init_func,NULL , &error_fatal); - -/* now chardevs have been created we may have semihosting to connect */ -qemu_semihosting_connect_chardevs (); -qemu_semihosting_console_init (); - -if (foreach_device_config (DEV_SERIAL , serial_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 ) -exit (1 ); +qemu_create_late_backends (); current_machine->boot_order = boot_order;
Signature · 1 line
2.26.2