diff mbox

[RFC,v3,16/24] qom: Introduce object_has_no_children() API

Message ID 1429858066-12088-17-git-send-email-bharata@linux.vnet.ibm.com
State New
Headers show

Commit Message

Bharata B Rao April 24, 2015, 6:47 a.m. UTC
This QOM API can be used to check of an object has any child objects
associated with it.

Needed by PowerPC CPU hotplug code to release parent CPU core and
socket objects only after ascertaining that they don't have any child
objects.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 include/qom/object.h | 11 +++++++++++
 qom/object.c         | 12 ++++++++++++
 2 files changed, 23 insertions(+)

Comments

David Gibson May 5, 2015, 7:13 a.m. UTC | #1
On Fri, Apr 24, 2015 at 12:17:38PM +0530, Bharata B Rao wrote:
> This QOM API can be used to check of an object has any child objects
> associated with it.
> 
> Needed by PowerPC CPU hotplug code to release parent CPU core and
> socket objects only after ascertaining that they don't have any child
> objects.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Another one which might be worth posting independently of the powerpc
hotplug series.
diff mbox

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index d2d7748..264e412 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1317,6 +1317,17 @@  int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
                          void *opaque);
 
 /**
+ * object_has_no_children:
+ * @obj: the object which will be checked for children
+ *
+ * Navigate the properties list of the @obj and check for any child
+ * property.
+ *
+ * Returns: true if no child properties are found, else returns false.
+ */
+bool object_has_no_children(Object *obj);
+
+/**
  * container_get:
  * @root: root of the #path, e.g., object_get_root()
  * @path: path to the container
diff --git a/qom/object.c b/qom/object.c
index d167038..0fddf00 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -683,6 +683,18 @@  int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
     return ret;
 }
 
+bool object_has_no_children(Object *obj)
+{
+    ObjectProperty *prop;
+
+    QTAILQ_FOREACH(prop, &obj->properties, node) {
+        if (object_property_is_child(prop)) {
+            return false;
+        }
+    }
+    return true;
+}
+
 static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
 {
     GSList **list = opaque;