Skip to content

Commit 11b9164

Browse files
trondmypdJ. Bruce Fields
authored andcommitted
nfsd: Add a struct nfs4_file field to struct nfs4_stid
All stateids are associated with a nfs4_file. Let's consolidate. Replace delegation->dl_file with the dl_stid.sc_file, and nfs4_ol_stateid->st_file with st_stid.sc_file. Signed-off-by: Trond Myklebust <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 6011695 commit 11b9164

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static void encode_cb_recall4args(struct xdr_stream *xdr,
337337
p = xdr_reserve_space(xdr, 4);
338338
*p++ = xdr_zero; /* truncate */
339339

340-
encode_nfs_fh4(xdr, &dp->dl_file->fi_fhandle);
340+
encode_nfs_fh4(xdr, &dp->dl_stid.sc_file->fi_fhandle);
341341

342342
hdr->nops++;
343343
}

fs/nfsd/nfs4state.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,6 @@ static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
515515

516516
static void nfs4_free_deleg(struct nfs4_stid *stid)
517517
{
518-
struct nfs4_delegation *dp = delegstateid(stid);
519-
520-
if (dp->dl_file)
521-
put_nfs4_file(dp->dl_file);
522518
kmem_cache_free(deleg_slab, stid);
523519
atomic_long_dec(&num_delegations);
524520
}
@@ -636,12 +632,15 @@ alloc_init_deleg(struct nfs4_client *clp, struct svc_fh *current_fh)
636632
void
637633
nfs4_put_stid(struct nfs4_stid *s)
638634
{
635+
struct nfs4_file *fp = s->sc_file;
639636
struct nfs4_client *clp = s->sc_client;
640637

641638
if (!atomic_dec_and_test(&s->sc_count))
642639
return;
643640
idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
644641
s->sc_free(s);
642+
if (fp)
643+
put_nfs4_file(fp);
645644
}
646645

647646
static void nfs4_put_deleg_lease(struct nfs4_file *fp)
@@ -677,7 +676,7 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
677676
static void
678677
unhash_delegation_locked(struct nfs4_delegation *dp)
679678
{
680-
struct nfs4_file *fp = dp->dl_file;
679+
struct nfs4_file *fp = dp->dl_stid.sc_file;
681680

682681
lockdep_assert_held(&state_lock);
683682

@@ -864,29 +863,29 @@ reset_union_bmap_deny(u32 deny, struct nfs4_ol_stateid *stp)
864863

865864
/* Recalculate per-file deny mode if there was a change */
866865
if (change)
867-
recalculate_deny_mode(stp->st_file);
866+
recalculate_deny_mode(stp->st_stid.sc_file);
868867
}
869868

870869
/* release all access and file references for a given stateid */
871870
static void
872871
release_all_access(struct nfs4_ol_stateid *stp)
873872
{
874873
int i;
875-
struct nfs4_file *fp = stp->st_file;
874+
struct nfs4_file *fp = stp->st_stid.sc_file;
876875

877876
if (fp && stp->st_deny_bmap != 0)
878877
recalculate_deny_mode(fp);
879878

880879
for (i = 1; i < 4; i++) {
881880
if (test_access(i, stp))
882-
nfs4_file_put_access(stp->st_file, i);
881+
nfs4_file_put_access(stp->st_stid.sc_file, i);
883882
clear_access(i, stp);
884883
}
885884
}
886885

887886
static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
888887
{
889-
struct nfs4_file *fp = stp->st_file;
888+
struct nfs4_file *fp = stp->st_stid.sc_file;
890889

891890
spin_lock(&fp->fi_lock);
892891
list_del(&stp->st_perfile);
@@ -899,8 +898,6 @@ static void nfs4_free_ol_stateid(struct nfs4_stid *stid)
899898
struct nfs4_ol_stateid *stp = openlockstateid(stid);
900899

901900
release_all_access(stp);
902-
if (stp->st_file)
903-
put_nfs4_file(stp->st_file);
904901
kmem_cache_free(stateid_slab, stid);
905902
}
906903

@@ -911,7 +908,7 @@ static void __release_lock_stateid(struct nfs4_ol_stateid *stp)
911908
list_del(&stp->st_locks);
912909
unhash_generic_stateid(stp);
913910
unhash_stid(&stp->st_stid);
914-
file = find_any_file(stp->st_file);
911+
file = find_any_file(stp->st_stid.sc_file);
915912
if (file)
916913
filp_close(file, (fl_owner_t)lockowner(stp->st_stateowner));
917914
nfs4_put_stid(&stp->st_stid);
@@ -2976,7 +2973,7 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
29762973
list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
29772974
stp->st_stateowner = &oo->oo_owner;
29782975
get_nfs4_file(fp);
2979-
stp->st_file = fp;
2976+
stp->st_stid.sc_file = fp;
29802977
stp->st_access_bmap = 0;
29812978
stp->st_deny_bmap = 0;
29822979
stp->st_openstp = NULL;
@@ -3097,10 +3094,10 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
30973094

30983095
void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp)
30993096
{
3100-
struct nfs4_client *clp = dp->dl_stid.sc_client;
3101-
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
3097+
struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net,
3098+
nfsd_net_id);
31023099

3103-
block_delegations(&dp->dl_file->fi_fhandle);
3100+
block_delegations(&dp->dl_stid.sc_file->fi_fhandle);
31043101

31053102
/*
31063103
* We can't do this in nfsd_break_deleg_cb because it is
@@ -3508,7 +3505,7 @@ static struct file_lock *nfs4_alloc_init_lease(struct nfs4_file *fp, int flag)
35083505

35093506
static int nfs4_setlease(struct nfs4_delegation *dp)
35103507
{
3511-
struct nfs4_file *fp = dp->dl_file;
3508+
struct nfs4_file *fp = dp->dl_stid.sc_file;
35123509
struct file_lock *fl;
35133510
struct file *filp;
35143511
int status = 0;
@@ -3573,7 +3570,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh,
35733570
get_nfs4_file(fp);
35743571
spin_lock(&state_lock);
35753572
spin_lock(&fp->fi_lock);
3576-
dp->dl_file = fp;
3573+
dp->dl_stid.sc_file = fp;
35773574
if (!fp->fi_lease) {
35783575
spin_unlock(&fp->fi_lock);
35793576
spin_unlock(&state_lock);
@@ -3669,7 +3666,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open,
36693666
default:
36703667
goto out_no_deleg;
36713668
}
3672-
dp = nfs4_set_delegation(clp, fh, stp->st_file);
3669+
dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file);
36733670
if (IS_ERR(dp))
36743671
goto out_no_deleg;
36753672

@@ -3959,7 +3956,7 @@ laundromat_main(struct work_struct *laundry)
39593956

39603957
static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp)
39613958
{
3962-
if (!nfsd_fh_match(&fhp->fh_handle, &stp->st_file->fi_fhandle))
3959+
if (!nfsd_fh_match(&fhp->fh_handle, &stp->st_stid.sc_file->fi_fhandle))
39633960
return nfserr_bad_stateid;
39643961
return nfs_ok;
39653962
}
@@ -4167,7 +4164,7 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
41674164
if (status)
41684165
goto out;
41694166
if (filpp) {
4170-
file = dp->dl_file->fi_deleg_file;
4167+
file = dp->dl_stid.sc_file->fi_deleg_file;
41714168
if (!file) {
41724169
WARN_ON_ONCE(1);
41734170
status = nfserr_serverfault;
@@ -4189,10 +4186,12 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
41894186
if (status)
41904187
goto out;
41914188
if (filpp) {
4189+
struct nfs4_file *fp = stp->st_stid.sc_file;
4190+
41924191
if (flags & RD_STATE)
4193-
file = find_readable_file(stp->st_file);
4192+
file = find_readable_file(fp);
41944193
else
4195-
file = find_writeable_file(stp->st_file);
4194+
file = find_writeable_file(fp);
41964195
}
41974196
break;
41984197
default:
@@ -4212,7 +4211,7 @@ nfsd4_free_lock_stateid(struct nfs4_ol_stateid *stp)
42124211
{
42134212
struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
42144213

4215-
if (check_for_locks(stp->st_file, lo))
4214+
if (check_for_locks(stp->st_stid.sc_file, lo))
42164215
return nfserr_locks_held;
42174216
release_lockowner_if_empty(lo);
42184217
return nfs_ok;
@@ -4403,7 +4402,7 @@ static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 a
44034402
{
44044403
if (!test_access(access, stp))
44054404
return;
4406-
nfs4_file_put_access(stp->st_file, access);
4405+
nfs4_file_put_access(stp->st_stid.sc_file, access);
44074406
clear_access(access, stp);
44084407
}
44094408

@@ -4492,9 +4491,9 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
44924491
* before returning however.
44934492
*/
44944493
release_all_access(s);
4495-
if (s->st_file) {
4496-
put_nfs4_file(s->st_file);
4497-
s->st_file = NULL;
4494+
if (s->st_stid.sc_file) {
4495+
put_nfs4_file(s->st_stid.sc_file);
4496+
s->st_stid.sc_file = NULL;
44984497
}
44994498
oo->oo_last_closed_stid = s;
45004499
if (list_empty(&oo->oo_owner.so_stateids))
@@ -4695,7 +4694,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
46954694
list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
46964695
stp->st_stateowner = &lo->lo_owner;
46974696
get_nfs4_file(fp);
4698-
stp->st_file = fp;
4697+
stp->st_stid.sc_file = fp;
46994698
stp->st_access_bmap = 0;
47004699
stp->st_deny_bmap = open_stp->st_deny_bmap;
47014700
stp->st_openstp = open_stp;
@@ -4712,7 +4711,7 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp)
47124711
struct nfs4_ol_stateid *lst;
47134712

47144713
list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) {
4715-
if (lst->st_file == fp)
4714+
if (lst->st_stid.sc_file == fp)
47164715
return lst;
47174716
}
47184717
return NULL;
@@ -4728,7 +4727,7 @@ check_lock_length(u64 offset, u64 length)
47284727

47294728
static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
47304729
{
4731-
struct nfs4_file *fp = lock_stp->st_file;
4730+
struct nfs4_file *fp = lock_stp->st_stid.sc_file;
47324731

47334732
lockdep_assert_held(&fp->fi_lock);
47344733

@@ -4740,7 +4739,7 @@ static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
47404739

47414740
static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new)
47424741
{
4743-
struct nfs4_file *fi = ost->st_file;
4742+
struct nfs4_file *fi = ost->st_stid.sc_file;
47444743
struct nfs4_openowner *oo = openowner(ost->st_stateowner);
47454744
struct nfs4_client *cl = oo->oo_owner.so_client;
47464745
struct inode *inode = cstate->current_fh.fh_dentry->d_inode;
@@ -4865,7 +4864,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
48654864
goto out;
48664865
}
48674866

4868-
fp = lock_stp->st_file;
4867+
fp = lock_stp->st_stid.sc_file;
48694868
locks_init_lock(file_lock);
48704869
switch (lock->lk_type) {
48714870
case NFS4_READ_LT:
@@ -5065,7 +5064,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
50655064
&stp, nn);
50665065
if (status)
50675066
goto out;
5068-
filp = find_any_file(stp->st_file);
5067+
filp = find_any_file(stp->st_stid.sc_file);
50695068
if (!filp) {
50705069
status = nfserr_lock_range;
50715070
goto out;
@@ -5188,7 +5187,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
51885187
lo = lockowner(sop);
51895188
/* see if there are still any locks associated with it */
51905189
list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) {
5191-
if (check_for_locks(stp->st_file, lo))
5190+
if (check_for_locks(stp->st_stid.sc_file, lo))
51925191
goto out;
51935192
}
51945193

fs/nfsd/state.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct nfs4_stid {
8585
unsigned char sc_type;
8686
stateid_t sc_stateid;
8787
struct nfs4_client *sc_client;
88+
struct nfs4_file *sc_file;
8889
void (*sc_free)(struct nfs4_stid *);
8990
};
9091

@@ -93,7 +94,6 @@ struct nfs4_delegation {
9394
struct list_head dl_perfile;
9495
struct list_head dl_perclnt;
9596
struct list_head dl_recall_lru; /* delegation recalled */
96-
struct nfs4_file *dl_file;
9797
u32 dl_type;
9898
time_t dl_time;
9999
/* For recall: */
@@ -407,7 +407,6 @@ struct nfs4_ol_stateid {
407407
struct list_head st_perstateowner;
408408
struct list_head st_locks;
409409
struct nfs4_stateowner * st_stateowner;
410-
struct nfs4_file * st_file;
411410
unsigned char st_access_bmap;
412411
unsigned char st_deny_bmap;
413412
struct nfs4_ol_stateid * st_openstp;

0 commit comments

Comments
 (0)