[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 06/14] qapi/device_add: Allow execution in machine initialized
From: |
Damien Hedde |
Subject: |
[PATCH v4 06/14] qapi/device_add: Allow execution in machine initialized phase |
Date: |
Wed, 23 Feb 2022 10:06:58 +0100 |
From: Mirela Grujic <mirela.grujic@greensocs.com>
This commit allows to use the QMP command to add a cold-plugged
device like we can do with the CLI option -device.
Note: for device_add command in qdev.json adding the 'allow-preconfig'
option has no effect because the command appears to bypass QAPI (see
TODO at qapi/qdev.json:61). The option is added there solely to
document the intent.
For the same reason, the flags have to be explicitly set in
monitor_init_qmp_commands() when the device_add command is registered.
Signed-off-by: Mirela Grujic <mirela.grujic@greensocs.com>
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
v4:
+ use phase_until()
+ add missing flag in hmp-commands.hx
---
qapi/qdev.json | 3 ++-
monitor/misc.c | 2 +-
softmmu/qdev-monitor.c | 4 ++++
hmp-commands.hx | 1 +
4 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/qapi/qdev.json b/qapi/qdev.json
index 26cd10106b..2e2de41499 100644
--- a/qapi/qdev.json
+++ b/qapi/qdev.json
@@ -77,7 +77,8 @@
{ 'command': 'device_add',
'data': {'driver': 'str', '*bus': 'str', '*id': 'str'},
'gen': false, # so we can get the additional arguments
- 'features': ['json-cli', 'json-cli-hotplug'] }
+ 'features': ['json-cli', 'json-cli-hotplug'],
+ 'allow-preconfig': true }
##
# @device_del:
diff --git a/monitor/misc.c b/monitor/misc.c
index a3a6e47844..fd56dd8f08 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -233,7 +233,7 @@ static void monitor_init_qmp_commands(void)
qmp_init_marshal(&qmp_commands);
qmp_register_command(&qmp_commands, "device_add",
- qmp_device_add, 0, 0);
+ qmp_device_add, QCO_ALLOW_PRECONFIG, 0);
QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 9ec3e0ebff..ec0eddaf72 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -853,6 +853,10 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,
Error **errp)
QemuOpts *opts;
DeviceState *dev;
+ if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) {
+ return;
+ }
+
opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp);
if (!opts) {
return;
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 70a9136ac2..3237085e22 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -668,6 +668,7 @@ ERST
.help = "add device, like -device on the command line",
.cmd = hmp_device_add,
.command_completion = device_add_completion,
+ .flags = "p",
},
SRST
--
2.35.1
- [PATCH v4 00/14] Initial support for machine creation via QMP, Damien Hedde, 2022/02/23
- [PATCH v4 05/14] qapi/device_add: handle the rom_order_override when cold-plugging, Damien Hedde, 2022/02/23
- [PATCH v4 10/14] none-machine: allow several cpus, Damien Hedde, 2022/02/23
- [PATCH v4 08/14] none-machine: add 'ram-addr' property, Damien Hedde, 2022/02/23
- [PATCH v4 02/14] machine&vl: introduce phase_until() to handle phase transitions, Damien Hedde, 2022/02/23
- [PATCH v4 06/14] qapi/device_add: Allow execution in machine initialized phase,
Damien Hedde <=
- [PATCH v4 07/14] none-machine: add the NoneMachineState structure, Damien Hedde, 2022/02/23
- [PATCH v4 01/14] machine: add phase_get() and document phase_check()/advance(), Damien Hedde, 2022/02/23
- [PATCH v4 03/14] vl: support machine-initialized target in phase_until(), Damien Hedde, 2022/02/23
- [PATCH v4 12/14] add sysbus-mmio-map qapi command, Damien Hedde, 2022/02/23
- [PATCH v4 04/14] qapi/device_add: compute is_hotplug flag, Damien Hedde, 2022/02/23
- [PATCH v4 09/14] none-machine: allow cold plugging sysbus devices, Damien Hedde, 2022/02/23
- [PATCH v4 13/14] hw/mem/system-memory: add a memory sysbus device, Damien Hedde, 2022/02/23