]> 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>
Fri, 9 Aug 2024 11:59:21 +0000 (13:59 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 11:53:50 +0000 (13:53 +0200)
Source kernel commit: 3fe80153ddb793f21d2d5fd5063acf594573f943

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>
Signed-off-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_rmap.c
libxfs/xfs_rtgroup.c
libxfs/xfs_rtgroup.h

index 688341e402fbd56c8bc95d9eb86f089561abd32a..73adcf9191815f46cce27ad7e33124e2383dbf6f 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_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(ri->ri_rtg, XFS_RTGLOCK_RMAP);
+               xfs_rtgroup_trans_join(tp, ri->ri_rtg, XFS_RTGLOCK_RMAP);
+               *pcur = rcur = xfs_rtrmapbt_init_cursor(mp, tp, ri->ri_rtg,
+                               ri->ri_rtg->rtg_inodes[XFS_RTG_RMAP]);
+       }
+
+       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);
+
+       return __xfs_rmap_finish_intent(rcur, ri->ri_type, bno,
+                       ri->ri_bmap.br_blockcount, &oinfo, unwritten);
 }
 
 /*
index 983b8a4902c90395f8af786aa70b8621a4c51b0e..49429d5b3b733228dda79ec7dd519a2cac51d7de 100644 (file)
@@ -226,6 +226,10 @@ xfs_rtgroup_lock(
        } else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) {
                xfs_ilock(rtg->rtg_inodes[XFS_RTG_BITMAP], XFS_ILOCK_SHARED);
        }
+
+       if ((rtglock_flags & XFS_RTGLOCK_RMAP) &&
+           rtg->rtg_inodes[XFS_RTG_RMAP] != NULL)
+               xfs_ilock(rtg->rtg_inodes[XFS_RTG_RMAP], XFS_ILOCK_EXCL);
 }
 
 /* Unlock metadata inodes associated with this rt group. */
@@ -238,6 +242,9 @@ xfs_rtgroup_unlock(
        ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
               !(rtglock_flags & XFS_RTGLOCK_BITMAP));
 
+       if ((rtglock_flags & XFS_RTGLOCK_RMAP) && rtg->rtg_inodes[XFS_RTG_RMAP])
+               xfs_iunlock(rtg->rtg_inodes[XFS_RTG_RMAP], XFS_ILOCK_EXCL);
+
        if (rtglock_flags & XFS_RTGLOCK_BITMAP) {
                xfs_iunlock(rtg->rtg_inodes[XFS_RTG_SUMMARY], XFS_ILOCK_EXCL);
                xfs_iunlock(rtg->rtg_inodes[XFS_RTG_BITMAP], XFS_ILOCK_EXCL);
@@ -265,6 +272,11 @@ xfs_rtgroup_trans_join(
                xfs_trans_ijoin(tp, rtg->rtg_inodes[XFS_RTG_SUMMARY],
                                XFS_ILOCK_EXCL);
        }
+
+       if ((rtglock_flags & XFS_RTGLOCK_RMAP) &&
+           rtg->rtg_inodes[XFS_RTG_RMAP] != NULL)
+               xfs_trans_ijoin(tp, rtg->rtg_inodes[XFS_RTG_RMAP],
+                               XFS_ILOCK_EXCL);
 }
 
 /* Retrieve rt group geometry. */
index b640399296ddfb7ae0e04e1556b0fd04de5bf740..bb0054a2729657de4ef2b762a1b0082c0465a002 100644 (file)
@@ -292,9 +292,12 @@ xfs_rtxnum_t xfs_rtgroup_extents(struct xfs_mount *mp, xfs_rgnumber_t rgno);
 #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_rtgroup *rtg, unsigned int rtglock_flags);
 void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);