From patchwork Thu May 2 09:38:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 240924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4ADD12C00C7 for ; Thu, 2 May 2013 19:39:29 +1000 (EST) Received: from localhost ([::1]:54717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXpz5-0006W3-Hc for incoming@patchwork.ozlabs.org; Thu, 02 May 2013 05:39:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXpyX-0006SA-0F for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXpyV-0001k0-Nw for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:52 -0400 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]:58735) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXpyV-0001jO-Ei for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:51 -0400 Received: by mail-we0-f179.google.com with SMTP id t9so300627wey.38 for ; Thu, 02 May 2013 02:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=YyTjWI40b4U8hZDLg0hnKD7BeAOQO7kj13FumzuU29Y=; b=QFSsQayx9u3OTjz4XuSh7tcuNuqsPIFzkU6ibSniRmZ2cyg3m7qjIt/EyTm/Jcahle 1XGvIYZ1YDAtpv5gziKbU1EcEO5SAJXRHqJ5Z/DxQpRsPrHZR38lxOrF5Lf20VsMZBgj y8aJCntjzqw+CPl9g1hmbtVAjVHVvfOFpsqFhU8A34+4TVkX2P62slTNQ46/Ysc5NhlM CO+7fJR5XHZ9b1qXIrvx62aI6nbxRsBveAi69Bz4x4YPZvfjJvjI2WUEaiNKX6l0jB3Q VrijQhFoq0ZJ6nod1phHPGKMecUQ1o63+zXyoHVCmZuT3LtQL7zigVHsOe+ULpusm05t Z9EA== X-Received: by 10.180.77.12 with SMTP id o12mr6594706wiw.0.1367487530553; Thu, 02 May 2013 02:38:50 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPSA id g8sm9258483wiy.4.2013.05.02.02.38.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 02 May 2013 02:38:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 2 May 2013 11:38:38 +0200 Message-Id: <1367487519-17332-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1367487519-17332-1-git-send-email-pbonzini@redhat.com> References: <1367487519-17332-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::233 Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH 1.5 2/3] qdev: allow both pre- and post-order vists in qdev walking functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Resetting should be done in post-order, not pre-order. However, qdev_walk_children and qbus_walk_children do not allow this. Fix it by adding two extra arguments to the functions. Tested-by: Claudio Bley Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 45 +++++++++++++++++++++++++++++++++------------ include/hw/qdev-core.h | 13 +++++++++---- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 4eb0134..280b641 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -239,12 +239,12 @@ static int qbus_reset_one(BusState *bus, void *opaque) void qdev_reset_all(DeviceState *dev) { - qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL); + qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL); } void qbus_reset_all(BusState *bus) { - qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL); + qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL); } void qbus_reset_all_fn(void *opaque) @@ -342,49 +342,70 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name) return NULL; } -int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, - qbus_walkerfn *busfn, void *opaque) +int qbus_walk_children(BusState *bus, + qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, + qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, + void *opaque) { BusChild *kid; int err; - if (busfn) { - err = busfn(bus, opaque); + if (pre_busfn) { + err = pre_busfn(bus, opaque); if (err) { return err; } } QTAILQ_FOREACH(kid, &bus->children, sibling) { - err = qdev_walk_children(kid->child, devfn, busfn, opaque); + err = qdev_walk_children(kid->child, + pre_devfn, pre_busfn, + post_devfn, post_busfn, opaque); if (err < 0) { return err; } } + if (post_busfn) { + err = post_busfn(bus, opaque); + if (err) { + return err; + } + } + return 0; } -int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn, - qbus_walkerfn *busfn, void *opaque) +int qdev_walk_children(DeviceState *dev, + qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, + qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, + void *opaque) { BusState *bus; int err; - if (devfn) { - err = devfn(dev, opaque); + if (pre_devfn) { + err = pre_devfn(dev, opaque); if (err) { return err; } } QLIST_FOREACH(bus, &dev->child_bus, sibling) { - err = qbus_walk_children(bus, devfn, busfn, opaque); + err = qbus_walk_children(bus, pre_devfn, pre_busfn, + post_devfn, post_busfn, opaque); if (err < 0) { return err; } } + if (post_devfn) { + err = post_devfn(dev, opaque); + if (err) { + return err; + } + } + return 0; } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index cf83d54..6f13254 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -240,10 +240,15 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, * < 0 if either devfn or busfn terminate walk somewhere in cursion, * 0 otherwise. */ -int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, - qbus_walkerfn *busfn, void *opaque); -int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn, - qbus_walkerfn *busfn, void *opaque); +int qbus_walk_children(BusState *bus, + qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, + qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, + void *opaque); +int qdev_walk_children(DeviceState *dev, + qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, + qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, + void *opaque); + void qdev_reset_all(DeviceState *dev); /**