render / rpms / qemu

Forked from rpms/qemu 5 months ago
Clone

Blame 0005-qdev-allow-both-pre-and-post-order-vists-in-qdev-wal.patch

9e0a86
From 7dbd6881f10537bf586f1eedf5a3bda2e50174ca Mon Sep 17 00:00:00 2001
9e0a86
From: Paolo Bonzini <pbonzini@redhat.com>
9e0a86
Date: Thu, 2 May 2013 11:38:38 +0200
9e0a86
Subject: [PATCH] qdev: allow both pre- and post-order vists in qdev walking
9e0a86
 functions
9e0a86
9e0a86
Resetting should be done in post-order, not pre-order.  However,
9e0a86
qdev_walk_children and qbus_walk_children do not allow this.  Fix
9e0a86
it by adding two extra arguments to the functions.
9e0a86
9e0a86
Tested-by: Claudio Bley <cbley@av-test.de>
9e0a86
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9e0a86
---
9e0a86
 hw/core/qdev.c         | 45 +++++++++++++++++++++++++++++++++------------
9e0a86
 include/hw/qdev-core.h | 13 +++++++++----
9e0a86
 2 files changed, 42 insertions(+), 16 deletions(-)
9e0a86
9e0a86
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
9e0a86
index 9190a7e..842804f 100644
9e0a86
--- a/hw/core/qdev.c
9e0a86
+++ b/hw/core/qdev.c
9e0a86
@@ -240,12 +240,12 @@ static int qbus_reset_one(BusState *bus, void *opaque)
9e0a86
 
9e0a86
 void qdev_reset_all(DeviceState *dev)
9e0a86
 {
9e0a86
-    qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL);
9e0a86
+    qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL);
9e0a86
 }
9e0a86
 
9e0a86
 void qbus_reset_all(BusState *bus)
9e0a86
 {
9e0a86
-    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
9e0a86
+    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL);
9e0a86
 }
9e0a86
 
9e0a86
 void qbus_reset_all_fn(void *opaque)
9e0a86
@@ -343,49 +343,70 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
9e0a86
     return NULL;
9e0a86
 }
9e0a86
 
9e0a86
-int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
9e0a86
-                       qbus_walkerfn *busfn, void *opaque)
9e0a86
+int qbus_walk_children(BusState *bus,
9e0a86
+                       qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
9e0a86
+                       qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
9e0a86
+                       void *opaque)
9e0a86
 {
9e0a86
     BusChild *kid;
9e0a86
     int err;
9e0a86
 
9e0a86
-    if (busfn) {
9e0a86
-        err = busfn(bus, opaque);
9e0a86
+    if (pre_busfn) {
9e0a86
+        err = pre_busfn(bus, opaque);
9e0a86
         if (err) {
9e0a86
             return err;
9e0a86
         }
9e0a86
     }
9e0a86
 
9e0a86
     QTAILQ_FOREACH(kid, &bus->children, sibling) {
9e0a86
-        err = qdev_walk_children(kid->child, devfn, busfn, opaque);
9e0a86
+        err = qdev_walk_children(kid->child,
9e0a86
+                                 pre_devfn, pre_busfn,
9e0a86
+                                 post_devfn, post_busfn, opaque);
9e0a86
         if (err < 0) {
9e0a86
             return err;
9e0a86
         }
9e0a86
     }
9e0a86
 
9e0a86
+    if (post_busfn) {
9e0a86
+        err = post_busfn(bus, opaque);
9e0a86
+        if (err) {
9e0a86
+            return err;
9e0a86
+        }
9e0a86
+    }
9e0a86
+
9e0a86
     return 0;
9e0a86
 }
9e0a86
 
9e0a86
-int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
9e0a86
-                       qbus_walkerfn *busfn, void *opaque)
9e0a86
+int qdev_walk_children(DeviceState *dev,
9e0a86
+                       qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
9e0a86
+                       qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
9e0a86
+                       void *opaque)
9e0a86
 {
9e0a86
     BusState *bus;
9e0a86
     int err;
9e0a86
 
9e0a86
-    if (devfn) {
9e0a86
-        err = devfn(dev, opaque);
9e0a86
+    if (pre_devfn) {
9e0a86
+        err = pre_devfn(dev, opaque);
9e0a86
         if (err) {
9e0a86
             return err;
9e0a86
         }
9e0a86
     }
9e0a86
 
9e0a86
     QLIST_FOREACH(bus, &dev->child_bus, sibling) {
9e0a86
-        err = qbus_walk_children(bus, devfn, busfn, opaque);
9e0a86
+        err = qbus_walk_children(bus, pre_devfn, pre_busfn,
9e0a86
+                                 post_devfn, post_busfn, opaque);
9e0a86
         if (err < 0) {
9e0a86
             return err;
9e0a86
         }
9e0a86
     }
9e0a86
 
9e0a86
+    if (post_devfn) {
9e0a86
+        err = post_devfn(dev, opaque);
9e0a86
+        if (err) {
9e0a86
+            return err;
9e0a86
+        }
9e0a86
+    }
9e0a86
+
9e0a86
     return 0;
9e0a86
 }
9e0a86
 
9e0a86
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
9e0a86
index 46972f4..c6c9b14 100644
9e0a86
--- a/include/hw/qdev-core.h
9e0a86
+++ b/include/hw/qdev-core.h
9e0a86
@@ -270,10 +270,15 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
9e0a86
 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
9e0a86
  *         < 0 if either devfn or busfn terminate walk somewhere in cursion,
9e0a86
  *           0 otherwise. */
9e0a86
-int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
9e0a86
-                       qbus_walkerfn *busfn, void *opaque);
9e0a86
-int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
9e0a86
-                       qbus_walkerfn *busfn, void *opaque);
9e0a86
+int qbus_walk_children(BusState *bus,
9e0a86
+                       qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
9e0a86
+                       qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
9e0a86
+                       void *opaque);
9e0a86
+int qdev_walk_children(DeviceState *dev,
9e0a86
+                       qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
9e0a86
+                       qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
9e0a86
+                       void *opaque);
9e0a86
+
9e0a86
 void qdev_reset_all(DeviceState *dev);
9e0a86
 
9e0a86
 /**