qom: Fix ambiguous path detection when ambiguous=NULL
cover qom: Fix ambiguous path detection when ambiguous=NULL
object_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)
With the above tree, object_resolve_path_type("", TYPE_FOO, NULL) will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.
Fix that by always calling object_resolve_partial_path() with a non-NULL ambiguous parameter.
Test case included.
Eduardo Habkost (2):
tests: Test case for object_resolve_path*()
qom: Fix ambiguous path detection when ambiguous=NULL
qom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/2 tests: Test case for object_resolve_path*()
Test for partial path lookup using object_resolve_path*().
--- tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
tests/check-qom-proplist.c +41 -0
@@ -568,6 +568,46 @@ static void test_dummy_delchild(void)object_unparent (OBJECT (dev)); } +static void test_qom_partial_path (void ) +{ +Object *root =object_get_objects_root (); +Object *cont1 =container_get (root,"/cont1" ); +Object *obj1 =object_new (TYPE_DUMMY ); +Object *obj2a =object_new (TYPE_DUMMY ); +Object *obj2b =object_new (TYPE_DUMMY ); +bool ambiguous; + +/* Objects created: +* /cont1 +* /cont1/obj1 +* /cont1/obj2 (obj2a) +* /obj2 (obj2b) +*/ +object_property_add_child (cont1,"obj1" , obj1, &error_abort); +object_unref (obj1); +object_property_add_child (cont1,"obj2" , obj2a, &error_abort); +object_unref (obj2a); +object_property_add_child (root,"obj2" , obj2b, &error_abort); +object_unref (obj2b); + + ambiguous = false; +g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (!object_resolve_path ("obj2" , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1); +g_assert (!ambiguous); + +object_unparent (obj1); +object_unparent (obj2a); +object_unparent (obj2b); +object_unparent (cont1); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -585,6 +625,7 @@ int main(int argc, char **argv)g_test_add_func ("/qom/proplist/getenum" , test_dummy_getenum);g_test_add_func ("/qom/proplist/iterator" , test_dummy_iterator);g_test_add_func ("/qom/proplist/delchild" , test_dummy_delchild); +g_test_add_func ("/qom/resolve/partial" , test_qom_partial_path);return g_test_run (); }
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
Quoted 38 lines · On Fri, 7 Jul 2017 18:30:51 -0300 Eduardo Habkost <[email protected]> wrote:
Test for partial path lookup using object_resolve_path*().
Signed-off-by Eduardo Habkost <[email protected]>--- tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)tests/check-qom-proplist.c +23
-0@@ -568,6 +568,46 @@ static void test_dummy_delchild(void)object_unparent (OBJECT (dev)); } +static void test_qom_partial_path (void ) +{ +Object *root =object_get_objects_root (); +Object *cont1 =container_get (root,"/cont1" ); +Object *obj1 =object_new (TYPE_DUMMY ); +Object *obj2a =object_new (TYPE_DUMMY ); +Object *obj2b =object_new (TYPE_DUMMY ); +bool ambiguous; + +/* Objects created: +* /cont1 +* /cont1/obj1 +* /cont1/obj2 (obj2a) +* /obj2 (obj2b) +*/ +object_property_add_child (cont1,"obj1" , obj1, &error_abort); +object_unref (obj1); +object_property_add_child (cont1,"obj2" , obj2a, &error_abort); +object_unref (obj2a); +object_property_add_child (root,"obj2" , obj2b, &error_abort); +object_unref (obj2b); + + ambiguous = false;
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 603
Quoted 10 lines
tests/check-qom-proplist.c +10
-0+g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (!object_resolve_path ("obj2" , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1); +g_assert (!ambiguous);
I'd also add test case for
object_resolve_path(..., NULL)
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 607
Quoted 4 lines
tests/check-qom-proplist.c +4
-0+ +object_unparent (obj1); +object_unparent (obj2a); +object_unparent (obj2b);
Are above unparenting is necessary?
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 608
Quoted 1 line
tests/check-qom-proplist.c +1
-0+object_unparent (cont1);
Wouldn't parent destruction sufficient to trigger
implicit destruction of children?
Quoted 13 lines
tests/check-qom-proplist.c +3
-0+} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );@@ -585,6 +625,7 @@ int main(int argc, char **argv)g_test_add_func ("/qom/proplist/getenum" , test_dummy_getenum);g_test_add_func ("/qom/proplist/iterator" , test_dummy_iterator);g_test_add_func ("/qom/proplist/delchild" , test_dummy_delchild); +g_test_add_func ("/qom/resolve/partial" , test_qom_partial_path);return g_test_run (); }
Re: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
Quoted 46 lines · Igor Mammedov
Quoted 43 lines · On Fri, 7 Jul 2017 18:30:51 -0300 Eduardo Habkost <[email protected]> wrote:
Test for partial path lookup using object_resolve_path*().
Signed-off-by Eduardo Habkost <[email protected]>--- tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)tests/check-qom-proplist.c +28
-0@@ -568,6 +568,46 @@ static void test_dummy_delchild(void)object_unparent (OBJECT (dev)); } +static void test_qom_partial_path (void ) +{ +Object *root =object_get_objects_root (); +Object *cont1 =container_get (root,"/cont1" ); +Object *obj1 =object_new (TYPE_DUMMY ); +Object *obj2a =object_new (TYPE_DUMMY ); +Object *obj2b =object_new (TYPE_DUMMY ); +bool ambiguous; + +/* Objects created: +* /cont1 +* /cont1/obj1 +* /cont1/obj2 (obj2a) +* /obj2 (obj2b) +*/ +object_property_add_child (cont1,"obj1" , obj1, &error_abort); +object_unref (obj1); +object_property_add_child (cont1,"obj2" , obj2a, &error_abort); +object_unref (obj2a); +object_property_add_child (root,"obj2" , obj2b, &error_abort); +object_unref (obj2b); + + ambiguous = false; +g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (!object_resolve_path ("obj2" , &ambiguous));
Quoted 8 lines
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 603
Quoted 5 lines
tests/check-qom-proplist.c +5
-0+g_assert (ambiguous); + + ambiguous = false; +g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1); +g_assert (!ambiguous);I'd also add test case for
object_resolve_path(..., NULL)
They are added by patch 2/2, after the bug is fixed.
Quoted 10 lines
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 607
Quoted 5 lines
tests/check-qom-proplist.c +4
-0+ +object_unparent (obj1); +object_unparent (obj2a); +object_unparent (obj2b);Are above unparenting is necessary?
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 608
Quoted 1 line
tests/check-qom-proplist.c +1
-0+object_unparent (cont1);Wouldn't parent destruction sufficient to trigger
implicit destruction of children?
Probably it is. I will test it.
Signature · 1 line
Eduardo
Igor Mammedov
Reviewed-byRe: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
Quoted 63 lines · On Mon, 10 Jul 2017 11:45:57 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 46 lines · Igor Mammedov
Quoted 43 lines · On Fri, 7 Jul 2017 18:30:51 -0300 Eduardo Habkost <[email protected]> wrote:
Test for partial path lookup using object_resolve_path*().
Signed-off-by Eduardo Habkost <[email protected]>--- tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)tests/check-qom-proplist.c +28
-0@@ -568,6 +568,46 @@ static void test_dummy_delchild(void)object_unparent (OBJECT (dev)); } +static void test_qom_partial_path (void ) +{ +Object *root =object_get_objects_root (); +Object *cont1 =container_get (root,"/cont1" ); +Object *obj1 =object_new (TYPE_DUMMY ); +Object *obj2a =object_new (TYPE_DUMMY ); +Object *obj2b =object_new (TYPE_DUMMY ); +bool ambiguous; + +/* Objects created: +* /cont1 +* /cont1/obj1 +* /cont1/obj2 (obj2a) +* /obj2 (obj2b) +*/ +object_property_add_child (cont1,"obj1" , obj1, &error_abort); +object_unref (obj1); +object_property_add_child (cont1,"obj2" , obj2a, &error_abort); +object_unref (obj2a); +object_property_add_child (root,"obj2" , obj2b, &error_abort); +object_unref (obj2b); + + ambiguous = false; +g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous)); +g_assert (ambiguous); + + ambiguous = false; +g_assert (!object_resolve_path ("obj2" , &ambiguous));Quoted 8 lines
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 603
Quoted 5 lines
tests/check-qom-proplist.c +5
-0+g_assert (ambiguous); + + ambiguous = false; +g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1); +g_assert (!ambiguous);I'd also add test case for
object_resolve_path(..., NULL)They are added by patch 2/2, after the bug is fixed.
Quoted 5 lines
Quoted 5 lines
tests/check-qom-proplist.c +4
-0+ +object_unparent (obj1); +object_unparent (obj2a); +object_unparent (obj2b);
Quoted 7 lines
Quoted 5 lines
Are above unparenting is necessary?
tests/check-qom-proplist.c static void test_dummy_delchild(void) · line 608
Quoted 1 line
tests/check-qom-proplist.c +1
-0+object_unparent (cont1);Wouldn't parent destruction sufficient to trigger
implicit destruction of children?Probably it is. I will test it.
It would be better to avoid not necessary calls if it works, but either way:
PATCH 1/1 fixup! qom: Fix ambiguous path detection when ambiguous=NULL
In reply to Eduardo HabkostQuoted 3 lines · Eduardo Habkost
Quoted 2 lines · Igor Mammedov
On Fri, 7 Jul 2017 18:30:51 -0300
Eduardo Habkost <[email protected]> wrote:
[...]
Quoted 11 lines
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + object_unparent(obj1); + object_unparent(obj2a); + object_unparent(obj2b);Are above unparenting is necessary?
Quoted 1 line
+
object_unparent(cont1);Wouldn't parent destruction sufficient to trigger
implicit destruction of children?Probably it is. I will test it.
The obj1 and obj2a object_unparent() calls are really unnecessary. object_unparent(obj2b) is still necessary because it is attached direcly to root.
--- tests/check-qom-proplist.c | 2 -- 1 file changed, 2 deletions(-)
tests/check-qom-proplist.c +0 -2
@@ -605,8 +605,6 @@ static void test_qom_partial_path(void)g_assert (!ambiguous);g_assert (object_resolve_path ("obj1" ,NULL ) == obj1); -object_unparent (obj1); -object_unparent (obj2a);object_unparent (obj2b);object_unparent (cont1); }
Signature · 4 lines
2.9.4 -- Eduardo
Re: [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL
Quoted 15 lines · On Mon, 10 Jul 2017 12:33:31 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 3 lines · Eduardo Habkost
Quoted 2 lines · Igor Mammedov
On Fri, 7 Jul 2017 18:30:51 -0300
Eduardo Habkost <[email protected]> wrote:[...]
Quoted 10 lines
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + object_unparent(obj1); + object_unparent(obj2a); + object_unparent(obj2b);Are above unparenting is necessary?
Quoted 1 line
+
object_unparent(cont1);Wouldn't parent destruction sufficient to trigger
implicit destruction of children?
Quoted 7 lines
Quoted 1 line
Probably it is. I will test it.
The obj1 and obj2a
object_unparent()calls are really unnecessary.object_unparent(obj2b)is still necessary because it is attached direcly to root.Signed-off-by Eduardo Habkost <[email protected]>
Quoted 17 lines
--- tests/check-qom-proplist.c | 2 -- 1 file changed, 2 deletions(-)tests/check-qom-proplist.c +0
-2@@ -605,8 +605,6 @@ static void test_qom_partial_path(void)g_assert (!ambiguous);g_assert (object_resolve_path ("obj1" ,NULL ) == obj1); -object_unparent (obj1); -object_unparent (obj2a);object_unparent (obj2b);object_unparent (cont1); }
PATCH 2/2 qom: Fix ambiguous path detection when ambiguous=NULL
In reply to Eduardo Habkostobject_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)
With the above tree, object_resolve_path_type("", TYPE_FOO, NULL) will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.
Fix that by always calling object_resolve_partial_path() with a non-NULL ambiguous parameter.
Test case included.
--- qom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-)
qom/object.c +8 -9
@@ -1712,15 +1712,13 @@ static Object *object_resolve_partial_path(Object *parent, typename, ambiguous);if (found) {if (obj) { -if (ambiguous) { - *ambiguous = true; - } + *ambiguous = true;return NULL ; } obj = found; } -if (ambiguous && *ambiguous) { +if (*ambiguous) {return NULL ; } }
@@ -1729,7 +1727,7 @@ static Object *object_resolve_partial_path(Object *parent, }Object *object_resolve_path_type (const char *path,const char *typename, -bool *ambiguous) +bool *ambiguousp) {Object *obj;gchar **parts;
@@ -1738,11 +1736,12 @@ Object *object_resolve_path_type(const char *path, const char *typename,assert (parts);if (parts[0 ] ==NULL ||strcmp (parts[0 ],"" ) !=0 ) { -if (ambiguous) { - *ambiguous = false; - } +bool ambiguous = false; obj =object_resolve_partial_path (object_get_root (), parts, - typename, ambiguous); + typename, &ambiguous); +if (ambiguousp) { + *ambiguousp = ambiguous; + } }else { obj =object_resolve_abs_path (object_get_root (), parts, typename,1 ); }
tests/check-qom-proplist.c +3 -0
@@ -593,14 +593,17 @@ static void test_qom_partial_path(void) ambiguous = false;g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous));g_assert (ambiguous); +g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY ,NULL )); ambiguous = false;g_assert (!object_resolve_path ("obj2" , &ambiguous));g_assert (ambiguous); +g_assert (!object_resolve_path ("obj2" ,NULL )); ambiguous = false;g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1);g_assert (!ambiguous); +g_assert (object_resolve_path ("obj1" ,NULL ) == obj1);object_unparent (obj1);object_unparent (obj2a);
Signature · 1 line
2.9.4
Quoted 12 lines · On Fri, 7 Jul 2017 18:30:52 -0300 Eduardo Habkost <[email protected]> wrote:
object_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (
TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)With the above tree,
object_resolve_path_type("", TYPE_FOO, NULL)will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.
Quoted 8 lines
Fix that by always calling
object_resolve_partial_path()with a non-NULL ambiguous parameter.Test case included.
Reported-by Igor Mammedov <[email protected]>Cc Mark Cave-Ayland <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>
Quoted 75 lines
--- qom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-)qom/object.c +8
-9@@ -1712,15 +1712,13 @@ static Object *object_resolve_partial_path(Object *parent, typename, ambiguous);if (found) {if (obj) { -if (ambiguous) { - *ambiguous = true; - } + *ambiguous = true;return NULL ; } obj = found; } -if (ambiguous && *ambiguous) { +if (*ambiguous) {return NULL ; } }@@ -1729,7 +1727,7 @@ static Object *object_resolve_partial_path(Object *parent, }Object *object_resolve_path_type (const char *path,const char *typename, -bool *ambiguous) +bool *ambiguousp) {Object *obj;gchar **parts;@@ -1738,11 +1736,12 @@ Object *object_resolve_path_type(const char *path, const char *typename,assert (parts);if (parts[0 ] ==NULL ||strcmp (parts[0 ],"" ) !=0 ) { -if (ambiguous) { - *ambiguous = false; - } +bool ambiguous = false; obj =object_resolve_partial_path (object_get_root (), parts, - typename, ambiguous); + typename, &ambiguous); +if (ambiguousp) { + *ambiguousp = ambiguous; + } }else { obj =object_resolve_abs_path (object_get_root (), parts, typename,1 ); }tests/check-qom-proplist.c +3
-0@@ -593,14 +593,17 @@ static void test_qom_partial_path(void) ambiguous = false;g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY , &ambiguous));g_assert (ambiguous); +g_assert (!object_resolve_path_type ("" ,TYPE_DUMMY ,NULL )); ambiguous = false;g_assert (!object_resolve_path ("obj2" , &ambiguous));g_assert (ambiguous); +g_assert (!object_resolve_path ("obj2" ,NULL )); ambiguous = false;g_assert (object_resolve_path ("obj1" , &ambiguous) == obj1);g_assert (!ambiguous); +g_assert (object_resolve_path ("obj1" ,NULL ) == obj1);object_unparent (obj1);object_unparent (obj2a);
Quoted 20 lines · Eduardo Habkost
object_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (
TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)With the above tree,
object_resolve_path_type("", TYPE_FOO, NULL)will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.Fix that by always calling
object_resolve_partial_path()with a non-NULL ambiguous parameter.Test case included.
Reported-by Igor Mammedov <[email protected]>Cc Mark Cave-Ayland <[email protected]>
Quoted 7 lines
Eduardo Habkost (2):
tests: Test case for object_resolve_path*()
qom: Fix ambiguous path detection when ambiguous=NULLqom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-)
I've done a quick test here and I get a pass on "make check" with these patches applied so:
Later on I'll also rework my fw_cfg patchset and send out a v8 which should hopefully be the last iteration.
ATB,
Mark.
Quoted 15 lines · Eduardo Habkost
object_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (
TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)With the above tree,
object_resolve_path_type("", TYPE_FOO, NULL)will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.Fix that by always calling
object_resolve_partial_path()with a non-NULL ambiguous parameter.
Quoted 7 lines
Test case included.
Reported-by Igor Mammedov <[email protected]>Cc Mark Cave-Ayland <[email protected]>Eduardo Habkost (2):
tests: Test case for object_resolve_path*()
I'm queueing patch 1/2 on my machine-next tree. I will wait a little longer for additional feedback on patch 2/2 before merging it.
Quoted 10 lines
qom: Fix ambiguous path detection when ambiguous=NULL
qom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-)Signature · 1 line
2.9.4
Signature · 1 line
Eduardo
Quoted 21 lines · Eduardo Habkost
Quoted 20 lines · Eduardo Habkost
object_resolve_path*() ambiguous path detection breaks when ambiguous==NULL and the object tree have 3 objects of the same type and only 2 of them are under the same parent. e.g.:
/container/obj1 (
TYPE_FOO)
/container/obj2 (TYPE_FOO)
/obj2 (TYPE_FOO)With the above tree,
object_resolve_path_type("", TYPE_FOO, NULL)will incorrectly return /obj2, because the search inside "/container" will return NULL, and the match at "/obj2" won't be detected as ambiguous.Fix that by always calling
object_resolve_partial_path()with a non-NULL ambiguous parameter.Test case included.
Reported-by Igor Mammedov <[email protected]>Cc Mark Cave-Ayland <[email protected]>
Quoted 6 lines
Quoted 2 lines
Eduardo Habkost (2):
tests: Test case for object_resolve_path*()I'm queueing patch 1/2 on my machine-next tree. I will wait a little longer for additional feedback on patch 2/2 before merging it.
Please apply both (with or without fixup, it's fine either way).
Paolo
Quoted 11 lines
Quoted 10 lines
qom: Fix ambiguous path detection when ambiguous=NULL
qom/object.c | 17 ++++++++--------- tests/check-qom-proplist.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-)Signature · 1 line
2.9.4