NFS: Don't check lock owner compatability unless file is locked (part 2)
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 6 Sep 2013 15:09:38 +0000 (11:09 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 6 Sep 2013 15:27:41 +0000 (11:27 -0400)
When coalescing requests into a single READ or WRITE RPC call, and there
is no file locking involved, we don't have to refuse coalescing for
requests where the lock owner information doesn't match.

Reported-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/pagelist.c

index 29cfb7ade121276e2d5ed7372d01949c5e0c2819..2ffebf2081ceb5c779cf7f53644fa453bff45ca2 100644 (file)
@@ -328,6 +328,19 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
 }
 EXPORT_SYMBOL_GPL(nfs_pageio_init);
 
+static bool nfs_match_open_context(const struct nfs_open_context *ctx1,
+               const struct nfs_open_context *ctx2)
+{
+       return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state;
+}
+
+static bool nfs_match_lock_context(const struct nfs_lock_context *l1,
+               const struct nfs_lock_context *l2)
+{
+       return l1->lockowner.l_owner == l2->lockowner.l_owner
+               && l1->lockowner.l_pid == l2->lockowner.l_pid;
+}
+
 /**
  * nfs_can_coalesce_requests - test two requests for compatibility
  * @prev: pointer to nfs_page
@@ -343,13 +356,10 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,
                                      struct nfs_page *req,
                                      struct nfs_pageio_descriptor *pgio)
 {
-       if (req->wb_context->cred != prev->wb_context->cred)
-               return false;
-       if (req->wb_lock_context->lockowner.l_owner != prev->wb_lock_context->lockowner.l_owner)
-               return false;
-       if (req->wb_lock_context->lockowner.l_pid != prev->wb_lock_context->lockowner.l_pid)
+       if (!nfs_match_open_context(req->wb_context, prev->wb_context))
                return false;
-       if (req->wb_context->state != prev->wb_context->state)
+       if (req->wb_context->dentry->d_inode->i_flock != NULL &&
+           !nfs_match_lock_context(req->wb_lock_context, prev->wb_lock_context))
                return false;
        if (req->wb_pgbase != 0)
                return false;