Re: [PATCH v5 1/4] xfs: Refactor xfs_isilocked()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 19, 2020 at 5:48 AM Darrick J. Wong <darrick.wong@xxxxxxxxxx> wrote:
>
> 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
>

Hello,

thanks for the comments.

Would code comment preceding the definition of __xfs_rwsem_islocked()
work for you?

Something like:

/* This is a helper function that encapsulates checking the state of
 * rw semaphores.
 *
 * if shared == true AND excl == true then function returns true if either
 * lock type (shared or excl) of a given semaphore are held.
 */




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux