[PATCH 11/12] qom: Add object_get_container()

Peter Xu posted 12 patches 2 days, 17 hours ago
There is a newer version of this series
[PATCH 11/12] qom: Add object_get_container()
Posted by Peter Xu 2 days, 17 hours ago
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 --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;
-- 
2.45.0
Re: [PATCH 11/12] qom: Add object_get_container()
Posted by Daniel P. Berrangé 2 days, 4 hours ago
On Wed, Nov 20, 2024 at 04:57:02PM -0500, Peter Xu wrote:
> 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(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH 11/12] qom: Add object_get_container()
Posted by Philippe Mathieu-Daudé 2 days, 5 hours ago
On 20/11/24 22:57, Peter Xu wrote:
> 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(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>