xfs: count the blocks in a btree
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 19 Sep 2016 00:25:20 +0000 (10:25 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 19 Sep 2016 00:25:20 +0000 (10:25 +1000)
Provide a helper method to count the number of blocks in a short form
btree.  The refcount and rmap btrees need to know the number of blocks
already in use to set up their per-AG block reservations during mount.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree.h

index 50cfb98719dd57f595d752d24844d998d9dce32c..aa1752f918b8d564e3eba5671262dc7c42e92604 100644 (file)
@@ -4821,3 +4821,26 @@ xfs_btree_calc_size(
        }
        return rval;
 }
+
+int
+xfs_btree_count_blocks_helper(
+       struct xfs_btree_cur    *cur,
+       int                     level,
+       void                    *data)
+{
+       xfs_extlen_t            *blocks = data;
+       (*blocks)++;
+
+       return 0;
+}
+
+/* Count the blocks in a btree and return the result in *blocks. */
+int
+xfs_btree_count_blocks(
+       struct xfs_btree_cur    *cur,
+       xfs_extlen_t            *blocks)
+{
+       *blocks = 0;
+       return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper,
+                       blocks);
+}
index 1c148f5c5675a2932169c170c7c9e2a0c631939b..3f8556a5c2ad789c04c884505472c47cd7d69f0e 100644 (file)
@@ -519,4 +519,6 @@ typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
 int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
                xfs_btree_visit_blocks_fn fn, void *data);
 
+int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
+
 #endif /* __XFS_BTREE_H__ */