diff options
| author | Theodore Ts'o <tytso@mit.edu> | 2015-01-22 12:06:09 -0500 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-05-27 19:39:48 +0200 |
| commit | 244ce5462adda80c97a9b3f4c055fffca5c71276 (patch) | |
| tree | 13f3c25d823fc36c8499c0c314d601afa5807037 | |
| parent | d4b722fb1671e1309971f251329f4e1af5a598d1 (diff) | |
fs: add {lock,unlock}_two_nondirectories for 3.18 backport
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
| -rw-r--r-- | fs/inode.c | 35 | ||||
| -rw-r--r-- | include/linux/fs.h | 7 |
2 files changed, 41 insertions, 1 deletions
diff --git a/fs/inode.c b/fs/inode.c index 9cd3598d7..63537c654 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -983,6 +983,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 * @hashval: hash value (usually inode number) to get diff --git a/include/linux/fs.h b/include/linux/fs.h index fecb12f16..86007bf1e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -651,9 +651,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 |
