All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
@ 2020-10-27 18:21 Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 01/29] trace: remove argument from trace_init_file Paolo Bonzini
                   ` (29 more replies)
  0 siblings, 30 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

The main improvements with respect to v1 are:

- further extraction of various phases of command line processing and VM
  creation to separate function;

- removing the preconfig main_loop: the VM is effectively always starting
  as if -preconfig was specified, it just executes automatically if not
  requested.  This enables "-incoming defer" to be specified together
  with "-preconfig".

I have other patches with which I could configure the VM like

  $ qemu -vnc :0 -monitor stdio -preconfig
    ... in theory blockdev-add and other backend creation would go here...
  (qemu) x-create-onboard-devices
  (qemu) device_add virtio-mouse-pci
  (qemu) cont

Here, x-create-onboard-devices creates enough of the machine to make
it possible to issue device_add monitor commands equivalent to
the -device command line.

However, I'm not posting that part because the above is not the
final state of the QMP interface.  The final QMP interface would have
three commands (machine-set, accel-set, machine-set-memory) that
bring the VM through successive phases of initialization corresponding
roughly to qemu_apply_machine_options (-smp, -boot, -M, -cpu?),
configure_accelerators (-accel) and qemu_finish_machine_init (-m, -M memdev);
after these three steps, one of migrate-incoming, cont, loadvm or
finish-machine-init (the latter of which is equivalent to -S on the
command line) leaves preconfig mode.  For more information see
https://wiki.qemu.org/User:Paolo_Bonzini/Machine_init_sequence#Basic_phases.

Based-on: <20201026143028.3034018-1-pbonzini@redhat.com>

Paolo Bonzini (29):
  trace: remove argument from trace_init_file
  semihosting: fix order of initialization functions
  vl: extract validation of -smp to machine.c
  vl: remove bogus check
  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 new functions
  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
  vl: separate qemu_create_machine
  vl: separate qemu_apply_machine_options
  vl: separate qemu_resolve_machine_memdev
  vl: initialize displays before preconfig loop
  vl: move -global check earlier
  migration, vl: start migration via qmp_migrate_incoming
  vl: start VM via qmp_cont
  hmp: introduce cmd_available
  remove preconfig state
  vl: remove separate preconfig main_loop
  vl: allow -incoming defer with -preconfig

 bsd-user/main.c                      |    6 +-
 hw/core/machine-qmp-cmds.c           |    5 +-
 hw/core/machine.c                    |   27 +
 include/hw/boards.h                  |    1 +
 include/hw/qdev-core.h               |    8 -
 include/migration/misc.h             |    1 -
 include/qapi/qmp/dispatch.h          |    1 +
 include/sysemu/runstate.h            |    1 -
 linux-user/main.c                    |    6 +-
 migration/migration.c                |   37 +-
 monitor/hmp.c                        |   23 +-
 monitor/qmp-cmds.c                   |   10 -
 qapi/qmp-dispatch.c                  |    5 +-
 qapi/run-state.json                  |    5 +-
 qemu-img.c                           |    6 +-
 qemu-io.c                            |    6 +-
 qemu-nbd.c                           |    6 +-
 scsi/qemu-pr-helper.c                |    6 +-
 softmmu/qdev-monitor.c               |   18 +-
 softmmu/vl.c                         | 1796 +++++++++++++-------------
 storage-daemon/qemu-storage-daemon.c |    9 +-
 stubs/meson.build                    |    1 +
 stubs/qmp-command-available.c        |    7 +
 trace/control.c                      |   10 +-
 trace/control.h                      |   12 +-
 25 files changed, 1021 insertions(+), 992 deletions(-)
 create mode 100644 stubs/qmp-command-available.c

-- 
2.26.2



^ permalink raw reply	[flat|nested] 78+ messages in thread

* [PATCH 01/29] trace: remove argument from trace_init_file
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 02/29] semihosting: fix order of initialization functions Paolo Bonzini
                   ` (28 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

It is not needed, all the callers are just saving what was
retrieved from -trace and trace_init_file can retrieve it
on its own.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index ac40d79bfa..0a918e8f74 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -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));
diff --git a/linux-user/main.c b/linux-user/main.c
index 75c9785157..24d1eb73ad 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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);
     }
diff --git a/qemu-img.c b/qemu-img.c
index 2103507936..ccfdf1f48d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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 */
diff --git a/qemu-io.c b/qemu-io.c
index 7cc832b3d6..ac88d8bd40 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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 */
diff --git a/qemu-nbd.c b/qemu-nbd.c
index a0701cdf36..e2ae822012 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -578,7 +578,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;
@@ -762,8 +761,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;
@@ -810,7 +808,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();
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index d26faaf91e..2733d92f2d 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -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
diff --git a/softmmu/vl.c b/softmmu/vl.c
index d5a21ebcf4..d39d914dd0 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2886,7 +2886,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;
@@ -3687,8 +3686,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);
@@ -3938,7 +3936,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.
      */
diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c
index e419ba9f19..7c914b0dc1 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -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");
diff --git a/trace/control.c b/trace/control.c
index b35e512dce..7a57fa7dd5 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -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)
diff --git a/trace/control.h b/trace/control.h
index 1f81c491b6..05b95ea453 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -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:
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 02/29] semihosting: fix order of initialization functions
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 01/29] trace: remove argument from trace_init_file Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 03/29] vl: extract validation of -smp to machine.c Paolo Bonzini
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée

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.

Both have to be called after processing -serial and friends though, so
that the semihosting console can connect to a multiplexer as in
"-serial mon:stdio -semihosting-config chardev=serial0"

Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Fixes: 619985e937 ("semihosting: defer connect_chardevs a little more to use serialx", 2020-07-27)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index d39d914dd0..b0ccfd750a 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4280,9 +4280,6 @@ 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 */
-    qemu_semihosting_console_init();
-
     if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
         exit(1);
     if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
@@ -4292,6 +4289,7 @@ void qemu_init(int argc, char **argv, char **envp)
 
     /* now chardevs have been created we may have semihosting to connect */
     qemu_semihosting_connect_chardevs();
+    qemu_semihosting_console_init();
 
     /* If no default VGA is requested, the default is "none".  */
     if (default_vga) {
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 03/29] vl: extract validation of -smp to machine.c
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 01/29] trace: remove argument from trace_init_file Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 02/29] semihosting: fix order of initialization functions Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-28 16:32   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 04/29] vl: remove bogus check Paolo Bonzini
                   ` (26 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Once smp_parse is done, the validation operates on the MachineState.
There is no reason for that code to be in vl.c.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/core/machine.c   | 23 +++++++++++++++++++++++
 include/hw/boards.h |  1 +
 softmmu/vl.c        | 20 ++------------------
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index c5e0e79e6d..baea4e8613 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1072,6 +1072,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);
diff --git a/include/hw/boards.h b/include/hw/boards.h
index a49e3a6b44..4537cfb5c6 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index b0ccfd750a..7f39ebdfee 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3971,24 +3971,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;
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 04/29] vl: remove bogus check
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (2 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 03/29] vl: extract validation of -smp to machine.c Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-28 16:48   ` Igor Mammedov
  2020-10-28 19:32   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 05/29] vl: split various early command line options to a separate function Paolo Bonzini
                   ` (25 subsequent siblings)
  29 siblings, 2 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

There 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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 7f39ebdfee..dbb72e621e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4027,12 +4027,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
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 05/29] vl: split various early command line options to a separate function
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (3 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 04/29] vl: remove bogus check Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-02 15:30   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 06/29] vl: move various initialization routines out of qemu_init Paolo Bonzini
                   ` (24 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

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>
---
 softmmu/vl.c | 202 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 113 insertions(+), 89 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index dbb72e621e..32880616e2 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 = 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;
@@ -2862,6 +2866,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;
@@ -2878,21 +2982,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);
@@ -3840,20 +3939,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();
@@ -3874,40 +3970,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);
@@ -3933,44 +3995,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);
 
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 06/29] vl: move various initialization routines out of qemu_init
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (4 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 05/29] vl: split various early command line options to a separate function Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-02 15:40   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 07/29] vl: extract qemu_init_subsystems Paolo Bonzini
                   ` (23 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Some very simple initialization routines can be nested in existing
subsystem-level functions, do that to simplify qemu_init.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index baea4e8613..d84b84463c 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -872,6 +872,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;
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 868973319e..56ce7f2d7f 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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:
  *
diff --git a/migration/migration.c b/migration/migration.c
index deb6005b8d..f48b03cac2 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -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)
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index bcfb90a08f..bcfcbac181 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -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",
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 32880616e2..b05340802a 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4275,10 +4275,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);
 
@@ -4311,7 +4307,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;
 
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 07/29] vl: extract qemu_init_subsystems
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (5 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 06/29] vl: move various initialization routines out of qemu_init Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-02 15:55   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions Paolo Bonzini
                   ` (22 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Group 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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 94 ++++++++++++++++++++++++----------------------------
 1 file changed, 43 insertions(+), 51 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index b05340802a..a086cd7066 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -128,7 +128,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,
@@ -1228,7 +1228,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:
@@ -2965,11 +2966,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;
@@ -2990,7 +3025,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;
@@ -2998,22 +3032,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);
@@ -3048,27 +3066,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;
@@ -3947,13 +3948,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) {
@@ -4132,9 +4130,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);
@@ -4251,9 +4246,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);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (6 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 07/29] vl: extract qemu_init_subsystems Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-11 19:29   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 09/29] vl: extract various command line validation snippets to a new function Paolo Bonzini
                   ` (21 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

The 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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 250 +++++++++++++++++++++++++++------------------------
 1 file changed, 135 insertions(+), 115 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index a086cd7066..f9bae50c27 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -120,6 +120,9 @@
 static const char *cpu_option;
 static const char *data_dir[16];
 static int data_dir_idx;
+static const char *mem_path;
+static const char *boot_order;
+static const char *boot_once;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 int display_opengl;
 const char* keyboard_layout = NULL;
@@ -3000,6 +3003,135 @@ static void qemu_init_subsystems(void)
     socket_init();
 }
 
+/*
+ * Called after leaving preconfig state.  From here on runstate is
+ * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE.
+ */
+static void qemu_finish_machine_init(void)
+{
+    MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
+
+    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 */
+    machine_run_board_init(current_machine);
+
+    /*
+     * TODO To drop support for deprecated bogus if=..., move
+     * drive_check_orphaned() here, replacing this call.  Also drop
+     * its deprecation warning, along with DriveInfo member
+     * @claimed_by_board.
+     */
+    drive_mark_claimed_by_board();
+
+    realtime_init();
+
+    if (hax_enabled()) {
+        /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
+        hax_sync_vcpus();
+    }
+}
+
+static void qemu_create_cli_devices(void)
+{
+    soundhw_init();
+
+    qemu_opts_foreach(qemu_find_opts("fw_cfg"),
+                      parse_fw_cfg, fw_cfg_find(), &error_fatal);
+
+    /* init USB devices */
+    if (machine_usb(current_machine)) {
+        if (foreach_device_config(DEV_USB, usb_parse) < 0)
+            exit(1);
+    }
+
+    /* init generic devices */
+    rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
+    qemu_opts_foreach(qemu_find_opts("device"),
+                      device_init_func, NULL, &error_fatal);
+    rom_reset_order_override();
+}
+
+static void qemu_machine_creation_done(void)
+{
+    DisplayState *ds;
+
+    cpu_synchronize_all_post_init();
+
+    /* Did we create any drives that we failed to create a device for? */
+    drive_check_orphaned();
+
+    /* Don't warn about the default network setup that you get if
+     * no command line -net or -netdev options are specified. There
+     * are two cases that we would otherwise complain about:
+     * (1) board doesn't support a NIC but the implicit "-net nic"
+     * requested one
+     * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
+     * sets up a nic that isn't connected to anything.
+     */
+    if (!default_net && (!qtest_enabled() || has_defaults)) {
+        net_check_clients();
+    }
+
+    if (boot_once) {
+        qemu_boot_set(boot_once, &error_fatal);
+        qemu_register_reset(restore_boot_order, g_strdup(boot_order));
+    }
+
+    /* init local displays */
+    ds = init_displaystate();
+    qemu_display_init(ds, &dpy);
+
+    /* must be after terminal init, SDL library changes signal handlers */
+    os_setup_signal_handling();
+
+    /* init remote displays */
+#ifdef CONFIG_VNC
+    qemu_opts_foreach(qemu_find_opts("vnc"),
+                      vnc_init_func, NULL, &error_fatal);
+#endif
+
+    if (using_spice) {
+        qemu_spice.display_init();
+    }
+
+    if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
+        exit(1);
+    }
+
+    qdev_machine_creation_done();
+
+    /* TODO: once all bus devices are qdevified, this should be done
+     * when bus is created by qdev.c */
+    /*
+     * TODO: If we had a main 'reset container' that the whole system
+     * lived in, we could reset that using the multi-phase reset
+     * APIs. For the moment, we just reset the sysbus, which will cause
+     * all devices hanging off it (and all their child buses, recursively)
+     * to be reset. Note that this will *not* reset any Device objects
+     * which are not attached to some part of the qbus tree!
+     */
+    qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
+    qemu_run_machine_init_done_notifiers();
+
+    if (rom_check_and_register_reset() != 0) {
+        error_report("rom check and register reset failed");
+        exit(1);
+    }
+
+    replay_start();
+
+    /* 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_RESET);
+    qemu_system_reset(SHUTDOWN_CAUSE_NONE);
+    register_global_state();
+}
+
 void qemu_init(int argc, char **argv, char **envp)
 {
     int i;
@@ -3007,9 +3139,6 @@ void qemu_init(int argc, char **argv, char **envp)
     int linux_boot;
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
-    const char *boot_order = NULL;
-    const char *boot_once = NULL;
-    DisplayState *ds;
     QemuOpts *opts, *machine_opts;
     QemuOpts *icount_opts = NULL, *accel_opts = NULL;
     QemuOptsList *olist;
@@ -3026,7 +3155,6 @@ void qemu_init(int argc, char **argv, char **envp)
     uint64_t ram_slots = 0;
     FILE *vmstate_dump_file = NULL;
     Error *err = NULL;
-    const char *mem_path = NULL;
     bool have_custom_ram_size;
     BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
     QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
@@ -4346,117 +4474,10 @@ void qemu_init(int argc, char **argv, char **envp)
     /* do monitor/qmp handling at preconfig state if requested */
     qemu_main_loop();
 
-    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 */
-    machine_run_board_init(current_machine);
-
-    /*
-     * TODO To drop support for deprecated bogus if=..., move
-     * drive_check_orphaned() here, replacing this call.  Also drop
-     * its deprecation warning, along with DriveInfo member
-     * @claimed_by_board.
-     */
-    drive_mark_claimed_by_board();
-
-    realtime_init();
+    qemu_finish_machine_init();
+    qemu_create_cli_devices();
+    qemu_machine_creation_done();
 
-    soundhw_init();
-
-    if (hax_enabled()) {
-        hax_sync_vcpus();
-    }
-
-    qemu_opts_foreach(qemu_find_opts("fw_cfg"),
-                      parse_fw_cfg, fw_cfg_find(), &error_fatal);
-
-    /* init USB devices */
-    if (machine_usb(current_machine)) {
-        if (foreach_device_config(DEV_USB, usb_parse) < 0)
-            exit(1);
-    }
-
-    /* init generic devices */
-    rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
-    qemu_opts_foreach(qemu_find_opts("device"),
-                      device_init_func, NULL, &error_fatal);
-
-    cpu_synchronize_all_post_init();
-
-    rom_reset_order_override();
-
-    /* Did we create any drives that we failed to create a device for? */
-    drive_check_orphaned();
-
-    /* Don't warn about the default network setup that you get if
-     * no command line -net or -netdev options are specified. There
-     * are two cases that we would otherwise complain about:
-     * (1) board doesn't support a NIC but the implicit "-net nic"
-     * requested one
-     * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
-     * sets up a nic that isn't connected to anything.
-     */
-    if (!default_net && (!qtest_enabled() || has_defaults)) {
-        net_check_clients();
-    }
-
-    if (boot_once) {
-        qemu_boot_set(boot_once, &error_fatal);
-        qemu_register_reset(restore_boot_order, g_strdup(boot_order));
-    }
-
-    /* init local displays */
-    ds = init_displaystate();
-    qemu_display_init(ds, &dpy);
-
-    /* must be after terminal init, SDL library changes signal handlers */
-    os_setup_signal_handling();
-
-    /* init remote displays */
-#ifdef CONFIG_VNC
-    qemu_opts_foreach(qemu_find_opts("vnc"),
-                      vnc_init_func, NULL, &error_fatal);
-#endif
-
-    if (using_spice) {
-        qemu_spice.display_init();
-    }
-
-    if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
-        exit(1);
-    }
-
-    qdev_machine_creation_done();
-
-    /* TODO: once all bus devices are qdevified, this should be done
-     * when bus is created by qdev.c */
-    /*
-     * TODO: If we had a main 'reset container' that the whole system
-     * lived in, we could reset that using the multi-phase reset
-     * APIs. For the moment, we just reset the sysbus, which will cause
-     * all devices hanging off it (and all their child buses, recursively)
-     * to be reset. Note that this will *not* reset any Device objects
-     * which are not attached to some part of the qbus tree!
-     */
-    qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
-    qemu_run_machine_init_done_notifiers();
-
-    if (rom_check_and_register_reset() != 0) {
-        error_report("rom check and register reset failed");
-        exit(1);
-    }
-
-    replay_start();
-
-    /* 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_RESET);
-    qemu_system_reset(SHUTDOWN_CAUSE_NONE);
-    register_global_state();
     if (loadvm) {
         Error *local_err = NULL;
         if (load_snapshot(loadvm, &local_err) < 0) {
@@ -4475,7 +4496,6 @@ void qemu_init(int argc, char **argv, char **envp)
         dump_vmstate_json_to_file(vmstate_dump_file);
         exit(0);
     }
-
     if (incoming) {
         Error *local_err = NULL;
         qemu_start_incoming_migration(incoming, &local_err);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 09/29] vl: extract various command line validation snippets to a new function
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (7 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-11 19:39   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive Paolo Bonzini
                   ` (20 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/core/machine.c |  1 +
 softmmu/vl.c      | 78 +++++++++++++++++++++++------------------------
 2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index d84b84463c..f5e559c493 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -878,6 +878,7 @@ static void machine_initfn(Object *obj)
     ms->dump_guest_core = true;
     ms->mem_merge = true;
     ms->enable_graphics = true;
+    ms->kernel_cmdline = g_strdup("");
 
     if (mc->nvdimm_supported) {
         Object *obj = OBJECT(ms);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index f9bae50c27..3316c5534c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
@@ -2870,6 +2871,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;
@@ -3136,9 +3170,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;
@@ -3147,7 +3178,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;
@@ -4068,6 +4098,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.
      */
@@ -4082,12 +4114,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();
@@ -4191,12 +4217,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) {
@@ -4327,11 +4347,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");
@@ -4352,24 +4367,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);
     }
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (8 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 09/29] vl: extract various command line validation snippets to a new function Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-11 19:58   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 11/29] vl: extract various command line desugaring snippets to a new function Paolo Bonzini
                   ` (19 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Just like -incoming.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 3316c5534c..c2a5ee61f9 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
@@ -2890,6 +2891,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");
@@ -3175,7 +3181,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;
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 11/29] vl: extract various command line desugaring snippets to a new function
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (9 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-11 19:57   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 12/29] vl: create "-net nic -net user" default earlier Paolo Bonzini
                   ` (18 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index c2a5ee61f9..6749109b29 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
@@ -2910,6 +2911,25 @@ static void qemu_validate_options(void)
 #endif
 }
 
+static void qemu_process_sugar_options(void)
+{
+    if (mem_prealloc) {
+        char *val;
+
+        val = g_strdup_printf("%d",
+                 (uint32_t) 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;
@@ -3174,7 +3194,6 @@ static void qemu_machine_creation_done(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;
@@ -3193,7 +3212,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);
@@ -4104,6 +4122,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.
@@ -4155,15 +4174,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.
@@ -4422,12 +4432,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. */
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 12/29] vl: create "-net nic -net user" default earlier
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (10 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 11/29] vl: extract various command line desugaring snippets to a new function Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-18 14:43   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 13/29] vl: load plugins as late as possible Paolo Bonzini
                   ` (17 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Create it together with other default backends, even though the processing is
done later.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 6749109b29..f643333f7e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4254,6 +4254,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++;
@@ -4389,14 +4397,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);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 13/29] vl: load plugins as late as possible
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (11 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 12/29] vl: create "-net nic -net user" default earlier Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 14/29] vl: move semihosting command line fallback to qemu_finish_machine_init Paolo Bonzini
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé

There is no need to load plugins in the middle of default device processing,
move -plugin handling just before preconfig is entered.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index f643333f7e..53d53ef206 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
@@ -3076,7 +3077,11 @@ static void qemu_finish_machine_init(void)
         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);
 
     /*
@@ -3211,7 +3216,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);
@@ -4183,11 +4187,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"),
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 14/29] vl: move semihosting command line fallback to qemu_finish_machine_init
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (12 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 13/29] vl: load plugins as late as possible Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 15/29] vl: extract default devices to separate functions Paolo Bonzini
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Move more sane parts of the huge qemu_init function out of it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 53d53ef206..bc85318b23 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3072,6 +3072,11 @@ static void qemu_finish_machine_init(void)
 {
     MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
 
+    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);
@@ -4389,13 +4394,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);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 15/29] vl: extract default devices to separate functions
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (13 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 14/29] vl: move semihosting command line fallback to qemu_finish_machine_init Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 16/29] vl: move CHECKPOINT_INIT after preconfig Paolo Bonzini
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 216 +++++++++++++++++++++++++++------------------------
 1 file changed, 114 insertions(+), 102 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index bc85318b23..b627b3138b 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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 with
                                              RTC_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;
@@ -3211,10 +3323,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;
@@ -4192,97 +4301,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");
@@ -4421,14 +4441,6 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_semihosting_connect_chardevs();
     qemu_semihosting_console_init();
 
-    /* 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. */
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 16/29] vl: move CHECKPOINT_INIT after preconfig
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (14 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 15/29] vl: extract default devices to separate functions Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-10-27 18:21 ` [PATCH 17/29] vl: separate qemu_create_early_backends Paolo Bonzini
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé

Move CHECKPOINT_INIT right before the machine initialization is
completed.  Everything before is essentially an extension of
command line parsing.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index b627b3138b..ebe3d46889 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3199,6 +3199,11 @@ static 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);
 
     /*
@@ -4441,11 +4446,6 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_semihosting_connect_chardevs();
     qemu_semihosting_console_init();
 
-    /* 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 */
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 17/29] vl: separate qemu_create_early_backends
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (15 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 16/29] vl: move CHECKPOINT_INIT after preconfig Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-18 16:29   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 18/29] vl: separate qemu_create_late_backends Paolo Bonzini
                   ` (12 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

"Early" backends are created before the machine and can be used as
machine options.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 123 +++++++++++++++++++++++++++------------------------
 1 file changed, 65 insertions(+), 58 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index ebe3d46889..109036c089 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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);
@@ -2696,6 +2698,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
@@ -2703,7 +2757,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);
 }
 
 
@@ -3321,7 +3375,6 @@ static void qemu_machine_creation_done(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;
@@ -3334,7 +3387,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);
@@ -4308,52 +4360,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,
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 18/29] vl: separate qemu_create_late_backends
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (16 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 17/29] vl: separate qemu_create_early_backends Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-18 16:33   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 19/29] vl: separate qemu_create_machine Paolo Bonzini
                   ` (11 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

"Late" backends are created after the machine.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 64 ++++++++++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 109036c089..0c390b979e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2755,11 +2755,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);
+
+    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);
+
+    /* now chardevs have been created we may have semihosting to connect */
+    qemu_semihosting_connect_chardevs();
+    qemu_semihosting_console_init();
+}
 
 static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
                                MachineClass *mc)
@@ -3385,7 +3415,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);
@@ -4402,10 +4431,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");
@@ -4426,32 +4451,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);
-
-    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);
-
-    /* now chardevs have been created we may have semihosting to connect */
-    qemu_semihosting_connect_chardevs();
-    qemu_semihosting_console_init();
+    qemu_create_late_backends();
 
     current_machine->boot_order = boot_order;
 
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 19/29] vl: separate qemu_create_machine
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (17 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 18/29] vl: separate qemu_create_late_backends Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-18 16:45   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 20/29] vl: separate qemu_apply_machine_options Paolo Bonzini
                   ` (10 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 111 +++++++++++++++++++++++++++------------------------
 1 file changed, 59 insertions(+), 52 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 0c390b979e..38ad3cc895 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -133,6 +133,8 @@ static const char *boot_order;
 static const char *boot_once;
 static const char *incoming;
 static const char *loadvm;
+static ram_addr_t maxram_size;
+static uint64_t ram_slots;
 static int display_remote;
 static int snapshot;
 static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
@@ -2791,8 +2793,13 @@ static void qemu_create_late_backends(void)
     qemu_semihosting_console_init();
 }
 
-static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
-                               MachineClass *mc)
+static bool have_custom_ram_size(void)
+{
+    QemuOpts *opts = qemu_find_opts_singleton("memory");
+    return !!qemu_opt_get(opts, "size");
+}
+
+static void set_memory_options(MachineClass *mc)
 {
     uint64_t sz;
     const char *mem_str;
@@ -2842,7 +2849,7 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
 
     /* store value for the future use */
     qemu_opt_set_number(opts, "size", ram_size, &error_abort);
-    *maxram_size = ram_size;
+    maxram_size = ram_size;
 
     if (qemu_opt_get(opts, "maxmem")) {
         uint64_t slots;
@@ -2863,15 +2870,58 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
             exit(EXIT_FAILURE);
         }
 
-        *maxram_size = sz;
-        *ram_slots = slots;
+        maxram_size = sz;
+        ram_slots = slots;
     } else if (qemu_opt_get(opts, "slots")) {
         error_report("invalid -m option value: missing 'maxmem' option");
         exit(EXIT_FAILURE);
     }
 
     loc_pop(&loc);
-    return !!mem_str;
+}
+
+static void qemu_create_machine(MachineClass *machine_class)
+{
+    object_set_machine_compat_props(machine_class->compat_props);
+
+    set_memory_options(machine_class);
+
+    current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
+    if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
+        exit(0);
+    }
+    object_property_add_child(object_get_root(), "machine",
+                              OBJECT(current_machine));
+    object_property_add_child(container_get(OBJECT(current_machine),
+                                            "/unattached"),
+                              "sysbus", OBJECT(sysbus_get_default()));
+
+    if (machine_class->minimum_page_bits) {
+        if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
+            /* This would be a board error: specifying a minimum smaller than
+             * a target's compile-time fixed setting.
+             */
+            g_assert_not_reached();
+        }
+    }
+
+    cpu_exec_init_all();
+
+    if (machine_class->hw_version) {
+        qemu_set_hw_version(machine_class->hw_version);
+    }
+
+    machine_smp_parse(current_machine,
+        qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
+
+    /*
+     * Get the default machine options from the machine if it is not already
+     * specified either by the configuration file or by the command line.
+     */
+    if (machine_class->default_machine_opts) {
+        qemu_opts_set_defaults(qemu_find_opts("machine"),
+                               machine_class->default_machine_opts, 0);
+    }
 }
 
 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -3412,10 +3462,7 @@ void qemu_init(int argc, char **argv, char **envp)
     const char *optarg;
     MachineClass *machine_class;
     bool userconfig = true;
-    ram_addr_t maxram_size;
-    uint64_t ram_slots = 0;
     FILE *vmstate_dump_file = NULL;
-    bool have_custom_ram_size;
 
     qemu_add_opts(&qemu_drive_opts);
     qemu_add_drive_opts(&qemu_legacy_drive_opts);
@@ -4344,48 +4391,7 @@ void qemu_init(int argc, char **argv, char **envp)
 
     configure_rtc(qemu_find_opts_singleton("rtc"));
 
-    machine_class = select_machine();
-    object_set_machine_compat_props(machine_class->compat_props);
-
-    have_custom_ram_size = set_memory_options(&ram_slots, &maxram_size,
-                                              machine_class);
-
-    current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
-    if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
-        exit(0);
-    }
-    object_property_add_child(object_get_root(), "machine",
-                              OBJECT(current_machine));
-    object_property_add_child(container_get(OBJECT(current_machine),
-                                            "/unattached"),
-                              "sysbus", OBJECT(sysbus_get_default()));
-
-    if (machine_class->minimum_page_bits) {
-        if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
-            /* This would be a board error: specifying a minimum smaller than
-             * a target's compile-time fixed setting.
-             */
-            g_assert_not_reached();
-        }
-    }
-
-    cpu_exec_init_all();
-
-    if (machine_class->hw_version) {
-        qemu_set_hw_version(machine_class->hw_version);
-    }
-
-    machine_smp_parse(current_machine,
-        qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
-
-    /*
-     * Get the default machine options from the machine if it is not already
-     * specified either by the configuration file or by the command line.
-     */
-    if (machine_class->default_machine_opts) {
-        qemu_opts_set_defaults(qemu_find_opts("machine"),
-                               machine_class->default_machine_opts, 0);
-    }
+    qemu_create_machine(select_machine());
 
     qemu_disable_default_devices();
     qemu_create_default_devices();
@@ -4420,6 +4426,7 @@ void qemu_init(int argc, char **argv, char **envp)
      * called from configure_accelerator().
      */
 
+    machine_class = MACHINE_GET_CLASS(current_machine);
     if (!qtest_enabled() && machine_class->deprecation_reason) {
         error_report("Machine type '%s' is deprecated: %s",
                      machine_class->name, machine_class->deprecation_reason);
@@ -4473,7 +4480,7 @@ void qemu_init(int argc, char **argv, char **envp)
             exit(EXIT_FAILURE);
         }
         backend_size = object_property_get_uint(backend, "size",  &error_abort);
-        if (have_custom_ram_size && backend_size != ram_size) {
+        if (have_custom_ram_size() && backend_size != ram_size) {
                 error_report("Size specified by -m option must match size of "
                              "explicitly specified 'memory-backend' property");
                 exit(EXIT_FAILURE);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 20/29] vl: separate qemu_apply_machine_options
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (18 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 19/29] vl: separate qemu_create_machine Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-18 16:57   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 21/29] vl: separate qemu_resolve_machine_memdev Paolo Bonzini
                   ` (9 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 66 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 38ad3cc895..9a3c92387e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2700,6 +2700,41 @@ static bool object_create_early(const char *type, QemuOpts *opts)
     return true;
 }
 
+static void qemu_apply_machine_options(void)
+{
+    MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
+    QemuOpts *machine_opts = qemu_get_machine_opts();
+    QemuOpts *opts;
+
+    qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
+                     &error_fatal);
+    current_machine->ram_size = ram_size;
+    current_machine->maxram_size = maxram_size;
+    current_machine->ram_slots = ram_slots;
+
+    opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
+    if (opts) {
+        boot_order = qemu_opt_get(opts, "order");
+        if (boot_order) {
+            validate_bootdevices(boot_order, &error_fatal);
+        }
+
+        boot_once = qemu_opt_get(opts, "once");
+        if (boot_once) {
+            validate_bootdevices(boot_once, &error_fatal);
+        }
+
+        boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
+        boot_strict = qemu_opt_get_bool(opts, "strict", false);
+    }
+
+    if (!boot_order) {
+        boot_order = machine_class->default_boot_order;
+    }
+
+    current_machine->boot_order = boot_order;
+}
+
 static void qemu_create_early_backends(void)
 {
     MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
@@ -3455,7 +3490,7 @@ static void qemu_machine_creation_done(void)
 
 void qemu_init(int argc, char **argv, char **envp)
 {
-    QemuOpts *opts, *machine_opts;
+    QemuOpts *opts;
     QemuOpts *icount_opts = NULL, *accel_opts = NULL;
     QemuOptsList *olist;
     int optind;
@@ -4397,12 +4432,7 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_create_default_devices();
     qemu_create_early_backends();
 
-    machine_opts = qemu_get_machine_opts();
-    qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
-                     &error_fatal);
-    current_machine->ram_size = ram_size;
-    current_machine->maxram_size = maxram_size;
-    current_machine->ram_slots = ram_slots;
+    qemu_apply_machine_options();
 
     /*
      * Note: uses machine properties such as kernel-irqchip, must run
@@ -4438,30 +4468,8 @@ void qemu_init(int argc, char **argv, char **envp)
      */
     migration_object_init();
 
-    opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
-    if (opts) {
-        boot_order = qemu_opt_get(opts, "order");
-        if (boot_order) {
-            validate_bootdevices(boot_order, &error_fatal);
-        }
-
-        boot_once = qemu_opt_get(opts, "once");
-        if (boot_once) {
-            validate_bootdevices(boot_once, &error_fatal);
-        }
-
-        boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
-        boot_strict = qemu_opt_get_bool(opts, "strict", false);
-    }
-
-    if (!boot_order) {
-        boot_order = machine_class->default_boot_order;
-    }
-
     qemu_create_late_backends();
 
-    current_machine->boot_order = boot_order;
-
     /* parse features once if machine provides default cpu_type */
     current_machine->cpu_type = machine_class->default_cpu_type;
     if (cpu_option) {
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 21/29] vl: separate qemu_resolve_machine_memdev
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (19 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 20/29] vl: separate qemu_apply_machine_options Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 13:15   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 22/29] vl: initialize displays before preconfig loop Paolo Bonzini
                   ` (8 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

This is a bit nasty: the machine is storing a string and later
resolving it.  We probably want to remove the memdev property
and instead make this a memory-set command.  "-M memdev" can be
handled as a legacy option that is special cased by
machine_set_property.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 70 +++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 33 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 9a3c92387e..1485aba8be 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2834,6 +2834,42 @@ static bool have_custom_ram_size(void)
     return !!qemu_opt_get(opts, "size");
 }
 
+static void qemu_resolve_machine_memdev(void)
+{
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;
+
+        backend = object_resolve_path_type(current_machine->ram_memdev_id,
+                                           TYPE_MEMORY_BACKEND, NULL);
+        if (!backend) {
+            error_report("Memory backend '%s' not found",
+                         current_machine->ram_memdev_id);
+            exit(EXIT_FAILURE);
+        }
+        backend_size = object_property_get_uint(backend, "size",  &error_abort);
+        if (have_custom_ram_size() && backend_size != ram_size) {
+                error_report("Size specified by -m option must match size of "
+                             "explicitly specified 'memory-backend' property");
+                exit(EXIT_FAILURE);
+        }
+        if (mem_path) {
+            error_report("'-mem-path' can't be used together with"
+                         "'-machine memory-backend'");
+            exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;
+    }
+
+    if (!xen_enabled()) {
+        /* On 32-bit hosts, QEMU is limited by virtual address space */
+        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
+            error_report("at most 2047 MB RAM can be simulated");
+            exit(1);
+        }
+    }
+}
+
 static void set_memory_options(MachineClass *mc)
 {
     uint64_t sz;
@@ -4476,39 +4512,7 @@ void qemu_init(int argc, char **argv, char **envp)
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }
 
-    if (current_machine->ram_memdev_id) {
-        Object *backend;
-        ram_addr_t backend_size;
-
-        backend = object_resolve_path_type(current_machine->ram_memdev_id,
-                                           TYPE_MEMORY_BACKEND, NULL);
-        if (!backend) {
-            error_report("Memory backend '%s' not found",
-                         current_machine->ram_memdev_id);
-            exit(EXIT_FAILURE);
-        }
-        backend_size = object_property_get_uint(backend, "size",  &error_abort);
-        if (have_custom_ram_size() && backend_size != ram_size) {
-                error_report("Size specified by -m option must match size of "
-                             "explicitly specified 'memory-backend' property");
-                exit(EXIT_FAILURE);
-        }
-        if (mem_path) {
-            error_report("'-mem-path' can't be used together with"
-                         "'-machine memory-backend'");
-            exit(EXIT_FAILURE);
-        }
-        ram_size = backend_size;
-    }
-
-    if (!xen_enabled()) {
-        /* On 32-bit hosts, QEMU is limited by virtual address space */
-        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
-            error_report("at most 2047 MB RAM can be simulated");
-            exit(1);
-        }
-    }
-
+    qemu_resolve_machine_memdev();
     parse_numa_opts(current_machine);
 
     /* do monitor/qmp handling at preconfig state if requested */
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (20 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 21/29] vl: separate qemu_resolve_machine_memdev Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 15:11   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 23/29] vl: move -global check earlier Paolo Bonzini
                   ` (7 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Displays should be available before the monitor starts, so that
it is possible to use the graphical console to interact with
the monitor itself.

This patch is quite ugly, but all this is temporary.  The double
call to qemu_init_displays will go away as soon we can unify machine
initialization between the preconfig and "normal" flows, and so will
the preconfig_exit_requested variable (that is only preconfig_requested
remains).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 58 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 1485aba8be..a46f1b9164 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -137,6 +137,7 @@ static ram_addr_t maxram_size;
 static uint64_t ram_slots;
 static int display_remote;
 static int snapshot;
+static bool preconfig_requested;
 static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
 static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
 static bool nographic = false;
@@ -3210,12 +3211,12 @@ static void qemu_validate_options(void)
           }
     }
 
-    if (loadvm && !preconfig_exit_requested) {
+    if (loadvm && preconfig_requested) {
         error_report("'preconfig' and 'loadvm' options are "
                      "mutually exclusive");
         exit(EXIT_FAILURE);
     }
-    if (incoming && !preconfig_exit_requested) {
+    if (incoming && preconfig_requested) {
         error_report("'preconfig' and 'incoming' options are "
                      "mutually exclusive");
         exit(EXIT_FAILURE);
@@ -3381,6 +3382,28 @@ static void qemu_init_subsystems(void)
     socket_init();
 }
 
+static void qemu_init_displays(void)
+{
+    DisplayState *ds;
+
+    /* init local displays */
+    ds = init_displaystate();
+    qemu_display_init(ds, &dpy);
+
+    /* must be after terminal init, SDL library changes signal handlers */
+    os_setup_signal_handling();
+
+    /* init remote displays */
+#ifdef CONFIG_VNC
+    qemu_opts_foreach(qemu_find_opts("vnc"),
+                      vnc_init_func, NULL, &error_fatal);
+#endif
+
+    if (using_spice) {
+        qemu_spice.display_init();
+    }
+}
+
 /*
  * Called after leaving preconfig state.  From here on runstate is
  * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE.
@@ -3449,8 +3472,6 @@ static void qemu_create_cli_devices(void)
 
 static void qemu_machine_creation_done(void)
 {
-    DisplayState *ds;
-
     cpu_synchronize_all_post_init();
 
     /* Did we create any drives that we failed to create a device for? */
@@ -3473,23 +3494,6 @@ static void qemu_machine_creation_done(void)
         qemu_register_reset(restore_boot_order, g_strdup(boot_order));
     }
 
-    /* init local displays */
-    ds = init_displaystate();
-    qemu_display_init(ds, &dpy);
-
-    /* must be after terminal init, SDL library changes signal handlers */
-    os_setup_signal_handling();
-
-    /* init remote displays */
-#ifdef CONFIG_VNC
-    qemu_opts_foreach(qemu_find_opts("vnc"),
-                      vnc_init_func, NULL, &error_fatal);
-#endif
-
-    if (using_spice) {
-        qemu_spice.display_init();
-    }
-
     if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
         exit(1);
     }
@@ -4094,6 +4098,7 @@ void qemu_init(int argc, char **argv, char **envp)
                 break;
             case QEMU_OPTION_preconfig:
                 preconfig_exit_requested = false;
+                preconfig_requested = true;
                 break;
             case QEMU_OPTION_enable_kvm:
                 olist = qemu_find_opts("machine");
@@ -4515,11 +4520,20 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_resolve_machine_memdev();
     parse_numa_opts(current_machine);
 
+    if (preconfig_requested) {
+        qemu_init_displays();
+    }
+
     /* do monitor/qmp handling at preconfig state if requested */
     qemu_main_loop();
-
     qemu_finish_machine_init();
+
     qemu_create_cli_devices();
+
+    /* initialize displays after all errors have been reported */
+    if (!preconfig_requested) {
+        qemu_init_displays();
+    }
     qemu_machine_creation_done();
 
     if (loadvm) {
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 23/29] vl: move -global check earlier
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (21 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 22/29] vl: initialize displays before preconfig loop Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 15:10   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming Paolo Bonzini
                   ` (6 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

The check has no effect after both builtin and user-specified devices
have been created.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index a46f1b9164..ae2854d8af 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3489,6 +3489,8 @@ static void qemu_machine_creation_done(void)
         net_check_clients();
     }
 
+    qdev_prop_check_globals();
+
     if (boot_once) {
         qemu_boot_set(boot_once, &error_fatal);
         qemu_register_reset(restore_boot_order, g_strdup(boot_order));
@@ -4548,7 +4550,6 @@ void qemu_init(int argc, char **argv, char **envp)
         replay_vmstate_init();
     }
 
-    qdev_prop_check_globals();
     if (vmstate_dump_file) {
         /* dump and exit */
         dump_vmstate_json_to_file(vmstate_dump_file);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (22 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 23/29] vl: move -global check earlier Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 15:34   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 25/29] vl: start VM via qmp_cont Paolo Bonzini
                   ` (5 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Make qemu_start_incoming_migration local to migration/migration.c.
By using the runstate instead of a separate flag, vl need not do
anything to setup deferred incoming migration.

qmp_migrate_incoming also does not need the deferred_incoming flag
anymore, because "-incoming PROTOCOL" will clear the "once" flag
before the main loop starts.  Therefore, later invocations of
the migrate-incoming command will fail with the existing
"The incoming migration has already been started" error message.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/migration/misc.h |  1 -
 migration/migration.c    | 33 ++++++++-------------------------
 softmmu/vl.c             | 11 +++++++----
 3 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/include/migration/misc.h b/include/migration/misc.h
index 34e7d75713..bccc1b6b44 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -58,7 +58,6 @@ void dump_vmstate_json_to_file(FILE *out_fp);
 /* migration/migration.c */
 void migration_object_init(void);
 void migration_shutdown(void);
-void qemu_start_incoming_migration(const char *uri, Error **errp);
 bool migration_is_idle(void);
 bool migration_is_active(MigrationState *);
 void add_migration_state_change_notifier(Notifier *notify);
diff --git a/migration/migration.c b/migration/migration.c
index f48b03cac2..d078094c56 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -114,8 +114,6 @@
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
 
-static bool deferred_incoming;
-
 /* Messages sent on the return path from destination to source */
 enum mig_rp_message_type {
     MIG_RP_MSG_INVALID = 0,  /* Must be 0 */
@@ -257,19 +255,6 @@ static bool migrate_late_block_activate(void)
         MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
 }
 
-/*
- * Called on -incoming with a defer: uri.
- * The migration can be started later after any parameters have been
- * changed.
- */
-static void deferred_incoming_migration(Error **errp)
-{
-    if (deferred_incoming) {
-        error_setg(errp, "Incoming migration already deferred");
-    }
-    deferred_incoming = true;
-}
-
 /*
  * Send a message on the return channel back to the source
  * of the migration.
@@ -380,16 +365,14 @@ void migrate_add_address(SocketAddress *address)
     addrs->value = QAPI_CLONE(SocketAddress, address);
 }
 
-void qemu_start_incoming_migration(const char *uri, Error **errp)
+static void qemu_start_incoming_migration(const char *uri, Error **errp)
 {
     const char *p = NULL;
 
     qapi_event_send_migration(MIGRATION_STATUS_SETUP);
-    if (!strcmp(uri, "defer")) {
-        deferred_incoming_migration(errp);
-    } else if (strstart(uri, "tcp:", &p) ||
-               strstart(uri, "unix:", NULL) ||
-               strstart(uri, "vsock:", NULL)) {
+    if (strstart(uri, "tcp:", &p) ||
+        strstart(uri, "unix:", NULL) ||
+        strstart(uri, "vsock:", NULL)) {
         socket_start_incoming_migration(p ? p : uri, errp);
 #ifdef CONFIG_RDMA
     } else if (strstart(uri, "rdma:", &p)) {
@@ -1926,14 +1909,14 @@ void qmp_migrate_incoming(const char *uri, Error **errp)
     Error *local_err = NULL;
     static bool once = true;
 
-    if (!deferred_incoming) {
-        error_setg(errp, "For use with '-incoming defer'");
-        return;
-    }
     if (!once) {
         error_setg(errp, "The incoming migration has already been started");
         return;
     }
+    if (!runstate_check(RUN_STATE_INMIGRATE)) {
+        error_setg(errp, "'-incoming' was not specified on the command line");
+        return;
+    }
 
     qemu_start_incoming_migration(uri, &local_err);
 
diff --git a/softmmu/vl.c b/softmmu/vl.c
index ae2854d8af..583366510b 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -109,6 +109,7 @@
 #include "qapi/qapi-visit-block-core.h"
 #include "qapi/qapi-visit-ui.h"
 #include "qapi/qapi-commands-block-core.h"
+#include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-run-state.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qerror.h"
@@ -4557,10 +4558,12 @@ void qemu_init(int argc, char **argv, char **envp)
     }
     if (incoming) {
         Error *local_err = NULL;
-        qemu_start_incoming_migration(incoming, &local_err);
-        if (local_err) {
-            error_reportf_err(local_err, "-incoming %s: ", incoming);
-            exit(1);
+        if (strcmp(incoming, "defer") != 0) {
+            qmp_migrate_incoming(incoming, &local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "-incoming %s: ", incoming);
+                exit(1);
+            }
         }
     } else if (autostart) {
         vm_start();
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 25/29] vl: start VM via qmp_cont
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (23 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 16:08   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 26/29] hmp: introduce cmd_available Paolo Bonzini
                   ` (4 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Complement the previous patch by starting the VM with a QMP command.
Later, the user will be able to do the same, invoking two
commands "finish-machine-init" and "cont" instead of
"x-exit-preconfig".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 583366510b..edabd17dac 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -110,6 +110,7 @@
 #include "qapi/qapi-visit-ui.h"
 #include "qapi/qapi-commands-block-core.h"
 #include "qapi/qapi-commands-migration.h"
+#include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-run-state.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qerror.h"
@@ -4566,7 +4567,7 @@ void qemu_init(int argc, char **argv, char **envp)
             }
         }
     } else if (autostart) {
-        vm_start();
+        qmp_cont(NULL);
     }
 
     accel_setup_post(current_machine);
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 26/29] hmp: introduce cmd_available
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (24 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 25/29] vl: start VM via qmp_cont Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 15:46   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 27/29] remove preconfig state Paolo Bonzini
                   ` (3 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Combine the RUN_STATE_PRECONFIG and cmd_can_preconfig checks
into a single function, to avoid repeating the same expression
(or its negation after applying DeMorgan's rule) over and
over again.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 monitor/hmp.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/monitor/hmp.c b/monitor/hmp.c
index c5cd9d372b..f13ef455e2 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -213,6 +213,11 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
     return strchr(cmd->flags, 'p');
 }
 
+static bool cmd_available(const HMPCommand *cmd)
+{
+    return !runstate_check(RUN_STATE_PRECONFIG) || cmd_can_preconfig(cmd);
+}
+
 static void help_cmd_dump_one(Monitor *mon,
                               const HMPCommand *cmd,
                               char **prefix_args,
@@ -220,7 +225,7 @@ static void help_cmd_dump_one(Monitor *mon,
 {
     int i;
 
-    if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) {
+    if (!cmd_available(cmd)) {
         return;
     }
 
@@ -248,8 +253,7 @@ static void help_cmd_dump(Monitor *mon, const HMPCommand *cmds,
     /* Find one entry to dump */
     for (cmd = cmds; cmd->name != NULL; cmd++) {
         if (hmp_compare_cmd(args[arg_index], cmd->name) &&
-            ((!runstate_check(RUN_STATE_PRECONFIG) ||
-                cmd_can_preconfig(cmd)))) {
+            cmd_available(cmd)) {
             if (cmd->sub_table) {
                 /* continue with next arg */
                 help_cmd_dump(mon, cmd->sub_table,
@@ -653,7 +657,7 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
                        (int)(p - cmdp_start), cmdp_start);
         return NULL;
     }
-    if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) {
+    if (!cmd_available(cmd)) {
         monitor_printf(mon, "Command '%.*s' not available with -preconfig "
                             "until after exit_preconfig.\n",
                        (int)(p - cmdp_start), cmdp_start);
@@ -1225,8 +1229,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
         }
         readline_set_completion_index(mon->rs, strlen(cmdname));
         for (cmd = cmd_table; cmd->name != NULL; cmd++) {
-            if (!runstate_check(RUN_STATE_PRECONFIG) ||
-                 cmd_can_preconfig(cmd)) {
+            if (cmd_available(cmd)) {
                 cmd_completion(mon, cmdname, cmd->name);
             }
         }
@@ -1234,8 +1237,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
         /* find the command */
         for (cmd = cmd_table; cmd->name != NULL; cmd++) {
             if (hmp_compare_cmd(args[0], cmd->name) &&
-                (!runstate_check(RUN_STATE_PRECONFIG) ||
-                 cmd_can_preconfig(cmd))) {
+                cmd_available(cmd)) {
                 break;
             }
         }
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 27/29] remove preconfig state
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (25 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 26/29] hmp: introduce cmd_available Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 16:01   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 28/29] vl: remove separate preconfig main_loop Paolo Bonzini
                   ` (2 subsequent siblings)
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

The preconfig state is only used if -incoming is not specified, which
makes the RunState state machine more tricky than it need be.  However
there is already an equivalent condition which works even with -incoming,
namely qdev_hotplug.  Use it instead of a separate runstate.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/core/machine-qmp-cmds.c    |  5 ++---
 include/qapi/qmp/dispatch.h   |  1 +
 monitor/hmp.c                 |  7 ++++---
 monitor/qmp-cmds.c            |  5 ++---
 qapi/qmp-dispatch.c           |  5 +----
 qapi/run-state.json           |  5 +----
 softmmu/qdev-monitor.c        | 12 ++++++++++++
 softmmu/vl.c                  | 13 ++-----------
 stubs/meson.build             |  1 +
 stubs/qmp-command-available.c |  7 +++++++
 10 files changed, 33 insertions(+), 28 deletions(-)
 create mode 100644 stubs/qmp-command-available.c

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 5362c80a18..cb9387c5f5 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -286,9 +286,8 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)
 
 void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
 {
-    if (!runstate_check(RUN_STATE_PRECONFIG)) {
-        error_setg(errp, "The command is permitted only in '%s' state",
-                   RunState_str(RUN_STATE_PRECONFIG));
+    if (qdev_hotplug) {
+         error_setg(errp, "The command is permitted only before the machine has been created");
          return;
     }
 
diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
index af8d96c570..1486cac3ef 100644
--- a/include/qapi/qmp/dispatch.h
+++ b/include/qapi/qmp/dispatch.h
@@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, const char *name);
 void qmp_enable_command(QmpCommandList *cmds, const char *name);
 
 bool qmp_command_is_enabled(const QmpCommand *cmd);
+bool qmp_command_available(const QmpCommand *cmd, Error **errp);
 const char *qmp_command_name(const QmpCommand *cmd);
 bool qmp_has_success_response(const QmpCommand *cmd);
 QDict *qmp_error_response(Error *err);
diff --git a/monitor/hmp.c b/monitor/hmp.c
index f13ef455e2..0027f1465d 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include <dirent.h>
+#include "hw/qdev-core.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
@@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
 
 static bool cmd_available(const HMPCommand *cmd)
 {
-    return !runstate_check(RUN_STATE_PRECONFIG) || cmd_can_preconfig(cmd);
+    return qdev_hotplug || cmd_can_preconfig(cmd);
 }
 
 static void help_cmd_dump_one(Monitor *mon,
@@ -658,8 +659,8 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
         return NULL;
     }
     if (!cmd_available(cmd)) {
-        monitor_printf(mon, "Command '%.*s' not available with -preconfig "
-                            "until after exit_preconfig.\n",
+        monitor_printf(mon, "Command '%.*s' not available "
+                            "until machine initialization has completed.\n",
                        (int)(p - cmdp_start), cmdp_start);
         return NULL;
     }
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index a08143b323..7c10b182e4 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)
 
 void qmp_x_exit_preconfig(Error **errp)
 {
-    if (!runstate_check(RUN_STATE_PRECONFIG)) {
-        error_setg(errp, "The command is permitted only in '%s' state",
-                   RunState_str(RUN_STATE_PRECONFIG));
+    if (qdev_hotplug) {
+        error_setg(errp, "The command is permitted only before machine initialization");
         return;
     }
     qemu_exit_preconfig_request();
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 9a2d7dd29a..0a2b20a4e4 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
         goto out;
     }
 
-    if (runstate_check(RUN_STATE_PRECONFIG) &&
-        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
-        error_setg(&err, "The command '%s' isn't permitted in '%s' state",
-                   cmd->name, RunState_str(RUN_STATE_PRECONFIG));
+    if (!qmp_command_available(cmd, &err)) {
         goto out;
     }
 
diff --git a/qapi/run-state.json b/qapi/run-state.json
index 964c8ef391..38194b0e44 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -50,15 +50,12 @@
 # @colo: guest is paused to save/restore VM state under colo checkpoint,
 #        VM can not get into this state unless colo capability is enabled
 #        for migration. (since 2.8)
-# @preconfig: QEMU is paused before board specific init callback is executed.
-#             The state is reachable only if the --preconfig CLI option is used.
-#             (Since 3.0)
 ##
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
             'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
             'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
-            'guest-panicked', 'colo', 'preconfig' ] }
+            'guest-panicked', 'colo' ] }
 
 ##
 # @ShutdownCause:
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index bcfcbac181..00720eb827 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -25,6 +25,7 @@
 #include "sysemu/arch_init.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-qdev.h"
+#include "qapi/qmp/dispatch.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/config-file.h"
@@ -997,3 +998,14 @@ int qemu_global_option(const char *str)
 
     return 0;
 }
+
+bool qmp_command_available(const QmpCommand *cmd, Error **errp)
+{
+    if (!qdev_hotplug &&
+        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
+        error_setg(errp, "The command '%s' is permitted only after machine initialization has completed",
+                   cmd->name);
+        return false;
+    }
+    return true;
+}
diff --git a/softmmu/vl.c b/softmmu/vl.c
index edabd17dac..68acd24d01 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -574,7 +574,7 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
 /***********************************************************/
 /* QEMU state */
 
-static RunState current_run_state = RUN_STATE_PRECONFIG;
+static RunState current_run_state = RUN_STATE_PRELAUNCH;
 
 /* We use RUN_STATE__MAX but any invalid value will do */
 static RunState vmstop_requested = RUN_STATE__MAX;
@@ -586,13 +586,7 @@ typedef struct {
 } RunStateTransition;
 
 static const RunStateTransition runstate_transitions_def[] = {
-    /*     from      ->     to      */
-    { RUN_STATE_PRECONFIG, RUN_STATE_PRELAUNCH },
-      /* Early switch to inmigrate state to allow  -incoming CLI option work
-       * as it used to. TODO: delay actual switching to inmigrate state to
-       * the point after machine is built and remove this hack.
-       */
-    { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE },
+    { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
     { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
@@ -1633,9 +1627,6 @@ static bool main_loop_should_exit(void)
     ShutdownCause request;
 
     if (preconfig_exit_requested) {
-        if (runstate_check(RUN_STATE_PRECONFIG)) {
-            runstate_set(RUN_STATE_PRELAUNCH);
-        }
         preconfig_exit_requested = false;
         return true;
     }
diff --git a/stubs/meson.build b/stubs/meson.build
index 82b7ba60ab..cc56c83063 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c'))
 stub_ss.add(files('pci-host-piix.c'))
 stub_ss.add(files('qemu-timer-notify-cb.c'))
 stub_ss.add(files('qmp_memory_device.c'))
+stub_ss.add(files('qmp-command-available.c'))
 stub_ss.add(files('qtest.c'))
 stub_ss.add(files('ram-block.c'))
 stub_ss.add(files('ramfb.c'))
diff --git a/stubs/qmp-command-available.c b/stubs/qmp-command-available.c
new file mode 100644
index 0000000000..46540af7bf
--- /dev/null
+++ b/stubs/qmp-command-available.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "qapi/qmp/dispatch.h"
+
+bool qmp_command_available(const QmpCommand *cmd, Error **errp)
+{
+    return true;
+}
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 28/29] vl: remove separate preconfig main_loop
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (26 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 27/29] remove preconfig state Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 16:26   ` Igor Mammedov
  2020-10-27 18:21 ` [PATCH 29/29] vl: allow -incoming defer with -preconfig Paolo Bonzini
  2020-11-02 15:57 ` [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Igor Mammedov
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Move post-preconfig initialization to the x-exit-preconfig.  If preconfig
is not requested, just exit preconfig mode immediately with the QMP
command.

As a result, the preconfig loop will run with accel_setup_post
and os_setup_post restrictions (xen_restrict, chroot, etc.)
already done.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/sysemu/runstate.h |  1 -
 monitor/qmp-cmds.c        |  9 ----
 softmmu/vl.c              | 94 +++++++++++++++++----------------------
 3 files changed, 41 insertions(+), 63 deletions(-)

diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index f760094858..e557f470d4 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -41,7 +41,6 @@ typedef enum WakeupReason {
     QEMU_WAKEUP_REASON_OTHER,
 } WakeupReason;
 
-void qemu_exit_preconfig_request(void);
 void qemu_system_reset_request(ShutdownCause reason);
 void qemu_system_suspend_request(void);
 void qemu_register_suspend_notifier(Notifier *notifier);
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 7c10b182e4..6680ba6c66 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -102,15 +102,6 @@ void qmp_system_powerdown(Error **errp)
     qemu_system_powerdown_request();
 }
 
-void qmp_x_exit_preconfig(Error **errp)
-{
-    if (qdev_hotplug) {
-        error_setg(errp, "The command is permitted only before machine initialization");
-        return;
-    }
-    qemu_exit_preconfig_request();
-}
-
 void qmp_cont(Error **errp)
 {
     BlockBackend *blk;
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 68acd24d01..98666c0612 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1313,7 +1313,6 @@ static pid_t shutdown_pid;
 static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
-static bool preconfig_exit_requested = true;
 static WakeupReason wakeup_reason;
 static NotifierList powerdown_notifiers =
     NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
@@ -1400,11 +1399,6 @@ static int qemu_debug_requested(void)
     return r;
 }
 
-void qemu_exit_preconfig_request(void)
-{
-    preconfig_exit_requested = true;
-}
-
 /*
  * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
  */
@@ -1626,10 +1620,6 @@ static bool main_loop_should_exit(void)
     RunState r;
     ShutdownCause request;
 
-    if (preconfig_exit_requested) {
-        preconfig_exit_requested = false;
-        return true;
-    }
     if (qemu_debug_requested()) {
         vm_stop(RUN_STATE_DEBUG);
     }
@@ -3523,6 +3513,43 @@ static void qemu_machine_creation_done(void)
     register_global_state();
 }
 
+void qmp_x_exit_preconfig(Error **errp)
+{
+    if (qdev_hotplug) {
+        error_setg(errp, "The command is permitted only before machine initialization");
+        return;
+    }
+
+    qemu_finish_machine_init();
+    qemu_create_cli_devices();
+    qemu_machine_creation_done();
+
+    if (loadvm) {
+        Error *local_err = NULL;
+        if (load_snapshot(loadvm, &local_err) < 0) {
+            error_report_err(local_err);
+            autostart = 0;
+            exit(1);
+        }
+    }
+    if (replay_mode != REPLAY_MODE_NONE) {
+        replay_vmstate_init();
+    }
+
+    if (incoming) {
+        Error *local_err = NULL;
+        if (strcmp(incoming, "defer") != 0) {
+            qmp_migrate_incoming(incoming, &local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "-incoming %s: ", incoming);
+                exit(1);
+            }
+        }
+    } else if (autostart) {
+        qmp_cont(NULL);
+    }
+}
+
 void qemu_init(int argc, char **argv, char **envp)
 {
     QemuOpts *opts;
@@ -4092,7 +4119,6 @@ void qemu_init(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_preconfig:
-                preconfig_exit_requested = false;
                 preconfig_requested = true;
                 break;
             case QEMU_OPTION_enable_kvm:
@@ -4515,56 +4541,18 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_resolve_machine_memdev();
     parse_numa_opts(current_machine);
 
-    if (preconfig_requested) {
-        qemu_init_displays();
-    }
-
-    /* do monitor/qmp handling at preconfig state if requested */
-    qemu_main_loop();
-    qemu_finish_machine_init();
-
-    qemu_create_cli_devices();
-
-    /* initialize displays after all errors have been reported */
-    if (!preconfig_requested) {
-        qemu_init_displays();
-    }
-    qemu_machine_creation_done();
-
-    if (loadvm) {
-        Error *local_err = NULL;
-        if (load_snapshot(loadvm, &local_err) < 0) {
-            error_report_err(local_err);
-            autostart = 0;
-            exit(1);
-        }
-    }
-    if (replay_mode != REPLAY_MODE_NONE) {
-        replay_vmstate_init();
-    }
-
     if (vmstate_dump_file) {
         /* dump and exit */
         dump_vmstate_json_to_file(vmstate_dump_file);
         exit(0);
     }
-    if (incoming) {
-        Error *local_err = NULL;
-        if (strcmp(incoming, "defer") != 0) {
-            qmp_migrate_incoming(incoming, &local_err);
-            if (local_err) {
-                error_reportf_err(local_err, "-incoming %s: ", incoming);
-                exit(1);
-            }
-        }
-    } else if (autostart) {
-        qmp_cont(NULL);
-    }
 
+    if (!preconfig_requested) {
+        qmp_x_exit_preconfig(&error_fatal);
+    }
+    qemu_init_displays();
     accel_setup_post(current_machine);
     os_setup_post();
-
-    return;
 }
 
 void qemu_cleanup(void)
-- 
2.26.2




^ permalink raw reply related	[flat|nested] 78+ messages in thread

* [PATCH 29/29] vl: allow -incoming defer with -preconfig
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (27 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 28/29] vl: remove separate preconfig main_loop Paolo Bonzini
@ 2020-10-27 18:21 ` Paolo Bonzini
  2020-11-20 16:28   ` Igor Mammedov
  2020-11-02 15:57 ` [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Igor Mammedov
  29 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-10-27 18:21 UTC (permalink / raw)
  To: qemu-devel

Now that there is no RUN_STATE_PRECONFIG anymore that can conflict with
RUN_STATE_INMIGRATE, we can allow -incoming defer with -preconfig.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/vl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 98666c0612..b0cb539da9 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3199,9 +3199,8 @@ static void qemu_validate_options(void)
                      "mutually exclusive");
         exit(EXIT_FAILURE);
     }
-    if (incoming && preconfig_requested) {
-        error_report("'preconfig' and 'incoming' options are "
-                     "mutually exclusive");
+    if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
+        error_report("'preconfig' supports '-incoming defer' only");
         exit(EXIT_FAILURE);
     }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 78+ messages in thread

* Re: [PATCH 03/29] vl: extract validation of -smp to machine.c
  2020-10-27 18:21 ` [PATCH 03/29] vl: extract validation of -smp to machine.c Paolo Bonzini
@ 2020-10-28 16:32   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-10-28 16:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:18 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Once smp_parse is done, the validation operates on the MachineState.
> There is no reason for that code to be in vl.c.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Tested-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  hw/core/machine.c   | 23 +++++++++++++++++++++++
>  include/hw/boards.h |  1 +
>  softmmu/vl.c        | 20 ++------------------
>  3 files changed, 26 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index c5e0e79e6d..baea4e8613 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -1072,6 +1072,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);
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index a49e3a6b44..4537cfb5c6 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -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);
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index b0ccfd750a..7f39ebdfee 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -3971,24 +3971,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;



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 04/29] vl: remove bogus check
  2020-10-27 18:21 ` [PATCH 04/29] vl: remove bogus check Paolo Bonzini
@ 2020-10-28 16:48   ` Igor Mammedov
  2020-10-28 16:55     ` Daniel P. Berrangé
  2020-10-28 19:32   ` Igor Mammedov
  1 sibling, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-10-28 16:48 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Daniel P. Berrange, qemu-devel

On Tue, 27 Oct 2020 14:21:19 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> There 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.

it was related to how libvirt starts QEMU but I don't recall why anymore,
CCing Daniel

> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 7f39ebdfee..dbb72e621e 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -4027,12 +4027,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



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 04/29] vl: remove bogus check
  2020-10-28 16:48   ` Igor Mammedov
@ 2020-10-28 16:55     ` Daniel P. Berrangé
  0 siblings, 0 replies; 78+ messages in thread
From: Daniel P. Berrangé @ 2020-10-28 16:55 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: Paolo Bonzini, qemu-devel

On Wed, Oct 28, 2020 at 05:48:57PM +0100, Igor Mammedov wrote:
> On Tue, 27 Oct 2020 14:21:19 -0400
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> > There 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.
> 
> it was related to how libvirt starts QEMU but I don't recall why anymore,
> CCing Daniel

Libvirt didn't request this to best of my knowledge.

We don't even use -daemonize, so have no reason to ask to forbid
-preconfig with -daemonize.

> 
> > 
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  softmmu/vl.c | 6 ------
> >  1 file changed, 6 deletions(-)
> > 
> > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > index 7f39ebdfee..dbb72e621e 100644
> > --- a/softmmu/vl.c
> > +++ b/softmmu/vl.c
> > @@ -4027,12 +4027,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
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 04/29] vl: remove bogus check
  2020-10-27 18:21 ` [PATCH 04/29] vl: remove bogus check Paolo Bonzini
  2020-10-28 16:48   ` Igor Mammedov
@ 2020-10-28 19:32   ` Igor Mammedov
  1 sibling, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-10-28 19:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:19 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> There 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.

looking some more at the current code, this piece is currently
somewhat broken, so it would indeed exit but 'after' fork
and output error message to nowhere. It happens since
os_daemonize() where moved before it later on, given no
one actually complained since then we probably do not care about it.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 7f39ebdfee..dbb72e621e 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -4027,12 +4027,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



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 05/29] vl: split various early command line options to a separate function
  2020-10-27 18:21 ` [PATCH 05/29] vl: split various early command line options to a separate function Paolo Bonzini
@ 2020-11-02 15:30   ` Igor Mammedov
  2020-11-02 16:33     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-02 15:30 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:20 -0400
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>
> ---
>  softmmu/vl.c | 202 ++++++++++++++++++++++++++++-----------------------
>  1 file changed, 113 insertions(+), 89 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
[...]
> +
> +static void qemu_maybe_daemonize(const char *pid_file)

why it's _maybe_ ?
It looks to me as just deamonize (or die which could be omitted)

> +{
> +    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);
> +}
[...]



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 06/29] vl: move various initialization routines out of qemu_init
  2020-10-27 18:21 ` [PATCH 06/29] vl: move various initialization routines out of qemu_init Paolo Bonzini
@ 2020-11-02 15:40   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-02 15:40 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:21 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Some very simple initialization routines can be nested in existing
> subsystem-level functions, do that to simplify qemu_init.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  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(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index baea4e8613..d84b84463c 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -872,6 +872,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;
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 868973319e..56ce7f2d7f 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -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:
>   *
> diff --git a/migration/migration.c b/migration/migration.c
> index deb6005b8d..f48b03cac2 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -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)
> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
> index bcfb90a08f..bcfcbac181 100644
> --- a/softmmu/qdev-monitor.c
> +++ b/softmmu/qdev-monitor.c
> @@ -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",
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 32880616e2..b05340802a 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -4275,10 +4275,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);
>  
> @@ -4311,7 +4307,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;
>  



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 07/29] vl: extract qemu_init_subsystems
  2020-10-27 18:21 ` [PATCH 07/29] vl: extract qemu_init_subsystems Paolo Bonzini
@ 2020-11-02 15:55   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-02 15:55 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:22 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Group 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 94 ++++++++++++++++++++++++----------------------------
>  1 file changed, 43 insertions(+), 51 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index b05340802a..a086cd7066 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -128,7 +128,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,
> @@ -1228,7 +1228,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:
> @@ -2965,11 +2966,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;
> @@ -2990,7 +3025,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;
> @@ -2998,22 +3032,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);
> @@ -3048,27 +3066,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;
> @@ -3947,13 +3948,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) {
> @@ -4132,9 +4130,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);
> @@ -4251,9 +4246,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);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
                   ` (28 preceding siblings ...)
  2020-10-27 18:21 ` [PATCH 29/29] vl: allow -incoming defer with -preconfig Paolo Bonzini
@ 2020-11-02 15:57 ` Igor Mammedov
  2020-11-02 16:34   ` Paolo Bonzini
  29 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-02 15:57 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:15 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> The main improvements with respect to v1 are:

series no longer applies to master
what commit if was based on?

> 
> - further extraction of various phases of command line processing and VM
>   creation to separate function;
> 
> - removing the preconfig main_loop: the VM is effectively always starting
>   as if -preconfig was specified, it just executes automatically if not
>   requested.  This enables "-incoming defer" to be specified together
>   with "-preconfig".
> 
> I have other patches with which I could configure the VM like
> 
>   $ qemu -vnc :0 -monitor stdio -preconfig
>     ... in theory blockdev-add and other backend creation would go here...
>   (qemu) x-create-onboard-devices
>   (qemu) device_add virtio-mouse-pci
>   (qemu) cont
> 
> Here, x-create-onboard-devices creates enough of the machine to make
> it possible to issue device_add monitor commands equivalent to
> the -device command line.
> 
> However, I'm not posting that part because the above is not the
> final state of the QMP interface.  The final QMP interface would have
> three commands (machine-set, accel-set, machine-set-memory) that
> bring the VM through successive phases of initialization corresponding
> roughly to qemu_apply_machine_options (-smp, -boot, -M, -cpu?),
> configure_accelerators (-accel) and qemu_finish_machine_init (-m, -M memdev);
> after these three steps, one of migrate-incoming, cont, loadvm or
> finish-machine-init (the latter of which is equivalent to -S on the
> command line) leaves preconfig mode.  For more information see
> https://wiki.qemu.org/User:Paolo_Bonzini/Machine_init_sequence#Basic_phases.
> 
> Based-on: <20201026143028.3034018-1-pbonzini@redhat.com>
> 
> Paolo Bonzini (29):
>   trace: remove argument from trace_init_file
>   semihosting: fix order of initialization functions
>   vl: extract validation of -smp to machine.c
>   vl: remove bogus check
>   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 new functions
>   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
>   vl: separate qemu_create_machine
>   vl: separate qemu_apply_machine_options
>   vl: separate qemu_resolve_machine_memdev
>   vl: initialize displays before preconfig loop
>   vl: move -global check earlier
>   migration, vl: start migration via qmp_migrate_incoming
>   vl: start VM via qmp_cont
>   hmp: introduce cmd_available
>   remove preconfig state
>   vl: remove separate preconfig main_loop
>   vl: allow -incoming defer with -preconfig
> 
>  bsd-user/main.c                      |    6 +-
>  hw/core/machine-qmp-cmds.c           |    5 +-
>  hw/core/machine.c                    |   27 +
>  include/hw/boards.h                  |    1 +
>  include/hw/qdev-core.h               |    8 -
>  include/migration/misc.h             |    1 -
>  include/qapi/qmp/dispatch.h          |    1 +
>  include/sysemu/runstate.h            |    1 -
>  linux-user/main.c                    |    6 +-
>  migration/migration.c                |   37 +-
>  monitor/hmp.c                        |   23 +-
>  monitor/qmp-cmds.c                   |   10 -
>  qapi/qmp-dispatch.c                  |    5 +-
>  qapi/run-state.json                  |    5 +-
>  qemu-img.c                           |    6 +-
>  qemu-io.c                            |    6 +-
>  qemu-nbd.c                           |    6 +-
>  scsi/qemu-pr-helper.c                |    6 +-
>  softmmu/qdev-monitor.c               |   18 +-
>  softmmu/vl.c                         | 1796 +++++++++++++-------------
>  storage-daemon/qemu-storage-daemon.c |    9 +-
>  stubs/meson.build                    |    1 +
>  stubs/qmp-command-available.c        |    7 +
>  trace/control.c                      |   10 +-
>  trace/control.h                      |   12 +-
>  25 files changed, 1021 insertions(+), 992 deletions(-)
>  create mode 100644 stubs/qmp-command-available.c
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 05/29] vl: split various early command line options to a separate function
  2020-11-02 15:30   ` Igor Mammedov
@ 2020-11-02 16:33     ` Paolo Bonzini
  0 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-02 16:33 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 02/11/20 16:30, Igor Mammedov wrote:
> On Tue, 27 Oct 2020 14:21:20 -0400
> 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>
>> ---
>>  softmmu/vl.c | 202 ++++++++++++++++++++++++++++-----------------------
>>  1 file changed, 113 insertions(+), 89 deletions(-)
>>
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
> [...]
>> +
>> +static void qemu_maybe_daemonize(const char *pid_file)
> 
> why it's _maybe_ ?
> It looks to me as just deamonize (or die which could be omitted)

Because os_daemonize() in turn only daemonize if the corresponding
option was set:

    void os_daemonize(void)
    {
        if (daemonize) {
            pid_t pid;
            int fds[2];
    ...

Paolo

>> +{
>> +    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);
>> +}
> [...]
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-11-02 15:57 ` [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Igor Mammedov
@ 2020-11-02 16:34   ` Paolo Bonzini
  2020-11-03 12:57     ` Igor Mammedov
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-02 16:34 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 02/11/20 16:57, Igor Mammedov wrote:
>> The main improvements with respect to v1 are:
> series no longer applies to master
> what commit if was based on?
> 

It's based on 20201026143028.3034018-1-pbonzini@redhat.com (which you
should be able to get through patchew).

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-11-02 16:34   ` Paolo Bonzini
@ 2020-11-03 12:57     ` Igor Mammedov
  2020-11-03 14:37       ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-03 12:57 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Mon, 2 Nov 2020 17:34:00 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 02/11/20 16:57, Igor Mammedov wrote:
> >> The main improvements with respect to v1 are:  
> > series no longer applies to master
> > what commit if was based on?
> >   
> 
> It's based on 20201026143028.3034018-1-pbonzini@redhat.com (which you
> should be able to get through patchew).

Not sure what you mean and how to do that.
Is it possible to share v2 as a git tree somewhere?

> 
> Paolo
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-11-03 12:57     ` Igor Mammedov
@ 2020-11-03 14:37       ` Paolo Bonzini
  2020-11-20 16:19         ` Igor Mammedov
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-03 14:37 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 03/11/20 13:57, Igor Mammedov wrote:
>> It's based on 20201026143028.3034018-1-pbonzini@redhat.com (which you
>> should be able to get through patchew).
> Not sure what you mean and how to do that.
> Is it possible to share v2 as a git tree somewhere?

I pushed it to for-6.0 on my gitlab repo.  There's a lot more stuff in
the branch, but these patches are at the top.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions
  2020-10-27 18:21 ` [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions Paolo Bonzini
@ 2020-11-11 19:29   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-11 19:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:23 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> The 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 250 +++++++++++++++++++++++++++------------------------
>  1 file changed, 135 insertions(+), 115 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index a086cd7066..f9bae50c27 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -120,6 +120,9 @@
>  static const char *cpu_option;
>  static const char *data_dir[16];
>  static int data_dir_idx;
> +static const char *mem_path;
> +static const char *boot_order;
> +static const char *boot_once;
>  enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>  int display_opengl;
>  const char* keyboard_layout = NULL;
> @@ -3000,6 +3003,135 @@ static void qemu_init_subsystems(void)
>      socket_init();
>  }
>  
> +/*
> + * Called after leaving preconfig state.  From here on runstate is
> + * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE.
> + */
> +static void qemu_finish_machine_init(void)
> +{
> +    MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
> +
> +    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 */
> +    machine_run_board_init(current_machine);
> +
> +    /*
> +     * TODO To drop support for deprecated bogus if=..., move
> +     * drive_check_orphaned() here, replacing this call.  Also drop
> +     * its deprecation warning, along with DriveInfo member
> +     * @claimed_by_board.
> +     */
> +    drive_mark_claimed_by_board();
> +
> +    realtime_init();
> +
> +    if (hax_enabled()) {
> +        /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
> +        hax_sync_vcpus();
> +    }
> +}
> +
> +static void qemu_create_cli_devices(void)
> +{
> +    soundhw_init();
> +
> +    qemu_opts_foreach(qemu_find_opts("fw_cfg"),
> +                      parse_fw_cfg, fw_cfg_find(), &error_fatal);
> +
> +    /* init USB devices */
> +    if (machine_usb(current_machine)) {
> +        if (foreach_device_config(DEV_USB, usb_parse) < 0)
> +            exit(1);
> +    }
> +
> +    /* init generic devices */
> +    rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
> +    qemu_opts_foreach(qemu_find_opts("device"),
> +                      device_init_func, NULL, &error_fatal);
> +    rom_reset_order_override();
> +}
> +
> +static void qemu_machine_creation_done(void)
> +{
> +    DisplayState *ds;
> +
> +    cpu_synchronize_all_post_init();
> +
> +    /* Did we create any drives that we failed to create a device for? */
> +    drive_check_orphaned();
> +
> +    /* Don't warn about the default network setup that you get if
> +     * no command line -net or -netdev options are specified. There
> +     * are two cases that we would otherwise complain about:
> +     * (1) board doesn't support a NIC but the implicit "-net nic"
> +     * requested one
> +     * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
> +     * sets up a nic that isn't connected to anything.
> +     */
> +    if (!default_net && (!qtest_enabled() || has_defaults)) {
> +        net_check_clients();
> +    }
> +
> +    if (boot_once) {
> +        qemu_boot_set(boot_once, &error_fatal);
> +        qemu_register_reset(restore_boot_order, g_strdup(boot_order));
> +    }
> +
> +    /* init local displays */
> +    ds = init_displaystate();
> +    qemu_display_init(ds, &dpy);
> +
> +    /* must be after terminal init, SDL library changes signal handlers */
> +    os_setup_signal_handling();
> +
> +    /* init remote displays */
> +#ifdef CONFIG_VNC
> +    qemu_opts_foreach(qemu_find_opts("vnc"),
> +                      vnc_init_func, NULL, &error_fatal);
> +#endif
> +
> +    if (using_spice) {
> +        qemu_spice.display_init();
> +    }
> +
> +    if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
> +        exit(1);
> +    }
> +
> +    qdev_machine_creation_done();
> +
> +    /* TODO: once all bus devices are qdevified, this should be done
> +     * when bus is created by qdev.c */
> +    /*
> +     * TODO: If we had a main 'reset container' that the whole system
> +     * lived in, we could reset that using the multi-phase reset
> +     * APIs. For the moment, we just reset the sysbus, which will cause
> +     * all devices hanging off it (and all their child buses, recursively)
> +     * to be reset. Note that this will *not* reset any Device objects
> +     * which are not attached to some part of the qbus tree!
> +     */
> +    qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
> +    qemu_run_machine_init_done_notifiers();
> +
> +    if (rom_check_and_register_reset() != 0) {
> +        error_report("rom check and register reset failed");
> +        exit(1);
> +    }
> +
> +    replay_start();
> +
> +    /* 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_RESET);
> +    qemu_system_reset(SHUTDOWN_CAUSE_NONE);
> +    register_global_state();
> +}
> +
>  void qemu_init(int argc, char **argv, char **envp)
>  {
>      int i;
> @@ -3007,9 +3139,6 @@ void qemu_init(int argc, char **argv, char **envp)
>      int linux_boot;
>      const char *initrd_filename;
>      const char *kernel_filename, *kernel_cmdline;
> -    const char *boot_order = NULL;
> -    const char *boot_once = NULL;
> -    DisplayState *ds;
>      QemuOpts *opts, *machine_opts;
>      QemuOpts *icount_opts = NULL, *accel_opts = NULL;
>      QemuOptsList *olist;
> @@ -3026,7 +3155,6 @@ void qemu_init(int argc, char **argv, char **envp)
>      uint64_t ram_slots = 0;
>      FILE *vmstate_dump_file = NULL;
>      Error *err = NULL;
> -    const char *mem_path = NULL;
>      bool have_custom_ram_size;
>      BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
>      QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
> @@ -4346,117 +4474,10 @@ void qemu_init(int argc, char **argv, char **envp)
>      /* do monitor/qmp handling at preconfig state if requested */
>      qemu_main_loop();
>  
> -    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 */
> -    machine_run_board_init(current_machine);
> -
> -    /*
> -     * TODO To drop support for deprecated bogus if=..., move
> -     * drive_check_orphaned() here, replacing this call.  Also drop
> -     * its deprecation warning, along with DriveInfo member
> -     * @claimed_by_board.
> -     */
> -    drive_mark_claimed_by_board();
> -
> -    realtime_init();
> +    qemu_finish_machine_init();
> +    qemu_create_cli_devices();
> +    qemu_machine_creation_done();
>  
> -    soundhw_init();
> -
> -    if (hax_enabled()) {
> -        hax_sync_vcpus();
> -    }
> -
> -    qemu_opts_foreach(qemu_find_opts("fw_cfg"),
> -                      parse_fw_cfg, fw_cfg_find(), &error_fatal);
> -
> -    /* init USB devices */
> -    if (machine_usb(current_machine)) {
> -        if (foreach_device_config(DEV_USB, usb_parse) < 0)
> -            exit(1);
> -    }
> -
> -    /* init generic devices */
> -    rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
> -    qemu_opts_foreach(qemu_find_opts("device"),
> -                      device_init_func, NULL, &error_fatal);
> -
> -    cpu_synchronize_all_post_init();
> -
> -    rom_reset_order_override();
> -
> -    /* Did we create any drives that we failed to create a device for? */
> -    drive_check_orphaned();
> -
> -    /* Don't warn about the default network setup that you get if
> -     * no command line -net or -netdev options are specified. There
> -     * are two cases that we would otherwise complain about:
> -     * (1) board doesn't support a NIC but the implicit "-net nic"
> -     * requested one
> -     * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
> -     * sets up a nic that isn't connected to anything.
> -     */
> -    if (!default_net && (!qtest_enabled() || has_defaults)) {
> -        net_check_clients();
> -    }
> -
> -    if (boot_once) {
> -        qemu_boot_set(boot_once, &error_fatal);
> -        qemu_register_reset(restore_boot_order, g_strdup(boot_order));
> -    }
> -
> -    /* init local displays */
> -    ds = init_displaystate();
> -    qemu_display_init(ds, &dpy);
> -
> -    /* must be after terminal init, SDL library changes signal handlers */
> -    os_setup_signal_handling();
> -
> -    /* init remote displays */
> -#ifdef CONFIG_VNC
> -    qemu_opts_foreach(qemu_find_opts("vnc"),
> -                      vnc_init_func, NULL, &error_fatal);
> -#endif
> -
> -    if (using_spice) {
> -        qemu_spice.display_init();
> -    }
> -
> -    if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
> -        exit(1);
> -    }
> -
> -    qdev_machine_creation_done();
> -
> -    /* TODO: once all bus devices are qdevified, this should be done
> -     * when bus is created by qdev.c */
> -    /*
> -     * TODO: If we had a main 'reset container' that the whole system
> -     * lived in, we could reset that using the multi-phase reset
> -     * APIs. For the moment, we just reset the sysbus, which will cause
> -     * all devices hanging off it (and all their child buses, recursively)
> -     * to be reset. Note that this will *not* reset any Device objects
> -     * which are not attached to some part of the qbus tree!
> -     */
> -    qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
> -    qemu_run_machine_init_done_notifiers();
> -
> -    if (rom_check_and_register_reset() != 0) {
> -        error_report("rom check and register reset failed");
> -        exit(1);
> -    }
> -
> -    replay_start();
> -
> -    /* 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_RESET);
> -    qemu_system_reset(SHUTDOWN_CAUSE_NONE);
> -    register_global_state();
>      if (loadvm) {
>          Error *local_err = NULL;
>          if (load_snapshot(loadvm, &local_err) < 0) {
> @@ -4475,7 +4496,6 @@ void qemu_init(int argc, char **argv, char **envp)
>          dump_vmstate_json_to_file(vmstate_dump_file);
>          exit(0);
>      }
> -
>      if (incoming) {
>          Error *local_err = NULL;
>          qemu_start_incoming_migration(incoming, &local_err);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 09/29] vl: extract various command line validation snippets to a new function
  2020-10-27 18:21 ` [PATCH 09/29] vl: extract various command line validation snippets to a new function Paolo Bonzini
@ 2020-11-11 19:39   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-11 19:39 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:24 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  hw/core/machine.c |  1 +
>  softmmu/vl.c      | 78 +++++++++++++++++++++++------------------------
>  2 files changed, 40 insertions(+), 39 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index d84b84463c..f5e559c493 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -878,6 +878,7 @@ static void machine_initfn(Object *obj)
>      ms->dump_guest_core = true;
>      ms->mem_merge = true;
>      ms->enable_graphics = true;
> +    ms->kernel_cmdline = g_strdup("");
>  
>      if (mc->nvdimm_supported) {
>          Object *obj = OBJECT(ms);
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index f9bae50c27..3316c5534c 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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;
> @@ -2870,6 +2871,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;
> @@ -3136,9 +3170,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;
> @@ -3147,7 +3178,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;
> @@ -4068,6 +4098,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.
>       */
> @@ -4082,12 +4114,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();
> @@ -4191,12 +4217,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) {
> @@ -4327,11 +4347,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");
> @@ -4352,24 +4367,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);
>      }



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 11/29] vl: extract various command line desugaring snippets to a new function
  2020-10-27 18:21 ` [PATCH 11/29] vl: extract various command line desugaring snippets to a new function Paolo Bonzini
@ 2020-11-11 19:57   ` Igor Mammedov
  2020-11-11 20:04     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-11 19:57 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:26 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 40 ++++++++++++++++++++++------------------
>  1 file changed, 22 insertions(+), 18 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index c2a5ee61f9..6749109b29 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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 */
Is there a reason for it not being static?

>  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;
> @@ -2910,6 +2911,25 @@ static void qemu_validate_options(void)
>  #endif
>  }
>  
> +static void qemu_process_sugar_options(void)
> +{
> +    if (mem_prealloc) {
> +        char *val;
> +
> +        val = g_strdup_printf("%d",
> +                 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
if -smp isn't present it value used here was mc->default_cpus,
which in most cases is 1 modulo some ARM boards and riscv.

But we probably don't care much how this heuristic is picked up for default_cpus,
is users really care about how many treads QEMU spawns for preallocating RAM,
they should use explicit -object memory-backend-foo,prealloc-threads=X explicitly


> +        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;
> @@ -3174,7 +3194,6 @@ static void qemu_machine_creation_done(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;
> @@ -3193,7 +3212,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);
> @@ -4104,6 +4122,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.
> @@ -4155,15 +4174,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.
> @@ -4422,12 +4432,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. */



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive
  2020-10-27 18:21 ` [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive Paolo Bonzini
@ 2020-11-11 19:58   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-11 19:58 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:25 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Just like -incoming.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 3316c5534c..c2a5ee61f9 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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;
> @@ -2890,6 +2891,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");
> @@ -3175,7 +3181,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;



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 11/29] vl: extract various command line desugaring snippets to a new function
  2020-11-11 19:57   ` Igor Mammedov
@ 2020-11-11 20:04     ` Paolo Bonzini
  2020-11-18 16:55       ` Igor Mammedov
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-11 20:04 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]

Il mer 11 nov 2020, 20:57 Igor Mammedov <imammedo@redhat.com> ha scritto:

> On Tue, 27 Oct 2020 14:21:26 -0400
> Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  softmmu/vl.c | 40 ++++++++++++++++++++++------------------
> >  1 file changed, 22 insertions(+), 18 deletions(-)
> >
> > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > index c2a5ee61f9..6749109b29 100644
> > --- a/softmmu/vl.c
> > +++ b/softmmu/vl.c
> > @@ -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 */
> Is there a reason for it not being static?
>

I will check if I am using it later in the series, but I don't think so.


> >  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;
> > @@ -2910,6 +2911,25 @@ static void qemu_validate_options(void)
> >  #endif
> >  }
> >
> > +static void qemu_process_sugar_options(void)
> > +{
> > +    if (mem_prealloc) {
> > +        char *val;
> > +
> > +        val = g_strdup_printf("%d",
> > +                 (uint32_t)
> qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
> if -smp isn't present it value used here was mc->default_cpus,
> which in most cases is 1 modulo some ARM boards and riscv.
>

Yes, I remember noticing that but decided I would not care. I should have
added it to the commit message, though.

Paolo

[-- Attachment #2: Type: text/html, Size: 2934 bytes --]

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 12/29] vl: create "-net nic -net user" default earlier
  2020-10-27 18:21 ` [PATCH 12/29] vl: create "-net nic -net user" default earlier Paolo Bonzini
@ 2020-11-18 14:43   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 14:43 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:27 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Create it together with other default backends, even though the processing is
> done later.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 6749109b29..f643333f7e 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -4254,6 +4254,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++;
> @@ -4389,14 +4397,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);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 17/29] vl: separate qemu_create_early_backends
  2020-10-27 18:21 ` [PATCH 17/29] vl: separate qemu_create_early_backends Paolo Bonzini
@ 2020-11-18 16:29   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 16:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:32 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> "Early" backends are created before the machine and can be used as
> machine options.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 123 +++++++++++++++++++++++++++------------------------
>  1 file changed, 65 insertions(+), 58 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index ebe3d46889..109036c089 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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);
> @@ -2696,6 +2698,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
> @@ -2703,7 +2757,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);
>  }
>  
>  
> @@ -3321,7 +3375,6 @@ static void qemu_machine_creation_done(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;
> @@ -3334,7 +3387,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);
> @@ -4308,52 +4360,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,



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 18/29] vl: separate qemu_create_late_backends
  2020-10-27 18:21 ` [PATCH 18/29] vl: separate qemu_create_late_backends Paolo Bonzini
@ 2020-11-18 16:33   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 16:33 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:33 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> "Late" backends are created after the machine.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 64 ++++++++++++++++++++++++++--------------------------
>  1 file changed, 32 insertions(+), 32 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 109036c089..0c390b979e 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2755,11 +2755,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);
> +
> +    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);
> +
> +    /* now chardevs have been created we may have semihosting to connect */
> +    qemu_semihosting_connect_chardevs();
> +    qemu_semihosting_console_init();
> +}
>  
>  static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
>                                 MachineClass *mc)
> @@ -3385,7 +3415,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);
> @@ -4402,10 +4431,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");
> @@ -4426,32 +4451,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);
> -
> -    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);
> -
> -    /* now chardevs have been created we may have semihosting to connect */
> -    qemu_semihosting_connect_chardevs();
> -    qemu_semihosting_console_init();
> +    qemu_create_late_backends();
>  
>      current_machine->boot_order = boot_order;
>  



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 19/29] vl: separate qemu_create_machine
  2020-10-27 18:21 ` [PATCH 19/29] vl: separate qemu_create_machine Paolo Bonzini
@ 2020-11-18 16:45   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 16:45 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:34 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 111 +++++++++++++++++++++++++++------------------------
>  1 file changed, 59 insertions(+), 52 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 0c390b979e..38ad3cc895 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -133,6 +133,8 @@ static const char *boot_order;
>  static const char *boot_once;
>  static const char *incoming;
>  static const char *loadvm;
> +static ram_addr_t maxram_size;
> +static uint64_t ram_slots;
>  static int display_remote;
>  static int snapshot;
>  static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
> @@ -2791,8 +2793,13 @@ static void qemu_create_late_backends(void)
>      qemu_semihosting_console_init();
>  }
>  
> -static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
> -                               MachineClass *mc)
> +static bool have_custom_ram_size(void)
> +{
> +    QemuOpts *opts = qemu_find_opts_singleton("memory");
> +    return !!qemu_opt_get(opts, "size");
> +}
> +
> +static void set_memory_options(MachineClass *mc)
>  {
>      uint64_t sz;
>      const char *mem_str;
> @@ -2842,7 +2849,7 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
>  
>      /* store value for the future use */
>      qemu_opt_set_number(opts, "size", ram_size, &error_abort);
> -    *maxram_size = ram_size;
> +    maxram_size = ram_size;
>  
>      if (qemu_opt_get(opts, "maxmem")) {
>          uint64_t slots;
> @@ -2863,15 +2870,58 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
>              exit(EXIT_FAILURE);
>          }
>  
> -        *maxram_size = sz;
> -        *ram_slots = slots;
> +        maxram_size = sz;
> +        ram_slots = slots;
>      } else if (qemu_opt_get(opts, "slots")) {
>          error_report("invalid -m option value: missing 'maxmem' option");
>          exit(EXIT_FAILURE);
>      }
>  
>      loc_pop(&loc);
> -    return !!mem_str;
> +}
> +
> +static void qemu_create_machine(MachineClass *machine_class)
> +{
> +    object_set_machine_compat_props(machine_class->compat_props);
> +
> +    set_memory_options(machine_class);
> +
> +    current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
> +    if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
> +        exit(0);
> +    }
> +    object_property_add_child(object_get_root(), "machine",
> +                              OBJECT(current_machine));
> +    object_property_add_child(container_get(OBJECT(current_machine),
> +                                            "/unattached"),
> +                              "sysbus", OBJECT(sysbus_get_default()));
> +
> +    if (machine_class->minimum_page_bits) {
> +        if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
> +            /* This would be a board error: specifying a minimum smaller than
> +             * a target's compile-time fixed setting.
> +             */
> +            g_assert_not_reached();
> +        }
> +    }
> +
> +    cpu_exec_init_all();
> +
> +    if (machine_class->hw_version) {
> +        qemu_set_hw_version(machine_class->hw_version);
> +    }
> +
> +    machine_smp_parse(current_machine,
> +        qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
> +
> +    /*
> +     * Get the default machine options from the machine if it is not already
> +     * specified either by the configuration file or by the command line.
> +     */
> +    if (machine_class->default_machine_opts) {
> +        qemu_opts_set_defaults(qemu_find_opts("machine"),
> +                               machine_class->default_machine_opts, 0);
> +    }
>  }
>  
>  static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
> @@ -3412,10 +3462,7 @@ void qemu_init(int argc, char **argv, char **envp)
>      const char *optarg;
>      MachineClass *machine_class;
>      bool userconfig = true;
> -    ram_addr_t maxram_size;
> -    uint64_t ram_slots = 0;
>      FILE *vmstate_dump_file = NULL;
> -    bool have_custom_ram_size;
>  
>      qemu_add_opts(&qemu_drive_opts);
>      qemu_add_drive_opts(&qemu_legacy_drive_opts);
> @@ -4344,48 +4391,7 @@ void qemu_init(int argc, char **argv, char **envp)
>  
>      configure_rtc(qemu_find_opts_singleton("rtc"));
>  
> -    machine_class = select_machine();
> -    object_set_machine_compat_props(machine_class->compat_props);
> -
> -    have_custom_ram_size = set_memory_options(&ram_slots, &maxram_size,
> -                                              machine_class);
> -
> -    current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
> -    if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
> -        exit(0);
> -    }
> -    object_property_add_child(object_get_root(), "machine",
> -                              OBJECT(current_machine));
> -    object_property_add_child(container_get(OBJECT(current_machine),
> -                                            "/unattached"),
> -                              "sysbus", OBJECT(sysbus_get_default()));
> -
> -    if (machine_class->minimum_page_bits) {
> -        if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
> -            /* This would be a board error: specifying a minimum smaller than
> -             * a target's compile-time fixed setting.
> -             */
> -            g_assert_not_reached();
> -        }
> -    }
> -
> -    cpu_exec_init_all();
> -
> -    if (machine_class->hw_version) {
> -        qemu_set_hw_version(machine_class->hw_version);
> -    }
> -
> -    machine_smp_parse(current_machine,
> -        qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
> -
> -    /*
> -     * Get the default machine options from the machine if it is not already
> -     * specified either by the configuration file or by the command line.
> -     */
> -    if (machine_class->default_machine_opts) {
> -        qemu_opts_set_defaults(qemu_find_opts("machine"),
> -                               machine_class->default_machine_opts, 0);
> -    }
> +    qemu_create_machine(select_machine());
>  
>      qemu_disable_default_devices();
>      qemu_create_default_devices();
> @@ -4420,6 +4426,7 @@ void qemu_init(int argc, char **argv, char **envp)
>       * called from configure_accelerator().
>       */
>  
> +    machine_class = MACHINE_GET_CLASS(current_machine);
>      if (!qtest_enabled() && machine_class->deprecation_reason) {
>          error_report("Machine type '%s' is deprecated: %s",
>                       machine_class->name, machine_class->deprecation_reason);
> @@ -4473,7 +4480,7 @@ void qemu_init(int argc, char **argv, char **envp)
>              exit(EXIT_FAILURE);
>          }
>          backend_size = object_property_get_uint(backend, "size",  &error_abort);
> -        if (have_custom_ram_size && backend_size != ram_size) {
> +        if (have_custom_ram_size() && backend_size != ram_size) {
>                  error_report("Size specified by -m option must match size of "
>                               "explicitly specified 'memory-backend' property");
>                  exit(EXIT_FAILURE);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 11/29] vl: extract various command line desugaring snippets to a new function
  2020-11-11 20:04     ` Paolo Bonzini
@ 2020-11-18 16:55       ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 16:55 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Wed, 11 Nov 2020 21:04:53 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il mer 11 nov 2020, 20:57 Igor Mammedov <imammedo@redhat.com> ha scritto:
> 
> > On Tue, 27 Oct 2020 14:21:26 -0400
> > Paolo Bonzini <pbonzini@redhat.com> wrote:
> >  
> > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > > ---
> > >  softmmu/vl.c | 40 ++++++++++++++++++++++------------------
> > >  1 file changed, 22 insertions(+), 18 deletions(-)
> > >
> > > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > > index c2a5ee61f9..6749109b29 100644
> > > --- a/softmmu/vl.c
> > > +++ b/softmmu/vl.c
> > > @@ -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 */  
> > Is there a reason for it not being static?
> >  
> 
> I will check if I am using it later in the series, but I don't think so.
with it fixed to static

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> 
> 
> > >  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;
> > > @@ -2910,6 +2911,25 @@ static void qemu_validate_options(void)
> > >  #endif
> > >  }
> > >
> > > +static void qemu_process_sugar_options(void)
> > > +{
> > > +    if (mem_prealloc) {
> > > +        char *val;
> > > +
> > > +        val = g_strdup_printf("%d",
> > > +                 (uint32_t)  
> > qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
> > if -smp isn't present it value used here was mc->default_cpus,
> > which in most cases is 1 modulo some ARM boards and riscv.
> >  
> 
> Yes, I remember noticing that but decided I would not care. I should have
> added it to the commit message, though.
> 
> Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 20/29] vl: separate qemu_apply_machine_options
  2020-10-27 18:21 ` [PATCH 20/29] vl: separate qemu_apply_machine_options Paolo Bonzini
@ 2020-11-18 16:57   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-18 16:57 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:35 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 66 +++++++++++++++++++++++++++++-----------------------
>  1 file changed, 37 insertions(+), 29 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 38ad3cc895..9a3c92387e 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2700,6 +2700,41 @@ static bool object_create_early(const char *type, QemuOpts *opts)
>      return true;
>  }
>  
> +static void qemu_apply_machine_options(void)
> +{
> +    MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
> +    QemuOpts *machine_opts = qemu_get_machine_opts();
> +    QemuOpts *opts;
> +
> +    qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
> +                     &error_fatal);
> +    current_machine->ram_size = ram_size;
> +    current_machine->maxram_size = maxram_size;
> +    current_machine->ram_slots = ram_slots;
> +
> +    opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
> +    if (opts) {
> +        boot_order = qemu_opt_get(opts, "order");
> +        if (boot_order) {
> +            validate_bootdevices(boot_order, &error_fatal);
> +        }
> +
> +        boot_once = qemu_opt_get(opts, "once");
> +        if (boot_once) {
> +            validate_bootdevices(boot_once, &error_fatal);
> +        }
> +
> +        boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
> +        boot_strict = qemu_opt_get_bool(opts, "strict", false);
> +    }
> +
> +    if (!boot_order) {
> +        boot_order = machine_class->default_boot_order;
> +    }
> +
> +    current_machine->boot_order = boot_order;
> +}
> +
>  static void qemu_create_early_backends(void)
>  {
>      MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
> @@ -3455,7 +3490,7 @@ static void qemu_machine_creation_done(void)
>  
>  void qemu_init(int argc, char **argv, char **envp)
>  {
> -    QemuOpts *opts, *machine_opts;
> +    QemuOpts *opts;
>      QemuOpts *icount_opts = NULL, *accel_opts = NULL;
>      QemuOptsList *olist;
>      int optind;
> @@ -4397,12 +4432,7 @@ void qemu_init(int argc, char **argv, char **envp)
>      qemu_create_default_devices();
>      qemu_create_early_backends();
>  
> -    machine_opts = qemu_get_machine_opts();
> -    qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
> -                     &error_fatal);
> -    current_machine->ram_size = ram_size;
> -    current_machine->maxram_size = maxram_size;
> -    current_machine->ram_slots = ram_slots;
> +    qemu_apply_machine_options();
>  
>      /*
>       * Note: uses machine properties such as kernel-irqchip, must run
> @@ -4438,30 +4468,8 @@ void qemu_init(int argc, char **argv, char **envp)
>       */
>      migration_object_init();
>  
> -    opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
> -    if (opts) {
> -        boot_order = qemu_opt_get(opts, "order");
> -        if (boot_order) {
> -            validate_bootdevices(boot_order, &error_fatal);
> -        }
> -
> -        boot_once = qemu_opt_get(opts, "once");
> -        if (boot_once) {
> -            validate_bootdevices(boot_once, &error_fatal);
> -        }
> -
> -        boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
> -        boot_strict = qemu_opt_get_bool(opts, "strict", false);
> -    }
> -
> -    if (!boot_order) {
> -        boot_order = machine_class->default_boot_order;
> -    }
> -
>      qemu_create_late_backends();
>  
> -    current_machine->boot_order = boot_order;
> -
>      /* parse features once if machine provides default cpu_type */
>      current_machine->cpu_type = machine_class->default_cpu_type;
>      if (cpu_option) {



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 21/29] vl: separate qemu_resolve_machine_memdev
  2020-10-27 18:21 ` [PATCH 21/29] vl: separate qemu_resolve_machine_memdev Paolo Bonzini
@ 2020-11-20 13:15   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 13:15 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:36 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> This is a bit nasty: the machine is storing a string and later
> resolving it.  We probably want to remove the memdev property
> and instead make this a memory-set command.  "-M memdev" can be
> handled as a legacy option that is special cased by
> machine_set_property.
I'd treat this description as topic starter and drop it from this patch in v2.
with that,
  Reviewed-by: Igor Mammedov <imammedo@redhat.com>

how  memory-set would help or be any better than memdev?

memdev should be a link property, but due to RAM allocation
being dependent on used accel we can't create actual backend
until accelerator is initialized (i.e. after machine options parsed,
which forced me to make memdev a string that refers to a backend
created later).

If we can make RAM allocation independent from used accelerator
(if I recall right it has TCG dependency) and if we split -m CLI
handling and default ram_memdev_id (which is implicit CLI),
then we can make -M memdev a link and move RAM backends to
qemu_create_early_backends() time.

Which in context of creating machine via QMP would imply that
link should be set explicitly via QMP after backend is created.

Flow could look like this:
CLI part:
  -m / defaults - preps and 'if not NUMA'
     executes QMP
       object_add memory-backend-foo,size=X,id=(ram_memdev_id)
     in case -M memory-backend is not set explicitly, or fetch
     id of explicitly provided backend (which would be created by
     qemu_create_early_backends)
QMP part:
   object_add machine_foo,id=my_machine
   set (link) my_machine.memory-backend=(ram_memdev_id)

that way we do no need to create a separate memory-set command,
we can  handle it as a normal property, where all compat stuff
is kept in CLI part.

For CLI part handling there are 2 caveats:

 * Xen doesn't use memdev at all, it allocates memory region directly.
   Not sure what we should do in this case
   (may be we can create a separate xen-ram backend for it and remove
    'mr == &ram_memory' in xen_ram_alloc() hack)

 * legacy S390 machine types (<5.0) fixup ram_size before creating backend, if user
   provided value is not correct 5c30ef937f5 (i.e. not aligned properly).
   I guess we are stuck with it, given it's version-ed machine type. The rest of the code was
   fixed to error-out in the case board doesn't like -m value.
   Or we can treat it as user error (which should be corrected by user) and deprecate/remove fixup. 

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 70 +++++++++++++++++++++++++++-------------------------
>  1 file changed, 37 insertions(+), 33 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 9a3c92387e..1485aba8be 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2834,6 +2834,42 @@ static bool have_custom_ram_size(void)
>      return !!qemu_opt_get(opts, "size");
>  }
>  
> +static void qemu_resolve_machine_memdev(void)
> +{
> +    if (current_machine->ram_memdev_id) {
> +        Object *backend;
> +        ram_addr_t backend_size;
> +
> +        backend = object_resolve_path_type(current_machine->ram_memdev_id,
> +                                           TYPE_MEMORY_BACKEND, NULL);
> +        if (!backend) {
> +            error_report("Memory backend '%s' not found",
> +                         current_machine->ram_memdev_id);
> +            exit(EXIT_FAILURE);
> +        }
> +        backend_size = object_property_get_uint(backend, "size",  &error_abort);
> +        if (have_custom_ram_size() && backend_size != ram_size) {
> +                error_report("Size specified by -m option must match size of "
> +                             "explicitly specified 'memory-backend' property");
> +                exit(EXIT_FAILURE);
> +        }
> +        if (mem_path) {
> +            error_report("'-mem-path' can't be used together with"
> +                         "'-machine memory-backend'");
> +            exit(EXIT_FAILURE);
> +        }
> +        ram_size = backend_size;
> +    }
> +
> +    if (!xen_enabled()) {
> +        /* On 32-bit hosts, QEMU is limited by virtual address space */
> +        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
> +            error_report("at most 2047 MB RAM can be simulated");
> +            exit(1);
> +        }
> +    }
> +}
> +
>  static void set_memory_options(MachineClass *mc)
>  {
>      uint64_t sz;
> @@ -4476,39 +4512,7 @@ void qemu_init(int argc, char **argv, char **envp)
>          current_machine->cpu_type = parse_cpu_option(cpu_option);
>      }
>  
> -    if (current_machine->ram_memdev_id) {
> -        Object *backend;
> -        ram_addr_t backend_size;
> -
> -        backend = object_resolve_path_type(current_machine->ram_memdev_id,
> -                                           TYPE_MEMORY_BACKEND, NULL);
> -        if (!backend) {
> -            error_report("Memory backend '%s' not found",
> -                         current_machine->ram_memdev_id);
> -            exit(EXIT_FAILURE);
> -        }
> -        backend_size = object_property_get_uint(backend, "size",  &error_abort);
> -        if (have_custom_ram_size() && backend_size != ram_size) {
> -                error_report("Size specified by -m option must match size of "
> -                             "explicitly specified 'memory-backend' property");
> -                exit(EXIT_FAILURE);
> -        }
> -        if (mem_path) {
> -            error_report("'-mem-path' can't be used together with"
> -                         "'-machine memory-backend'");
> -            exit(EXIT_FAILURE);
> -        }
> -        ram_size = backend_size;
> -    }
> -
> -    if (!xen_enabled()) {
> -        /* On 32-bit hosts, QEMU is limited by virtual address space */
> -        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
> -            error_report("at most 2047 MB RAM can be simulated");
> -            exit(1);
> -        }
> -    }
> -
> +    qemu_resolve_machine_memdev();
>      parse_numa_opts(current_machine);
>  
>      /* do monitor/qmp handling at preconfig state if requested */



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 23/29] vl: move -global check earlier
  2020-10-27 18:21 ` [PATCH 23/29] vl: move -global check earlier Paolo Bonzini
@ 2020-11-20 15:10   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 15:10 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:38 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> The check has no effect after both builtin and user-specified devices
> have been created.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index a46f1b9164..ae2854d8af 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -3489,6 +3489,8 @@ static void qemu_machine_creation_done(void)
>          net_check_clients();
>      }
>  
> +    qdev_prop_check_globals();
> +
>      if (boot_once) {
>          qemu_boot_set(boot_once, &error_fatal);
>          qemu_register_reset(restore_boot_order, g_strdup(boot_order));
> @@ -4548,7 +4550,6 @@ void qemu_init(int argc, char **argv, char **envp)
>          replay_vmstate_init();
>      }
>  
> -    qdev_prop_check_globals();
>      if (vmstate_dump_file) {
>          /* dump and exit */
>          dump_vmstate_json_to_file(vmstate_dump_file);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-10-27 18:21 ` [PATCH 22/29] vl: initialize displays before preconfig loop Paolo Bonzini
@ 2020-11-20 15:11   ` Igor Mammedov
  2020-11-20 15:53     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 15:11 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:37 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Displays should be available before the monitor starts, so that
> it is possible to use the graphical console to interact with
> the monitor itself.
> 
> This patch is quite ugly, but all this is temporary.  The double
> call to qemu_init_displays will go away as soon we can unify machine
> initialization between the preconfig and "normal" flows, and so will
> the preconfig_exit_requested variable (that is only preconfig_requested
> remains).
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Doesn't apply to yer for-6.0 branch

> ---
>  softmmu/vl.c | 58 ++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 36 insertions(+), 22 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 1485aba8be..a46f1b9164 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -137,6 +137,7 @@ static ram_addr_t maxram_size;
>  static uint64_t ram_slots;
>  static int display_remote;
>  static int snapshot;
> +static bool preconfig_requested;
>  static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
>  static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
>  static bool nographic = false;
> @@ -3210,12 +3211,12 @@ static void qemu_validate_options(void)
>            }
>      }
>  
> -    if (loadvm && !preconfig_exit_requested) {
> +    if (loadvm && preconfig_requested) {
>          error_report("'preconfig' and 'loadvm' options are "
>                       "mutually exclusive");
>          exit(EXIT_FAILURE);
>      }
> -    if (incoming && !preconfig_exit_requested) {
> +    if (incoming && preconfig_requested) {
>          error_report("'preconfig' and 'incoming' options are "
>                       "mutually exclusive");
>          exit(EXIT_FAILURE);
> @@ -3381,6 +3382,28 @@ static void qemu_init_subsystems(void)
>      socket_init();
>  }
>  
> +static void qemu_init_displays(void)
> +{
> +    DisplayState *ds;
> +
> +    /* init local displays */
> +    ds = init_displaystate();
> +    qemu_display_init(ds, &dpy);
> +
> +    /* must be after terminal init, SDL library changes signal handlers */
> +    os_setup_signal_handling();
> +
> +    /* init remote displays */
> +#ifdef CONFIG_VNC
> +    qemu_opts_foreach(qemu_find_opts("vnc"),
> +                      vnc_init_func, NULL, &error_fatal);
> +#endif
> +
> +    if (using_spice) {
> +        qemu_spice.display_init();
> +    }
> +}
> +
>  /*
>   * Called after leaving preconfig state.  From here on runstate is
>   * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE.
> @@ -3449,8 +3472,6 @@ static void qemu_create_cli_devices(void)
>  
>  static void qemu_machine_creation_done(void)
>  {
> -    DisplayState *ds;
> -
>      cpu_synchronize_all_post_init();
>  
>      /* Did we create any drives that we failed to create a device for? */
> @@ -3473,23 +3494,6 @@ static void qemu_machine_creation_done(void)
>          qemu_register_reset(restore_boot_order, g_strdup(boot_order));
>      }
>  
> -    /* init local displays */
> -    ds = init_displaystate();
> -    qemu_display_init(ds, &dpy);
> -
> -    /* must be after terminal init, SDL library changes signal handlers */
> -    os_setup_signal_handling();
> -
> -    /* init remote displays */
> -#ifdef CONFIG_VNC
> -    qemu_opts_foreach(qemu_find_opts("vnc"),
> -                      vnc_init_func, NULL, &error_fatal);
> -#endif
> -
> -    if (using_spice) {
> -        qemu_spice.display_init();
> -    }
> -
>      if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
>          exit(1);
>      }
> @@ -4094,6 +4098,7 @@ void qemu_init(int argc, char **argv, char **envp)
>                  break;
>              case QEMU_OPTION_preconfig:
>                  preconfig_exit_requested = false;
> +                preconfig_requested = true;
>                  break;
>              case QEMU_OPTION_enable_kvm:
>                  olist = qemu_find_opts("machine");
> @@ -4515,11 +4520,20 @@ void qemu_init(int argc, char **argv, char **envp)
>      qemu_resolve_machine_memdev();
>      parse_numa_opts(current_machine);
>  
> +    if (preconfig_requested) {
> +        qemu_init_displays();
> +    }
> +
>      /* do monitor/qmp handling at preconfig state if requested */
>      qemu_main_loop();
> -
>      qemu_finish_machine_init();
> +
>      qemu_create_cli_devices();
> +
> +    /* initialize displays after all errors have been reported */
> +    if (!preconfig_requested) {
> +        qemu_init_displays();
> +    }
>      qemu_machine_creation_done();
>  
>      if (loadvm) {



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-10-27 18:21 ` [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming Paolo Bonzini
@ 2020-11-20 15:34   ` Igor Mammedov
  2020-11-20 16:02     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 15:34 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, dgilbert

On Tue, 27 Oct 2020 14:21:39 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Make qemu_start_incoming_migration local to migration/migration.c.
> By using the runstate instead of a separate flag, vl need not do
> anything to setup deferred incoming migration.
> 
> qmp_migrate_incoming also does not need the deferred_incoming flag
> anymore, because "-incoming PROTOCOL" will clear the "once" flag
> before the main loop starts.  Therefore, later invocations of
> the migrate-incoming command will fail with the existing
> "The incoming migration has already been started" error message.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/migration/misc.h |  1 -
>  migration/migration.c    | 33 ++++++++-------------------------
>  softmmu/vl.c             | 11 +++++++----
>  3 files changed, 15 insertions(+), 30 deletions(-)
> 
> diff --git a/include/migration/misc.h b/include/migration/misc.h
> index 34e7d75713..bccc1b6b44 100644
> --- a/include/migration/misc.h
> +++ b/include/migration/misc.h
> @@ -58,7 +58,6 @@ void dump_vmstate_json_to_file(FILE *out_fp);
>  /* migration/migration.c */
>  void migration_object_init(void);
>  void migration_shutdown(void);
> -void qemu_start_incoming_migration(const char *uri, Error **errp);
>  bool migration_is_idle(void);
>  bool migration_is_active(MigrationState *);
>  void add_migration_state_change_notifier(Notifier *notify);
> diff --git a/migration/migration.c b/migration/migration.c
> index f48b03cac2..d078094c56 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -114,8 +114,6 @@
>  static NotifierList migration_state_notifiers =
>      NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
>  
> -static bool deferred_incoming;
> -
>  /* Messages sent on the return path from destination to source */
>  enum mig_rp_message_type {
>      MIG_RP_MSG_INVALID = 0,  /* Must be 0 */
> @@ -257,19 +255,6 @@ static bool migrate_late_block_activate(void)
>          MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE];
>  }
>  
> -/*
> - * Called on -incoming with a defer: uri.
> - * The migration can be started later after any parameters have been
> - * changed.
> - */
> -static void deferred_incoming_migration(Error **errp)
> -{
> -    if (deferred_incoming) {
> -        error_setg(errp, "Incoming migration already deferred");
> -    }
> -    deferred_incoming = true;
> -}
> -
>  /*
>   * Send a message on the return channel back to the source
>   * of the migration.
> @@ -380,16 +365,14 @@ void migrate_add_address(SocketAddress *address)
>      addrs->value = QAPI_CLONE(SocketAddress, address);
>  }
>  
> -void qemu_start_incoming_migration(const char *uri, Error **errp)
> +static void qemu_start_incoming_migration(const char *uri, Error **errp)
>  {
>      const char *p = NULL;
>  
>      qapi_event_send_migration(MIGRATION_STATUS_SETUP);
> -    if (!strcmp(uri, "defer")) {
> -        deferred_incoming_migration(errp);
> -    } else if (strstart(uri, "tcp:", &p) ||
> -               strstart(uri, "unix:", NULL) ||
> -               strstart(uri, "vsock:", NULL)) {
considering the last hunk does won't call qmp_migrate_incoming
if 'defer' was used, wouldn't we will lose QAPI event here?
not sure how important it to users,
Ccing David

> +    if (strstart(uri, "tcp:", &p) ||
> +        strstart(uri, "unix:", NULL) ||
> +        strstart(uri, "vsock:", NULL)) {
>          socket_start_incoming_migration(p ? p : uri, errp);
>  #ifdef CONFIG_RDMA
>      } else if (strstart(uri, "rdma:", &p)) {
> @@ -1926,14 +1909,14 @@ void qmp_migrate_incoming(const char *uri, Error **errp)
>      Error *local_err = NULL;
>      static bool once = true;
>  
> -    if (!deferred_incoming) {
> -        error_setg(errp, "For use with '-incoming defer'");
> -        return;
> -    }
>      if (!once) {
>          error_setg(errp, "The incoming migration has already been started");
>          return;
>      }
> +    if (!runstate_check(RUN_STATE_INMIGRATE)) {
> +        error_setg(errp, "'-incoming' was not specified on the command line");
> +        return;
> +    }
>  
>      qemu_start_incoming_migration(uri, &local_err);
>  
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index ae2854d8af..583366510b 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -109,6 +109,7 @@
>  #include "qapi/qapi-visit-block-core.h"
>  #include "qapi/qapi-visit-ui.h"
>  #include "qapi/qapi-commands-block-core.h"
> +#include "qapi/qapi-commands-migration.h"
>  #include "qapi/qapi-commands-run-state.h"
>  #include "qapi/qapi-commands-ui.h"
>  #include "qapi/qmp/qerror.h"
> @@ -4557,10 +4558,12 @@ void qemu_init(int argc, char **argv, char **envp)
>      }
>      if (incoming) {
>          Error *local_err = NULL;
> -        qemu_start_incoming_migration(incoming, &local_err);
> -        if (local_err) {
> -            error_reportf_err(local_err, "-incoming %s: ", incoming);
> -            exit(1);
> +        if (strcmp(incoming, "defer") != 0) {
> +            qmp_migrate_incoming(incoming, &local_err);
> +            if (local_err) {
> +                error_reportf_err(local_err, "-incoming %s: ", incoming);
> +                exit(1);
> +            }
>          }
>      } else if (autostart) {
>          vm_start();



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 26/29] hmp: introduce cmd_available
  2020-10-27 18:21 ` [PATCH 26/29] hmp: introduce cmd_available Paolo Bonzini
@ 2020-11-20 15:46   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 15:46 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:41 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Combine the RUN_STATE_PRECONFIG and cmd_can_preconfig checks
> into a single function, to avoid repeating the same expression
> (or its negation after applying DeMorgan's rule) over and
> over again.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  monitor/hmp.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index c5cd9d372b..f13ef455e2 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -213,6 +213,11 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
>      return strchr(cmd->flags, 'p');
>  }
>  
> +static bool cmd_available(const HMPCommand *cmd)
> +{
> +    return !runstate_check(RUN_STATE_PRECONFIG) || cmd_can_preconfig(cmd);
> +}
> +
>  static void help_cmd_dump_one(Monitor *mon,
>                                const HMPCommand *cmd,
>                                char **prefix_args,
> @@ -220,7 +225,7 @@ static void help_cmd_dump_one(Monitor *mon,
>  {
>      int i;
>  
> -    if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) {
> +    if (!cmd_available(cmd)) {
>          return;
>      }
>  
> @@ -248,8 +253,7 @@ static void help_cmd_dump(Monitor *mon, const HMPCommand *cmds,
>      /* Find one entry to dump */
>      for (cmd = cmds; cmd->name != NULL; cmd++) {
>          if (hmp_compare_cmd(args[arg_index], cmd->name) &&
> -            ((!runstate_check(RUN_STATE_PRECONFIG) ||
> -                cmd_can_preconfig(cmd)))) {
> +            cmd_available(cmd)) {
>              if (cmd->sub_table) {
>                  /* continue with next arg */
>                  help_cmd_dump(mon, cmd->sub_table,
> @@ -653,7 +657,7 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
>                         (int)(p - cmdp_start), cmdp_start);
>          return NULL;
>      }
> -    if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) {
> +    if (!cmd_available(cmd)) {
>          monitor_printf(mon, "Command '%.*s' not available with -preconfig "
>                              "until after exit_preconfig.\n",
>                         (int)(p - cmdp_start), cmdp_start);
> @@ -1225,8 +1229,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
>          }
>          readline_set_completion_index(mon->rs, strlen(cmdname));
>          for (cmd = cmd_table; cmd->name != NULL; cmd++) {
> -            if (!runstate_check(RUN_STATE_PRECONFIG) ||
> -                 cmd_can_preconfig(cmd)) {
> +            if (cmd_available(cmd)) {
>                  cmd_completion(mon, cmdname, cmd->name);
>              }
>          }
> @@ -1234,8 +1237,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
>          /* find the command */
>          for (cmd = cmd_table; cmd->name != NULL; cmd++) {
>              if (hmp_compare_cmd(args[0], cmd->name) &&
> -                (!runstate_check(RUN_STATE_PRECONFIG) ||
> -                 cmd_can_preconfig(cmd))) {
> +                cmd_available(cmd)) {
>                  break;
>              }
>          }



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-11-20 15:11   ` Igor Mammedov
@ 2020-11-20 15:53     ` Paolo Bonzini
  2020-11-20 16:32       ` Igor Mammedov
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 15:53 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 16:11, Igor Mammedov wrote:
> On Tue, 27 Oct 2020 14:21:37 -0400
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> Displays should be available before the monitor starts, so that
>> it is possible to use the graphical console to interact with
>> the monitor itself.
>>
>> This patch is quite ugly, but all this is temporary.  The double
>> call to qemu_init_displays will go away as soon we can unify machine
>> initialization between the preconfig and "normal" flows, and so will
>> the preconfig_exit_requested variable (that is only preconfig_requested
>> remains).
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Doesn't apply to yer for-6.0 branch

I updated the branch.

Thanks,

Paolo

>> ---
>>   softmmu/vl.c | 58 ++++++++++++++++++++++++++++++++--------------------
>>   1 file changed, 36 insertions(+), 22 deletions(-)
>>
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index 1485aba8be..a46f1b9164 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -137,6 +137,7 @@ static ram_addr_t maxram_size;
>>   static uint64_t ram_slots;
>>   static int display_remote;
>>   static int snapshot;
>> +static bool preconfig_requested;
>>   static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
>>   static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
>>   static bool nographic = false;
>> @@ -3210,12 +3211,12 @@ static void qemu_validate_options(void)
>>             }
>>       }
>>   
>> -    if (loadvm && !preconfig_exit_requested) {
>> +    if (loadvm && preconfig_requested) {
>>           error_report("'preconfig' and 'loadvm' options are "
>>                        "mutually exclusive");
>>           exit(EXIT_FAILURE);
>>       }
>> -    if (incoming && !preconfig_exit_requested) {
>> +    if (incoming && preconfig_requested) {
>>           error_report("'preconfig' and 'incoming' options are "
>>                        "mutually exclusive");
>>           exit(EXIT_FAILURE);
>> @@ -3381,6 +3382,28 @@ static void qemu_init_subsystems(void)
>>       socket_init();
>>   }
>>   
>> +static void qemu_init_displays(void)
>> +{
>> +    DisplayState *ds;
>> +
>> +    /* init local displays */
>> +    ds = init_displaystate();
>> +    qemu_display_init(ds, &dpy);
>> +
>> +    /* must be after terminal init, SDL library changes signal handlers */
>> +    os_setup_signal_handling();
>> +
>> +    /* init remote displays */
>> +#ifdef CONFIG_VNC
>> +    qemu_opts_foreach(qemu_find_opts("vnc"),
>> +                      vnc_init_func, NULL, &error_fatal);
>> +#endif
>> +
>> +    if (using_spice) {
>> +        qemu_spice.display_init();
>> +    }
>> +}
>> +
>>   /*
>>    * Called after leaving preconfig state.  From here on runstate is
>>    * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE.
>> @@ -3449,8 +3472,6 @@ static void qemu_create_cli_devices(void)
>>   
>>   static void qemu_machine_creation_done(void)
>>   {
>> -    DisplayState *ds;
>> -
>>       cpu_synchronize_all_post_init();
>>   
>>       /* Did we create any drives that we failed to create a device for? */
>> @@ -3473,23 +3494,6 @@ static void qemu_machine_creation_done(void)
>>           qemu_register_reset(restore_boot_order, g_strdup(boot_order));
>>       }
>>   
>> -    /* init local displays */
>> -    ds = init_displaystate();
>> -    qemu_display_init(ds, &dpy);
>> -
>> -    /* must be after terminal init, SDL library changes signal handlers */
>> -    os_setup_signal_handling();
>> -
>> -    /* init remote displays */
>> -#ifdef CONFIG_VNC
>> -    qemu_opts_foreach(qemu_find_opts("vnc"),
>> -                      vnc_init_func, NULL, &error_fatal);
>> -#endif
>> -
>> -    if (using_spice) {
>> -        qemu_spice.display_init();
>> -    }
>> -
>>       if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
>>           exit(1);
>>       }
>> @@ -4094,6 +4098,7 @@ void qemu_init(int argc, char **argv, char **envp)
>>                   break;
>>               case QEMU_OPTION_preconfig:
>>                   preconfig_exit_requested = false;
>> +                preconfig_requested = true;
>>                   break;
>>               case QEMU_OPTION_enable_kvm:
>>                   olist = qemu_find_opts("machine");
>> @@ -4515,11 +4520,20 @@ void qemu_init(int argc, char **argv, char **envp)
>>       qemu_resolve_machine_memdev();
>>       parse_numa_opts(current_machine);
>>   
>> +    if (preconfig_requested) {
>> +        qemu_init_displays();
>> +    }
>> +
>>       /* do monitor/qmp handling at preconfig state if requested */
>>       qemu_main_loop();
>> -
>>       qemu_finish_machine_init();
>> +
>>       qemu_create_cli_devices();
>> +
>> +    /* initialize displays after all errors have been reported */
>> +    if (!preconfig_requested) {
>> +        qemu_init_displays();
>> +    }
>>       qemu_machine_creation_done();
>>   
>>       if (loadvm) {
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 27/29] remove preconfig state
  2020-10-27 18:21 ` [PATCH 27/29] remove preconfig state Paolo Bonzini
@ 2020-11-20 16:01   ` Igor Mammedov
  2020-11-20 16:22     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:01 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:42 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> The preconfig state is only used if -incoming is not specified, which
> makes the RunState state machine more tricky than it need be.  However
> there is already an equivalent condition which works even with -incoming,
> namely qdev_hotplug.  Use it instead of a separate runstate.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

ERROR:
tests/qtest/qmp-test.c:298:test_qmp_preconfig: assertion failed (qdict_get_try_str(ret, "status") == "preconfig"): ("prelaunch" == "preconfig")

> ---
>  hw/core/machine-qmp-cmds.c    |  5 ++---
>  include/qapi/qmp/dispatch.h   |  1 +
>  monitor/hmp.c                 |  7 ++++---
>  monitor/qmp-cmds.c            |  5 ++---
>  qapi/qmp-dispatch.c           |  5 +----
>  qapi/run-state.json           |  5 +----
>  softmmu/qdev-monitor.c        | 12 ++++++++++++
>  softmmu/vl.c                  | 13 ++-----------
>  stubs/meson.build             |  1 +
>  stubs/qmp-command-available.c |  7 +++++++
>  10 files changed, 33 insertions(+), 28 deletions(-)
>  create mode 100644 stubs/qmp-command-available.c
> 
> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> index 5362c80a18..cb9387c5f5 100644
> --- a/hw/core/machine-qmp-cmds.c
> +++ b/hw/core/machine-qmp-cmds.c
> @@ -286,9 +286,8 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)
>  
>  void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
>  {
> -    if (!runstate_check(RUN_STATE_PRECONFIG)) {
> -        error_setg(errp, "The command is permitted only in '%s' state",
> -                   RunState_str(RUN_STATE_PRECONFIG));
> +    if (qdev_hotplug) {
> +         error_setg(errp, "The command is permitted only before the machine has been created");
>           return;
>      }
>  
> diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
> index af8d96c570..1486cac3ef 100644
> --- a/include/qapi/qmp/dispatch.h
> +++ b/include/qapi/qmp/dispatch.h
> @@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, const char *name);
>  void qmp_enable_command(QmpCommandList *cmds, const char *name);
>  
>  bool qmp_command_is_enabled(const QmpCommand *cmd);
> +bool qmp_command_available(const QmpCommand *cmd, Error **errp);
>  const char *qmp_command_name(const QmpCommand *cmd);
>  bool qmp_has_success_response(const QmpCommand *cmd);
>  QDict *qmp_error_response(Error *err);
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index f13ef455e2..0027f1465d 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -24,6 +24,7 @@
>  
>  #include "qemu/osdep.h"
>  #include <dirent.h>
> +#include "hw/qdev-core.h"
>  #include "monitor-internal.h"
>  #include "qapi/error.h"
>  #include "qapi/qmp/qdict.h"
> @@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
>  
>  static bool cmd_available(const HMPCommand *cmd)
>  {
> -    return !runstate_check(RUN_STATE_PRECONFIG) || cmd_can_preconfig(cmd);
> +    return qdev_hotplug || cmd_can_preconfig(cmd);
>  }
>  
>  static void help_cmd_dump_one(Monitor *mon,
> @@ -658,8 +659,8 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
>          return NULL;
>      }
>      if (!cmd_available(cmd)) {
> -        monitor_printf(mon, "Command '%.*s' not available with -preconfig "
> -                            "until after exit_preconfig.\n",
> +        monitor_printf(mon, "Command '%.*s' not available "
> +                            "until machine initialization has completed.\n",
>                         (int)(p - cmdp_start), cmdp_start);
>          return NULL;
>      }
> diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
> index a08143b323..7c10b182e4 100644
> --- a/monitor/qmp-cmds.c
> +++ b/monitor/qmp-cmds.c
> @@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)
>  
>  void qmp_x_exit_preconfig(Error **errp)
>  {
> -    if (!runstate_check(RUN_STATE_PRECONFIG)) {
> -        error_setg(errp, "The command is permitted only in '%s' state",
> -                   RunState_str(RUN_STATE_PRECONFIG));
> +    if (qdev_hotplug) {
> +        error_setg(errp, "The command is permitted only before machine initialization");
>          return;
>      }
>      qemu_exit_preconfig_request();
> diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
> index 9a2d7dd29a..0a2b20a4e4 100644
> --- a/qapi/qmp-dispatch.c
> +++ b/qapi/qmp-dispatch.c
> @@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
>          goto out;
>      }
>  
> -    if (runstate_check(RUN_STATE_PRECONFIG) &&
> -        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
> -        error_setg(&err, "The command '%s' isn't permitted in '%s' state",
> -                   cmd->name, RunState_str(RUN_STATE_PRECONFIG));
> +    if (!qmp_command_available(cmd, &err)) {
>          goto out;
>      }
>  
> diff --git a/qapi/run-state.json b/qapi/run-state.json
> index 964c8ef391..38194b0e44 100644
> --- a/qapi/run-state.json
> +++ b/qapi/run-state.json
> @@ -50,15 +50,12 @@
>  # @colo: guest is paused to save/restore VM state under colo checkpoint,
>  #        VM can not get into this state unless colo capability is enabled
>  #        for migration. (since 2.8)
> -# @preconfig: QEMU is paused before board specific init callback is executed.
> -#             The state is reachable only if the --preconfig CLI option is used.
> -#             (Since 3.0)
>  ##
>  { 'enum': 'RunState',
>    'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
>              'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
>              'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
> -            'guest-panicked', 'colo', 'preconfig' ] }
> +            'guest-panicked', 'colo' ] }
>  
>  ##
>  # @ShutdownCause:
> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
> index bcfcbac181..00720eb827 100644
> --- a/softmmu/qdev-monitor.c
> +++ b/softmmu/qdev-monitor.c
> @@ -25,6 +25,7 @@
>  #include "sysemu/arch_init.h"
>  #include "qapi/error.h"
>  #include "qapi/qapi-commands-qdev.h"
> +#include "qapi/qmp/dispatch.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qerror.h"
>  #include "qemu/config-file.h"
> @@ -997,3 +998,14 @@ int qemu_global_option(const char *str)
>  
>      return 0;
>  }
> +
> +bool qmp_command_available(const QmpCommand *cmd, Error **errp)
> +{
> +    if (!qdev_hotplug &&
> +        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
> +        error_setg(errp, "The command '%s' is permitted only after machine initialization has completed",
> +                   cmd->name);
> +        return false;
> +    }
> +    return true;
> +}
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index edabd17dac..68acd24d01 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -574,7 +574,7 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
>  /***********************************************************/
>  /* QEMU state */
>  
> -static RunState current_run_state = RUN_STATE_PRECONFIG;
> +static RunState current_run_state = RUN_STATE_PRELAUNCH;
>  
>  /* We use RUN_STATE__MAX but any invalid value will do */
>  static RunState vmstop_requested = RUN_STATE__MAX;
> @@ -586,13 +586,7 @@ typedef struct {
>  } RunStateTransition;
>  
>  static const RunStateTransition runstate_transitions_def[] = {
> -    /*     from      ->     to      */
> -    { RUN_STATE_PRECONFIG, RUN_STATE_PRELAUNCH },
> -      /* Early switch to inmigrate state to allow  -incoming CLI option work
> -       * as it used to. TODO: delay actual switching to inmigrate state to
> -       * the point after machine is built and remove this hack.
> -       */
> -    { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE },
> +    { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
>  
>      { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
>      { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
> @@ -1633,9 +1627,6 @@ static bool main_loop_should_exit(void)
>      ShutdownCause request;
>  
>      if (preconfig_exit_requested) {
> -        if (runstate_check(RUN_STATE_PRECONFIG)) {
> -            runstate_set(RUN_STATE_PRELAUNCH);
> -        }
>          preconfig_exit_requested = false;
>          return true;
>      }
> diff --git a/stubs/meson.build b/stubs/meson.build
> index 82b7ba60ab..cc56c83063 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c'))
>  stub_ss.add(files('pci-host-piix.c'))
>  stub_ss.add(files('qemu-timer-notify-cb.c'))
>  stub_ss.add(files('qmp_memory_device.c'))
> +stub_ss.add(files('qmp-command-available.c'))
>  stub_ss.add(files('qtest.c'))
>  stub_ss.add(files('ram-block.c'))
>  stub_ss.add(files('ramfb.c'))
> diff --git a/stubs/qmp-command-available.c b/stubs/qmp-command-available.c
> new file mode 100644
> index 0000000000..46540af7bf
> --- /dev/null
> +++ b/stubs/qmp-command-available.c
> @@ -0,0 +1,7 @@
> +#include "qemu/osdep.h"
> +#include "qapi/qmp/dispatch.h"
> +
> +bool qmp_command_available(const QmpCommand *cmd, Error **errp)
> +{
> +    return true;
> +}



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-11-20 15:34   ` Igor Mammedov
@ 2020-11-20 16:02     ` Paolo Bonzini
  2020-12-02 13:10       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:02 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, dgilbert

On 20/11/20 16:34, Igor Mammedov wrote:
>>       qapi_event_send_migration(MIGRATION_STATUS_SETUP);
>> -    if (!strcmp(uri, "defer")) {
>> -        deferred_incoming_migration(errp);
>> -    } else if (strstart(uri, "tcp:", &p) ||
>> -               strstart(uri, "unix:", NULL) ||
>> -               strstart(uri, "vsock:", NULL)) {
> considering the last hunk does won't call qmp_migrate_incoming
> if 'defer' was used, wouldn't we will lose QAPI event here?
> not sure how important it to users,

Hmm yeah that's true.  That might even be considered a bugfix (no setup 
is done until the "real" migrate-incoming command), but I can also add 
the event manually in qemu_init.

(Libvirt doesn't use the SETUP case of the event but that's of course 
only part of the story).

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 25/29] vl: start VM via qmp_cont
  2020-10-27 18:21 ` [PATCH 25/29] vl: start VM via qmp_cont Paolo Bonzini
@ 2020-11-20 16:08   ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:40 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Complement the previous patch by starting the VM with a QMP command.
> Later, the user will be able to do the same, invoking two
> commands "finish-machine-init" and "cont" instead of
> "x-exit-preconfig".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  softmmu/vl.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 583366510b..edabd17dac 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -110,6 +110,7 @@
>  #include "qapi/qapi-visit-ui.h"
>  #include "qapi/qapi-commands-block-core.h"
>  #include "qapi/qapi-commands-migration.h"
> +#include "qapi/qapi-commands-misc.h"
>  #include "qapi/qapi-commands-run-state.h"
>  #include "qapi/qapi-commands-ui.h"
>  #include "qapi/qmp/qerror.h"
> @@ -4566,7 +4567,7 @@ void qemu_init(int argc, char **argv, char **envp)
>              }
>          }
>      } else if (autostart) {
> -        vm_start();
> +        qmp_cont(NULL);
>      }
>  
>      accel_setup_post(current_machine);



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-11-03 14:37       ` Paolo Bonzini
@ 2020-11-20 16:19         ` Igor Mammedov
  2020-11-20 16:27           ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:19 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 3 Nov 2020 15:37:13 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 03/11/20 13:57, Igor Mammedov wrote:
> >> It's based on 20201026143028.3034018-1-pbonzini@redhat.com (which you
> >> should be able to get through patchew).  
> > Not sure what you mean and how to do that.
> > Is it possible to share v2 as a git tree somewhere?  
> 
> I pushed it to for-6.0 on my gitlab repo.  There's a lot more stuff in
> the branch, but these patches are at the top.

had to use temporary fixup, to make build pass and fix '-device help' crash
with your branch. (upstream master doesn't have this problem)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 858860377b..78f3397736 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -776,6 +776,7 @@ static const char *get_opt_name_value(const char *params,
         /* found "foo,more" */
         if (help_wanted && starts_with_help_option(params) == len) {
             *help_wanted = true;
+            return NULL;
         } else if (firstname) {
             /* implicitly named first option */
             *name = g_strdup(firstname);

> 
> Paolo
> 
> 



^ permalink raw reply related	[flat|nested] 78+ messages in thread

* Re: [PATCH 27/29] remove preconfig state
  2020-11-20 16:01   ` Igor Mammedov
@ 2020-11-20 16:22     ` Paolo Bonzini
  0 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:22 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:01, Igor Mammedov wrote:
> On Tue, 27 Oct 2020 14:21:42 -0400
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> The preconfig state is only used if -incoming is not specified, which
>> makes the RunState state machine more tricky than it need be.  However
>> there is already an equivalent condition which works even with -incoming,
>> namely qdev_hotplug.  Use it instead of a separate runstate.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> ERROR:
> tests/qtest/qmp-test.c:298:test_qmp_preconfig: assertion failed (qdict_get_try_str(ret, "status") == "preconfig"): ("prelaunch" == "preconfig")

Uff, of course.  So this would be an incompatible change.

Do you think it's important to keep the runstate?  Especially when 
allowing "-incoming defer" with preconfig things become complicated, 
because there's code that checks for RUN_STATE_INMIGRATE and it would 
break if the state is preconfig.

Paolo

>> ---
>>   hw/core/machine-qmp-cmds.c    |  5 ++---
>>   include/qapi/qmp/dispatch.h   |  1 +
>>   monitor/hmp.c                 |  7 ++++---
>>   monitor/qmp-cmds.c            |  5 ++---
>>   qapi/qmp-dispatch.c           |  5 +----
>>   qapi/run-state.json           |  5 +----
>>   softmmu/qdev-monitor.c        | 12 ++++++++++++
>>   softmmu/vl.c                  | 13 ++-----------
>>   stubs/meson.build             |  1 +
>>   stubs/qmp-command-available.c |  7 +++++++
>>   10 files changed, 33 insertions(+), 28 deletions(-)
>>   create mode 100644 stubs/qmp-command-available.c
>>
>> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
>> index 5362c80a18..cb9387c5f5 100644
>> --- a/hw/core/machine-qmp-cmds.c
>> +++ b/hw/core/machine-qmp-cmds.c
>> @@ -286,9 +286,8 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)
>>   
>>   void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
>>   {
>> -    if (!runstate_check(RUN_STATE_PRECONFIG)) {
>> -        error_setg(errp, "The command is permitted only in '%s' state",
>> -                   RunState_str(RUN_STATE_PRECONFIG));
>> +    if (qdev_hotplug) {
>> +         error_setg(errp, "The command is permitted only before the machine has been created");
>>            return;
>>       }
>>   
>> diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
>> index af8d96c570..1486cac3ef 100644
>> --- a/include/qapi/qmp/dispatch.h
>> +++ b/include/qapi/qmp/dispatch.h
>> @@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, const char *name);
>>   void qmp_enable_command(QmpCommandList *cmds, const char *name);
>>   
>>   bool qmp_command_is_enabled(const QmpCommand *cmd);
>> +bool qmp_command_available(const QmpCommand *cmd, Error **errp);
>>   const char *qmp_command_name(const QmpCommand *cmd);
>>   bool qmp_has_success_response(const QmpCommand *cmd);
>>   QDict *qmp_error_response(Error *err);
>> diff --git a/monitor/hmp.c b/monitor/hmp.c
>> index f13ef455e2..0027f1465d 100644
>> --- a/monitor/hmp.c
>> +++ b/monitor/hmp.c
>> @@ -24,6 +24,7 @@
>>   
>>   #include "qemu/osdep.h"
>>   #include <dirent.h>
>> +#include "hw/qdev-core.h"
>>   #include "monitor-internal.h"
>>   #include "qapi/error.h"
>>   #include "qapi/qmp/qdict.h"
>> @@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
>>   
>>   static bool cmd_available(const HMPCommand *cmd)
>>   {
>> -    return !runstate_check(RUN_STATE_PRECONFIG) || cmd_can_preconfig(cmd);
>> +    return qdev_hotplug || cmd_can_preconfig(cmd);
>>   }
>>   
>>   static void help_cmd_dump_one(Monitor *mon,
>> @@ -658,8 +659,8 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
>>           return NULL;
>>       }
>>       if (!cmd_available(cmd)) {
>> -        monitor_printf(mon, "Command '%.*s' not available with -preconfig "
>> -                            "until after exit_preconfig.\n",
>> +        monitor_printf(mon, "Command '%.*s' not available "
>> +                            "until machine initialization has completed.\n",
>>                          (int)(p - cmdp_start), cmdp_start);
>>           return NULL;
>>       }
>> diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
>> index a08143b323..7c10b182e4 100644
>> --- a/monitor/qmp-cmds.c
>> +++ b/monitor/qmp-cmds.c
>> @@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)
>>   
>>   void qmp_x_exit_preconfig(Error **errp)
>>   {
>> -    if (!runstate_check(RUN_STATE_PRECONFIG)) {
>> -        error_setg(errp, "The command is permitted only in '%s' state",
>> -                   RunState_str(RUN_STATE_PRECONFIG));
>> +    if (qdev_hotplug) {
>> +        error_setg(errp, "The command is permitted only before machine initialization");
>>           return;
>>       }
>>       qemu_exit_preconfig_request();
>> diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
>> index 9a2d7dd29a..0a2b20a4e4 100644
>> --- a/qapi/qmp-dispatch.c
>> +++ b/qapi/qmp-dispatch.c
>> @@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
>>           goto out;
>>       }
>>   
>> -    if (runstate_check(RUN_STATE_PRECONFIG) &&
>> -        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
>> -        error_setg(&err, "The command '%s' isn't permitted in '%s' state",
>> -                   cmd->name, RunState_str(RUN_STATE_PRECONFIG));
>> +    if (!qmp_command_available(cmd, &err)) {
>>           goto out;
>>       }
>>   
>> diff --git a/qapi/run-state.json b/qapi/run-state.json
>> index 964c8ef391..38194b0e44 100644
>> --- a/qapi/run-state.json
>> +++ b/qapi/run-state.json
>> @@ -50,15 +50,12 @@
>>   # @colo: guest is paused to save/restore VM state under colo checkpoint,
>>   #        VM can not get into this state unless colo capability is enabled
>>   #        for migration. (since 2.8)
>> -# @preconfig: QEMU is paused before board specific init callback is executed.
>> -#             The state is reachable only if the --preconfig CLI option is used.
>> -#             (Since 3.0)
>>   ##
>>   { 'enum': 'RunState',
>>     'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
>>               'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
>>               'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
>> -            'guest-panicked', 'colo', 'preconfig' ] }
>> +            'guest-panicked', 'colo' ] }
>>   
>>   ##
>>   # @ShutdownCause:
>> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
>> index bcfcbac181..00720eb827 100644
>> --- a/softmmu/qdev-monitor.c
>> +++ b/softmmu/qdev-monitor.c
>> @@ -25,6 +25,7 @@
>>   #include "sysemu/arch_init.h"
>>   #include "qapi/error.h"
>>   #include "qapi/qapi-commands-qdev.h"
>> +#include "qapi/qmp/dispatch.h"
>>   #include "qapi/qmp/qdict.h"
>>   #include "qapi/qmp/qerror.h"
>>   #include "qemu/config-file.h"
>> @@ -997,3 +998,14 @@ int qemu_global_option(const char *str)
>>   
>>       return 0;
>>   }
>> +
>> +bool qmp_command_available(const QmpCommand *cmd, Error **errp)
>> +{
>> +    if (!qdev_hotplug &&
>> +        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
>> +        error_setg(errp, "The command '%s' is permitted only after machine initialization has completed",
>> +                   cmd->name);
>> +        return false;
>> +    }
>> +    return true;
>> +}
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index edabd17dac..68acd24d01 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -574,7 +574,7 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
>>   /***********************************************************/
>>   /* QEMU state */
>>   
>> -static RunState current_run_state = RUN_STATE_PRECONFIG;
>> +static RunState current_run_state = RUN_STATE_PRELAUNCH;
>>   
>>   /* We use RUN_STATE__MAX but any invalid value will do */
>>   static RunState vmstop_requested = RUN_STATE__MAX;
>> @@ -586,13 +586,7 @@ typedef struct {
>>   } RunStateTransition;
>>   
>>   static const RunStateTransition runstate_transitions_def[] = {
>> -    /*     from      ->     to      */
>> -    { RUN_STATE_PRECONFIG, RUN_STATE_PRELAUNCH },
>> -      /* Early switch to inmigrate state to allow  -incoming CLI option work
>> -       * as it used to. TODO: delay actual switching to inmigrate state to
>> -       * the point after machine is built and remove this hack.
>> -       */
>> -    { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE },
>> +    { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
>>   
>>       { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
>>       { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
>> @@ -1633,9 +1627,6 @@ static bool main_loop_should_exit(void)
>>       ShutdownCause request;
>>   
>>       if (preconfig_exit_requested) {
>> -        if (runstate_check(RUN_STATE_PRECONFIG)) {
>> -            runstate_set(RUN_STATE_PRELAUNCH);
>> -        }
>>           preconfig_exit_requested = false;
>>           return true;
>>       }
>> diff --git a/stubs/meson.build b/stubs/meson.build
>> index 82b7ba60ab..cc56c83063 100644
>> --- a/stubs/meson.build
>> +++ b/stubs/meson.build
>> @@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c'))
>>   stub_ss.add(files('pci-host-piix.c'))
>>   stub_ss.add(files('qemu-timer-notify-cb.c'))
>>   stub_ss.add(files('qmp_memory_device.c'))
>> +stub_ss.add(files('qmp-command-available.c'))
>>   stub_ss.add(files('qtest.c'))
>>   stub_ss.add(files('ram-block.c'))
>>   stub_ss.add(files('ramfb.c'))
>> diff --git a/stubs/qmp-command-available.c b/stubs/qmp-command-available.c
>> new file mode 100644
>> index 0000000000..46540af7bf
>> --- /dev/null
>> +++ b/stubs/qmp-command-available.c
>> @@ -0,0 +1,7 @@
>> +#include "qemu/osdep.h"
>> +#include "qapi/qmp/dispatch.h"
>> +
>> +bool qmp_command_available(const QmpCommand *cmd, Error **errp)
>> +{
>> +    return true;
>> +}
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 28/29] vl: remove separate preconfig main_loop
  2020-10-27 18:21 ` [PATCH 28/29] vl: remove separate preconfig main_loop Paolo Bonzini
@ 2020-11-20 16:26   ` Igor Mammedov
  2020-11-20 16:39     ` Paolo Bonzini
  2020-11-23  8:34     ` Paolo Bonzini
  0 siblings, 2 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:26 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:43 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Move post-preconfig initialization to the x-exit-preconfig.  If preconfig
> is not requested, just exit preconfig mode immediately with the QMP
> command.
> 
> As a result, the preconfig loop will run with accel_setup_post
> and os_setup_post restrictions (xen_restrict, chroot, etc.)
> already done.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

This one also doesn't apply,

+ one more comment below

> ---
>  include/sysemu/runstate.h |  1 -
>  monitor/qmp-cmds.c        |  9 ----
>  softmmu/vl.c              | 94 +++++++++++++++++----------------------
>  3 files changed, 41 insertions(+), 63 deletions(-)
> 
> diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
> index f760094858..e557f470d4 100644
> --- a/include/sysemu/runstate.h
> +++ b/include/sysemu/runstate.h
> @@ -41,7 +41,6 @@ typedef enum WakeupReason {
>      QEMU_WAKEUP_REASON_OTHER,
>  } WakeupReason;
>  
> -void qemu_exit_preconfig_request(void);
>  void qemu_system_reset_request(ShutdownCause reason);
>  void qemu_system_suspend_request(void);
>  void qemu_register_suspend_notifier(Notifier *notifier);
> diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
> index 7c10b182e4..6680ba6c66 100644
> --- a/monitor/qmp-cmds.c
> +++ b/monitor/qmp-cmds.c
> @@ -102,15 +102,6 @@ void qmp_system_powerdown(Error **errp)
>      qemu_system_powerdown_request();
>  }
>  
> -void qmp_x_exit_preconfig(Error **errp)
> -{
> -    if (qdev_hotplug) {
> -        error_setg(errp, "The command is permitted only before machine initialization");
> -        return;
> -    }
> -    qemu_exit_preconfig_request();
> -}
> -
>  void qmp_cont(Error **errp)
>  {
>      BlockBackend *blk;
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 68acd24d01..98666c0612 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -1313,7 +1313,6 @@ static pid_t shutdown_pid;
>  static int powerdown_requested;
>  static int debug_requested;
>  static int suspend_requested;
> -static bool preconfig_exit_requested = true;
>  static WakeupReason wakeup_reason;
>  static NotifierList powerdown_notifiers =
>      NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
> @@ -1400,11 +1399,6 @@ static int qemu_debug_requested(void)
>      return r;
>  }
>  
> -void qemu_exit_preconfig_request(void)
> -{
> -    preconfig_exit_requested = true;
> -}
> -
>  /*
>   * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
>   */
> @@ -1626,10 +1620,6 @@ static bool main_loop_should_exit(void)
>      RunState r;
>      ShutdownCause request;
>  
> -    if (preconfig_exit_requested) {
> -        preconfig_exit_requested = false;
> -        return true;
> -    }
>      if (qemu_debug_requested()) {
>          vm_stop(RUN_STATE_DEBUG);
>      }
> @@ -3523,6 +3513,43 @@ static void qemu_machine_creation_done(void)
>      register_global_state();
>  }
>  
> +void qmp_x_exit_preconfig(Error **errp)
> +{
> +    if (qdev_hotplug) {
> +        error_setg(errp, "The command is permitted only before machine initialization");
> +        return;
> +    }
> +
> +    qemu_finish_machine_init();
> +    qemu_create_cli_devices();
> +    qemu_machine_creation_done();
> +
> +    if (loadvm) {
> +        Error *local_err = NULL;
> +        if (load_snapshot(loadvm, &local_err) < 0) {
> +            error_report_err(local_err);
> +            autostart = 0;
> +            exit(1);
> +        }
> +    }
> +    if (replay_mode != REPLAY_MODE_NONE) {
> +        replay_vmstate_init();
> +    }
> +
> +    if (incoming) {
> +        Error *local_err = NULL;
> +        if (strcmp(incoming, "defer") != 0) {
> +            qmp_migrate_incoming(incoming, &local_err);
> +            if (local_err) {
> +                error_reportf_err(local_err, "-incoming %s: ", incoming);
> +                exit(1);
> +            }
> +        }
> +    } else if (autostart) {
> +        qmp_cont(NULL);
> +    }
> +}
> +
>  void qemu_init(int argc, char **argv, char **envp)
>  {
>      QemuOpts *opts;
> @@ -4092,7 +4119,6 @@ void qemu_init(int argc, char **argv, char **envp)
>                  }
>                  break;
>              case QEMU_OPTION_preconfig:
> -                preconfig_exit_requested = false;
>                  preconfig_requested = true;
>                  break;
>              case QEMU_OPTION_enable_kvm:
> @@ -4515,56 +4541,18 @@ void qemu_init(int argc, char **argv, char **envp)
>      qemu_resolve_machine_memdev();
>      parse_numa_opts(current_machine);
>  
> -    if (preconfig_requested) {
> -        qemu_init_displays();
> -    }

^^^

> -
> -    /* do monitor/qmp handling at preconfig state if requested */
> -    qemu_main_loop();
> -    qemu_finish_machine_init();
> -
> -    qemu_create_cli_devices();
> -
> -    /* initialize displays after all errors have been reported */
> -    if (!preconfig_requested) {
> -        qemu_init_displays();
> -    }

^^^

[...]
>  

1)

> +    if (!preconfig_requested) {
> +        qmp_x_exit_preconfig(&error_fatal);
> +    }
> +    qemu_init_displays();
given that qemu_init_displays() were called in both cases,
shouldn't it be called unconditionally at [1]?

>      accel_setup_post(current_machine);
>      os_setup_post();
> -
> -    return;
>  }
>  
>  void qemu_cleanup(void)



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing
  2020-11-20 16:19         ` Igor Mammedov
@ 2020-11-20 16:27           ` Paolo Bonzini
  0 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:27 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:19, Igor Mammedov wrote:
> On Tue, 3 Nov 2020 15:37:13 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> On 03/11/20 13:57, Igor Mammedov wrote:
>>>> It's based on 20201026143028.3034018-1-pbonzini@redhat.com (which you
>>>> should be able to get through patchew).
>>> Not sure what you mean and how to do that.
>>> Is it possible to share v2 as a git tree somewhere?
>>
>> I pushed it to for-6.0 on my gitlab repo.  There's a lot more stuff in
>> the branch, but these patches are at the top.
> 
> had to use temporary fixup, to make build pass and fix '-device help' crash
> with your branch. (upstream master doesn't have this problem)
> 
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 858860377b..78f3397736 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -776,6 +776,7 @@ static const char *get_opt_name_value(const char *params,
>           /* found "foo,more" */
>           if (help_wanted && starts_with_help_option(params) == len) {
>               *help_wanted = true;
> +            return NULL;
>           } else if (firstname) {
>               /* implicitly named first option */
>               *name = g_strdup(firstname);

Thanks!  I'll integrate this in the right place of the series.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 29/29] vl: allow -incoming defer with -preconfig
  2020-10-27 18:21 ` [PATCH 29/29] vl: allow -incoming defer with -preconfig Paolo Bonzini
@ 2020-11-20 16:28   ` Igor Mammedov
  2020-11-20 16:45     ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:28 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, 27 Oct 2020 14:21:44 -0400
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Now that there is no RUN_STATE_PRECONFIG anymore that can conflict with
> RUN_STATE_INMIGRATE, we can allow -incoming defer with -preconfig.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 98666c0612..b0cb539da9 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -3199,9 +3199,8 @@ static void qemu_validate_options(void)
>                       "mutually exclusive");
>          exit(EXIT_FAILURE);
>      }
> -    if (incoming && preconfig_requested) {
> -        error_report("'preconfig' and 'incoming' options are "
> -                     "mutually exclusive");
> +    if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
why limit it only to 'defer'?

> +        error_report("'preconfig' supports '-incoming defer' only");
>          exit(EXIT_FAILURE);
>      }
>  



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-11-20 15:53     ` Paolo Bonzini
@ 2020-11-20 16:32       ` Igor Mammedov
  2020-11-20 16:46         ` Paolo Bonzini
  0 siblings, 1 reply; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 16:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Fri, 20 Nov 2020 16:53:41 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 20/11/20 16:11, Igor Mammedov wrote:
> > On Tue, 27 Oct 2020 14:21:37 -0400
> > Paolo Bonzini <pbonzini@redhat.com> wrote:
> >   
> >> Displays should be available before the monitor starts, so that
> >> it is possible to use the graphical console to interact with
> >> the monitor itself.
> >>
> >> This patch is quite ugly, but all this is temporary.  The double
> >> call to qemu_init_displays will go away as soon we can unify machine
> >> initialization between the preconfig and "normal" flows, and so will
> >> the preconfig_exit_requested variable (that is only preconfig_requested
> >> remains).
> >>
> >> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>  
> > 
> > Doesn't apply to yer for-6.0 branch  
> 
> I updated the branch.

it probably won't help,
what I do review/test is drop these patches on branch
and reapply them from this thread.
Having v2 on list that applies to master would be better.

> Thanks,
> 
> Paolo
> 
[...]



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 28/29] vl: remove separate preconfig main_loop
  2020-11-20 16:26   ` Igor Mammedov
@ 2020-11-20 16:39     ` Paolo Bonzini
  2020-11-23  8:34     ` Paolo Bonzini
  1 sibling, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:39 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:26, Igor Mammedov wrote:
>> +    if (!preconfig_requested) {
>> +        qmp_x_exit_preconfig(&error_fatal);
>> +    }
>> +    qemu_init_displays();
> given that qemu_init_displays() were called in both cases,
> shouldn't it be called unconditionally at [1]?

Yes, makes sense.  In fact, it would be nicer to also call

     accel_setup_post(current_machine);
     os_setup_post();

before x_exit_preconfig, but it's left for another day.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 29/29] vl: allow -incoming defer with -preconfig
  2020-11-20 16:28   ` Igor Mammedov
@ 2020-11-20 16:45     ` Paolo Bonzini
  0 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:45 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:28, Igor Mammedov wrote:
> On Tue, 27 Oct 2020 14:21:44 -0400
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> Now that there is no RUN_STATE_PRECONFIG anymore that can conflict with
>> RUN_STATE_INMIGRATE, we can allow -incoming defer with -preconfig.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>   softmmu/vl.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index 98666c0612..b0cb539da9 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -3199,9 +3199,8 @@ static void qemu_validate_options(void)
>>                        "mutually exclusive");
>>           exit(EXIT_FAILURE);
>>       }
>> -    if (incoming && preconfig_requested) {
>> -        error_report("'preconfig' and 'incoming' options are "
>> -                     "mutually exclusive");
>> +    if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
> why limit it only to 'defer'?

After these patches, the difference between "-incoming defer" and 
"-incoming foo" is very small: the latter adds an automatic 
"migrate-incoming foo" at the tail of x-exit-preconfig, and that's it.

At the time I sent these patches, my plan was to replace 
x-exit-preconfig with a command "finish-machine-init" that the user 
would follow with one of "cont", "migrate-incoming" or "loadvm".  So it 
would make sense to have "-incoming defer" only, because without 
"x-exit-preconfig" there's no command that triggers incoming migration 
as specified with "-incoming foo".

Then I sent only the minimal (so to speak) beginning of the series, but 
decided to be consrvative in what to allow on the command line.  Since 
you are interacting with the monitor anyway to exit preconfig, you can 
use it to send the migrate-incoming command.

Thanks,

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-11-20 16:32       ` Igor Mammedov
@ 2020-11-20 16:46         ` Paolo Bonzini
  2020-11-20 17:11           ` Igor Mammedov
  0 siblings, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-20 16:46 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:32, Igor Mammedov wrote:
> On Fri, 20 Nov 2020 16:53:41 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> On 20/11/20 16:11, Igor Mammedov wrote:
>>> On Tue, 27 Oct 2020 14:21:37 -0400
>>> Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>    
>>>> Displays should be available before the monitor starts, so that
>>>> it is possible to use the graphical console to interact with
>>>> the monitor itself.
>>>>
>>>> This patch is quite ugly, but all this is temporary.  The double
>>>> call to qemu_init_displays will go away as soon we can unify machine
>>>> initialization between the preconfig and "normal" flows, and so will
>>>> the preconfig_exit_requested variable (that is only preconfig_requested
>>>> remains).
>>>>
>>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>>
>>> Doesn't apply to yer for-6.0 branch
>>
>> I updated the branch.
> 
> it probably won't help,
> what I do review/test is drop these patches on branch
> and reapply them from this thread.
> Having v2 on list that applies to master would be better.

Yes, of course.  I meant that the for-6.0 branch already _is_ the v2, 
I'll send it out as soon as I integrate all your feedback.

Thanks,

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 22/29] vl: initialize displays before preconfig loop
  2020-11-20 16:46         ` Paolo Bonzini
@ 2020-11-20 17:11           ` Igor Mammedov
  0 siblings, 0 replies; 78+ messages in thread
From: Igor Mammedov @ 2020-11-20 17:11 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Fri, 20 Nov 2020 17:46:14 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 20/11/20 17:32, Igor Mammedov wrote:
> > On Fri, 20 Nov 2020 16:53:41 +0100
> > Paolo Bonzini <pbonzini@redhat.com> wrote:
> >   
> >> On 20/11/20 16:11, Igor Mammedov wrote:  
> >>> On Tue, 27 Oct 2020 14:21:37 -0400
> >>> Paolo Bonzini <pbonzini@redhat.com> wrote:
> >>>      
> >>>> Displays should be available before the monitor starts, so that
> >>>> it is possible to use the graphical console to interact with
> >>>> the monitor itself.
> >>>>
> >>>> This patch is quite ugly, but all this is temporary.  The double
> >>>> call to qemu_init_displays will go away as soon we can unify machine
> >>>> initialization between the preconfig and "normal" flows, and so will
> >>>> the preconfig_exit_requested variable (that is only preconfig_requested
> >>>> remains).
> >>>>
> >>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>  
> >>>
> >>> Doesn't apply to yer for-6.0 branch  
> >>
> >> I updated the branch.  
> > 
> > it probably won't help,
> > what I do review/test is drop these patches on branch
> > and reapply them from this thread.
> > Having v2 on list that applies to master would be better.  
> 
> Yes, of course.  I meant that the for-6.0 branch already _is_ the v2, 
> I'll send it out as soon as I integrate all your feedback.

Thanks for trying to make hornets nest (vl.c) in something manageable and
less scary to touch.
I'll try to review v2 faster (there is not much of it left by now)

> 
> Thanks,
> 
> Paolo
> 
> 



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 28/29] vl: remove separate preconfig main_loop
  2020-11-20 16:26   ` Igor Mammedov
  2020-11-20 16:39     ` Paolo Bonzini
@ 2020-11-23  8:34     ` Paolo Bonzini
  1 sibling, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-11-23  8:34 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel

On 20/11/20 17:26, Igor Mammedov wrote:
>> +    if (!preconfig_requested) {
>> +        qmp_x_exit_preconfig(&error_fatal);
>> +    }
>> +    qemu_init_displays();
> given that qemu_init_displays() were called in both cases,
> shouldn't it be called unconditionally at [1]?
> 

Yes, correct.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-11-20 16:02     ` Paolo Bonzini
@ 2020-12-02 13:10       ` Dr. David Alan Gilbert
  2020-12-02 13:15         ` Daniel P. Berrangé
  2020-12-02 13:36         ` Paolo Bonzini
  0 siblings, 2 replies; 78+ messages in thread
From: Dr. David Alan Gilbert @ 2020-12-02 13:10 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Igor Mammedov, qemu-devel

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 20/11/20 16:34, Igor Mammedov wrote:
> > >       qapi_event_send_migration(MIGRATION_STATUS_SETUP);
> > > -    if (!strcmp(uri, "defer")) {
> > > -        deferred_incoming_migration(errp);
> > > -    } else if (strstart(uri, "tcp:", &p) ||
> > > -               strstart(uri, "unix:", NULL) ||
> > > -               strstart(uri, "vsock:", NULL)) {
> > considering the last hunk does won't call qmp_migrate_incoming
> > if 'defer' was used, wouldn't we will lose QAPI event here?
> > not sure how important it to users,
> 
> Hmm yeah that's true.  That might even be considered a bugfix (no setup is
> done until the "real" migrate-incoming command), but I can also add the
> event manually in qemu_init.
> 
> (Libvirt doesn't use the SETUP case of the event but that's of course only
> part of the story).

I'm more worried about how this stops a repeated 'migrate incoming'
or a 'migrate_incoming' that's issued following a qemu that's been
started with -incoming tcp:... but which a socket hasn't yet connected
to.

Dave

> Paolo
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-12-02 13:10       ` Dr. David Alan Gilbert
@ 2020-12-02 13:15         ` Daniel P. Berrangé
  2020-12-02 13:29           ` Paolo Bonzini
  2020-12-02 13:36         ` Paolo Bonzini
  1 sibling, 1 reply; 78+ messages in thread
From: Daniel P. Berrangé @ 2020-12-02 13:15 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: Paolo Bonzini, qemu-devel, Igor Mammedov

On Wed, Dec 02, 2020 at 01:10:37PM +0000, Dr. David Alan Gilbert wrote:
> * Paolo Bonzini (pbonzini@redhat.com) wrote:
> > On 20/11/20 16:34, Igor Mammedov wrote:
> > > >       qapi_event_send_migration(MIGRATION_STATUS_SETUP);
> > > > -    if (!strcmp(uri, "defer")) {
> > > > -        deferred_incoming_migration(errp);
> > > > -    } else if (strstart(uri, "tcp:", &p) ||
> > > > -               strstart(uri, "unix:", NULL) ||
> > > > -               strstart(uri, "vsock:", NULL)) {
> > > considering the last hunk does won't call qmp_migrate_incoming
> > > if 'defer' was used, wouldn't we will lose QAPI event here?
> > > not sure how important it to users,
> > 
> > Hmm yeah that's true.  That might even be considered a bugfix (no setup is
> > done until the "real" migrate-incoming command), but I can also add the
> > event manually in qemu_init.
> > 
> > (Libvirt doesn't use the SETUP case of the event but that's of course only
> > part of the story).
> 
> I'm more worried about how this stops a repeated 'migrate incoming'
> or a 'migrate_incoming' that's issued following a qemu that's been
> started with -incoming tcp:... but which a socket hasn't yet connected
> to.

Can someone remind me why we need to have an -incoming arg at all ?

With snapshots, we can just start QEMU normally, using -S if desired,
and then invoke "loadvm" to restore from a snapshot at any time.

What is different thet means we can't just run "migrate_incoming" on
any QEMU at any time, ignoring -incoming entirely ?


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-12-02 13:15         ` Daniel P. Berrangé
@ 2020-12-02 13:29           ` Paolo Bonzini
  0 siblings, 0 replies; 78+ messages in thread
From: Paolo Bonzini @ 2020-12-02 13:29 UTC (permalink / raw)
  To: Daniel P. Berrangé, Dr. David Alan Gilbert; +Cc: Igor Mammedov, qemu-devel

On 02/12/20 14:15, Daniel P. Berrangé wrote:
> Can someone remind me why we need to have an -incoming arg at all ?
> 
> With snapshots, we can just start QEMU normally, using -S if desired,
> and then invoke "loadvm" to restore from a snapshot at any time.
> 
> What is different thet means we can't just run "migrate_incoming" on
> any QEMU at any time, ignoring -incoming entirely ?

There are some parts of QEMU that operate differently based on 
RUN_STATE_INCOMING.  Removing those is one of the things that these 
patches should enable, though there are also some uses in Xen that I'm 
more worried about.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-12-02 13:10       ` Dr. David Alan Gilbert
  2020-12-02 13:15         ` Daniel P. Berrangé
@ 2020-12-02 13:36         ` Paolo Bonzini
  2020-12-02 15:08           ` Dr. David Alan Gilbert
  1 sibling, 1 reply; 78+ messages in thread
From: Paolo Bonzini @ 2020-12-02 13:36 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: Igor Mammedov, qemu-devel

On 02/12/20 14:10, Dr. David Alan Gilbert wrote:
> I'm more worried about how this stops a repeated 'migrate incoming'
> or a 'migrate_incoming' that's issued following a qemu that's been
> started with -incoming tcp:... but which a socket hasn't yet connected
> to.

Good question, fortunately it is simply handled answer:

void qmp_migrate_incoming(const char *uri, Error **errp)
{
     Error *local_err = NULL;
     static bool once = true;

     if (!once) {
         error_setg(errp, "The incoming migration has already been 
started");
         return;
     }
     if (!runstate_check(RUN_STATE_INMIGRATE)) {
         error_setg(errp, "'-incoming' was not specified on the command 
line");
         return;
     }

     qemu_start_incoming_migration(uri, &local_err);

     if (local_err) {
         error_propagate(errp, local_err);
         return;
     }

     once = false;
}

This patch can simplify things because every incoming migrations (no 
matter if '-incoming defer' or '-incoming tcp:...') goes through the 
qmp_migrate_incoming function above.

Paolo



^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming
  2020-12-02 13:36         ` Paolo Bonzini
@ 2020-12-02 15:08           ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 78+ messages in thread
From: Dr. David Alan Gilbert @ 2020-12-02 15:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Igor Mammedov, qemu-devel

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 02/12/20 14:10, Dr. David Alan Gilbert wrote:
> > I'm more worried about how this stops a repeated 'migrate incoming'
> > or a 'migrate_incoming' that's issued following a qemu that's been
> > started with -incoming tcp:... but which a socket hasn't yet connected
> > to.
> 
> Good question, fortunately it is simply handled answer:
> 
> void qmp_migrate_incoming(const char *uri, Error **errp)
> {
>     Error *local_err = NULL;
>     static bool once = true;
> 
>     if (!once) {
>         error_setg(errp, "The incoming migration has already been started");
>         return;
>     }
>     if (!runstate_check(RUN_STATE_INMIGRATE)) {
>         error_setg(errp, "'-incoming' was not specified on the command
> line");
>         return;
>     }
> 
>     qemu_start_incoming_migration(uri, &local_err);
> 
>     if (local_err) {
>         error_propagate(errp, local_err);
>         return;
>     }
> 
>     once = false;
> }
> 
> This patch can simplify things because every incoming migrations (no matter
> if '-incoming defer' or '-incoming tcp:...') goes through the
> qmp_migrate_incoming function above.

Yeh I think that's OK.

Dave

> Paolo
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2020-12-02 15:10 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 18:21 [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Paolo Bonzini
2020-10-27 18:21 ` [PATCH 01/29] trace: remove argument from trace_init_file Paolo Bonzini
2020-10-27 18:21 ` [PATCH 02/29] semihosting: fix order of initialization functions Paolo Bonzini
2020-10-27 18:21 ` [PATCH 03/29] vl: extract validation of -smp to machine.c Paolo Bonzini
2020-10-28 16:32   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 04/29] vl: remove bogus check Paolo Bonzini
2020-10-28 16:48   ` Igor Mammedov
2020-10-28 16:55     ` Daniel P. Berrangé
2020-10-28 19:32   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 05/29] vl: split various early command line options to a separate function Paolo Bonzini
2020-11-02 15:30   ` Igor Mammedov
2020-11-02 16:33     ` Paolo Bonzini
2020-10-27 18:21 ` [PATCH 06/29] vl: move various initialization routines out of qemu_init Paolo Bonzini
2020-11-02 15:40   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 07/29] vl: extract qemu_init_subsystems Paolo Bonzini
2020-11-02 15:55   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 08/29] vl: move prelaunch part of qemu_init to new functions Paolo Bonzini
2020-11-11 19:29   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 09/29] vl: extract various command line validation snippets to a new function Paolo Bonzini
2020-11-11 19:39   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 10/29] vl: preconfig and loadvm are mutually exclusive Paolo Bonzini
2020-11-11 19:58   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 11/29] vl: extract various command line desugaring snippets to a new function Paolo Bonzini
2020-11-11 19:57   ` Igor Mammedov
2020-11-11 20:04     ` Paolo Bonzini
2020-11-18 16:55       ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 12/29] vl: create "-net nic -net user" default earlier Paolo Bonzini
2020-11-18 14:43   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 13/29] vl: load plugins as late as possible Paolo Bonzini
2020-10-27 18:21 ` [PATCH 14/29] vl: move semihosting command line fallback to qemu_finish_machine_init Paolo Bonzini
2020-10-27 18:21 ` [PATCH 15/29] vl: extract default devices to separate functions Paolo Bonzini
2020-10-27 18:21 ` [PATCH 16/29] vl: move CHECKPOINT_INIT after preconfig Paolo Bonzini
2020-10-27 18:21 ` [PATCH 17/29] vl: separate qemu_create_early_backends Paolo Bonzini
2020-11-18 16:29   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 18/29] vl: separate qemu_create_late_backends Paolo Bonzini
2020-11-18 16:33   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 19/29] vl: separate qemu_create_machine Paolo Bonzini
2020-11-18 16:45   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 20/29] vl: separate qemu_apply_machine_options Paolo Bonzini
2020-11-18 16:57   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 21/29] vl: separate qemu_resolve_machine_memdev Paolo Bonzini
2020-11-20 13:15   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 22/29] vl: initialize displays before preconfig loop Paolo Bonzini
2020-11-20 15:11   ` Igor Mammedov
2020-11-20 15:53     ` Paolo Bonzini
2020-11-20 16:32       ` Igor Mammedov
2020-11-20 16:46         ` Paolo Bonzini
2020-11-20 17:11           ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 23/29] vl: move -global check earlier Paolo Bonzini
2020-11-20 15:10   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 24/29] migration, vl: start migration via qmp_migrate_incoming Paolo Bonzini
2020-11-20 15:34   ` Igor Mammedov
2020-11-20 16:02     ` Paolo Bonzini
2020-12-02 13:10       ` Dr. David Alan Gilbert
2020-12-02 13:15         ` Daniel P. Berrangé
2020-12-02 13:29           ` Paolo Bonzini
2020-12-02 13:36         ` Paolo Bonzini
2020-12-02 15:08           ` Dr. David Alan Gilbert
2020-10-27 18:21 ` [PATCH 25/29] vl: start VM via qmp_cont Paolo Bonzini
2020-11-20 16:08   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 26/29] hmp: introduce cmd_available Paolo Bonzini
2020-11-20 15:46   ` Igor Mammedov
2020-10-27 18:21 ` [PATCH 27/29] remove preconfig state Paolo Bonzini
2020-11-20 16:01   ` Igor Mammedov
2020-11-20 16:22     ` Paolo Bonzini
2020-10-27 18:21 ` [PATCH 28/29] vl: remove separate preconfig main_loop Paolo Bonzini
2020-11-20 16:26   ` Igor Mammedov
2020-11-20 16:39     ` Paolo Bonzini
2020-11-23  8:34     ` Paolo Bonzini
2020-10-27 18:21 ` [PATCH 29/29] vl: allow -incoming defer with -preconfig Paolo Bonzini
2020-11-20 16:28   ` Igor Mammedov
2020-11-20 16:45     ` Paolo Bonzini
2020-11-02 15:57 ` [RFC PATCH v2 00/37] cleanup qemu_init and make sense of command line processing Igor Mammedov
2020-11-02 16:34   ` Paolo Bonzini
2020-11-03 12:57     ` Igor Mammedov
2020-11-03 14:37       ` Paolo Bonzini
2020-11-20 16:19         ` Igor Mammedov
2020-11-20 16:27           ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.