diff options
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 | { |
