mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-09 13:23:14 +00:00
scoutfs: add scoutfs_lock_protected()
The item code had a manual comparison of lock modes when testing if a given access was protected by a held lock. Let's offer a proper interface from the lock code. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -1288,6 +1288,25 @@ void scoutfs_lock_del_coverage(struct super_block *sb,
|
||||
spin_unlock(&cov->cov_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if the given lock protects the given access of the given
|
||||
* key. The lock must have a current granted mode that is compatible
|
||||
* with the access mode and the access key must be in the lock's key
|
||||
* range.
|
||||
*
|
||||
* This is called by lock holders who's use of the lock must be preventing
|
||||
* the mode and keys from changing.
|
||||
*/
|
||||
bool scoutfs_lock_protected(struct scoutfs_lock *lock, struct scoutfs_key *key,
|
||||
int mode)
|
||||
{
|
||||
signed char lock_mode = ACCESS_ONCE(lock->mode);
|
||||
|
||||
return lock_modes_match(lock_mode, mode) &&
|
||||
scoutfs_key_compare_ranges(key, key,
|
||||
&lock->start, &lock->end) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The shrink callback got the lock, marked it request_pending, and
|
||||
* handed it off to us. We kick off a null request and the lock will
|
||||
|
||||
@@ -83,6 +83,8 @@ bool scoutfs_lock_is_covered(struct super_block *sb,
|
||||
struct scoutfs_lock_coverage *cov);
|
||||
void scoutfs_lock_del_coverage(struct super_block *sb,
|
||||
struct scoutfs_lock_coverage *cov);
|
||||
bool scoutfs_lock_protected(struct scoutfs_lock *lock, struct scoutfs_key *key,
|
||||
int mode);
|
||||
|
||||
void scoutfs_free_unused_locks(struct super_block *sb, unsigned long nr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user