]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor realtime inode locking
authorChristoph Hellwig <hch@lst.de>
Mon, 29 Jul 2024 23:22:41 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:01 +0000 (17:01 -0700)
Source kernel commit: b7e23c0e2e3b1c520a3370f058870b914071a470

Create helper functions to deal with locking realtime metadata inodes.
This enables us to maintain correct locking order once we start adding
the realtime rmap and refcount btree inodes.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
libxfs/libxfs_priv.h
libxfs/xfs_bmap.c
libxfs/xfs_rtbitmap.c
libxfs/xfs_rtbitmap.h

index aa0a3adb4614adebf5830dbcbe040c4e4c022626..fa7cad0e06e703ba871a913a9d18cc2fdacabf8b 100644 (file)
@@ -170,6 +170,9 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 
 #define XFS_ERRLEVEL_LOW               1
 #define XFS_ILOCK_EXCL                 0
+#define XFS_ILOCK_SHARED               0
+#define XFS_ILOCK_RTBITMAP             0
+#define XFS_ILOCK_RTSUM                        0
 #define XFS_STATS_INC(mp, count)       do { (mp) = (mp); } while (0)
 #define XFS_STATS_DEC(mp, count, x)    do { (mp) = (mp); } while (0)
 #define XFS_STATS_ADD(mp, count, x)    do { (mp) = (mp); } while (0)
index 63feb20e24b32629bf6ff1656ed128d39cb12c91..f339e16a1d2cdb158a128137a2db8402c832cc77 100644 (file)
@@ -5412,12 +5412,9 @@ __xfs_bunmapi(
 
        if (isrt) {
                /*
-                * Synchronize by locking the bitmap inode.
+                * Synchronize by locking the realtime bitmap.
                 */
-               xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP);
-               xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
-               xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM);
-               xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
+               xfs_rtbitmap_lock(tp, mp);
        }
 
        extno = 0;
index 543cfd2fb9c54d3772397656555d81a355af57a6..58a3ba992f51cc8151648c2b897194df0d24309e 100644 (file)
@@ -1166,3 +1166,60 @@ xfs_rtsummary_wordcount(
        blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
        return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
 }
+
+/*
+ * Lock both realtime free space metadata inodes for a freespace update.  If a
+ * transaction is given, the inodes will be joined to the transaction and the
+ * ILOCKs will be released on transaction commit.
+ */
+void
+xfs_rtbitmap_lock(
+       struct xfs_trans        *tp,
+       struct xfs_mount        *mp)
+{
+       xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
+       if (tp)
+               xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
+
+       xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
+       if (tp)
+               xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
+}
+
+/* Unlock both realtime free space metadata inodes after a freespace update. */
+void
+xfs_rtbitmap_unlock(
+       struct xfs_mount        *mp)
+{
+       xfs_iunlock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
+       xfs_iunlock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
+}
+
+/*
+ * Lock the realtime free space metadata inodes for a freespace scan.  Callers
+ * must walk metadata blocks in order of increasing file offset.
+ */
+void
+xfs_rtbitmap_lock_shared(
+       struct xfs_mount        *mp,
+       unsigned int            rbmlock_flags)
+{
+       if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
+               xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
+
+       if (rbmlock_flags & XFS_RBMLOCK_SUMMARY)
+               xfs_ilock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM);
+}
+
+/* Unlock the realtime free space metadata inodes after a freespace scan. */
+void
+xfs_rtbitmap_unlock_shared(
+       struct xfs_mount        *mp,
+       unsigned int            rbmlock_flags)
+{
+       if (rbmlock_flags & XFS_RBMLOCK_SUMMARY)
+               xfs_iunlock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM);
+
+       if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
+               xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
+}
index 152a66750af554d91a0641ae9a3ed1011ffb7386..6186585f2c376d97ba1d20b1a0666147d34c55b7 100644 (file)
@@ -360,6 +360,19 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
                unsigned int rsumlevels, xfs_extlen_t rbmblocks);
 unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
                unsigned int rsumlevels, xfs_extlen_t rbmblocks);
+
+void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp);
+void xfs_rtbitmap_unlock(struct xfs_mount *mp);
+
+/* Lock the rt bitmap inode in shared mode */
+#define XFS_RBMLOCK_BITMAP     (1U << 0)
+/* Lock the rt summary inode in shared mode */
+#define XFS_RBMLOCK_SUMMARY    (1U << 1)
+
+void xfs_rtbitmap_lock_shared(struct xfs_mount *mp,
+               unsigned int rbmlock_flags);
+void xfs_rtbitmap_unlock_shared(struct xfs_mount *mp,
+               unsigned int rbmlock_flags);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)                      (-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)                    (-ENOSYS)
@@ -378,6 +391,10 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
 # define xfs_rtbitmap_wordcount(mp, r)                 (0)
 # define xfs_rtsummary_blockcount(mp, l, b)            (0)
 # define xfs_rtsummary_wordcount(mp, l, b)             (0)
+# define xfs_rtbitmap_lock(tp, mp)             do { } while (0)
+# define xfs_rtbitmap_unlock(mp)               do { } while (0)
+# define xfs_rtbitmap_lock_shared(mp, lf)      do { } while (0)
+# define xfs_rtbitmap_unlock_shared(mp, lf)    do { } while (0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __XFS_RTBITMAP_H__ */