From: Igor Mammedov <imammedo@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 03/36] vl: split various early command line options to a separate function
Date: Thu, 26 Nov 2020 17:47:30 +0100 [thread overview]
Message-ID: <20201126174730.51d11148@redhat.com> (raw)
In-Reply-To: <20201123141435.2726558-4-pbonzini@redhat.com>
On Mon, 23 Nov 2020 09:14:02 -0500
Paolo Bonzini <pbonzini@redhat.com> wrote:
> Various 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.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> softmmu/vl.c | 200 ++++++++++++++++++++++++++++-----------------------
> 1 file changed, 112 insertions(+), 88 deletions(-)
>
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index c45a99a2bf..07378301d5 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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;
> enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
> @@ -142,6 +143,9 @@ int vga_interface_type = VGA_NONE;
> static DisplayOptions dpy;
> static int num_serial_hds;
> static Chardev **serial_hds;
> +static const char *log_mask;
> +static const char *log_file;
> +static bool list_data_dirs;
> Chardev *parallel_hds[MAX_PARALLEL_PORTS];
> int win2k_install_hack = 0;
> int singlestep = 0;
> @@ -2862,6 +2866,105 @@ 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;
> @@ -2878,21 +2981,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);
> @@ -3842,19 +3940,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();
> @@ -3875,40 +3971,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);
> @@ -3934,44 +3996,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);
>
next prev parent reply other threads:[~2020-11-26 16:48 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-23 14:13 [PATCH v3 00/36] cleanup qemu_init and make sense of command line processing Paolo Bonzini
2020-11-23 14:14 ` [PATCH 01/36] vl: extract validation of -smp to machine.c Paolo Bonzini
2020-11-23 14:14 ` [PATCH 02/36] vl: remove bogus check Paolo Bonzini
2020-11-23 14:14 ` [PATCH 03/36] vl: split various early command line options to a separate function Paolo Bonzini
2020-11-26 16:47 ` Igor Mammedov [this message]
2020-11-23 14:14 ` [PATCH 04/36] vl: move various initialization routines out of qemu_init Paolo Bonzini
2020-11-23 14:14 ` [PATCH 05/36] vl: extract qemu_init_subsystems Paolo Bonzini
2020-11-23 14:14 ` [PATCH 06/36] vl: move prelaunch part of qemu_init to new functions Paolo Bonzini
2020-11-23 14:14 ` [PATCH 07/36] vl: extract various command line validation snippets to a new function Paolo Bonzini
2020-11-23 14:14 ` [PATCH 08/36] vl: preconfig and loadvm are mutually exclusive Paolo Bonzini
2020-11-23 14:14 ` [PATCH 09/36] vl: extract various command line desugaring snippets to a new function Paolo Bonzini
2020-11-23 14:14 ` [PATCH 10/36] qemu-option: restrict qemu_opts_set to merge-lists QemuOpts Paolo Bonzini
2020-11-23 14:14 ` [PATCH 11/36] vl: create "-net nic -net user" default earlier Paolo Bonzini
2020-11-23 14:14 ` [PATCH 12/36] vl: load plugins as late as possible Paolo Bonzini
2020-11-26 16:54 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 13/36] vl: move semihosting command line fallback to qemu_init_board Paolo Bonzini
2020-11-26 17:10 ` Igor Mammedov
2020-11-27 5:03 ` Paolo Bonzini
2020-11-27 10:31 ` Igor Mammedov
2020-11-27 11:22 ` Paolo Bonzini
2020-11-27 12:12 ` Igor Mammedov
2020-11-27 12:22 ` Paolo Bonzini
2020-11-23 14:14 ` [PATCH 14/36] vl: extract default devices to separate functions Paolo Bonzini
2020-11-26 17:29 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 15/36] vl: move CHECKPOINT_INIT after preconfig Paolo Bonzini
2020-11-26 17:36 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 16/36] vl: separate qemu_create_early_backends Paolo Bonzini
2020-11-23 14:14 ` [PATCH 17/36] vl: separate qemu_create_late_backends Paolo Bonzini
2020-11-23 14:14 ` [PATCH 18/36] vl: separate qemu_create_machine Paolo Bonzini
2020-11-23 14:14 ` [PATCH 19/36] vl: separate qemu_apply_machine_options Paolo Bonzini
2020-11-23 14:14 ` [PATCH 20/36] vl: separate qemu_resolve_machine_memdev Paolo Bonzini
2020-11-26 17:39 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 21/36] vl: initialize displays before preconfig loop Paolo Bonzini
2020-11-26 17:51 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 22/36] vl: move -global check earlier Paolo Bonzini
2020-11-26 17:55 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 23/36] migration, vl: start migration via qmp_migrate_incoming Paolo Bonzini
2020-11-26 18:04 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 24/36] vl: start VM via qmp_cont Paolo Bonzini
2020-11-23 14:14 ` [PATCH 25/36] hmp: introduce cmd_available Paolo Bonzini
2020-11-23 14:14 ` [PATCH 26/36] remove preconfig state Paolo Bonzini
2020-11-26 18:55 ` Igor Mammedov
2020-11-27 5:19 ` Paolo Bonzini
2020-11-27 10:50 ` Igor Mammedov
2020-11-27 11:50 ` Paolo Bonzini
2020-11-30 12:41 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 27/36] vl: remove separate preconfig main_loop Paolo Bonzini
2020-11-30 12:46 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 28/36] vl: allow -incoming defer with -preconfig Paolo Bonzini
2020-11-27 10:51 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 29/36] vl: extract softmmu/datadir.c Paolo Bonzini
2020-11-27 12:06 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 30/36] vl: extract machine done notifiers Paolo Bonzini
2020-11-27 12:14 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 31/36] vl: extract softmmu/rtc.c Paolo Bonzini
2020-11-27 12:43 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 32/36] vl: extract softmmu/runstate.c Paolo Bonzini
2020-11-27 12:59 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 33/36] vl: extract softmmu/globals.c Paolo Bonzini
2020-11-27 13:19 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 34/36] vl: remove serial_max_hds Paolo Bonzini
2020-11-27 13:11 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 35/36] vl: clean up -boot variables Paolo Bonzini
2020-11-27 13:12 ` Igor Mammedov
2020-11-23 14:14 ` [PATCH 36/36] vl: move all generic initialization out of vl.c Paolo Bonzini
2020-11-27 13:30 ` Igor Mammedov
2020-11-27 12:00 ` [PATCH 37/36] machine: introduce MachineInitPhase Paolo Bonzini
2020-11-27 13:29 ` Igor Mammedov
2020-11-27 15:29 ` Paolo Bonzini
2020-11-30 12:50 ` [PATCH v3 00/36] cleanup qemu_init and make sense of command line processing Igor Mammedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201126174730.51d11148@redhat.com \
--to=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).