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