summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2014-07-29 21:34:08 -0400
committerJ. Bruce Fields <bfields@redhat.com>2014-07-31 12:51:34 -0400
commit11b9164adad7cd119b82b1f2c911a6d9bc67f1cc (patch)
tree865bd5d31dccec6f6ff9d71534e83dad10e9e215 /fs
parent6011695da2d7c588f2dfe57c318758f0bf1154dd (diff)
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 <trond.myklebust@primarydata.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfsd/nfs4callback.c2
-rw-r--r--fs/nfsd/nfs4state.c69
-rw-r--r--fs/nfsd/state.h3
3 files changed, 36 insertions, 38 deletions
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 8574c708cf8c..e0be57b0f79b 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -337,7 +337,7 @@ static void encode_cb_recall4args(struct xdr_stream *xdr,
337 p = xdr_reserve_space(xdr, 4); 337 p = xdr_reserve_space(xdr, 4);
338 *p++ = xdr_zero; /* truncate */ 338 *p++ = xdr_zero; /* truncate */
339 339
340 encode_nfs_fh4(xdr, &dp->dl_file->fi_fhandle); 340 encode_nfs_fh4(xdr, &dp->dl_stid.sc_file->fi_fhandle);
341 341
342 hdr->nops++; 342 hdr->nops++;
343} 343}
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 60ab22b6e099..344cd1ac3f67 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -515,10 +515,6 @@ static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
515 515
516static void nfs4_free_deleg(struct nfs4_stid *stid) 516static void nfs4_free_deleg(struct nfs4_stid *stid)
517{ 517{
518 struct nfs4_delegation *dp = delegstateid(stid);
519
520 if (dp->dl_file)
521 put_nfs4_file(dp->dl_file);
522 kmem_cache_free(deleg_slab, stid); 518 kmem_cache_free(deleg_slab, stid);
523 atomic_long_dec(&num_delegations); 519 atomic_long_dec(&num_delegations);
524} 520}
@@ -636,12 +632,15 @@ out_dec:
636void 632void
637nfs4_put_stid(struct nfs4_stid *s) 633nfs4_put_stid(struct nfs4_stid *s)
638{ 634{
635 struct nfs4_file *fp = s->sc_file;
639 struct nfs4_client *clp = s->sc_client; 636 struct nfs4_client *clp = s->sc_client;
640 637
641 if (!atomic_dec_and_test(&s->sc_count)) 638 if (!atomic_dec_and_test(&s->sc_count))
642 return; 639 return;
643 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); 640 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
644 s->sc_free(s); 641 s->sc_free(s);
642 if (fp)
643 put_nfs4_file(fp);
645} 644}
646 645
647static void nfs4_put_deleg_lease(struct nfs4_file *fp) 646static void nfs4_put_deleg_lease(struct nfs4_file *fp)
@@ -677,7 +676,7 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
677static void 676static void
678unhash_delegation_locked(struct nfs4_delegation *dp) 677unhash_delegation_locked(struct nfs4_delegation *dp)
679{ 678{
680 struct nfs4_file *fp = dp->dl_file; 679 struct nfs4_file *fp = dp->dl_stid.sc_file;
681 680
682 lockdep_assert_held(&state_lock); 681 lockdep_assert_held(&state_lock);
683 682
@@ -864,7 +863,7 @@ reset_union_bmap_deny(u32 deny, struct nfs4_ol_stateid *stp)
864 863
865 /* Recalculate per-file deny mode if there was a change */ 864 /* Recalculate per-file deny mode if there was a change */
866 if (change) 865 if (change)
867 recalculate_deny_mode(stp->st_file); 866 recalculate_deny_mode(stp->st_stid.sc_file);
868} 867}
869 868
870/* release all access and file references for a given stateid */ 869/* release all access and file references for a given stateid */
@@ -872,21 +871,21 @@ static void
872release_all_access(struct nfs4_ol_stateid *stp) 871release_all_access(struct nfs4_ol_stateid *stp)
873{ 872{
874 int i; 873 int i;
875 struct nfs4_file *fp = stp->st_file; 874 struct nfs4_file *fp = stp->st_stid.sc_file;
876 875
877 if (fp && stp->st_deny_bmap != 0) 876 if (fp && stp->st_deny_bmap != 0)
878 recalculate_deny_mode(fp); 877 recalculate_deny_mode(fp);
879 878
880 for (i = 1; i < 4; i++) { 879 for (i = 1; i < 4; i++) {
881 if (test_access(i, stp)) 880 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);
883 clear_access(i, stp); 882 clear_access(i, stp);
884 } 883 }
885} 884}
886 885
887static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) 886static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
888{ 887{
889 struct nfs4_file *fp = stp->st_file; 888 struct nfs4_file *fp = stp->st_stid.sc_file;
890 889
891 spin_lock(&fp->fi_lock); 890 spin_lock(&fp->fi_lock);
892 list_del(&stp->st_perfile); 891 list_del(&stp->st_perfile);
@@ -899,8 +898,6 @@ static void nfs4_free_ol_stateid(struct nfs4_stid *stid)
899 struct nfs4_ol_stateid *stp = openlockstateid(stid); 898 struct nfs4_ol_stateid *stp = openlockstateid(stid);
900 899
901 release_all_access(stp); 900 release_all_access(stp);
902 if (stp->st_file)
903 put_nfs4_file(stp->st_file);
904 kmem_cache_free(stateid_slab, stid); 901 kmem_cache_free(stateid_slab, stid);
905} 902}
906 903
@@ -911,7 +908,7 @@ static void __release_lock_stateid(struct nfs4_ol_stateid *stp)
911 list_del(&stp->st_locks); 908 list_del(&stp->st_locks);
912 unhash_generic_stateid(stp); 909 unhash_generic_stateid(stp);
913 unhash_stid(&stp->st_stid); 910 unhash_stid(&stp->st_stid);
914 file = find_any_file(stp->st_file); 911 file = find_any_file(stp->st_stid.sc_file);
915 if (file) 912 if (file)
916 filp_close(file, (fl_owner_t)lockowner(stp->st_stateowner)); 913 filp_close(file, (fl_owner_t)lockowner(stp->st_stateowner));
917 nfs4_put_stid(&stp->st_stid); 914 nfs4_put_stid(&stp->st_stid);
@@ -2976,7 +2973,7 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
2976 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); 2973 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
2977 stp->st_stateowner = &oo->oo_owner; 2974 stp->st_stateowner = &oo->oo_owner;
2978 get_nfs4_file(fp); 2975 get_nfs4_file(fp);
2979 stp->st_file = fp; 2976 stp->st_stid.sc_file = fp;
2980 stp->st_access_bmap = 0; 2977 stp->st_access_bmap = 0;
2981 stp->st_deny_bmap = 0; 2978 stp->st_deny_bmap = 0;
2982 stp->st_openstp = NULL; 2979 stp->st_openstp = NULL;
@@ -3097,10 +3094,10 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
3097 3094
3098void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp) 3095void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp)
3099{ 3096{
3100 struct nfs4_client *clp = dp->dl_stid.sc_client; 3097 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net,
3101 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); 3098 nfsd_net_id);
3102 3099
3103 block_delegations(&dp->dl_file->fi_fhandle); 3100 block_delegations(&dp->dl_stid.sc_file->fi_fhandle);
3104 3101
3105 /* 3102 /*
3106 * We can't do this in nfsd_break_deleg_cb because it is 3103 * 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)
3508 3505
3509static int nfs4_setlease(struct nfs4_delegation *dp) 3506static int nfs4_setlease(struct nfs4_delegation *dp)
3510{ 3507{
3511 struct nfs4_file *fp = dp->dl_file; 3508 struct nfs4_file *fp = dp->dl_stid.sc_file;
3512 struct file_lock *fl; 3509 struct file_lock *fl;
3513 struct file *filp; 3510 struct file *filp;
3514 int status = 0; 3511 int status = 0;
@@ -3573,7 +3570,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh,
3573 get_nfs4_file(fp); 3570 get_nfs4_file(fp);
3574 spin_lock(&state_lock); 3571 spin_lock(&state_lock);
3575 spin_lock(&fp->fi_lock); 3572 spin_lock(&fp->fi_lock);
3576 dp->dl_file = fp; 3573 dp->dl_stid.sc_file = fp;
3577 if (!fp->fi_lease) { 3574 if (!fp->fi_lease) {
3578 spin_unlock(&fp->fi_lock); 3575 spin_unlock(&fp->fi_lock);
3579 spin_unlock(&state_lock); 3576 spin_unlock(&state_lock);
@@ -3669,7 +3666,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open,
3669 default: 3666 default:
3670 goto out_no_deleg; 3667 goto out_no_deleg;
3671 } 3668 }
3672 dp = nfs4_set_delegation(clp, fh, stp->st_file); 3669 dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file);
3673 if (IS_ERR(dp)) 3670 if (IS_ERR(dp))
3674 goto out_no_deleg; 3671 goto out_no_deleg;
3675 3672
@@ -3959,7 +3956,7 @@ laundromat_main(struct work_struct *laundry)
3959 3956
3960static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp) 3957static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp)
3961{ 3958{
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))
3963 return nfserr_bad_stateid; 3960 return nfserr_bad_stateid;
3964 return nfs_ok; 3961 return nfs_ok;
3965} 3962}
@@ -4167,7 +4164,7 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
4167 if (status) 4164 if (status)
4168 goto out; 4165 goto out;
4169 if (filpp) { 4166 if (filpp) {
4170 file = dp->dl_file->fi_deleg_file; 4167 file = dp->dl_stid.sc_file->fi_deleg_file;
4171 if (!file) { 4168 if (!file) {
4172 WARN_ON_ONCE(1); 4169 WARN_ON_ONCE(1);
4173 status = nfserr_serverfault; 4170 status = nfserr_serverfault;
@@ -4189,10 +4186,12 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
4189 if (status) 4186 if (status)
4190 goto out; 4187 goto out;
4191 if (filpp) { 4188 if (filpp) {
4189 struct nfs4_file *fp = stp->st_stid.sc_file;
4190
4192 if (flags & RD_STATE) 4191 if (flags & RD_STATE)
4193 file = find_readable_file(stp->st_file); 4192 file = find_readable_file(fp);
4194 else 4193 else
4195 file = find_writeable_file(stp->st_file); 4194 file = find_writeable_file(fp);
4196 } 4195 }
4197 break; 4196 break;
4198 default: 4197 default:
@@ -4212,7 +4211,7 @@ nfsd4_free_lock_stateid(struct nfs4_ol_stateid *stp)
4212{ 4211{
4213 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); 4212 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
4214 4213
4215 if (check_for_locks(stp->st_file, lo)) 4214 if (check_for_locks(stp->st_stid.sc_file, lo))
4216 return nfserr_locks_held; 4215 return nfserr_locks_held;
4217 release_lockowner_if_empty(lo); 4216 release_lockowner_if_empty(lo);
4218 return nfs_ok; 4217 return nfs_ok;
@@ -4403,7 +4402,7 @@ static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 a
4403{ 4402{
4404 if (!test_access(access, stp)) 4403 if (!test_access(access, stp))
4405 return; 4404 return;
4406 nfs4_file_put_access(stp->st_file, access); 4405 nfs4_file_put_access(stp->st_stid.sc_file, access);
4407 clear_access(access, stp); 4406 clear_access(access, stp);
4408} 4407}
4409 4408
@@ -4492,9 +4491,9 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
4492 * before returning however. 4491 * before returning however.
4493 */ 4492 */
4494 release_all_access(s); 4493 release_all_access(s);
4495 if (s->st_file) { 4494 if (s->st_stid.sc_file) {
4496 put_nfs4_file(s->st_file); 4495 put_nfs4_file(s->st_stid.sc_file);
4497 s->st_file = NULL; 4496 s->st_stid.sc_file = NULL;
4498 } 4497 }
4499 oo->oo_last_closed_stid = s; 4498 oo->oo_last_closed_stid = s;
4500 if (list_empty(&oo->oo_owner.so_stateids)) 4499 if (list_empty(&oo->oo_owner.so_stateids))
@@ -4695,7 +4694,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
4695 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); 4694 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
4696 stp->st_stateowner = &lo->lo_owner; 4695 stp->st_stateowner = &lo->lo_owner;
4697 get_nfs4_file(fp); 4696 get_nfs4_file(fp);
4698 stp->st_file = fp; 4697 stp->st_stid.sc_file = fp;
4699 stp->st_access_bmap = 0; 4698 stp->st_access_bmap = 0;
4700 stp->st_deny_bmap = open_stp->st_deny_bmap; 4699 stp->st_deny_bmap = open_stp->st_deny_bmap;
4701 stp->st_openstp = open_stp; 4700 stp->st_openstp = open_stp;
@@ -4712,7 +4711,7 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp)
4712 struct nfs4_ol_stateid *lst; 4711 struct nfs4_ol_stateid *lst;
4713 4712
4714 list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { 4713 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)
4716 return lst; 4715 return lst;
4717 } 4716 }
4718 return NULL; 4717 return NULL;
@@ -4728,7 +4727,7 @@ check_lock_length(u64 offset, u64 length)
4728 4727
4729static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access) 4728static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
4730{ 4729{
4731 struct nfs4_file *fp = lock_stp->st_file; 4730 struct nfs4_file *fp = lock_stp->st_stid.sc_file;
4732 4731
4733 lockdep_assert_held(&fp->fi_lock); 4732 lockdep_assert_held(&fp->fi_lock);
4734 4733
@@ -4740,7 +4739,7 @@ static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
4740 4739
4741static __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) 4740static __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)
4742{ 4741{
4743 struct nfs4_file *fi = ost->st_file; 4742 struct nfs4_file *fi = ost->st_stid.sc_file;
4744 struct nfs4_openowner *oo = openowner(ost->st_stateowner); 4743 struct nfs4_openowner *oo = openowner(ost->st_stateowner);
4745 struct nfs4_client *cl = oo->oo_owner.so_client; 4744 struct nfs4_client *cl = oo->oo_owner.so_client;
4746 struct inode *inode = cstate->current_fh.fh_dentry->d_inode; 4745 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,
4865 goto out; 4864 goto out;
4866 } 4865 }
4867 4866
4868 fp = lock_stp->st_file; 4867 fp = lock_stp->st_stid.sc_file;
4869 locks_init_lock(file_lock); 4868 locks_init_lock(file_lock);
4870 switch (lock->lk_type) { 4869 switch (lock->lk_type) {
4871 case NFS4_READ_LT: 4870 case NFS4_READ_LT:
@@ -5065,7 +5064,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
5065 &stp, nn); 5064 &stp, nn);
5066 if (status) 5065 if (status)
5067 goto out; 5066 goto out;
5068 filp = find_any_file(stp->st_file); 5067 filp = find_any_file(stp->st_stid.sc_file);
5069 if (!filp) { 5068 if (!filp) {
5070 status = nfserr_lock_range; 5069 status = nfserr_lock_range;
5071 goto out; 5070 goto out;
@@ -5188,7 +5187,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
5188 lo = lockowner(sop); 5187 lo = lockowner(sop);
5189 /* see if there are still any locks associated with it */ 5188 /* see if there are still any locks associated with it */
5190 list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { 5189 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))
5192 goto out; 5191 goto out;
5193 } 5192 }
5194 5193
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 32c466265ac1..af1d9c42e939 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -85,6 +85,7 @@ struct nfs4_stid {
85 unsigned char sc_type; 85 unsigned char sc_type;
86 stateid_t sc_stateid; 86 stateid_t sc_stateid;
87 struct nfs4_client *sc_client; 87 struct nfs4_client *sc_client;
88 struct nfs4_file *sc_file;
88 void (*sc_free)(struct nfs4_stid *); 89 void (*sc_free)(struct nfs4_stid *);
89}; 90};
90 91
@@ -93,7 +94,6 @@ struct nfs4_delegation {
93 struct list_head dl_perfile; 94 struct list_head dl_perfile;
94 struct list_head dl_perclnt; 95 struct list_head dl_perclnt;
95 struct list_head dl_recall_lru; /* delegation recalled */ 96 struct list_head dl_recall_lru; /* delegation recalled */
96 struct nfs4_file *dl_file;
97 u32 dl_type; 97 u32 dl_type;
98 time_t dl_time; 98 time_t dl_time;
99/* For recall: */ 99/* For recall: */
@@ -407,7 +407,6 @@ struct nfs4_ol_stateid {
407 struct list_head st_perstateowner; 407 struct list_head st_perstateowner;
408 struct list_head st_locks; 408 struct list_head st_locks;
409 struct nfs4_stateowner * st_stateowner; 409 struct nfs4_stateowner * st_stateowner;
410 struct nfs4_file * st_file;
411 unsigned char st_access_bmap; 410 unsigned char st_access_bmap;
412 unsigned char st_deny_bmap; 411 unsigned char st_deny_bmap;
413 struct nfs4_ol_stateid * st_openstp; 412 struct nfs4_ol_stateid * st_openstp;