diff options
author | Darrick J. Wong <djwong@kernel.org> | 2021-01-05 17:45:50 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2021-03-25 17:08:41 -0700 |
commit | 88f51c0a90367b465fd7c390a495ab96ff5349f2 (patch) | |
tree | f7a80b60a92bea409aff688194e660178a4d1247 | |
parent | 0f9fbdd81875b23479769538e767e70662d74738 (diff) |
xfs: refactor realtime inode lockingrefactor-rt-locking_2021-03-25
Refactor realtime metadata inode locking so that we can get some sense
here.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r-- | fs/xfs/libxfs/xfs_bmap.c | 7 | ||||
-rw-r--r-- | fs/xfs/scrub/common.c | 7 | ||||
-rw-r--r-- | fs/xfs/xfs_bmap_util.c | 5 | ||||
-rw-r--r-- | fs/xfs/xfs_fsmap.c | 4 | ||||
-rw-r--r-- | fs/xfs/xfs_rtalloc.c | 49 | ||||
-rw-r--r-- | fs/xfs/xfs_rtalloc.h | 9 |
6 files changed, 58 insertions, 23 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 230c7604dbb8..c013baae6ee3 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5507,12 +5507,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_rtlock(tp, mp, XFS_RTLOCK_ALLOC); } extno = 0; diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c index dc117954823b..41f1d871355e 100644 --- a/fs/xfs/scrub/common.c +++ b/fs/xfs/scrub/common.c @@ -27,6 +27,7 @@ #include "xfs_trans_priv.h" #include "xfs_attr.h" #include "xfs_reflink.h" +#include "xfs_rtalloc.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h" @@ -608,8 +609,7 @@ xchk_rt_init( struct xfs_scrub *sc, struct xchk_rt *sr) { - xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); - xfs_ilock(sc->mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM); + xfs_rtlock(NULL, sc->mp, XFS_RTLOCK_ALL); sr->locked = true; } @@ -625,8 +625,7 @@ xchk_rt_unlock( if (!sr->locked) return; - xfs_iunlock(sc->mp->m_rsumip, XFS_ILOCK_EXCL); - xfs_iunlock(sc->mp->m_rbmip, XFS_ILOCK_EXCL); + xfs_rtunlock(sc->mp, XFS_RTLOCK_ALL); sr->locked = false; } diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 114c1ebee3b9..291f3554ec21 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -118,10 +118,7 @@ xfs_bmap_rtalloc( /* * Lock out modifications to both the RT bitmap and summary inodes */ - xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); - xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL); - xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); - xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL); + xfs_rtlock(ap->tp, mp, XFS_RTLOCK_ALLOC); /* * If it's an allocation to an empty file at offset 0, diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 34f2b971ce43..d598ad5f027f 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -524,7 +524,7 @@ xfs_getfsmap_rtdev_rtbitmap_query( struct xfs_rtalloc_rec ahigh = { 0 }; int error; - xfs_ilock(tp->t_mountp->m_rbmip, XFS_ILOCK_SHARED); + xfs_rtlock(NULL, tp->t_mountp, XFS_RTLOCK_ALL); alow.ar_startext = info->low.rm_startblock; ahigh.ar_startext = info->high.rm_startblock; @@ -542,7 +542,7 @@ xfs_getfsmap_rtdev_rtbitmap_query( if (error) goto err; err: - xfs_iunlock(tp->t_mountp->m_rbmip, XFS_ILOCK_SHARED); + xfs_rtunlock(tp->t_mountp, XFS_RTLOCK_ALL); return error; } diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index fa1ba013425a..52d243188569 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1030,10 +1030,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 @@ -1044,11 +1044,6 @@ xfs_growfs_rt( i_size_write(VFS_I(mp->m_rbmip), mp->m_rbmip->i_d.di_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. @@ -1348,3 +1343,41 @@ xfs_rtpick_extent( *pick = b; return 0; } + +/* + * 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)); + + xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); + if (tp) + xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL); + + if (lock_flags & XFS_RTLOCK_ALLOC) { + 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); +} diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h index ed885620589c..0ae5d6079dc1 100644 --- a/fs/xfs/xfs_rtalloc.h +++ b/fs/xfs/xfs_rtalloc.h @@ -135,6 +135,13 @@ bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno); int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, xfs_extlen_t len, bool *is_free); + +#define XFS_RTLOCK_ALLOC (1 << 0) /* rt allocation */ +#define XFS_RTLOCK_ALL (XFS_RTLOCK_ALLOC) + +void xfs_rtlock(struct xfs_trans *tp, struct xfs_mount *mp, + unsigned int rtlock_flags); +void xfs_rtunlock(struct xfs_mount *mp, unsigned int lock_flags); #else # define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb) (ENOSYS) # define xfs_rtfree_extent(t,b,l) (ENOSYS) @@ -157,6 +164,8 @@ xfs_rtmount_init( } # define xfs_rtmount_inodes(m) (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS)) # define xfs_rtunmount_inodes(m) +# define xfs_rtlock(tp, mp, lock_flags) do { } while (0) +# define xfs_rtunlock(mp, lock_flags) do { } while (0) #endif /* CONFIG_XFS_RT */ #endif /* __XFS_RTALLOC_H__ */ |