* [PATCH] monitor: Fix find_device_state() for IDs containing slashes
@ 2021-10-19 8:57 Markus Armbruster
2021-10-19 9:01 ` Christian Borntraeger
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Markus Armbruster @ 2021-10-19 8:57 UTC (permalink / raw)
To: qemu-devel; +Cc: damien.hedde, pbonzini, berrange, ehabkost, borntraeger
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 <borntraeger@de.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
include/qom/object.h | 12 ++++++++++++
qom/object.c | 11 +++++++++++
softmmu/qdev-monitor.c | 8 +-------
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index faae0d841f..fae096f51c 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -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
diff --git a/qom/object.c b/qom/object.c
index 6be710bc40..4f0677cca9 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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 **);
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 89c473cb22..e8a1c7e52a 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -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);
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] monitor: Fix find_device_state() for IDs containing slashes
2021-10-19 8:57 [PATCH] monitor: Fix find_device_state() for IDs containing slashes Markus Armbruster
@ 2021-10-19 9:01 ` Christian Borntraeger
2021-10-19 10:13 ` Paolo Bonzini
2021-11-10 5:49 ` Markus Armbruster
2 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2021-10-19 9:01 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: damien.hedde, pbonzini, berrange, ehabkost
Am 19.10.21 um 10:57 schrieb 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 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 <borntraeger@de.ibm.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
thank you for your quick response, highly appreciated.
> ---
> include/qom/object.h | 12 ++++++++++++
> qom/object.c | 11 +++++++++++
> softmmu/qdev-monitor.c | 8 +-------
> 3 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index faae0d841f..fae096f51c 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -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
> diff --git a/qom/object.c b/qom/object.c
> index 6be710bc40..4f0677cca9 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -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 **);
> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
> index 89c473cb22..e8a1c7e52a 100644
> --- a/softmmu/qdev-monitor.c
> +++ b/softmmu/qdev-monitor.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] monitor: Fix find_device_state() for IDs containing slashes
2021-10-19 8:57 [PATCH] monitor: Fix find_device_state() for IDs containing slashes Markus Armbruster
2021-10-19 9:01 ` Christian Borntraeger
@ 2021-10-19 10:13 ` Paolo Bonzini
2021-10-28 5:40 ` Markus Armbruster
2021-11-10 5:49 ` Markus Armbruster
2 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2021-10-19 10:13 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel
Cc: damien.hedde, borntraeger, berrange, ehabkost
On 19/10/21 10:57, Markus Armbruster wrote:
> 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 <borntraeger@de.ibm.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> include/qom/object.h | 12 ++++++++++++
> qom/object.c | 11 +++++++++++
> softmmu/qdev-monitor.c | 8 +-------
> 3 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index faae0d841f..fae096f51c 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -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
> diff --git a/qom/object.c b/qom/object.c
> index 6be710bc40..4f0677cca9 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -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 **);
> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
> index 89c473cb22..e8a1c7e52a 100644
> --- a/softmmu/qdev-monitor.c
> +++ b/softmmu/qdev-monitor.c
> @@ -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);
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Thanks for the quick fix!
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] monitor: Fix find_device_state() for IDs containing slashes
2021-10-19 10:13 ` Paolo Bonzini
@ 2021-10-28 5:40 ` Markus Armbruster
2021-11-04 8:59 ` Markus Armbruster
0 siblings, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2021-10-28 5:40 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: damien.hedde, borntraeger, berrange, qemu-devel, ehabkost
Paolo Bonzini <pbonzini@redhat.com> writes:
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Thanks for the quick fix!
Who's going to do the pull request?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] monitor: Fix find_device_state() for IDs containing slashes
2021-10-28 5:40 ` Markus Armbruster
@ 2021-11-04 8:59 ` Markus Armbruster
0 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2021-11-04 8:59 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: damien.hedde, borntraeger, berrange, qemu-devel, ehabkost
Markus Armbruster <armbru@redhat.com> writes:
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
>> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>>
>> Thanks for the quick fix!
>
> Who's going to do the pull request?
Ping!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] monitor: Fix find_device_state() for IDs containing slashes
2021-10-19 8:57 [PATCH] monitor: Fix find_device_state() for IDs containing slashes Markus Armbruster
2021-10-19 9:01 ` Christian Borntraeger
2021-10-19 10:13 ` Paolo Bonzini
@ 2021-11-10 5:49 ` Markus Armbruster
2 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2021-11-10 5:49 UTC (permalink / raw)
To: qemu-devel; +Cc: damien.hedde, pbonzini, berrange, ehabkost, borntraeger
Markus Armbruster <armbru@redhat.com> writes:
> 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 <borntraeger@de.ibm.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Queued for 6.2 & PR sent.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-10 5:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 8:57 [PATCH] monitor: Fix find_device_state() for IDs containing slashes Markus Armbruster
2021-10-19 9:01 ` Christian Borntraeger
2021-10-19 10:13 ` Paolo Bonzini
2021-10-28 5:40 ` Markus Armbruster
2021-11-04 8:59 ` Markus Armbruster
2021-11-10 5:49 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).