From: Trond Myklebust NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock Use the new behaviour of {flock,posix}_file_lock(F_UNLCK) to determine if we held a lock, and only send the RPC request to the server if this was the case. Signed-off-by: Trond Myklebust --- fs/lockd/clntproc.c | 5 +++-- fs/nfs/nfs4proc.c | 29 +++++++++++++---------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c index 4db6209..d2e4137 100644 --- a/fs/lockd/clntproc.c +++ b/fs/lockd/clntproc.c @@ -607,7 +607,7 @@ nlmclnt_unlock(struct nlm_rqst *req, str { struct nlm_host *host = req->a_host; struct nlm_res *resp = &req->a_res; - int status; + int status = 0; /* * Note: the server is supposed to either grant us the unlock @@ -617,6 +617,8 @@ nlmclnt_unlock(struct nlm_rqst *req, str down_read(&host->h_rwsem); do_vfs_lock(fl); up_read(&host->h_rwsem); + if (fl->fl_type != F_UNLCK) + goto out; if (req->a_flags & RPC_TASK_ASYNC) return nlm_async_call(req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops); @@ -625,7 +627,6 @@ nlmclnt_unlock(struct nlm_rqst *req, str if (status < 0) goto out; - status = 0; if (resp->status == NLM_LCK_GRANTED) goto out; diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e38a848..5b991fa 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3195,8 +3195,6 @@ static struct rpc_task *nfs4_do_unlck(st return ERR_PTR(-ENOMEM); } - /* Unlock _before_ we do the RPC call */ - do_vfs_lock(fl->fl_file, fl); return rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data); } @@ -3207,30 +3205,29 @@ static int nfs4_proc_unlck(struct nfs4_s struct rpc_task *task; int status = 0; - /* Is this a delegated lock? */ - if (test_bit(NFS_DELEGATED_STATE, &state->flags)) - goto out_unlock; - /* Is this open_owner holding any locks on the server? */ - if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) - goto out_unlock; - status = nfs4_set_lock_state(state, request); + /* Unlock _before_ we do the RPC call */ + do_vfs_lock(request->fl_file, request); if (status != 0) - goto out_unlock; + goto out; + /* Is this open_owner holding any locks on the server? */ + if (request->fl_type != F_UNLCK) + goto out; + /* Is this a delegated lock? */ + if (test_bit(NFS_DELEGATED_STATE, &state->flags)) + goto out; lsp = request->fl_u.nfs4_fl.owner; - status = -ENOMEM; seqid = nfs_alloc_seqid(&lsp->ls_seqid); + status = -ENOMEM; if (seqid == NULL) - goto out_unlock; + goto out; task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid); status = PTR_ERR(task); if (IS_ERR(task)) - goto out_unlock; + goto out; status = nfs4_wait_for_completion_rpc_task(task); rpc_release_task(task); - return status; -out_unlock: - do_vfs_lock(request->fl_file, request); +out: return status; }