forked from Minki/linux
xfs: factor out the common lock flags assert
There are similar lock flags assert in xfs_ilock(), xfs_ilock_nowait(), xfs_iunlock(), thus we can factor it out into a helper that is clear. Signed-off-by: Kaixu Xia <kaixuxia@tencent.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
This commit is contained in:
parent
5e672cd69f
commit
ca76a761ea
@ -131,6 +131,26 @@ xfs_ilock_attr_map_shared(
|
||||
return lock_mode;
|
||||
}
|
||||
|
||||
/*
|
||||
* You can't set both SHARED and EXCL for the same lock,
|
||||
* and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_MMAPLOCK_SHARED,
|
||||
* XFS_MMAPLOCK_EXCL, XFS_ILOCK_SHARED, XFS_ILOCK_EXCL are valid values
|
||||
* to set in lock_flags.
|
||||
*/
|
||||
static inline void
|
||||
xfs_lock_flags_assert(
|
||||
uint lock_flags)
|
||||
{
|
||||
ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
|
||||
(XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
|
||||
(XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
|
||||
(XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
|
||||
ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
|
||||
ASSERT(lock_flags != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* In addition to i_rwsem in the VFS inode, the xfs inode contains 2
|
||||
* multi-reader locks: invalidate_lock and the i_lock. This routine allows
|
||||
@ -168,18 +188,7 @@ xfs_ilock(
|
||||
{
|
||||
trace_xfs_ilock(ip, lock_flags, _RET_IP_);
|
||||
|
||||
/*
|
||||
* You can't set both SHARED and EXCL for the same lock,
|
||||
* and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
|
||||
* and XFS_ILOCK_EXCL are valid values to set in lock_flags.
|
||||
*/
|
||||
ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
|
||||
(XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
|
||||
(XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
|
||||
(XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
|
||||
ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
|
||||
xfs_lock_flags_assert(lock_flags);
|
||||
|
||||
if (lock_flags & XFS_IOLOCK_EXCL) {
|
||||
down_write_nested(&VFS_I(ip)->i_rwsem,
|
||||
@ -222,18 +231,7 @@ xfs_ilock_nowait(
|
||||
{
|
||||
trace_xfs_ilock_nowait(ip, lock_flags, _RET_IP_);
|
||||
|
||||
/*
|
||||
* You can't set both SHARED and EXCL for the same lock,
|
||||
* and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
|
||||
* and XFS_ILOCK_EXCL are valid values to set in lock_flags.
|
||||
*/
|
||||
ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
|
||||
(XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
|
||||
(XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
|
||||
(XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
|
||||
ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
|
||||
xfs_lock_flags_assert(lock_flags);
|
||||
|
||||
if (lock_flags & XFS_IOLOCK_EXCL) {
|
||||
if (!down_write_trylock(&VFS_I(ip)->i_rwsem))
|
||||
@ -291,19 +289,7 @@ xfs_iunlock(
|
||||
xfs_inode_t *ip,
|
||||
uint lock_flags)
|
||||
{
|
||||
/*
|
||||
* You can't set both SHARED and EXCL for the same lock,
|
||||
* and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
|
||||
* and XFS_ILOCK_EXCL are valid values to set in lock_flags.
|
||||
*/
|
||||
ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
|
||||
(XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
|
||||
(XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
|
||||
ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
|
||||
(XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
|
||||
ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_SUBCLASS_MASK)) == 0);
|
||||
ASSERT(lock_flags != 0);
|
||||
xfs_lock_flags_assert(lock_flags);
|
||||
|
||||
if (lock_flags & XFS_IOLOCK_EXCL)
|
||||
up_write(&VFS_I(ip)->i_rwsem);
|
||||
|
Loading…
Reference in New Issue
Block a user