aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMarc Eshel <eshel@almaden.ibm.com>2007-02-21 00:55:18 -0500
committerJ. Bruce Fields <bfields@citi.umich.edu>2007-05-06 17:39:00 -0400
commit9d6a8c5c213e34c475e72b245a8eb709258e968c (patch)
tree96110535c2bd9485129c0753a9e0f012083b220f /fs
parent70cc6487a4e08b8698c0e2ec935fb48d10490162 (diff)
locks: give posix_test_lock same interface as ->lock
posix_test_lock() and ->lock() do the same job but have gratuitously different interfaces. Modify posix_test_lock() so the two agree, simplifying some code in the process. Signed-off-by: Marc Eshel <eshel@almaden.ibm.com> Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
Diffstat (limited to 'fs')
-rw-r--r--fs/fuse/file.c3
-rw-r--r--fs/gfs2/locking/nolock/main.c8
-rw-r--r--fs/gfs2/ops_file.c7
-rw-r--r--fs/lockd/svclock.c13
-rw-r--r--fs/locks.c37
-rw-r--r--fs/nfs/file.c7
-rw-r--r--fs/nfsd/nfs4state.c6
7 files changed, 31 insertions, 50 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 2fd06927e851..acfad65a6e8e 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -738,8 +738,7 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
738 738
739 if (cmd == F_GETLK) { 739 if (cmd == F_GETLK) {
740 if (fc->no_lock) { 740 if (fc->no_lock) {
741 if (!posix_test_lock(file, fl, fl)) 741 posix_test_lock(file, fl);
742 fl->fl_type = F_UNLCK;
743 err = 0; 742 err = 0;
744 } else 743 } else
745 err = fuse_getlk(file, fl); 744 err = fuse_getlk(file, fl);
diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c
index acfbc941f319..5cc1dfa7944a 100644
--- a/fs/gfs2/locking/nolock/main.c
+++ b/fs/gfs2/locking/nolock/main.c
@@ -164,13 +164,7 @@ static void nolock_unhold_lvb(void *lock, char *lvb)
164static int nolock_plock_get(void *lockspace, struct lm_lockname *name, 164static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
165 struct file *file, struct file_lock *fl) 165 struct file *file, struct file_lock *fl)
166{ 166{
167 struct file_lock tmp; 167 posix_test_lock(file, fl);
168 int ret;
169
170 ret = posix_test_lock(file, fl, &tmp);
171 fl->fl_type = F_UNLCK;
172 if (ret)
173 memcpy(fl, &tmp, sizeof(struct file_lock));
174 168
175 return 0; 169 return 0;
176} 170}
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index b50180e22779..48b248d7c823 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -513,12 +513,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
513 513
514 if (sdp->sd_args.ar_localflocks) { 514 if (sdp->sd_args.ar_localflocks) {
515 if (IS_GETLK(cmd)) { 515 if (IS_GETLK(cmd)) {
516 struct file_lock tmp; 516 posix_test_lock(file, fl);
517 int ret;
518 ret = posix_test_lock(file, fl, &tmp);
519 fl->fl_type = F_UNLCK;
520 if (ret)
521 memcpy(fl, &tmp, sizeof(struct file_lock));
522 return 0; 517 return 0;
523 } else { 518 } else {
524 return posix_lock_file_wait(file, fl); 519 return posix_lock_file_wait(file, fl);
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index cf51f849e76c..97b0160ef10f 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -426,15 +426,18 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
426 (long long)lock->fl.fl_start, 426 (long long)lock->fl.fl_start,
427 (long long)lock->fl.fl_end); 427 (long long)lock->fl.fl_end);
428 428
429 if (posix_test_lock(file->f_file, &lock->fl, &conflock->fl)) { 429 if (posix_test_lock(file->f_file, &lock->fl)) {
430 dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n", 430 dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
431 conflock->fl.fl_type, 431 lock->fl.fl_type,
432 (long long)conflock->fl.fl_start, 432 (long long)lock->fl.fl_start,
433 (long long)conflock->fl.fl_end); 433 (long long)lock->fl.fl_end);
434 conflock->caller = "somehost"; /* FIXME */ 434 conflock->caller = "somehost"; /* FIXME */
435 conflock->len = strlen(conflock->caller); 435 conflock->len = strlen(conflock->caller);
436 conflock->oh.len = 0; /* don't return OH info */ 436 conflock->oh.len = 0; /* don't return OH info */
437 conflock->svid = conflock->fl.fl_pid; 437 conflock->svid = lock->fl.fl_pid;
438 conflock->fl.fl_type = lock->fl.fl_type;
439 conflock->fl.fl_start = lock->fl.fl_start;
440 conflock->fl.fl_end = lock->fl.fl_end;
438 return nlm_lck_denied; 441 return nlm_lck_denied;
439 } 442 }
440 443
diff --git a/fs/locks.c b/fs/locks.c
index b07e6e6f819b..749a0dc7cd4b 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -666,11 +666,11 @@ static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *w
666} 666}
667 667
668int 668int
669posix_test_lock(struct file *filp, struct file_lock *fl, 669posix_test_lock(struct file *filp, struct file_lock *fl)
670 struct file_lock *conflock)
671{ 670{
672 struct file_lock *cfl; 671 struct file_lock *cfl;
673 672
673 fl->fl_type = F_UNLCK;
674 lock_kernel(); 674 lock_kernel();
675 for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { 675 for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
676 if (!IS_POSIX(cfl)) 676 if (!IS_POSIX(cfl))
@@ -679,7 +679,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl,
679 break; 679 break;
680 } 680 }
681 if (cfl) { 681 if (cfl) {
682 __locks_copy_lock(conflock, cfl); 682 __locks_copy_lock(fl, cfl);
683 unlock_kernel(); 683 unlock_kernel();
684 return 1; 684 return 1;
685 } 685 }
@@ -1648,7 +1648,7 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
1648 */ 1648 */
1649int fcntl_getlk(struct file *filp, struct flock __user *l) 1649int fcntl_getlk(struct file *filp, struct flock __user *l)
1650{ 1650{
1651 struct file_lock *fl, cfl, file_lock; 1651 struct file_lock file_lock;
1652 struct flock flock; 1652 struct flock flock;
1653 int error; 1653 int error;
1654 1654
@@ -1667,15 +1667,12 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
1667 error = filp->f_op->lock(filp, F_GETLK, &file_lock); 1667 error = filp->f_op->lock(filp, F_GETLK, &file_lock);
1668 if (error < 0) 1668 if (error < 0)
1669 goto out; 1669 goto out;
1670 else 1670 } else
1671 fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock); 1671 posix_test_lock(filp, &file_lock);
1672 } else {
1673 fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
1674 }
1675 1672
1676 flock.l_type = F_UNLCK; 1673 flock.l_type = file_lock.fl_type;
1677 if (fl != NULL) { 1674 if (file_lock.fl_type != F_UNLCK) {
1678 error = posix_lock_to_flock(&flock, fl); 1675 error = posix_lock_to_flock(&flock, &file_lock);
1679 if (error) 1676 if (error)
1680 goto out; 1677 goto out;
1681 } 1678 }
@@ -1785,7 +1782,7 @@ out:
1785 */ 1782 */
1786int fcntl_getlk64(struct file *filp, struct flock64 __user *l) 1783int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
1787{ 1784{
1788 struct file_lock *fl, cfl, file_lock; 1785 struct file_lock file_lock;
1789 struct flock64 flock; 1786 struct flock64 flock;
1790 int error; 1787 int error;
1791 1788
@@ -1804,15 +1801,13 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
1804 error = filp->f_op->lock(filp, F_GETLK, &file_lock); 1801 error = filp->f_op->lock(filp, F_GETLK, &file_lock);
1805 if (error < 0) 1802 if (error < 0)
1806 goto out; 1803 goto out;
1807 else 1804 } else
1808 fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock); 1805 posix_test_lock(filp, &file_lock);
1809 } else {
1810 fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
1811 }
1812 1806
1813 flock.l_type = F_UNLCK; 1807 flock.l_type = file_lock.fl_type;
1814 if (fl != NULL) 1808 if (file_lock.fl_type != F_UNLCK)
1815 posix_lock_to_flock64(&flock, fl); 1809 posix_lock_to_flock64(&flock, &file_lock);
1810
1816 error = -EFAULT; 1811 error = -EFAULT;
1817 if (!copy_to_user(l, &flock, sizeof(flock))) 1812 if (!copy_to_user(l, &flock, sizeof(flock)))
1818 error = 0; 1813 error = 0;
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 8e66b5a2d490..5eaee6dd040b 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -391,17 +391,12 @@ out_swapfile:
391 391
392static int do_getlk(struct file *filp, int cmd, struct file_lock *fl) 392static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
393{ 393{
394 struct file_lock cfl;
395 struct inode *inode = filp->f_mapping->host; 394 struct inode *inode = filp->f_mapping->host;
396 int status = 0; 395 int status = 0;
397 396
398 lock_kernel(); 397 lock_kernel();
399 /* Try local locking first */ 398 /* Try local locking first */
400 if (posix_test_lock(filp, fl, &cfl)) { 399 if (posix_test_lock(filp, fl)) {
401 fl->fl_start = cfl.fl_start;
402 fl->fl_end = cfl.fl_end;
403 fl->fl_type = cfl.fl_type;
404 fl->fl_pid = cfl.fl_pid;
405 goto out; 400 goto out;
406 } 401 }
407 402
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index af360705e551..e42c7a0eb6fa 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2813,7 +2813,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2813 struct inode *inode; 2813 struct inode *inode;
2814 struct file file; 2814 struct file file;
2815 struct file_lock file_lock; 2815 struct file_lock file_lock;
2816 struct file_lock conflock;
2817 __be32 status; 2816 __be32 status;
2818 2817
2819 if (nfs4_in_grace()) 2818 if (nfs4_in_grace())
@@ -2878,9 +2877,10 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2878 file.f_path.dentry = cstate->current_fh.fh_dentry; 2877 file.f_path.dentry = cstate->current_fh.fh_dentry;
2879 2878
2880 status = nfs_ok; 2879 status = nfs_ok;
2881 if (posix_test_lock(&file, &file_lock, &conflock)) { 2880 posix_test_lock(&file, &file_lock);
2881 if (file_lock.fl_type != F_UNLCK) {
2882 status = nfserr_denied; 2882 status = nfserr_denied;
2883 nfs4_set_lock_denied(&conflock, &lockt->lt_denied); 2883 nfs4_set_lock_denied(&file_lock, &lockt->lt_denied);
2884 } 2884 }
2885out: 2885out:
2886 nfs4_unlock_state(); 2886 nfs4_unlock_state();