[PATCH v2 1/2] xfs: factor out a xfs_getfsmap_del_cursors helper
From: zhangshida2026
Date: Wed Nov 25 2026 - 20:30:54 EST
From: Shida Zhang <zhangshida@xxxxxxxxxx>
The data and rt device getfsmap walkers open-code the same rmap btree
cursor deletion at group boundaries and at the end of the walk. Fold
it into a helper in preparation for caching a refcount cursor across
the walk.
No functional change.
Suggested-by: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Signed-off-by: Shida Zhang <zhangshida@xxxxxxxxxx>
---
fs/xfs/xfs_fsmap.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c
index 041bb2105ec..fe9093c0987 100644
--- a/fs/xfs/xfs_fsmap.c
+++ b/fs/xfs/xfs_fsmap.c
@@ -202,6 +202,17 @@ xfs_getfsmap_dev_compare(
return d1->dev - d2->dev;
}
+/* Delete the btree cursors used by a getfsmap group walk. */
+static void
+xfs_getfsmap_del_cursors(
+ struct xfs_btree_cur *bt_cur,
+ int error)
+{
+ if (bt_cur)
+ xfs_btree_del_cursor(bt_cur, error < 0 ?
+ XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
+}
+
/* Decide if this mapping is shared. */
STATIC int
xfs_getfsmap_is_shared(
@@ -545,7 +556,7 @@ __xfs_getfsmap_datadev(
}
if (bt_cur) {
- xfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
+ xfs_getfsmap_del_cursors(bt_cur, 0);
bt_cur = NULL;
xfs_trans_brelse(tp, info->agf_bp);
info->agf_bp = NULL;
@@ -585,9 +596,7 @@ __xfs_getfsmap_datadev(
info->group = NULL;
}
- if (bt_cur)
- xfs_btree_del_cursor(bt_cur, error < 0 ? XFS_BTREE_ERROR :
- XFS_BTREE_NOERROR);
+ xfs_getfsmap_del_cursors(bt_cur, error);
if (info->agf_bp) {
xfs_trans_brelse(tp, info->agf_bp);
info->agf_bp = NULL;
@@ -989,7 +998,7 @@ xfs_getfsmap_rtdev_rmapbt(
xfs_rtgroup_unlock(to_rtg(bt_cur->bc_group),
XFS_RTGLOCK_RMAP |
XFS_RTGLOCK_REFCOUNT);
- xfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
+ xfs_getfsmap_del_cursors(bt_cur, 0);
bt_cur = NULL;
}
@@ -1027,8 +1036,7 @@ xfs_getfsmap_rtdev_rmapbt(
if (bt_cur) {
xfs_rtgroup_unlock(to_rtg(bt_cur->bc_group),
XFS_RTGLOCK_RMAP | XFS_RTGLOCK_REFCOUNT);
- xfs_btree_del_cursor(bt_cur, error < 0 ? XFS_BTREE_ERROR :
- XFS_BTREE_NOERROR);
+ xfs_getfsmap_del_cursors(bt_cur, error);
}
/* loop termination case */
--
2.34.1