aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2010-10-31 08:35:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-31 09:35:15 -0400
commit51ee4b84f5c86935b438d6636f34b523edb415a8 (patch)
treec60e0da8f8b6393477d79ef6d6ce321ee3b8ecaa /fs
parent96f935934591b72f5b05fd6923bc8cdcae92f2e5 (diff)
locks: let the caller free file_lock on ->setlease failure
The caller allocated it, the caller should free it. The only issue so far is that we could change the flp pointer even on an error return if the fl_change callback failed. But we can simply move the flp assignment after the fl_change invocation, as the callers don't care about the flp return value if the setlease call failed. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/cifsfs.c5
-rw-r--r--fs/gfs2/file.c2
-rw-r--r--fs/locks.c20
-rw-r--r--fs/nfs/file.c2
-rw-r--r--fs/nfsd/nfs4state.c1
5 files changed, 13 insertions, 17 deletions
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 54745b6c3db9..75c4eaa79588 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -625,11 +625,8 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
625 knows that the file won't be changed on the server 625 knows that the file won't be changed on the server
626 by anyone else */ 626 by anyone else */
627 return generic_setlease(file, arg, lease); 627 return generic_setlease(file, arg, lease);
628 else { 628 else
629 if (arg != F_UNLCK)
630 locks_free_lock(*lease);
631 return -EAGAIN; 629 return -EAGAIN;
632 }
633} 630}
634 631
635struct file_system_type cifs_fs_type = { 632struct file_system_type cifs_fs_type = {
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index ac943c1307b5..aa996471ec5c 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -629,8 +629,6 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
629 629
630static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) 630static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
631{ 631{
632 if (arg != F_UNLCK)
633 locks_free_lock(*fl);
634 return -EINVAL; 632 return -EINVAL;
635} 633}
636 634
diff --git a/fs/locks.c b/fs/locks.c
index 5b526a977882..a2ab790471b5 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1428,8 +1428,9 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1428 goto out; 1428 goto out;
1429 1429
1430 if (my_before != NULL) { 1430 if (my_before != NULL) {
1431 *flp = *my_before;
1432 error = lease->fl_lmops->fl_change(my_before, arg); 1431 error = lease->fl_lmops->fl_change(my_before, arg);
1432 if (!error)
1433 *flp = *my_before;
1433 goto out; 1434 goto out;
1434 } 1435 }
1435 1436
@@ -1444,8 +1445,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1444 return 0; 1445 return 0;
1445 1446
1446out: 1447out:
1447 if (arg != F_UNLCK)
1448 locks_free_lock(lease);
1449 return error; 1448 return error;
1450} 1449}
1451EXPORT_SYMBOL(generic_setlease); 1450EXPORT_SYMBOL(generic_setlease);
@@ -1524,8 +1523,11 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
1524 } 1523 }
1525 lock_flocks(); 1524 lock_flocks();
1526 error = __vfs_setlease(filp, arg, &fl); 1525 error = __vfs_setlease(filp, arg, &fl);
1527 if (error) 1526 if (error) {
1528 goto out_unlock; 1527 unlock_flocks();
1528 locks_free_lock(fl);
1529 goto out_free_fasync;
1530 }
1529 1531
1530 /* 1532 /*
1531 * fasync_insert_entry() returns the old entry if any. 1533 * fasync_insert_entry() returns the old entry if any.
@@ -1541,12 +1543,12 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
1541 fl->fl_type = F_UNLCK | F_INPROGRESS; 1543 fl->fl_type = F_UNLCK | F_INPROGRESS;
1542 fl->fl_break_time = jiffies - 10; 1544 fl->fl_break_time = jiffies - 10;
1543 time_out_leases(inode); 1545 time_out_leases(inode);
1544 goto out_unlock; 1546 } else {
1547 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
1545 } 1548 }
1546
1547 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
1548out_unlock:
1549 unlock_flocks(); 1549 unlock_flocks();
1550
1551out_free_fasync:
1550 if (new) 1552 if (new)
1551 fasync_free(new); 1553 fasync_free(new);
1552 return error; 1554 return error;
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 1e524fb73ba5..60677f9f1311 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -884,7 +884,5 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
884 dprintk("NFS: setlease(%s/%s, arg=%ld)\n", 884 dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
885 file->f_path.dentry->d_parent->d_name.name, 885 file->f_path.dentry->d_parent->d_name.name,
886 file->f_path.dentry->d_name.name, arg); 886 file->f_path.dentry->d_name.name, arg);
887 if (arg != F_UNLCK)
888 locks_free_lock(*fl);
889 return -EINVAL; 887 return -EINVAL;
890} 888}
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index b7f818b0580c..f1e5ec6b5105 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2652,6 +2652,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
2652 if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) { 2652 if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) {
2653 dprintk("NFSD: setlease failed [%d], no delegation\n", status); 2653 dprintk("NFSD: setlease failed [%d], no delegation\n", status);
2654 dp->dl_flock = NULL; 2654 dp->dl_flock = NULL;
2655 locks_free_lock(fl);
2655 unhash_delegation(dp); 2656 unhash_delegation(dp);
2656 flag = NFS4_OPEN_DELEGATE_NONE; 2657 flag = NFS4_OPEN_DELEGATE_NONE;
2657 goto out; 2658 goto out;