On Mon, Feb 17, 2020 at 05:35:21AM -0800, Christoph Hellwig wrote: > On Fri, Feb 14, 2020 at 07:59:39PM +0100, Pavel Reichl wrote: > > Refactor xfs_isilocked() to use newly introduced __xfs_rwsem_islocked(). > > __xfs_rwsem_islocked() is a helper function which encapsulates checking > > state of rw_semaphores hold by inode. > > > > Signed-off-by: Pavel Reichl <preichl@xxxxxxxxxx> > > Suggested-by: Dave Chinner <dchinner@xxxxxxxxxx> > > Suggested-by: Eric Sandeen <sandeen@xxxxxxxxxx> > > --- > > fs/xfs/xfs_inode.c | 54 ++++++++++++++++++++++++++++++++-------------- > > fs/xfs/xfs_inode.h | 2 +- > > 2 files changed, 39 insertions(+), 17 deletions(-) > > > > diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c > > index c5077e6326c7..3d28c4790231 100644 > > --- a/fs/xfs/xfs_inode.c > > +++ b/fs/xfs/xfs_inode.c > > @@ -345,32 +345,54 @@ xfs_ilock_demote( > > } > > > > #if defined(DEBUG) || defined(XFS_WARN) > > -int > > +static inline bool > > +__xfs_rwsem_islocked( > > + struct rw_semaphore *rwsem, > > + bool shared, > > + bool excl) > > +{ > > + bool locked = false; > > + > > + if (!rwsem_is_locked(rwsem)) > > + return false; > > + > > + if (!debug_locks) > > + return true; > > + > > + if (shared) > > + locked = lockdep_is_held_type(rwsem, 0); > > + > > + if (excl) > > + locked |= lockdep_is_held_type(rwsem, 1); > > + > > + return locked; > > This could use some comments explaining the logic, especially why we > need the shared and excl flags, which seems very confusing given that > a lock can be held either shared or exclusive, but not neither and not > both. Yes, this predicate should document that callers are allowed to pass in shared==true and excl==true when the caller wants to assert that either lock type (shared or excl) of a given lock class (e.g. iolock) are held. --D