[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 04/41] qom/object: Introduce helper to resolve path from non-direct
From: |
Zhao Liu |
Subject: |
[RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent |
Date: |
Thu, 30 Nov 2023 22:41:26 +0800 |
From: Zhao Liu <zhao1.liu@intel.com>
When we support child<> property creation from cli, the peripheral
container (/machine/peripheral) may not be the direct parent of the
devices created from cli.
For this case, add a helper to resolve path from non-direct parent.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
include/qom/object.h | 15 +++++++++++++++
qom/object.c | 18 ++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index afccd24ca7ab..494eef801be3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1562,6 +1562,21 @@ Object *object_resolve_path_type(const char *path, const
char *typename,
*/
Object *object_resolve_path_at(Object *parent, const char *path);
+/**
+ * object_resolve_path_from:
+ * @parent: the object from which to resolve the path
+ * @path: the path to resolve
+ * @ambiguous: returns true if the path resolution failed because of an
+ * ambiguous match
+ *
+ * This is like object_resolve_path_at(), except @parent may be the
+ * partial parent of @path.
+ *
+ * Returns: The resolved object or NULL on path lookup failure.
+ */
+Object *object_resolve_path_from(Object *parent, const char *path,
+ bool *ambiguous);
+
/**
* object_resolve_path_component:
* @parent: the object in which to resolve the path
diff --git a/qom/object.c b/qom/object.c
index 95c0dc8285fe..da29e88816b5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2192,6 +2192,24 @@ Object *object_resolve_path_at(Object *parent, const
char *path)
return object_resolve_abs_path(parent, parts, TYPE_OBJECT);
}
+Object *object_resolve_path_from(Object *parent, const char *path,
+ bool *ambiguousp)
+{
+ g_auto(GStrv) parts = NULL;
+ bool ambiguous = false;
+ Object *obj;
+
+ parts = g_strsplit(path, "/", 0);
+ assert(parts);
+
+ obj = object_resolve_partial_path(parent, parts, TYPE_OBJECT,
+ &ambiguous);
+ if (ambiguousp) {
+ *ambiguousp = ambiguous;
+ }
+ return obj;
+}
+
typedef struct StringProperty
{
char *(*get)(Object *, Error **);
--
2.34.1
- [RFC 00/41] qom-topo: Abstract Everything about CPU Topology, Zhao Liu, 2023/11/30
- [RFC 01/41] qdev: Introduce new device category to cover basic topology device, Zhao Liu, 2023/11/30
- [RFC 02/41] qdev: Allow qdev_device_add() to add specific category device, Zhao Liu, 2023/11/30
- [RFC 03/41] system: Create base category devices from cli before board initialization, Zhao Liu, 2023/11/30
- [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent,
Zhao Liu <=
- [RFC 05/41] qdev: Set device parent and id after setting properties, Zhao Liu, 2023/11/30
- [RFC 06/41] qdev: Introduce user-child interface to collect devices from -device, Zhao Liu, 2023/11/30
- [RFC 07/41] qdev: Introduce parent option in -device, Zhao Liu, 2023/11/30
- [RFC 08/41] hw/core/topo: Introduce CPU topology device abstraction, Zhao Liu, 2023/11/30
- [RFC 09/41] hw/core/topo: Support topology index for topology device, Zhao Liu, 2023/11/30
- [RFC 10/41] hw/core/topo: Add virtual method to update topology info for parent, Zhao Liu, 2023/11/30
- [RFC 11/41] hw/core/topo: Add virtual method to check topology child, Zhao Liu, 2023/11/30
- [RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree, Zhao Liu, 2023/11/30
- [RFC 13/41] hw/core/cpu: Convert CPU from general device to topology device, Zhao Liu, 2023/11/30
- [RFC 14/41] PPC/ppc-core: Offload core-id to PPC specific core abstarction, Zhao Liu, 2023/11/30