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>
This commit is contained in:
Trond Myklebust 2014-07-29 21:34:08 -04:00 коммит произвёл J. Bruce Fields
Родитель 6011695da2
Коммит 11b9164ada
3 изменённых файлов: 36 добавлений и 38 удалений

Просмотреть файл

@ -337,7 +337,7 @@ static void encode_cb_recall4args(struct xdr_stream *xdr,
p = xdr_reserve_space(xdr, 4); p = xdr_reserve_space(xdr, 4);
*p++ = xdr_zero; /* truncate */ *p++ = xdr_zero; /* truncate */
encode_nfs_fh4(xdr, &dp->dl_file->fi_fhandle); encode_nfs_fh4(xdr, &dp->dl_stid.sc_file->fi_fhandle);
hdr->nops++; hdr->nops++;
} }

Просмотреть файл

@ -515,10 +515,6 @@ static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
static void nfs4_free_deleg(struct nfs4_stid *stid) static void nfs4_free_deleg(struct nfs4_stid *stid)
{ {
struct nfs4_delegation *dp = delegstateid(stid);
if (dp->dl_file)
put_nfs4_file(dp->dl_file);
kmem_cache_free(deleg_slab, stid); kmem_cache_free(deleg_slab, stid);
atomic_long_dec(&num_delegations); atomic_long_dec(&num_delegations);
} }
@ -636,12 +632,15 @@ out_dec:
void void
nfs4_put_stid(struct nfs4_stid *s) nfs4_put_stid(struct nfs4_stid *s)
{ {
struct nfs4_file *fp = s->sc_file;
struct nfs4_client *clp = s->sc_client; struct nfs4_client *clp = s->sc_client;
if (!atomic_dec_and_test(&s->sc_count)) if (!atomic_dec_and_test(&s->sc_count))
return; return;
idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
s->sc_free(s); s->sc_free(s);
if (fp)
put_nfs4_file(fp);
} }
static void nfs4_put_deleg_lease(struct nfs4_file *fp) 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)
static void static void
unhash_delegation_locked(struct nfs4_delegation *dp) unhash_delegation_locked(struct nfs4_delegation *dp)
{ {
struct nfs4_file *fp = dp->dl_file; struct nfs4_file *fp = dp->dl_stid.sc_file;
lockdep_assert_held(&state_lock); lockdep_assert_held(&state_lock);
@ -864,7 +863,7 @@ reset_union_bmap_deny(u32 deny, struct nfs4_ol_stateid *stp)
/* Recalculate per-file deny mode if there was a change */ /* Recalculate per-file deny mode if there was a change */
if (change) if (change)
recalculate_deny_mode(stp->st_file); recalculate_deny_mode(stp->st_stid.sc_file);
} }
/* release all access and file references for a given stateid */ /* release all access and file references for a given stateid */
@ -872,21 +871,21 @@ static void
release_all_access(struct nfs4_ol_stateid *stp) release_all_access(struct nfs4_ol_stateid *stp)
{ {
int i; int i;
struct nfs4_file *fp = stp->st_file; struct nfs4_file *fp = stp->st_stid.sc_file;
if (fp && stp->st_deny_bmap != 0) if (fp && stp->st_deny_bmap != 0)
recalculate_deny_mode(fp); recalculate_deny_mode(fp);
for (i = 1; i < 4; i++) { for (i = 1; i < 4; i++) {
if (test_access(i, stp)) if (test_access(i, stp))
nfs4_file_put_access(stp->st_file, i); nfs4_file_put_access(stp->st_stid.sc_file, i);
clear_access(i, stp); clear_access(i, stp);
} }
} }
static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
{ {
struct nfs4_file *fp = stp->st_file; struct nfs4_file *fp = stp->st_stid.sc_file;
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
list_del(&stp->st_perfile); list_del(&stp->st_perfile);
@ -899,8 +898,6 @@ static void nfs4_free_ol_stateid(struct nfs4_stid *stid)
struct nfs4_ol_stateid *stp = openlockstateid(stid); struct nfs4_ol_stateid *stp = openlockstateid(stid);
release_all_access(stp); release_all_access(stp);
if (stp->st_file)
put_nfs4_file(stp->st_file);
kmem_cache_free(stateid_slab, stid); kmem_cache_free(stateid_slab, stid);
} }
@ -911,7 +908,7 @@ static void __release_lock_stateid(struct nfs4_ol_stateid *stp)
list_del(&stp->st_locks); list_del(&stp->st_locks);
unhash_generic_stateid(stp); unhash_generic_stateid(stp);
unhash_stid(&stp->st_stid); unhash_stid(&stp->st_stid);
file = find_any_file(stp->st_file); file = find_any_file(stp->st_stid.sc_file);
if (file) if (file)
filp_close(file, (fl_owner_t)lockowner(stp->st_stateowner)); filp_close(file, (fl_owner_t)lockowner(stp->st_stateowner));
nfs4_put_stid(&stp->st_stid); nfs4_put_stid(&stp->st_stid);
@ -2976,7 +2973,7 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
stp->st_stateowner = &oo->oo_owner; stp->st_stateowner = &oo->oo_owner;
get_nfs4_file(fp); get_nfs4_file(fp);
stp->st_file = fp; stp->st_stid.sc_file = fp;
stp->st_access_bmap = 0; stp->st_access_bmap = 0;
stp->st_deny_bmap = 0; stp->st_deny_bmap = 0;
stp->st_openstp = NULL; stp->st_openstp = NULL;
@ -3097,10 +3094,10 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp) void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp)
{ {
struct nfs4_client *clp = dp->dl_stid.sc_client; struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net,
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); nfsd_net_id);
block_delegations(&dp->dl_file->fi_fhandle); block_delegations(&dp->dl_stid.sc_file->fi_fhandle);
/* /*
* We can't do this in nfsd_break_deleg_cb because it is * 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)
static int nfs4_setlease(struct nfs4_delegation *dp) static int nfs4_setlease(struct nfs4_delegation *dp)
{ {
struct nfs4_file *fp = dp->dl_file; struct nfs4_file *fp = dp->dl_stid.sc_file;
struct file_lock *fl; struct file_lock *fl;
struct file *filp; struct file *filp;
int status = 0; int status = 0;
@ -3573,7 +3570,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh,
get_nfs4_file(fp); get_nfs4_file(fp);
spin_lock(&state_lock); spin_lock(&state_lock);
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
dp->dl_file = fp; dp->dl_stid.sc_file = fp;
if (!fp->fi_lease) { if (!fp->fi_lease) {
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
spin_unlock(&state_lock); spin_unlock(&state_lock);
@ -3669,7 +3666,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open,
default: default:
goto out_no_deleg; goto out_no_deleg;
} }
dp = nfs4_set_delegation(clp, fh, stp->st_file); dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file);
if (IS_ERR(dp)) if (IS_ERR(dp))
goto out_no_deleg; goto out_no_deleg;
@ -3959,7 +3956,7 @@ laundromat_main(struct work_struct *laundry)
static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp) static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp)
{ {
if (!nfsd_fh_match(&fhp->fh_handle, &stp->st_file->fi_fhandle)) if (!nfsd_fh_match(&fhp->fh_handle, &stp->st_stid.sc_file->fi_fhandle))
return nfserr_bad_stateid; return nfserr_bad_stateid;
return nfs_ok; return nfs_ok;
} }
@ -4167,7 +4164,7 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
if (status) if (status)
goto out; goto out;
if (filpp) { if (filpp) {
file = dp->dl_file->fi_deleg_file; file = dp->dl_stid.sc_file->fi_deleg_file;
if (!file) { if (!file) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
status = nfserr_serverfault; status = nfserr_serverfault;
@ -4189,10 +4186,12 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
if (status) if (status)
goto out; goto out;
if (filpp) { if (filpp) {
struct nfs4_file *fp = stp->st_stid.sc_file;
if (flags & RD_STATE) if (flags & RD_STATE)
file = find_readable_file(stp->st_file); file = find_readable_file(fp);
else else
file = find_writeable_file(stp->st_file); file = find_writeable_file(fp);
} }
break; break;
default: default:
@ -4212,7 +4211,7 @@ nfsd4_free_lock_stateid(struct nfs4_ol_stateid *stp)
{ {
struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
if (check_for_locks(stp->st_file, lo)) if (check_for_locks(stp->st_stid.sc_file, lo))
return nfserr_locks_held; return nfserr_locks_held;
release_lockowner_if_empty(lo); release_lockowner_if_empty(lo);
return nfs_ok; return nfs_ok;
@ -4403,7 +4402,7 @@ static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 a
{ {
if (!test_access(access, stp)) if (!test_access(access, stp))
return; return;
nfs4_file_put_access(stp->st_file, access); nfs4_file_put_access(stp->st_stid.sc_file, access);
clear_access(access, stp); clear_access(access, stp);
} }
@ -4492,9 +4491,9 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s)
* before returning however. * before returning however.
*/ */
release_all_access(s); release_all_access(s);
if (s->st_file) { if (s->st_stid.sc_file) {
put_nfs4_file(s->st_file); put_nfs4_file(s->st_stid.sc_file);
s->st_file = NULL; s->st_stid.sc_file = NULL;
} }
oo->oo_last_closed_stid = s; oo->oo_last_closed_stid = s;
if (list_empty(&oo->oo_owner.so_stateids)) if (list_empty(&oo->oo_owner.so_stateids))
@ -4695,7 +4694,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
stp->st_stateowner = &lo->lo_owner; stp->st_stateowner = &lo->lo_owner;
get_nfs4_file(fp); get_nfs4_file(fp);
stp->st_file = fp; stp->st_stid.sc_file = fp;
stp->st_access_bmap = 0; stp->st_access_bmap = 0;
stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_deny_bmap = open_stp->st_deny_bmap;
stp->st_openstp = open_stp; stp->st_openstp = open_stp;
@ -4712,7 +4711,7 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp)
struct nfs4_ol_stateid *lst; struct nfs4_ol_stateid *lst;
list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) {
if (lst->st_file == fp) if (lst->st_stid.sc_file == fp)
return lst; return lst;
} }
return NULL; return NULL;
@ -4728,7 +4727,7 @@ check_lock_length(u64 offset, u64 length)
static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access) static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
{ {
struct nfs4_file *fp = lock_stp->st_file; struct nfs4_file *fp = lock_stp->st_stid.sc_file;
lockdep_assert_held(&fp->fi_lock); lockdep_assert_held(&fp->fi_lock);
@ -4740,7 +4739,7 @@ static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
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) 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)
{ {
struct nfs4_file *fi = ost->st_file; struct nfs4_file *fi = ost->st_stid.sc_file;
struct nfs4_openowner *oo = openowner(ost->st_stateowner); struct nfs4_openowner *oo = openowner(ost->st_stateowner);
struct nfs4_client *cl = oo->oo_owner.so_client; struct nfs4_client *cl = oo->oo_owner.so_client;
struct inode *inode = cstate->current_fh.fh_dentry->d_inode; 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,
goto out; goto out;
} }
fp = lock_stp->st_file; fp = lock_stp->st_stid.sc_file;
locks_init_lock(file_lock); locks_init_lock(file_lock);
switch (lock->lk_type) { switch (lock->lk_type) {
case NFS4_READ_LT: case NFS4_READ_LT:
@ -5065,7 +5064,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
&stp, nn); &stp, nn);
if (status) if (status)
goto out; goto out;
filp = find_any_file(stp->st_file); filp = find_any_file(stp->st_stid.sc_file);
if (!filp) { if (!filp) {
status = nfserr_lock_range; status = nfserr_lock_range;
goto out; goto out;
@ -5188,7 +5187,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
lo = lockowner(sop); lo = lockowner(sop);
/* see if there are still any locks associated with it */ /* see if there are still any locks associated with it */
list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) {
if (check_for_locks(stp->st_file, lo)) if (check_for_locks(stp->st_stid.sc_file, lo))
goto out; goto out;
} }

Просмотреть файл

@ -85,6 +85,7 @@ struct nfs4_stid {
unsigned char sc_type; unsigned char sc_type;
stateid_t sc_stateid; stateid_t sc_stateid;
struct nfs4_client *sc_client; struct nfs4_client *sc_client;
struct nfs4_file *sc_file;
void (*sc_free)(struct nfs4_stid *); void (*sc_free)(struct nfs4_stid *);
}; };
@ -93,7 +94,6 @@ struct nfs4_delegation {
struct list_head dl_perfile; struct list_head dl_perfile;
struct list_head dl_perclnt; struct list_head dl_perclnt;
struct list_head dl_recall_lru; /* delegation recalled */ struct list_head dl_recall_lru; /* delegation recalled */
struct nfs4_file *dl_file;
u32 dl_type; u32 dl_type;
time_t dl_time; time_t dl_time;
/* For recall: */ /* For recall: */
@ -407,7 +407,6 @@ struct nfs4_ol_stateid {
struct list_head st_perstateowner; struct list_head st_perstateowner;
struct list_head st_locks; struct list_head st_locks;
struct nfs4_stateowner * st_stateowner; struct nfs4_stateowner * st_stateowner;
struct nfs4_file * st_file;
unsigned char st_access_bmap; unsigned char st_access_bmap;
unsigned char st_deny_bmap; unsigned char st_deny_bmap;
struct nfs4_ol_stateid * st_openstp; struct nfs4_ol_stateid * st_openstp;