Print this page
5269 zfs: zpool import slow
PORTING: this code relies on the property of taskq_wait to wait
until no more tasks are queued and no more tasks are active. As
we always queue new tasks from within other tasks, task_wait
reliably waits for the full recursion to finish, even though we
enqueue new tasks after taskq_wait has been called.
On platforms other than illumos, taskq_wait may not have this
property.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: George Wilson <george.wilson@delphix.com>

@@ -176,10 +176,30 @@
                         return (mvd);
 
         return (NULL);
 }
 
+static int
+vdev_count_leaves_impl(vdev_t *vd)
+{
+        int n = 0;
+
+        if (vd->vdev_ops->vdev_op_leaf)
+                return (1);
+
+        for (int c = 0; c < vd->vdev_children; c++)
+                n += vdev_count_leaves_impl(vd->vdev_child[c]);
+
+        return (n);
+}
+
+int
+vdev_count_leaves(spa_t *spa)
+{
+        return (vdev_count_leaves_impl(spa->spa_root_vdev));
+}
+
 void
 vdev_add_child(vdev_t *pvd, vdev_t *cvd)
 {
         size_t oldsize, newsize;
         uint64_t id = cvd->vdev_id;