Skip to contentSkip to conversation

nfs41 client session bug fixes

PATCH Applied [email protected] 3 participants 8 messages Oct 21, 2009 – Nov 3, 2009 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover nfs41 client session bug fixes

nfs41 client session bug fixes. 2.6.32-rc2 nfs41-all branch.

Fix multiple calls to nfs41_sequence_free_slot (Reported by Trond). Fix a race between state manager session reset and queued rpc's calling nfs41_setup_sequence.

0001-nfs41-fix-multiple-free-slot-calls.patch
0002-nfs41-fix-race-on-session-reset.patch

Passed connectathon tests.
Passed pynfs testclient.py SESSION reset tests.
Passed connectathon basic tests against a with modified pynfs server that returns NFS4ERR_SEQ_MISORDERED every 50 SEQUENCE operations.

-->Andy

#1 lore raw

PATCH 1/2 nfs41: fix multiple free slot calls

From: Andy Adamson <[email protected]>

nfs41_sequence_free_slot is called multiple times on SEQUENCE operation errors.

Fix this by moving the call to nfs41_sequence_free_slot from the error path of nfs41_sequence_done to nfs4_async_handle_error for the SEQUENCE operation error cases.

---
 fs/nfs/nfs4proc.c |   63 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 36 insertions(+), 27 deletions(-)
fs/nfs/nfs4proc.c +36 -27
index c321002..eb245a1 100644
@@ -65,7 +65,8 @@
 struct nfs4_opendata;
 static int _nfs4_proc_open(struct nfs4_opendata *data);
 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
-static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
+static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *,
+			 struct nfs4_state *, struct nfs4_sequence_res *);
 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
 
@@ -370,11 +371,12 @@ static void nfs41_sequence_done(struct nfs_client *clp,
 
 	/* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
 	if (res->sr_slotid == NFS4_MAX_SLOT_TABLE)
-		goto out;
+		return;
 
 	tbl = &clp->cl_session->fc_slot_table;
 	slot = tbl->slots + res->sr_slotid;
 
+	/* Check the SEQUENCE operation status */
 	if (res->sr_status == 0) {
 		/* Update the slot's sequence and clientid lease timer */
 		++slot->seq_nr;
@@ -386,15 +388,6 @@ static void nfs41_sequence_done(struct nfs_client *clp,
 		return;
 	}
 
-	/* Do not free slot if retried while operation was in progress */
-	if (res->sr_status == -NFS4ERR_DELAY) {
-		dprintk("%s: Operation in progress\n", __func__);
-		return;
-	}
-out:
-	/* The session may be reset by one of the error handlers. */
-	dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
-	nfs41_sequence_free_slot(clp, res);
 }
 
 /*
@@ -1743,7 +1736,8 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
 			if (calldata->arg.fmode == 0)
 				break;
 		default:
-			if (nfs4_async_handle_error(task, server, state) == -EAGAIN) {
+			if (nfs4_async_handle_error(task, server, state,
+					&calldata->res.seq_res) == -EAGAIN) {
 				nfs4_restart_rpc(task, server->nfs_client);
 				return;
 			}
@@ -2537,7 +2531,8 @@ static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
 	struct nfs_removeres *res = task->tk_msg.rpc_resp;
 
 	nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
-	if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
+	if (nfs4_async_handle_error(task, res->server, NULL,
+						&res->seq_res) == -EAGAIN)
 		return 0;
 	nfs4_sequence_free_slot(res->server->nfs_client, &res->seq_res);
 	update_changeattr(dir, &res->cinfo);
@@ -2981,7 +2976,8 @@ static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
 	/* nfs4_sequence_free_slot called in the read rpc_call_done */
 	nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
 
-	if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
+	if (nfs4_async_handle_error(task, server, data->args.context->state,
+					&data->res.seq_res) == -EAGAIN) {
 		nfs4_restart_rpc(task, server->nfs_client);
 		return -EAGAIN;
 	}
@@ -3002,11 +2998,14 @@ static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
 {
 	struct inode *inode = data->inode;
 	
+	dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
 	/* slot is freed in nfs_writeback_done */
 	nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
 			   task->tk_status);
 
-	if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
+	if (nfs4_async_handle_error(task, NFS_SERVER(inode),
+				    data->args.context->state,
+				    &data->res.seq_res) == -EAGAIN) {
 		nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
 		return -EAGAIN;
 	}
@@ -3032,9 +3031,12 @@ static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
 {
 	struct inode *inode = data->inode;
 	
+	dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
+
 	nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
 			   task->tk_status);
-	if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
+	if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL,
+					&data->res.seq_res) == -EAGAIN) {
 		nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
 		return -EAGAIN;
 	}
@@ -3330,7 +3332,9 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
 }
 
 static int
-_nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state)
+_nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
+			 struct nfs_client *clp, struct nfs4_state *state,
+			 struct nfs4_sequence_res *res)
 {
 	if (!clp || task->tk_status >= 0)
 		return 0;
@@ -3361,6 +3365,8 @@ _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
 			dprintk("%s ERROR %d, Reset session\n", __func__,
 				task->tk_status);
 			set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+			/* Free the slot so session can drain */
+			nfs41_sequence_free_slot(clp, res);
 			task->tk_status = 0;
 			return -EAGAIN;
 #endif /* CONFIG_NFS_V4_1 */
@@ -3380,9 +3386,11 @@ _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
 }
 
 static int
-nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
+nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
+			struct nfs4_state *state, struct nfs4_sequence_res *res)
 {
-	return _nfs4_async_handle_error(task, server, server->nfs_client, state);
+	return _nfs4_async_handle_error(task, server, server->nfs_client,
+					state, res);
 }
 
 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
@@ -3732,9 +3740,9 @@ static void nfs4_locku_release_calldata(void *data)
 static void nfs4_locku_done(struct rpc_task *task, void *data)
 {
 	struct nfs4_unlockdata *calldata = data;
+	struct nfs4_sequence_res *res = &calldata->res.seq_res;
 
-	nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
-			   task->tk_status);
+	nfs4_sequence_done(calldata->server, res, task->tk_status);
 	if (RPC_ASSASSINATED(task))
 		return;
 	switch (task->tk_status) {
@@ -3750,12 +3758,12 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
 		case -NFS4ERR_EXPIRED:
 			break;
 		default:
-			if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
+			if (nfs4_async_handle_error(task, calldata->server,
+						    NULL, res) == -EAGAIN)
 				nfs4_restart_rpc(task,
 						calldata->server->nfs_client);
 	}
-	nfs4_sequence_free_slot(calldata->server->nfs_client,
-				&calldata->res.seq_res);
+	nfs4_sequence_free_slot(calldata->server->nfs_client, res);
 }
 
 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
@@ -4875,19 +4883,20 @@ static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
 void nfs41_sequence_call_done(struct rpc_task *task, void *data)
 {
 	struct nfs_client *clp = (struct nfs_client *)data;
+	struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
 
-	nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status);
+	nfs41_sequence_done(clp, res, task->tk_status);
 
 	if (task->tk_status < 0) {
 		dprintk("%s ERROR %d\n", __func__, task->tk_status);
 
-		if (_nfs4_async_handle_error(task, NULL, clp, NULL)
+		if (_nfs4_async_handle_error(task, NULL, clp, NULL, res)
 								== -EAGAIN) {
 			nfs4_restart_rpc(task, clp);
 			return;
 		}
 	}
-	nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp);
+	nfs41_sequence_free_slot(clp, res);
 	dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
 
 	put_rpccred(task->tk_msg.rpc_cred);
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/2 nfs41: fix race on session reset

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the session has been reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SESSION) to prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
 fs/nfs/nfs4proc.c  |    3 +++
 fs/nfs/nfs4state.c |   15 +++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +3 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_client *clp, int reset)
 	if (status)
 		goto out;
 
+	/* Signal nfs41_setup_sequence that the session is ready for use */
+	clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
 	ptr = (unsigned *)&session->sess_id.data[0];
 	dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
 		clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
fs/nfs/nfs4state.c +9 -6
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_client *clp)
 				continue;
 		}
 		/* Initialize or reset the session */
-		if (test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
-		   && nfs4_has_session(clp)) {
+		if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
+		    && nfs4_has_session(clp)) {
 			if (clp->cl_cons_state == NFS_CS_SESSION_INITING)
 				status = nfs4_initialize_session(clp);
 			else
 				status = nfs4_reset_session(clp);
-			if (status) {
-				if (status == -NFS4ERR_STALE_CLIENTID)
-					continue;
+			if (status == -NFS4ERR_STALE_CLIENTID)
+				continue;
+			/* For error case. On success the bit is cleared in
+			 * nfs4_proc_create_session */
+			clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
+			if (status)
 				goto out_error;
-			}
 		}
 		/* First recover reboot state... */
 		if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
Signature · 1 line
1.6.2.5
#3 lore raw

Re: [pnfs] [PATCH 2/2] nfs41: fix race on session reset

Quoted 40 lines · On Oct. 21, 2009, 20:24 +0200, [email protected] wrote:

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the session has been reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SESSION) to prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
 fs/nfs/nfs4proc.c  |    3 +++
 fs/nfs/nfs4state.c |   15 +++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +3 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_client *clp, int reset)
 	if (status)
 		goto out;
 
+	/* Signal nfs41_setup_sequence that the session is ready for use */
+	clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
 	ptr = (unsigned *)&session->sess_id.data[0];
 	dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
 		clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
fs/nfs/nfs4state.c +2 -2
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_client *clp)
 				continue;
 		}
 		/* Initialize or reset the session */
-		if (test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
-		   && nfs4_has_session(clp)) {
+		if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
+		    && nfs4_has_session(clp)) {
 			if (clp->cl_cons_state == NFS_CS_SESSION_INITING)

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 1264

Quoted 10 lines
fs/nfs/nfs4state.c +4 -3
 				status = nfs4_initialize_session(clp);
 			else
 				status = nfs4_reset_session(clp);
-			if (status) {
-				if (status == -NFS4ERR_STALE_CLIENTID)
-					continue;
+			if (status == -NFS4ERR_STALE_CLIENTID)
+				continue;
+			/* For error case. On success the bit is cleared in
+			 * nfs4_proc_create_session */

Why the separation?
Why not handle both success and error cases here?

Benny

Quoted 8 lines
fs/nfs/nfs4state.c +3 -1
+			clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
+			if (status)
 				goto out_error;
-			}
 		}
 		/* First recover reboot state... */
 		if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
#4 lore raw

Re: [pnfs] [PATCH 2/2] nfs41: fix race on session reset

On Thu, Oct 22, 2009 at 9:20 AM, Benny Halevy <[email protected]> wro= te:

Quoted 4 lines · On Oct. 21, 2009, 20:24 +0200, [email protected] wrote:
Quoted 3 lines

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the session =

has been

Quoted 1 line
Quoted 1 line

reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SESSI=

ON) to

Quoted 9 lines
Quoted 9 lines

prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
=A0fs/nfs/nfs4proc.c =A0| =A0 =A03 +++ =A0fs/nfs/nfs4state.c | =A0 15 +++++++++------ =A02 files changed, 12 insertions(+), 6 deletions(-)

Quoted 5 lines

fs/nfs/nfs4proc.c int nfs4_proc_create_session(struct nfs_client=

Quoted 5 lines
fs/nfs/nfs4proc.c +0 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_client=

*clp, int reset)

Quoted 4 lines

fs/nfs/nfs4proc.c int nfs4_proc_create_session(struct nfs_client= · line 4791

Quoted 4 lines
fs/nfs/nfs4proc.c +1 -0
 =A0 =A0 =A0 if (status)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
 
+ =A0 =A0 /* Signal nfs41_setup_sequence that the session is ready f=

or use */

Quoted 4 lines
Quoted 4 lines
fs/nfs/nfs4proc.c +2 -0
+ =A0 =A0 clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
 =A0 =A0 =A0 ptr =3D (unsigned *)&session->sess_id.data[0];

=A0 =A0 =A0 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __=

func__,

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 clp->cl_seqid, ptr[0], ptr[1], ptr[2], p=

tr[3]);

Quoted 5 lines

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_cl=

Quoted 5 lines
fs/nfs/nfs4state.c +0 -0
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_cl=

ient *clp)

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue=

;

Quoted 3 lines
Quoted 3 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Initialize or reset the session */
- =A0 =A0 =A0 =A0 =A0 =A0 if (test_and_clear_bit(NFS4CLNT_SESSION_SE=

TUP, &clp->cl_state)

Quoted 5 lines
Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& nfs4_has_session(clp)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 if (test_bit(NFS4CLNT_SESSION_SETUP, &clp-=

cl_state)

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && nfs4_has_session(clp)) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (clp->cl_cons_state =3D=

=3D NFS_CS_SESSION_INITING)

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 status =3D=

nfs4_initialize_session(clp);

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 status =3D=

nfs4_reset_session(clp);

Quoted 2 lines
Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status=

=3D=3D -NFS4ERR_STALE_CLIENTID)

Quoted 1 line
Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 continue;

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status =3D=3D -NFS4ERR=

_STALE_CLIENTID)

Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* For error case. On succ=

ess the bit is cleared in

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* nfs4_proc_create_sess=

ion */

Quoted 3 lines

Why the separation?
Why not handle both success and error cases here?

We don't clear the bit on NFS4ERR_STALE_CLIENTID because we first need an EXCHANGE_ID and then session reset and we don't want any rpc's queued on the slot_tbl_waitq to run. The check for NFS4ERR_STALE_CLIENTID is in the nfs4_state_manager. Also, all other cases in the state manager clear the bits used - so I thought it best to follow suit.

-->Andy

Quoted 4 lines

Benny

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 clear_bit(NFS4CLNT_SESSION=

_SETUP, &clp->cl_state);

Quoted 3 lines
Quoted 3 lines

+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out=

_error;

Quoted 4 lines
Quoted 4 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 /* First recover reboot state... */ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (test_and_clear_bit(NFS4CLNT_RECLAIM_=

REBOOT, &clp->cl_state)) {

Quoted 5 lines

_______________________________________________
pNFS mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/pnfs

A message that is not in the archive (sent off-list or not yet received): 89c397150910220632o5708b8efhb7223541315b4e33-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [pnfs] [PATCH 2/2] nfs41: fix race on session reset

Quoted 55 lines · William A. (Andy) Adamson
Quoted 45 lines · Benny Halevy
Quoted 44 lines · On Oct. 21, 2009, 20:24 +0200, [email protected] wrote:

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the session has been reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SESSION) to prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
 fs/nfs/nfs4proc.c  |    3 +++
 fs/nfs/nfs4state.c |   15 +++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +3 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_client *clp, int reset)
      if (status)
              goto out;
 
+     /* Signal nfs41_setup_sequence that the session is ready for use */
+     clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
      ptr = (unsigned *)&session->sess_id.data[0];
      dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
              clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
fs/nfs/nfs4state.c +2 -3
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_client *clp)
                              continue;
              }
              /* Initialize or reset the session */
-             if (test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
-                && nfs4_has_session(clp)) {
+             if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
+                 && nfs4_has_session(clp)) {
                      if (clp->cl_cons_state == NFS_CS_SESSION_INITING)
                              status = nfs4_initialize_session(clp);
                      else
                              status = nfs4_reset_session(clp);
-                     if (status) {
Quoted 8 lines

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 1264

Quoted 6 lines
fs/nfs/nfs4state.c +4 -2
-                             if (status == -NFS4ERR_STALE_CLIENTID)
-                                     continue;
+                     if (status == -NFS4ERR_STALE_CLIENTID)
+                             continue;
+                     /* For error case. On success the bit is cleared in
+                      * nfs4_proc_create_session */

Why the separation?
Why not handle both success and error cases here?

Quoted 6 lines

We don't clear the bit on NFS4ERR_STALE_CLIENTID because we first need an EXCHANGE_ID and then session reset and we don't want any rpc's queued on the slot_tbl_waitq to run. The check for NFS4ERR_STALE_CLIENTID is in the nfs4_state_manager. Also, all other cases in the state manager clear the bits used - so I thought it best to follow suit.

I agree, so why clear the NFS4CLNT_SESSION_SETUP bit on success in nfs4_proc_create_session()
Also, nfs4_proc_create_session() clears NFS4CLNT_LEASE_EXPIRED which is test_and_cleared by the state manager...

Benny

Quoted 18 lines

-->Andy

Quoted 15 lines

Benny

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 1271

Quoted 8 lines
fs/nfs/nfs4state.c +3 -1
+                     clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
+                     if (status)
                              goto out_error;
-                     }
              }
              /* First recover reboot state... */
              if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {

_______________________________________________
pNFS mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/pnfs

#7 lore raw

Re: [pnfs] [PATCH 2/2] nfs41: fix race on session reset

On Thu, Oct 22, 2009 at 9:47 AM, Benny Halevy <[email protected]> wro= te:

Quoted 1 line

On Oct. 22, 2009, 15:32 +0200, "William A. (Andy) Adamson" <androsada=

Quoted 1 line · [email protected]> wrote:
Quoted 1 line

On Thu, Oct 22, 2009 at 9:20 AM, Benny Halevy <[email protected]> =

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines · On Oct. 21, 2009, 20:24 +0200, [email protected] wrote:
Quoted 3 lines

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the sessio=

n has been

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SES=

SION) to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
=A0fs/nfs/nfs4proc.c =A0| =A0 =A03 +++ =A0fs/nfs/nfs4state.c | =A0 15 +++++++++------ =A02 files changed, 12 insertions(+), 6 deletions(-)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fs/nfs/nfs4proc.c int nfs4_proc_create_session(struct nfs_clie=

Quoted 5 lines
fs/nfs/nfs4proc.c +0 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_clie=

nt *clp, int reset)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

fs/nfs/nfs4proc.c int nfs4_proc_create_session(struct nfs_clie= · line 4791

Quoted 4 lines
fs/nfs/nfs4proc.c +1 -0
 =A0 =A0 =A0 if (status)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
 
+ =A0 =A0 /* Signal nfs41_setup_sequence that the session is ready=

for use */

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/nfs/nfs4proc.c +2 -0
+ =A0 =A0 clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
 =A0 =A0 =A0 ptr =3D (unsigned *)&session->sess_id.data[0];

=A0 =A0 =A0 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", =

__func__,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 clp->cl_seqid, ptr[0], ptr[1], ptr[2],=

ptr[3]);

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_=

Quoted 5 lines
fs/nfs/nfs4state.c +0 -0
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_=

client *clp)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 contin=

ue;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Initialize or reset the session */
- =A0 =A0 =A0 =A0 =A0 =A0 if (test_and_clear_bit(NFS4CLNT_SESSION_=

SETUP, &clp->cl_state)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& nfs4_has_session(clp)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 if (test_bit(NFS4CLNT_SESSION_SETUP, &cl=

p->cl_state)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && nfs4_has_session(clp)) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (clp->cl_cons_state=

=3D=3D NFS_CS_SESSION_INITING)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 status=

=3D nfs4_initialize_session(clp);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 status=

=3D nfs4_reset_session(clp);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (stat=

us =3D=3D -NFS4ERR_STALE_CLIENTID)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 continue;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status =3D=3D -NFS4E=

RR_STALE_CLIENTID)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue=

;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* For error case. On su=

ccess the bit is cleared in

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* nfs4_proc_create_se=

ssion */

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Why the separation?
Why not handle both success and error cases here?

We don't clear the bit on NFS4ERR_STALE_CLIENTID because we first ne=

ed

Quoted 4 lines
Quoted 4 lines

an EXCHANGE_ID and then session reset and we don't want any rpc's queued on the slot_tbl_waitq to run. The check for NFS4ERR_STALE_CLIENTID is in the nfs4_state_manager. Also, all other cases in the state manager clear the bits used - so I thought it bes=

t

Quoted 4 lines
Quoted 1 line

to follow suit.

I agree, so why clear the NFS4CLNT_SESSION_SETUP bit on success in nfs4_proc_create_session()

so that nfs4_proc_get_lease_time can use the newly created session.

Quoted 2 lines

Also, nfs4_proc_create_session() clears NFS4CLNT_LEASE_EXPIRED which is test_and_cleared by the state manager...

True and harmless.

-->Andy

Quoted 9 lines

Benny

Quoted 6 lines

-->Andy

Quoted 3 lines

Benny

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 clear_bit(NFS4CLNT_SESSI=

ON_SETUP, &clp->cl_state);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (status) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto o=

ut_error;

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0 =A0 =A0 /* First recover reboot state... */ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (test_and_clear_bit(NFS4CLNT_RECLAI=

M_REBOOT, &clp->cl_state)) {

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

_______________________________________________
pNFS mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/pnfs

A message that is not in the archive (sent off-list or not yet received): 89c397150910220714jae5e335qa8313a994e440660-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

Applied
#9 lore raw

Re: [pnfs] [PATCH 2/2] nfs41: fix race on session reset

I merged both patches also into the pnfs tree.

Benny

Quoted 93 lines · William A. (Andy) Adamson
Quoted 55 lines · Benny Halevy
Quoted 54 lines · William A. (Andy) Adamson
Quoted 53 lines · Benny Halevy
Quoted 40 lines · On Oct. 21, 2009, 20:24 +0200, [email protected] wrote:

From: Andy Adamson <[email protected]>

Do not clear the NFS4CLNT_SESSION_SETUP bit until after the session has been reset (a possible EXCHANGE_ID, a DESTROY_SESSION, and a CREATE_SESSION) to prevent a race with nfs41_setup_sequence assigning a slot on a partially reset session.

---
 fs/nfs/nfs4proc.c  |    3 +++
 fs/nfs/nfs4state.c |   15 +++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +3 -0
index eb245a1..80764e2 100644
@@ -4788,6 +4788,9 @@ int nfs4_proc_create_session(struct nfs_client *clp, int reset)
      if (status)
              goto out;
 
+     /* Signal nfs41_setup_sequence that the session is ready for use */
+     clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
      ptr = (unsigned *)&session->sess_id.data[0];
      dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
              clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
fs/nfs/nfs4state.c +2 -2
index 1394dfb..09ca30b 100644
@@ -1252,17 +1252,20 @@ static void nfs4_state_manager(struct nfs_client *clp)
                              continue;
              }
              /* Initialize or reset the session */
-             if (test_and_clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
-                && nfs4_has_session(clp)) {
+             if (test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)
+                 && nfs4_has_session(clp)) {
                      if (clp->cl_cons_state == NFS_CS_SESSION_INITING)

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 1264

Quoted 10 lines
fs/nfs/nfs4state.c +4 -3
                              status = nfs4_initialize_session(clp);
                      else
                              status = nfs4_reset_session(clp);
-                     if (status) {
-                             if (status == -NFS4ERR_STALE_CLIENTID)
-                                     continue;
+                     if (status == -NFS4ERR_STALE_CLIENTID)
+                             continue;
+                     /* For error case. On success the bit is cleared in
+                      * nfs4_proc_create_session */

Why the separation?
Why not handle both success and error cases here?

Quoted 8 lines
Quoted 6 lines

We don't clear the bit on NFS4ERR_STALE_CLIENTID because we first need an EXCHANGE_ID and then session reset and we don't want any rpc's queued on the slot_tbl_waitq to run. The check for NFS4ERR_STALE_CLIENTID is in the nfs4_state_manager. Also, all other cases in the state manager clear the bits used - so I thought it best to follow suit.

I agree, so why clear the NFS4CLNT_SESSION_SETUP bit on success in nfs4_proc_create_session()

so that nfs4_proc_get_lease_time can use the newly created session.

Quoted 2 lines

Also, nfs4_proc_create_session() clears NFS4CLNT_LEASE_EXPIRED which is test_and_cleared by the state manager...

True and harmless.

-->Andy

Quoted 19 lines

Benny

Quoted 17 lines

-->Andy

Quoted 15 lines

Benny

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 1271

Quoted 8 lines
fs/nfs/nfs4state.c +3 -1
+                     clear_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
+
+                     if (status)
                              goto out_error;
-                     }
              }
              /* First recover reboot state... */
              if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {

_______________________________________________
pNFS mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/pnfs