monitor: Fix find_device_state() for IDs containing slashes
PATCH 1/1 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().
--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 11 +++++++++++ softmmu/qdev-monitor.c | 8 +------- 3 files changed, 24 insertions(+), 7 deletions(-)
include/qom/object.h +12 -0
@@ -1543,6 +1543,18 @@ Object *object_resolve_path(const char *path, bool *ambiguous);Object *object_resolve_path_type (const char *path,const char *typename,bool *ambiguous); +/** +* object_resolve_path_at: +* @parent: the object in which to resolve the path +* @path: the path to resolve +* +* This is like object_resolve_path(), except paths not starting with +* a slash are relative to @parent. +* +* Returns: The resolved object or NULL on path lookup failure. +*/ +Object *object_resolve_path_at (Object *parent,const char *path); +/** * object_resolve_path_component: * @parent: the object in which to resolve the path
qom/object.c +11 -0
@@ -2144,6 +2144,17 @@ Object *object_resolve_path(const char *path, bool *ambiguous)return object_resolve_path_type (path,TYPE_OBJECT , ambiguous); } +Object *object_resolve_path_at (Object *parent,const char *path) +{ +g_auto (GStrv) parts =g_strsplit (path,"/" ,0 ); + +if (*path =='/' ) { +return object_resolve_abs_path (object_get_root (), parts +1 , +TYPE_OBJECT ); + } +return object_resolve_abs_path (parent, parts,TYPE_OBJECT ); +} + typedef struct StringProperty { char *(*get)(Object *, Error **);
softmmu/qdev-monitor.c +1 -7
@@ -865,15 +865,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);
Signature · 1 line
2.31.1
Am 19.10.21 um 10:57 schrieb Markus Armbruster:
Quoted 11 lines
Recent commit 6952026120 "monitor: Tidy up
find_device_state()" assumed the function's argument is "the device's ID or QOM path" (as documented fordevice_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.
Quoted 7 lines
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 newobject_resolve_path_at()for that, and use it infind_device_state().Reported-by Christian Borntraeger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
thank you for your quick response, highly appreciated.
Quoted 73 lines
--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 11 +++++++++++ softmmu/qdev-monitor.c | 8 +------- 3 files changed, 24 insertions(+), 7 deletions(-)include/qom/object.h +12
-0@@ -1543,6 +1543,18 @@ Object *object_resolve_path(const char *path, bool *ambiguous);Object *object_resolve_path_type (const char *path,const char *typename,bool *ambiguous); +/** +* object_resolve_path_at: +* @parent: the object in which to resolve the path +* @path: the path to resolve +* +* This is like object_resolve_path(), except paths not starting with +* a slash are relative to @parent. +* +* Returns: The resolved object or NULL on path lookup failure. +*/ +Object *object_resolve_path_at (Object *parent,const char *path); +/** * object_resolve_path_component: * @parent: the object in which to resolve the path qom/object.c +11
-0@@ -2144,6 +2144,17 @@ Object *object_resolve_path(const char *path, bool *ambiguous)return object_resolve_path_type (path,TYPE_OBJECT , ambiguous); } +Object *object_resolve_path_at (Object *parent,const char *path) +{ +g_auto (GStrv) parts =g_strsplit (path,"/" ,0 ); + +if (*path =='/' ) { +return object_resolve_abs_path (object_get_root (), parts +1 , +TYPE_OBJECT ); + } +return object_resolve_abs_path (parent, parts,TYPE_OBJECT ); +} + typedef struct StringProperty { char *(*get)(Object *, Error **);softmmu/qdev-monitor.c +1
-7@@ -865,15 +865,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);
Quoted 81 lines · Markus Armbruster
Recent commit 6952026120 "monitor: Tidy up
find_device_state()" assumed the function's argument is "the device's ID or QOM path" (as documented fordevice_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 newobject_resolve_path_at()for that, and use it infind_device_state().Reported-by Christian Borntraeger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 11 +++++++++++ softmmu/qdev-monitor.c | 8 +------- 3 files changed, 24 insertions(+), 7 deletions(-)include/qom/object.h +12
-0@@ -1543,6 +1543,18 @@ Object *object_resolve_path(const char *path, bool *ambiguous);Object *object_resolve_path_type (const char *path,const char *typename,bool *ambiguous); +/** +* object_resolve_path_at: +* @parent: the object in which to resolve the path +* @path: the path to resolve +* +* This is like object_resolve_path(), except paths not starting with +* a slash are relative to @parent. +* +* Returns: The resolved object or NULL on path lookup failure. +*/ +Object *object_resolve_path_at (Object *parent,const char *path); +/** * object_resolve_path_component: * @parent: the object in which to resolve the path qom/object.c +11
-0@@ -2144,6 +2144,17 @@ Object *object_resolve_path(const char *path, bool *ambiguous)return object_resolve_path_type (path,TYPE_OBJECT , ambiguous); } +Object *object_resolve_path_at (Object *parent,const char *path) +{ +g_auto (GStrv) parts =g_strsplit (path,"/" ,0 ); + +if (*path =='/' ) { +return object_resolve_abs_path (object_get_root (), parts +1 , +TYPE_OBJECT ); + } +return object_resolve_abs_path (parent, parts,TYPE_OBJECT ); +} + typedef struct StringProperty { char *(*get)(Object *, Error **);softmmu/qdev-monitor.c +1
-1@@ -865,15 +865,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;
softmmu/qdev-monitor.c void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) · line 873
Quoted 10 lines
softmmu/qdev-monitor.c +0
-6-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);
Thanks for the quick fix!
Paolo
Quoted 3 lines · Paolo Bonzini
Acked-by Paolo Bonzini <[email protected]>Thanks for the quick fix!
Who's going to do the pull request?
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Paolo Bonzini
Acked-by Paolo Bonzini <[email protected]>Thanks for the quick fix!
Who's going to do the pull request?
Ping!
Quoted 11 lines · Markus Armbruster
Recent commit 6952026120 "monitor: Tidy up
find_device_state()" assumed the function's argument is "the device's ID or QOM path" (as documented fordevice_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.
Quoted 7 lines
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 newobject_resolve_path_at()for that, and use it infind_device_state().Reported-by Christian Borntraeger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Queued for 6.2 & PR sent.