locks: give posix_test_lock same interface as ->lock
authorMarc Eshel <eshel@almaden.ibm.com>
Wed, 21 Feb 2007 05:55:18 +0000 (00:55 -0500)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Sun, 6 May 2007 21:39:00 +0000 (17:39 -0400)
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>
fs/fuse/file.c
fs/gfs2/locking/nolock/main.c
fs/gfs2/ops_file.c
fs/lockd/svclock.c
fs/locks.c
fs/nfs/file.c
fs/nfsd/nfs4state.c
include/linux/fs.h

index 2fd06927e851674e14968cda55898ec832ab2ac0..acfad65a6e8e20b5f2a0af9821e4281df74e33b0 100644 (file)
@@ -738,8 +738,7 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
 
        if (cmd == F_GETLK) {
                if (fc->no_lock) {
-                       if (!posix_test_lock(file, fl, fl))
-                               fl->fl_type = F_UNLCK;
+                       posix_test_lock(file, fl);
                        err = 0;
                } else
                        err = fuse_getlk(file, fl);
index acfbc941f31950c87323928cd6d48d82082f2685..5cc1dfa7944a2ee3ff9f14c4f6447768063dfc22 100644 (file)
@@ -164,13 +164,7 @@ static void nolock_unhold_lvb(void *lock, char *lvb)
 static int nolock_plock_get(void *lockspace, struct lm_lockname *name,
                            struct file *file, struct file_lock *fl)
 {
-       struct file_lock tmp;
-       int ret;
-
-       ret = posix_test_lock(file, fl, &tmp);
-       fl->fl_type = F_UNLCK;
-       if (ret)
-               memcpy(fl, &tmp, sizeof(struct file_lock));
+       posix_test_lock(file, fl);
 
        return 0;
 }
index b50180e227790115f0e6b12570b0c9bedc14614c..48b248d7c8235b7991e6cbdbf7914f3959eb12a0 100644 (file)
@@ -513,12 +513,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
 
        if (sdp->sd_args.ar_localflocks) {
                if (IS_GETLK(cmd)) {
-                       struct file_lock tmp;
-                       int ret;
-                       ret = posix_test_lock(file, fl, &tmp);
-                       fl->fl_type = F_UNLCK;
-                       if (ret)
-                               memcpy(fl, &tmp, sizeof(struct file_lock));
+                       posix_test_lock(file, fl);
                        return 0;
                } else {
                        return posix_lock_file_wait(file, fl);
index cf51f849e76c86732af645b5ab79ea12a002b021..97b0160ef10ffa25e1ba72223c7f55d8d29b3fb0 100644 (file)
@@ -426,15 +426,18 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end);
 
-       if (posix_test_lock(file->f_file, &lock->fl, &conflock->fl)) {
+       if (posix_test_lock(file->f_file, &lock->fl)) {
                dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
-                               conflock->fl.fl_type,
-                               (long long)conflock->fl.fl_start,
-                               (long long)conflock->fl.fl_end);
+                               lock->fl.fl_type,
+                               (long long)lock->fl.fl_start,
+                               (long long)lock->fl.fl_end);
                conflock->caller = "somehost";  /* FIXME */
                conflock->len = strlen(conflock->caller);
                conflock->oh.len = 0;           /* don't return OH info */
-               conflock->svid = conflock->fl.fl_pid;
+               conflock->svid = lock->fl.fl_pid;
+               conflock->fl.fl_type = lock->fl.fl_type;
+               conflock->fl.fl_start = lock->fl.fl_start;
+               conflock->fl.fl_end = lock->fl.fl_end;
                return nlm_lck_denied;
        }
 
index b07e6e6f819b62e2d944f800046591cd00acd928..749a0dc7cd4b674cdd974ec8ee02e271923d5401 100644 (file)
@@ -666,11 +666,11 @@ static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *w
 }
 
 int
-posix_test_lock(struct file *filp, struct file_lock *fl,
-               struct file_lock *conflock)
+posix_test_lock(struct file *filp, struct file_lock *fl)
 {
        struct file_lock *cfl;
 
+       fl->fl_type = F_UNLCK;
        lock_kernel();
        for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
                if (!IS_POSIX(cfl))
@@ -679,7 +679,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl,
                        break;
        }
        if (cfl) {
-               __locks_copy_lock(conflock, cfl);
+               __locks_copy_lock(fl, cfl);
                unlock_kernel();
                return 1;
        }
@@ -1648,7 +1648,7 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
  */
 int fcntl_getlk(struct file *filp, struct flock __user *l)
 {
-       struct file_lock *fl, cfl, file_lock;
+       struct file_lock file_lock;
        struct flock flock;
        int error;
 
@@ -1667,15 +1667,12 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
                error = filp->f_op->lock(filp, F_GETLK, &file_lock);
                if (error < 0)
                        goto out;
-               else
-                 fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock);
-       } else {
-               fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
-       }
+       } else
+               posix_test_lock(filp, &file_lock);
  
-       flock.l_type = F_UNLCK;
-       if (fl != NULL) {
-               error = posix_lock_to_flock(&flock, fl);
+       flock.l_type = file_lock.fl_type;
+       if (file_lock.fl_type != F_UNLCK) {
+               error = posix_lock_to_flock(&flock, &file_lock);
                if (error)
                        goto out;
        }
@@ -1785,7 +1782,7 @@ out:
  */
 int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
 {
-       struct file_lock *fl, cfl, file_lock;
+       struct file_lock file_lock;
        struct flock64 flock;
        int error;
 
@@ -1804,15 +1801,13 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
                error = filp->f_op->lock(filp, F_GETLK, &file_lock);
                if (error < 0)
                        goto out;
-               else
-                 fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock);
-       } else {
-               fl = (posix_test_lock(filp, &file_lock, &cfl) ? &cfl : NULL);
-       }
+       } else
+               posix_test_lock(filp, &file_lock);
  
-       flock.l_type = F_UNLCK;
-       if (fl != NULL)
-               posix_lock_to_flock64(&flock, fl);
+       flock.l_type = file_lock.fl_type;
+       if (file_lock.fl_type != F_UNLCK)
+               posix_lock_to_flock64(&flock, &file_lock);
+
        error = -EFAULT;
        if (!copy_to_user(l, &flock, sizeof(flock)))
                error = 0;
index 8e66b5a2d490129bb918a10ecf5e811a7488783e..5eaee6dd040b95542cada17a8691e8b6b3b8fb85 100644 (file)
@@ -391,17 +391,12 @@ out_swapfile:
 
 static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
 {
-       struct file_lock cfl;
        struct inode *inode = filp->f_mapping->host;
        int status = 0;
 
        lock_kernel();
        /* Try local locking first */
-       if (posix_test_lock(filp, fl, &cfl)) {
-               fl->fl_start = cfl.fl_start;
-               fl->fl_end = cfl.fl_end;
-               fl->fl_type = cfl.fl_type;
-               fl->fl_pid = cfl.fl_pid;
+       if (posix_test_lock(filp, fl)) {
                goto out;
        }
 
index af360705e551afc5f9bf9954db7a2790aebca6cc..e42c7a0eb6facfd28fbf5acc16d903ebbda776b3 100644 (file)
@@ -2813,7 +2813,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        struct inode *inode;
        struct file file;
        struct file_lock file_lock;
-       struct file_lock conflock;
        __be32 status;
 
        if (nfs4_in_grace())
@@ -2878,9 +2877,10 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        file.f_path.dentry = cstate->current_fh.fh_dentry;
 
        status = nfs_ok;
-       if (posix_test_lock(&file, &file_lock, &conflock)) {
+       posix_test_lock(&file, &file_lock);
+       if (file_lock.fl_type != F_UNLCK) {
                status = nfserr_denied;
-               nfs4_set_lock_denied(&conflock, &lockt->lt_denied);
+               nfs4_set_lock_denied(&file_lock, &lockt->lt_denied);
        }
 out:
        nfs4_unlock_state();
index 86ec3f4a7da6ec0cc33825c6052c9bbe1c4dbf9a..9e1ddffe3884c6bf7687b26c2006de00e84ff846 100644 (file)
@@ -851,7 +851,7 @@ extern void locks_init_lock(struct file_lock *);
 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
 extern void locks_remove_posix(struct file *, fl_owner_t);
 extern void locks_remove_flock(struct file *);
-extern int posix_test_lock(struct file *, struct file_lock *, struct file_lock *);
+extern int posix_test_lock(struct file *, struct file_lock *);
 extern int posix_lock_file_conf(struct file *, struct file_lock *, struct file_lock *);
 extern int posix_lock_file(struct file *, struct file_lock *);
 extern int posix_lock_file_wait(struct file *, struct file_lock *);