qom: Make object_child_foreach safe for objects removal
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
@@ -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
Quoted 9 lines · Alexey Kardashevskiy
Current
object_child_foreach()usesQTAILQ_FOREACH()to walk through children and that makes children removal from the callback impossible.This makes
object_child_foreach()useQTAILQ_FOREACH_SAFE().Signed-off-by Alexey Kardashevskiy <[email protected]>---
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_SAFEin sPAPR PHB code butobject_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@@ -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
Il 13/07/2014 16:41, Alexey Kardashevskiy ha scritto:
Quoted 30 lines
Current
object_child_foreach()usesQTAILQ_FOREACH()to walk through children and that makes children removal from the callback impossible.This makes
object_child_foreach()useQTAILQ_FOREACH_SAFE().Signed-off-by Alexey Kardashevskiy <[email protected]>---
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_SAFEin sPAPR PHB code butobject_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@@ -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
Quoted 38 lines · Paolo Bonzini
Il 13/07/2014 16:41, Alexey Kardashevskiy ha scritto:
Quoted 37 lines
Current
object_child_foreach()usesQTAILQ_FOREACH()to walk through children and that makes children removal from the callback impossible.This makes
object_child_foreach()useQTAILQ_FOREACH_SAFE().Signed-off-by Alexey Kardashevskiy <[email protected]>---
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_SAFEin sPAPR PHB code butobject_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@@ -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
Andreas Färber
AppliedAm 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()usesQTAILQ_FOREACH()to walk through children and that makes children removal from the callback impossible.This makes
object_child_foreach()useQTAILQ_FOREACH_SAFE().Signed-off-by Alexey Kardashevskiy <[email protected]>---
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_SAFEin sPAPR PHB code butobject_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@@ -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