[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 34/41] hw/core/topo: Implement user-child to collect topology device from cli, (continued)
- [RFC 34/41] hw/core/topo: Implement user-child to collect topology device from cli, Zhao Liu, 2023/11/30
- [RFC 35/41] hw/i386: Make x86_cpu_new() private in x86.c, Zhao Liu, 2023/11/30
- [RFC 37/41] hw/i386: Allow i386 to create new CPUs from QOM topology, Zhao Liu, 2023/11/30
- [RFC 38/41] hw/i386: Wrap apic id and topology sub ids assigning as helpers, Zhao Liu, 2023/11/30
- [RFC 01/41] qdev: Introduce new device category to cover basic topology device, Zhao Liu, 2023/11/30
- [RFC 21/41] hw/cpu/cluster: Allow cpu-cluster to be created by -device, Zhao Liu, 2023/11/30
- [RFC 22/41] hw/cpu/cluster: Convert cpu-cluster from general device to topology device, Zhao Liu, 2023/11/30
- [RFC 27/41] hw/core/slot: Introduce CPU slot as the root of CPU topology, Zhao Liu, 2023/11/30
- [RFC 07/41] qdev: Introduce parent option in -device, Zhao Liu, 2023/11/30
- [RFC 30/41] hw/core/slot: Check topology child to be added under CPU slot, Zhao Liu, 2023/11/30
- [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent,
Zhao Liu <=
- [RFC 06/41] qdev: Introduce user-child interface to collect devices from -device, 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 16/41] PPC/ppc-core: Limit plugged-threads and nr-threads to be equal, Zhao Liu, 2023/11/30
- [RFC 24/41] hw/cpu/socket: Abstract cpu-socket level as topology device, Zhao Liu, 2023/11/30
- [RFC 26/41] hw/cpu/drawer: Abstract cpu-drawer level as topology device, Zhao Liu, 2023/11/30
- [RFC 15/41] hw/cpu/core: Allow to configure plugged threads for cpu-core, Zhao Liu, 2023/11/30
- [RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot, Zhao Liu, 2023/11/30
- [RFC 33/41] hw/machine: Validate smp topology tree without -smp, Zhao Liu, 2023/11/30
- [RFC 36/41] hw/i386: Allow x86_cpu_new() to specify parent for new CPU, Zhao Liu, 2023/11/30