xfs: create a function to query all records in a btree
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 28 Mar 2017 21:56:35 +0000 (14:56 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 3 Apr 2017 22:18:17 +0000 (15:18 -0700)
Create a helper function that will query all records in a btree.
This will be used by the online repair functions to examine every
record in a btree to rebuild a second btree.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_alloc.h
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree.h
fs/xfs/libxfs/xfs_rmap.c
fs/xfs/libxfs/xfs_rmap.h

index f65b8d49ec16120ea6e69da504f61a5da3f1708e..7486401ccbd36e0b076c020f15f433e9592322cc 100644 (file)
@@ -2910,3 +2910,18 @@ xfs_alloc_query_range(
        return xfs_btree_query_range(cur, &low_brec, &high_brec,
                        xfs_alloc_query_range_helper, &query);
 }
+
+/* Find all free space records. */
+int
+xfs_alloc_query_all(
+       struct xfs_btree_cur                    *cur,
+       xfs_alloc_query_range_fn                fn,
+       void                                    *priv)
+{
+       struct xfs_alloc_query_range_info       query;
+
+       ASSERT(cur->bc_btnum == XFS_BTNUM_BNO);
+       query.priv = priv;
+       query.fn = fn;
+       return xfs_btree_query_all(cur, xfs_alloc_query_range_helper, &query);
+}
index 6c2643c4abd3f2f51ea114db23aef89802db5c4c..77d9c27330abc2fbe7dbf192a8d25e8c2352fa17 100644 (file)
@@ -228,5 +228,7 @@ int xfs_alloc_query_range(struct xfs_btree_cur *cur,
                struct xfs_alloc_rec_incore *low_rec,
                struct xfs_alloc_rec_incore *high_rec,
                xfs_alloc_query_range_fn fn, void *priv);
+int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
+               void *priv);
 
 #endif /* __XFS_ALLOC_H__ */
index c3decedc94557e14c3cb7fa7eee81d09e54f4c9e..92aa20d565532b321e70b36fb9031af8f4614624 100644 (file)
@@ -4842,6 +4842,21 @@ xfs_btree_query_range(
                        fn, priv);
 }
 
+/* Query a btree for all records. */
+int
+xfs_btree_query_all(
+       struct xfs_btree_cur            *cur,
+       xfs_btree_query_range_fn        fn,
+       void                            *priv)
+{
+       union xfs_btree_irec            low_rec;
+       union xfs_btree_irec            high_rec;
+
+       memset(&low_rec, 0, sizeof(low_rec));
+       memset(&high_rec, 0xFF, sizeof(high_rec));
+       return xfs_btree_query_range(cur, &low_rec, &high_rec, fn, priv);
+}
+
 /*
  * Calculate the number of blocks needed to store a given number of records
  * in a short-format (per-AG metadata) btree.
index 4bb62580a7fd0029702b7d5092638af34b78c70b..27bed08261c530fac9508f9138f00b0f13a8cdd9 100644 (file)
@@ -496,6 +496,8 @@ typedef int (*xfs_btree_query_range_fn)(struct xfs_btree_cur *cur,
 int xfs_btree_query_range(struct xfs_btree_cur *cur,
                union xfs_btree_irec *low_rec, union xfs_btree_irec *high_rec,
                xfs_btree_query_range_fn fn, void *priv);
+int xfs_btree_query_all(struct xfs_btree_cur *cur, xfs_btree_query_range_fn fn,
+               void *priv);
 
 typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
                void *data);
index 3a8cc7139912bf83d0830090c3c88a91e79b6677..384055668374d093de49c6327db7dfdb4463d388 100644 (file)
@@ -2001,14 +2001,14 @@ xfs_rmap_query_range_helper(
 /* Find all rmaps between two keys. */
 int
 xfs_rmap_query_range(
-       struct xfs_btree_cur            *cur,
-       struct xfs_rmap_irec            *low_rec,
-       struct xfs_rmap_irec            *high_rec,
-       xfs_rmap_query_range_fn fn,
-       void                            *priv)
+       struct xfs_btree_cur                    *cur,
+       struct xfs_rmap_irec                    *low_rec,
+       struct xfs_rmap_irec                    *high_rec,
+       xfs_rmap_query_range_fn                 fn,
+       void                                    *priv)
 {
-       union xfs_btree_irec            low_brec;
-       union xfs_btree_irec            high_brec;
+       union xfs_btree_irec                    low_brec;
+       union xfs_btree_irec                    high_brec;
        struct xfs_rmap_query_range_info        query;
 
        low_brec.r = *low_rec;
@@ -2019,6 +2019,20 @@ xfs_rmap_query_range(
                        xfs_rmap_query_range_helper, &query);
 }
 
+/* Find all rmaps. */
+int
+xfs_rmap_query_all(
+       struct xfs_btree_cur                    *cur,
+       xfs_rmap_query_range_fn                 fn,
+       void                                    *priv)
+{
+       struct xfs_rmap_query_range_info        query;
+
+       query.priv = priv;
+       query.fn = fn;
+       return xfs_btree_query_all(cur, xfs_rmap_query_range_helper, &query);
+}
+
 /* Clean up after calling xfs_rmap_finish_one. */
 void
 xfs_rmap_finish_one_cleanup(
index 789930599339058ed8db437a6ff5be061095877c..faf2c1a2e63be348f7b7ae468b85141acabd1b1d 100644 (file)
@@ -162,6 +162,8 @@ typedef int (*xfs_rmap_query_range_fn)(
 int xfs_rmap_query_range(struct xfs_btree_cur *cur,
                struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
                xfs_rmap_query_range_fn fn, void *priv);
+int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
+               void *priv);
 
 enum xfs_rmap_intent_type {
        XFS_RMAP_MAP,