aboutsummaryrefslogtreecommitdiffstats
path: root/fs/locks.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/locks.c')
-rw-r--r--fs/locks.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/fs/locks.c b/fs/locks.c
index eb463257f867..c0f789dfa655 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1292,7 +1292,7 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
1292} 1292}
1293 1293
1294/* We already had a lease on this file; just change its type */ 1294/* We already had a lease on this file; just change its type */
1295int lease_modify(struct file_lock **before, int arg) 1295int lease_modify(struct file_lock **before, int arg, struct list_head *dispose)
1296{ 1296{
1297 struct file_lock *fl = *before; 1297 struct file_lock *fl = *before;
1298 int error = assign_type(fl, arg); 1298 int error = assign_type(fl, arg);
@@ -1311,7 +1311,7 @@ int lease_modify(struct file_lock **before, int arg)
1311 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); 1311 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
1312 fl->fl_fasync = NULL; 1312 fl->fl_fasync = NULL;
1313 } 1313 }
1314 locks_delete_lock(before, NULL); 1314 locks_delete_lock(before, dispose);
1315 } 1315 }
1316 return 0; 1316 return 0;
1317} 1317}
@@ -1325,7 +1325,7 @@ static bool past_time(unsigned long then)
1325 return time_after(jiffies, then); 1325 return time_after(jiffies, then);
1326} 1326}
1327 1327
1328static void time_out_leases(struct inode *inode) 1328static void time_out_leases(struct inode *inode, struct list_head *dispose)
1329{ 1329{
1330 struct file_lock **before; 1330 struct file_lock **before;
1331 struct file_lock *fl; 1331 struct file_lock *fl;
@@ -1336,9 +1336,9 @@ static void time_out_leases(struct inode *inode)
1336 while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) { 1336 while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) {
1337 trace_time_out_leases(inode, fl); 1337 trace_time_out_leases(inode, fl);
1338 if (past_time(fl->fl_downgrade_time)) 1338 if (past_time(fl->fl_downgrade_time))
1339 lease_modify(before, F_RDLCK); 1339 lease_modify(before, F_RDLCK, dispose);
1340 if (past_time(fl->fl_break_time)) 1340 if (past_time(fl->fl_break_time))
1341 lease_modify(before, F_UNLCK); 1341 lease_modify(before, F_UNLCK, dispose);
1342 if (fl == *before) /* lease_modify may have freed fl */ 1342 if (fl == *before) /* lease_modify may have freed fl */
1343 before = &fl->fl_next; 1343 before = &fl->fl_next;
1344 } 1344 }
@@ -1373,6 +1373,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1373 int i_have_this_lease = 0; 1373 int i_have_this_lease = 0;
1374 bool lease_conflict = false; 1374 bool lease_conflict = false;
1375 int want_write = (mode & O_ACCMODE) != O_RDONLY; 1375 int want_write = (mode & O_ACCMODE) != O_RDONLY;
1376 LIST_HEAD(dispose);
1376 1377
1377 new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK); 1378 new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
1378 if (IS_ERR(new_fl)) 1379 if (IS_ERR(new_fl))
@@ -1381,7 +1382,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1381 1382
1382 spin_lock(&inode->i_lock); 1383 spin_lock(&inode->i_lock);
1383 1384
1384 time_out_leases(inode); 1385 time_out_leases(inode, &dispose);
1385 1386
1386 flock = inode->i_flock; 1387 flock = inode->i_flock;
1387 if ((flock == NULL) || !IS_LEASE(flock)) 1388 if ((flock == NULL) || !IS_LEASE(flock))
@@ -1436,6 +1437,7 @@ restart:
1436 locks_insert_block(flock, new_fl); 1437 locks_insert_block(flock, new_fl);
1437 trace_break_lease_block(inode, new_fl); 1438 trace_break_lease_block(inode, new_fl);
1438 spin_unlock(&inode->i_lock); 1439 spin_unlock(&inode->i_lock);
1440 locks_dispose_list(&dispose);
1439 error = wait_event_interruptible_timeout(new_fl->fl_wait, 1441 error = wait_event_interruptible_timeout(new_fl->fl_wait,
1440 !new_fl->fl_next, break_time); 1442 !new_fl->fl_next, break_time);
1441 spin_lock(&inode->i_lock); 1443 spin_lock(&inode->i_lock);
@@ -1443,7 +1445,7 @@ restart:
1443 locks_delete_block(new_fl); 1445 locks_delete_block(new_fl);
1444 if (error >= 0) { 1446 if (error >= 0) {
1445 if (error == 0) 1447 if (error == 0)
1446 time_out_leases(inode); 1448 time_out_leases(inode, &dispose);
1447 /* 1449 /*
1448 * Wait for the next conflicting lease that has not been 1450 * Wait for the next conflicting lease that has not been
1449 * broken yet 1451 * broken yet
@@ -1458,6 +1460,7 @@ restart:
1458 1460
1459out: 1461out:
1460 spin_unlock(&inode->i_lock); 1462 spin_unlock(&inode->i_lock);
1463 locks_dispose_list(&dispose);
1461 locks_free_lock(new_fl); 1464 locks_free_lock(new_fl);
1462 return error; 1465 return error;
1463} 1466}
@@ -1522,9 +1525,10 @@ int fcntl_getlease(struct file *filp)
1522 struct file_lock *fl; 1525 struct file_lock *fl;
1523 struct inode *inode = file_inode(filp); 1526 struct inode *inode = file_inode(filp);
1524 int type = F_UNLCK; 1527 int type = F_UNLCK;
1528 LIST_HEAD(dispose);
1525 1529
1526 spin_lock(&inode->i_lock); 1530 spin_lock(&inode->i_lock);
1527 time_out_leases(file_inode(filp)); 1531 time_out_leases(file_inode(filp), &dispose);
1528 for (fl = file_inode(filp)->i_flock; fl && IS_LEASE(fl); 1532 for (fl = file_inode(filp)->i_flock; fl && IS_LEASE(fl);
1529 fl = fl->fl_next) { 1533 fl = fl->fl_next) {
1530 if (fl->fl_file == filp) { 1534 if (fl->fl_file == filp) {
@@ -1533,6 +1537,7 @@ int fcntl_getlease(struct file *filp)
1533 } 1537 }
1534 } 1538 }
1535 spin_unlock(&inode->i_lock); 1539 spin_unlock(&inode->i_lock);
1540 locks_dispose_list(&dispose);
1536 return type; 1541 return type;
1537} 1542}
1538 1543
@@ -1570,6 +1575,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1570 struct inode *inode = dentry->d_inode; 1575 struct inode *inode = dentry->d_inode;
1571 bool is_deleg = (*flp)->fl_flags & FL_DELEG; 1576 bool is_deleg = (*flp)->fl_flags & FL_DELEG;
1572 int error; 1577 int error;
1578 LIST_HEAD(dispose);
1573 1579
1574 lease = *flp; 1580 lease = *flp;
1575 trace_generic_add_lease(inode, lease); 1581 trace_generic_add_lease(inode, lease);
@@ -1593,7 +1599,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1593 } 1599 }
1594 1600
1595 spin_lock(&inode->i_lock); 1601 spin_lock(&inode->i_lock);
1596 time_out_leases(inode); 1602 time_out_leases(inode, &dispose);
1597 error = check_conflicting_open(dentry, arg); 1603 error = check_conflicting_open(dentry, arg);
1598 if (error) 1604 if (error)
1599 goto out; 1605 goto out;
@@ -1630,7 +1636,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1630 1636
1631 if (my_before != NULL) { 1637 if (my_before != NULL) {
1632 lease = *my_before; 1638 lease = *my_before;
1633 error = lease->fl_lmops->lm_change(my_before, arg); 1639 error = lease->fl_lmops->lm_change(my_before, arg, &dispose);
1634 if (error) 1640 if (error)
1635 goto out; 1641 goto out;
1636 goto out_setup; 1642 goto out_setup;
@@ -1660,6 +1666,7 @@ out_setup:
1660 lease->fl_lmops->lm_setup(lease, priv); 1666 lease->fl_lmops->lm_setup(lease, priv);
1661out: 1667out:
1662 spin_unlock(&inode->i_lock); 1668 spin_unlock(&inode->i_lock);
1669 locks_dispose_list(&dispose);
1663 if (is_deleg) 1670 if (is_deleg)
1664 mutex_unlock(&inode->i_mutex); 1671 mutex_unlock(&inode->i_mutex);
1665 if (!error && !my_before) 1672 if (!error && !my_before)
@@ -1676,8 +1683,10 @@ static int generic_delete_lease(struct file *filp)
1676 struct file_lock *fl, **before; 1683 struct file_lock *fl, **before;
1677 struct dentry *dentry = filp->f_path.dentry; 1684 struct dentry *dentry = filp->f_path.dentry;
1678 struct inode *inode = dentry->d_inode; 1685 struct inode *inode = dentry->d_inode;
1686 LIST_HEAD(dispose);
1679 1687
1680 spin_lock(&inode->i_lock); 1688 spin_lock(&inode->i_lock);
1689 time_out_leases(inode, &dispose);
1681 for (before = &inode->i_flock; 1690 for (before = &inode->i_flock;
1682 ((fl = *before) != NULL) && IS_LEASE(fl); 1691 ((fl = *before) != NULL) && IS_LEASE(fl);
1683 before = &fl->fl_next) { 1692 before = &fl->fl_next) {
@@ -1686,8 +1695,9 @@ static int generic_delete_lease(struct file *filp)
1686 } 1695 }
1687 trace_generic_delete_lease(inode, fl); 1696 trace_generic_delete_lease(inode, fl);
1688 if (fl) 1697 if (fl)
1689 error = fl->fl_lmops->lm_change(before, F_UNLCK); 1698 error = fl->fl_lmops->lm_change(before, F_UNLCK, &dispose);
1690 spin_unlock(&inode->i_lock); 1699 spin_unlock(&inode->i_lock);
1700 locks_dispose_list(&dispose);
1691 return error; 1701 return error;
1692} 1702}
1693 1703
@@ -2372,7 +2382,7 @@ void locks_remove_file(struct file *filp)
2372 while ((fl = *before) != NULL) { 2382 while ((fl = *before) != NULL) {
2373 if (fl->fl_file == filp) { 2383 if (fl->fl_file == filp) {
2374 if (IS_LEASE(fl)) { 2384 if (IS_LEASE(fl)) {
2375 lease_modify(before, F_UNLCK); 2385 lease_modify(before, F_UNLCK, &dispose);
2376 continue; 2386 continue;
2377 } 2387 }
2378 2388