aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorAndy Adamson <andros@netapp.com>2009-12-04 15:55:38 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2009-12-04 15:55:38 -0500
commitea028ac92541ac30bf202ed94cb53eec2ea0c9d6 (patch)
treef9b807cf0f870db922f96e72dab68ed37ba18cf0 /fs/nfs
parent05f0d2364726c92f6b870db654967088349379fe (diff)
nfs41: nfs41: fix state manager deadlock in session reset
If the session is reset during state recovery, the state manager thread can sleep on the slot_tbl_waitq causing a deadlock. Add a completion framework to the session. Have the state manager thread set a new session state (NFS4CLNT_SESSION_DRAINING) and wait for the session slot table to drain. Signal the state manager thread in nfs41_sequence_free_slot when the NFS4CLNT_SESSION_DRAINING bit is set and the session is drained. Reported-by: Trond Myklebust <trond@netapp.com> Signed-off-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/nfs4_fs.h1
-rw-r--r--fs/nfs/nfs4proc.c26
-rw-r--r--fs/nfs/nfs4state.c15
3 files changed, 33 insertions, 9 deletions
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index e9ecd6bf9257..5c7740178a08 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -45,6 +45,7 @@ enum nfs4_client_state {
45 NFS4CLNT_RECLAIM_NOGRACE, 45 NFS4CLNT_RECLAIM_NOGRACE,
46 NFS4CLNT_DELEGRETURN, 46 NFS4CLNT_DELEGRETURN,
47 NFS4CLNT_SESSION_RESET, 47 NFS4CLNT_SESSION_RESET,
48 NFS4CLNT_SESSION_DRAINING,
48}; 49};
49 50
50/* 51/*
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index fb62919f7f2c..c1bc9cad5e85 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -361,6 +361,16 @@ void nfs41_sequence_free_slot(const struct nfs_client *clp,
361 } 361 }
362 nfs4_free_slot(tbl, res->sr_slotid); 362 nfs4_free_slot(tbl, res->sr_slotid);
363 res->sr_slotid = NFS4_MAX_SLOT_TABLE; 363 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
364
365 /* Signal state manager thread if session is drained */
366 if (test_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state)) {
367 spin_lock(&tbl->slot_tbl_lock);
368 if (tbl->highest_used_slotid == -1) {
369 dprintk("%s COMPLETE: Session Drained\n", __func__);
370 complete(&clp->cl_session->complete);
371 }
372 spin_unlock(&tbl->slot_tbl_lock);
373 }
364} 374}
365 375
366static void nfs41_sequence_done(struct nfs_client *clp, 376static void nfs41_sequence_done(struct nfs_client *clp,
@@ -457,15 +467,11 @@ static int nfs41_setup_sequence(struct nfs4_session *session,
457 467
458 spin_lock(&tbl->slot_tbl_lock); 468 spin_lock(&tbl->slot_tbl_lock);
459 if (test_bit(NFS4CLNT_SESSION_RESET, &session->clp->cl_state)) { 469 if (test_bit(NFS4CLNT_SESSION_RESET, &session->clp->cl_state)) {
460 if (tbl->highest_used_slotid != -1) { 470 /*
461 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 471 * The state manager will wait until the slot table is empty.
462 spin_unlock(&tbl->slot_tbl_lock); 472 * Schedule the reset thread
463 dprintk("<-- %s: Session reset: draining\n", __func__); 473 */
464 return -EAGAIN; 474 dprintk("%s Schedule Session Reset\n", __func__);
465 }
466
467 /* The slot table is empty; start the reset thread */
468 dprintk("%s Session Reset\n", __func__);
469 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 475 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
470 nfs4_schedule_state_manager(session->clp); 476 nfs4_schedule_state_manager(session->clp);
471 spin_unlock(&tbl->slot_tbl_lock); 477 spin_unlock(&tbl->slot_tbl_lock);
@@ -4506,6 +4512,7 @@ static int nfs4_reset_slot_tables(struct nfs4_session *session)
4506 1); 4512 1);
4507 if (status) 4513 if (status)
4508 return status; 4514 return status;
4515 init_completion(&session->complete);
4509 4516
4510 status = nfs4_reset_slot_table(&session->bc_slot_table, 4517 status = nfs4_reset_slot_table(&session->bc_slot_table,
4511 session->bc_attrs.max_reqs, 4518 session->bc_attrs.max_reqs,
@@ -4608,6 +4615,7 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4608 * nfs_client struct 4615 * nfs_client struct
4609 */ 4616 */
4610 clp->cl_cons_state = NFS_CS_SESSION_INITING; 4617 clp->cl_cons_state = NFS_CS_SESSION_INITING;
4618 init_completion(&session->complete);
4611 4619
4612 tbl = &session->fc_slot_table; 4620 tbl = &session->fc_slot_table;
4613 spin_lock_init(&tbl->slot_tbl_lock); 4621 spin_lock_init(&tbl->slot_tbl_lock);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index f56f6be5e314..3c1433598b60 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1181,8 +1181,23 @@ static void nfs4_session_recovery_handle_error(struct nfs_client *clp, int err)
1181 1181
1182static int nfs4_reset_session(struct nfs_client *clp) 1182static int nfs4_reset_session(struct nfs_client *clp)
1183{ 1183{
1184 struct nfs4_session *ses = clp->cl_session;
1185 struct nfs4_slot_table *tbl = &ses->fc_slot_table;
1184 int status; 1186 int status;
1185 1187
1188 INIT_COMPLETION(ses->complete);
1189 spin_lock(&tbl->slot_tbl_lock);
1190 if (tbl->highest_used_slotid != -1) {
1191 set_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state);
1192 spin_unlock(&tbl->slot_tbl_lock);
1193 status = wait_for_completion_interruptible(&ses->complete);
1194 clear_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state);
1195 if (status) /* -ERESTARTSYS */
1196 goto out;
1197 } else {
1198 spin_unlock(&tbl->slot_tbl_lock);
1199 }
1200
1186 status = nfs4_proc_destroy_session(clp->cl_session); 1201 status = nfs4_proc_destroy_session(clp->cl_session);
1187 if (status && status != -NFS4ERR_BADSESSION && 1202 if (status && status != -NFS4ERR_BADSESSION &&
1188 status != -NFS4ERR_DEADSESSION) { 1203 status != -NFS4ERR_DEADSESSION) {