From patchwork Thu Nov 12 20:29:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 38271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 92DFBB7B9F for ; Fri, 13 Nov 2009 07:32:32 +1100 (EST) Received: from localhost ([127.0.0.1]:37155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8gLF-0003SW-7g for incoming@patchwork.ozlabs.org; Thu, 12 Nov 2009 15:32:29 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8gKT-0003EL-4z for qemu-devel@nongnu.org; Thu, 12 Nov 2009 15:31:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8gKO-0003BQ-Jy for qemu-devel@nongnu.org; Thu, 12 Nov 2009 15:31:40 -0500 Received: from [199.232.76.173] (port=58764 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8gKN-0003BJ-Rk for qemu-devel@nongnu.org; Thu, 12 Nov 2009 15:31:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28903) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N8gKM-0005Aa-PG for qemu-devel@nongnu.org; Thu, 12 Nov 2009 15:31:35 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nACKVX1C024637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 12 Nov 2009 15:31:33 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nACKVWEP029894; Thu, 12 Nov 2009 15:31:33 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id 4E32062BE; Thu, 12 Nov 2009 20:29:03 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 12 Nov 2009 20:29:00 +0000 Message-Id: <1258057742-18699-6-git-send-email-markmc@redhat.com> In-Reply-To: <1258057742-18699-1-git-send-email-markmc@redhat.com> References: <1258057742-18699-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin , kraxel@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org No doubt this is the worst idea ever, but the requirement is simple - some way to iterate all NICs in the system. Signed-off-by: Mark McLoughlin --- hw/qdev.c | 20 ++++++++++++++++++++ hw/qdev.h | 3 +++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index b8ab449..d6e3184 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -401,6 +401,26 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name) return NULL; } +static void qdev_foreach_recursive(BusState *bus, qdev_foreach_func func, void *opaque) +{ + DeviceState *dev; + + QLIST_FOREACH(dev, &bus->children, sibling) { + BusState *child; + + func(dev, opaque); + + QLIST_FOREACH(child, &dev->child_bus, sibling) { + qdev_foreach_recursive(child, func, opaque); + } + } +} + +void qdev_foreach(qdev_foreach_func func, void *opaque) +{ + qdev_foreach_recursive(main_system_bus, func, opaque); +} + static BusState *qbus_find_recursive(BusState *bus, const char *name, const BusInfo *info) { diff --git a/hw/qdev.h b/hw/qdev.h index 26e372c..712ae3b 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -153,6 +153,9 @@ CharDriverState *qdev_init_chardev(DeviceState *dev); BusState *qdev_get_parent_bus(DeviceState *dev); +typedef void (*qdev_foreach_func)(DeviceState *dev, void *opaque); +void qdev_foreach(qdev_foreach_func func, void *opaque); + /* Convert from a base type to a parent type, with compile time checking. */ #ifdef __GNUC__ #define DO_UPCAST(type, field, dev) ( __extension__ ( { \