fs: add {lock,unlock}_two_nondirectories for 3.18 backport
Change-Id: Iea7a9d8b87442764bb2fd16306996b494e6ed1b3 Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Theodore Ts'o <tytso@google.com> Git-commit: b226d199c38e353cf59240000704a4cfdd40a954 Git-repo: https://android.googlesource.com/kernel/common.git Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
This commit is contained in:
parent
d2e323cd8b
commit
805074fa98
35
fs/inode.c
35
fs/inode.c
|
@ -979,6 +979,41 @@ void unlock_new_inode(struct inode *inode)
|
|||
}
|
||||
EXPORT_SYMBOL(unlock_new_inode);
|
||||
|
||||
/**
|
||||
* lock_two_nondirectories - take two i_mutexes on non-directory objects
|
||||
*
|
||||
* Lock any non-NULL argument that is not a directory.
|
||||
* Zero, one or two objects may be locked by this function.
|
||||
*
|
||||
* @inode1: first inode to lock
|
||||
* @inode2: second inode to lock
|
||||
*/
|
||||
void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
|
||||
{
|
||||
if (inode1 > inode2)
|
||||
swap(inode1, inode2);
|
||||
|
||||
if (inode1 && !S_ISDIR(inode1->i_mode))
|
||||
mutex_lock(&inode1->i_mutex);
|
||||
if (inode2 && !S_ISDIR(inode2->i_mode) && inode2 != inode1)
|
||||
mutex_lock_nested(&inode2->i_mutex, I_MUTEX_NONDIR2);
|
||||
}
|
||||
EXPORT_SYMBOL(lock_two_nondirectories);
|
||||
|
||||
/**
|
||||
* unlock_two_nondirectories - release locks from lock_two_nondirectories()
|
||||
* @inode1: first inode to unlock
|
||||
* @inode2: second inode to unlock
|
||||
*/
|
||||
void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2)
|
||||
{
|
||||
if (inode1 && !S_ISDIR(inode1->i_mode))
|
||||
mutex_unlock(&inode1->i_mutex);
|
||||
if (inode2 && !S_ISDIR(inode2->i_mode) && inode2 != inode1)
|
||||
mutex_unlock(&inode2->i_mutex);
|
||||
}
|
||||
EXPORT_SYMBOL(unlock_two_nondirectories);
|
||||
|
||||
/**
|
||||
* iget5_locked - obtain an inode from a mounted file system
|
||||
* @sb: super block of file system
|
||||
|
|
|
@ -632,9 +632,14 @@ enum inode_i_mutex_lock_class
|
|||
I_MUTEX_PARENT,
|
||||
I_MUTEX_CHILD,
|
||||
I_MUTEX_XATTR,
|
||||
I_MUTEX_QUOTA
|
||||
I_MUTEX_QUOTA,
|
||||
I_MUTEX_NONDIR2,
|
||||
I_MUTEX_PARENT2,
|
||||
};
|
||||
|
||||
void lock_two_nondirectories(struct inode *, struct inode*);
|
||||
void unlock_two_nondirectories(struct inode *, struct inode*);
|
||||
|
||||
/*
|
||||
* NOTE: in a 32bit arch with a preemptable kernel and
|
||||
* an UP compile the i_size_read/write must be atomic
|
||||
|
|
Loading…
Reference in New Issue