From nobody Wed Nov 5 06:39:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499463149300131.1816725747484; Fri, 7 Jul 2017 14:32:29 -0700 (PDT) Received: from localhost ([::1]:58875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTarT-0000E9-Tv for importer@patchew.org; Fri, 07 Jul 2017 17:32:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTaq5-0007u7-P3 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTaq3-0000d4-R0 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:31:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTaq3-0000ck-Ki for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:30:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89132158A87; Fri, 7 Jul 2017 21:30:58 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-61.gru2.redhat.com [10.97.116.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A51C5F912; Fri, 7 Jul 2017 21:30:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89132158A87 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 89132158A87 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:30:51 -0300 Message-Id: <20170707213052.13087-2-ehabkost@redhat.com> In-Reply-To: <20170707213052.13087-1-ehabkost@redhat.com> References: <20170707213052.13087-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 07 Jul 2017 21:30:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test for partial path lookup using object_resolve_path*(). Signed-off-by: Eduardo Habkost Reported-by: Igor Mammedov Reviewed-by: Igor Mammedov Tested-by: Mark Cave-Ayland --- 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)); } =20 +static void test_qom_partial_path(void) +{ + Object *root =3D object_get_objects_root(); + Object *cont1 =3D container_get(root, "/cont1"); + Object *obj1 =3D object_new(TYPE_DUMMY); + Object *obj2a =3D object_new(TYPE_DUMMY); + Object *obj2b =3D 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 =3D false; + g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous)); + g_assert(ambiguous); + + ambiguous =3D false; + g_assert(!object_resolve_path("obj2", &ambiguous)); + g_assert(ambiguous); + + ambiguous =3D false; + g_assert(object_resolve_path("obj1", &ambiguous) =3D=3D 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); =20 return g_test_run(); } --=20 2.9.4 From nobody Wed Nov 5 06:39:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499463228956820.7539286416531; Fri, 7 Jul 2017 14:33:48 -0700 (PDT) Received: from localhost ([::1]:58878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTasl-00013b-F7 for importer@patchew.org; Fri, 07 Jul 2017 17:33:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTaq6-0007uH-Tw for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:31:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTaq5-0000eC-Q2 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:31:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTaq5-0000di-H2 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 17:31:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82D508123D; Fri, 7 Jul 2017 21:31:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-61.gru2.redhat.com [10.97.116.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id E25D06D282; Fri, 7 Jul 2017 21:30:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 82D508123D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 82D508123D From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 7 Jul 2017 18:30:52 -0300 Message-Id: <20170707213052.13087-3-ehabkost@redhat.com> In-Reply-To: <20170707213052.13087-1-ehabkost@redhat.com> References: <20170707213052.13087-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 21:31:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] qom: Fix ambiguous path detection when ambiguous=NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Mark Cave-Ayland , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" object_resolve_path*() ambiguous path detection breaks when ambiguous=3D=3DNULL 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 Cc: Mark Cave-Ayland Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Tested-by: Mark Cave-Ayland --- 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 =3D true; - } + *ambiguous =3D true; return NULL; } obj =3D found; } =20 - if (ambiguous && *ambiguous) { + if (*ambiguous) { return NULL; } } @@ -1729,7 +1727,7 @@ static Object *object_resolve_partial_path(Object *pa= rent, } =20 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); =20 if (parts[0] =3D=3D NULL || strcmp(parts[0], "") !=3D 0) { - if (ambiguous) { - *ambiguous =3D false; - } + bool ambiguous =3D false; obj =3D object_resolve_partial_path(object_get_root(), parts, - typename, ambiguous); + typename, &ambiguous); + if (ambiguousp) { + *ambiguousp =3D ambiguous; + } } else { obj =3D 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 =3D false; g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous)); g_assert(ambiguous); + g_assert(!object_resolve_path_type("", TYPE_DUMMY, NULL)); =20 ambiguous =3D false; g_assert(!object_resolve_path("obj2", &ambiguous)); g_assert(ambiguous); + g_assert(!object_resolve_path("obj2", NULL)); =20 ambiguous =3D false; g_assert(object_resolve_path("obj1", &ambiguous) =3D=3D obj1); g_assert(!ambiguous); + g_assert(object_resolve_path("obj1", NULL) =3D=3D obj1); =20 object_unparent(obj1); object_unparent(obj2a); --=20 2.9.4