[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 08/23] qdev: Introduce qdev_iterate_recursive
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v4 08/23] qdev: Introduce qdev_iterate_recursive |
Date: |
Wed, 23 Jun 2010 11:40:37 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Jan Kiszka <address@hidden> writes:
> From: Jan Kiszka <address@hidden>
>
> 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 <address@hidden>
> ---
> 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.
[...]
- Re: [Qemu-devel] [PATCH v4 03/23] qdev: Drop ID matching from qtree paths, (continued)
[Qemu-devel] [PATCH v4 06/23] qdev: Push QMP mode checks into qbus_list_bus/dev, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 05/23] qdev: Convert device and bus lists to QTAILQ, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 02/23] qdev: Restrict direct bus addressing via its name, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 08/23] qdev: Introduce qdev_iterate_recursive, Jan Kiszka, 2010/06/15
- Re: [Qemu-devel] [PATCH v4 08/23] qdev: Introduce qdev_iterate_recursive,
Markus Armbruster <=
[Qemu-devel] [PATCH v4 07/23] qdev: Allow device specification by qtree path for device_del, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 09/23] monitor: Fix leakage during completion processing, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 10/23] monitor: Fix command completion vs. boolean switches, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 13/23] monitor: Allow to specify HMP-specifc command arguments, Jan Kiszka, 2010/06/15
[Qemu-devel] [PATCH v4 11/23] monitor: Add completion support for option lists, Jan Kiszka, 2010/06/15