Message ID | 1305575021-2841-2-git-send-email-bjschuma@netapp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, May 16, 2011 at 03:43:40PM -0400, bjschuma@netapp.com wrote: > +static __be32 > +nfsd4_free_file_stateid(stateid_t *stateid) > +{ > + struct nfs4_stateid *stp = search_for_stateid(stateid); > + if (!stp) > + return nfserr_bad_stateid; > + if (stateid->si_generation != 0) { > + if (stateid->si_generation < stp->st_stateid.si_generation) > + return nfserr_old_stateid; > + if (stateid->si_generation > stp->st_stateid.si_generation) > + return nfserr_bad_stateid; > + } > + > + if (check_for_locks(stp->st_file, stp->st_stateowner)) > + return nfserr_locks_held; I think this catches a lock stateid, but not an open stateid that has associated lock stateid's that in turn hold locks. Hm, also: "The FREE_STATEID operation is used to free a stateid that no longer has any associated locks (including opens, byte-range locks, delegations, and layouts)" So an open stateid also shouldn't be freeable as long as there are opens associated with it. Also I guess a client shouldn't be permitted to free a delegation that it still holds. That means we'll always just return nfserr_locks for delegation stateid's. I assume free_stateid is only useful in this case for the case where a server forcibly revokes part of the client's state and leaves some "stub" stateid's around in place of the revoked ones. --b. -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, May 18, 2011 at 06:56:09PM -0400, J. Bruce Fields wrote: > Also I guess a client shouldn't be permitted to free a delegation that > it still holds. That means we'll always just return nfserr_locks for > delegation stateid's. I assume free_stateid is only useful in this case > for the case where a server forcibly revokes part of the client's state > and leaves some "stub" stateid's around in place of the revoked ones. So I think what we really need to do here is this: http://wiki.linux-nfs.org/wiki/index.php/Server_4.0_and_4.1_issues#SEQ4_STATUS_RECALLABLE_STATE_REVOKED --b. -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/18/2011 06:56 PM, J. Bruce Fields wrote: > On Mon, May 16, 2011 at 03:43:40PM -0400, bjschuma@netapp.com wrote: >> +static __be32 >> +nfsd4_free_file_stateid(stateid_t *stateid) >> +{ >> + struct nfs4_stateid *stp = search_for_stateid(stateid); >> + if (!stp) >> + return nfserr_bad_stateid; >> + if (stateid->si_generation != 0) { >> + if (stateid->si_generation < stp->st_stateid.si_generation) >> + return nfserr_old_stateid; >> + if (stateid->si_generation > stp->st_stateid.si_generation) >> + return nfserr_bad_stateid; >> + } >> + >> + if (check_for_locks(stp->st_file, stp->st_stateowner)) >> + return nfserr_locks_held; > > I think this catches a lock stateid, but not an open stateid that has > associated lock stateid's that in turn hold locks. > > Hm, also: > > "The FREE_STATEID operation is used to free a stateid that no > longer has any associated locks (including opens, byte-range > locks, delegations, and layouts)" > > So an open stateid also shouldn't be freeable as long as there are opens > associated with it. So having an open stateid doesn't necessarily mean that the file is open? and having a lock stateid doesn't mean that the file is locked? I'll look at making a "check_for_opens()" function to help with this check. > > Also I guess a client shouldn't be permitted to free a delegation that > it still holds. That means we'll always just return nfserr_locks for > delegation stateid's. I assume free_stateid is only useful in this case Sounds simple enough. > for the case where a server forcibly revokes part of the client's state > and leaves some "stub" stateid's around in place of the revoked ones. > > --b. -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, May 19, 2011 at 11:33:56AM -0400, Bryan Schumaker wrote: > On 05/18/2011 06:56 PM, J. Bruce Fields wrote: > > On Mon, May 16, 2011 at 03:43:40PM -0400, bjschuma@netapp.com wrote: > >> +static __be32 > >> +nfsd4_free_file_stateid(stateid_t *stateid) > >> +{ > >> + struct nfs4_stateid *stp = search_for_stateid(stateid); > >> + if (!stp) > >> + return nfserr_bad_stateid; > >> + if (stateid->si_generation != 0) { > >> + if (stateid->si_generation < stp->st_stateid.si_generation) > >> + return nfserr_old_stateid; > >> + if (stateid->si_generation > stp->st_stateid.si_generation) > >> + return nfserr_bad_stateid; > >> + } > >> + > >> + if (check_for_locks(stp->st_file, stp->st_stateowner)) > >> + return nfserr_locks_held; > > > > I think this catches a lock stateid, but not an open stateid that has > > associated lock stateid's that in turn hold locks. > > > > Hm, also: > > > > "The FREE_STATEID operation is used to free a stateid that no > > longer has any associated locks (including opens, byte-range > > locks, delegations, and layouts)" > > > > So an open stateid also shouldn't be freeable as long as there are opens > > associated with it. > > So having an open stateid doesn't necessarily mean that the file is open? Looking back at it.... Sorry, you're right, open stateid's are destroyed on close, so like delegation stateid's they should just never be freeable. > and having a lock stateid doesn't mean that the file is locked? Here we don't know whether the file's locked or not, so we do have to check. > I'll look at making a "check_for_opens()" function to help with this check. So actually I think it's really simple: always fail opens and delegations, but check for locks. (Except I'm not sure if check_for_locks() does the right things, as it operates on a stateowner not a stateid--I'm forgetting how those work.... If there's a unique lock stateid per (stateowner,file) pair then check_for_locks() should do what you want.) --b. > > > > > Also I guess a client shouldn't be permitted to free a delegation that > > it still holds. That means we'll always just return nfserr_locks for > > delegation stateid's. I assume free_stateid is only useful in this case > > Sounds simple enough. > > > for the case where a server forcibly revokes part of the client's state > > and leaves some "stub" stateid's around in place of the revoked ones. > > > > --b. > -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/19/2011 12:30 PM, J. Bruce Fields wrote: > On Thu, May 19, 2011 at 11:33:56AM -0400, Bryan Schumaker wrote: >> On 05/18/2011 06:56 PM, J. Bruce Fields wrote: >>> On Mon, May 16, 2011 at 03:43:40PM -0400, bjschuma@netapp.com wrote: >>>> +static __be32 >>>> +nfsd4_free_file_stateid(stateid_t *stateid) >>>> +{ >>>> + struct nfs4_stateid *stp = search_for_stateid(stateid); >>>> + if (!stp) >>>> + return nfserr_bad_stateid; >>>> + if (stateid->si_generation != 0) { >>>> + if (stateid->si_generation < stp->st_stateid.si_generation) >>>> + return nfserr_old_stateid; >>>> + if (stateid->si_generation > stp->st_stateid.si_generation) >>>> + return nfserr_bad_stateid; >>>> + } >>>> + >>>> + if (check_for_locks(stp->st_file, stp->st_stateowner)) >>>> + return nfserr_locks_held; >>> >>> I think this catches a lock stateid, but not an open stateid that has >>> associated lock stateid's that in turn hold locks. >>> >>> Hm, also: >>> >>> "The FREE_STATEID operation is used to free a stateid that no >>> longer has any associated locks (including opens, byte-range >>> locks, delegations, and layouts)" >>> >>> So an open stateid also shouldn't be freeable as long as there are opens >>> associated with it. >> >> So having an open stateid doesn't necessarily mean that the file is open? > > Looking back at it.... Sorry, you're right, open stateid's are destroyed > on close, so like delegation stateid's they should just never be > freeable. > >> and having a lock stateid doesn't mean that the file is locked? > > Here we don't know whether the file's locked or not, so we do have to > check. > >> I'll look at making a "check_for_opens()" function to help with this check. > > So actually I think it's really simple: always fail opens and > delegations, but check for locks. (Except I'm not sure if That is much simpler. I'm glad I asked! > check_for_locks() does the right things, as it operates on a stateowner > not a stateid--I'm forgetting how those work.... If there's a unique > lock stateid per (stateowner,file) pair then check_for_locks() should do > what you want.) I'm not sure how they work either. I'll browse through the code to see what I can find. Thanks! > > --b. > >> >>> >>> Also I guess a client shouldn't be permitted to free a delegation that >>> it still holds. That means we'll always just return nfserr_locks for >>> delegation stateid's. I assume free_stateid is only useful in this case >> >> Sounds simple enough. >> >>> for the case where a server forcibly revokes part of the client's state >>> and leaves some "stub" stateid's around in place of the revoked ones. >>> >>> --b. >> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/19/2011 12:35 PM, Bryan Schumaker wrote: > On 05/19/2011 12:30 PM, J. Bruce Fields wrote: >> On Thu, May 19, 2011 at 11:33:56AM -0400, Bryan Schumaker wrote: >>> On 05/18/2011 06:56 PM, J. Bruce Fields wrote: >>>> On Mon, May 16, 2011 at 03:43:40PM -0400, bjschuma@netapp.com wrote: >>>>> +static __be32 >>>>> +nfsd4_free_file_stateid(stateid_t *stateid) >>>>> +{ >>>>> + struct nfs4_stateid *stp = search_for_stateid(stateid); >>>>> + if (!stp) >>>>> + return nfserr_bad_stateid; >>>>> + if (stateid->si_generation != 0) { >>>>> + if (stateid->si_generation < stp->st_stateid.si_generation) >>>>> + return nfserr_old_stateid; >>>>> + if (stateid->si_generation > stp->st_stateid.si_generation) >>>>> + return nfserr_bad_stateid; >>>>> + } >>>>> + >>>>> + if (check_for_locks(stp->st_file, stp->st_stateowner)) >>>>> + return nfserr_locks_held; >>>> >>>> I think this catches a lock stateid, but not an open stateid that has >>>> associated lock stateid's that in turn hold locks. >>>> >>>> Hm, also: >>>> >>>> "The FREE_STATEID operation is used to free a stateid that no >>>> longer has any associated locks (including opens, byte-range >>>> locks, delegations, and layouts)" >>>> >>>> So an open stateid also shouldn't be freeable as long as there are opens >>>> associated with it. >>> >>> So having an open stateid doesn't necessarily mean that the file is open? >> >> Looking back at it.... Sorry, you're right, open stateid's are destroyed >> on close, so like delegation stateid's they should just never be >> freeable. >> >>> and having a lock stateid doesn't mean that the file is locked? >> >> Here we don't know whether the file's locked or not, so we do have to >> check. >> >>> I'll look at making a "check_for_opens()" function to help with this check. >> >> So actually I think it's really simple: always fail opens and >> delegations, but check for locks. (Except I'm not sure if > > That is much simpler. I'm glad I asked! > >> check_for_locks() does the right things, as it operates on a stateowner >> not a stateid--I'm forgetting how those work.... If there's a unique >> lock stateid per (stateowner,file) pair then check_for_locks() should do >> what you want.) > > I'm not sure how they work either. I'll browse through the code to see what I can find. It looks like a stateid only applies to a single (stateowner, file), but I don't know if multiple stateids can point to the same (stateowner, file). It looks like lock set / test / unlock is all done through the vfs, so I'm not sure how to check if a specific stateid is locked without using check_for_locks(). > > Thanks! > >> >> --b. >> >>> >>>> >>>> Also I guess a client shouldn't be permitted to free a delegation that >>>> it still holds. That means we'll always just return nfserr_locks for >>>> delegation stateid's. I assume free_stateid is only useful in this case >>> >>> Sounds simple enough. >>> >>>> for the case where a server forcibly revokes part of the client's state >>>> and leaves some "stub" stateid's around in place of the revoked ones. >>>> >>>> --b. >>> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-nfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 3a6dbd7..7e00116 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -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) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index a2ea14f..043baa0 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -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: */ @@ -3212,6 +3215,59 @@ out: return status; } +static __be32 +nfsd4_free_delegation_stateid(stateid_t *stateid) +{ + struct nfs4_delegation *dp = search_for_delegation(stateid); + __be32 ret = nfs_ok; + + if (dp) + unhash_delegation(dp); + else + ret = nfserr_bad_stateid; + return ret; +} + +static __be32 +nfsd4_free_file_stateid(stateid_t *stateid) +{ + struct nfs4_stateid *stp = search_for_stateid(stateid); + if (!stp) + return nfserr_bad_stateid; + if (stateid->si_generation != 0) { + if (stateid->si_generation < stp->st_stateid.si_generation) + return nfserr_old_stateid; + if (stateid->si_generation > stp->st_stateid.si_generation) + return nfserr_bad_stateid; + } + + if (check_for_locks(stp->st_file, stp->st_stateowner)) + return nfserr_locks_held; + + if (stp->st_openstp) + release_lock_stateid(stp); + else + release_open_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; + __be32 ret; + + if (is_delegation_stateid(stateid)) + ret = nfsd4_free_delegation_stateid(stateid); + else + ret = nfsd4_free_file_stateid(stateid); + return ret; +} + static inline int setlkflg (int type) { @@ -3590,6 +3646,18 @@ 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_generation != id_two->si_generation) + return 0; + else if (id_one->si_boot != id_two->si_boot) + return 0; + else 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) { @@ -3619,6 +3687,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) { diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 195a91d..5da6874 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -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, @@ -3115,6 +3128,21 @@ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, return 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; +} + __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, diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 366401e..ed1784d 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -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 /*