diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-11-12 09:38:36 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-12-15 12:51:52 -0500 |
commit | 2f181fbd5a9d456d1da291bea61d7e3ad10ec7d1 (patch) | |
tree | f6be4e559a9b9a95a2870caf0fc323e7ca6778e7 /hw/core | |
parent | 5a1ee6077b89ee9a803aaf8d1c98004701f63684 (diff) | |
download | qemu-2f181fbd5a9d456d1da291bea61d7e3ad10ec7d1.zip qemu-2f181fbd5a9d456d1da291bea61d7e3ad10ec7d1.tar.gz qemu-2f181fbd5a9d456d1da291bea61d7e3ad10ec7d1.tar.bz2 |
machine: introduce MachineInitPhase
Generalize the qdev_hotplug variable to the different phases of
machine initialization. We would like to allow different
monitor commands depending on the phase.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/core')
-rw-r--r-- | hw/core/machine-qmp-cmds.c | 6 | ||||
-rw-r--r-- | hw/core/machine.c | 8 | ||||
-rw-r--r-- | hw/core/qdev.c | 16 |
3 files changed, 20 insertions, 10 deletions
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index cb9387c..87f1414 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -286,9 +286,9 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) void qmp_set_numa_node(NumaOptions *cmd, Error **errp) { - if (qdev_hotplug) { - error_setg(errp, "The command is permitted only before the machine has been created"); - return; + if (phase_check(PHASE_MACHINE_INITIALIZED)) { + error_setg(errp, "The command is permitted only before the machine has been created"); + return; } set_numa_options(MACHINE(qdev_get_machine()), cmd, errp); diff --git a/hw/core/machine.c b/hw/core/machine.c index 07268af..607eb88 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1174,17 +1174,16 @@ void machine_run_board_init(MachineState *machine) } machine_class->init(machine); + phase_advance(PHASE_MACHINE_INITIALIZED); } static NotifierList machine_init_done_notifiers = NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); -static bool machine_init_done; - void qemu_add_machine_init_done_notifier(Notifier *notify) { notifier_list_add(&machine_init_done_notifiers, notify); - if (machine_init_done) { + if (phase_check(PHASE_MACHINE_READY)) { notify->notify(notify, NULL); } } @@ -1207,7 +1206,7 @@ void qdev_machine_creation_done(void) * ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - qdev_hotplug = true; + phase_advance(PHASE_MACHINE_READY); qdev_assert_realized_properly(); /* TODO: once all bus devices are qdevified, this should be done @@ -1222,7 +1221,6 @@ void qdev_machine_creation_done(void) */ qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); - machine_init_done = true; notifier_list_notify(&machine_init_done_notifiers, NULL); if (rom_check_and_register_reset() != 0) { diff --git a/hw/core/qdev.c b/hw/core/qdev.c index dddb0b2..cefc5ea 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -41,7 +41,6 @@ #include "migration/vmstate.h" #include "trace.h" -bool qdev_hotplug = false; static bool qdev_hot_added = false; bool qdev_hot_removed = false; @@ -905,7 +904,7 @@ static void device_initfn(Object *obj) { DeviceState *dev = DEVICE(obj); - if (qdev_hotplug) { + if (phase_check(PHASE_MACHINE_READY)) { dev->hotplugged = 1; qdev_hot_added = true; } @@ -1138,6 +1137,19 @@ Object *qdev_get_machine(void) return dev; } +static MachineInitPhase machine_phase; + +bool phase_check(MachineInitPhase phase) +{ + return machine_phase >= phase; +} + +void phase_advance(MachineInitPhase phase) +{ + assert(machine_phase == phase - 1); + machine_phase = phase; +} + static const TypeInfo device_type_info = { .name = TYPE_DEVICE, .parent = TYPE_OBJECT, |