Address several issues with TEST_STATEID
Subsystems (2)
cover Address several issues with TEST_STATEID
Hi-
While testing the recently introduced PURGE_STATE logic, I found some issues with the error handling logic under nfs41_open_expired().
After fixing these issues, I am able to get Connectathon basic, general, and special tests to pass with a server rigged to assert SEQ4_STATUS_ADMIN_STATE_REVOKED at regular intervals. The Connectathon lock tests encounter a deadlock, which I've already reported, that appears to pre-date PURGE_STATE.
---
Chuck Lever (4):
NFS: Refactor nfs41_check_expired_stateid()
NFS: state reclaim clears OPEN state
NFS: Properly sort TEST_STATEID results
NFS: Clean up TEST_STATEID and FREE_STATEID proc error reporting
fs/nfs/nfs4proc.c | 144 ++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 115 insertions(+), 29 deletions(-)
Signature · 1 line
Chuck Lever
PATCH 1/4 NFS: Clean up TEST_STATEID and FREE_STATEID proc error reporting
The TEST_STATEID and FREE_STATEID operations can return NFS4ERR_BAD_STATEID, NFS4ERR_OLD_STATEID, or NFS4ERR_DEADSESSION. These error values should not be passed to nfs4_handle_exception(), since that will recursively kick off state recovery, resulting in a deadlock.
The reason to continue using nfs4_handle_exception() is to deal with NFS4ERR_DELAY. [ Sidebar: It seems to me we are dealing with only DELAY in enough places now that it might make sense to add a version of nfs4_handle_exception() that handles only GRACE and DELAY) ].
Moreover, specifically when the TEST_STATEID operation returns NFS4_OK, res.status can contain one of these errors. _nfs41_test_stateid() replaces NFS4_OK with the value in res.status, which is then returned to callers.
But res.status is not passed through nfs4_stat_to_errno(), and thus is a positive NFS4ERR value. Currently callers are only interested in !NFS4_OK, and nfs4_handle_exception() ignores positive values, so this oversight hasn't bitten us so far.
Bryan agrees the original intent was to return res.status as a negative NFS4ERR value to callers of nfs41_test_stateid(), as long as no state ID recovery is attempted.
As a finishing touch, add appropriate documenting comments and some debugging printk's. Documenting comments are added to record the intent of the return value.
---
fs/nfs/nfs4proc.c | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 40 insertions(+), 11 deletions(-)
fs/nfs/nfs4proc.c +40 -11
@@ -6384,22 +6384,36 @@ static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) .rpc_resp = &res, }; +dprintk ("NFS call test_stateid %p\n" , stateid);nfs41_init_sequence (&args.seq_args, &res.seq_res,0 ); status =nfs4_call_sync_sequence (server->client, server, &msg, &args.seq_args, &res.seq_res,1 ); - -if (status ==NFS_OK ) -return res.status; -return status; +if (status !=NFS_OK ) { +dprintk ("NFS reply test_stateid: failed, %d\n" , status); +return status; + } +dprintk ("NFS reply test_stateid: succeeded, %d\n" , -res.status); +return -res.status; } +/** +* nfs41_test_stateid - perform a TEST_STATEID operation +* +* @server: NFS server that may know about "stateid" +* @stateid: state ID to test +* +* Returns NFS_OK if the server recognizes the state ID as valid. +* Otherwise a negative NFS4ERR value is returned if the operation +* failed or the state ID is not currently valid. +*/ static int nfs41_test_stateid (struct nfs_server *server,nfs4_stateid *stateid) {struct nfs4_exception exception = { };int err;do { - err =nfs4_handle_exception (server, -_nfs41_test_stateid (server, stateid), - &exception); + err =_nfs41_test_stateid (server, stateid); +if (err != -NFS4ERR_DELAY ) +break ; +nfs4_handle_exception (server, err, &exception); }while (exception.retry);return err; }
@@ -6415,19 +6429,34 @@ static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) .rpc_argp = &args, .rpc_resp = &res, }; +int status; +dprintk ("NFS call free_stateid %p\n" , stateid);nfs41_init_sequence (&args.seq_args, &res.seq_res,0 ); -return nfs4_call_sync_sequence (server->client, server, &msg, &args.seq_args, &res.seq_res,1 ); + status =nfs4_call_sync_sequence (server->client, server, &msg, + &args.seq_args, &res.seq_res,1 ); +dprintk ("NFS reply free_stateid: %d\n" , status); +return status; } +/** +* nfs41_free_stateid - perform a FREE_STATEID operation +* +* @server: NFS server that may know about "stateid" +* @stateid: state ID to release +* +* Returns NFS_OK if the server freed the state ID. Otherwise a +* negative NFS4ERR value is returned if the operation failed. +*/ static int nfs41_free_stateid (struct nfs_server *server,nfs4_stateid *stateid) {struct nfs4_exception exception = { };int err;do { - err =nfs4_handle_exception (server, -_nfs4_free_stateid (server, stateid), - &exception); + err =_nfs4_free_stateid (server, stateid); +if (err != -NFS4ERR_DELAY ) +break ; +nfs4_handle_exception (server, err, &exception); }while (exception.retry);return err; }
PATCH 2/4 NFS: Properly sort TEST_STATEID results
In reply to Chuck LeverThe result of a TEST_STATEID operation can indicate a few different things. If NFS_OK is returned, then the client can continue using the state ID under test, and skip recovery. RFC 5661 says that if and only if the state ID was revoked, then the client must perform an explicit FREE_STATEID before trying to re-open.
However, if the server doesn't recognize the state ID at all, then the client should immediately continue with open recovery.
---
fs/nfs/nfs4proc.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 files changed, 36 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +36 -2
@@ -1733,6 +1733,14 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta }#if defined(CONFIG_NFS_V4_1 ) +/** +* nfs41_check_expired_stateid - does a state ID need recovery? +* +* @state: NFSv4 open state for a file +* +* Returns NFS_OK if recovery for this state ID is now finished. +* Otherwise a negative NFS4ERR value is returned. +*/ static int nfs41_check_expired_stateid (struct nfs4_state *state,nfs4_stateid *stateid,unsigned int flags) {int status =NFS_OK ;
@@ -1740,9 +1748,19 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *sif (state->flags & flags) { status =nfs41_test_stateid (server, stateid); -if (status !=NFS_OK ) { +switch (status) { +case NFS_OK : +/* server recognizes this one, don't re-open */ +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +/* state was revoked, free then re-open */ nfs41_free_stateid (server, stateid); state->flags &= ~flags; +break ; +default : +/* anything else: go ahead and re-open it */ +break ; } }return status;
@@ -4642,6 +4660,14 @@ out: }#if defined(CONFIG_NFS_V4_1 ) +/** +* nfs41_check_expired_locks - clear lock state IDs +* +* @state: NFSv4 open state for a file +* +* Returns NFS_OK if recovery for this state ID is now finished. +* Otherwise a negative NFS4ERR value is returned. +*/ static int nfs41_check_expired_locks (struct nfs4_state *state) {int status, ret =NFS_OK ;
@@ -4651,9 +4677,17 @@ static int nfs41_check_expired_locks(struct nfs4_state *state)list_for_each_entry (lsp, &state->lock_states, ls_locks) {if (lsp->ls_flags &NFS_LOCK_INITIALIZED ) { status =nfs41_test_stateid (server, &lsp->ls_stateid); -if (status !=NFS_OK ) { +switch (status) { +case NFS_OK : +/* server recognizes this one, don't re-lock */ +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +/* lock was revoked, free then re-lock */ nfs41_free_stateid (server, &lsp->ls_stateid); lsp->ls_flags &= ~NFS_LOCK_INITIALIZED ; +/*FALLTHROUGH*/ +default : ret = status; } }
Re: [PATCH 2/4] NFS: Properly sort TEST_STATEID results
Quoted 38 lines · Chuck Lever
The result of a
TEST_STATEIDoperation can indicate a few different things. IfNFS_OKis returned, then the client can continue using the state ID under test, and skip recovery. RFC 5661 says that if and only if the state ID was revoked, then the client must perform an explicitFREE_STATEIDbefore trying to re-open.However, if the server doesn't recognize the state ID at all, then the client should immediately continue with open recovery.
Signed-off-by Chuck Lever <[email protected]>---
fs/nfs/nfs4proc.c| 38 ++++++++++++++++++++++++++++++++++++--1 files changed, 36 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +8
-0@@ -1733,6 +1733,14 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta }#if defined(CONFIG_NFS_V4_1 ) +/** +* nfs41_check_expired_stateid - does a state ID need recovery? +* +* @state: NFSv4 open state for a file +* +* Returns NFS_OK if recovery for this state ID is now finished. +* Otherwise a negative NFS4ERR value is returned. +*/ static int nfs41_check_expired_stateid (struct nfs4_state *state,nfs4_stateid *stateid,unsigned int flags) {int status =NFS_OK ;@@ -1740,9 +1748,19 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *sif (state->flags & flags) { status =nfs41_test_stateid (server, stateid);
fs/nfs/nfs4proc.c static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *s · line 1759
Quoted 10 lines
fs/nfs/nfs4proc.c +7
-1-if (status !=NFS_OK ) { +switch (status) { +case NFS_OK : +/* server recognizes this one, don't re-open */ +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +/* state was revoked, free then re-open */ nfs41_free_stateid (server, stateid); state->flags &= ~flags;
Actually, I think we want to clear these flags in any case when status != NFS_OK.
Quoted 46 lines
fs/nfs/nfs4proc.c +21
-2+break ; +default : +/* anything else: go ahead and re-open it */ +break ; } }return status;@@ -4642,6 +4660,14 @@ out: }#if defined(CONFIG_NFS_V4_1 ) +/** +* nfs41_check_expired_locks - clear lock state IDs +* +* @state: NFSv4 open state for a file +* +* Returns NFS_OK if recovery for this state ID is now finished. +* Otherwise a negative NFS4ERR value is returned. +*/ static int nfs41_check_expired_locks (struct nfs4_state *state) {int status, ret =NFS_OK ;@@ -4651,9 +4677,17 @@ static int nfs41_check_expired_locks(struct nfs4_state *state)list_for_each_entry (lsp, &state->lock_states, ls_locks) {if (lsp->ls_flags &NFS_LOCK_INITIALIZED ) { status =nfs41_test_stateid (server, &lsp->ls_stateid); -if (status !=NFS_OK ) { +switch (status) { +case NFS_OK : +/* server recognizes this one, don't re-lock */ +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +/* lock was revoked, free then re-lock */ nfs41_free_stateid (server, &lsp->ls_stateid); lsp->ls_flags &= ~NFS_LOCK_INITIALIZED ; +/*FALLTHROUGH*/ +default : ret = status; } } --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 2/4] NFS: Properly sort TEST_STATEID results
In reply to Chuck LeverT24gRnJpLCAyMDEyLTA2LTAxIGF0IDExOjM4IC0wNDAw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DFfZnJlZV9zdGF0ZWlkKHNlcnZlciwg JmxzcC0+bHNfc3RhdGVpZCk7DQo+ICAJCQkJbHNwLT5sc19mbGFncyAmPSB+TkZTX0xPQ0tfSU5J VElBTElaRUQ7DQo+ICsJCQkJLypGQUxMVEhST1VHSCovDQoNCldoeSBkbyB3ZSBuZWVkIHRoaXMg Y29tbWVudD8gSXQgc2hvdWxkIGJlIG9idmlvdXMuDQoNCj4gKwkJCWRlZmF1bHQ6DQo+ICAJCQkJ cmV0ID0gc3RhdHVzOw0KPiAgCQkJfQ0KPiAgCQl9DQo+IA0KPiAtLQ0KPiBUbyB1bnN1YnNjcmli ZSBmcm9tIHRoaXMgbGlzdDogc2VuZCB0aGUgbGluZSAidW5zdWJzY3JpYmUgbGludXgtbmZzIiBp bg0KPiB0aGUgYm9keSBvZiBhIG1lc3NhZ2UgdG8gbWFqb3Jkb21vQHZnZXIua2VybmVsLm9yZw0K PiBNb3JlIG1ham9yZG9tbyBpbmZvIGF0ICBodHRwOi8vdmdlci5rZXJuZWwub3JnL21ham9yZG9t by1pbmZvLmh0bWwNCg0KLS0gDQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFp bnRhaW5lcg0KDQpOZXRBcHANClRyb25kLk15a2xlYnVzdEBuZXRhcHAuY29tDQp3d3cubmV0YXBw LmNvbQ0KDQo=
Re: [PATCH 2/4] NFS: Properly sort TEST_STATEID results
Quoted 21 lines · Trond
Quoted 7 lines · Chuck Lever
fs/nfs/nfs4proc.c +1
-1@@ -1740,9 +1748,19 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *sif (state->flags & flags) { status =nfs41_test_stateid (server, stateid); -if (status !=NFS_OK ) { +switch (status) {fs/nfs/nfs4proc.c static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *s · line 1761
Quoted 10 lines
fs/nfs/nfs4proc.c +8
-0+case NFS_OK : +/* server recognizes this one, don't re-open */ +break ; +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +/* state was revoked, free then re-open */ nfs41_free_stateid (server, stateid); state->flags &= ~flags; +break ; +default :Please don't add empty "default:" cases.
Quoted 4 lines
fs/nfs/nfs4proc.c static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *s · line 1763
Quoted 2 lines
fs/nfs/nfs4proc.c +2
-0+/* anything else: go ahead and re-open it */ +break ;That last "break" is unnecessary too in standard C99.
OK, all fixed for next version. I'll wait for additional comments before reposting.
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
PATCH 3/4 NFS: state reclaim clears OPEN state
In reply to Chuck LeverBefore beginning state recovery, the state manager zaps open and lock state for each open file, thus the "state->flags & flags" test always fails during reclaim. But open recovery is still needed for these files.
To force a call to nfs4_open_expired(), change the default return value for nfs41_check_expired_stateid() to force open recovery and nfs41_check_locks() to force lock recovery if the requested flags are clear. Fix suggested by Bryan Schumaker.
The presence of a delegation state ID must not prevent normal open recovery. The delegation state ID must be cleared if it was revoked, but once cleared I don't think it's presence or absence has any bearing on whether open recovery is still needed.
The logic in nfs41_lock_expired() is cleaned up to match the form of nfs41_open_expired(), but no change in behavior is expected there.
---
fs/nfs/nfs4proc.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
fs/nfs/nfs4proc.c +11 -11
@@ -1743,8 +1743,8 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta*/ static int nfs41_check_expired_stateid (struct nfs4_state *state,nfs4_stateid *stateid,unsigned int flags) { -int status =NFS_OK ;struct nfs_server *server =NFS_SERVER (state->inode); +int status = -NFS4ERR_BAD_STATEID ;if (state->flags & flags) { status =nfs41_test_stateid (server, stateid);
@@ -1768,16 +1768,16 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *sstatic int nfs41_open_expired (struct nfs4_state_owner *sp,struct nfs4_state *state) { -int deleg_status, open_status;int deleg_flags =1 <<NFS_DELEGATED_STATE ;int open_flags = (1 <<NFS_O_RDONLY_STATE ) | (1 <<NFS_O_WRONLY_STATE ) | (1 <<NFS_O_RDWR_STATE ); +int status; - deleg_status =nfs41_check_expired_stateid (state, &state->stateid, deleg_flags); - open_status =nfs41_check_expired_stateid (state, &state->open_stateid, open_flags); +nfs41_check_expired_stateid (state, &state->stateid, deleg_flags); + status =nfs41_check_expired_stateid (state, &state->open_stateid, open_flags); -if ((deleg_status ==NFS_OK ) && (open_status ==NFS_OK )) -return NFS_OK ; -return nfs4_open_expired (sp, state); +if (status !=NFS_OK ) + status =nfs4_open_expired (sp, state); +return status; }#endif
@@ -4670,7 +4670,7 @@ out:*/ static int nfs41_check_expired_locks (struct nfs4_state *state) { -int status, ret =NFS_OK ; +int status, ret = -NFS4ERR_BAD_STATEID ;struct nfs4_lock_state *lsp;struct nfs_server *server =NFS_SERVER (state->inode);
@@ -4702,9 +4702,9 @@ static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *requesif (test_bit (LK_STATE_IN_USE , &state->flags)) status =nfs41_check_expired_locks (state); -if (status ==NFS_OK ) -return status; - return nfs4_lock_expired(state, request); +if (status !=NFS_OK ) + status =nfs4_lock_expired (state, request); + return status; }#endif
PATCH 4/4 NFS: Refactor nfs41_check_expired_stateid()
In reply to Chuck LeverClean up: The logic for dealing with a delegation state ID and an open state ID is now sufficiently distinct that I've refactored nfs41_check_expired_stateid() into two separate functions.
Instead of open-coded flag manipulation, use test_bit() and clear_bit() just like all other accessors of the state->flag field.
This also eliminates a bunch of unnecessary integer type conversions.
---
fs/nfs/nfs4proc.c | 41 ++++++++++++++++++++++++++++++++--------- 1 files changed, 32 insertions(+), 9 deletions(-)
fs/nfs/nfs4proc.c +32 -9
@@ -1734,19 +1734,42 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta#if defined(CONFIG_NFS_V4_1 )/** -* nfs41_check_expired_stateid - does a state ID need recovery? +* nfs41_clear_delegation_stateid - possibly clear revoked delegation state ID * -* @state: NFSv4 open state for a file +* @state: NFSv4 open state for an inode +*/ +static void nfs41_clear_delegation_stateid (struct nfs4_state *state) +{ +struct nfs_server *server =NFS_SERVER (state->inode); +nfs4_stateid *stateid = &state->stateid; + +if (test_bit (NFS_DELEGATED_STATE , &state->flags) !=0 ) +switch (nfs41_test_stateid (server, stateid)) { +case -NFS4ERR_ADMIN_REVOKED : +case -NFS4ERR_DELEG_REVOKED : +nfs41_free_stateid (server, stateid); +clear_bit (NFS_DELEGATED_STATE , &state->flags); +break ; + } +} + +/** +* nfs41_check_open_stateid - clear open state ID +* +* @state: NFSv4 open state for an inode * * Returns NFS_OK if recovery for this state ID is now finished. * Otherwise a negative NFS4ERR value is returned. */ -static int nfs41_check_expired_stateid (struct nfs4_state *state,nfs4_stateid *stateid,unsigned int flags) +static int nfs41_check_open_stateid (struct nfs4_state *state) {struct nfs_server *server =NFS_SERVER (state->inode); +nfs4_stateid *stateid = &state->stateid;int status = -NFS4ERR_BAD_STATEID ; -if (state->flags & flags) { +if ((test_bit (NFS_O_RDONLY_STATE , &state->flags) !=0 ) || + (test_bit (NFS_O_WRONLY_STATE , &state->flags) !=0 ) || + (test_bit (NFS_O_RDWR_STATE , &state->flags) !=0 )) { status =nfs41_test_stateid (server, stateid);switch (status) {case NFS_OK :
@@ -1756,7 +1779,9 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *scase -NFS4ERR_DELEG_REVOKED :/* state was revoked, free then re-open */ nfs41_free_stateid (server, stateid); - state->flags &= ~flags; +clear_bit (NFS_O_RDONLY_STATE , &state->flags); +clear_bit (NFS_O_WRONLY_STATE , &state->flags); +clear_bit (NFS_O_RDWR_STATE , &state->flags);break ;default :/* anything else: go ahead and re-open it */
@@ -1768,12 +1793,10 @@ static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *sstatic int nfs41_open_expired (struct nfs4_state_owner *sp,struct nfs4_state *state) { -int deleg_flags =1 <<NFS_DELEGATED_STATE ; -int open_flags = (1 <<NFS_O_RDONLY_STATE ) | (1 <<NFS_O_WRONLY_STATE ) | (1 <<NFS_O_RDWR_STATE );int status; -nfs41_check_expired_stateid (state, &state->stateid, deleg_flags); - status =nfs41_check_expired_stateid (state, &state->open_stateid, open_flags); +nfs41_clear_delegation_stateid (state); + status =nfs41_check_open_stateid (state);if (status !=NFS_OK ) status =nfs4_open_expired (sp, state);