aboutsummaryrefslogtreecommitdiff
path: root/fs/nfs/nfs4proc.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2008-12-23 15:21:44 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-12-23 15:21:44 -0500
commit19e03c570e6099ffaf24e5628d4fe1a8acbe820d (patch)
tree6e7eb831bbfe732044105f7f7a477fda5e912b6c /fs/nfs/nfs4proc.c
parent65de872ed6501a68e918a49a5c2fa7fca9c6ce21 (diff)
NFSv4: Ensure that file unlock requests don't conflict with state recovery
The unlock path is currently failing to take the nfs_client->cl_sem read lock, and hence the recovery path may see locks disappear from underneath it. Also ensure that it takes the nfs_inode->rwsem read lock so that it there is no conflict with delegation recalls. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/nfs4proc.c')
-rw-r--r--fs/nfs/nfs4proc.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 660c5dcfb0a..aec4e47c462 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3273,6 +3273,8 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
{
+ struct nfs_client *clp = state->owner->so_client;
+ struct nfs_inode *nfsi = NFS_I(state->inode);
struct nfs_seqid *seqid;
struct nfs4_lock_state *lsp;
struct rpc_task *task;
@@ -3282,8 +3284,15 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
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)
+ down_read(&clp->cl_sem);
+ down_read(&nfsi->rwsem);
+ if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
+ up_read(&nfsi->rwsem);
+ up_read(&clp->cl_sem);
goto out;
+ }
+ up_read(&nfsi->rwsem);
+ up_read(&clp->cl_sem);
if (status != 0)
goto out;
/* Is this a delegated lock? */
@@ -3510,6 +3519,7 @@ static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request
static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
{
struct nfs_client *clp = state->owner->so_client;
+ struct nfs_inode *nfsi = NFS_I(state->inode);
unsigned char fl_flags = request->fl_flags;
int status;
@@ -3522,18 +3532,13 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
if (status < 0)
goto out;
down_read(&clp->cl_sem);
+ down_read(&nfsi->rwsem);
if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
- struct nfs_inode *nfsi = NFS_I(state->inode);
/* Yes: cache locks! */
- down_read(&nfsi->rwsem);
/* ...but avoid races with delegation recall... */
- if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
- request->fl_flags = fl_flags & ~FL_SLEEP;
- status = do_vfs_lock(request->fl_file, request);
- up_read(&nfsi->rwsem);
- goto out_unlock;
- }
- up_read(&nfsi->rwsem);
+ request->fl_flags = fl_flags & ~FL_SLEEP;
+ status = do_vfs_lock(request->fl_file, request);
+ goto out_unlock;
}
status = _nfs4_do_setlk(state, cmd, request, 0);
if (status != 0)
@@ -3543,6 +3548,7 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
if (do_vfs_lock(request->fl_file, request) < 0)
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
out_unlock:
+ up_read(&nfsi->rwsem);
up_read(&clp->cl_sem);
out:
request->fl_flags = fl_flags;