diff options
author | J. Bruce Fields <bfields@redhat.com> | 2011-08-12 09:42:57 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2011-08-27 14:21:24 -0400 |
commit | ff194bd95959ea9047d536b4f4ad6a992754e48d (patch) | |
tree | dbbe145c6982ddba05fefb7f2abdcec58a918907 /fs/nfsd | |
parent | 506f275fffcaceb8abe3db69e581d86c7da48a82 (diff) |
nfsd4: cleanup lock/stateowner initialization
Share some common code, stop doing silly things like initializing a list
head immediately before adding it to a list, etc.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/nfs4state.c | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index dd6424face32..3e64288399f7 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -2215,51 +2215,61 @@ nfs4_free_stateowner(struct kref *kref) | |||
2215 | kmem_cache_free(stateowner_slab, sop); | 2215 | kmem_cache_free(stateowner_slab, sop); |
2216 | } | 2216 | } |
2217 | 2217 | ||
2218 | static inline struct nfs4_stateowner * | 2218 | static void init_nfs4_replay(struct nfs4_replay *rp) |
2219 | alloc_stateowner(struct xdr_netobj *owner) | ||
2220 | { | 2219 | { |
2221 | struct nfs4_stateowner *sop; | 2220 | rp->rp_status = nfserr_serverfault; |
2222 | 2221 | rp->rp_buflen = 0; | |
2223 | if ((sop = kmem_cache_alloc(stateowner_slab, GFP_KERNEL))) { | 2222 | rp->rp_buf = rp->rp_ibuf; |
2224 | if ((sop->so_owner.data = kmalloc(owner->len, GFP_KERNEL))) { | ||
2225 | memcpy(sop->so_owner.data, owner->data, owner->len); | ||
2226 | sop->so_owner.len = owner->len; | ||
2227 | kref_init(&sop->so_ref); | ||
2228 | return sop; | ||
2229 | } | ||
2230 | kmem_cache_free(stateowner_slab, sop); | ||
2231 | } | ||
2232 | return NULL; | ||
2233 | } | 2223 | } |
2234 | 2224 | ||
2235 | static struct nfs4_stateowner * | 2225 | static inline struct nfs4_stateowner *alloc_stateowner(struct xdr_netobj *owner, struct nfs4_client *clp) |
2236 | alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfsd4_open *open) { | 2226 | { |
2237 | struct nfs4_stateowner *sop; | 2227 | struct nfs4_stateowner *sop; |
2238 | struct nfs4_replay *rp; | ||
2239 | unsigned int idhashval; | ||
2240 | 2228 | ||
2241 | if (!(sop = alloc_stateowner(&open->op_owner))) | 2229 | sop = kmem_cache_alloc(stateowner_slab, GFP_KERNEL); |
2230 | if (!sop) | ||
2231 | return NULL; | ||
2232 | |||
2233 | sop->so_owner.data = kmemdup(owner->data, owner->len, GFP_KERNEL); | ||
2234 | if (!sop->so_owner.data) { | ||
2235 | kmem_cache_free(stateowner_slab, sop); | ||
2242 | return NULL; | 2236 | return NULL; |
2243 | idhashval = open_ownerid_hashval(current_ownerid); | 2237 | } |
2244 | INIT_LIST_HEAD(&sop->so_idhash); | 2238 | sop->so_owner.len = owner->len; |
2245 | INIT_LIST_HEAD(&sop->so_strhash); | 2239 | |
2240 | kref_init(&sop->so_ref); | ||
2246 | INIT_LIST_HEAD(&sop->so_perclient); | 2241 | INIT_LIST_HEAD(&sop->so_perclient); |
2247 | INIT_LIST_HEAD(&sop->so_stateids); | 2242 | INIT_LIST_HEAD(&sop->so_stateids); |
2248 | INIT_LIST_HEAD(&sop->so_perstateid); /* not used */ | 2243 | INIT_LIST_HEAD(&sop->so_perstateid); |
2249 | INIT_LIST_HEAD(&sop->so_close_lru); | 2244 | INIT_LIST_HEAD(&sop->so_close_lru); |
2245 | sop->so_id = current_ownerid++; | ||
2250 | sop->so_time = 0; | 2246 | sop->so_time = 0; |
2247 | sop->so_client = clp; | ||
2248 | init_nfs4_replay(&sop->so_replay); | ||
2249 | return sop; | ||
2250 | } | ||
2251 | |||
2252 | static void hash_openowner(struct nfs4_stateowner *sop, struct nfs4_client *clp, unsigned int strhashval) | ||
2253 | { | ||
2254 | unsigned int idhashval; | ||
2255 | |||
2256 | idhashval = open_ownerid_hashval(sop->so_id); | ||
2251 | list_add(&sop->so_idhash, &open_ownerid_hashtbl[idhashval]); | 2257 | list_add(&sop->so_idhash, &open_ownerid_hashtbl[idhashval]); |
2252 | list_add(&sop->so_strhash, &open_ownerstr_hashtbl[strhashval]); | 2258 | list_add(&sop->so_strhash, &open_ownerstr_hashtbl[strhashval]); |
2253 | list_add(&sop->so_perclient, &clp->cl_openowners); | 2259 | list_add(&sop->so_perclient, &clp->cl_openowners); |
2260 | } | ||
2261 | |||
2262 | static struct nfs4_stateowner * | ||
2263 | alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfsd4_open *open) { | ||
2264 | struct nfs4_stateowner *sop; | ||
2265 | |||
2266 | sop = alloc_stateowner(&open->op_owner, clp); | ||
2267 | if (!sop) | ||
2268 | return NULL; | ||
2254 | sop->so_is_open_owner = 1; | 2269 | sop->so_is_open_owner = 1; |
2255 | sop->so_id = current_ownerid++; | ||
2256 | sop->so_client = clp; | ||
2257 | sop->so_seqid = open->op_seqid; | 2270 | sop->so_seqid = open->op_seqid; |
2258 | sop->so_confirmed = 0; | 2271 | sop->so_confirmed = 0; |
2259 | rp = &sop->so_replay; | 2272 | hash_openowner(sop, clp, strhashval); |
2260 | rp->rp_status = nfserr_serverfault; | ||
2261 | rp->rp_buflen = 0; | ||
2262 | rp->rp_buf = rp->rp_ibuf; | ||
2263 | return sop; | 2273 | return sop; |
2264 | } | 2274 | } |
2265 | 2275 | ||
@@ -3902,6 +3912,16 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid, | |||
3902 | return NULL; | 3912 | return NULL; |
3903 | } | 3913 | } |
3904 | 3914 | ||
3915 | static void hash_lockowner(struct nfs4_stateowner *sop, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp) | ||
3916 | { | ||
3917 | unsigned int idhashval; | ||
3918 | |||
3919 | idhashval = lockownerid_hashval(sop->so_id); | ||
3920 | list_add(&sop->so_idhash, &lock_ownerid_hashtbl[idhashval]); | ||
3921 | list_add(&sop->so_strhash, &lock_ownerstr_hashtbl[strhashval]); | ||
3922 | list_add(&sop->so_perstateid, &open_stp->st_lockowners); | ||
3923 | } | ||
3924 | |||
3905 | /* | 3925 | /* |
3906 | * Alloc a lock owner structure. | 3926 | * Alloc a lock owner structure. |
3907 | * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has | 3927 | * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has |
@@ -3913,33 +3933,17 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid, | |||
3913 | static struct nfs4_stateowner * | 3933 | static struct nfs4_stateowner * |
3914 | alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp, struct nfsd4_lock *lock) { | 3934 | alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp, struct nfsd4_lock *lock) { |
3915 | struct nfs4_stateowner *sop; | 3935 | struct nfs4_stateowner *sop; |
3916 | struct nfs4_replay *rp; | ||
3917 | unsigned int idhashval; | ||
3918 | 3936 | ||
3919 | if (!(sop = alloc_stateowner(&lock->lk_new_owner))) | 3937 | sop = alloc_stateowner(&lock->lk_new_owner, clp); |
3938 | if (!sop) | ||
3920 | return NULL; | 3939 | return NULL; |
3921 | idhashval = lockownerid_hashval(current_ownerid); | ||
3922 | INIT_LIST_HEAD(&sop->so_idhash); | ||
3923 | INIT_LIST_HEAD(&sop->so_strhash); | ||
3924 | INIT_LIST_HEAD(&sop->so_perclient); | ||
3925 | INIT_LIST_HEAD(&sop->so_stateids); | 3940 | INIT_LIST_HEAD(&sop->so_stateids); |
3926 | INIT_LIST_HEAD(&sop->so_perstateid); | ||
3927 | INIT_LIST_HEAD(&sop->so_close_lru); /* not used */ | ||
3928 | sop->so_time = 0; | ||
3929 | list_add(&sop->so_idhash, &lock_ownerid_hashtbl[idhashval]); | ||
3930 | list_add(&sop->so_strhash, &lock_ownerstr_hashtbl[strhashval]); | ||
3931 | list_add(&sop->so_perstateid, &open_stp->st_lockowners); | ||
3932 | sop->so_is_open_owner = 0; | 3941 | sop->so_is_open_owner = 0; |
3933 | sop->so_id = current_ownerid++; | ||
3934 | sop->so_client = clp; | ||
3935 | /* It is the openowner seqid that will be incremented in encode in the | 3942 | /* It is the openowner seqid that will be incremented in encode in the |
3936 | * case of new lockowners; so increment the lock seqid manually: */ | 3943 | * case of new lockowners; so increment the lock seqid manually: */ |
3937 | sop->so_seqid = lock->lk_new_lock_seqid + 1; | 3944 | sop->so_seqid = lock->lk_new_lock_seqid + 1; |
3938 | sop->so_confirmed = 1; | 3945 | sop->so_confirmed = 1; |
3939 | rp = &sop->so_replay; | 3946 | hash_lockowner(sop, strhashval, clp, open_stp); |
3940 | rp->rp_status = nfserr_serverfault; | ||
3941 | rp->rp_buflen = 0; | ||
3942 | rp->rp_buf = rp->rp_ibuf; | ||
3943 | return sop; | 3947 | return sop; |
3944 | } | 3948 | } |
3945 | 3949 | ||