]> git.proxmox.com Git - mirror_zfs.git/blobdiff - cmd/zfs/zfs_iter.c
Do not iterate through filesystems unnecessarily
[mirror_zfs.git] / cmd / zfs / zfs_iter.c
index 9ad6919388aedc6750ca6b78a86e3d66aa721050..d10bbed7dbd62101fbb07d48dd1bbb2de88b6453 100644 (file)
@@ -134,16 +134,31 @@ zfs_callback(zfs_handle_t *zhp, void *data)
            ((cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
            cb->cb_depth < cb->cb_depth_limit)) {
                cb->cb_depth++;
-               if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM)
+
+               /*
+                * If we are not looking for filesystems, we don't need to
+                * recurse into filesystems when we are at our depth limit.
+                */
+               if ((cb->cb_depth < cb->cb_depth_limit ||
+                   (cb->cb_flags & ZFS_ITER_DEPTH_LIMIT) == 0 ||
+                   (cb->cb_types &
+                   (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) &&
+                   zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) {
                        (void) zfs_iter_filesystems(zhp, zfs_callback, data);
+               }
+
                if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
-                   ZFS_TYPE_BOOKMARK)) == 0) && include_snaps)
+                   ZFS_TYPE_BOOKMARK)) == 0) && include_snaps) {
                        (void) zfs_iter_snapshots(zhp,
-                           (cb->cb_flags & ZFS_ITER_SIMPLE) != 0, zfs_callback,
-                           data, 0, 0);
+                           (cb->cb_flags & ZFS_ITER_SIMPLE) != 0,
+                           zfs_callback, data, 0, 0);
+               }
+
                if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
-                   ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks)
+                   ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks) {
                        (void) zfs_iter_bookmarks(zhp, zfs_callback, data);
+               }
+
                cb->cb_depth--;
        }