aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfs4state.c
diff options
context:
space:
mode:
authorBryan Schumaker <bjschuma@netapp.com>2011-07-13 11:04:21 -0400
committerJ. Bruce Fields <bfields@redhat.com>2011-07-15 18:58:47 -0400
commite1ca12dfb1be7fe8b82ca723a9b511f7d808bf81 (patch)
tree4d70be30b1bbd329d1edb036f9b974cce24f9b40 /fs/nfsd/nfs4state.c
parentebc63e531cc6a457595dd110b07ac530eae788c3 (diff)
NFSD: added FREE_STATEID operation
This operation is used by the client to tell the server to free a stateid. Signed-off-by: Bryan Schumaker <bjschuma@netapp.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd/nfs4state.c')
-rw-r--r--fs/nfsd/nfs4state.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index e98f3c2e9492..55c36e267b7d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -60,9 +60,12 @@ static u64 current_sessionid = 1;
60 60
61/* forward declarations */ 61/* forward declarations */
62static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags); 62static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags);
63static struct nfs4_stateid * search_for_stateid(stateid_t *stid);
64static struct nfs4_delegation * search_for_delegation(stateid_t *stid);
63static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid); 65static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid);
64static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery"; 66static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
65static void nfs4_set_recdir(char *recdir); 67static void nfs4_set_recdir(char *recdir);
68static int check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner);
66 69
67/* Locking: */ 70/* Locking: */
68 71
@@ -3137,6 +3140,11 @@ static int is_delegation_stateid(stateid_t *stateid)
3137 return stateid->si_fileid == 0; 3140 return stateid->si_fileid == 0;
3138} 3141}
3139 3142
3143static int is_open_stateid(struct nfs4_stateid *stateid)
3144{
3145 return stateid->st_openstp == NULL;
3146}
3147
3140/* 3148/*
3141* Checks for stateid operations 3149* Checks for stateid operations
3142*/ 3150*/
@@ -3216,6 +3224,70 @@ out:
3216 return status; 3224 return status;
3217} 3225}
3218 3226
3227static __be32
3228nfsd4_free_delegation_stateid(stateid_t *stateid)
3229{
3230 struct nfs4_delegation *dp = search_for_delegation(stateid);
3231 if (dp)
3232 return nfserr_locks_held;
3233 return nfserr_bad_stateid;
3234}
3235
3236static __be32
3237nfsd4_free_lock_stateid(struct nfs4_stateid *stp)
3238{
3239 if (check_for_locks(stp->st_file, stp->st_stateowner))
3240 return nfserr_locks_held;
3241 release_lock_stateid(stp);
3242 return nfs_ok;
3243}
3244
3245/*
3246 * Free a state id
3247 */
3248__be32
3249nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3250 struct nfsd4_free_stateid *free_stateid)
3251{
3252 stateid_t *stateid = &free_stateid->fr_stateid;
3253 struct nfs4_stateid *stp;
3254 __be32 ret;
3255
3256 nfs4_lock_state();
3257 if (is_delegation_stateid(stateid)) {
3258 ret = nfsd4_free_delegation_stateid(stateid);
3259 goto out;
3260 }
3261
3262 stp = search_for_stateid(stateid);
3263 if (!stp) {
3264 ret = nfserr_bad_stateid;
3265 goto out;
3266 }
3267 if (stateid->si_generation != 0) {
3268 if (stateid->si_generation < stp->st_stateid.si_generation) {
3269 ret = nfserr_old_stateid;
3270 goto out;
3271 }
3272 if (stateid->si_generation > stp->st_stateid.si_generation) {
3273 ret = nfserr_bad_stateid;
3274 goto out;
3275 }
3276 }
3277
3278 if (is_open_stateid(stp)) {
3279 ret = nfserr_locks_held;
3280 goto out;
3281 } else {
3282 ret = nfsd4_free_lock_stateid(stp);
3283 goto out;
3284 }
3285
3286out:
3287 nfs4_unlock_state();
3288 return ret;
3289}
3290
3219static inline int 3291static inline int
3220setlkflg (int type) 3292setlkflg (int type)
3221{ 3293{
@@ -3594,6 +3666,14 @@ static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE];
3594static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; 3666static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE];
3595static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE]; 3667static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE];
3596 3668
3669static int
3670same_stateid(stateid_t *id_one, stateid_t *id_two)
3671{
3672 if (id_one->si_stateownerid != id_two->si_stateownerid)
3673 return 0;
3674 return id_one->si_fileid == id_two->si_fileid;
3675}
3676
3597static struct nfs4_stateid * 3677static struct nfs4_stateid *
3598find_stateid(stateid_t *stid, int flags) 3678find_stateid(stateid_t *stid, int flags)
3599{ 3679{
@@ -3623,6 +3703,44 @@ find_stateid(stateid_t *stid, int flags)
3623 return NULL; 3703 return NULL;
3624} 3704}
3625 3705
3706static struct nfs4_stateid *
3707search_for_stateid(stateid_t *stid)
3708{
3709 struct nfs4_stateid *local;
3710 unsigned int hashval = stateid_hashval(stid->si_stateownerid, stid->si_fileid);
3711
3712 list_for_each_entry(local, &lockstateid_hashtbl[hashval], st_hash) {
3713 if (same_stateid(&local->st_stateid, stid))
3714 return local;
3715 }
3716
3717 list_for_each_entry(local, &stateid_hashtbl[hashval], st_hash) {
3718 if (same_stateid(&local->st_stateid, stid))
3719 return local;
3720 }
3721 return NULL;
3722}
3723
3724static struct nfs4_delegation *
3725search_for_delegation(stateid_t *stid)
3726{
3727 struct nfs4_file *fp;
3728 struct nfs4_delegation *dp;
3729 struct list_head *pos;
3730 int i;
3731
3732 for (i = 0; i < FILE_HASH_SIZE; i++) {
3733 list_for_each_entry(fp, &file_hashtbl[i], fi_hash) {
3734 list_for_each(pos, &fp->fi_delegations) {
3735 dp = list_entry(pos, struct nfs4_delegation, dl_perfile);
3736 if (same_stateid(&dp->dl_stateid, stid))
3737 return dp;
3738 }
3739 }
3740 }
3741 return NULL;
3742}
3743
3626static struct nfs4_delegation * 3744static struct nfs4_delegation *
3627find_delegation_stateid(struct inode *ino, stateid_t *stid) 3745find_delegation_stateid(struct inode *ino, stateid_t *stid)
3628{ 3746{