btrfs: introduce btrfs_inode_lock()/unlock()
btrfs_inode_lock/unlock() are wrappers around inode locks, separating the type of lock and actual locking. - 0 - default, exclusive lock - BTRFS_ILOCK_SHARED - for shared locks, for possible parallel DIO - BTRFS_ILOCK_TRY - for the RWF_NOWAIT sequence The bits SHARED and TRY can be combined together. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
committed by
David Sterba
parent
b8d8e1fd57
commit
a14b78ad06
@@ -95,6 +95,51 @@ static void __endio_write_update_ordered(struct btrfs_inode *inode,
|
||||
const u64 offset, const u64 bytes,
|
||||
const bool uptodate);
|
||||
|
||||
/*
|
||||
* btrfs_inode_lock - lock inode i_rwsem based on arguments passed
|
||||
*
|
||||
* ilock_flags can have the following bit set:
|
||||
*
|
||||
* BTRFS_ILOCK_SHARED - acquire a shared lock on the inode
|
||||
* BTRFS_ILOCK_TRY - try to acquire the lock, if fails on first attempt
|
||||
* return -EAGAIN
|
||||
*/
|
||||
int btrfs_inode_lock(struct inode *inode, unsigned int ilock_flags)
|
||||
{
|
||||
if (ilock_flags & BTRFS_ILOCK_SHARED) {
|
||||
if (ilock_flags & BTRFS_ILOCK_TRY) {
|
||||
if (!inode_trylock_shared(inode))
|
||||
return -EAGAIN;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
inode_lock_shared(inode);
|
||||
} else {
|
||||
if (ilock_flags & BTRFS_ILOCK_TRY) {
|
||||
if (!inode_trylock(inode))
|
||||
return -EAGAIN;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
inode_lock(inode);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* btrfs_inode_unlock - unock inode i_rwsem
|
||||
*
|
||||
* ilock_flags should contain the same bits set as passed to btrfs_inode_lock()
|
||||
* to decide whether the lock acquired is shared or exclusive.
|
||||
*/
|
||||
void btrfs_inode_unlock(struct inode *inode, unsigned int ilock_flags)
|
||||
{
|
||||
if (ilock_flags & BTRFS_ILOCK_SHARED)
|
||||
inode_unlock_shared(inode);
|
||||
else
|
||||
inode_unlock(inode);
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleanup all submitted ordered extents in specified range to handle errors
|
||||
* from the btrfs_run_delalloc_range() callback.
|
||||
|
||||
Reference in New Issue
Block a user