diff options
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 182 |
1 files changed, 107 insertions, 75 deletions
diff --git a/fs/locks.c b/fs/locks.c index ab24d49fc048..50ec15927aab 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -142,14 +142,32 @@ int lease_break_time = 45; | |||
142 | 142 | ||
143 | static LIST_HEAD(file_lock_list); | 143 | static LIST_HEAD(file_lock_list); |
144 | static LIST_HEAD(blocked_list); | 144 | static LIST_HEAD(blocked_list); |
145 | static DEFINE_SPINLOCK(file_lock_lock); | ||
146 | |||
147 | /* | ||
148 | * Protects the two list heads above, plus the inode->i_flock list | ||
149 | * FIXME: should use a spinlock, once lockd and ceph are ready. | ||
150 | */ | ||
151 | void lock_flocks(void) | ||
152 | { | ||
153 | spin_lock(&file_lock_lock); | ||
154 | } | ||
155 | EXPORT_SYMBOL_GPL(lock_flocks); | ||
156 | |||
157 | void unlock_flocks(void) | ||
158 | { | ||
159 | spin_unlock(&file_lock_lock); | ||
160 | } | ||
161 | EXPORT_SYMBOL_GPL(unlock_flocks); | ||
145 | 162 | ||
146 | static struct kmem_cache *filelock_cache __read_mostly; | 163 | static struct kmem_cache *filelock_cache __read_mostly; |
147 | 164 | ||
148 | /* Allocate an empty lock structure. */ | 165 | /* Allocate an empty lock structure. */ |
149 | static struct file_lock *locks_alloc_lock(void) | 166 | struct file_lock *locks_alloc_lock(void) |
150 | { | 167 | { |
151 | return kmem_cache_alloc(filelock_cache, GFP_KERNEL); | 168 | return kmem_cache_alloc(filelock_cache, GFP_KERNEL); |
152 | } | 169 | } |
170 | EXPORT_SYMBOL_GPL(locks_alloc_lock); | ||
153 | 171 | ||
154 | void locks_release_private(struct file_lock *fl) | 172 | void locks_release_private(struct file_lock *fl) |
155 | { | 173 | { |
@@ -511,9 +529,9 @@ static void __locks_delete_block(struct file_lock *waiter) | |||
511 | */ | 529 | */ |
512 | static void locks_delete_block(struct file_lock *waiter) | 530 | static void locks_delete_block(struct file_lock *waiter) |
513 | { | 531 | { |
514 | lock_kernel(); | 532 | lock_flocks(); |
515 | __locks_delete_block(waiter); | 533 | __locks_delete_block(waiter); |
516 | unlock_kernel(); | 534 | unlock_flocks(); |
517 | } | 535 | } |
518 | 536 | ||
519 | /* Insert waiter into blocker's block list. | 537 | /* Insert waiter into blocker's block list. |
@@ -644,7 +662,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) | |||
644 | { | 662 | { |
645 | struct file_lock *cfl; | 663 | struct file_lock *cfl; |
646 | 664 | ||
647 | lock_kernel(); | 665 | lock_flocks(); |
648 | for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { | 666 | for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { |
649 | if (!IS_POSIX(cfl)) | 667 | if (!IS_POSIX(cfl)) |
650 | continue; | 668 | continue; |
@@ -657,7 +675,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) | |||
657 | fl->fl_pid = pid_vnr(cfl->fl_nspid); | 675 | fl->fl_pid = pid_vnr(cfl->fl_nspid); |
658 | } else | 676 | } else |
659 | fl->fl_type = F_UNLCK; | 677 | fl->fl_type = F_UNLCK; |
660 | unlock_kernel(); | 678 | unlock_flocks(); |
661 | return; | 679 | return; |
662 | } | 680 | } |
663 | EXPORT_SYMBOL(posix_test_lock); | 681 | EXPORT_SYMBOL(posix_test_lock); |
@@ -730,18 +748,16 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
730 | int error = 0; | 748 | int error = 0; |
731 | int found = 0; | 749 | int found = 0; |
732 | 750 | ||
733 | lock_kernel(); | 751 | if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) { |
734 | if (request->fl_flags & FL_ACCESS) | ||
735 | goto find_conflict; | ||
736 | |||
737 | if (request->fl_type != F_UNLCK) { | ||
738 | error = -ENOMEM; | ||
739 | new_fl = locks_alloc_lock(); | 752 | new_fl = locks_alloc_lock(); |
740 | if (new_fl == NULL) | 753 | if (!new_fl) |
741 | goto out; | 754 | return -ENOMEM; |
742 | error = 0; | ||
743 | } | 755 | } |
744 | 756 | ||
757 | lock_flocks(); | ||
758 | if (request->fl_flags & FL_ACCESS) | ||
759 | goto find_conflict; | ||
760 | |||
745 | for_each_lock(inode, before) { | 761 | for_each_lock(inode, before) { |
746 | struct file_lock *fl = *before; | 762 | struct file_lock *fl = *before; |
747 | if (IS_POSIX(fl)) | 763 | if (IS_POSIX(fl)) |
@@ -767,8 +783,11 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
767 | * If a higher-priority process was blocked on the old file lock, | 783 | * If a higher-priority process was blocked on the old file lock, |
768 | * give it the opportunity to lock the file. | 784 | * give it the opportunity to lock the file. |
769 | */ | 785 | */ |
770 | if (found) | 786 | if (found) { |
787 | unlock_flocks(); | ||
771 | cond_resched(); | 788 | cond_resched(); |
789 | lock_flocks(); | ||
790 | } | ||
772 | 791 | ||
773 | find_conflict: | 792 | find_conflict: |
774 | for_each_lock(inode, before) { | 793 | for_each_lock(inode, before) { |
@@ -794,7 +813,7 @@ find_conflict: | |||
794 | error = 0; | 813 | error = 0; |
795 | 814 | ||
796 | out: | 815 | out: |
797 | unlock_kernel(); | 816 | unlock_flocks(); |
798 | if (new_fl) | 817 | if (new_fl) |
799 | locks_free_lock(new_fl); | 818 | locks_free_lock(new_fl); |
800 | return error; | 819 | return error; |
@@ -823,7 +842,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str | |||
823 | new_fl2 = locks_alloc_lock(); | 842 | new_fl2 = locks_alloc_lock(); |
824 | } | 843 | } |
825 | 844 | ||
826 | lock_kernel(); | 845 | lock_flocks(); |
827 | if (request->fl_type != F_UNLCK) { | 846 | if (request->fl_type != F_UNLCK) { |
828 | for_each_lock(inode, before) { | 847 | for_each_lock(inode, before) { |
829 | fl = *before; | 848 | fl = *before; |
@@ -991,7 +1010,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str | |||
991 | locks_wake_up_blocks(left); | 1010 | locks_wake_up_blocks(left); |
992 | } | 1011 | } |
993 | out: | 1012 | out: |
994 | unlock_kernel(); | 1013 | unlock_flocks(); |
995 | /* | 1014 | /* |
996 | * Free any unused locks. | 1015 | * Free any unused locks. |
997 | */ | 1016 | */ |
@@ -1066,14 +1085,14 @@ int locks_mandatory_locked(struct inode *inode) | |||
1066 | /* | 1085 | /* |
1067 | * Search the lock list for this inode for any POSIX locks. | 1086 | * Search the lock list for this inode for any POSIX locks. |
1068 | */ | 1087 | */ |
1069 | lock_kernel(); | 1088 | lock_flocks(); |
1070 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 1089 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
1071 | if (!IS_POSIX(fl)) | 1090 | if (!IS_POSIX(fl)) |
1072 | continue; | 1091 | continue; |
1073 | if (fl->fl_owner != owner) | 1092 | if (fl->fl_owner != owner) |
1074 | break; | 1093 | break; |
1075 | } | 1094 | } |
1076 | unlock_kernel(); | 1095 | unlock_flocks(); |
1077 | return fl ? -EAGAIN : 0; | 1096 | return fl ? -EAGAIN : 0; |
1078 | } | 1097 | } |
1079 | 1098 | ||
@@ -1186,7 +1205,7 @@ int __break_lease(struct inode *inode, unsigned int mode) | |||
1186 | 1205 | ||
1187 | new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); | 1206 | new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); |
1188 | 1207 | ||
1189 | lock_kernel(); | 1208 | lock_flocks(); |
1190 | 1209 | ||
1191 | time_out_leases(inode); | 1210 | time_out_leases(inode); |
1192 | 1211 | ||
@@ -1247,8 +1266,10 @@ restart: | |||
1247 | break_time++; | 1266 | break_time++; |
1248 | } | 1267 | } |
1249 | locks_insert_block(flock, new_fl); | 1268 | locks_insert_block(flock, new_fl); |
1269 | unlock_flocks(); | ||
1250 | error = wait_event_interruptible_timeout(new_fl->fl_wait, | 1270 | error = wait_event_interruptible_timeout(new_fl->fl_wait, |
1251 | !new_fl->fl_next, break_time); | 1271 | !new_fl->fl_next, break_time); |
1272 | lock_flocks(); | ||
1252 | __locks_delete_block(new_fl); | 1273 | __locks_delete_block(new_fl); |
1253 | if (error >= 0) { | 1274 | if (error >= 0) { |
1254 | if (error == 0) | 1275 | if (error == 0) |
@@ -1263,7 +1284,7 @@ restart: | |||
1263 | } | 1284 | } |
1264 | 1285 | ||
1265 | out: | 1286 | out: |
1266 | unlock_kernel(); | 1287 | unlock_flocks(); |
1267 | if (!IS_ERR(new_fl)) | 1288 | if (!IS_ERR(new_fl)) |
1268 | locks_free_lock(new_fl); | 1289 | locks_free_lock(new_fl); |
1269 | return error; | 1290 | return error; |
@@ -1319,7 +1340,7 @@ int fcntl_getlease(struct file *filp) | |||
1319 | struct file_lock *fl; | 1340 | struct file_lock *fl; |
1320 | int type = F_UNLCK; | 1341 | int type = F_UNLCK; |
1321 | 1342 | ||
1322 | lock_kernel(); | 1343 | lock_flocks(); |
1323 | time_out_leases(filp->f_path.dentry->d_inode); | 1344 | time_out_leases(filp->f_path.dentry->d_inode); |
1324 | for (fl = filp->f_path.dentry->d_inode->i_flock; fl && IS_LEASE(fl); | 1345 | for (fl = filp->f_path.dentry->d_inode->i_flock; fl && IS_LEASE(fl); |
1325 | fl = fl->fl_next) { | 1346 | fl = fl->fl_next) { |
@@ -1328,7 +1349,7 @@ int fcntl_getlease(struct file *filp) | |||
1328 | break; | 1349 | break; |
1329 | } | 1350 | } |
1330 | } | 1351 | } |
1331 | unlock_kernel(); | 1352 | unlock_flocks(); |
1332 | return type; | 1353 | return type; |
1333 | } | 1354 | } |
1334 | 1355 | ||
@@ -1341,12 +1362,11 @@ int fcntl_getlease(struct file *filp) | |||
1341 | * The (input) flp->fl_lmops->fl_break function is required | 1362 | * The (input) flp->fl_lmops->fl_break function is required |
1342 | * by break_lease(). | 1363 | * by break_lease(). |
1343 | * | 1364 | * |
1344 | * Called with kernel lock held. | 1365 | * Called with file_lock_lock held. |
1345 | */ | 1366 | */ |
1346 | int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | 1367 | int generic_setlease(struct file *filp, long arg, struct file_lock **flp) |
1347 | { | 1368 | { |
1348 | struct file_lock *fl, **before, **my_before = NULL, *lease; | 1369 | struct file_lock *fl, **before, **my_before = NULL, *lease; |
1349 | struct file_lock *new_fl = NULL; | ||
1350 | struct dentry *dentry = filp->f_path.dentry; | 1370 | struct dentry *dentry = filp->f_path.dentry; |
1351 | struct inode *inode = dentry->d_inode; | 1371 | struct inode *inode = dentry->d_inode; |
1352 | int error, rdlease_count = 0, wrlease_count = 0; | 1372 | int error, rdlease_count = 0, wrlease_count = 0; |
@@ -1366,11 +1386,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | |||
1366 | lease = *flp; | 1386 | lease = *flp; |
1367 | 1387 | ||
1368 | if (arg != F_UNLCK) { | 1388 | if (arg != F_UNLCK) { |
1369 | error = -ENOMEM; | ||
1370 | new_fl = locks_alloc_lock(); | ||
1371 | if (new_fl == NULL) | ||
1372 | goto out; | ||
1373 | |||
1374 | error = -EAGAIN; | 1389 | error = -EAGAIN; |
1375 | if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) | 1390 | if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) |
1376 | goto out; | 1391 | goto out; |
@@ -1415,7 +1430,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | |||
1415 | goto out; | 1430 | goto out; |
1416 | } | 1431 | } |
1417 | 1432 | ||
1418 | error = 0; | ||
1419 | if (arg == F_UNLCK) | 1433 | if (arg == F_UNLCK) |
1420 | goto out; | 1434 | goto out; |
1421 | 1435 | ||
@@ -1423,20 +1437,24 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | |||
1423 | if (!leases_enable) | 1437 | if (!leases_enable) |
1424 | goto out; | 1438 | goto out; |
1425 | 1439 | ||
1426 | locks_copy_lock(new_fl, lease); | 1440 | locks_insert_lock(before, lease); |
1427 | locks_insert_lock(before, new_fl); | ||
1428 | |||
1429 | *flp = new_fl; | ||
1430 | return 0; | 1441 | return 0; |
1431 | 1442 | ||
1432 | out: | 1443 | out: |
1433 | if (new_fl != NULL) | 1444 | locks_free_lock(lease); |
1434 | locks_free_lock(new_fl); | ||
1435 | return error; | 1445 | return error; |
1436 | } | 1446 | } |
1437 | EXPORT_SYMBOL(generic_setlease); | 1447 | EXPORT_SYMBOL(generic_setlease); |
1438 | 1448 | ||
1439 | /** | 1449 | static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease) |
1450 | { | ||
1451 | if (filp->f_op && filp->f_op->setlease) | ||
1452 | return filp->f_op->setlease(filp, arg, lease); | ||
1453 | else | ||
1454 | return generic_setlease(filp, arg, lease); | ||
1455 | } | ||
1456 | |||
1457 | /** | ||
1440 | * vfs_setlease - sets a lease on an open file | 1458 | * vfs_setlease - sets a lease on an open file |
1441 | * @filp: file pointer | 1459 | * @filp: file pointer |
1442 | * @arg: type of lease to obtain | 1460 | * @arg: type of lease to obtain |
@@ -1467,12 +1485,9 @@ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease) | |||
1467 | { | 1485 | { |
1468 | int error; | 1486 | int error; |
1469 | 1487 | ||
1470 | lock_kernel(); | 1488 | lock_flocks(); |
1471 | if (filp->f_op && filp->f_op->setlease) | 1489 | error = __vfs_setlease(filp, arg, lease); |
1472 | error = filp->f_op->setlease(filp, arg, lease); | 1490 | unlock_flocks(); |
1473 | else | ||
1474 | error = generic_setlease(filp, arg, lease); | ||
1475 | unlock_kernel(); | ||
1476 | 1491 | ||
1477 | return error; | 1492 | return error; |
1478 | } | 1493 | } |
@@ -1490,33 +1505,47 @@ EXPORT_SYMBOL_GPL(vfs_setlease); | |||
1490 | */ | 1505 | */ |
1491 | int fcntl_setlease(unsigned int fd, struct file *filp, long arg) | 1506 | int fcntl_setlease(unsigned int fd, struct file *filp, long arg) |
1492 | { | 1507 | { |
1493 | struct file_lock fl, *flp = &fl; | 1508 | struct file_lock *fl; |
1509 | struct fasync_struct *new; | ||
1494 | struct inode *inode = filp->f_path.dentry->d_inode; | 1510 | struct inode *inode = filp->f_path.dentry->d_inode; |
1495 | int error; | 1511 | int error; |
1496 | 1512 | ||
1497 | locks_init_lock(&fl); | 1513 | fl = lease_alloc(filp, arg); |
1498 | error = lease_init(filp, arg, &fl); | 1514 | if (IS_ERR(fl)) |
1499 | if (error) | 1515 | return PTR_ERR(fl); |
1500 | return error; | ||
1501 | 1516 | ||
1502 | lock_kernel(); | 1517 | new = fasync_alloc(); |
1503 | 1518 | if (!new) { | |
1504 | error = vfs_setlease(filp, arg, &flp); | 1519 | locks_free_lock(fl); |
1520 | return -ENOMEM; | ||
1521 | } | ||
1522 | lock_flocks(); | ||
1523 | error = __vfs_setlease(filp, arg, &fl); | ||
1505 | if (error || arg == F_UNLCK) | 1524 | if (error || arg == F_UNLCK) |
1506 | goto out_unlock; | 1525 | goto out_unlock; |
1507 | 1526 | ||
1508 | error = fasync_helper(fd, filp, 1, &flp->fl_fasync); | 1527 | /* |
1528 | * fasync_insert_entry() returns the old entry if any. | ||
1529 | * If there was no old entry, then it used 'new' and | ||
1530 | * inserted it into the fasync list. Clear new so that | ||
1531 | * we don't release it here. | ||
1532 | */ | ||
1533 | if (!fasync_insert_entry(fd, filp, &fl->fl_fasync, new)) | ||
1534 | new = NULL; | ||
1535 | |||
1509 | if (error < 0) { | 1536 | if (error < 0) { |
1510 | /* remove lease just inserted by setlease */ | 1537 | /* remove lease just inserted by setlease */ |
1511 | flp->fl_type = F_UNLCK | F_INPROGRESS; | 1538 | fl->fl_type = F_UNLCK | F_INPROGRESS; |
1512 | flp->fl_break_time = jiffies - 10; | 1539 | fl->fl_break_time = jiffies - 10; |
1513 | time_out_leases(inode); | 1540 | time_out_leases(inode); |
1514 | goto out_unlock; | 1541 | goto out_unlock; |
1515 | } | 1542 | } |
1516 | 1543 | ||
1517 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); | 1544 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); |
1518 | out_unlock: | 1545 | out_unlock: |
1519 | unlock_kernel(); | 1546 | unlock_flocks(); |
1547 | if (new) | ||
1548 | fasync_free(new); | ||
1520 | return error; | 1549 | return error; |
1521 | } | 1550 | } |
1522 | 1551 | ||
@@ -2020,7 +2049,7 @@ void locks_remove_flock(struct file *filp) | |||
2020 | fl.fl_ops->fl_release_private(&fl); | 2049 | fl.fl_ops->fl_release_private(&fl); |
2021 | } | 2050 | } |
2022 | 2051 | ||
2023 | lock_kernel(); | 2052 | lock_flocks(); |
2024 | before = &inode->i_flock; | 2053 | before = &inode->i_flock; |
2025 | 2054 | ||
2026 | while ((fl = *before) != NULL) { | 2055 | while ((fl = *before) != NULL) { |
@@ -2038,7 +2067,7 @@ void locks_remove_flock(struct file *filp) | |||
2038 | } | 2067 | } |
2039 | before = &fl->fl_next; | 2068 | before = &fl->fl_next; |
2040 | } | 2069 | } |
2041 | unlock_kernel(); | 2070 | unlock_flocks(); |
2042 | } | 2071 | } |
2043 | 2072 | ||
2044 | /** | 2073 | /** |
@@ -2053,12 +2082,12 @@ posix_unblock_lock(struct file *filp, struct file_lock *waiter) | |||
2053 | { | 2082 | { |
2054 | int status = 0; | 2083 | int status = 0; |
2055 | 2084 | ||
2056 | lock_kernel(); | 2085 | lock_flocks(); |
2057 | if (waiter->fl_next) | 2086 | if (waiter->fl_next) |
2058 | __locks_delete_block(waiter); | 2087 | __locks_delete_block(waiter); |
2059 | else | 2088 | else |
2060 | status = -ENOENT; | 2089 | status = -ENOENT; |
2061 | unlock_kernel(); | 2090 | unlock_flocks(); |
2062 | return status; | 2091 | return status; |
2063 | } | 2092 | } |
2064 | 2093 | ||
@@ -2085,7 +2114,7 @@ EXPORT_SYMBOL_GPL(vfs_cancel_lock); | |||
2085 | #include <linux/seq_file.h> | 2114 | #include <linux/seq_file.h> |
2086 | 2115 | ||
2087 | static void lock_get_status(struct seq_file *f, struct file_lock *fl, | 2116 | static void lock_get_status(struct seq_file *f, struct file_lock *fl, |
2088 | int id, char *pfx) | 2117 | loff_t id, char *pfx) |
2089 | { | 2118 | { |
2090 | struct inode *inode = NULL; | 2119 | struct inode *inode = NULL; |
2091 | unsigned int fl_pid; | 2120 | unsigned int fl_pid; |
@@ -2098,7 +2127,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, | |||
2098 | if (fl->fl_file != NULL) | 2127 | if (fl->fl_file != NULL) |
2099 | inode = fl->fl_file->f_path.dentry->d_inode; | 2128 | inode = fl->fl_file->f_path.dentry->d_inode; |
2100 | 2129 | ||
2101 | seq_printf(f, "%d:%s ", id, pfx); | 2130 | seq_printf(f, "%lld:%s ", id, pfx); |
2102 | if (IS_POSIX(fl)) { | 2131 | if (IS_POSIX(fl)) { |
2103 | seq_printf(f, "%6s %s ", | 2132 | seq_printf(f, "%6s %s ", |
2104 | (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", | 2133 | (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", |
@@ -2161,30 +2190,33 @@ static int locks_show(struct seq_file *f, void *v) | |||
2161 | 2190 | ||
2162 | fl = list_entry(v, struct file_lock, fl_link); | 2191 | fl = list_entry(v, struct file_lock, fl_link); |
2163 | 2192 | ||
2164 | lock_get_status(f, fl, (long)f->private, ""); | 2193 | lock_get_status(f, fl, *((loff_t *)f->private), ""); |
2165 | 2194 | ||
2166 | list_for_each_entry(bfl, &fl->fl_block, fl_block) | 2195 | list_for_each_entry(bfl, &fl->fl_block, fl_block) |
2167 | lock_get_status(f, bfl, (long)f->private, " ->"); | 2196 | lock_get_status(f, bfl, *((loff_t *)f->private), " ->"); |
2168 | 2197 | ||
2169 | f->private++; | ||
2170 | return 0; | 2198 | return 0; |
2171 | } | 2199 | } |
2172 | 2200 | ||
2173 | static void *locks_start(struct seq_file *f, loff_t *pos) | 2201 | static void *locks_start(struct seq_file *f, loff_t *pos) |
2174 | { | 2202 | { |
2175 | lock_kernel(); | 2203 | loff_t *p = f->private; |
2176 | f->private = (void *)1; | 2204 | |
2205 | lock_flocks(); | ||
2206 | *p = (*pos + 1); | ||
2177 | return seq_list_start(&file_lock_list, *pos); | 2207 | return seq_list_start(&file_lock_list, *pos); |
2178 | } | 2208 | } |
2179 | 2209 | ||
2180 | static void *locks_next(struct seq_file *f, void *v, loff_t *pos) | 2210 | static void *locks_next(struct seq_file *f, void *v, loff_t *pos) |
2181 | { | 2211 | { |
2212 | loff_t *p = f->private; | ||
2213 | ++*p; | ||
2182 | return seq_list_next(v, &file_lock_list, pos); | 2214 | return seq_list_next(v, &file_lock_list, pos); |
2183 | } | 2215 | } |
2184 | 2216 | ||
2185 | static void locks_stop(struct seq_file *f, void *v) | 2217 | static void locks_stop(struct seq_file *f, void *v) |
2186 | { | 2218 | { |
2187 | unlock_kernel(); | 2219 | unlock_flocks(); |
2188 | } | 2220 | } |
2189 | 2221 | ||
2190 | static const struct seq_operations locks_seq_operations = { | 2222 | static const struct seq_operations locks_seq_operations = { |
@@ -2196,14 +2228,14 @@ static const struct seq_operations locks_seq_operations = { | |||
2196 | 2228 | ||
2197 | static int locks_open(struct inode *inode, struct file *filp) | 2229 | static int locks_open(struct inode *inode, struct file *filp) |
2198 | { | 2230 | { |
2199 | return seq_open(filp, &locks_seq_operations); | 2231 | return seq_open_private(filp, &locks_seq_operations, sizeof(loff_t)); |
2200 | } | 2232 | } |
2201 | 2233 | ||
2202 | static const struct file_operations proc_locks_operations = { | 2234 | static const struct file_operations proc_locks_operations = { |
2203 | .open = locks_open, | 2235 | .open = locks_open, |
2204 | .read = seq_read, | 2236 | .read = seq_read, |
2205 | .llseek = seq_lseek, | 2237 | .llseek = seq_lseek, |
2206 | .release = seq_release, | 2238 | .release = seq_release_private, |
2207 | }; | 2239 | }; |
2208 | 2240 | ||
2209 | static int __init proc_locks_init(void) | 2241 | static int __init proc_locks_init(void) |
@@ -2231,7 +2263,7 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len) | |||
2231 | { | 2263 | { |
2232 | struct file_lock *fl; | 2264 | struct file_lock *fl; |
2233 | int result = 1; | 2265 | int result = 1; |
2234 | lock_kernel(); | 2266 | lock_flocks(); |
2235 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 2267 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
2236 | if (IS_POSIX(fl)) { | 2268 | if (IS_POSIX(fl)) { |
2237 | if (fl->fl_type == F_RDLCK) | 2269 | if (fl->fl_type == F_RDLCK) |
@@ -2248,7 +2280,7 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len) | |||
2248 | result = 0; | 2280 | result = 0; |
2249 | break; | 2281 | break; |
2250 | } | 2282 | } |
2251 | unlock_kernel(); | 2283 | unlock_flocks(); |
2252 | return result; | 2284 | return result; |
2253 | } | 2285 | } |
2254 | 2286 | ||
@@ -2271,7 +2303,7 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) | |||
2271 | { | 2303 | { |
2272 | struct file_lock *fl; | 2304 | struct file_lock *fl; |
2273 | int result = 1; | 2305 | int result = 1; |
2274 | lock_kernel(); | 2306 | lock_flocks(); |
2275 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 2307 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
2276 | if (IS_POSIX(fl)) { | 2308 | if (IS_POSIX(fl)) { |
2277 | if ((fl->fl_end < start) || (fl->fl_start > (start + len))) | 2309 | if ((fl->fl_end < start) || (fl->fl_start > (start + len))) |
@@ -2286,7 +2318,7 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) | |||
2286 | result = 0; | 2318 | result = 0; |
2287 | break; | 2319 | break; |
2288 | } | 2320 | } |
2289 | unlock_kernel(); | 2321 | unlock_flocks(); |
2290 | return result; | 2322 | return result; |
2291 | } | 2323 | } |
2292 | 2324 | ||