diff --git a/hmp-commands.hx b/hmp-commands.hx index a511004434f5ce92cf45d53a85e447ea7e260b10..3a4ae3950ad500fce21a86147317fe3bf21fa3f0 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -676,7 +676,8 @@ ETEXI STEXI @item device_del @var{id} @findex device_del -Remove device @var{id}. +Remove device @var{id}. @var{id} may be a short ID +or a QOM object path. ETEXI { diff --git a/qapi-schema.json b/qapi-schema.json index 821362d6373b55bbbe329282761bdc06568c4a0b..527690dfe076f640dfb701c7babd7bdf97785875 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1951,7 +1951,7 @@ # # Remove a device from a guest # -# @id: the name of the device +# @id: the name or QOM path of the device # # Returns: Nothing on success # If @id is not a valid device, DeviceNotFound diff --git a/qdev-monitor.c b/qdev-monitor.c index 0bf7f83a1d8bde97d99ffadfd55378823488375a..eb7aef2c81390221a044bfd08f2224b6463495c9 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -771,12 +771,17 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) void qmp_device_del(const char *id, Error **errp) { Object *obj; - char *root_path = object_get_canonical_path(qdev_get_peripheral()); - char *path = g_strdup_printf("%s/%s", root_path, id); - g_free(root_path); - obj = object_resolve_path_type(path, TYPE_DEVICE, NULL); - g_free(path); + if (id[0] == '/') { + obj = object_resolve_path(id, NULL); + } else { + char *root_path = object_get_canonical_path(qdev_get_peripheral()); + char *path = g_strdup_printf("%s/%s", root_path, id); + + g_free(root_path); + obj = object_resolve_path_type(path, TYPE_DEVICE, NULL); + g_free(path); + } if (!obj) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, @@ -784,6 +789,11 @@ void qmp_device_del(const char *id, Error **errp) return; } + if (!object_dynamic_cast(obj, TYPE_DEVICE)) { + error_setg(errp, "%s is not a hotpluggable device", id); + return; + } + qdev_unplug(DEVICE(obj), errp); } diff --git a/qmp-commands.hx b/qmp-commands.hx index 66f03007ecd73fc1ad925755ca9891b1e7dd07ec..d2ba800d5effaddcae4c437452ef1f67c0aaaaa9 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -321,13 +321,18 @@ Remove a device. Arguments: -- "id": the device's ID (json-string) +- "id": the device's ID or QOM path (json-string) Example: -> { "execute": "device_del", "arguments": { "id": "net1" } } <- { "return": {} } +Example: + +-> { "execute": "device_del", "arguments": { "id": "/machine/peripheral-anon/device[0]" } } +<- { "return": {} } + EQMP {