diff options
author | Mark Fasheh <mark.fasheh@oracle.com> | 2006-10-17 04:31:38 -0400 |
---|---|---|
committer | Jens Axboe <axboe@nelson.home.kernel.dk> | 2006-10-19 14:53:08 -0400 |
commit | 62752ee198dca9209b7dee504763e51b11e9e0ca (patch) | |
tree | 5e340a4c690851dadc3a8aa395e4c0d14b4837eb /fs/inode.c | |
parent | ce9e3d9953c8cb67001719b5516da2928e956be4 (diff) |
[PATCH] Take i_mutex in splice_from_pipe()
The splice_actor may be calling ->prepare_write() and ->commit_write(). We
want i_mutex on the inode being written to before calling those so that we
don't race i_size changes.
The double locking behavior is done elsewhere in splice.c, and if we
eventually want _nolock variants of generic_file_splice_write(), fs modules
might have to replicate the nasty locking code. We introduce
inode_double_lock() and inode_double_unlock() to consolidate the locking
rules into one set of functions.
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'fs/inode.c')
-rw-r--r-- | fs/inode.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/inode.c b/fs/inode.c index d9a21d122926..26cdb115ce67 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -1306,6 +1306,42 @@ void wake_up_inode(struct inode *inode) | |||
1306 | wake_up_bit(&inode->i_state, __I_LOCK); | 1306 | wake_up_bit(&inode->i_state, __I_LOCK); |
1307 | } | 1307 | } |
1308 | 1308 | ||
1309 | /* | ||
1310 | * We rarely want to lock two inodes that do not have a parent/child | ||
1311 | * relationship (such as directory, child inode) simultaneously. The | ||
1312 | * vast majority of file systems should be able to get along fine | ||
1313 | * without this. Do not use these functions except as a last resort. | ||
1314 | */ | ||
1315 | void inode_double_lock(struct inode *inode1, struct inode *inode2) | ||
1316 | { | ||
1317 | if (inode1 == NULL || inode2 == NULL || inode1 == inode2) { | ||
1318 | if (inode1) | ||
1319 | mutex_lock(&inode1->i_mutex); | ||
1320 | else if (inode2) | ||
1321 | mutex_lock(&inode2->i_mutex); | ||
1322 | return; | ||
1323 | } | ||
1324 | |||
1325 | if (inode1 < inode2) { | ||
1326 | mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT); | ||
1327 | mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD); | ||
1328 | } else { | ||
1329 | mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT); | ||
1330 | mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD); | ||
1331 | } | ||
1332 | } | ||
1333 | EXPORT_SYMBOL(inode_double_lock); | ||
1334 | |||
1335 | void inode_double_unlock(struct inode *inode1, struct inode *inode2) | ||
1336 | { | ||
1337 | if (inode1) | ||
1338 | mutex_unlock(&inode1->i_mutex); | ||
1339 | |||
1340 | if (inode2 && inode2 != inode1) | ||
1341 | mutex_unlock(&inode2->i_mutex); | ||
1342 | } | ||
1343 | EXPORT_SYMBOL(inode_double_unlock); | ||
1344 | |||
1309 | static __initdata unsigned long ihash_entries; | 1345 | static __initdata unsigned long ihash_entries; |
1310 | static int __init set_ihash_entries(char *str) | 1346 | static int __init set_ihash_entries(char *str) |
1311 | { | 1347 | { |