splice: add helpers for locking pipe inode
There are lots of sequences like this, especially in splice code: if (pipe->inode) mutex_lock(&pipe->inode->i_mutex); /* do something */ if (pipe->inode) mutex_unlock(&pipe->inode->i_mutex); so introduce helpers which do the conditional locking and unlocking. Also replace the inode_double_lock() call with a pipe_double_lock() helper to avoid spreading the use of this functionality beyond the pipe code. This patch is just a cleanup, and should cause no behavioral changes. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
This commit is contained in:
committed by
Jens Axboe
parent
f8cc774ce4
commit
61e0d47c33
36
fs/inode.c
36
fs/inode.c
@@ -1470,42 +1470,6 @@ static void __wait_on_freeing_inode(struct inode *inode)
|
||||
spin_lock(&inode_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* We rarely want to lock two inodes that do not have a parent/child
|
||||
* relationship (such as directory, child inode) simultaneously. The
|
||||
* vast majority of file systems should be able to get along fine
|
||||
* without this. Do not use these functions except as a last resort.
|
||||
*/
|
||||
void inode_double_lock(struct inode *inode1, struct inode *inode2)
|
||||
{
|
||||
if (inode1 == NULL || inode2 == NULL || inode1 == inode2) {
|
||||
if (inode1)
|
||||
mutex_lock(&inode1->i_mutex);
|
||||
else if (inode2)
|
||||
mutex_lock(&inode2->i_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (inode1 < inode2) {
|
||||
mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT);
|
||||
mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD);
|
||||
} else {
|
||||
mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT);
|
||||
mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(inode_double_lock);
|
||||
|
||||
void inode_double_unlock(struct inode *inode1, struct inode *inode2)
|
||||
{
|
||||
if (inode1)
|
||||
mutex_unlock(&inode1->i_mutex);
|
||||
|
||||
if (inode2 && inode2 != inode1)
|
||||
mutex_unlock(&inode2->i_mutex);
|
||||
}
|
||||
EXPORT_SYMBOL(inode_double_unlock);
|
||||
|
||||
static __initdata unsigned long ihash_entries;
|
||||
static int __init set_ihash_entries(char *str)
|
||||
{
|
||||
|
Reference in New Issue
Block a user