diff options
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 250 |
1 files changed, 148 insertions, 102 deletions
diff --git a/fs/locks.c b/fs/locks.c index ab24d49fc048..0e62dd35d088 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 | { |
@@ -168,7 +186,7 @@ void locks_release_private(struct file_lock *fl) | |||
168 | EXPORT_SYMBOL_GPL(locks_release_private); | 186 | EXPORT_SYMBOL_GPL(locks_release_private); |
169 | 187 | ||
170 | /* Free a lock which is not in use. */ | 188 | /* Free a lock which is not in use. */ |
171 | static void locks_free_lock(struct file_lock *fl) | 189 | void locks_free_lock(struct file_lock *fl) |
172 | { | 190 | { |
173 | BUG_ON(waitqueue_active(&fl->fl_wait)); | 191 | BUG_ON(waitqueue_active(&fl->fl_wait)); |
174 | BUG_ON(!list_empty(&fl->fl_block)); | 192 | BUG_ON(!list_empty(&fl->fl_block)); |
@@ -177,6 +195,7 @@ static void locks_free_lock(struct file_lock *fl) | |||
177 | locks_release_private(fl); | 195 | locks_release_private(fl); |
178 | kmem_cache_free(filelock_cache, fl); | 196 | kmem_cache_free(filelock_cache, fl); |
179 | } | 197 | } |
198 | EXPORT_SYMBOL(locks_free_lock); | ||
180 | 199 | ||
181 | void locks_init_lock(struct file_lock *fl) | 200 | void locks_init_lock(struct file_lock *fl) |
182 | { | 201 | { |
@@ -216,11 +235,8 @@ static void locks_copy_private(struct file_lock *new, struct file_lock *fl) | |||
216 | fl->fl_ops->fl_copy_lock(new, fl); | 235 | fl->fl_ops->fl_copy_lock(new, fl); |
217 | new->fl_ops = fl->fl_ops; | 236 | new->fl_ops = fl->fl_ops; |
218 | } | 237 | } |
219 | if (fl->fl_lmops) { | 238 | if (fl->fl_lmops) |
220 | if (fl->fl_lmops->fl_copy_lock) | ||
221 | fl->fl_lmops->fl_copy_lock(new, fl); | ||
222 | new->fl_lmops = fl->fl_lmops; | 239 | new->fl_lmops = fl->fl_lmops; |
223 | } | ||
224 | } | 240 | } |
225 | 241 | ||
226 | /* | 242 | /* |
@@ -511,9 +527,9 @@ static void __locks_delete_block(struct file_lock *waiter) | |||
511 | */ | 527 | */ |
512 | static void locks_delete_block(struct file_lock *waiter) | 528 | static void locks_delete_block(struct file_lock *waiter) |
513 | { | 529 | { |
514 | lock_kernel(); | 530 | lock_flocks(); |
515 | __locks_delete_block(waiter); | 531 | __locks_delete_block(waiter); |
516 | unlock_kernel(); | 532 | unlock_flocks(); |
517 | } | 533 | } |
518 | 534 | ||
519 | /* Insert waiter into blocker's block list. | 535 | /* Insert waiter into blocker's block list. |
@@ -644,7 +660,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) | |||
644 | { | 660 | { |
645 | struct file_lock *cfl; | 661 | struct file_lock *cfl; |
646 | 662 | ||
647 | lock_kernel(); | 663 | lock_flocks(); |
648 | for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { | 664 | for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { |
649 | if (!IS_POSIX(cfl)) | 665 | if (!IS_POSIX(cfl)) |
650 | continue; | 666 | continue; |
@@ -657,7 +673,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) | |||
657 | fl->fl_pid = pid_vnr(cfl->fl_nspid); | 673 | fl->fl_pid = pid_vnr(cfl->fl_nspid); |
658 | } else | 674 | } else |
659 | fl->fl_type = F_UNLCK; | 675 | fl->fl_type = F_UNLCK; |
660 | unlock_kernel(); | 676 | unlock_flocks(); |
661 | return; | 677 | return; |
662 | } | 678 | } |
663 | EXPORT_SYMBOL(posix_test_lock); | 679 | EXPORT_SYMBOL(posix_test_lock); |
@@ -730,18 +746,16 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
730 | int error = 0; | 746 | int error = 0; |
731 | int found = 0; | 747 | int found = 0; |
732 | 748 | ||
733 | lock_kernel(); | 749 | 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(); | 750 | new_fl = locks_alloc_lock(); |
740 | if (new_fl == NULL) | 751 | if (!new_fl) |
741 | goto out; | 752 | return -ENOMEM; |
742 | error = 0; | ||
743 | } | 753 | } |
744 | 754 | ||
755 | lock_flocks(); | ||
756 | if (request->fl_flags & FL_ACCESS) | ||
757 | goto find_conflict; | ||
758 | |||
745 | for_each_lock(inode, before) { | 759 | for_each_lock(inode, before) { |
746 | struct file_lock *fl = *before; | 760 | struct file_lock *fl = *before; |
747 | if (IS_POSIX(fl)) | 761 | if (IS_POSIX(fl)) |
@@ -767,8 +781,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, | 781 | * If a higher-priority process was blocked on the old file lock, |
768 | * give it the opportunity to lock the file. | 782 | * give it the opportunity to lock the file. |
769 | */ | 783 | */ |
770 | if (found) | 784 | if (found) { |
785 | unlock_flocks(); | ||
771 | cond_resched(); | 786 | cond_resched(); |
787 | lock_flocks(); | ||
788 | } | ||
772 | 789 | ||
773 | find_conflict: | 790 | find_conflict: |
774 | for_each_lock(inode, before) { | 791 | for_each_lock(inode, before) { |
@@ -794,7 +811,7 @@ find_conflict: | |||
794 | error = 0; | 811 | error = 0; |
795 | 812 | ||
796 | out: | 813 | out: |
797 | unlock_kernel(); | 814 | unlock_flocks(); |
798 | if (new_fl) | 815 | if (new_fl) |
799 | locks_free_lock(new_fl); | 816 | locks_free_lock(new_fl); |
800 | return error; | 817 | return error; |
@@ -823,7 +840,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str | |||
823 | new_fl2 = locks_alloc_lock(); | 840 | new_fl2 = locks_alloc_lock(); |
824 | } | 841 | } |
825 | 842 | ||
826 | lock_kernel(); | 843 | lock_flocks(); |
827 | if (request->fl_type != F_UNLCK) { | 844 | if (request->fl_type != F_UNLCK) { |
828 | for_each_lock(inode, before) { | 845 | for_each_lock(inode, before) { |
829 | fl = *before; | 846 | fl = *before; |
@@ -991,7 +1008,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str | |||
991 | locks_wake_up_blocks(left); | 1008 | locks_wake_up_blocks(left); |
992 | } | 1009 | } |
993 | out: | 1010 | out: |
994 | unlock_kernel(); | 1011 | unlock_flocks(); |
995 | /* | 1012 | /* |
996 | * Free any unused locks. | 1013 | * Free any unused locks. |
997 | */ | 1014 | */ |
@@ -1066,14 +1083,14 @@ int locks_mandatory_locked(struct inode *inode) | |||
1066 | /* | 1083 | /* |
1067 | * Search the lock list for this inode for any POSIX locks. | 1084 | * Search the lock list for this inode for any POSIX locks. |
1068 | */ | 1085 | */ |
1069 | lock_kernel(); | 1086 | lock_flocks(); |
1070 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 1087 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
1071 | if (!IS_POSIX(fl)) | 1088 | if (!IS_POSIX(fl)) |
1072 | continue; | 1089 | continue; |
1073 | if (fl->fl_owner != owner) | 1090 | if (fl->fl_owner != owner) |
1074 | break; | 1091 | break; |
1075 | } | 1092 | } |
1076 | unlock_kernel(); | 1093 | unlock_flocks(); |
1077 | return fl ? -EAGAIN : 0; | 1094 | return fl ? -EAGAIN : 0; |
1078 | } | 1095 | } |
1079 | 1096 | ||
@@ -1186,7 +1203,7 @@ int __break_lease(struct inode *inode, unsigned int mode) | |||
1186 | 1203 | ||
1187 | new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); | 1204 | new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); |
1188 | 1205 | ||
1189 | lock_kernel(); | 1206 | lock_flocks(); |
1190 | 1207 | ||
1191 | time_out_leases(inode); | 1208 | time_out_leases(inode); |
1192 | 1209 | ||
@@ -1247,8 +1264,10 @@ restart: | |||
1247 | break_time++; | 1264 | break_time++; |
1248 | } | 1265 | } |
1249 | locks_insert_block(flock, new_fl); | 1266 | locks_insert_block(flock, new_fl); |
1267 | unlock_flocks(); | ||
1250 | error = wait_event_interruptible_timeout(new_fl->fl_wait, | 1268 | error = wait_event_interruptible_timeout(new_fl->fl_wait, |
1251 | !new_fl->fl_next, break_time); | 1269 | !new_fl->fl_next, break_time); |
1270 | lock_flocks(); | ||
1252 | __locks_delete_block(new_fl); | 1271 | __locks_delete_block(new_fl); |
1253 | if (error >= 0) { | 1272 | if (error >= 0) { |
1254 | if (error == 0) | 1273 | if (error == 0) |
@@ -1263,7 +1282,7 @@ restart: | |||
1263 | } | 1282 | } |
1264 | 1283 | ||
1265 | out: | 1284 | out: |
1266 | unlock_kernel(); | 1285 | unlock_flocks(); |
1267 | if (!IS_ERR(new_fl)) | 1286 | if (!IS_ERR(new_fl)) |
1268 | locks_free_lock(new_fl); | 1287 | locks_free_lock(new_fl); |
1269 | return error; | 1288 | return error; |
@@ -1319,7 +1338,7 @@ int fcntl_getlease(struct file *filp) | |||
1319 | struct file_lock *fl; | 1338 | struct file_lock *fl; |
1320 | int type = F_UNLCK; | 1339 | int type = F_UNLCK; |
1321 | 1340 | ||
1322 | lock_kernel(); | 1341 | lock_flocks(); |
1323 | time_out_leases(filp->f_path.dentry->d_inode); | 1342 | time_out_leases(filp->f_path.dentry->d_inode); |
1324 | for (fl = filp->f_path.dentry->d_inode->i_flock; fl && IS_LEASE(fl); | 1343 | for (fl = filp->f_path.dentry->d_inode->i_flock; fl && IS_LEASE(fl); |
1325 | fl = fl->fl_next) { | 1344 | fl = fl->fl_next) { |
@@ -1328,7 +1347,7 @@ int fcntl_getlease(struct file *filp) | |||
1328 | break; | 1347 | break; |
1329 | } | 1348 | } |
1330 | } | 1349 | } |
1331 | unlock_kernel(); | 1350 | unlock_flocks(); |
1332 | return type; | 1351 | return type; |
1333 | } | 1352 | } |
1334 | 1353 | ||
@@ -1341,36 +1360,32 @@ int fcntl_getlease(struct file *filp) | |||
1341 | * The (input) flp->fl_lmops->fl_break function is required | 1360 | * The (input) flp->fl_lmops->fl_break function is required |
1342 | * by break_lease(). | 1361 | * by break_lease(). |
1343 | * | 1362 | * |
1344 | * Called with kernel lock held. | 1363 | * Called with file_lock_lock held. |
1345 | */ | 1364 | */ |
1346 | int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | 1365 | int generic_setlease(struct file *filp, long arg, struct file_lock **flp) |
1347 | { | 1366 | { |
1348 | struct file_lock *fl, **before, **my_before = NULL, *lease; | 1367 | struct file_lock *fl, **before, **my_before = NULL, *lease; |
1349 | struct file_lock *new_fl = NULL; | ||
1350 | struct dentry *dentry = filp->f_path.dentry; | 1368 | struct dentry *dentry = filp->f_path.dentry; |
1351 | struct inode *inode = dentry->d_inode; | 1369 | struct inode *inode = dentry->d_inode; |
1352 | int error, rdlease_count = 0, wrlease_count = 0; | 1370 | int error, rdlease_count = 0, wrlease_count = 0; |
1353 | 1371 | ||
1372 | lease = *flp; | ||
1373 | |||
1374 | error = -EACCES; | ||
1354 | if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE)) | 1375 | if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE)) |
1355 | return -EACCES; | 1376 | goto out; |
1377 | error = -EINVAL; | ||
1356 | if (!S_ISREG(inode->i_mode)) | 1378 | if (!S_ISREG(inode->i_mode)) |
1357 | return -EINVAL; | 1379 | goto out; |
1358 | error = security_file_lock(filp, arg); | 1380 | error = security_file_lock(filp, arg); |
1359 | if (error) | 1381 | if (error) |
1360 | return error; | 1382 | goto out; |
1361 | 1383 | ||
1362 | time_out_leases(inode); | 1384 | time_out_leases(inode); |
1363 | 1385 | ||
1364 | BUG_ON(!(*flp)->fl_lmops->fl_break); | 1386 | BUG_ON(!(*flp)->fl_lmops->fl_break); |
1365 | 1387 | ||
1366 | lease = *flp; | ||
1367 | |||
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; |
@@ -1410,12 +1425,12 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | |||
1410 | goto out; | 1425 | goto out; |
1411 | 1426 | ||
1412 | if (my_before != NULL) { | 1427 | if (my_before != NULL) { |
1413 | *flp = *my_before; | ||
1414 | error = lease->fl_lmops->fl_change(my_before, arg); | 1428 | error = lease->fl_lmops->fl_change(my_before, arg); |
1429 | if (!error) | ||
1430 | *flp = *my_before; | ||
1415 | goto out; | 1431 | goto out; |
1416 | } | 1432 | } |
1417 | 1433 | ||
1418 | error = 0; | ||
1419 | if (arg == F_UNLCK) | 1434 | if (arg == F_UNLCK) |
1420 | goto out; | 1435 | goto out; |
1421 | 1436 | ||
@@ -1423,20 +1438,23 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) | |||
1423 | if (!leases_enable) | 1438 | if (!leases_enable) |
1424 | goto out; | 1439 | goto out; |
1425 | 1440 | ||
1426 | locks_copy_lock(new_fl, lease); | 1441 | locks_insert_lock(before, lease); |
1427 | locks_insert_lock(before, new_fl); | ||
1428 | |||
1429 | *flp = new_fl; | ||
1430 | return 0; | 1442 | return 0; |
1431 | 1443 | ||
1432 | out: | 1444 | out: |
1433 | if (new_fl != NULL) | ||
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,17 +1485,67 @@ 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 | } |
1479 | EXPORT_SYMBOL_GPL(vfs_setlease); | 1494 | EXPORT_SYMBOL_GPL(vfs_setlease); |
1480 | 1495 | ||
1496 | static int do_fcntl_delete_lease(struct file *filp) | ||
1497 | { | ||
1498 | struct file_lock fl, *flp = &fl; | ||
1499 | |||
1500 | lease_init(filp, F_UNLCK, flp); | ||
1501 | |||
1502 | return vfs_setlease(filp, F_UNLCK, &flp); | ||
1503 | } | ||
1504 | |||
1505 | static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) | ||
1506 | { | ||
1507 | struct file_lock *fl, *ret; | ||
1508 | struct fasync_struct *new; | ||
1509 | int error; | ||
1510 | |||
1511 | fl = lease_alloc(filp, arg); | ||
1512 | if (IS_ERR(fl)) | ||
1513 | return PTR_ERR(fl); | ||
1514 | |||
1515 | new = fasync_alloc(); | ||
1516 | if (!new) { | ||
1517 | locks_free_lock(fl); | ||
1518 | return -ENOMEM; | ||
1519 | } | ||
1520 | ret = fl; | ||
1521 | lock_flocks(); | ||
1522 | error = __vfs_setlease(filp, arg, &ret); | ||
1523 | if (error) { | ||
1524 | unlock_flocks(); | ||
1525 | locks_free_lock(fl); | ||
1526 | goto out_free_fasync; | ||
1527 | } | ||
1528 | if (ret != fl) | ||
1529 | locks_free_lock(fl); | ||
1530 | |||
1531 | /* | ||
1532 | * fasync_insert_entry() returns the old entry if any. | ||
1533 | * If there was no old entry, then it used 'new' and | ||
1534 | * inserted it into the fasync list. Clear new so that | ||
1535 | * we don't release it here. | ||
1536 | */ | ||
1537 | if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new)) | ||
1538 | new = NULL; | ||
1539 | |||
1540 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); | ||
1541 | unlock_flocks(); | ||
1542 | |||
1543 | out_free_fasync: | ||
1544 | if (new) | ||
1545 | fasync_free(new); | ||
1546 | return error; | ||
1547 | } | ||
1548 | |||
1481 | /** | 1549 | /** |
1482 | * fcntl_setlease - sets a lease on an open file | 1550 | * fcntl_setlease - sets a lease on an open file |
1483 | * @fd: open file descriptor | 1551 | * @fd: open file descriptor |
@@ -1490,34 +1558,9 @@ EXPORT_SYMBOL_GPL(vfs_setlease); | |||
1490 | */ | 1558 | */ |
1491 | int fcntl_setlease(unsigned int fd, struct file *filp, long arg) | 1559 | int fcntl_setlease(unsigned int fd, struct file *filp, long arg) |
1492 | { | 1560 | { |
1493 | struct file_lock fl, *flp = &fl; | 1561 | if (arg == F_UNLCK) |
1494 | struct inode *inode = filp->f_path.dentry->d_inode; | 1562 | return do_fcntl_delete_lease(filp); |
1495 | int error; | 1563 | return do_fcntl_add_lease(fd, filp, arg); |
1496 | |||
1497 | locks_init_lock(&fl); | ||
1498 | error = lease_init(filp, arg, &fl); | ||
1499 | if (error) | ||
1500 | return error; | ||
1501 | |||
1502 | lock_kernel(); | ||
1503 | |||
1504 | error = vfs_setlease(filp, arg, &flp); | ||
1505 | if (error || arg == F_UNLCK) | ||
1506 | goto out_unlock; | ||
1507 | |||
1508 | error = fasync_helper(fd, filp, 1, &flp->fl_fasync); | ||
1509 | if (error < 0) { | ||
1510 | /* remove lease just inserted by setlease */ | ||
1511 | flp->fl_type = F_UNLCK | F_INPROGRESS; | ||
1512 | flp->fl_break_time = jiffies - 10; | ||
1513 | time_out_leases(inode); | ||
1514 | goto out_unlock; | ||
1515 | } | ||
1516 | |||
1517 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); | ||
1518 | out_unlock: | ||
1519 | unlock_kernel(); | ||
1520 | return error; | ||
1521 | } | 1564 | } |
1522 | 1565 | ||
1523 | /** | 1566 | /** |
@@ -2020,7 +2063,7 @@ void locks_remove_flock(struct file *filp) | |||
2020 | fl.fl_ops->fl_release_private(&fl); | 2063 | fl.fl_ops->fl_release_private(&fl); |
2021 | } | 2064 | } |
2022 | 2065 | ||
2023 | lock_kernel(); | 2066 | lock_flocks(); |
2024 | before = &inode->i_flock; | 2067 | before = &inode->i_flock; |
2025 | 2068 | ||
2026 | while ((fl = *before) != NULL) { | 2069 | while ((fl = *before) != NULL) { |
@@ -2038,7 +2081,7 @@ void locks_remove_flock(struct file *filp) | |||
2038 | } | 2081 | } |
2039 | before = &fl->fl_next; | 2082 | before = &fl->fl_next; |
2040 | } | 2083 | } |
2041 | unlock_kernel(); | 2084 | unlock_flocks(); |
2042 | } | 2085 | } |
2043 | 2086 | ||
2044 | /** | 2087 | /** |
@@ -2053,12 +2096,12 @@ posix_unblock_lock(struct file *filp, struct file_lock *waiter) | |||
2053 | { | 2096 | { |
2054 | int status = 0; | 2097 | int status = 0; |
2055 | 2098 | ||
2056 | lock_kernel(); | 2099 | lock_flocks(); |
2057 | if (waiter->fl_next) | 2100 | if (waiter->fl_next) |
2058 | __locks_delete_block(waiter); | 2101 | __locks_delete_block(waiter); |
2059 | else | 2102 | else |
2060 | status = -ENOENT; | 2103 | status = -ENOENT; |
2061 | unlock_kernel(); | 2104 | unlock_flocks(); |
2062 | return status; | 2105 | return status; |
2063 | } | 2106 | } |
2064 | 2107 | ||
@@ -2085,7 +2128,7 @@ EXPORT_SYMBOL_GPL(vfs_cancel_lock); | |||
2085 | #include <linux/seq_file.h> | 2128 | #include <linux/seq_file.h> |
2086 | 2129 | ||
2087 | static void lock_get_status(struct seq_file *f, struct file_lock *fl, | 2130 | static void lock_get_status(struct seq_file *f, struct file_lock *fl, |
2088 | int id, char *pfx) | 2131 | loff_t id, char *pfx) |
2089 | { | 2132 | { |
2090 | struct inode *inode = NULL; | 2133 | struct inode *inode = NULL; |
2091 | unsigned int fl_pid; | 2134 | unsigned int fl_pid; |
@@ -2098,7 +2141,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, | |||
2098 | if (fl->fl_file != NULL) | 2141 | if (fl->fl_file != NULL) |
2099 | inode = fl->fl_file->f_path.dentry->d_inode; | 2142 | inode = fl->fl_file->f_path.dentry->d_inode; |
2100 | 2143 | ||
2101 | seq_printf(f, "%d:%s ", id, pfx); | 2144 | seq_printf(f, "%lld:%s ", id, pfx); |
2102 | if (IS_POSIX(fl)) { | 2145 | if (IS_POSIX(fl)) { |
2103 | seq_printf(f, "%6s %s ", | 2146 | seq_printf(f, "%6s %s ", |
2104 | (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", | 2147 | (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", |
@@ -2161,30 +2204,33 @@ static int locks_show(struct seq_file *f, void *v) | |||
2161 | 2204 | ||
2162 | fl = list_entry(v, struct file_lock, fl_link); | 2205 | fl = list_entry(v, struct file_lock, fl_link); |
2163 | 2206 | ||
2164 | lock_get_status(f, fl, (long)f->private, ""); | 2207 | lock_get_status(f, fl, *((loff_t *)f->private), ""); |
2165 | 2208 | ||
2166 | list_for_each_entry(bfl, &fl->fl_block, fl_block) | 2209 | list_for_each_entry(bfl, &fl->fl_block, fl_block) |
2167 | lock_get_status(f, bfl, (long)f->private, " ->"); | 2210 | lock_get_status(f, bfl, *((loff_t *)f->private), " ->"); |
2168 | 2211 | ||
2169 | f->private++; | ||
2170 | return 0; | 2212 | return 0; |
2171 | } | 2213 | } |
2172 | 2214 | ||
2173 | static void *locks_start(struct seq_file *f, loff_t *pos) | 2215 | static void *locks_start(struct seq_file *f, loff_t *pos) |
2174 | { | 2216 | { |
2175 | lock_kernel(); | 2217 | loff_t *p = f->private; |
2176 | f->private = (void *)1; | 2218 | |
2219 | lock_flocks(); | ||
2220 | *p = (*pos + 1); | ||
2177 | return seq_list_start(&file_lock_list, *pos); | 2221 | return seq_list_start(&file_lock_list, *pos); |
2178 | } | 2222 | } |
2179 | 2223 | ||
2180 | static void *locks_next(struct seq_file *f, void *v, loff_t *pos) | 2224 | static void *locks_next(struct seq_file *f, void *v, loff_t *pos) |
2181 | { | 2225 | { |
2226 | loff_t *p = f->private; | ||
2227 | ++*p; | ||
2182 | return seq_list_next(v, &file_lock_list, pos); | 2228 | return seq_list_next(v, &file_lock_list, pos); |
2183 | } | 2229 | } |
2184 | 2230 | ||
2185 | static void locks_stop(struct seq_file *f, void *v) | 2231 | static void locks_stop(struct seq_file *f, void *v) |
2186 | { | 2232 | { |
2187 | unlock_kernel(); | 2233 | unlock_flocks(); |
2188 | } | 2234 | } |
2189 | 2235 | ||
2190 | static const struct seq_operations locks_seq_operations = { | 2236 | static const struct seq_operations locks_seq_operations = { |
@@ -2196,14 +2242,14 @@ static const struct seq_operations locks_seq_operations = { | |||
2196 | 2242 | ||
2197 | static int locks_open(struct inode *inode, struct file *filp) | 2243 | static int locks_open(struct inode *inode, struct file *filp) |
2198 | { | 2244 | { |
2199 | return seq_open(filp, &locks_seq_operations); | 2245 | return seq_open_private(filp, &locks_seq_operations, sizeof(loff_t)); |
2200 | } | 2246 | } |
2201 | 2247 | ||
2202 | static const struct file_operations proc_locks_operations = { | 2248 | static const struct file_operations proc_locks_operations = { |
2203 | .open = locks_open, | 2249 | .open = locks_open, |
2204 | .read = seq_read, | 2250 | .read = seq_read, |
2205 | .llseek = seq_lseek, | 2251 | .llseek = seq_lseek, |
2206 | .release = seq_release, | 2252 | .release = seq_release_private, |
2207 | }; | 2253 | }; |
2208 | 2254 | ||
2209 | static int __init proc_locks_init(void) | 2255 | static int __init proc_locks_init(void) |
@@ -2231,7 +2277,7 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len) | |||
2231 | { | 2277 | { |
2232 | struct file_lock *fl; | 2278 | struct file_lock *fl; |
2233 | int result = 1; | 2279 | int result = 1; |
2234 | lock_kernel(); | 2280 | lock_flocks(); |
2235 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 2281 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
2236 | if (IS_POSIX(fl)) { | 2282 | if (IS_POSIX(fl)) { |
2237 | if (fl->fl_type == F_RDLCK) | 2283 | if (fl->fl_type == F_RDLCK) |
@@ -2248,7 +2294,7 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len) | |||
2248 | result = 0; | 2294 | result = 0; |
2249 | break; | 2295 | break; |
2250 | } | 2296 | } |
2251 | unlock_kernel(); | 2297 | unlock_flocks(); |
2252 | return result; | 2298 | return result; |
2253 | } | 2299 | } |
2254 | 2300 | ||
@@ -2271,7 +2317,7 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) | |||
2271 | { | 2317 | { |
2272 | struct file_lock *fl; | 2318 | struct file_lock *fl; |
2273 | int result = 1; | 2319 | int result = 1; |
2274 | lock_kernel(); | 2320 | lock_flocks(); |
2275 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 2321 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
2276 | if (IS_POSIX(fl)) { | 2322 | if (IS_POSIX(fl)) { |
2277 | if ((fl->fl_end < start) || (fl->fl_start > (start + len))) | 2323 | if ((fl->fl_end < start) || (fl->fl_start > (start + len))) |
@@ -2286,7 +2332,7 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) | |||
2286 | result = 0; | 2332 | result = 0; |
2287 | break; | 2333 | break; |
2288 | } | 2334 | } |
2289 | unlock_kernel(); | 2335 | unlock_flocks(); |
2290 | return result; | 2336 | return result; |
2291 | } | 2337 | } |
2292 | 2338 | ||