nfs4state.c (36b2e922b5acd291051fab25bc7535274ce49532) | nfs4state.c (e1ca12dfb1be7fe8b82ca723a9b511f7d808bf81) |
---|---|
1/* 2* Copyright (c) 2001 The Regents of the University of Michigan. 3* All rights reserved. 4* 5* Kendrick Smith <kmsmith@umich.edu> 6* Andy Adamson <kandros@umich.edu> 7* 8* Redistribution and use in source and binary forms, with or without --- 46 unchanged lines hidden (view full) --- 55static stateid_t onestateid; /* bits all 1 */ 56static u64 current_sessionid = 1; 57 58#define ZERO_STATEID(stateid) (!memcmp((stateid), &zerostateid, sizeof(stateid_t))) 59#define ONE_STATEID(stateid) (!memcmp((stateid), &onestateid, sizeof(stateid_t))) 60 61/* forward declarations */ 62static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags); | 1/* 2* Copyright (c) 2001 The Regents of the University of Michigan. 3* All rights reserved. 4* 5* Kendrick Smith <kmsmith@umich.edu> 6* Andy Adamson <kandros@umich.edu> 7* 8* Redistribution and use in source and binary forms, with or without --- 46 unchanged lines hidden (view full) --- 55static stateid_t onestateid; /* bits all 1 */ 56static u64 current_sessionid = 1; 57 58#define ZERO_STATEID(stateid) (!memcmp((stateid), &zerostateid, sizeof(stateid_t))) 59#define ONE_STATEID(stateid) (!memcmp((stateid), &onestateid, sizeof(stateid_t))) 60 61/* forward declarations */ 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); 64static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery"; 65static void nfs4_set_recdir(char *recdir); | 65static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid); 66static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery"; 67static void nfs4_set_recdir(char *recdir); |
68static int check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner); |
|
66 67/* Locking: */ 68 69/* Currently used for almost all code touching nfsv4 state: */ 70static DEFINE_MUTEX(client_mutex); 71 72/* 73 * Currently used for the del_recall_lru and file hash table. In an --- 3058 unchanged lines hidden (view full) --- 3132 return nfs_ok; 3133} 3134 3135static int is_delegation_stateid(stateid_t *stateid) 3136{ 3137 return stateid->si_fileid == 0; 3138} 3139 | 69 70/* Locking: */ 71 72/* Currently used for almost all code touching nfsv4 state: */ 73static DEFINE_MUTEX(client_mutex); 74 75/* 76 * Currently used for the del_recall_lru and file hash table. In an --- 3058 unchanged lines hidden (view full) --- 3135 return nfs_ok; 3136} 3137 3138static int is_delegation_stateid(stateid_t *stateid) 3139{ 3140 return stateid->si_fileid == 0; 3141} 3142 |
3143static int is_open_stateid(struct nfs4_stateid *stateid) 3144{ 3145 return stateid->st_openstp == NULL; 3146} 3147 |
|
3140/* 3141* Checks for stateid operations 3142*/ 3143__be32 3144nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate, 3145 stateid_t *stateid, int flags, struct file **filpp) 3146{ 3147 struct nfs4_stateid *stp = NULL; --- 63 unchanged lines hidden (view full) --- 3211 *filpp = find_writeable_file(stp->st_file); 3212 } 3213 } 3214 status = nfs_ok; 3215out: 3216 return status; 3217} 3218 | 3148/* 3149* Checks for stateid operations 3150*/ 3151__be32 3152nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate, 3153 stateid_t *stateid, int flags, struct file **filpp) 3154{ 3155 struct nfs4_stateid *stp = NULL; --- 63 unchanged lines hidden (view full) --- 3219 *filpp = find_writeable_file(stp->st_file); 3220 } 3221 } 3222 status = nfs_ok; 3223out: 3224 return status; 3225} 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 3220setlkflg (int type) 3221{ 3222 return (type == NFS4_READW_LT || type == NFS4_READ_LT) ? 3223 RD_STATE : WR_STATE; 3224} 3225 3226/* --- 362 unchanged lines hidden (view full) --- 3589 + opaque_hashval(ownername->data, ownername->len)) 3590 & LOCK_HASH_MASK; 3591} 3592 3593static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE]; 3594static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; 3595static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE]; 3596 | 3291static inline int 3292setlkflg (int type) 3293{ 3294 return (type == NFS4_READW_LT || type == NFS4_READ_LT) ? 3295 RD_STATE : WR_STATE; 3296} 3297 3298/* --- 362 unchanged lines hidden (view full) --- 3661 + opaque_hashval(ownername->data, ownername->len)) 3662 & LOCK_HASH_MASK; 3663} 3664 3665static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE]; 3666static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; 3667static struct list_head lockstateid_hashtbl[STATEID_HASH_SIZE]; 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 * 3598find_stateid(stateid_t *stid, int flags) 3599{ 3600 struct nfs4_stateid *local; 3601 u32 st_id = stid->si_stateownerid; 3602 u32 f_id = stid->si_fileid; 3603 unsigned int hashval; 3604 --- 13 unchanged lines hidden (view full) --- 3618 if ((local->st_stateid.si_stateownerid == st_id) && 3619 (local->st_stateid.si_fileid == f_id)) 3620 return local; 3621 } 3622 } 3623 return NULL; 3624} 3625 | 3677static struct nfs4_stateid * 3678find_stateid(stateid_t *stid, int flags) 3679{ 3680 struct nfs4_stateid *local; 3681 u32 st_id = stid->si_stateownerid; 3682 u32 f_id = stid->si_fileid; 3683 unsigned int hashval; 3684 --- 13 unchanged lines hidden (view full) --- 3698 if ((local->st_stateid.si_stateownerid == st_id) && 3699 (local->st_stateid.si_fileid == f_id)) 3700 return local; 3701 } 3702 } 3703 return NULL; 3704} 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 |
|
3626static struct nfs4_delegation * | 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 3744static struct nfs4_delegation * |
|
3627find_delegation_stateid(struct inode *ino, stateid_t *stid) 3628{ 3629 struct nfs4_file *fp; 3630 struct nfs4_delegation *dl; 3631 3632 dprintk("NFSD: %s: stateid=" STATEID_FMT "\n", __func__, 3633 STATEID_VAL(stid)); 3634 --- 860 unchanged lines hidden --- | 3745find_delegation_stateid(struct inode *ino, stateid_t *stid) 3746{ 3747 struct nfs4_file *fp; 3748 struct nfs4_delegation *dl; 3749 3750 dprintk("NFSD: %s: stateid=" STATEID_FMT "\n", __func__, 3751 STATEID_VAL(stid)); 3752 --- 860 unchanged lines hidden --- |