aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2013-02-04 20:17:49 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2013-02-11 15:33:12 -0500
commit9a99af494bd7141d567d00b5ef94b141821e158c (patch)
tree1ca9c1ea6536b5384012e50d889eeb7753460244 /fs/nfs
parentc137afabe330f64eddcd4dd281258807e27fd430 (diff)
NFSv4.1: Prevent deadlocks between state recovery and file locking
We currently have a deadlock in which the state recovery thread ends up blocking due to one of the locks which it is trying to recover holding the nfs_inode->rwsem. The situation is as follows: the state recovery thread is scheduled in order to recover from a reboot. It immediately drains the session, forcing all ordinary NFSv4.1 calls to nfs41_setup_sequence() to be put to sleep. This includes the file locking process that holds the nfs_inode->rwsem. When the thread gets to nfs4_reclaim_locks(), it tries to grab a write lock on nfs_inode->rwsem, and boom... Fix is to have the lock drop the nfs_inode->rwsem while it is doing RPC calls. We use a sequence lock in order to signal to the locking process whether or not a state recovery thread has run on that inode, in which case it should retry the lock. Reported-by: Andy Adamson <andros@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/nfs4proc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 62fa4001e47a..92584c1ea725 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -4813,8 +4813,10 @@ static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *reques
4813 4813
4814static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 4814static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4815{ 4815{
4816 struct nfs4_state_owner *sp = state->owner;
4816 struct nfs_inode *nfsi = NFS_I(state->inode); 4817 struct nfs_inode *nfsi = NFS_I(state->inode);
4817 unsigned char fl_flags = request->fl_flags; 4818 unsigned char fl_flags = request->fl_flags;
4819 unsigned int seq;
4818 int status = -ENOLCK; 4820 int status = -ENOLCK;
4819 4821
4820 if ((fl_flags & FL_POSIX) && 4822 if ((fl_flags & FL_POSIX) &&
@@ -4836,9 +4838,16 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
4836 status = do_vfs_lock(request->fl_file, request); 4838 status = do_vfs_lock(request->fl_file, request);
4837 goto out_unlock; 4839 goto out_unlock;
4838 } 4840 }
4841 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
4842 up_read(&nfsi->rwsem);
4839 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); 4843 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4840 if (status != 0) 4844 if (status != 0)
4845 goto out;
4846 down_read(&nfsi->rwsem);
4847 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
4848 status = -NFS4ERR_DELAY;
4841 goto out_unlock; 4849 goto out_unlock;
4850 }
4842 /* Note: we always want to sleep here! */ 4851 /* Note: we always want to sleep here! */
4843 request->fl_flags = fl_flags | FL_SLEEP; 4852 request->fl_flags = fl_flags | FL_SLEEP;
4844 if (do_vfs_lock(request->fl_file, request) < 0) 4853 if (do_vfs_lock(request->fl_file, request) < 0)