From 1bf4d3294bd48b702530b131e3344860495425fd Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 19 Oct 2021 10:57:11 +0200 Subject: monitor: Fix find_device_state() for IDs containing slashes Recent commit 6952026120 "monitor: Tidy up find_device_state()" assumed the function's argument is "the device's ID or QOM path" (as documented for device_del). It's actually either an absolute QOM path, or a QOM path relative to /machine/peripheral/. Such a relative path is a device ID when it doesn't contain a slash. When it does, the function now always fails. Broke iotest 200, which uses relative path "vda/virtio-backend". It fails because object_resolve_path_component() resolves just one component, not a relative path. The obvious function to resolve relative paths is object_resolve_path(). It picks a parent automatically. Too much magic, we want to specify the parent. Create new object_resolve_path_at() for that, and use it in find_device_state(). Reported-by: Christian Borntraeger Signed-off-by: Markus Armbruster Message-Id: <20211019085711.86377-1-armbru@redhat.com> Tested-by: Christian Borntraeger Acked-by: Paolo Bonzini --- softmmu/qdev-monitor.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'softmmu') diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index f8b3a4c..b5aaae4 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -871,15 +871,9 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) static DeviceState *find_device_state(const char *id, Error **errp) { - Object *obj; + Object *obj = object_resolve_path_at(qdev_get_peripheral(), id); DeviceState *dev; - if (id[0] == '/') { - obj = object_resolve_path(id, NULL); - } else { - obj = object_resolve_path_component(qdev_get_peripheral(), id); - } - if (!obj) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", id); -- cgit v1.1