@@ -74,7 +74,8 @@
{ 'command': 'device_add',
'data': {'driver': 'str', '*bus': 'str', '*id': 'str'},
'gen': false, # so we can get the additional arguments
- 'features': ['json-cli'] }
+ 'features': ['json-cli'],
+ 'allow-preconfig': true }
##
# @device_del:
@@ -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",
@@ -842,6 +842,12 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
QemuOpts *opts;
DeviceState *dev;
+ if (!phase_check(MACHINE_INIT_PHASE_INITIALIZED)) {
+ error_setg(errp, "The command is permitted only after "
+ "the machine is initialized");
+ return;
+ }
+
opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp);
if (!opts) {
return;