diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2017-03-28 17:56:35 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2017-04-03 18:18:17 -0400 |
commit | 2d520bfaa28b60401fbfe581f485a0bb952d881c (patch) | |
tree | a343fc588824a4c60dc5eb1f0f5a9164c3fc92d2 | |
parent | 08438b1e386b7899e8a2ffef59d6ebf29aac530f (diff) |
xfs: provide a query_range function for freespace btrees
Implement a query_range function for the bnobt and cntbt. This will
be used for getfsmap fallback if there is no rmapbt and by the online
scrub and repair code.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
-rw-r--r-- | fs/xfs/libxfs/xfs_alloc.c | 42 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_alloc.h | 10 |
2 files changed, 52 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 369adcc18c02..f65b8d49ec16 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c | |||
@@ -2868,3 +2868,45 @@ err: | |||
2868 | xfs_trans_brelse(tp, agbp); | 2868 | xfs_trans_brelse(tp, agbp); |
2869 | return error; | 2869 | return error; |
2870 | } | 2870 | } |
2871 | |||
2872 | struct xfs_alloc_query_range_info { | ||
2873 | xfs_alloc_query_range_fn fn; | ||
2874 | void *priv; | ||
2875 | }; | ||
2876 | |||
2877 | /* Format btree record and pass to our callback. */ | ||
2878 | STATIC int | ||
2879 | xfs_alloc_query_range_helper( | ||
2880 | struct xfs_btree_cur *cur, | ||
2881 | union xfs_btree_rec *rec, | ||
2882 | void *priv) | ||
2883 | { | ||
2884 | struct xfs_alloc_query_range_info *query = priv; | ||
2885 | struct xfs_alloc_rec_incore irec; | ||
2886 | |||
2887 | irec.ar_startblock = be32_to_cpu(rec->alloc.ar_startblock); | ||
2888 | irec.ar_blockcount = be32_to_cpu(rec->alloc.ar_blockcount); | ||
2889 | return query->fn(cur, &irec, query->priv); | ||
2890 | } | ||
2891 | |||
2892 | /* Find all free space within a given range of blocks. */ | ||
2893 | int | ||
2894 | xfs_alloc_query_range( | ||
2895 | struct xfs_btree_cur *cur, | ||
2896 | struct xfs_alloc_rec_incore *low_rec, | ||
2897 | struct xfs_alloc_rec_incore *high_rec, | ||
2898 | xfs_alloc_query_range_fn fn, | ||
2899 | void *priv) | ||
2900 | { | ||
2901 | union xfs_btree_irec low_brec; | ||
2902 | union xfs_btree_irec high_brec; | ||
2903 | struct xfs_alloc_query_range_info query; | ||
2904 | |||
2905 | ASSERT(cur->bc_btnum == XFS_BTNUM_BNO); | ||
2906 | low_brec.a = *low_rec; | ||
2907 | high_brec.a = *high_rec; | ||
2908 | query.priv = priv; | ||
2909 | query.fn = fn; | ||
2910 | return xfs_btree_query_range(cur, &low_brec, &high_brec, | ||
2911 | xfs_alloc_query_range_helper, &query); | ||
2912 | } | ||
diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 2a8d0fa6fbbe..6c2643c4abd3 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h | |||
@@ -219,4 +219,14 @@ int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno, | |||
219 | 219 | ||
220 | xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp); | 220 | xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp); |
221 | 221 | ||
222 | typedef int (*xfs_alloc_query_range_fn)( | ||
223 | struct xfs_btree_cur *cur, | ||
224 | struct xfs_alloc_rec_incore *rec, | ||
225 | void *priv); | ||
226 | |||
227 | int xfs_alloc_query_range(struct xfs_btree_cur *cur, | ||
228 | struct xfs_alloc_rec_incore *low_rec, | ||
229 | struct xfs_alloc_rec_incore *high_rec, | ||
230 | xfs_alloc_query_range_fn fn, void *priv); | ||
231 | |||
222 | #endif /* __XFS_ALLOC_H__ */ | 232 | #endif /* __XFS_ALLOC_H__ */ |