NFSD: add FREE_STATEID and TEST_STATEID operations
Subsystems (2)
v5 cover NFSD: add FREE_STATEID and TEST_STATEID operations
From: Bryan Schumaker <[email protected]>
These patches add FREE_STATEID and TEST_STATEID to the NFS server. I initially tested them by hard coding calls both before and after the client completes a CLOSE operation. Eventually, I modified the client's state recovery code to place these calls. I would turn off networking on the client for two minutes so it would expired on the server and force recovery once networking was reenabled.
I later added in a fault injection framework on the server. I would have the client acquire a lock, tell the server to delete it, and then have the client use TEST_STATEID and FREE_STATEID to recover the lock.
v2:
- FREE_STATEID
- Free open, lock, and delegation state ids correctly
- Use the check_for_locks() function to check for locks
- TEST_STATEID
- Remove openmode check
- Sanity check on size of stateid list
- Delay decoding stateid list until encoding the reply
v3:
- FREE_STATEID
- Open stateids and delegations are never freeable (return nfserr_locks_held)
- TEST_STATEID
- Remove unused arguments from a function call
- Store and use the HAS_SESSION flag for validating stateids
v4:
- FREE_STATEID
- Remove unused argument from nfs4_free_lock_stateid()
- TEST_STATEID
- Remove double call to nfs4_validate_stateid()
v5:
- FREE_STATEID
- Acquire the state lock before using the state lists
- TEST_STATEID
- Acquire the state lock before using the state lists
- Bryan
v5 cover NFSD: add FREE_STATEID and TEST_STATEID operations
This operation is used by the client to tell the server to free a stateid.
--- fs/nfsd/nfs4proc.c | 5 ++ fs/nfsd/nfs4state.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 32 +++++++++++++- fs/nfsd/xdr4.h | 8 +++ 4 files changed, 161 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +5 -0
@@ -1412,6 +1412,11 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_flags = OP_HANDLES_WRONGSEC, .op_name = "OP_SECINFO_NO_NAME", }, + [OP_FREE_STATEID] = { + .op_func = (nfsd4op_func)nfsd4_free_stateid, + .op_flags = ALLOWED_WITHOUT_FH, + .op_name = "OP_FREE_STATEID", + }, };static const char *nfsd4_op_name (unsigned opnum)
fs/nfsd/nfs4state.c +118 -0
151 lines not on this page · raw message
fs/nfsd/nfs4xdr.c +30 -2
@@ -1246,6 +1246,19 @@ nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_free_stateid (struct nfsd4_compoundargs *argp, +struct nfsd4_free_stateid *free_stateid) +{ +DECODE_HEAD ; + +READ_BUF (sizeof (stateid_t)); +READ32 (free_stateid->fr_stateid.si_generation); +COPYMEM (&free_stateid->fr_stateid.si_opaque,sizeof (stateid_opaque_t)); + +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_sequence (struct nfsd4_compoundargs *argp,struct nfsd4_sequence *seq) {
@@ -1370,7 +1383,7 @@ static nfsd4_dec nfsd41_dec_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
@@ -3116,6 +3129,21 @@ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, }static __be32 +nfsd4_encode_free_stateid (struct nfsd4_compoundres *resp,int nfserr, +struct nfsd4_free_stateid *free_stateid) +{ +__be32 *p; + +if (nfserr) +return nfserr; + +RESERVE_SPACE (4 ); +WRITE32 (nfserr); +ADJUST_ARGS (); +return nfserr; +} + +static __be32 nfsd4_encode_sequence (struct nfsd4_compoundres *resp,int nfserr,struct nfsd4_sequence *seq) {
@@ -3196,7 +3224,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, + [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
fs/nfsd/xdr4.h +8 -0
@@ -342,6 +342,11 @@ struct nfsd4_setclientid_confirm {nfs4_verifier sc_confirm; }; +struct nfsd4_free_stateid { +stateid_t fr_stateid;/* request */ +__be32 fr_status;/* response */ +}; +/* also used for NVERIFY */ struct nfsd4_verify {u32 ve_bmval[3 ];/* request */
@@ -432,6 +437,7 @@ struct nfsd4_op {struct nfsd4_destroy_session destroy_session;struct nfsd4_sequence sequence;struct nfsd4_reclaim_complete reclaim_complete; +struct nfsd4_free_stateid free_stateid; } u;struct nfs4_replay * replay; };
@@ -564,6 +570,8 @@ extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);extern __be32 nfsd4_renew (struct svc_rqst *rqstp,struct nfsd4_compound_state *,clientid_t *clid); +extern __be32 nfsd4_free_stateid (struct svc_rqst *rqstp, +struct nfsd4_compound_state *,struct nfsd4_free_stateid *free_stateid);#endif /*
Signature · 1 line
1.7.6
I don't know what happened to the subject of this email. The file that I passed to git send-email has the correct line...
Subject: [PATCH v5 1/2] NFSD: added FREE_STATEID operation
This operation is used by the client to tell the server to free a stateid.
Quoted 284 lines · On 07/13/2011 10:50 AM, [email protected] wrote:
This operation is used by the client to tell the server to free a stateid.
Signed-off-by Bryan Schumaker <[email protected]>--- fs/nfsd/nfs4proc.c | 5 ++ fs/nfsd/nfs4state.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 32 +++++++++++++- fs/nfsd/xdr4.h | 8 +++ 4 files changed, 161 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +5
-0@@ -1412,6 +1412,11 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_flags = OP_HANDLES_WRONGSEC, .op_name = "OP_SECINFO_NO_NAME", }, + [OP_FREE_STATEID] = { + .op_func = (nfsd4op_func)nfsd4_free_stateid, + .op_flags = ALLOWED_WITHOUT_FH, + .op_name = "OP_FREE_STATEID", + }, };static const char *nfsd4_op_name (unsigned opnum)fs/nfsd/nfs4state.c +118
-0@@ -60,9 +60,12 @@ static u64 current_sessionid = 1;/* forward declarations */ static struct nfs4_stateid *find_stateid (stateid_t *stid,int flags); +static struct nfs4_stateid *search_for_stateid (stateid_t *stid); +static struct nfs4_delegation *search_for_delegation (stateid_t *stid);static struct nfs4_delegation *find_delegation_stateid (struct inode *ino,stateid_t *stid);static char user_recovery_dirname[PATH_MAX ] ="/var/lib/nfs/v4recovery" ;static void nfs4_set_recdir (char *recdir); +static int check_for_locks (struct nfs4_file *filp,struct nfs4_stateowner *lowner);/* Locking: */ @@ -3137,6 +3140,11 @@ static int is_delegation_stateid(stateid_t *stateid)return stateid->si_fileid ==0 ; } +static int is_open_stateid (struct nfs4_stateid *stateid) +{ +return stateid->st_openstp ==NULL ; +} +/* * Checks for stateid operations */ @@ -3216,6 +3224,70 @@ out:return status; } +static __be32 +nfsd4_free_delegation_stateid (stateid_t *stateid) +{ +struct nfs4_delegation *dp =search_for_delegation (stateid); +if (dp) +return nfserr_locks_held; +return nfserr_bad_stateid; +} + +static __be32 +nfsd4_free_lock_stateid (struct nfs4_stateid *stp) +{ +if (check_for_locks (stp->st_file, stp->st_stateowner)) +return nfserr_locks_held; +release_lock_stateid (stp); +return nfs_ok; +} + +/* +* Free a state id +*/ +__be32 +nfsd4_free_stateid (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_free_stateid *free_stateid) +{ +stateid_t *stateid = &free_stateid->fr_stateid; +struct nfs4_stateid *stp; +__be32 ret; + +nfs4_lock_state (); +if (is_delegation_stateid (stateid)) { + ret =nfsd4_free_delegation_stateid (stateid); + goto out; + } + + stp =search_for_stateid (stateid); +if (!stp) { + ret = nfserr_bad_stateid; + goto out; + } +if (stateid->si_generation !=0 ) { +if (stateid->si_generation < stp->st_stateid.si_generation) { + ret = nfserr_old_stateid; + goto out; + } +if (stateid->si_generation > stp->st_stateid.si_generation) { + ret = nfserr_bad_stateid; + goto out; + } + } + +if (is_open_stateid (stp)) { + ret = nfserr_locks_held; + goto out; + }else { + ret =nfsd4_free_lock_stateid (stp); + goto out; + } + +out: +nfs4_unlock_state (); +return ret; +} +static inline int setlkflg (int type) {@@ -3594,6 +3666,14 @@ static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE];static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE ];static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE ]; +static int +same_stateid (stateid_t *id_one,stateid_t *id_two) +{ +if (id_one->si_stateownerid != id_two->si_stateownerid) +return 0 ; +return id_one->si_fileid == id_two->si_fileid; +} +static struct nfs4_stateid *find_stateid (stateid_t *stid,int flags) {@@ -3623,6 +3703,44 @@ find_stateid(stateid_t *stid, int flags)return NULL ; } +static struct nfs4_stateid * +search_for_stateid (stateid_t *stid) +{ +struct nfs4_stateid *local; +unsigned int hashval =stateid_hashval (stid->si_stateownerid, stid->si_fileid); + +list_for_each_entry (local, &lockstateid_hashtbl[hashval], st_hash) { +if (same_stateid (&local->st_stateid, stid)) +return local; + } + +list_for_each_entry (local, &stateid_hashtbl[hashval], st_hash) { +if (same_stateid (&local->st_stateid, stid)) +return local; + } +return NULL ; +} + +static struct nfs4_delegation * +search_for_delegation (stateid_t *stid) +{ +struct nfs4_file *fp; +struct nfs4_delegation *dp; +struct list_head *pos; +int i; + +for (i =0 ; i <FILE_HASH_SIZE ; i++) { +list_for_each_entry (fp, &file_hashtbl[i], fi_hash) { +list_for_each (pos, &fp->fi_delegations) { + dp = list_entry(pos, struct nfs4_delegation, dl_perfile); +if (same_stateid (&dp->dl_stateid, stid)) +return dp; + } + } + } +return NULL ; +} +static struct nfs4_delegation *find_delegation_stateid (struct inode *ino,stateid_t *stid) {fs/nfsd/nfs4xdr.c +30
-2@@ -1246,6 +1246,19 @@ nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_free_stateid (struct nfsd4_compoundargs *argp, +struct nfsd4_free_stateid *free_stateid) +{ +DECODE_HEAD ; + +READ_BUF (sizeof (stateid_t)); +READ32 (free_stateid->fr_stateid.si_generation); +COPYMEM (&free_stateid->fr_stateid.si_opaque,sizeof (stateid_opaque_t)); + +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_sequence (struct nfsd4_compoundargs *argp,struct nfsd4_sequence *seq) {@@ -1370,7 +1383,7 @@ static nfsd4_dec nfsd41_dec_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,@@ -3116,6 +3129,21 @@ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, }static __be32 +nfsd4_encode_free_stateid (struct nfsd4_compoundres *resp,int nfserr, +struct nfsd4_free_stateid *free_stateid) +{ +__be32 *p; + +if (nfserr) +return nfserr; + +RESERVE_SPACE (4 ); +WRITE32 (nfserr); +ADJUST_ARGS (); +return nfserr; +} + +static __be32 nfsd4_encode_sequence (struct nfsd4_compoundres *resp,int nfserr,struct nfsd4_sequence *seq) {@@ -3196,7 +3224,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, + [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,fs/nfsd/xdr4.h +8
-0@@ -342,6 +342,11 @@ struct nfsd4_setclientid_confirm {nfs4_verifier sc_confirm; }; +struct nfsd4_free_stateid { +stateid_t fr_stateid;/* request */ +__be32 fr_status;/* response */ +}; +/* also used for NVERIFY */ struct nfsd4_verify {u32 ve_bmval[3 ];/* request */ @@ -432,6 +437,7 @@ struct nfsd4_op {struct nfsd4_destroy_session destroy_session;struct nfsd4_sequence sequence;struct nfsd4_reclaim_complete reclaim_complete; +struct nfsd4_free_stateid free_stateid; } u;struct nfs4_replay * replay; };@@ -564,6 +570,8 @@ extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);extern __be32 nfsd4_renew (struct svc_rqst *rqstp,struct nfsd4_compound_state *,clientid_t *clid); +extern __be32 nfsd4_free_stateid (struct svc_rqst *rqstp, +struct nfsd4_compound_state *,struct nfsd4_free_stateid *free_stateid);#endif /*
PATCH v5 1/2 NFSD: added FREE_STATEID operation
In reply to [email protected]This operation is used by the client to tell the server to free a stateid.
--- fs/nfsd/nfs4proc.c | 5 ++ fs/nfsd/nfs4state.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 32 +++++++++++++- fs/nfsd/xdr4.h | 8 +++ 4 files changed, 161 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +5 -0
@@ -1412,6 +1412,11 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_flags = OP_HANDLES_WRONGSEC, .op_name = "OP_SECINFO_NO_NAME", }, + [OP_FREE_STATEID] = { + .op_func = (nfsd4op_func)nfsd4_free_stateid, + .op_flags = ALLOWED_WITHOUT_FH, + .op_name = "OP_FREE_STATEID", + }, };static const char *nfsd4_op_name (unsigned opnum)
fs/nfsd/nfs4state.c +118 -0
151 lines not on this page · raw message
fs/nfsd/nfs4xdr.c +30 -2
@@ -1246,6 +1246,19 @@ nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_free_stateid (struct nfsd4_compoundargs *argp, +struct nfsd4_free_stateid *free_stateid) +{ +DECODE_HEAD ; + +READ_BUF (sizeof (stateid_t)); +READ32 (free_stateid->fr_stateid.si_generation); +COPYMEM (&free_stateid->fr_stateid.si_opaque,sizeof (stateid_opaque_t)); + +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_sequence (struct nfsd4_compoundargs *argp,struct nfsd4_sequence *seq) {
@@ -1370,7 +1383,7 @@ static nfsd4_dec nfsd41_dec_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
@@ -3116,6 +3129,21 @@ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, }static __be32 +nfsd4_encode_free_stateid (struct nfsd4_compoundres *resp,int nfserr, +struct nfsd4_free_stateid *free_stateid) +{ +__be32 *p; + +if (nfserr) +return nfserr; + +RESERVE_SPACE (4 ); +WRITE32 (nfserr); +ADJUST_ARGS (); +return nfserr; +} + +static __be32 nfsd4_encode_sequence (struct nfsd4_compoundres *resp,int nfserr,struct nfsd4_sequence *seq) {
@@ -3196,7 +3224,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, + [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
fs/nfsd/xdr4.h +8 -0
@@ -342,6 +342,11 @@ struct nfsd4_setclientid_confirm {nfs4_verifier sc_confirm; }; +struct nfsd4_free_stateid { +stateid_t fr_stateid;/* request */ +__be32 fr_status;/* response */ +}; +/* also used for NVERIFY */ struct nfsd4_verify {u32 ve_bmval[3 ];/* request */
@@ -432,6 +437,7 @@ struct nfsd4_op {struct nfsd4_destroy_session destroy_session;struct nfsd4_sequence sequence;struct nfsd4_reclaim_complete reclaim_complete; +struct nfsd4_free_stateid free_stateid; } u;struct nfs4_replay * replay; };
@@ -564,6 +570,8 @@ extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);extern __be32 nfsd4_renew (struct svc_rqst *rqstp,struct nfsd4_compound_state *,clientid_t *clid); +extern __be32 nfsd4_free_stateid (struct svc_rqst *rqstp, +struct nfsd4_compound_state *,struct nfsd4_free_stateid *free_stateid);#endif /*
Signature · 1 line
1.7.6
Re: [PATCH v5 1/2] NFSD: added FREE_STATEID operation
Quoted 2 lines · Bryan Schumaker
This operation is used by the client to tell the server to free a stateid.
Thanks, applying.--b.
Quoted 284 lines
Signed-off-by Bryan Schumaker <[email protected]>--- fs/nfsd/nfs4proc.c | 5 ++ fs/nfsd/nfs4state.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 32 +++++++++++++- fs/nfsd/xdr4.h | 8 +++ 4 files changed, 161 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +5
-0@@ -1412,6 +1412,11 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_flags = OP_HANDLES_WRONGSEC, .op_name = "OP_SECINFO_NO_NAME", }, + [OP_FREE_STATEID] = { + .op_func = (nfsd4op_func)nfsd4_free_stateid, + .op_flags = ALLOWED_WITHOUT_FH, + .op_name = "OP_FREE_STATEID", + }, };static const char *nfsd4_op_name (unsigned opnum)fs/nfsd/nfs4state.c +118
-0@@ -60,9 +60,12 @@ static u64 current_sessionid = 1;/* forward declarations */ static struct nfs4_stateid *find_stateid (stateid_t *stid,int flags); +static struct nfs4_stateid *search_for_stateid (stateid_t *stid); +static struct nfs4_delegation *search_for_delegation (stateid_t *stid);static struct nfs4_delegation *find_delegation_stateid (struct inode *ino,stateid_t *stid);static char user_recovery_dirname[PATH_MAX ] ="/var/lib/nfs/v4recovery" ;static void nfs4_set_recdir (char *recdir); +static int check_for_locks (struct nfs4_file *filp,struct nfs4_stateowner *lowner);/* Locking: */ @@ -3137,6 +3140,11 @@ static int is_delegation_stateid(stateid_t *stateid)return stateid->si_fileid ==0 ; } +static int is_open_stateid (struct nfs4_stateid *stateid) +{ +return stateid->st_openstp ==NULL ; +} +/* * Checks for stateid operations */ @@ -3216,6 +3224,70 @@ out:return status; } +static __be32 +nfsd4_free_delegation_stateid (stateid_t *stateid) +{ +struct nfs4_delegation *dp =search_for_delegation (stateid); +if (dp) +return nfserr_locks_held; +return nfserr_bad_stateid; +} + +static __be32 +nfsd4_free_lock_stateid (struct nfs4_stateid *stp) +{ +if (check_for_locks (stp->st_file, stp->st_stateowner)) +return nfserr_locks_held; +release_lock_stateid (stp); +return nfs_ok; +} + +/* +* Free a state id +*/ +__be32 +nfsd4_free_stateid (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_free_stateid *free_stateid) +{ +stateid_t *stateid = &free_stateid->fr_stateid; +struct nfs4_stateid *stp; +__be32 ret; + +nfs4_lock_state (); +if (is_delegation_stateid (stateid)) { + ret =nfsd4_free_delegation_stateid (stateid); + goto out; + } + + stp =search_for_stateid (stateid); +if (!stp) { + ret = nfserr_bad_stateid; + goto out; + } +if (stateid->si_generation !=0 ) { +if (stateid->si_generation < stp->st_stateid.si_generation) { + ret = nfserr_old_stateid; + goto out; + } +if (stateid->si_generation > stp->st_stateid.si_generation) { + ret = nfserr_bad_stateid; + goto out; + } + } + +if (is_open_stateid (stp)) { + ret = nfserr_locks_held; + goto out; + }else { + ret =nfsd4_free_lock_stateid (stp); + goto out; + } + +out: +nfs4_unlock_state (); +return ret; +} +static inline int setlkflg (int type) {@@ -3594,6 +3666,14 @@ static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE];static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE ];static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE ]; +static int +same_stateid (stateid_t *id_one,stateid_t *id_two) +{ +if (id_one->si_stateownerid != id_two->si_stateownerid) +return 0 ; +return id_one->si_fileid == id_two->si_fileid; +} +static struct nfs4_stateid *find_stateid (stateid_t *stid,int flags) {@@ -3623,6 +3703,44 @@ find_stateid(stateid_t *stid, int flags)return NULL ; } +static struct nfs4_stateid * +search_for_stateid (stateid_t *stid) +{ +struct nfs4_stateid *local; +unsigned int hashval =stateid_hashval (stid->si_stateownerid, stid->si_fileid); + +list_for_each_entry (local, &lockstateid_hashtbl[hashval], st_hash) { +if (same_stateid (&local->st_stateid, stid)) +return local; + } + +list_for_each_entry (local, &stateid_hashtbl[hashval], st_hash) { +if (same_stateid (&local->st_stateid, stid)) +return local; + } +return NULL ; +} + +static struct nfs4_delegation * +search_for_delegation (stateid_t *stid) +{ +struct nfs4_file *fp; +struct nfs4_delegation *dp; +struct list_head *pos; +int i; + +for (i =0 ; i <FILE_HASH_SIZE ; i++) { +list_for_each_entry (fp, &file_hashtbl[i], fi_hash) { +list_for_each (pos, &fp->fi_delegations) { + dp = list_entry(pos, struct nfs4_delegation, dl_perfile); +if (same_stateid (&dp->dl_stateid, stid)) +return dp; + } + } + } +return NULL ; +} +static struct nfs4_delegation *find_delegation_stateid (struct inode *ino,stateid_t *stid) {fs/nfsd/nfs4xdr.c +30
-2@@ -1246,6 +1246,19 @@ nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, }static __be32 +nfsd4_decode_free_stateid (struct nfsd4_compoundargs *argp, +struct nfsd4_free_stateid *free_stateid) +{ +DECODE_HEAD ; + +READ_BUF (sizeof (stateid_t)); +READ32 (free_stateid->fr_stateid.si_generation); +COPYMEM (&free_stateid->fr_stateid.si_opaque,sizeof (stateid_opaque_t)); + +DECODE_TAIL ; +} + +static __be32 nfsd4_decode_sequence (struct nfsd4_compoundargs *argp,struct nfsd4_sequence *seq) {@@ -1370,7 +1383,7 @@ static nfsd4_dec nfsd41_dec_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,@@ -3116,6 +3129,21 @@ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, }static __be32 +nfsd4_encode_free_stateid (struct nfsd4_compoundres *resp,int nfserr, +struct nfsd4_free_stateid *free_stateid) +{ +__be32 *p; + +if (nfserr) +return nfserr; + +RESERVE_SPACE (4 ); +WRITE32 (nfserr); +ADJUST_ARGS (); +return nfserr; +} + +static __be32 nfsd4_encode_sequence (struct nfsd4_compoundres *resp,int nfserr,struct nfsd4_sequence *seq) {@@ -3196,7 +3224,7 @@ static nfsd4_enc nfsd4_enc_ops[] = { [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, - [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, + [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid, [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,fs/nfsd/xdr4.h +8
-0@@ -342,6 +342,11 @@ struct nfsd4_setclientid_confirm {nfs4_verifier sc_confirm; }; +struct nfsd4_free_stateid { +stateid_t fr_stateid;/* request */ +__be32 fr_status;/* response */ +}; +/* also used for NVERIFY */ struct nfsd4_verify {u32 ve_bmval[3 ];/* request */ @@ -432,6 +437,7 @@ struct nfsd4_op {struct nfsd4_destroy_session destroy_session;struct nfsd4_sequence sequence;struct nfsd4_reclaim_complete reclaim_complete; +struct nfsd4_free_stateid free_stateid; } u;struct nfs4_replay * replay; };@@ -564,6 +570,8 @@ extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);extern __be32 nfsd4_renew (struct svc_rqst *rqstp,struct nfsd4_compound_state *,clientid_t *clid); +extern __be32 nfsd4_free_stateid (struct svc_rqst *rqstp, +struct nfsd4_compound_state *,struct nfsd4_free_stateid *free_stateid);#endif /* Signature · 1 line
1.7.6
PATCH v5 2/2 NFSD: Added TEST_STATEID operation
In reply to [email protected]From: Bryan Schumaker <[email protected]>
This operation is used by the client to check the validity of a list of stateids.
--- fs/nfsd/nfs4proc.c | 5 +++ fs/nfsd/nfs4state.c | 38 ++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-- fs/nfsd/state.h | 1 + fs/nfsd/xdr4.h | 17 ++++++++++ 5 files changed, 145 insertions(+), 3 deletions(-)
fs/nfsd/nfs4proc.c +5 -0
@@ -1412,6 +1412,11 @@ static struct nfsd4_operation nfsd4_ops[] = { .op_flags = OP_HANDLES_WRONGSEC, .op_name = "OP_SECINFO_NO_NAME", }, + [OP_TEST_STATEID] = { + .op_func = (nfsd4op_func)nfsd4_test_stateid, + .op_flags = ALLOWED_WITHOUT_FH, + .op_name = "OP_TEST_STATEID", + }, [OP_FREE_STATEID] = { .op_func = (nfsd4op_func)nfsd4_free_stateid, .op_flags = ALLOWED_WITHOUT_FH,
fs/nfsd/nfs4state.c +38 -0
@@ -37,6 +37,7 @@#include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h> +#include <linux/pagemap.h> #include <linux/sunrpc/svcauth_gss.h> #include <linux/sunrpc/clnt.h> #include "xdr4.h"
@@ -3145,6 +3146,32 @@ static int is_open_stateid(struct nfs4_stateid *stateid)return stateid->st_openstp ==NULL ; } +__be32 nfs4_validate_stateid (stateid_t *stateid,int flags) +{ +struct nfs4_stateid *stp =NULL ; +__be32 status = nfserr_stale_stateid; + +if (STALE_STATEID (stateid)) + goto out; + + status = nfserr_expired; + stp =search_for_stateid (stateid); +if (!stp) + goto out; + status = nfserr_bad_stateid; + +if (!stp->st_stateowner->so_confirmed) + goto out; + + status =check_stateid_generation (stateid, &stp->st_stateid, flags); +if (status) + goto out; + + status = nfs_ok; +out: +return status; +} +/* * Checks for stateid operations */
@@ -3243,6 +3270,17 @@ nfsd4_free_lock_stateid(struct nfs4_stateid *stp) }/* +* Test if the stateid is valid +*/ +__be32 +nfsd4_test_stateid (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate, +struct nfsd4_test_stateid *test_stateid) +{ + test_stateid->ts_has_session =nfsd4_has_session (cstate); +return nfs_ok; +} + +/* * Free a state id */ __be32
fs/nfsd/nfs4xdr.c +84 -3
129 lines not on this page · raw message
fs/nfsd/state.h +1 -0
@@ -482,6 +482,7 @@ extern void nfsd4_recdir_purge_old(void);extern int nfsd4_create_clid_dir (struct nfs4_client *clp);extern void nfsd4_remove_clid_dir (struct nfs4_client *clp);extern void release_session_client (struct nfsd4_session *); +extern __be32 nfs4_validate_stateid (stateid_t *,int );static inline void nfs4_put_stateowner (struct nfs4_stateowner *so)
fs/nfsd/xdr4.h +17 -0
@@ -342,6 +342,20 @@ struct nfsd4_setclientid_confirm {nfs4_verifier sc_confirm; }; +struct nfsd4_saved_compoundargs { +__be32 *p; +__be32 *end; +int pagelen; +struct page **pagelist; +}; + +struct nfsd4_test_stateid { +__be32 ts_num_ids; +__be32 ts_has_session; +struct nfsd4_compoundargs *ts_saved_args; +struct nfsd4_saved_compoundargs ts_savedp; +}; +struct nfsd4_free_stateid {stateid_t fr_stateid;/* request */ __be32 fr_status;/* response */
@@ -437,6 +451,7 @@ struct nfsd4_op {struct nfsd4_destroy_session destroy_session;struct nfsd4_sequence sequence;struct nfsd4_reclaim_complete reclaim_complete; +struct nfsd4_test_stateid test_stateid;struct nfsd4_free_stateid free_stateid; } u;struct nfs4_replay * replay;
@@ -570,6 +585,8 @@ extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *, struct nfsd4_delegreturn *dr);extern __be32 nfsd4_renew (struct svc_rqst *rqstp,struct nfsd4_compound_state *,clientid_t *clid); +extern __be32 nfsd4_test_stateid (struct svc_rqst *rqstp, +struct nfsd4_compound_state *,struct nfsd4_test_stateid *test_stateid);extern __be32 nfsd4_free_stateid (struct svc_rqst *rqstp,struct nfsd4_compound_state *,struct nfsd4_free_stateid *free_stateid);#endif
Signature · 1 line
1.7.6