From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57515 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ORMU3-00070J-H0 for qemu-devel@nongnu.org; Wed, 23 Jun 2010 05:43:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ORMRm-0000yh-JL for qemu-devel@nongnu.org; Wed, 23 Jun 2010 05:40:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5635) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ORMRm-0000yZ-Cc for qemu-devel@nongnu.org; Wed, 23 Jun 2010 05:40:42 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH v4 08/23] qdev: Introduce qdev_iterate_recursive References: <8f4efb5aab7b6cd6bca60816059dd38e77c6a1ff.1276641524.git.jan.kiszka@web.de> Date: Wed, 23 Jun 2010 11:40:37 +0200 In-Reply-To: <8f4efb5aab7b6cd6bca60816059dd38e77c6a1ff.1276641524.git.jan.kiszka@web.de> (Jan Kiszka's message of "Wed, 16 Jun 2010 00:38:32 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Anthony Liguori , Juan Quintela , Jan Kiszka , qemu-devel@nongnu.org, Luiz Capitulino , Blue Swirl , Avi Kivity Jan Kiszka writes: > From: Jan Kiszka > > Add qdev_iterate_recursive to walk the complete qtree invoking a > callback for each device. Use this service to implement > qdev_find_id_recursive. > > Signed-off-by: Jan Kiszka > --- > hw/qdev.c | 29 +++++++++++++++++++++++++---- > hw/qdev.h | 3 +++ > 2 files changed, 28 insertions(+), 4 deletions(-) > > diff --git a/hw/qdev.c b/hw/qdev.c > index 2d1d171..466d8d5 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -475,16 +475,22 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name, > return NULL; > } > > -static DeviceState *qdev_find_id_recursive(BusState *bus, const char *id) > +void *qdev_iterate_recursive(BusState *bus, qdev_iteratefn callback, > + void *opaque) > { > DeviceState *dev, *ret; > BusState *child; > > + if (!bus) { > + bus = main_system_bus; > + } > QTAILQ_FOREACH(dev, &bus->children, sibling) { > - if (dev->id && strcmp(dev->id, id) == 0) > - return dev; > + ret = callback(dev, opaque); > + if (ret) { > + return ret; > + } > QTAILQ_FOREACH(child, &dev->child_bus, sibling) { > - ret = qdev_find_id_recursive(child, id); > + ret = qdev_iterate_recursive(child, callback, opaque); > if (ret) { > return ret; > } I'd call "iterate recursive" simply "walk". It's common usage for trees. Except this isn't a walk or iteration, it's a search: the walk stops as soon as the callback returns non-null. Not obvious from the name, therefore needs a comment. [...]