Skip to contentSkip to conversation

qom: Make object_child_foreach safe for objects removal

PATCH Applied Alexey Kardashevskiy 4 participants 5 messages Jul 13, 2014 – Jul 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qom: Make object_child_foreach safe for objects removal

Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible.

This makes object_child_foreach() use QTAILQ_FOREACH_SAFE().

---

The problem I am trying to solve is:
there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one.

I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child() is static and we probably do not want to make it public.

---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qom/object.c +2 -2
index 0e8267b..4a814dc 100644
@@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
                          void *opaque)
 {
-    ObjectProperty *prop;
+    ObjectProperty *prop, *next;
     int ret = 0;
 
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
         if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {
Signature · 1 line
2.0.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Alexey Kardashevskiy

Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible.

This makes object_child_foreach() use QTAILQ_FOREACH_SAFE().

---

Quoted 7 lines

The problem I am trying to solve is:
there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one.

I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child() is static and we probably do not want to make it public.

But people tend to accept changes like this one together with the patch(es) that need it.

Regards,
Hu

Quoted 26 lines

---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qom/object.c +2 -2
index 0e8267b..4a814dc 100644
@@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
                          void *opaque)
 {
-    ObjectProperty *prop;
+    ObjectProperty *prop, *next;
     int ret = 0;
 
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
         if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {
Signature · 1 line
2.0.0
#2 lore raw
In reply to Alexey Kardashevskiy

Il 13/07/2014 16:41, Alexey Kardashevskiy ha scritto:

Quoted 30 lines

Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible.

This makes object_child_foreach() use QTAILQ_FOREACH_SAFE().

---

The problem I am trying to solve is:
there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one.

I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child() is static and we probably do not want to make it public.

---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qom/object.c +0 -0
index 0e8267b..4a814dc 100644
@@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
 int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
                          void *opaque)

qom/object.c void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque), · line 687

Quoted 10 lines
qom/object.c +2 -2
 {
-    ObjectProperty *prop;
+    ObjectProperty *prop, *next;
     int ret = 0;
 
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
         if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {

The patch is certainly okay, do you need it in 2.1?

Paolo

#3 lore raw
Quoted 38 lines · Paolo Bonzini

Il 13/07/2014 16:41, Alexey Kardashevskiy ha scritto:

Quoted 37 lines

Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible.

This makes object_child_foreach() use QTAILQ_FOREACH_SAFE().

---

The problem I am trying to solve is:
there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one.

I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child()
is static and we probably do not want to make it public.

---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qom/object.c +1 -1
index 0e8267b..4a814dc 100644
@@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass
 *klass, void *opaque),
 int object_child_foreach(Object *obj, int (*fn)(Object *child, void
 *opaque),
                          void *opaque)
 {
-    ObjectProperty *prop;
+    ObjectProperty *prop, *next;
     int ret = 0;
 
Quoted 8 lines
Quoted 6 lines
qom/object.c +1 -1
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
         if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {

The patch is certainly okay, do you need it in 2.1?

Nope, I will need it for dynamic DMA windows (VFIO, PPC) which are not for 2.1 for sure.

Signature · 1 line
Alexey
#4 lore raw

Am 14.07.2014 15:12, schrieb Alexey Kardashevskiy:

Quoted 49 lines · Paolo Bonzini
Quoted 38 lines

Il 13/07/2014 16:41, Alexey Kardashevskiy ha scritto:

Quoted 37 lines

Current object_child_foreach() uses QTAILQ_FOREACH() to walk through children and that makes children removal from the callback impossible.

This makes object_child_foreach() use QTAILQ_FOREACH_SAFE().

---

The problem I am trying to solve is:
there is a PHB with multiple DMA windows a.k.a. sPAPRTCETable's which are QOM children of PHB. One of RTAS functions is "reset" which is supposed to remove all windows (now just one) except the default one.

I could call QTAILQ_FOREACH_SAFE in sPAPR PHB code but object_property_is_child()
is static and we probably do not want to make it public.

---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qom/object.c +1 -1
index 0e8267b..4a814dc 100644
@@ -678,10 +678,10 @@ void object_class_foreach(void (*fn)(ObjectClass
 *klass, void *opaque),
 int object_child_foreach(Object *obj, int (*fn)(Object *child, void
 *opaque),
                          void *opaque)
 {
-    ObjectProperty *prop;
+    ObjectProperty *prop, *next;
     int ret = 0;
 
Quoted 8 lines
Quoted 6 lines
qom/object.c +1 -1
-    QTAILQ_FOREACH(prop, &obj->properties, node) {
+    QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
         if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {

The patch is certainly okay, do you need it in 2.1?

Quoted 2 lines

Nope, I will need it for dynamic DMA windows (VFIO, PPC) which are not for 2.1 for sure.

Thanks, applied to qom-next so that it doesn't get forgotten.
https://github.com/afaerber/qemu-cpu/commits/qom-next

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg