]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: wire up rmap map and unmap to the realtime rmapbt
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:18 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 16 Jul 2024 22:49:19 +0000 (15:49 -0700)
Connect the map and unmap reverse-mapping operations to the realtime
rmapbt via the deferred operation callbacks.  This enables us to
perform rmap operations against the correct btree.

[Contains a minor bugfix from hch]

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_rmap.c
libxfs/xfs_rtgroup.c
libxfs/xfs_rtgroup.h

index 688341e402fbd56c8bc95d9eb86f089561abd32a..a6c05bcb6e7beed63257fe9c0f9e4135cc4bed45 100644 (file)
@@ -25,6 +25,7 @@
 #include "xfs_health.h"
 #include "defer_item.h"
 #include "xfs_rtgroup.h"
+#include "xfs_rtrmap_btree.h"
 
 struct kmem_cache      *xfs_rmap_intent_cache;
 
@@ -2699,9 +2700,39 @@ xfs_rtrmap_finish_one(
        struct xfs_rmap_intent          *ri,
        struct xfs_btree_cur            **pcur)
 {
-       /* coming in a subsequent patch */
-       ASSERT(0);
-       return -EFSCORRUPTED;
+       struct xfs_owner_info           oinfo;
+       struct xfs_mount                *mp = tp->t_mountp;
+       struct xfs_btree_cur            *rcur = *pcur;
+       xfs_rgnumber_t                  rgno;
+       xfs_rgblock_t                   bno;
+       bool                            unwritten;
+
+       trace_xfs_rmap_deferred(mp, ri);
+
+       if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_RMAP_FINISH_ONE))
+               return -EIO;
+
+       /*
+        * If we haven't gotten a cursor or the cursor rtgroup doesn't match
+        * the startblock, get one now.
+        */
+       if (rcur != NULL && rcur->bc_ino.rtg != ri->ri_rtg) {
+               xfs_btree_del_cursor(rcur, 0);
+               rcur = NULL;
+       }
+       if (rcur == NULL) {
+               xfs_rtgroup_lock(tp, ri->ri_rtg, XFS_RTGLOCK_RMAP);
+               *pcur = rcur = xfs_rtrmapbt_init_cursor(mp, tp, ri->ri_rtg,
+                               ri->ri_rtg->rtg_rmapip);
+       }
+
+       xfs_rmap_ino_owner(&oinfo, ri->ri_owner, ri->ri_whichfork,
+                       ri->ri_bmap.br_startoff);
+       unwritten = ri->ri_bmap.br_state == XFS_EXT_UNWRITTEN;
+       bno = xfs_rtb_to_rgbno(mp, ri->ri_bmap.br_startblock, &rgno);
+
+       return __xfs_rmap_finish_intent(rcur, ri->ri_type, bno,
+                       ri->ri_bmap.br_blockcount, &oinfo, unwritten);
 }
 
 /*
index 2036a20510c1257729421bf0ef1c9d56242c1757..d94ca72b2e8ff5afa0fb043059d42cdc57843287 100644 (file)
@@ -432,6 +432,12 @@ xfs_rtgroup_lock(
                xfs_rtbitmap_lock(tp, rtg->rtg_mount);
        else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
                xfs_rtbitmap_lock_shared(rtg->rtg_mount, XFS_RBMLOCK_BITMAP);
+
+       if ((rtglock_flags & XFS_RTGLOCK_RMAP) && rtg->rtg_rmapip) {
+               xfs_ilock(rtg->rtg_rmapip, XFS_ILOCK_EXCL);
+               if (tp)
+                       xfs_trans_ijoin(tp, rtg->rtg_rmapip, XFS_ILOCK_EXCL);
+       }
 }
 
 /* Unlock metadata inodes associated with this rt group. */
@@ -444,6 +450,9 @@ xfs_rtgroup_unlock(
        ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
               !(rtglock_flags & XFS_RTGLOCK_BITMAP));
 
+       if ((rtglock_flags & XFS_RTGLOCK_RMAP) && rtg->rtg_rmapip)
+               xfs_iunlock(rtg->rtg_rmapip, XFS_ILOCK_EXCL);
+
        if (rtglock_flags & XFS_RTGLOCK_BITMAP)
                xfs_rtbitmap_unlock(rtg->rtg_mount);
        else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
index c8ea22ea70ac078d238ec316d0fe0fe45fd47752..ecafe96af9376b3d592be50facf5dd50270f9668 100644 (file)
@@ -236,9 +236,12 @@ struct xfs_buf *xfs_rtgroup_log_super(struct xfs_trans *tp,
 #define XFS_RTGLOCK_BITMAP             (1U << 0)
 /* Lock the rt bitmap inode in shared mode */
 #define XFS_RTGLOCK_BITMAP_SHARED      (1U << 1)
+/* Lock the rt rmap inode in exclusive mode */
+#define XFS_RTGLOCK_RMAP               (1U << 2)
 
 #define XFS_RTGLOCK_ALL_FLAGS  (XFS_RTGLOCK_BITMAP | \
-                                XFS_RTGLOCK_BITMAP_SHARED)
+                                XFS_RTGLOCK_BITMAP_SHARED | \
+                                XFS_RTGLOCK_RMAP)
 
 void xfs_rtgroup_lock(struct xfs_trans *tp, struct xfs_rtgroup *rtg,
                unsigned int rtglock_flags);