diff mbox series

[11/12] qom: Add object_get_container()

Message ID 20241120215703.3918445-12-peterx@redhat.com (mailing list archive)
State New
Headers show
Series QOM: container_get() removal | expand

Commit Message

Peter Xu Nov. 20, 2024, 9:57 p.m. UTC
Add a helper to fetch a root container (under object_get_root()).  Sanity
check on the type of the object.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/qom/object.h | 10 ++++++++++
 qom/object.c         | 10 ++++++++++
 2 files changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index 41ef53241e..87b13f9681 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1524,6 +1524,16 @@  const char *object_property_get_type(Object *obj, const char *name,
  */
 Object *object_get_root(void);
 
+/**
+ * object_get_container:
+ * @name: the name of container to lookup
+ *
+ * Lookup a root level container.
+ *
+ * Returns: the container with @name.
+ */
+Object *object_get_container(const char *name);
+
 
 /**
  * object_get_objects_root:
diff --git a/qom/object.c b/qom/object.c
index 810e6f2bd9..cf66803a6a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1748,6 +1748,16 @@  static Object *object_root_initialize(void)
     return root;
 }
 
+Object *object_get_container(const char *name)
+{
+    Object *container;
+
+    container = object_resolve_path_component(object_get_root(), name);
+    assert(object_dynamic_cast(container, TYPE_CONTAINER));
+
+    return container;
+}
+
 Object *object_get_root(void)
 {
     static Object *root;