xfs: improve xfs_isilocked
PATCH 1/1 xfs: improve xfs_isilocked
Use rwsem_is_locked to make the assertations for shared locks work.
fs/xfs/xfs_iget.c +10 -16
@@ -740,30 +738,24 @@ xfs_ilock_demote( }#ifdef DEBUG -/* -* Debug-only routine, without additional rw_semaphore APIs, we can -* now only answer requests regarding whether we hold the lock for write -* (reader state is outside our visibility, we only track writer state). -* -* Note: this means !xfs_isilocked would give false positives, so don't do that. -*/ int xfs_isilocked (xfs_inode_t *ip,uint lock_flags) { -if ((lock_flags & (XFS_ILOCK_EXCL |XFS_ILOCK_SHARED )) == -XFS_ILOCK_EXCL ) { -if (!ip->i_lock.mr_writer) -return 0 ; +if (lock_flags & (XFS_ILOCK_EXCL |XFS_ILOCK_SHARED )) { +if (!(lock_flags &XFS_ILOCK_SHARED )) +return !!ip->i_lock.mr_writer; +return rwsem_is_locked (&ip->i_lock.mr_lock); } -if ((lock_flags & (XFS_IOLOCK_EXCL |XFS_IOLOCK_SHARED )) == -XFS_IOLOCK_EXCL ) { -if (!ip->i_iolock.mr_writer) -return 0 ; +if (lock_flags & (XFS_IOLOCK_EXCL |XFS_IOLOCK_SHARED )) { +if (!(lock_flags &XFS_IOLOCK_SHARED )) +return !!ip->i_iolock.mr_writer; +return rwsem_is_locked (&ip->i_iolock.mr_lock); } -return 1 ; +ASSERT (0 ); +return 0 ; }#endif
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 1 line · Christoph Hellwig
Use
rwsem_is_lockedto make the assertations for shared locks work.
So you're changing it so it answers "yes it's locked" even it it's only a read lock now, right?
Previously it was basically (once each for ilock and iolock): "If the exclusive flag is set, but there is no writer, then it is not locked; otherwise it is."
Now it's "If the exclusive flag is set, but no writer, it's not locked. Otherwise if the shared flag is set it's locked if rwsem_is_locked() says we are. Otherwise (ASSERT(0) and) it is not locked."
That last part is wrong I think. It should be OK to call xfs_isilocked() with neither flag set, in which case the result should be 0. And if the exclusive flag is set, and there *is* a writer, it *is* locked, so it should return 1.
-Alex
Quoted 48 lines
Signed-off-by Christoph Hellwig <[email protected]>Index:
xfs/fs/xfs/xfs_iget.c
===================================================================fs/xfs/xfs_iget.c +10
-16@@ -740,30 +738,24 @@ xfs_ilock_demote( }#ifdef DEBUG -/* -* Debug-only routine, without additional rw_semaphore APIs, we can -* now only answer requests regarding whether we hold the lock for write -* (reader state is outside our visibility, we only track writer state). -* -* Note: this means !xfs_isilocked would give false positives, so don't do that. -*/ int xfs_isilocked (xfs_inode_t *ip,uint lock_flags) { -if ((lock_flags & (XFS_ILOCK_EXCL |XFS_ILOCK_SHARED )) == -XFS_ILOCK_EXCL ) { -if (!ip->i_lock.mr_writer) -return 0 ; +if (lock_flags & (XFS_ILOCK_EXCL |XFS_ILOCK_SHARED )) { +if (!(lock_flags &XFS_ILOCK_SHARED )) +return !!ip->i_lock.mr_writer; +return rwsem_is_locked (&ip->i_lock.mr_lock); } -if ((lock_flags & (XFS_IOLOCK_EXCL |XFS_IOLOCK_SHARED )) == -XFS_IOLOCK_EXCL ) { -if (!ip->i_iolock.mr_writer) -return 0 ; +if (lock_flags & (XFS_IOLOCK_EXCL |XFS_IOLOCK_SHARED )) { +if (!(lock_flags &XFS_IOLOCK_SHARED )) +return !!ip->i_iolock.mr_writer; +return rwsem_is_locked (&ip->i_iolock.mr_lock); } -return 1 ; +ASSERT (0 ); +return 0 ; }#endif
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 5 lines · Alex Elder
Quoted 1 line · Christoph Hellwig
Use
rwsem_is_lockedto make the assertations for shared locks work.So you're changing it so it answers "yes it's locked" even it it's only a read lock now, right?
If XFS_ILOCK_SHARED/XFS_IOLOCK_SHARED are in the flags we'll answer yes it's locked for a read lock now, indeed.
Quoted 3 lines
Previously it was basically (once each for ilock and iolock): "If the exclusive flag is set, but there is no writer, then it is not locked; otherwise it is."
Yes.
Quoted 4 lines
Now it's "If the exclusive flag is set, but no writer, it's not locked. Otherwise if the shared flag is set it's locked if
rwsem_is_locked()says we are. Otherwise (ASSERT(0) and) it is not locked."
Not exactly. Now it's:
- if excl is set but shared isn't return true if mr_writer is set, else false
- if shared is set either alone or together with excl return if it is locked in any way (rwsem_is_locked).
Note that xfs_isilocked can be called like:
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
which means that either excl or shared is fine.
- if either one or both of excl and shared are set and it's
Quoted 3 lines
That last part is wrong I think. It should be OK to call
xfs_isilocked()with neither flag set, in which case the result should be 0.
We can argue about removing the assert, but we currently don't and should't call xfs_isilocked wit ha 0 argument - it's rather pointless to do so.
Quoted 3 lines
And if the exclusive
flag is set, and there *is* a writer, it *is* locked, so it should return 1.
We do that right now.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Alex Elder
Reviewed-byQuoted 6 lines · Christoph Hellwig
Quoted 5 lines · Alex Elder
Quoted 1 line · Christoph Hellwig
Use
rwsem_is_lockedto make the assertations for shared locks work.So you're changing it so it answers "yes it's locked" even it it's only a read lock now, right?
. . .
Quoted 11 lines
Quoted 4 lines
Now it's "If the exclusive flag is set, but no writer, it's not locked. Otherwise if the shared flag is set it's locked if
rwsem_is_locked()says we are. Otherwise (ASSERT(0) and) it is not locked."Not exactly. Now it's:
- if excl is set but shared isn't return true if
mr_writeris set, else false
- if shared is set either alone or together with excl return if it is locked in any way (rwsem_is_locked).
OK, that makes sense, I get it now.
Quoted 8 lines
Note that
xfs_isilockedcan be called like:ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));which means that either excl or shared is fine.
- if either one or both of excl and shared are set and it's
Quoted 7 lines
Quoted 3 lines
That last part is wrong I think. It should be OK to call
xfs_isilocked()with neither flag set, in which case the result should be 0.We can argue about removing the assert, but we currently don't and should't call
xfs_isilockedwit ha 0 argument - it's rather pointless to do so.
Yes, you're right. I'd still say the function should return the right answer even if given an unreasonable request. But that's being pedantic.
Quoted 6 lines
Quoted 4 lines
And if the exclusive
flag is set, and there *is* a writer, it *is* locked, so it should return 1.We do that right now.
Yup. Thanks for setting me straight.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs