Merge tag 'net-next-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-2.6-microblaze.git] / fs / lockd / svclock.c
index bcd180b..e9b85d8 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/lockd/nlm.h>
 #include <linux/lockd/lockd.h>
 #include <linux/kthread.h>
+#include <linux/exportfs.h>
 
 #define NLMDBG_FACILITY                NLMDBG_SVCLOCK
 
@@ -470,17 +471,24 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
            struct nlm_cookie *cookie, int reclaim)
 {
        struct nlm_block        *block = NULL;
+       struct inode            *inode = nlmsvc_file_inode(file);
        int                     error;
+       int                     mode;
+       int                     async_block = 0;
        __be32                  ret;
 
        dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
-                               nlmsvc_file_inode(file)->i_sb->s_id,
-                               nlmsvc_file_inode(file)->i_ino,
+                               inode->i_sb->s_id, inode->i_ino,
                                lock->fl.fl_type, lock->fl.fl_pid,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end,
                                wait);
 
+       if (inode->i_sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS) {
+               async_block = wait;
+               wait = 0;
+       }
+
        /* Lock file against concurrent access */
        mutex_lock(&file->f_mutex);
        /* Get existing block (in case client is busy-waiting)
@@ -524,7 +532,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
 
        if (!wait)
                lock->fl.fl_flags &= ~FL_SLEEP;
-       error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
+       mode = lock_to_openmode(&lock->fl);
+       error = vfs_lock_file(file->f_file[mode], F_SETLK, &lock->fl, NULL);
        lock->fl.fl_flags &= ~FL_SLEEP;
 
        dprintk("lockd: vfs_lock_file returned %d\n", error);
@@ -540,7 +549,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
                         */
                        if (wait)
                                break;
-                       ret = nlm_lck_denied;
+                       ret = async_block ? nlm_lck_blocked : nlm_lck_denied;
                        goto out;
                case FILE_LOCK_DEFERRED:
                        if (wait)
@@ -577,6 +586,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
                struct nlm_lock *conflock, struct nlm_cookie *cookie)
 {
        int                     error;
+       int                     mode;
        __be32                  ret;
        struct nlm_lockowner    *test_owner;
 
@@ -595,7 +605,8 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
        /* If there's a conflicting lock, remember to clean up the test lock */
        test_owner = (struct nlm_lockowner *)lock->fl.fl_owner;
 
-       error = vfs_test_lock(file->f_file, &lock->fl);
+       mode = lock_to_openmode(&lock->fl);
+       error = vfs_test_lock(file->f_file[mode], &lock->fl);
        if (error) {
                /* We can't currently deal with deferred test requests */
                if (error == FILE_LOCK_DEFERRED)
@@ -641,7 +652,7 @@ out:
 __be32
 nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
 {
-       int     error;
+       int     error = 0;
 
        dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n",
                                nlmsvc_file_inode(file)->i_sb->s_id,
@@ -654,7 +665,12 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
        nlmsvc_cancel_blocked(net, file, lock);
 
        lock->fl.fl_type = F_UNLCK;
-       error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
+       if (file->f_file[O_RDONLY])
+               error = vfs_lock_file(file->f_file[O_RDONLY], F_SETLK,
+                                       &lock->fl, NULL);
+       if (file->f_file[O_WRONLY])
+               error = vfs_lock_file(file->f_file[O_WRONLY], F_SETLK,
+                                       &lock->fl, NULL);
 
        return (error < 0)? nlm_lck_denied_nolocks : nlm_granted;
 }
@@ -671,6 +687,7 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l
 {
        struct nlm_block        *block;
        int status = 0;
+       int mode;
 
        dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n",
                                nlmsvc_file_inode(file)->i_sb->s_id,
@@ -686,7 +703,8 @@ nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *l
        block = nlmsvc_lookup_block(file, lock);
        mutex_unlock(&file->f_mutex);
        if (block != NULL) {
-               vfs_cancel_lock(block->b_file->f_file,
+               mode = lock_to_openmode(&lock->fl);
+               vfs_cancel_lock(block->b_file->f_file[mode],
                                &block->b_call->a_args.lock.fl);
                status = nlmsvc_unlink_block(block);
                nlmsvc_release_block(block);
@@ -803,6 +821,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
 {
        struct nlm_file         *file = block->b_file;
        struct nlm_lock         *lock = &block->b_call->a_args.lock;
+       int                     mode;
        int                     error;
        loff_t                  fl_start, fl_end;
 
@@ -828,7 +847,8 @@ nlmsvc_grant_blocked(struct nlm_block *block)
        lock->fl.fl_flags |= FL_SLEEP;
        fl_start = lock->fl.fl_start;
        fl_end = lock->fl.fl_end;
-       error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
+       mode = lock_to_openmode(&lock->fl);
+       error = vfs_lock_file(file->f_file[mode], F_SETLK, &lock->fl, NULL);
        lock->fl.fl_flags &= ~FL_SLEEP;
        lock->fl.fl_start = fl_start;
        lock->fl.fl_end = fl_end;