Commit 9b073574 authored by Trond Myklebust's avatar 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: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent f475ae95
...@@ -454,7 +454,7 @@ static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *ho ...@@ -454,7 +454,7 @@ static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *ho
fl->fl_ops = &nlmclnt_lock_ops; fl->fl_ops = &nlmclnt_lock_ops;
} }
static void do_vfs_lock(struct file_lock *fl) static int do_vfs_lock(struct file_lock *fl)
{ {
int res = 0; int res = 0;
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
...@@ -467,9 +467,7 @@ static void do_vfs_lock(struct file_lock *fl) ...@@ -467,9 +467,7 @@ static void do_vfs_lock(struct file_lock *fl)
default: default:
BUG(); BUG();
} }
if (res < 0) return res;
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
__FUNCTION__);
} }
/* /*
...@@ -541,7 +539,8 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl) ...@@ -541,7 +539,8 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
} }
fl->fl_flags |= FL_SLEEP; fl->fl_flags |= FL_SLEEP;
/* Ensure the resulting lock will get added to granted list */ /* Ensure the resulting lock will get added to granted list */
do_vfs_lock(fl); if (do_vfs_lock(fl) < 0)
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
up_read(&host->h_rwsem); up_read(&host->h_rwsem);
} }
status = nlm_stat_to_errno(resp->status); status = nlm_stat_to_errno(resp->status);
...@@ -606,15 +605,19 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl) ...@@ -606,15 +605,19 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
{ {
struct nlm_host *host = req->a_host; struct nlm_host *host = req->a_host;
struct nlm_res *resp = &req->a_res; struct nlm_res *resp = &req->a_res;
int status; int status = 0;
/* /*
* Note: the server is supposed to either grant us the unlock * Note: the server is supposed to either grant us the unlock
* request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either * request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either
* case, we want to unlock. * case, we want to unlock.
*/ */
fl->fl_flags |= FL_EXISTS;
down_read(&host->h_rwsem); down_read(&host->h_rwsem);
do_vfs_lock(fl); if (do_vfs_lock(fl) == -ENOENT) {
up_read(&host->h_rwsem);
goto out;
}
up_read(&host->h_rwsem); up_read(&host->h_rwsem);
if (req->a_flags & RPC_TASK_ASYNC) if (req->a_flags & RPC_TASK_ASYNC)
...@@ -624,7 +627,6 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl) ...@@ -624,7 +627,6 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
if (status < 0) if (status < 0)
goto out; goto out;
status = 0;
if (resp->status == NLM_LCK_GRANTED) if (resp->status == NLM_LCK_GRANTED)
goto out; goto out;
......
...@@ -3144,9 +3144,6 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl) ...@@ -3144,9 +3144,6 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl)
default: default:
BUG(); BUG();
} }
if (res < 0)
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
__FUNCTION__);
return res; return res;
} }
...@@ -3258,8 +3255,6 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, ...@@ -3258,8 +3255,6 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
return ERR_PTR(-ENOMEM); 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); return rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data);
} }
...@@ -3270,30 +3265,28 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * ...@@ -3270,30 +3265,28 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
struct rpc_task *task; struct rpc_task *task;
int status = 0; 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); status = nfs4_set_lock_state(state, request);
/* Unlock _before_ we do the RPC call */
request->fl_flags |= FL_EXISTS;
if (do_vfs_lock(request->fl_file, request) == -ENOENT)
goto out;
if (status != 0) if (status != 0)
goto out_unlock; goto out;
/* Is this a delegated lock? */
if (test_bit(NFS_DELEGATED_STATE, &state->flags))
goto out;
lsp = request->fl_u.nfs4_fl.owner; lsp = request->fl_u.nfs4_fl.owner;
status = -ENOMEM;
seqid = nfs_alloc_seqid(&lsp->ls_seqid); seqid = nfs_alloc_seqid(&lsp->ls_seqid);
status = -ENOMEM;
if (seqid == NULL) if (seqid == NULL)
goto out_unlock; goto out;
task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid); task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid);
status = PTR_ERR(task); status = PTR_ERR(task);
if (IS_ERR(task)) if (IS_ERR(task))
goto out_unlock; goto out;
status = nfs4_wait_for_completion_rpc_task(task); status = nfs4_wait_for_completion_rpc_task(task);
rpc_release_task(task); rpc_release_task(task);
return status; out:
out_unlock:
do_vfs_lock(request->fl_file, request);
return status; return status;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment