summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_rtalloc.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:15:55 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-09-17 18:55:11 -0700
commitaa640160d2f9c05bfbfce4cb15b479516e804830 (patch)
tree71e31d4c1671dd66ff7decbaa3db2a453e4cac50 /fs/xfs/xfs_rtalloc.c
parentb0a580dd65f1595d915a1612180c622d2461e2cd (diff)
xfs: refactor realtime inode lockingrefactor-rt-locking_2021-09-17
Refactor realtime metadata inode locking so that we can get some sense here. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/xfs_rtalloc.c')
-rw-r--r--fs/xfs/xfs_rtalloc.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 0ef94f67ccbd..0e3e7fa2cfbb 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1055,10 +1055,10 @@ xfs_growfs_rt(
if (error)
break;
/*
- * Lock out other callers by grabbing the bitmap inode lock.
+ * Lock out other callers by grabbing the bitmap and summary
+ * inode locks and joining them to the transaction.
*/
- xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
- xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
+ xfs_rtlock(tp, mp, XFS_RTLOCK_ALLOC);
/*
* Update the bitmap inode's size ondisk and incore. We need
* to update the incore size so that inode inactivation won't
@@ -1069,11 +1069,6 @@ xfs_growfs_rt(
i_size_write(VFS_I(mp->m_rbmip), mp->m_rbmip->i_disk_size);
xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE);
/*
- * Get the summary inode into the transaction.
- */
- xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
- xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
- /*
* Update the summary inode's size. We need to update the
* incore size so that inode inactivation won't punch what it
* thinks are "posteof" blocks.
@@ -1538,3 +1533,41 @@ err:
xfs_trans_cancel(tp);
return ret;
}
+
+/*
+ * Lock the metadata inodes for the realtime volume. If a transaction is
+ * given, the rt metadata inode will be joined to the transaction and the lock
+ * will be released on transaction commit.
+ */
+void
+xfs_rtlock(
+ struct xfs_trans *tp,
+ struct xfs_mount *mp,
+ unsigned int lock_flags)
+{
+ ASSERT(!(lock_flags & ~XFS_RTLOCK_ALL));
+
+ if (lock_flags & XFS_RTLOCK_ALLOC) {
+ 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 the realtime metadata inodes. */
+void
+xfs_rtunlock(
+ struct xfs_mount *mp,
+ unsigned int lock_flags)
+{
+ ASSERT(!(lock_flags & ~XFS_RTLOCK_ALL));
+
+ if (lock_flags & XFS_RTLOCK_ALLOC) {
+ xfs_iunlock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
+ xfs_iunlock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
+ }
+}