xfs: create a standard btree size calculator code
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 19 Sep 2016 00:25:03 +0000 (10:25 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 19 Sep 2016 00:25:03 +0000 (10:25 +1000)
Create a helper to generate AG btree height calculator functions.
This will be used (much) later when we get to the refcount btree.

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 7be8d9cda2b696d1c833eabc493e1b21b41b520b..50cfb98719dd57f595d752d24844d998d9dce32c 100644 (file)
@@ -4797,3 +4797,27 @@ xfs_btree_query_range(
        return xfs_btree_overlapped_query_range(cur, &low_key, &high_key,
                        fn, priv);
 }
+
+/*
+ * Calculate the number of blocks needed to store a given number of records
+ * in a short-format (per-AG metadata) btree.
+ */
+xfs_extlen_t
+xfs_btree_calc_size(
+       struct xfs_mount        *mp,
+       uint                    *limits,
+       unsigned long long      len)
+{
+       int                     level;
+       int                     maxrecs;
+       xfs_extlen_t            rval;
+
+       maxrecs = limits[0];
+       for (level = 0, rval = 0; len > 1; level++) {
+               len += maxrecs - 1;
+               do_div(len, maxrecs);
+               maxrecs = limits[1];
+               rval += len;
+       }
+       return rval;
+}
index f41a4cfff740e7c0645050c06a38205b78e01331..1c148f5c5675a2932169c170c7c9e2a0c631939b 100644 (file)
@@ -501,6 +501,8 @@ bool xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp);
 bool xfs_btree_sblock_verify(struct xfs_buf *bp, unsigned int max_recs);
 uint xfs_btree_compute_maxlevels(struct xfs_mount *mp, uint *limits,
                                 unsigned long len);
+xfs_extlen_t xfs_btree_calc_size(struct xfs_mount *mp, uint *limits,
+               unsigned long long len);
 
 /* return codes */
 #define XFS_BTREE_QUERY_RANGE_CONTINUE 0       /* keep iterating */