stateid handling improvements
Subsystems (2)
Ensure that we allocate a file structure in nfs4_preprocess_stateid_op for all callers that as for it to consolidate code and fix the handling of ALLOCATE, DEALLOCATE and SEEK to match the latest NFSv4.2 drafts.
PATCH 1/5 nfsd: clean up raparams handling
Refactor the raparam hash helpers to just deal with the raparms, and keep opening/closing files separate from that.
--- fs/nfsd/nfs4xdr.c | 24 +++++++++++++------- fs/nfsd/vfs.c | 68 ++++++++++++++++++++----------------------------------- fs/nfsd/vfs.h | 6 ++--- 3 files changed, 43 insertions(+), 55 deletions(-)
fs/nfsd/nfs4xdr.c +16 -8
@@ -33,6 +33,7 @@* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <linux/file.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/statfs.h>
@@ -3419,7 +3420,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,struct file *file = read->rd_filp;struct svc_fh *fhp = read->rd_fhp;int starting_len = xdr->buf->len; -struct raparms *ra; +struct raparms *ra =NULL ;__be32 *p;__be32 err;
@@ -3441,23 +3442,30 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len)); maxcount = min_t(unsigned long, maxcount, read->rd_length); -if (read->rd_filp) +if (read->rd_filp) { err =nfsd_permission (resp->rqstp, fhp->fh_export, fhp->fh_dentry,NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); -else - err =nfsd_get_tmp_read_open (resp->rqstp, read->rd_fhp, - &file, &ra); -if (err) - goto err_truncate; +if (err) + goto err_truncate; + }else { + err =nfsd_open (resp->rqstp, fhp,S_IFREG ,NFSD_MAY_READ , + &file); +if (err) + goto err_truncate; + + ra =nfsd_init_raparms (file); + }if (file->f_op->splice_read &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) err =nfsd4_encode_splice_read (resp, read, file, maxcount);else err =nfsd4_encode_readv (resp, read, file, maxcount); +if (ra) +nfsd_put_raparams (file, ra);if (!read->rd_filp) -nfsd_put_tmp_read_open (file, ra); +fput (file); err_truncate:if (err)
fs/nfsd/vfs.c +24 -44
100 lines not on this page · raw message
fs/nfsd/vfs.h +3 -3
@@ -72,9 +72,6 @@ __be32 nfsd_commit(struct svc_rqst *, struct svc_fh *,__be32 nfsd_open (struct svc_rqst *,struct svc_fh *,umode_t ,int ,struct file **);struct raparms ; -__be32 nfsd_get_tmp_read_open (struct svc_rqst *,struct svc_fh *, -struct file **,struct raparms **); -void nfsd_put_tmp_read_open (struct file *,struct raparms *);__be32 nfsd_splice_read (struct svc_rqst *,struct file *,loff_t ,unsigned long *); __be32 nfsd_readv(struct file *, loff_t, struct kvec *, int,
@@ -103,6 +100,9 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,__be32 nfsd_permission (struct svc_rqst *,struct svc_export *,struct dentry *,int ); +struct raparms *nfsd_init_raparms (struct file *file); +void nfsd_put_raparams (struct file *file,struct raparms *ra); +static inline int fh_want_write (struct svc_fh *fh) {int ret =mnt_want_write (fh->fh_export->ex_path.mnt);
Signature · 1 line
1.9.1
PATCH 2/5 nfsd: refactor nfs4_preprocess_stateid_op
In reply to Christoph HellwigSplit out two self contained helpers to make the function more readable.
--- fs/nfsd/nfs4state.c | 97 ++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 45 deletions(-)
fs/nfsd/nfs4state.c +52 -45
@@ -4573,20 +4573,51 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,return nfs_ok; } +static struct file * +nfs4_find_file (struct nfs4_stid *s,int flags) +{ +switch (s->sc_type) { +case NFS4_DELEG_STID : +if (WARN_ON_ONCE (!s->sc_file->fi_deleg_file)) +return NULL ; +return get_file (s->sc_file->fi_deleg_file); +case NFS4_OPEN_STID : +case NFS4_LOCK_STID : +if (flags &RD_STATE ) +return find_readable_file (s->sc_file); +else +return find_writeable_file (s->sc_file); +break ; + } + +return NULL ; +} + +static __be32 +nfs4_check_olstateid (struct svc_fh *fhp,struct nfs4_ol_stateid *ols,int flags) +{ +__be32 status; + + status =nfs4_check_fh (fhp, ols); +if (status) +return status; + status =nfsd4_check_openowner_confirmed (ols); +if (status) +return status; +return nfs4_check_openmode (ols, flags); +} +/* -* Checks for stateid operations -*/ +* Checks for stateid operations +*/ __be32 nfs4_preprocess_stateid_op (struct net *net,struct nfsd4_compound_state *cstate,stateid_t *stateid,int flags,struct file **filpp) { -struct nfs4_stid *s; -struct nfs4_ol_stateid *stp =NULL ; -struct nfs4_delegation *dp =NULL ; -struct svc_fh *current_fh = &cstate->current_fh; -struct inode *ino =d_inode (current_fh->fh_dentry); +struct svc_fh *fhp = &cstate->current_fh; +struct inode *ino =d_inode (fhp->fh_dentry);struct nfsd_net *nn =net_generic (net, nfsd_net_id); -struct file *file =NULL ; +struct nfs4_stid *s;__be32 status;if (filpp)
@@ -4596,60 +4627,36 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,return nfserr_grace;if (ZERO_STATEID (stateid) ||ONE_STATEID (stateid)) -return check_special_stateids (net, current_fh, stateid, flags); +return check_special_stateids (net, fhp, stateid, flags); status =nfsd4_lookup_stateid (cstate, stateid,NFS4_DELEG_STID |NFS4_OPEN_STID |NFS4_LOCK_STID , &s, nn);if (status)return status; - status =check_stateid_generation (stateid, &s->sc_stateid,nfsd4_has_session (cstate)); + status =check_stateid_generation (stateid, &s->sc_stateid, +nfsd4_has_session (cstate));if (status) goto out; +switch (s->sc_type) {case NFS4_DELEG_STID : - dp =delegstateid (s); - status =nfs4_check_delegmode (dp, flags); -if (status) - goto out; -if (filpp) { - file = dp->dl_stid.sc_file->fi_deleg_file; -if (!file) { -WARN_ON_ONCE (1 ); - status = nfserr_serverfault; - goto out; - } -get_file (file); - } + status =nfs4_check_delegmode (delegstateid (s), flags);break ;case NFS4_OPEN_STID :case NFS4_LOCK_STID : - stp =openlockstateid (s); - status =nfs4_check_fh (current_fh, stp); -if (status) - goto out; - status =nfsd4_check_openowner_confirmed (stp); -if (status) - goto out; - status =nfs4_check_openmode (stp, flags); -if (status) - goto out; -if (filpp) { -struct nfs4_file *fp = stp->st_stid.sc_file; - -if (flags &RD_STATE ) - file =find_readable_file (fp); -else - file =find_writeable_file (fp); - } + status =nfs4_check_olstateid (fhp,openlockstateid (s), flags);break ;default : status = nfserr_bad_stateid; - goto out; +break ; + } + +if (!status && filpp) { + *filpp =nfs4_find_file (s, flags); +if (!*filpp) + status = nfserr_serverfault; } - status = nfs_ok; -if (file) - *filpp = file; out:nfs4_put_stid (s);return status;
Signature · 1 line
1.9.1
PATCH 3/5 nfsd: take struct file setup fully into nfs4_preprocess_stateid_op
In reply to Christoph HellwigThis patch changes nfs4_preprocess_stateid_op so it always returns a valid struct file if it has been asked for that. For that we now allocate a temporary struct file for special stateids, and check permissions if we got the file structure from the stateid. This ensures that all callers will get their handling of special stateids right, and avoids code duplication.
There is a little wart in here because the read code needs to know if we allocated a file structure so that it can copy around the read-ahead parameters. In the long run we should probably aim to cache full file structures used with special stateids instead.
--- fs/nfsd/nfs4proc.c | 39 ++++++++++++++-------------------- fs/nfsd/nfs4state.c | 60 +++++++++++++++++++++++++++++++++++++++++++---------- fs/nfsd/nfs4xdr.c | 19 +---------------- fs/nfsd/state.h | 6 +++--- fs/nfsd/vfs.c | 7 +------ fs/nfsd/vfs.h | 4 ++++ fs/nfsd/xdr4.h | 1 + 7 files changed, 74 insertions(+), 62 deletions(-)
fs/nfsd/nfs4proc.c +15 -24
@@ -760,8 +760,6 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, {__be32 status; -/* no need to check permission - this will be done in nfsd_read() */ - read->rd_filp =NULL ;if (read->rd_offset >=OFFSET_MAX )return nfserr_inval;
@@ -778,9 +776,9 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,clear_bit (RQ_SPLICE_OK , &rqstp->rq_flags);/* check stateid */ -if ((status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), - cstate, &read->rd_stateid, -RD_STATE , &read->rd_filp))) { + status =nfs4_preprocess_stateid_op (rqstp, cstate, &read->rd_stateid, +RD_STATE , &read->rd_filp, &read->rd_tmp_file); +if (status) {dprintk ("NFSD: nfsd4_read: couldn't process stateid!\n" ); goto out; }
@@ -924,8 +922,8 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,int err;if (setattr->sa_iattr.ia_valid &ATTR_SIZE ) { - status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), cstate, - &setattr->sa_stateid,WR_STATE ,NULL ); + status =nfs4_preprocess_stateid_op (rqstp, cstate, + &setattr->sa_stateid,WR_STATE ,NULL ,NULL );if (status) {dprintk ("NFSD: nfsd4_setattr: couldn't process stateid!\n" );return status;
@@ -986,13 +984,11 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,unsigned long cnt;int nvecs; -/* no need to check permission - this will be done in nfsd_write() */ -if (write->wr_offset >=OFFSET_MAX )return nfserr_inval; - status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), - cstate, stateid,WR_STATE , &filp); + status =nfs4_preprocess_stateid_op (rqstp, cstate, stateid,WR_STATE , + &filp,NULL );if (status) {dprintk ("NFSD: nfsd4_write: couldn't process stateid!\n" );return status;
@@ -1005,11 +1001,10 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nvecs =fill_in_write_vector (rqstp->rq_vec, write);WARN_ON_ONCE (nvecs >ARRAY_SIZE (rqstp->rq_vec)); - status =nfsd_write (rqstp, &cstate->current_fh, filp, - write->wr_offset, rqstp->rq_vec, nvecs, - &cnt, &write->wr_how_written); -if (filp) -fput (filp); + status =nfsd_vfs_write (rqstp, &cstate->current_fh, filp, + write->wr_offset, rqstp->rq_vec, nvecs, &cnt, + &write->wr_how_written); +fput (filp); write->wr_bytes_written = cnt;
@@ -1023,15 +1018,13 @@ nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,__be32 status = nfserr_notsupp;struct file *file; - status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), cstate, + status =nfs4_preprocess_stateid_op (rqstp, cstate, &fallocate->falloc_stateid, -WR_STATE , &file); +WR_STATE , &file,NULL );if (status != nfs_ok) {dprintk ("NFSD: nfsd4_fallocate: couldn't process stateid!\n" );return status; } -if (!file) -return nfserr_bad_stateid; status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, fallocate->falloc_offset,
@@ -1064,15 +1057,13 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,__be32 status;struct file *file; - status =nfs4_preprocess_stateid_op (SVC_NET (rqstp), cstate, + status =nfs4_preprocess_stateid_op (rqstp, cstate, &seek->seek_stateid, -RD_STATE , &file); +RD_STATE , &file,NULL );if (status) {dprintk ("NFSD: nfsd4_seek: couldn't process stateid!\n" );return status; } -if (!file) -return nfserr_bad_stateid;switch (seek->seek_whence) {case NFS4_CONTENT_DATA :
fs/nfsd/nfs4state.c +49 -11
95 lines not on this page · raw message
fs/nfsd/nfs4xdr.c +1 -18
@@ -33,7 +33,6 @@* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <linux/file.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/statfs.h>
@@ -3418,7 +3417,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,unsigned long maxcount;struct xdr_stream *xdr = &resp->xdr;struct file *file = read->rd_filp; -struct svc_fh *fhp = read->rd_fhp;int starting_len = xdr->buf->len;struct raparms *ra =NULL ;__be32 *p;
@@ -3442,20 +3440,8 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len)); maxcount = min_t(unsigned long, maxcount, read->rd_length); -if (read->rd_filp) { - err =nfsd_permission (resp->rqstp, fhp->fh_export, - fhp->fh_dentry, -NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); -if (err) - goto err_truncate; - }else { - err =nfsd_open (resp->rqstp, fhp,S_IFREG ,NFSD_MAY_READ , - &file); -if (err) - goto err_truncate; - +if (read->rd_tmp_file) ra =nfsd_init_raparms (file); - }if (file->f_op->splice_read &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) err =nfsd4_encode_splice_read (resp, read, file, maxcount);
@@ -3464,10 +3450,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,if (ra)nfsd_put_raparams (file, ra); -if (!read->rd_filp) -fput (file); -err_truncate:if (err)xdr_truncate_encode (xdr, starting_len);return err;
fs/nfsd/state.h +3 -3
@@ -582,9 +582,9 @@ enum nfsd4_cb_op {struct nfsd4_compound_state ;struct nfsd_net ; -extern __be32 nfs4_preprocess_stateid_op (struct net *net, -struct nfsd4_compound_state *cstate, -stateid_t *stateid,int flags,struct file **filp); +extern __be32 nfs4_preprocess_stateid_op (struct svc_rqst *rqstp, +struct nfsd4_compound_state *cstate,stateid_t *stateid, +int flags,struct file **filp,bool *tmp_file);__be32 nfsd4_lookup_stateid (struct nfsd4_compound_state *cstate,stateid_t *stateid,unsigned char typemask,struct nfs4_stid **s,struct nfsd_net *nn);
fs/nfsd/vfs.c +1 -6
@@ -508,16 +508,11 @@ __be32 nfsd4_vfs_fallocate(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, loff_t offset, loff_t len, int flags) { - __be32 err; int error;if (!S_ISREG (file_inode (file)->i_mode))return nfserr_inval; - err =nfsd_permission (rqstp, fhp->fh_export, fhp->fh_dentry,NFSD_MAY_WRITE ); -if (err) -return err; - error =vfs_fallocate (file, flags, offset, len);if (!error) error =commit_metadata (fhp);
@@ -918,7 +913,7 @@ static int wait_for_concurrent_writes(struct file *file)return err; } -static __be32 +__be32 nfsd_vfs_write (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,struct kvec *vec,int vlen,unsigned long *cnt,int *stablep)
fs/nfsd/vfs.h +4 -0
@@ -80,6 +80,10 @@ __be32 nfsd_read(struct svc_rqst *, struct svc_fh *, loff_t, struct kvec *, int, unsigned long *);__be32 nfsd_write (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,struct kvec *,int ,unsigned long *,int *); +__be32 nfsd_vfs_write (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct file *file,loff_t offset, +struct kvec *vec,int vlen,unsigned long *cnt, +int *stablep);__be32 nfsd_readlink (struct svc_rqst *,struct svc_fh *,char *,int *); __be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr4.h +1 -0
@@ -273,6 +273,7 @@ struct nfsd4_read {u32 rd_length;/* request */ int rd_vlen;struct file *rd_filp; +bool rd_tmp_file;struct svc_rqst *rd_rqstp;/* response */ struct svc_fh * rd_fhp;/* response */
Signature · 1 line
1.9.1
PATCH 4/5 nfsd: fput rd_file from XDR encode context
In reply to Christoph HellwigRemove the hack where we fput the read-specific file in generic code. Instead we can do it in nfsd4_encode_read as that gets called for all error cases as well.
--- fs/nfsd/nfs4proc.c | 4 ---- fs/nfsd/nfs4xdr.c | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-)
fs/nfsd/nfs4proc.c +0 -4
@@ -1723,10 +1723,6 @@ encode_op: be32_to_cpu(status));nfsd4_cstate_clear_replay (cstate); -/* XXX Ugh, we need to get rid of this kind of special case: */ -if (op->opnum ==OP_READ && op->u.read.rd_filp) -fput (op->u.read.rd_filp); -nfsd4_increment_op_stats (op->opnum); }
fs/nfsd/nfs4xdr.c +14 -8
@@ -33,6 +33,7 @@* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <linux/file.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/statfs.h>
@@ -3420,19 +3421,20 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,int starting_len = xdr->buf->len;struct raparms *ra =NULL ;__be32 *p; -__be32 err;if (nfserr) -return nfserr; + goto out; p =xdr_reserve_space (xdr,8 );/* eof flag and byte count */ if (!p) {WARN_ON_ONCE (test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)); -return nfserr_resource; + nfserr = nfserr_resource; + goto out; }if (resp->xdr.buf->page_len &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) {WARN_ON_ONCE (1 ); -return nfserr_resource; + nfserr = nfserr_resource; + goto out; }xdr_commit_encode (xdr);
@@ -3444,16 +3446,20 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, ra =nfsd_init_raparms (file);if (file->f_op->splice_read &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) - err =nfsd4_encode_splice_read (resp, read, file, maxcount); + nfserr =nfsd4_encode_splice_read (resp, read, file, maxcount);else - err =nfsd4_encode_readv (resp, read, file, maxcount); + nfserr =nfsd4_encode_readv (resp, read, file, maxcount);if (ra)nfsd_put_raparams (file, ra); -if (err) +if (nfserr)xdr_truncate_encode (xdr, starting_len); -return err; + +out: +if (file) +fput (file); +return nfserr; } static __be32
Signature · 1 line
1.9.1
PATCH 5/5 nfsd: wrap too long lines in nfsd4_encode_read
In reply to Christoph Hellwig--- fs/nfsd/nfs4xdr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/nfsd/nfs4xdr.c +6 -3
@@ -3431,7 +3431,8 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, nfserr = nfserr_resource; goto out; } -if (resp->xdr.buf->page_len &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) { +if (resp->xdr.buf->page_len && +test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) {WARN_ON_ONCE (1 ); nfserr = nfserr_resource; goto out;
@@ -3439,13 +3440,15 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,xdr_commit_encode (xdr); maxcount =svc_max_payload (resp->rqstp); - maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len)); + maxcount = min_t(unsigned long, maxcount, + (xdr->buf->buflen - xdr->buf->len)); maxcount = min_t(unsigned long, maxcount, read->rd_length);if (read->rd_tmp_file) ra =nfsd_init_raparms (file); -if (file->f_op->splice_read &&test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) +if (file->f_op->splice_read && +test_bit (RQ_SPLICE_OK , &resp->rqstp->rq_flags)) nfserr =nfsd4_encode_splice_read (resp, read, file, maxcount);else nfserr =nfsd4_encode_readv (resp, read, file, maxcount);
Signature · 1 line
1.9.1
Quoted 3 lines · Christoph Hellwig
Ensure that we allocate a file structure in
nfs4_preprocess_stateid_opfor all callers that as for it to consolidate code and fix the handling of ALLOCATE, DEALLOCATE and SEEK to match the latest NFSv4.2 drafts.
Those make sense to me, thanks.
Applying pending some testing.
--b.