[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/22] vl: extract validation of -smp to machine.c
From: |
Paolo Bonzini |
Subject: |
[PATCH 05/22] vl: extract validation of -smp to machine.c |
Date: |
Wed, 21 Oct 2020 16:56:59 -0400 |
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 7efeac03b3..70b1e5e8e8 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1073,6 +1073,29 @@ MemoryRegion *machine_consume_memdev(MachineState
*machine,
return ret;
}
+bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
+{
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+ mc->smp_parse(ms, opts);
+
+ /* sanity-check smp_cpus and max_cpus against mc */
+ if (ms->smp.cpus < mc->min_cpus) {
+ error_setg(errp, "Invalid SMP CPUs %d. The min CPUs "
+ "supported by machine '%s' is %d",
+ ms->smp.cpus,
+ mc->name, mc->min_cpus);
+ return false;
+ } else if (ms->smp.max_cpus > mc->max_cpus) {
+ error_setg(errp, "Invalid SMP CPUs %d. The max CPUs "
+ "supported by machine '%s' is %d",
+ current_machine->smp.max_cpus,
+ mc->name, mc->max_cpus);
+ return false;
+ }
+ return true;
+}
+
void machine_run_board_init(MachineState *machine)
{
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
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 05422a15ee..8a7d11ef05 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3966,24 +3966,8 @@ void qemu_init(int argc, char **argv, char **envp)
exit(0);
}
- machine_class->smp_parse(current_machine,
- qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
-
- /* sanity-check smp_cpus and max_cpus against machine_class */
- if (current_machine->smp.cpus < machine_class->min_cpus) {
- error_report("Invalid SMP CPUs %d. The min CPUs "
- "supported by machine '%s' is %d",
- current_machine->smp.cpus,
- machine_class->name, machine_class->min_cpus);
- exit(1);
- }
- if (current_machine->smp.max_cpus > machine_class->max_cpus) {
- error_report("Invalid SMP CPUs %d. The max CPUs "
- "supported by machine '%s' is %d",
- current_machine->smp.max_cpus,
- machine_class->name, machine_class->max_cpus);
- exit(1);
- }
+ machine_smp_parse(current_machine,
+ qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
if (mem_prealloc) {
char *val;
--
2.26.2
- Re: [PATCH 03/22] machine: move UP defaults to class_base_init, (continued)
- [PATCH 04/22] machine: move SMP initialization from vl.c, Paolo Bonzini, 2020/10/21
- [PATCH 02/22] machine: remove deprecated -machine enforce-config-section option, Paolo Bonzini, 2020/10/21
- [PATCH 07/22] trace: remove argument from trace_init_file, Paolo Bonzini, 2020/10/21
- [PATCH 06/22] vl: remove bogus check, Paolo Bonzini, 2020/10/21
- [PATCH 15/22] vl: extract various command line desugaring snippets to a new function, Paolo Bonzini, 2020/10/21
- [PATCH 08/22] vl: split various early command line options to a separate function, Paolo Bonzini, 2020/10/21
- [PATCH 05/22] vl: extract validation of -smp to machine.c,
Paolo Bonzini <=
- [PATCH 01/22] semihosting: fix order of initialization functions, Paolo Bonzini, 2020/10/21
- [PATCH 11/22] vl: move prelaunch part of qemu_init to a new function, Paolo Bonzini, 2020/10/21
- [PATCH 19/22] vl: extract default devices to separate functions, Paolo Bonzini, 2020/10/21
- [PATCH 18/22] vl: move semihosting command line fallback to qemu_finish_machine_init, Paolo Bonzini, 2020/10/21
- [PATCH 20/22] vl: move CHECKPOINT_INIT after preconfig, Paolo Bonzini, 2020/10/21
- [PATCH 22/22] vl: separate qemu_create_late_backends, Paolo Bonzini, 2020/10/21
- [PATCH 10/22] vl: extract qemu_init_subsystems, Paolo Bonzini, 2020/10/21