aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-11-10 09:52:41 +0100
committerRichard Henderson <richard.henderson@linaro.org>2021-11-10 09:52:41 +0100
commitd73b6ae2c0893420c4b5d9f15b5e1407ca0d2173 (patch)
treef8f02e4b994b3c48eaf702044c10a6709fd40527
parent856f9fa9a2c528dc29693d3b3a64a9b93bf866a2 (diff)
parent1bf4d3294bd48b702530b131e3344860495425fd (diff)
downloadqemu-d73b6ae2c0893420c4b5d9f15b5e1407ca0d2173.zip
qemu-d73b6ae2c0893420c4b5d9f15b5e1407ca0d2173.tar.gz
qemu-d73b6ae2c0893420c4b5d9f15b5e1407ca0d2173.tar.bz2
Merge tag 'pull-monitor-2021-11-10' of git://repo.or.cz/qemu/armbru into staging
Monitor patches patches for 2021-11-10 # gpg: Signature made Wed 10 Nov 2021 06:15:38 AM CET # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] * tag 'pull-monitor-2021-11-10' of git://repo.or.cz/qemu/armbru: monitor: Fix find_device_state() for IDs containing slashes Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
-rw-r--r--include/qom/object.h12
-rw-r--r--qom/object.c11
-rw-r--r--softmmu/qdev-monitor.c8
3 files changed, 24 insertions, 7 deletions
diff --git a/include/qom/object.h b/include/qom/object.h
index faae0d8..fae096f 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1544,6 +1544,18 @@ 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
* @part: the component to resolve.
diff --git a/qom/object.c b/qom/object.c
index 6be710b..4f0677c 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 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);