]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: teach rmapbt to support interval queries
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 10 Aug 2016 04:38:58 +0000 (14:38 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 10 Aug 2016 04:38:58 +0000 (14:38 +1000)
Source kernel commit: c543838a1e00a5f8791e59ae570b1030d70906f2

Now that the generic btree code supports querying all records within a
range of keys, use that functionality to allow us to ask for all the
extents mapped to a range of physical blocks.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/xfs_rmap.c
libxfs/xfs_rmap.h

index 008190907cbc275b7cf573a1d0ffa2ee74adb6ad..65df88b53f6317d001de53aab031c0bbe13569b2 100644 (file)
@@ -181,3 +181,46 @@ out_error:
        trace_xfs_rmap_map_error(mp, agno, error, _RET_IP_);
        return error;
 }
+
+struct xfs_rmap_query_range_info {
+       xfs_rmap_query_range_fn fn;
+       void                            *priv;
+};
+
+/* Format btree record and pass to our callback. */
+STATIC int
+xfs_rmap_query_range_helper(
+       struct xfs_btree_cur    *cur,
+       union xfs_btree_rec     *rec,
+       void                    *priv)
+{
+       struct xfs_rmap_query_range_info        *query = priv;
+       struct xfs_rmap_irec                    irec;
+       int                                     error;
+
+       error = xfs_rmap_btrec_to_irec(rec, &irec);
+       if (error)
+               return error;
+       return query->fn(cur, &irec, query->priv);
+}
+
+/* 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)
+{
+       union xfs_btree_irec            low_brec;
+       union xfs_btree_irec            high_brec;
+       struct xfs_rmap_query_range_info        query;
+
+       low_brec.r = *low_rec;
+       high_brec.r = *high_rec;
+       query.priv = priv;
+       query.fn = fn;
+       return xfs_btree_query_range(cur, &low_brec, &high_brec,
+                       xfs_rmap_query_range_helper, &query);
+}
index aa39a2a825e7159c13867f493044588bb294c626..34c811a2dacca573da962669ca7650e71775c3b9 100644 (file)
@@ -151,4 +151,13 @@ int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
 int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
                int *stat);
 
+typedef int (*xfs_rmap_query_range_fn)(
+       struct xfs_btree_cur    *cur,
+       struct xfs_rmap_irec    *rec,
+       void                    *priv);
+
+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);
+
 #endif /* __XFS_RMAP_H__ */