qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL
@ 2017-07-07 21:30 Eduardo Habkost
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-07 21:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov,
	Mark Cave-Ayland

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 <imammedo@redhat.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

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(-)

-- 
2.9.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
  2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
@ 2017-07-07 21:30 ` Eduardo Habkost
  2017-07-10  8:10   ` Igor Mammedov
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 2/2] " Eduardo Habkost
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-07 21:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov

Test for partial path lookup using object_resolve_path*().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 8e432e9..abafbd7 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -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();
 }
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 2/2] qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
@ 2017-07-07 21:30 ` Eduardo Habkost
  2017-07-10  8:18   ` Igor Mammedov
  2017-07-10  6:42 ` [Qemu-devel] [PATCH 0/2] " Mark Cave-Ayland
  2017-07-10 18:23 ` Eduardo Habkost
  3 siblings, 1 reply; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-07 21:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov,
	Mark Cave-Ayland

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 <imammedo@redhat.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qom/object.c               | 17 ++++++++---------
 tests/check-qom-proplist.c |  3 +++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 5f6fdfa..0cdddcb 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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);
     }
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index abafbd7..381532c 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -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);
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 2/2] " Eduardo Habkost
@ 2017-07-10  6:42 ` Mark Cave-Ayland
  2017-07-10 18:23 ` Eduardo Habkost
  3 siblings, 0 replies; 12+ messages in thread
From: Mark Cave-Ayland @ 2017-07-10  6:42 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov

On 07/07/17 22:30, Eduardo Habkost 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.
> 
> Fix that by always calling object_resolve_partial_path() with a non-NULL
> ambiguous parameter.
> 
> Test case included.
> 
> Reported-by: Igor Mammedov <imammedo@redhat.com>
> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> 
> 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(-)

I've done a quick test here and I get a pass on "make check" with these
patches applied so:

Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Later on I'll also rework my fw_cfg patchset and send out a v8 which
should hopefully be the last iteration.


ATB,

Mark.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
@ 2017-07-10  8:10   ` Igor Mammedov
  2017-07-10 14:45     ` Eduardo Habkost
  0 siblings, 1 reply; 12+ messages in thread
From: Igor Mammedov @ 2017-07-10  8:10 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Andreas Färber

On Fri,  7 Jul 2017 18:30:51 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Test for partial path lookup using object_resolve_path*().
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index 8e432e9..abafbd7 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -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);

I'd also add test case for
  object_resolve_path(..., NULL)

> +
> +    object_unparent(obj1);
> +    object_unparent(obj2a);
> +    object_unparent(obj2b);
Are above unparenting is necessary?

> +    object_unparent(cont1);
Wouldn't parent destruction sufficient to trigger
implicit destruction of children?

> +}
> +
>  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();
>  }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-07 21:30 ` [Qemu-devel] [PATCH 2/2] " Eduardo Habkost
@ 2017-07-10  8:18   ` Igor Mammedov
  0 siblings, 0 replies; 12+ messages in thread
From: Igor Mammedov @ 2017-07-10  8:18 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, Paolo Bonzini, Mark Cave-Ayland, Andreas Färber

On Fri,  7 Jul 2017 18:30:52 -0300
Eduardo Habkost <ehabkost@redhat.com> 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.
> 
> Fix that by always calling object_resolve_partial_path() with a non-NULL
> ambiguous parameter.
> 
> Test case included.
> 
> Reported-by: Igor Mammedov <imammedo@redhat.com>
> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  qom/object.c               | 17 ++++++++---------
>  tests/check-qom-proplist.c |  3 +++
>  2 files changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 5f6fdfa..0cdddcb 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -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);
>      }
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index abafbd7..381532c 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -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);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
  2017-07-10  8:10   ` Igor Mammedov
@ 2017-07-10 14:45     ` Eduardo Habkost
  2017-07-10 14:48       ` Igor Mammedov
  2017-07-10 15:33       ` [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
  0 siblings, 2 replies; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-10 14:45 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Paolo Bonzini, Andreas Färber

On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> On Fri,  7 Jul 2017 18:30:51 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > Test for partial path lookup using object_resolve_path*().
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> > 
> > diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> > index 8e432e9..abafbd7 100644
> > --- a/tests/check-qom-proplist.c
> > +++ b/tests/check-qom-proplist.c
> > @@ -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);
> 
> I'd also add test case for
>   object_resolve_path(..., NULL)

They are added by patch 2/2, after the bug is fixed.

> 
> > +
> > +    object_unparent(obj1);
> > +    object_unparent(obj2a);
> > +    object_unparent(obj2b);
> Are above unparenting is necessary?
> 
> > +    object_unparent(cont1);
> Wouldn't parent destruction sufficient to trigger
> implicit destruction of children?

Probably it is.  I will test it.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*()
  2017-07-10 14:45     ` Eduardo Habkost
@ 2017-07-10 14:48       ` Igor Mammedov
  2017-07-10 15:33       ` [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
  1 sibling, 0 replies; 12+ messages in thread
From: Igor Mammedov @ 2017-07-10 14:48 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Andreas Färber

On Mon, 10 Jul 2017 11:45:57 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> > On Fri,  7 Jul 2017 18:30:51 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
> >   
> > > Test for partial path lookup using object_resolve_path*().
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 41 insertions(+)
> > > 
> > > diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> > > index 8e432e9..abafbd7 100644
> > > --- a/tests/check-qom-proplist.c
> > > +++ b/tests/check-qom-proplist.c
> > > @@ -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);  
> > 
> > I'd also add test case for
> >   object_resolve_path(..., NULL)  
> 
> They are added by patch 2/2, after the bug is fixed.
> 
> >   
> > > +
> > > +    object_unparent(obj1);
> > > +    object_unparent(obj2a);
> > > +    object_unparent(obj2b);  
> > Are above unparenting is necessary?
> >   
> > > +    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:

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-10 14:45     ` Eduardo Habkost
  2017-07-10 14:48       ` Igor Mammedov
@ 2017-07-10 15:33       ` Eduardo Habkost
  2017-07-10 16:26         ` Igor Mammedov
  1 sibling, 1 reply; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-10 15:33 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: Paolo Bonzini, qemu-devel, Andreas Färber

On Mon, Jul 10, 2017 at 11:45:57AM -0300, Eduardo Habkost wrote:
> On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> > On Fri,  7 Jul 2017 18:30:51 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
[...]
> > > +
> > > +    object_unparent(obj1);
> > > +    object_unparent(obj2a);
> > > +    object_unparent(obj2b);
> > Are above unparenting is necessary?
> > 
> > > +    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.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/check-qom-proplist.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 381532c..432b665 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -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);
 }
-- 
2.9.4

-- 
Eduardo

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-10 15:33       ` [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
@ 2017-07-10 16:26         ` Igor Mammedov
  0 siblings, 0 replies; 12+ messages in thread
From: Igor Mammedov @ 2017-07-10 16:26 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Paolo Bonzini, qemu-devel, Andreas Färber

On Mon, 10 Jul 2017 12:33:31 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Mon, Jul 10, 2017 at 11:45:57AM -0300, Eduardo Habkost wrote:
> > On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:  
> > > On Fri,  7 Jul 2017 18:30:51 -0300
> > > Eduardo Habkost <ehabkost@redhat.com> wrote:  
> [...]
> > > > +
> > > > +    object_unparent(obj1);
> > > > +    object_unparent(obj2a);
> > > > +    object_unparent(obj2b);  
> > > Are above unparenting is necessary?
> > >   
> > > > +    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.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  tests/check-qom-proplist.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index 381532c..432b665 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -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);
>  }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
                   ` (2 preceding siblings ...)
  2017-07-10  6:42 ` [Qemu-devel] [PATCH 0/2] " Mark Cave-Ayland
@ 2017-07-10 18:23 ` Eduardo Habkost
  2017-07-13 12:09   ` Paolo Bonzini
  3 siblings, 1 reply; 12+ messages in thread
From: Eduardo Habkost @ 2017-07-10 18:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Mark Cave-Ayland, Andreas Färber,
	Igor Mammedov

On Fri, Jul 07, 2017 at 06:30:50PM -0300, Eduardo Habkost 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.
> 
> Fix that by always calling object_resolve_partial_path() with a non-NULL
> ambiguous parameter.
> 
> Test case included.
> 
> Reported-by: Igor Mammedov <imammedo@redhat.com>
> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> 
> 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.

>   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(-)
> 
> -- 
> 2.9.4
> 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL
  2017-07-10 18:23 ` Eduardo Habkost
@ 2017-07-13 12:09   ` Paolo Bonzini
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2017-07-13 12:09 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Mark Cave-Ayland, Andreas Färber, Igor Mammedov

On 10/07/2017 20:23, Eduardo Habkost wrote:
> On Fri, Jul 07, 2017 at 06:30:50PM -0300, Eduardo Habkost 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.
>>
>> Fix that by always calling object_resolve_partial_path() with a non-NULL
>> ambiguous parameter.
>>
>> Test case included.
>>
>> Reported-by: Igor Mammedov <imammedo@redhat.com>
>> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>>
>> 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

>>   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(-)
>>
>> -- 
>> 2.9.4
>>
>>
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-07-13 12:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
2017-07-10  8:10   ` Igor Mammedov
2017-07-10 14:45     ` Eduardo Habkost
2017-07-10 14:48       ` Igor Mammedov
2017-07-10 15:33       ` [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
2017-07-10 16:26         ` Igor Mammedov
2017-07-07 21:30 ` [Qemu-devel] [PATCH 2/2] " Eduardo Habkost
2017-07-10  8:18   ` Igor Mammedov
2017-07-10  6:42 ` [Qemu-devel] [PATCH 0/2] " Mark Cave-Ayland
2017-07-10 18:23 ` Eduardo Habkost
2017-07-13 12:09   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).