xdr encoding fixes (v3)
Subsystems (4)
Changes since the previous posting include:
- fix for a bug in "allow exotic read compounds" that appears to have been the cause for xfstests hangs
- tighten the estimate of space required for checksumming/encryption (in particular it can be zero in the non-krb5i/krb5p case).
- fix some sloppy reply size estimates uncovered by the previous change.
I'll soon start merging at least the first patches for 3.16.
Original introduction follows:
This is a collection of fixes for the NFS server's encoding of NFSv4 compounds, along with a few tangentially related cleanups and bugfixes I noticed along the way.
The basic problem is that we've always assumed an rpc reply is either
- "small" (much less than a page), or
- looks like a read (a bunch of data with a little bit at the beginning and the end).
That assumption has allowed us to cover the most important cases without having to deal with some annoying details like how to encode arbitrary data across a page boundary, but:
- The inability to encode attributes of more than a page annoys some people who would like to get and set extraordinarily long ACLs.
- The inability to encode attributes that cross page boundaries also means we can't return more than a page of readdir data at a time, limiting readdir performance on large directories.
- The NFSv4 protocol doesn't really allow us to place these sorts of arbitrary limits on the types of compounds we handle. (Well, 4.0 is a bit fuzzy on this point, but 4.1 I think definitely considers it a bug if a server won't handle, e.g., multiple read ops in a compound.) This hasn't been an issue because most of these exotic compounds aren't really useful to clients. But maybe future clients will find a use for some of them--in which case we'd prefer not to make the work around a server that doesn't meet the spec.
So, the main goal is to fix those limitations. We also get to share a little more code with the client.
Further work may include:
- writing more pynfs tests for exotic compounds and odd corner cases,
- auditing the annoying nfsd4_*_rsize() functions, which we now depend on for more things,
- improving our (currently very sloppy) estimate of how much space we need for krb5i/krb5p to checksum/encrypt the result.
- sharing some of this with the v2/v3 code (especially in the read and readdir cases),
- allow rpc's whose call and reply are both very large (our one remaining dubious limit on compounds, though again something clients seem unlikely to notice for now),
- on the decode side, eliminating the existing macros and sharing more helpers with the client.
--b.
PATCH 1/52 nfsd4: READ, READDIR, etc., are idempotent
From: "J. Bruce Fields" <[email protected]>
OP_MODIFIES_SOMETHING flags operations that we should be careful not to initiate without being sure we have the buffer space to encode a reply.
None of these ops fall into that category.
We could probably remove a few more, but this isn't a very important problem at least for ops whose reply size is easy to estimate.
--- fs/nfsd/nfs4proc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
fs/nfsd/nfs4proc.c +3 -10
@@ -1665,38 +1665,31 @@ static struct nfsd4_operation nfsd4_ops[] = { [OP_PUTFH] = { .op_func = (nfsd4op_func)nfsd4_putfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTPUBFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTPUBFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTROOTFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTROOTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_READ] = { .op_func = (nfsd4op_func)nfsd4_read, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READ", .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, }, [OP_READDIR] = { .op_func = (nfsd4op_func)nfsd4_readdir, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READDIR", .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, }, [OP_READLINK] = {
Signature · 1 line
1.9.0
Re: [PATCH 01/52] nfsd4: READ, READDIR, etc., are idempotent
Quoted 41 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
OP_MODIFIES_SOMETHINGflags operations that we should be careful not to initiate without being sure we have the buffer space to encode a reply.None of these ops fall into that category.
We could probably remove a few more, but this isn't a very important problem at least for ops whose reply size is easy to estimate.
Signed-off-by J. Bruce Fields <[email protected]>--- fs/nfsd/nfs4proc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)fs/nfsd/nfs4proc.c +2
-4@@ -1665,38 +1665,31 @@ static struct nfsd4_operation nfsd4_ops[] = { [OP_PUTFH] = { .op_func = (nfsd4op_func)nfsd4_putfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTPUBFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTPUBFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTROOTFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS
fs/nfsd/nfs4proc.c static struct nfsd4_operation nfsd4_ops[] = { · line 1692
Quoted 10 lines
fs/nfsd/nfs4proc.c +1
-4- | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTROOTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_READ] = { .op_func = (nfsd4op_func)nfsd4_read, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READ",
Should not delete op_name.
fs/nfsd/nfs4proc.c static struct nfsd4_operation nfsd4_ops[] = { · line 1699
Quoted 7 lines
fs/nfsd/nfs4proc.c +0
-2.op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, }, [OP_READDIR] = { .op_func = (nfsd4op_func)nfsd4_readdir, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READDIR",
Same as above.
Because "[PATCH 03/52] nfsd4: fill in some missing op_name's" re-adds them.
thanks,
Kinglong Mee
Re: [PATCH 01/52] nfsd4: READ, READDIR, etc., are idempotent
Quoted 65 lines · Kinglong Mee
Quoted 41 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
OP_MODIFIES_SOMETHINGflags operations that we should be careful not to initiate without being sure we have the buffer space to encode a reply.None of these ops fall into that category.
We could probably remove a few more, but this isn't a very important problem at least for ops whose reply size is easy to estimate.
Signed-off-by J. Bruce Fields <[email protected]>--- fs/nfsd/nfs4proc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)fs/nfsd/nfs4proc.c +2
-4@@ -1665,38 +1665,31 @@ static struct nfsd4_operation nfsd4_ops[] = { [OP_PUTFH] = { .op_func = (nfsd4op_func)nfsd4_putfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTPUBFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS - |OP_IS_PUTFH_LIKE |OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTPUBFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_PUTROOTFH] = { .op_func = (nfsd4op_func)nfsd4_putrootfh, .op_flags =ALLOWED_WITHOUT_FH |ALLOWED_ON_ABSENT_FS fs/nfsd/nfs4proc.c static struct nfsd4_operation nfsd4_ops[] = { · line 1692
Quoted 10 lines
fs/nfsd/nfs4proc.c +1
-4- | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING - | OP_CLEAR_STATEID, + | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, .op_name = "OP_PUTROOTFH", .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, }, [OP_READ] = { .op_func = (nfsd4op_func)nfsd4_read, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READ",Should not delete
op_name.fs/nfsd/nfs4proc.c static struct nfsd4_operation nfsd4_ops[] = { · line 1699
Quoted 7 lines
fs/nfsd/nfs4proc.c +0
-2.op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, }, [OP_READDIR] = { .op_func = (nfsd4op_func)nfsd4_readdir, - .op_flags = OP_MODIFIES_SOMETHING, - .op_name = "OP_READDIR",Same as above.
Quoted 1 line
Because "[PATCH 03/52] nfsd4: fill in some missing op_name's" re-adds them.
Good grief--I should have checked when those op_name's diseappeared before making the new patch. Thanks.
--b.
PATCH 2/52 nfsd4: allow larger 4.1 session drc slots
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
The client is actually asking for 2532 bytes. I suspect that's a mistake. But maybe we can allow some more. In theory lock needs more if it might return a maximum-length lockowner in the denied case.
--- fs/nfsd/state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/state.h +1 -1
@@ -122,7 +122,7 @@ static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)/* Maximum number of operations per session compound */ #define NFSD_MAX_OPS_PER_COMPOUND 16/* Maximum session per slot cache size */ -#define NFSD_SLOT_CACHE_SIZE 1024 +#define NFSD_SLOT_CACHE_SIZE 2048/* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */ #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32#define NFSD_MAX_MEM_PER_SESSION \
Signature · 1 line
1.9.0
PATCH 3/52 nfsd4: fill in some missing op_name's
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4proc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfsd/nfs4proc.c +2 -0
@@ -1685,11 +1685,13 @@ static struct nfsd4_operation nfsd4_ops[] = { }, [OP_READ] = { .op_func = (nfsd4op_func)nfsd4_read, + .op_name = "OP_READ", .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, }, [OP_READDIR] = { .op_func = (nfsd4op_func)nfsd4_readdir, + .op_name = "OP_READDIR", .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, }, [OP_READLINK] = {
Signature · 1 line
1.9.0
PATCH 4/52 nfsd4: decoding errors can still be cached and require space
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Currently a non-idempotent op reply may be cached if it fails in the proc code but not if it fails at xdr decoding. I doubt there are any xdr-decoding-time errors that would make this a problem in practice, so this probably isn't a serious bug.
The space estimates should also take into account space required for encoding of error returns. Again, not a practical problem, though it would become one after future patches which will tighten the space estimates.
--- fs/nfsd/nfs4proc.c | 2 ++ fs/nfsd/nfs4xdr.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-)
fs/nfsd/nfs4proc.c +2 -0
@@ -1215,6 +1215,8 @@ static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)bool nfsd4_cache_this_op (struct nfsd4_op *op) { +if (op->opnum ==OP_ILLEGAL ) +return false;return OPDESC (op)->op_flags &OP_CACHEME ; }
fs/nfsd/nfs4xdr.c +5 -5
@@ -1677,11 +1677,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp) op->opnum =OP_ILLEGAL ; op->status = nfserr_op_illegal; } - -if (op->status) { - argp->opcnt = i+1 ; -break ; - }/* * We'll try to cache the result in the DRC if any one * op in the compound wants to be cached:
@@ -1689,6 +1684,11 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp) cachethis |=nfsd4_cache_this_op (op); max_reply =max (max_reply,nfsd4_max_reply (op->opnum)); + +if (op->status) { + argp->opcnt = i+1 ; +break ; + } }/* Sessions make the DRC unnecessary: */ if (argp->minorversion)
Signature · 1 line
1.9.0
PATCH 5/52 nfsd4: read size estimate should include padding
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1491,7 +1491,7 @@ static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)if (rlen > maxcount) rlen = maxcount; -return (op_encode_hdr_size +2 ) *sizeof (__be32) + rlen; +return (op_encode_hdr_size +2 +XDR_QUADLEN (rlen)) *sizeof (__be32); }static inline u32 nfsd4_readdir_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op)
Signature · 1 line
1.9.0
PATCH 6/52 nfsd4: fix write reply size estimate
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
The write reply also includes count and stable_how.
--- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1530,7 +1530,7 @@ static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_ostatic inline u32 nfsd4_write_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op) { -return (op_encode_hdr_size + op_encode_verifier_maxsz) *sizeof (__be32); +return (op_encode_hdr_size +2 + op_encode_verifier_maxsz) *sizeof (__be32); }static inline u32 nfsd4_exchange_id_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op)
Signature · 1 line
1.9.0
PATCH 7/52 nfsd4: embed xdr_stream in nfsd4_compoundres
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
This is a mechanical transformation with no change in behavior.
--- fs/nfsd/nfs4proc.c | 12 +++++----- fs/nfsd/nfs4state.c | 8 +++---- fs/nfsd/nfs4xdr.c | 67 ++++++++++++++++++++++++++++------------------------- fs/nfsd/xdr4.h | 4 +--- 4 files changed, 46 insertions(+), 45 deletions(-)
fs/nfsd/nfs4proc.c +6 -6
@@ -1270,13 +1270,13 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,u32 plen =0 ;__be32 status; - resp->xbuf = &rqstp->rq_res; - resp->p = rqstp->rq_res.head[0 ].iov_base + + resp->xdr.buf = &rqstp->rq_res; + resp->xdr.p = rqstp->rq_res.head[0 ].iov_base + rqstp->rq_res.head[0 ].iov_len; - resp->tagp = resp->p; + resp->tagp = resp->xdr.p;/* reserve space for: taglen, tag, and opcnt */ - resp->p +=2 +XDR_QUADLEN (args->taglen); - resp->end = rqstp->rq_res.head[0 ].iov_base +PAGE_SIZE ; + resp->xdr.p +=2 +XDR_QUADLEN (args->taglen); + resp->xdr.end = rqstp->rq_res.head[0 ].iov_base +PAGE_SIZE ; resp->taglen = args->taglen; resp->tag = args->tag; resp->opcnt =0 ;
@@ -1328,7 +1328,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,* failed response to the next operation. If we don't * have enough room, fail with ERR_RESOURCE. */ - slack_bytes = (char *)resp->end - (char *)resp->p; + slack_bytes = (char *)resp->xdr.end - (char *)resp->xdr.p;if (slack_bytes <COMPOUND_SLACK_SPACE +COMPOUND_ERR_SLACK_SPACE ) {BUG_ON (slack_bytes <COMPOUND_ERR_SLACK_SPACE );
fs/nfsd/nfs4state.c +4 -4
@@ -1573,10 +1573,10 @@ nfsd4_store_cache_entry(struct nfsd4_compoundres *resp) slot->sl_datalen =0 ;return ; } - slot->sl_datalen = (char *)resp->p - (char *)resp->cstate.datap; + slot->sl_datalen = (char *)resp->xdr.p - (char *)resp->cstate.datap; base = (char *)resp->cstate.datap - - (char *)resp->xbuf->head[0 ].iov_base; -if (read_bytes_from_xdr_buf (resp->xbuf, base, slot->sl_data, + (char *)resp->xdr.buf->head[0 ].iov_base; +if (read_bytes_from_xdr_buf (resp->xdr.buf, base, slot->sl_data, slot->sl_datalen))WARN ("%s: sessions DRC could not cache compound\n" , __func__);return ;
@@ -1630,7 +1630,7 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,memcpy (resp->cstate.datap, slot->sl_data, slot->sl_datalen); resp->opcnt = slot->sl_opcnt; - resp->p = resp->cstate.datap +XDR_QUADLEN (slot->sl_datalen); + resp->xdr.p = resp->cstate.datap +XDR_QUADLEN (slot->sl_datalen); status = slot->sl_status;return status;
fs/nfsd/nfs4xdr.c +35 -32
156 lines not on this page · raw message
fs/nfsd/xdr4.h +1 -3
@@ -506,9 +506,7 @@ struct nfsd4_compoundargs {struct nfsd4_compoundres {/* scratch variables for XDR encode */ -__be32 * p; -__be32 * end; -struct xdr_buf * xbuf; +struct xdr_stream xdr;struct svc_rqst * rqstp;u32 taglen;
Signature · 1 line
1.9.0
PATCH 8/52 nfsd4: tweak nfsd4_encode_getattr to take xdr_stream
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Just change the nfsd4_encode_getattr api. Not changing any code or adding any new functionality yet.
--- fs/nfsd/nfs4proc.c | 6 +++--- fs/nfsd/nfs4xdr.c | 47 +++++++++++++++++++++++++++++++++++------------ fs/nfsd/xdr4.h | 7 ++++--- 3 files changed, 42 insertions(+), 18 deletions(-)
fs/nfsd/nfs4proc.c +3 -3
@@ -1061,10 +1061,10 @@ _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return nfserr_jukebox; p = buf; - status =nfsd4_encode_fattr (&cstate->current_fh, + status =nfsd4_encode_fattr_to_buf (&p, count, &cstate->current_fh, cstate->current_fh.fh_export, - cstate->current_fh.fh_dentry, &p, - count, verify->ve_bmval, + cstate->current_fh.fh_dentry, + verify->ve_bmval, rqstp,0 );/* * If nfsd4_encode_fattr() ran out of space, assume that's because
fs/nfsd/nfs4xdr.c +35 -12
93 lines not on this page · raw message
fs/nfsd/xdr4.h +4 -3
@@ -562,9 +562,10 @@ int nfs4svc_encode_compoundres(struct svc_rqst *, __be32 *,__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *,u32 );void nfsd4_encode_operation (struct nfsd4_compoundres *,struct nfsd4_op *);void nfsd4_encode_replay (struct nfsd4_compoundres *resp,struct nfsd4_op *op); -__be32 nfsd4_encode_fattr (struct svc_fh *fhp,struct svc_export *exp, -struct dentry *dentry,__be32 **buffer,int countp, -u32 *bmval,struct svc_rqst *,int ignore_crossmnt); +__be32 nfsd4_encode_fattr_to_buf (__be32 **p,int words, +struct svc_fh *fhp,struct svc_export *exp, +struct dentry *dentry, +u32 *bmval,struct svc_rqst *,int ignore_crossmnt);extern __be32 nfsd4_setclientid (struct svc_rqst *rqstp,struct nfsd4_compound_state *,struct nfsd4_setclientid *setclid);
Signature · 1 line
1.9.0
PATCH 9/52 nfsd4: move proc_compound xdr encode init to helper
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Mechanical transformation with no change of behavior.
--- fs/nfsd/nfs4proc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
fs/nfsd/nfs4proc.c +13 -4
@@ -1253,6 +1253,18 @@ static bool need_wrongsec_check(struct svc_rqst *rqstp)return !(nextd->op_flags &OP_HANDLES_WRONGSEC ); } +static void svcxdr_init_encode (struct svc_rqst *rqstp, +struct nfsd4_compoundres *resp) +{ +struct xdr_stream *xdr = &resp->xdr; +struct xdr_buf *buf = &rqstp->rq_res; +struct kvec *head = buf->head; + + xdr->buf = buf; + xdr->p = head->iov_base + head->iov_len; + xdr->end = head->iov_base +PAGE_SIZE ; +} +/* * COMPOUND call. */
@@ -1270,13 +1282,10 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,u32 plen =0 ;__be32 status; - resp->xdr.buf = &rqstp->rq_res; - resp->xdr.p = rqstp->rq_res.head[0 ].iov_base + - rqstp->rq_res.head[0 ].iov_len; +svcxdr_init_encode (rqstp, resp); resp->tagp = resp->xdr.p;/* reserve space for: taglen, tag, and opcnt */ resp->xdr.p +=2 +XDR_QUADLEN (args->taglen); - resp->xdr.end = rqstp->rq_res.head[0 ].iov_base +PAGE_SIZE ; resp->taglen = args->taglen; resp->tag = args->tag; resp->opcnt =0 ;
Signature · 1 line
1.9.0
PATCH 10/52 nfsd4: reserve head space for krb5 integ/priv info
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Currently if the nfs-level part of a reply would be too large, we'll return an error to the client. But if the nfs-level part fits and leaves no room for krb5p or krb5i stuff, then we just drop the request entirely.
That's no good. Instead, reserve some slack space at the end of the buffer and make sure we fail outright if we'd come close.
The slack space here is a massive overstimate of what's required, we should probably try for a tighter limit at some point.
--- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1262,7 +1262,7 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, xdr->buf = buf; xdr->p = head->iov_base + head->iov_len; - xdr->end = head->iov_base +PAGE_SIZE ; + xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; }/*
Signature · 1 line
1.9.0
PATCH 11/52 nfsd4: fix encoding of out-of-space replies
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
If nfsd4_check_resp_size() returns an error then we should really be truncating the reply here, otherwise we may leave extra garbage at the end of the rpc reply.
Also add a warning to catch any cases where our reply-size estimates may be wrong in the case of a non-idempotent operation.
--- fs/nfsd/nfs4proc.c | 9 +++++++++ fs/nfsd/nfs4xdr.c | 17 ++++++++++++++++- fs/nfsd/xdr4.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +9 -0
@@ -1859,6 +1859,15 @@ static struct nfsd4_operation nfsd4_ops[] = { }, }; +void warn_on_nonidempotent_op (struct nfsd4_op *op) +{ +if (OPDESC (op)->op_flags &OP_MODIFIES_SOMETHING ) { +pr_err ("unable to encode reply to nonidempotent op %d (%s)\n" , + op->opnum,nfsd4_op_name (op->opnum)); +WARN_ON_ONCE (1 ); + } +} +#ifdef NFSD_DEBUG static const char *nfsd4_op_name (unsigned opnum) {
fs/nfsd/nfs4xdr.c +16 -1
@@ -3637,6 +3637,7 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) {struct nfs4_stateowner *so = resp->cstate.replay_owner;__be32 *statp; +nfsd4_enc encoder;__be32 *p;RESERVE_SPACE (8 );
@@ -3648,10 +3649,24 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) goto status;BUG_ON (op->opnum <0 || op->opnum >=ARRAY_SIZE (nfsd4_enc_ops) || !nfsd4_enc_ops[op->opnum]); - op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u); + encoder = nfsd4_enc_ops[op->opnum]; + op->status =encoder (resp, op->status, &op->u);/* nfsd4_check_resp_size guarantees enough room for error status */ if (!op->status) op->status =nfsd4_check_resp_size (resp,0 ); +if (op->status == nfserr_resource || + op->status == nfserr_rep_too_big || + op->status == nfserr_rep_too_big_to_cache) { +/* +* The operation may have already been encoded or +* partially encoded. No op returns anything additional +* in the case of one of these three errors, so we can +* just truncate back to after the status. But it's a +* bug if we had to do this on a non-idempotent op: +*/ +warn_on_nonidempotent_op (op); + resp->xdr.p = statp +1 ; + }if (so) { so->so_replay.rp_status = op->status; so->so_replay.rp_buflen = (char *)resp->xdr.p
fs/nfsd/xdr4.h +2 -0
@@ -536,6 +536,8 @@ static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp)return argp->opcnt == resp->opcnt; } +void warn_on_nonidempotent_op (struct nfsd4_op *op); +#define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs) static inline void
Signature · 1 line
1.9.0
PATCH 12/52 nfsd4: allow space for final error return
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
This post-encoding check should be taking into account the need to encode at least an out-of-space error to the following op (if any).
--- fs/nfsd/nfs4xdr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/nfsd/nfs4xdr.c +7 -2
@@ -3636,6 +3636,7 @@ void nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) { struct nfs4_stateowner *so = resp->cstate.replay_owner; +struct svc_rqst *rqstp = resp->rqstp;__be32 *statp;nfsd4_enc encoder;__be32 *p;
@@ -3652,8 +3653,12 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) encoder = nfsd4_enc_ops[op->opnum]; op->status =encoder (resp, op->status, &op->u);/* nfsd4_check_resp_size guarantees enough room for error status */ -if (!op->status) - op->status =nfsd4_check_resp_size (resp,0 ); +if (!op->status) { +int space_needed =0 ; +if (!nfsd4_last_compound_op (rqstp)) + space_needed =COMPOUND_ERR_SLACK_SPACE ; + op->status =nfsd4_check_resp_size (resp, space_needed); + }if (op->status == nfserr_resource || op->status == nfserr_rep_too_big || op->status == nfserr_rep_too_big_to_cache) {
Signature · 1 line
1.9.0
PATCH 13/52 nfsd4: use xdr_reserve_space in attribute encoding
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
This is a cosmetic change for now; no change in behavior.
Note we're just depending on xdr_reserve_space to do the bounds checking for us, we're not really depending on its adjustment of iovec or xdr_buf lengths yet, as those are fixed up by as necessary after the fact by read-link operations and by nfs4svc_encode_compoundres. However we do have to update xdr->iov on read-like operations to prevent xdr_reserve_space from messing with the already-fixed-up length of the the head.
When the attribute encoding fails partway through we have to undo the length adjustments made so far. We do it manually for now, but later patches will add an xdr_truncate_encode() helper to handle cases like this.
--- fs/nfsd/acl.h | 2 +- fs/nfsd/idmap.h | 4 +- fs/nfsd/nfs4acl.c | 11 +- fs/nfsd/nfs4idmap.c | 42 ++++---- fs/nfsd/nfs4proc.c | 1 + fs/nfsd/nfs4xdr.c | 286 +++++++++++++++++++++++++++++++--------------------- 6 files changed, 202 insertions(+), 144 deletions(-)
fs/nfsd/acl.h +1 -1
@@ -49,7 +49,7 @@ struct svc_rqst;struct nfs4_acl *nfs4_acl_new (int );int nfs4_acl_get_whotype (char *,u32 ); -__be32 nfs4_acl_write_who (int who,__be32 **p,int *len); +__be32 nfs4_acl_write_who (struct xdr_stream *xdr,int who);int nfsd4_get_nfs4_acl (struct svc_rqst *rqstp,struct dentry *dentry,struct nfs4_acl **acl);
fs/nfsd/idmap.h +2 -2
@@ -56,7 +56,7 @@ static inline void nfsd_idmap_shutdown(struct net *net)__be32 nfsd_map_name_to_uid (struct svc_rqst *,const char *,size_t ,kuid_t *);__be32 nfsd_map_name_to_gid (struct svc_rqst *,const char *,size_t ,kgid_t *); -__be32 nfsd4_encode_user (struct svc_rqst *,kuid_t ,__be32 **,int *); -__be32 nfsd4_encode_group (struct svc_rqst *,kgid_t ,__be32 **,int *); +__be32 nfsd4_encode_user (struct xdr_stream *,struct svc_rqst *,kuid_t ); +__be32 nfsd4_encode_group (struct xdr_stream *,struct svc_rqst *,kgid_t );#endif /* LINUX_NFSD_IDMAP_H */
fs/nfsd/nfs4acl.c +5 -6
@@ -919,20 +919,19 @@ nfs4_acl_get_whotype(char *p, u32 len)return NFS4_ACL_WHO_NAMED ; } -__be32 nfs4_acl_write_who (int who,__be32 **p,int *len) +__be32 nfs4_acl_write_who (struct xdr_stream *xdr,int who) { +__be32 *p;int i; -int bytes;for (i =0 ; i <ARRAY_SIZE (s2t_map); i++) {if (s2t_map[i].type != who)continue ; - bytes =4 + (XDR_QUADLEN (s2t_map[i].stringlen) <<2 ); -if (bytes > *len) + p =xdr_reserve_space (xdr, s2t_map[i].stringlen +4 ); +if (!p)return nfserr_resource; - *p =xdr_encode_opaque (*p, s2t_map[i].string, + p =xdr_encode_opaque (p, s2t_map[i].string, s2t_map[i].stringlen); - *len -= bytes;return 0 ; }WARN_ON_ONCE (1 );
fs/nfsd/nfs4idmap.c +22 -20
91 lines not on this page · raw message
fs/nfsd/nfs4proc.c +1 -0
@@ -1261,6 +1261,7 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp,struct kvec *head = buf->head; xdr->buf = buf; + xdr->iov = head; xdr->p = head->iov_base + head->iov_len; xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; }
fs/nfsd/nfs4xdr.c +171 -115
738 lines not on this page · raw message
Signature · 1 line
1.9.0
Re: [PATCH 13/52] nfsd4: use xdr_reserve_space in attribute encoding
Quoted 405 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
This is a cosmetic change for now; no change in behavior.
Note we're just depending on
xdr_reserve_spaceto do the bounds checking for us, we're not really depending on its adjustment of iovec orxdr_buflengths yet, as those are fixed up by as necessary after the fact by read-link operations and bynfs4svc_encode_compoundres. However we do have to updatexdr->iovon read-like operations to preventxdr_reserve_spacefrom messing with the already-fixed-up length of the the head.When the attribute encoding fails partway through we have to undo the length adjustments made so far. We do it manually for now, but later patches will add an
xdr_truncate_encode()helper to handle cases like this.Signed-off-by J. Bruce Fields <[email protected]>--- fs/nfsd/acl.h | 2 +- fs/nfsd/idmap.h | 4 +- fs/nfsd/nfs4acl.c | 11 +- fs/nfsd/nfs4idmap.c | 42 ++++---- fs/nfsd/nfs4proc.c | 1 + fs/nfsd/nfs4xdr.c | 286 +++++++++++++++++++++++++++++++--------------------- 6 files changed, 202 insertions(+), 144 deletions(-)fs/nfsd/acl.h +1
-1@@ -49,7 +49,7 @@ struct svc_rqst;struct nfs4_acl *nfs4_acl_new (int );int nfs4_acl_get_whotype (char *,u32 ); -__be32 nfs4_acl_write_who (int who,__be32 **p,int *len); +__be32 nfs4_acl_write_who (struct xdr_stream *xdr,int who);int nfsd4_get_nfs4_acl (struct svc_rqst *rqstp,struct dentry *dentry,struct nfs4_acl **acl);fs/nfsd/idmap.h +2
-2@@ -56,7 +56,7 @@ static inline void nfsd_idmap_shutdown(struct net *net)__be32 nfsd_map_name_to_uid (struct svc_rqst *,const char *,size_t ,kuid_t *);__be32 nfsd_map_name_to_gid (struct svc_rqst *,const char *,size_t ,kgid_t *); -__be32 nfsd4_encode_user (struct svc_rqst *,kuid_t ,__be32 **,int *); -__be32 nfsd4_encode_group (struct svc_rqst *,kgid_t ,__be32 **,int *); +__be32 nfsd4_encode_user (struct xdr_stream *,struct svc_rqst *,kuid_t ); +__be32 nfsd4_encode_group (struct xdr_stream *,struct svc_rqst *,kgid_t );#endif /* LINUX_NFSD_IDMAP_H */ fs/nfsd/nfs4acl.c +5
-6@@ -919,20 +919,19 @@ nfs4_acl_get_whotype(char *p, u32 len)return NFS4_ACL_WHO_NAMED ; } -__be32 nfs4_acl_write_who (int who,__be32 **p,int *len) +__be32 nfs4_acl_write_who (struct xdr_stream *xdr,int who) { +__be32 *p;int i; -int bytes;for (i =0 ; i <ARRAY_SIZE (s2t_map); i++) {if (s2t_map[i].type != who)continue ; - bytes =4 + (XDR_QUADLEN (s2t_map[i].stringlen) <<2 ); -if (bytes > *len) + p =xdr_reserve_space (xdr, s2t_map[i].stringlen +4 ); +if (!p)return nfserr_resource; - *p =xdr_encode_opaque (*p, s2t_map[i].string, + p =xdr_encode_opaque (p, s2t_map[i].string, s2t_map[i].stringlen); - *len -= bytes;return 0 ; }WARN_ON_ONCE (1 );fs/nfsd/nfs4idmap.c +22
-20@@ -551,44 +551,43 @@ idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelenreturn 0 ; } -static __be32 encode_ascii_id (u32 id,__be32 **p,int *buflen) +static __be32 encode_ascii_id (struct xdr_stream *xdr,u32 id) {char buf[11 ];int len; -int bytes; +__be32 *p; len =sprintf (buf,"%u" , id); - bytes =4 + (XDR_QUADLEN (len) <<2 ); -if (bytes > *buflen) + p =xdr_reserve_space (xdr, len +4 ); +if (!p)return nfserr_resource; - *p =xdr_encode_opaque (*p, buf, len); - *buflen -= bytes; + p =xdr_encode_opaque (p, buf, len);return 0 ; } -static __be32 idmap_id_to_name (struct svc_rqst *rqstp,int type,u32 id,__be32 **p,int *buflen) +static __be32 idmap_id_to_name (struct xdr_stream *xdr, +struct svc_rqst *rqstp,int type,u32 id) {struct ent *item, key = { .id = id, .type = type, }; +__be32 *p;int ret; -int bytes;struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);strlcpy (key.authname,rqst_authname (rqstp),sizeof (key.authname)); ret =idmap_lookup (rqstp, idtoname_lookup, &key, nn->idtoname_cache, &item);if (ret == -ENOENT ) -return encode_ascii_id (id, p, buflen); +return encode_ascii_id (xdr, id);if (ret)return nfserrno (ret); ret =strlen (item->name);WARN_ON_ONCE (ret >IDMAP_NAMESZ ); - bytes =4 + (XDR_QUADLEN (ret) <<2 ); -if (bytes > *buflen) + p =xdr_reserve_space (xdr, ret +4 ); +if (!p)return nfserr_resource; - *p =xdr_encode_opaque (*p, item->name, ret); - *buflen -= bytes; + p =xdr_encode_opaque (p, item->name, ret);cache_put (&item->h, nn->idtoname_cache);return 0 ; }@@ -622,11 +621,12 @@ do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, ureturn idmap_name_to_id (rqstp, type, name, namelen, id); } -static __be32 encode_name_from_id (struct svc_rqst *rqstp,int type,u32 id,__be32 **p,int *buflen) +static __be32 encode_name_from_id (struct xdr_stream *xdr, +struct svc_rqst *rqstp,int type,u32 id) {if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor <RPC_AUTH_GSS ) -return encode_ascii_id (id, p, buflen); -return idmap_id_to_name (rqstp, type, id, p, buflen); +return encode_ascii_id (xdr, id); +return idmap_id_to_name (xdr, rqstp, type, id); } __be32@@ -655,14 +655,16 @@ nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, size_t namelen,return status; } -__be32 nfsd4_encode_user (struct svc_rqst *rqstp,kuid_t uid,__be32 **p,int *buflen) +__be32 nfsd4_encode_user (struct xdr_stream *xdr,struct svc_rqst *rqstp, +kuid_t uid) {u32 id =from_kuid (&init_user_ns, uid); -return encode_name_from_id (rqstp,IDMAP_TYPE_USER , id, p, buflen); +return encode_name_from_id (xdr, rqstp,IDMAP_TYPE_USER , id); } -__be32 nfsd4_encode_group (struct svc_rqst *rqstp,kgid_t gid,__be32 **p,int *buflen) +__be32 nfsd4_encode_group (struct xdr_stream *xdr,struct svc_rqst *rqstp, +kgid_t gid) {u32 id =from_kgid (&init_user_ns, gid); -return encode_name_from_id (rqstp,IDMAP_TYPE_GROUP , id, p, buflen); +return encode_name_from_id (xdr, rqstp,IDMAP_TYPE_GROUP , id); }fs/nfsd/nfs4proc.c +1
-0@@ -1261,6 +1261,7 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp,struct kvec *head = buf->head; xdr->buf = buf; + xdr->iov = head; xdr->p = head->iov_base + head->iov_len; xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; }fs/nfsd/nfs4xdr.c +41
-43@@ -1755,18 +1755,20 @@ static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)/* Encode as an array of strings the string given with components * separated @sep, escaped with esc_enter and esc_exit. */ -static __be32 nfsd4_encode_components_esc (char sep,char *components, -__be32 **pp,int *buflen, -char esc_enter,char esc_exit) +static __be32 nfsd4_encode_components_esc (struct xdr_stream *xdr,char sep, +char *components,char esc_enter, +char esc_exit) { -__be32 *p = *pp; -__be32 *countp = p; +__be32 *p; +__be32 *countp;int strlen, count=0 ;char *str, *end, *next;dprintk ("nfsd4_encode_components(%s)\n" , components); -if ((*buflen -=4 ) <0 ) + p =xdr_reserve_space (xdr,4 ); +if (!p)return nfserr_resource; + countp = p;WRITE32 (0 );/* We will fill this in with @count later */ end = str = components;while (*end) {@@ -1789,7 +1791,8 @@ static __be32 nfsd4_encode_components_esc(char sep, char *components, strlen = end - str;if (strlen) { -if ((*buflen -= ((XDR_QUADLEN (strlen) <<2 ) +4 )) <0 ) + p =xdr_reserve_space (xdr, strlen +4 ); +if (!p)return nfserr_resource;WRITE32 (strlen);WRITEMEM (str, strlen);@@ -1799,7 +1802,6 @@ static __be32 nfsd4_encode_components_esc(char sep, char *components, end++; str = end; } - *pp = p; p = countp;WRITE32 (count);return 0 ;@@ -1808,40 +1810,39 @@ static __be32 nfsd4_encode_components_esc(char sep, char *components,/* Encode as an array of strings the string given with components * separated @sep. */ -static __be32 nfsd4_encode_components (char sep,char *components, -__be32 **pp,int *buflen) +static __be32 nfsd4_encode_components (struct xdr_stream *xdr,char sep, +char *components) { -return nfsd4_encode_components_esc (sep, components, pp, buflen,0 ,0 ); +return nfsd4_encode_components_esc (xdr, sep, components,0 ,0 ); }/* * encode a location element of a fs_locations structure */ -static __be32 nfsd4_encode_fs_location4 (struct nfsd4_fs_location *location, -__be32 **pp,int *buflen) +static __be32 nfsd4_encode_fs_location4 (struct xdr_stream *xdr, +struct nfsd4_fs_location *location) {__be32 status; -__be32 *p = *pp; - status =nfsd4_encode_components_esc (':' , location->hosts, &p, buflen, + status =nfsd4_encode_components_esc (xdr,':' , location->hosts,'[' ,']' );if (status)return status; - status =nfsd4_encode_components ('/' , location->path, &p, buflen); + status =nfsd4_encode_components (xdr,'/' , location->path);if (status)return status; - *pp = p;return 0 ; }/* * Encode a path in RFC3530 'pathname4' format */ -static __be32 nfsd4_encode_path (const struct path *root, -const struct path *path,__be32 **pp,int *buflen) +static __be32 nfsd4_encode_path (struct xdr_stream *xdr, +const struct path *root, +const struct path *path) {struct path cur = *path; -__be32 *p = *pp; +__be32 *p;struct dentry **components =NULL ;unsigned int ncomponents =0 ;__be32 err = nfserr_jukebox;@@ -1872,9 +1873,9 @@ static __be32 nfsd4_encode_path(const struct path *root, components[ncomponents++] = cur.dentry; cur.dentry =dget_parent (cur.dentry); } - - *buflen -=4 ; -if (*buflen <0 ) + err = nfserr_resource; + p =xdr_reserve_space (xdr,4 ); +if (!p) goto out_free;WRITE32 (ncomponents);@@ -1884,8 +1885,8 @@ static __be32 nfsd4_encode_path(const struct path *root,spin_lock (&dentry->d_lock); len = dentry->d_name.len; - *buflen -=4 + (XDR_QUADLEN (len) <<2 ); -if (*buflen <0 ) { + p =xdr_reserve_space (xdr, len +4 ); +if (!p) {spin_unlock (&dentry->d_lock); goto out_free; }@@ -1897,7 +1898,6 @@ static __be32 nfsd4_encode_path(const struct path *root, ncomponents--; } - *pp = p; err =0 ; out_free:dprintk (")\n" );@@ -1908,8 +1908,8 @@ out_free:return err; } -static __be32 nfsd4_encode_fsloc_fsroot (struct svc_rqst *rqstp, -const struct path *path,__be32 **pp,int *buflen) +static __be32 nfsd4_encode_fsloc_fsroot (struct xdr_stream *xdr, +struct svc_rqst *rqstp,const struct path *path) {struct svc_export *exp_ps;__be32 res;@@ -1917,7 +1917,7 @@ static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp, exp_ps =rqst_find_fsidzero_export (rqstp);if (IS_ERR (exp_ps))return nfserrno (PTR_ERR (exp_ps)); - res =nfsd4_encode_path (&exp_ps->ex_path, path, pp, buflen); + res =nfsd4_encode_path (xdr, &exp_ps->ex_path, path);exp_put (exp_ps);return res; }@@ -1925,28 +1925,26 @@ static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp,/* * encode a fs_locations structure */ -static __be32 nfsd4_encode_fs_locations (struct svc_rqst *rqstp, -struct svc_export *exp, -__be32 **pp,int *buflen) +static __be32 nfsd4_encode_fs_locations (struct xdr_stream *xdr, +struct svc_rqst *rqstp,struct svc_export *exp) {__be32 status;int i; -__be32 *p = *pp; +__be32 *p;struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; - status =nfsd4_encode_fsloc_fsroot (rqstp, &exp->ex_path, &p, buflen); + status =nfsd4_encode_fsloc_fsroot (xdr, rqstp, &exp->ex_path);if (status)return status; -if ((*buflen -=4 ) <0 ) + p =xdr_reserve_space (xdr,4 ); +if (!p)return nfserr_resource;WRITE32 (fslocs->locations_count);for (i=0 ; i<fslocs->locations_count; i++) { - status =nfsd4_encode_fs_location4 (&fslocs->locations[i], - &p, buflen); + status =nfsd4_encode_fs_location4 (xdr, &fslocs->locations[i]);if (status)return status; } - *pp = p;return 0 ; }@@ -1965,15 +1963,15 @@ static u32 nfs4_file_type(umode_t mode) }static inline __be32 -nfsd4_encode_aclname (struct svc_rqst *rqstp,struct nfs4_ace *ace, -__be32 **p,int *buflen) +nfsd4_encode_aclname (struct xdr_stream *xdr,struct svc_rqst *rqstp, +struct nfs4_ace *ace) {if (ace->whotype !=NFS4_ACL_WHO_NAMED ) -return nfs4_acl_write_who (ace->whotype, p, buflen); +return nfs4_acl_write_who (xdr, ace->whotype);else if (ace->flag &NFS4_ACE_IDENTIFIER_GROUP ) -return nfsd4_encode_group (rqstp, ace->who_gid, p, buflen); +return nfsd4_encode_group (xdr, rqstp, ace->who_gid);else -return nfsd4_encode_user (rqstp, ace->who_uid, p, buflen); +return nfsd4_encode_user (xdr, rqstp, ace->who_uid); }#define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 1986
Quoted 8 lines
fs/nfsd/nfs4xdr.c +2
-1@@ -1982,31 +1980,28 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,#ifdef CONFIG_NFSD_V4_SECURITY_LABEL static inline __be32 -nfsd4_encode_security_label (struct svc_rqst *rqstp,void *context,int len,__be32 **pp,int *buflen) +nfsd4_encode_security_label (struct xdr_stream *xdr,struct svc_rqst *rqstp, +void *context,int len) {__be32 *p = *pp;
CC [M] fs/nfsd/nfs4xdr.ofs/nfsd/nfs4xdr.c: In function ‘nfsd4_encode_security_label’:fs/nfsd/nfs4xdr.c:1984:15: error: ‘pp’ undeclared (first use in this function)
__be32 *p = *pp;
^fs/nfsd/nfs4xdr.c:1984:15: note: each undeclared identifier is reported only once for each function it appears in make[1]: *** [fs/nfsd/nfs4xdr.o] Error 1
make: *** [fs/nfsd/] Error 2
thanks,
Kinglong Mee
PATCH 14/52 nfsd4: use xdr_stream throughout compound encoding
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Note this makes ADJUST_ARGS useless; we'll remove it in the following patch.
--- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4xdr.c | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1286,7 +1286,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,svcxdr_init_encode (rqstp, resp); resp->tagp = resp->xdr.p;/* reserve space for: taglen, tag, and opcnt */ - resp->xdr.p +=2 +XDR_QUADLEN (args->taglen); +xdr_reserve_space (&resp->xdr,8 + args->taglen); resp->taglen = args->taglen; resp->tag = args->tag; resp->opcnt =0 ;
fs/nfsd/nfs4xdr.c +15 -8
@@ -1747,10 +1747,10 @@ static void write_cinfo(__be32 **p, struct nfsd4_change_info *c) }#define RESERVE_SPACE (nbytes) do { \ - p = resp->xdr.p; \ - BUG_ON(p + XDR_QUADLEN(nbytes) > resp->xdr.end); \ + p = xdr_reserve_space(&resp->xdr, nbytes); \ + BUG_ON(!p); \ } while (0) -#define ADJUST_ARGS () resp->xdr.p = p +#define ADJUST_ARGS () WARN_ON_ONCE(p != resp->xdr.p) \/* Encode as an array of strings the string given with components * separated @sep, escaped with esc_enter and esc_exit.
@@ -3056,8 +3056,11 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen, &maxcount); -if (nfserr) +if (nfserr) { + xdr->p -=2 ; + xdr->iov->iov_len -=8 ;return nfserr; + } eof = (read->rd_offset + maxcount >= read->rd_fhp->fh_dentry->d_inode->i_size);
@@ -3110,9 +3113,12 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd*/ nfserr =nfsd_readlink (readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);if (nfserr == nfserr_isdir) -return nfserr_inval; -if (nfserr) + nfserr = nfserr_inval; +if (nfserr) { + xdr->p--; + xdr->iov->iov_len -=4 ;return nfserr; + }WRITE32 (maxcount);ADJUST_ARGS ();
@@ -3213,8 +3219,9 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4return 0 ; err_no_verf: - p = savep; -ADJUST_ARGS (); + xdr->p = savep; + xdr->iov->iov_len = ((char *)resp->xdr.p) + - (char *)resp->xdr.buf->head[0 ].iov_base;return nfserr; }
Signature · 1 line
1.9.0
PATCH 15/52 nfsd4: remove ADJUST_ARGS
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
It's just uninteresting debugging code at this point.
--- fs/nfsd/nfs4xdr.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-)
fs/nfsd/nfs4xdr.c +0 -40
@@ -1750,7 +1750,6 @@ static void write_cinfo(__be32 **p, struct nfsd4_change_info *c) p =xdr_reserve_space (&resp->xdr, nbytes); \BUG_ON (!p); \ }while (0 ) -#define ADJUST_ARGS () WARN_ON_ONCE(p != resp->xdr.p) \/* Encode as an array of strings the string given with components * separated @sep, escaped with esc_enter and esc_exit.
@@ -2744,7 +2743,6 @@ nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)RESERVE_SPACE (sizeof (stateid_t));WRITE32 (sid->si_generation);WRITEMEM (&sid->si_opaque,sizeof (stateid_opaque_t)); -ADJUST_ARGS (); } static __be32
@@ -2756,7 +2754,6 @@ nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_RESERVE_SPACE (8 );WRITE32 (access->ac_supported);WRITE32 (access->ac_resp_access); -ADJUST_ARGS (); }return nfserr; }
@@ -2771,7 +2768,6 @@ static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp,WRITE32 (bcts->dir);/* Sorry, we do not yet support RDMA over 4.1: */ WRITE32 (0 ); -ADJUST_ARGS (); }return nfserr; }
@@ -2794,7 +2790,6 @@ nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_if (!nfserr) {RESERVE_SPACE (NFS4_VERIFIER_SIZE );WRITEMEM (commit->co_verf.data,NFS4_VERIFIER_SIZE ); -ADJUST_ARGS (); }return nfserr; }
@@ -2810,7 +2805,6 @@ nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_WRITE32 (2 );WRITE32 (create->cr_bmval[0 ]);WRITE32 (create->cr_bmval[1 ]); -ADJUST_ARGS (); }return nfserr; }
@@ -2842,7 +2836,6 @@ nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fhRESERVE_SPACE (len +4 );WRITE32 (len);WRITEMEM (&fhp->fh_handle.fh_base, len); -ADJUST_ARGS (); }return nfserr; }
@@ -2870,7 +2863,6 @@ nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denieWRITE64 ((u64 )0 );/* clientid */ WRITE32 (0 );/* length of owner name */ } -ADJUST_ARGS (); } static __be32
@@ -2910,7 +2902,6 @@ nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_liif (!nfserr) {RESERVE_SPACE (20 );write_cinfo (&p, &link->li_cinfo); -ADJUST_ARGS (); }return nfserr; }
@@ -2932,7 +2923,6 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_opWRITE32 (open->op_bmval[0 ]);WRITE32 (open->op_bmval[1 ]);WRITE32 (open->op_delegate_type); -ADJUST_ARGS ();switch (open->op_delegate_type) {case NFS4_OPEN_DELEGATE_NONE :
@@ -2949,7 +2939,6 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_opWRITE32 (0 );WRITE32 (0 );WRITE32 (0 );/* XXX: is NULL principal ok? */ -ADJUST_ARGS ();break ;case NFS4_OPEN_DELEGATE_WRITE :nfsd4_encode_stateid (resp, &open->op_delegate_stateid);
@@ -2970,7 +2959,6 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_opWRITE32 (0 );WRITE32 (0 );WRITE32 (0 );/* XXX: is NULL principal ok? */ -ADJUST_ARGS ();break ;case NFS4_OPEN_DELEGATE_NONE_EXT :/* 4.1 */ switch (open->op_why_no_deleg) {
@@ -2984,7 +2972,6 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_opRESERVE_SPACE (4 );WRITE32 (open->op_why_no_deleg); } -ADJUST_ARGS ();break ;default :BUG ();
@@ -3066,7 +3053,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (eof);WRITE32 (maxcount); -ADJUST_ARGS (); resp->xdr.buf->head[0 ].iov_len = (char *)p - (char *)resp->xdr.buf->head[0 ].iov_base; resp->xdr.buf->page_len = maxcount;
@@ -3080,7 +3066,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (0 ); resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); -ADJUST_ARGS (); }return 0 ; }
@@ -3121,7 +3106,6 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd }WRITE32 (maxcount); -ADJUST_ARGS (); resp->xdr.buf->head[0 ].iov_len = (char *)p - (char *)resp->xdr.buf->head[0 ].iov_base; resp->xdr.buf->page_len = maxcount;
@@ -3135,7 +3119,6 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdWRITE32 (0 ); resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); -ADJUST_ARGS (); }return 0 ; }
@@ -3162,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4/* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ WRITE32 (0 );WRITE32 (0 ); -ADJUST_ARGS (); resp->xdr.buf->head[0 ].iov_len = ((char *)resp->xdr.p) - (char *)resp->xdr.buf->head[0 ].iov_base; tailbase = p;
@@ -3233,7 +3215,6 @@ nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_if (!nfserr) {RESERVE_SPACE (20 );write_cinfo (&p, &remove->rm_cinfo); -ADJUST_ARGS (); }return nfserr; }
@@ -3247,7 +3228,6 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_RESERVE_SPACE (40 );write_cinfo (&p, &rename->rn_sinfo);write_cinfo (&p, &rename->rn_tinfo); -ADJUST_ARGS (); }return nfserr; }
@@ -3287,7 +3267,6 @@ nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp, supported =0 ;RESERVE_SPACE (4 ); flavorsp = p++;/* to be backfilled later */ -ADJUST_ARGS ();for (i =0 ; i < nflavs; i++) {rpc_authflavor_t pf = flavs[i].pseudoflavor;
@@ -3301,12 +3280,10 @@ nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,WRITEMEM (info.oid.data, info.oid.len);WRITE32 (info.qop);WRITE32 (info.service); -ADJUST_ARGS (); }else if (pf <RPC_AUTH_MAXFLAVOR ) { supported++;RESERVE_SPACE (4 );WRITE32 (pf); -ADJUST_ARGS (); }else {if (report) pr_warn("NFS: SECINFO: security flavor %u "
@@ -3360,7 +3337,6 @@ nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4WRITE32 (setattr->sa_bmval[1 ]);WRITE32 (setattr->sa_bmval[2 ]); } -ADJUST_ARGS ();return nfserr; }
@@ -3373,13 +3349,11 @@ nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nRESERVE_SPACE (8 +NFS4_VERIFIER_SIZE );WRITEMEM (&scd->se_clientid,8 );WRITEMEM (&scd->se_confirm,NFS4_VERIFIER_SIZE ); -ADJUST_ARGS (); }else if (nfserr == nfserr_clid_inuse) {RESERVE_SPACE (8 );WRITE32 (0 );WRITE32 (0 ); -ADJUST_ARGS (); }return nfserr; }
@@ -3394,7 +3368,6 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_wWRITE32 (write->wr_bytes_written);WRITE32 (write->wr_how_written);WRITEMEM (write->wr_verifier.data,NFS4_VERIFIER_SIZE ); -ADJUST_ARGS (); }return nfserr; }
@@ -3437,7 +3410,6 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (exid->flags);WRITE32 (exid->spa_how); -ADJUST_ARGS ();switch (exid->spa_how) {case SP4_NONE :
@@ -3453,7 +3425,6 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,/* empty spo_must_allow bitmap: */ WRITE32 (0 ); -ADJUST_ARGS ();break ;default :WARN_ON_ONCE (1 );
@@ -3479,7 +3450,6 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,/* Implementation id */ WRITE32 (0 );/* zero length nfs_impl_id4 array */ -ADJUST_ARGS ();return 0 ; }
@@ -3496,7 +3466,6 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,WRITEMEM (sess->sessionid.data,NFS4_MAX_SESSIONID_LEN );WRITE32 (sess->seqid);WRITE32 (sess->flags); -ADJUST_ARGS ();RESERVE_SPACE (28 );WRITE32 (0 );/* headerpadsz */
@@ -3506,12 +3475,10 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (sess->fore_channel.maxops);WRITE32 (sess->fore_channel.maxreqs);WRITE32 (sess->fore_channel.nr_rdma_attrs); -ADJUST_ARGS ();if (sess->fore_channel.nr_rdma_attrs) {RESERVE_SPACE (4 );WRITE32 (sess->fore_channel.rdma_attrs); -ADJUST_ARGS (); }RESERVE_SPACE (28 );
@@ -3522,12 +3489,10 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (sess->back_channel.maxops);WRITE32 (sess->back_channel.maxreqs);WRITE32 (sess->back_channel.nr_rdma_attrs); -ADJUST_ARGS ();if (sess->back_channel.nr_rdma_attrs) {RESERVE_SPACE (4 );WRITE32 (sess->back_channel.rdma_attrs); -ADJUST_ARGS (); }return 0 ; }
@@ -3550,7 +3515,6 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (seq->maxslots -1 );/* sr_target_highest_slotid */ WRITE32 (seq->status_flags); -ADJUST_ARGS (); resp->cstate.datap = p;/* DRC cache data pointer */ return 0 ; }
@@ -3572,7 +3536,6 @@ nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, *p++ = stateid->ts_id_status; } -ADJUST_ARGS ();return nfserr; }
@@ -3707,7 +3670,6 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)RESERVE_SPACE (8 );WRITE32 (op->opnum); statp = p++;/* to be backfilled at the end */ -ADJUST_ARGS ();if (op->opnum ==OP_ILLEGAL ) goto status;
@@ -3768,11 +3730,9 @@ nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)RESERVE_SPACE (8 );WRITE32 (op->opnum); *p++ = rp->rp_status;/* already xdr'ed */ -ADJUST_ARGS ();RESERVE_SPACE (rp->rp_buflen);WRITEMEM (rp->rp_buf, rp->rp_buflen); -ADJUST_ARGS (); }int
Signature · 1 line
1.9.0
PATCH 16/52 nfsd4: no need for encode_compoundres to adjust lengths
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
xdr_reserve_space should now be calculating the length correctly as we go, so there's no longer any need to fix it up here.
--- fs/nfsd/nfs4state.c | 3 +++ fs/nfsd/nfs4xdr.c | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-)
fs/nfsd/nfs4state.c +3 -0
@@ -1618,6 +1618,7 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp, struct nfsd4_sequence *seq) {struct nfsd4_slot *slot = resp->cstate.slot; +struct kvec *head = resp->xdr.iov;__be32 status;dprintk ("--> %s slot %p\n" , __func__, slot);
@@ -1631,6 +1632,8 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp, resp->opcnt = slot->sl_opcnt; resp->xdr.p = resp->cstate.datap +XDR_QUADLEN (slot->sl_datalen); + head->iov_len = (void *)resp->xdr.p - head->iov_base; + resp->xdr.buf->len = head->iov_len; status = slot->sl_status;return status;
fs/nfsd/nfs4xdr.c +1 -7
@@ -3789,19 +3789,13 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo* All that remains is to write the tag and operation count... */ struct nfsd4_compound_state *cs = &resp->cstate; -struct kvec *iov; + p = resp->tagp; *p++ =htonl (resp->taglen);memcpy (p, resp->tag, resp->taglen); p +=XDR_QUADLEN (resp->taglen); *p++ =htonl (resp->opcnt); -if (rqstp->rq_res.page_len) - iov = &rqstp->rq_res.tail[0 ]; -else - iov = &rqstp->rq_res.head[0 ]; - iov->iov_len = ((char *)resp->xdr.p) - (char *)iov->iov_base; -BUG_ON (iov->iov_len >PAGE_SIZE );if (nfsd4_has_session (cs)) {struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct nfs4_client *clp = cs->session->se_client;
Signature · 1 line
1.9.0
PATCH 17/52 nfsd4: keep xdr buf length updated
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4proc.c | 2 ++ fs/nfsd/nfs4xdr.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +2 -0
@@ -1264,6 +1264,8 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, xdr->iov = head; xdr->p = head->iov_base + head->iov_len; xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; +/* Tail and page_len should be zero at this point: */ + buf->len = buf->head[0 ].iov_len; }/*
fs/nfsd/nfs4xdr.c +10 -2
@@ -3053,9 +3053,10 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (eof);WRITE32 (maxcount); - resp->xdr.buf->head[0 ].iov_len = (char *)p - - (char *)resp->xdr.buf->head[0 ].iov_base; +WARN_ON_ONCE (resp->xdr.buf->head[0 ].iov_len != (char *)p + - (char *)resp->xdr.buf->head[0 ].iov_base); resp->xdr.buf->page_len = maxcount; + xdr->buf->len += maxcount; xdr->iov = xdr->buf->tail;/* Use rest of head for padding and remaining ops: */
@@ -3066,6 +3067,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (0 ); resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); + xdr->buf->len -= (maxcount&3 ); }return 0 ; }
@@ -3109,6 +3111,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd resp->xdr.buf->head[0 ].iov_len = (char *)p - (char *)resp->xdr.buf->head[0 ].iov_base; resp->xdr.buf->page_len = maxcount; + xdr->buf->len += maxcount; xdr->iov = xdr->buf->tail;/* Use rest of head for padding and remaining ops: */
@@ -3189,6 +3192,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 *p++ =htonl (readdir->common.err == nfserr_eof); resp->xdr.buf->page_len = ((char *)p) - (char *)page_address (*(resp->rqstp->rq_next_page-1 )); + xdr->buf->len += xdr->buf->page_len; xdr->iov = xdr->buf->tail;
@@ -3789,6 +3793,10 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo* All that remains is to write the tag and operation count... */ struct nfsd4_compound_state *cs = &resp->cstate; +struct xdr_buf *buf = resp->xdr.buf; + +WARN_ON_ONCE (buf->len != buf->head[0 ].iov_len + buf->page_len + + buf->tail[0 ].iov_len); p = resp->tagp; *p++ =htonl (resp->taglen);
Signature · 1 line
1.9.0
PATCH 18/52 rpc: xdr_truncate_encode
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
This will be used in the server side in a few cases:
- when certain operations (read, readdir, readlink) fail after encoding a partial response.
- when we run out of space after encoding a partial response.
- in readlink, where we initially reserve PAGE_SIZE bytes for data, then truncate to the actual size.
--- include/linux/sunrpc/xdr.h | 1 + net/sunrpc/xdr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
include/linux/sunrpc/xdr.h +1 -0
@@ -215,6 +215,7 @@ typedef int (*kxdrdproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);extern void xdr_init_encode (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p);extern __be32 *xdr_reserve_space (struct xdr_stream *xdr,size_t nbytes); +extern void xdr_truncate_encode (struct xdr_stream *xdr,size_t len);extern void xdr_write_pages (struct xdr_stream *xdr,struct page **pages,unsigned int base,unsigned int len);extern unsigned int xdr_stream_pos (const struct xdr_stream *xdr);
net/sunrpc/xdr.c +67 -0
73 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 19/52 nfsd4: use xdr_truncate_encode
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Now that lengths are reliable, we can use xdr_truncate instead of open-coding it everywhere.
--- fs/nfsd/nfs4xdr.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
fs/nfsd/nfs4xdr.c +16 -17
@@ -2053,7 +2053,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,struct svc_fh *tempfh =NULL ;struct kstatfs statfs;__be32 *p; -__be32 *start = xdr->p; +int starting_len = xdr->buf->len;__be32 *attrlenp;u32 dummy;u64 dummy64;
@@ -2547,13 +2547,8 @@ out:fh_put (tempfh);kfree (tempfh); } -if (status) { -int nbytes = (char *)xdr->p - (char *)start; -/* open code what *should* be xdr_truncate(xdr, len); */ - xdr->iov->iov_len -= nbytes; - xdr->buf->len -= nbytes; - xdr->p = start; - } +if (status) +xdr_truncate_encode (xdr, starting_len);return status; out_nfserr: status =nfserrno (err);
@@ -3008,6 +3003,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,struct page *page;unsigned long maxcount;struct xdr_stream *xdr = &resp->xdr; +int starting_len = xdr->buf->len;long len;__be32 *p;
@@ -3044,8 +3040,13 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, &maxcount);if (nfserr) { - xdr->p -=2 ; - xdr->iov->iov_len -=8 ; +/* +* nfsd_splice_actor may have already messed with the +* page length; reset it so as not to confuse +* xdr_truncate_encode: +*/ + xdr->buf->page_len =0 ; +xdr_truncate_encode (xdr, starting_len);return nfserr; } eof = (read->rd_offset + maxcount >=
@@ -3078,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdint maxcount;struct xdr_stream *xdr = &resp->xdr;char *page; +int length_offset = xdr->buf->len;__be32 *p;if (nfserr)
@@ -3102,8 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdif (nfserr == nfserr_isdir) nfserr = nfserr_inval;if (nfserr) { - xdr->p--; - xdr->iov->iov_len -=4 ; +xdr_truncate_encode (xdr, length_offset);return nfserr; }
@@ -3132,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4int maxcount;loff_t offset;struct xdr_stream *xdr = &resp->xdr; -__be32 *page, *savep, *tailbase; +int starting_len = xdr->buf->len; +__be32 *page, *tailbase;__be32 *p;if (nfserr)
@@ -3143,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4return nfserr_resource;RESERVE_SPACE (NFS4_VERIFIER_SIZE ); - savep = p;/* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ WRITE32 (0 );
@@ -3205,9 +3206,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4return 0 ; err_no_verf: - xdr->p = savep; - xdr->iov->iov_len = ((char *)resp->xdr.p) - - (char *)resp->xdr.buf->head[0 ].iov_base; +xdr_truncate_encode (xdr, starting_len);return nfserr; }
Signature · 1 line
1.9.0
PATCH 20/52 nfsd4: "backfill" using write_bytes_to_xdr_buf
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Normally xdr encoding proceeds in a single pass from start of a buffer to end, but sometimes we have to write a few bytes to an earlier position.
Use write_bytes_to_xdr_buf for these cases rather than saving a pointer to write to. We plan to rewrite xdr_reserve_space to handle encoding across page boundaries using a scratch buffer, and don't want to risk writing to a pointer that was contained in a scratch buffer.
Also it will no longer be safe to calculate lengths by subtracting two pointers, so use xdr_buf offsets instead.
--- fs/nfsd/nfs4xdr.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-)
fs/nfsd/nfs4xdr.c +26 -19
@@ -1759,16 +1759,19 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, char esc_exit) {__be32 *p; -__be32 *countp; +__be32 pathlen; +int pathlen_offset;int strlen, count=0 ;char *str, *end, *next;dprintk ("nfsd4_encode_components(%s)\n" , components); + + pathlen_offset = xdr->buf->len; p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; - countp = p; -WRITE32 (0 );/* We will fill this in with @count later */ + p++;/* We will fill this in with @count later */ + end = str = components;while (*end) {bool found_esc = false;
@@ -1801,8 +1804,8 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, end++; str = end; } - p = countp; -WRITE32 (count); + pathlen =htonl (xdr->buf->len - pathlen_offset); +write_bytes_to_xdr_buf (xdr->buf, pathlen_offset, &pathlen,4 );return 0 ; }
@@ -2054,7 +2057,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,struct kstatfs statfs;__be32 *p;int starting_len = xdr->buf->len; -__be32 *attrlenp; +int attrlen_offset; +__be32 attrlen;u32 dummy;u64 dummy64;u32 rdattr_err =0 ;
@@ -2159,10 +2163,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,WRITE32 (1 );WRITE32 (bmval0); } + + attrlen_offset = xdr->buf->len; p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; - attrlenp = p++;/* to be backfilled later */ + p++;/* to be backfilled later */ if (bmval0 &FATTR4_WORD0_SUPPORTED_ATTRS ) {u32 word0 =nfsd_suppattrs0 (minorversion);
@@ -2534,7 +2540,8 @@ out_acl:WRITE32 (NFSD_SUPPATTR_EXCLCREAT_WORD2 ); } - *attrlenp =htonl ((char *)xdr->p - (char *)attrlenp -4 ); + attrlen =htonl (xdr->buf->len - attrlen_offset -4 ); +write_bytes_to_xdr_buf (xdr->buf, attrlen_offset, &attrlen,4 ); status = nfs_ok; out:
@@ -3664,15 +3671,16 @@ __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)void nfsd4_encode_operation (struct nfsd4_compoundres *resp,struct nfsd4_op *op) { +struct xdr_stream *xdr = &resp->xdr;struct nfs4_stateowner *so = resp->cstate.replay_owner;struct svc_rqst *rqstp = resp->rqstp; -__be32 *statp; +int post_err_offset;nfsd4_enc encoder;__be32 *p;RESERVE_SPACE (8 );WRITE32 (op->opnum); - statp = p++;/* to be backfilled at the end */ + post_err_offset = xdr->buf->len;if (op->opnum ==OP_ILLEGAL ) goto status;
@@ -3698,20 +3706,19 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)* bug if we had to do this on a non-idempotent op: */ warn_on_nonidempotent_op (op); - resp->xdr.p = statp +1 ; +xdr_truncate_encode (xdr, post_err_offset); }if (so) { +int len = xdr->buf->len - post_err_offset; + so->so_replay.rp_status = op->status; - so->so_replay.rp_buflen = (char *)resp->xdr.p - - (char *)(statp+1 ); -memcpy (so->so_replay.rp_buf, statp+1 , so->so_replay.rp_buflen); + so->so_replay.rp_buflen = len; +read_bytes_from_xdr_buf (xdr->buf, post_err_offset, + so->so_replay.rp_buf, len); } status: -/* -* Note: We write the status directly, instead of using WRITE32(), -* since it is already in network byte order. -*/ - *statp = op->status; +/* Note that op->status is already in network byte order: */ +write_bytes_to_xdr_buf (xdr->buf, post_err_offset -4 , &op->status,4 ); }/*
Signature · 1 line
1.9.0
PATCH 21/52 nfsd4: teach encoders to handle reserve_space failures
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We've tried to prevent running out of space with COMPOUND_SLACK_SPACE and special checking in those operations (getattr) whose result can vary enormously.
However:
- COMPOUND_SLACK_SPACE may be difficult to maintain as we add more protocol.
- BUG_ON or page faulting on failure seems overly fragile.
- Especially in the 4.1 case, we prefer not to fail compounds just because the returned result came *close* to session limits. (Though perfect enforcement here may be difficult.)
- I'd prefer encoding to be uniform for all encoders instead of having special exceptions for encoders containing, for example, attributes.
--- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4xdr.c | 247 +++++++++++++++++++++++++++++++++++++++-------------- fs/nfsd/xdr4.h | 2 +- 3 files changed, 185 insertions(+), 66 deletions(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1402,7 +1402,7 @@ encode_op: }if (op->status == nfserr_replay_me) { op->replay = &cstate->replay_owner->so_replay; -nfsd4_encode_replay (resp, op); +nfsd4_encode_replay (&resp->xdr, op); status = op->status = op->replay->rp_status; }else {nfsd4_encode_operation (resp, op);
fs/nfsd/nfs4xdr.c +183 -64
645 lines not on this page · raw message
fs/nfsd/xdr4.h +1 -1
@@ -563,7 +563,7 @@ int nfs4svc_encode_compoundres(struct svc_rqst *, __be32 *, struct nfsd4_compoundres *);__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *,u32 );void nfsd4_encode_operation (struct nfsd4_compoundres *,struct nfsd4_op *); -void nfsd4_encode_replay (struct nfsd4_compoundres *resp,struct nfsd4_op *op); +void nfsd4_encode_replay (struct xdr_stream *xdr,struct nfsd4_op *op); __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
Signature · 1 line
1.9.0
PATCH 22/52 nfsd4: reserve space before inlining 0-copy pages
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Once we've included page-cache pages in the encoding it's difficult to remove them and restart encoding. (xdr_truncate_encode doesn't handle that case.) So, make sure we'll have adequate space to finish the operation first.
For now COMPOUND_SLACK_SPACE checks should prevent this case happening, but we want to remove those checks.
--- fs/nfsd/nfs4xdr.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/nfsd/nfs4xdr.c +7 -4
@@ -3071,6 +3071,10 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,if (!p)return nfserr_resource; +/* Make sure there will be room for padding if needed: */ +if (xdr->end - xdr->p <1 ) +return nfserr_resource; + maxcount =svc_max_payload (resp->rqstp);if (maxcount > read->rd_length) maxcount = read->rd_length;
@@ -3122,8 +3126,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, resp->xdr.buf->tail[0 ].iov_len =0 ;if (maxcount&3 ) { p =xdr_reserve_space (xdr,4 ); -if (!p) -return nfserr_resource;WRITE32 (0 ); resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 );
@@ -3156,6 +3158,9 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdif (!p)return nfserr_resource; +if (xdr->end - xdr->p <1 ) +return nfserr_resource; +/* * XXX: By default, the ->readlink() VFS op will truncate symlinks * if they would overflow the buffer. Is this kosher in NFSv4? If
@@ -3182,8 +3187,6 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd resp->xdr.buf->tail[0 ].iov_len =0 ;if (maxcount&3 ) { p =xdr_reserve_space (xdr,4 ); -if (!p) -return nfserr_resource;WRITE32 (0 ); resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 );
Signature · 1 line
1.9.0
PATCH 23/52 nfsd4: nfsd4_check_resp_size needn't recalculate length
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We're keeping the length updated as we go now, so there's no need for the extra calculation here.
--- fs/nfsd/nfs4xdr.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
fs/nfsd/nfs4xdr.c +3 -15
@@ -3752,32 +3752,20 @@ static nfsd4_enc nfsd4_enc_ops[] = {*/ __be32 nfsd4_check_resp_size (struct nfsd4_compoundres *resp,u32 pad) { -struct xdr_buf *xb = &resp->rqstp->rq_res; +struct xdr_buf *buf = &resp->rqstp->rq_res;struct nfsd4_session *session =NULL ;struct nfsd4_slot *slot = resp->cstate.slot; -u32 length, tlen =0 ;if (!nfsd4_has_session (&resp->cstate))return 0 ; session = resp->cstate.session; -if (xb->page_len ==0 ) { - length = (char *)resp->xdr.p - (char *)xb->head[0 ].iov_base + pad; - }else { -if (xb->tail[0 ].iov_base && xb->tail[0 ].iov_len >0 ) - tlen = (char *)resp->xdr.p - (char *)xb->tail[0 ].iov_base; - - length = xb->head[0 ].iov_len + xb->page_len + tlen + pad; - } -dprintk ("%s length %u, xb->page_len %u tlen %u pad %u\n" , __func__, - length, xb->page_len, tlen, pad); - -if (length > session->se_fchannel.maxresp_sz) +if (buf->len + pad > session->se_fchannel.maxresp_sz)return nfserr_rep_too_big;if ((slot->sl_flags &NFSD4_SLOT_CACHETHIS ) && - length > session->se_fchannel.maxresp_cached) + buf->len + pad > session->se_fchannel.maxresp_cached)return nfserr_rep_too_big_to_cache;return 0 ;
Signature · 1 line
1.9.0
PATCH 24/52 nfsd4: remove redundant encode buffer size checking
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Now that all op encoders can handle running out of space, we no longer need to check the remaining size for every operation; only nonidempotent operations need that check, and that can be done by nfsd4_check_resp_size.
--- fs/nfsd/nfs4proc.c | 14 -------------- fs/nfsd/nfs4xdr.c | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 23 deletions(-)
fs/nfsd/nfs4proc.c +0 -14
@@ -1281,7 +1281,6 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate = &resp->cstate;struct svc_fh *current_fh = &cstate->current_fh;struct svc_fh *save_fh = &cstate->save_fh; -int slack_bytes;u32 plen =0 ;__be32 status;
@@ -1335,19 +1334,6 @@ nfsd4_proc_compound(struct svc_rqst *rqstp, goto encode_op; } -/* We must be able to encode a successful response to -* this operation, with enough room left over to encode a -* failed response to the next operation. If we don't -* have enough room, fail with ERR_RESOURCE. -*/ - slack_bytes = (char *)resp->xdr.end - (char *)resp->xdr.p; -if (slack_bytes <COMPOUND_SLACK_SPACE - +COMPOUND_ERR_SLACK_SPACE ) { -BUG_ON (slack_bytes <COMPOUND_ERR_SLACK_SPACE ); - op->status = nfserr_resource; - goto encode_op; - } - opdesc =OPDESC (op);if (!current_fh->fh_dentry) {
fs/nfsd/nfs4xdr.c +13 -9
@@ -3753,20 +3753,24 @@ static nfsd4_enc nfsd4_enc_ops[] = {__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *resp,u32 pad) {struct xdr_buf *buf = &resp->rqstp->rq_res; -struct nfsd4_session *session =NULL ; +struct nfsd4_session *session = resp->cstate.session;struct nfsd4_slot *slot = resp->cstate.slot; +int slack_bytes = (char *)resp->xdr.end - (char *)resp->xdr.p; -if (!nfsd4_has_session (&resp->cstate)) -return 0 ; +if (nfsd4_has_session (&resp->cstate)) { - session = resp->cstate.session; +if (buf->len + pad > session->se_fchannel.maxresp_sz) +return nfserr_rep_too_big; -if (buf->len + pad > session->se_fchannel.maxresp_sz) -return nfserr_rep_too_big; +if ((slot->sl_flags &NFSD4_SLOT_CACHETHIS ) && + buf->len + pad > session->se_fchannel.maxresp_cached) +return nfserr_rep_too_big_to_cache; + } -if ((slot->sl_flags &NFSD4_SLOT_CACHETHIS ) && - buf->len + pad > session->se_fchannel.maxresp_cached) -return nfserr_rep_too_big_to_cache; +if (pad > slack_bytes) { +WARN_ON_ONCE (nfsd4_has_session (&resp->cstate)); +return nfserr_resource; + }return 0 ; }
Signature · 1 line
1.9.0
PATCH 25/52 nfsd4: size-checking cleanup
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Better variable name, some comments, etc.
--- fs/nfsd/nfs4proc.c | 9 ++++++--- fs/nfsd/nfs4xdr.c | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-)
fs/nfsd/nfs4proc.c +6 -3
@@ -1281,7 +1281,6 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate = &resp->cstate;struct svc_fh *current_fh = &cstate->current_fh;struct svc_fh *save_fh = &cstate->save_fh; -u32 plen =0 ;__be32 status;svcxdr_init_encode (rqstp, resp);
@@ -1351,9 +1350,13 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,/* If op is non-idempotent */ if (opdesc->op_flags &OP_MODIFIES_SOMETHING ) { - plen = opdesc->op_rsize_bop (rqstp, op);/* -* If there's still another operation, make sure +* Don't execute this op if we couldn't encode a +* succesful reply: +*/ +u32 plen = opdesc->op_rsize_bop (rqstp, op); +/* +* Plus if there's another operation, make sure * we'll have space to at least encode an error: */ if (resp->opcnt < args->opcnt)
fs/nfsd/nfs4xdr.c +15 -14
@@ -3739,35 +3739,36 @@ static nfsd4_enc nfsd4_enc_ops[] = { };/* -* Calculate the total amount of memory that the compound response has taken -* after encoding the current operation with pad. +* Calculate whether we still have space to encode repsize bytes. +* There are two considerations: +* - For NFS versions >=4.1, the size of the reply must stay within +* session limits +* - For all NFS versions, we must stay within limited preallocated +* buffer space. * -* pad: if operation is non-idempotent, pad was calculate by op_rsize_bop() -* which was specified at nfsd4_operation, else pad is zero. -* -* Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached. -* -* Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so -* will be at least a page and will therefore hold the xdr_buf head. +* This is called before the operation is processed, so can only provide +* an upper estimate. For some nonidempotent operations (such as +* getattr), it's not necessarily a problem if that estimate is wrong, +* as we can fail it after processing without significant side effects. */ -__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *resp,u32 pad) +__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *resp,u32 respsize) {struct xdr_buf *buf = &resp->rqstp->rq_res;struct nfsd4_session *session = resp->cstate.session; -struct nfsd4_slot *slot = resp->cstate.slot;int slack_bytes = (char *)resp->xdr.end - (char *)resp->xdr.p;if (nfsd4_has_session (&resp->cstate)) { +struct nfsd4_slot *slot = resp->cstate.slot; -if (buf->len + pad > session->se_fchannel.maxresp_sz) +if (buf->len + respsize > session->se_fchannel.maxresp_sz)return nfserr_rep_too_big;if ((slot->sl_flags &NFSD4_SLOT_CACHETHIS ) && - buf->len + pad > session->se_fchannel.maxresp_cached) + buf->len + respsize > session->se_fchannel.maxresp_cached)return nfserr_rep_too_big_to_cache; } -if (pad > slack_bytes) { +if (respsize > slack_bytes) {WARN_ON_ONCE (nfsd4_has_session (&resp->cstate));return nfserr_resource; }
Signature · 1 line
1.9.0
PATCH 26/52 nfsd4: allow encoding across page boundaries
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
After this we can handle for example getattr of very large ACLs.
Read, readdir, readlink are still special cases with their own limits.
Also we can't handle a new operation starting close to the end of a page.
--- fs/nfsd/nfs4proc.c | 4 +++ fs/nfsd/nfs4xdr.c | 60 +++++++++++++++++++++++++---------- include/linux/sunrpc/svc.h | 1 + include/linux/sunrpc/xdr.h | 1 + net/sunrpc/svc_xprt.c | 1 + net/sunrpc/xdr.c | 78 ++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 126 insertions(+), 19 deletions(-)
fs/nfsd/nfs4proc.c +4 -0
@@ -1266,6 +1266,10 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ;/* Tail and page_len should be zero at this point: */ buf->len = buf->head[0 ].iov_len; + xdr->scratch.iov_len =0 ; + xdr->page_ptr = buf->pages; + buf->buflen =PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) + -2 *RPC_MAX_AUTH_SIZE ; }/*
fs/nfsd/nfs4xdr.c +43 -17
145 lines not on this page · raw message
include/linux/sunrpc/svc.h +1 -0
@@ -244,6 +244,7 @@ struct svc_rqst {struct page * rq_pages[RPCSVC_MAXPAGES ];struct page * *rq_respages;/* points into rq_pages */ struct page * *rq_next_page;/* next reply page to use */ +struct page * *rq_page_end;/* one past the last page */ struct kvec rq_vec[RPCSVC_MAXPAGES ];/* generally useful.. */
include/linux/sunrpc/xdr.h +1 -0
@@ -215,6 +215,7 @@ typedef int (*kxdrdproc_t)(void *rqstp, struct xdr_stream *xdr, void *obj);extern void xdr_init_encode (struct xdr_stream *xdr,struct xdr_buf *buf,__be32 *p);extern __be32 *xdr_reserve_space (struct xdr_stream *xdr,size_t nbytes); +extern void xdr_commit_encode (struct xdr_stream *xdr);extern void xdr_truncate_encode (struct xdr_stream *xdr,size_t len);extern void xdr_write_pages (struct xdr_stream *xdr,struct page **pages,unsigned int base,unsigned int len);
net/sunrpc/svc_xprt.c +1 -0
@@ -597,6 +597,7 @@ static int svc_alloc_arg(struct svc_rqst *rqstp) } rqstp->rq_pages[i] = p; } + rqstp->rq_page_end = &rqstp->rq_pages[i]; rqstp->rq_pages[i++] =NULL ;/* this might be seen in nfs_read_actor */ /* Make arg->head point to first page and arg->pages point to rest */
net/sunrpc/xdr.c +76 -2
108 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 27/52 nfsd4: convert 4.1 replay encoding
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Limits on maxresp_sz mean that we only ever need to replay rpc's that are contained entirely in the head.
The one exception is very small zero-copy reads. That's an odd corner case as clients wouldn't normally ask those to be cached.
in any case, this seems a little more robust.
--- fs/nfsd/nfs4state.c | 28 ++++++++++++++-------------- fs/nfsd/nfs4xdr.c | 2 +- fs/nfsd/xdr4.h | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-)
fs/nfsd/nfs4state.c +14 -14
@@ -1560,6 +1560,7 @@ out_err:void nfsd4_store_cache_entry (struct nfsd4_compoundres *resp) { +struct xdr_buf *buf = resp->xdr.buf;struct nfsd4_slot *slot = resp->cstate.slot;unsigned int base;
@@ -1573,11 +1574,9 @@ nfsd4_store_cache_entry(struct nfsd4_compoundres *resp) slot->sl_datalen =0 ;return ; } - slot->sl_datalen = (char *)resp->xdr.p - (char *)resp->cstate.datap; - base = (char *)resp->cstate.datap - - (char *)resp->xdr.buf->head[0 ].iov_base; -if (read_bytes_from_xdr_buf (resp->xdr.buf, base, slot->sl_data, - slot->sl_datalen)) + base = resp->cstate.data_offset; + slot->sl_datalen = buf->len - base; +if (read_bytes_from_xdr_buf (buf, base, slot->sl_data, slot->sl_datalen))WARN ("%s: sessions DRC could not cache compound\n" , __func__);return ; }
@@ -1618,7 +1617,8 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp, struct nfsd4_sequence *seq) {struct nfsd4_slot *slot = resp->cstate.slot; -struct kvec *head = resp->xdr.iov; +struct xdr_stream *xdr = &resp->xdr; +__be32 *p;__be32 status;dprintk ("--> %s slot %p\n" , __func__, slot);
@@ -1627,16 +1627,16 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,if (status)return status; -/* The sequence operation has been encoded, cstate->datap set. */ -memcpy (resp->cstate.datap, slot->sl_data, slot->sl_datalen); + p =xdr_reserve_space (xdr, slot->sl_datalen); +if (!p) { +WARN_ON_ONCE (1 ); +return nfserr_serverfault; + } +xdr_encode_opaque_fixed (p, slot->sl_data, slot->sl_datalen); +xdr_commit_encode (xdr); resp->opcnt = slot->sl_opcnt; - resp->xdr.p = resp->cstate.datap +XDR_QUADLEN (slot->sl_datalen); - head->iov_len = (void *)resp->xdr.p - head->iov_base; - resp->xdr.buf->len = head->iov_len; - status = slot->sl_status; - -return status; +return slot->sl_status; }/*
fs/nfsd/nfs4xdr.c +1 -1
@@ -3659,7 +3659,7 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,WRITE32 (seq->maxslots -1 );/* sr_target_highest_slotid */ WRITE32 (seq->status_flags); - resp->cstate.datap = p;/* DRC cache data pointer */ + resp->cstate.data_offset = xdr->buf->len;/* DRC cache data pointer */ return 0 ; }
fs/nfsd/xdr4.h +1 -1
@@ -58,7 +58,7 @@ struct nfsd4_compound_state {/* For sessions DRC */ struct nfsd4_session *session;struct nfsd4_slot *slot; -__be32 *datap; +int data_offset;size_t iovlen;u32 minorversion;__be32 status;
Signature · 1 line
1.9.0
PATCH 28/52 nfsd4: don't try to encode conflicting owner if low on space
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
I ran into this corner case in testing: in theory clients can provide state owners up to 1024 bytes long. In the sessions case there might be a risk of this pushing us over the DRC slot size.
The conflicting owner isn't really that important, so let's humor a client that provides a small maxresponsize_cached by allowing ourselves to return without the conflicting owner instead of outright failing the operation.
--- fs/nfsd/nfs4proc.c | 3 ++- fs/nfsd/nfs4xdr.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-)
fs/nfsd/nfs4proc.c +2 -1
@@ -1434,7 +1434,8 @@ out:#define op_encode_change_info_maxsz (5)#define nfs4_fattr_bitmap_maxsz (4) -#define op_encode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) +/* We'll fall back on returning no lockowner if run out of space: */ +#define op_encode_lockowner_maxsz (0)#define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
fs/nfsd/nfs4xdr.c +13 -3
@@ -2878,9 +2878,20 @@ nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld)struct xdr_netobj *conf = &ld->ld_owner;__be32 *p; +again: p =xdr_reserve_space (xdr,32 +XDR_LEN (conf->len)); -if (!p) +if (!p) { +/* +* Don't fail to return the result just because we can't +* return the conflicting open: +*/ +if (conf->len) { + conf->len =0 ; + conf->data =NULL ; + goto again; + }return nfserr_resource; + }WRITE64 (ld->ld_start);WRITE64 (ld->ld_length);WRITE32 (ld->ld_type);
@@ -2888,7 +2899,6 @@ nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld)WRITEMEM (&ld->ld_clientid,8 );WRITE32 (conf->len);WRITEMEM (conf->data, conf->len); -kfree (conf->data); }else {/* non - nfsv4 lock in conflict, no clientid nor owner */ WRITE64 ((u64 )0 );/* clientid */ WRITE32 (0 );/* length of owner name */
@@ -2905,7 +2915,7 @@ nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lo nfserr =nfsd4_encode_stateid (xdr, &lock->lk_resp_stateid); else if (nfserr == nfserr_denied) nfserr =nfsd4_encode_lock_denied (xdr, &lock->lk_denied); - +kfree (lock->lk_denied.ld_owner.data);return nfserr; }
Signature · 1 line
1.9.0
PATCH 29/52 nfsd4: more precise nfsd4_max_reply
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
It will turn out to be useful to have a more accurate estimate of reply size; so, piggyback on the existing op reply-size estimators.
Also move nfsd4_max_reply to nfs4proc.c to get easier access to struct nfsd4_operation and friends. (Thanks to Christoph Hellwig for pointing out that simplification.)
--- fs/nfsd/nfs4proc.c | 12 ++++++++++++ fs/nfsd/nfs4xdr.c | 35 ++++------------------------------- fs/nfsd/xdr4.h | 1 + 3 files changed, 17 insertions(+), 31 deletions(-)
fs/nfsd/nfs4proc.c +12 -0
@@ -1856,6 +1856,18 @@ static struct nfsd4_operation nfsd4_ops[] = { }, }; +int nfsd4_max_reply (struct svc_rqst *rqstp,struct nfsd4_op *op) +{ +struct nfsd4_operation *opdesc; +nfsd4op_rsize estimator; + +if (op->opnum ==OP_ILLEGAL ) +return op_encode_hdr_size; + opdesc =OPDESC (op); + estimator = opdesc->op_rsize_bop; +return estimator ?estimator (rqstp, op) :PAGE_SIZE ; +} +void warn_on_nonidempotent_op (struct nfsd4_op *op) {if (OPDESC (op)->op_flags &OP_MODIFIES_SOMETHING ) {
fs/nfsd/nfs4xdr.c +4 -31
@@ -1605,40 +1605,13 @@ nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)return true; } -/* -* Return a rough estimate of the maximum possible reply size. Note the -* estimate includes rpc headers so is meant to be passed to -* svc_reserve, not svc_reserve_auth. -* -* Also note the current compound encoding permits only one operation to -* use pages beyond the first one, so the maximum possible length is the -* maximum over these values, not the sum. -*/ -static int nfsd4_max_reply (u32 opnum) -{ -switch (opnum) { -case OP_READLINK : -case OP_READDIR : -/* -* Both of these ops take a single page for data and put -* the head and tail in another page: -*/ -return 2 *PAGE_SIZE ; -case OP_GETATTR : -case OP_READ : -return INT_MAX ; -default : -return PAGE_SIZE ; - } -} -static __be32 nfsd4_decode_compound (struct nfsd4_compoundargs *argp) {DECODE_HEAD ;struct nfsd4_op *op;bool cachethis = false; -int max_reply =PAGE_SIZE ; +int max_reply =2 *RPC_MAX_AUTH_SIZE +8 ;/* opcnt, status */ int i;READ_BUF (4 );
@@ -1647,6 +1620,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)SAVEMEM (argp->tag, argp->taglen);READ32 (argp->minorversion);READ32 (argp->opcnt); + max_reply +=4 + (XDR_QUADLEN (argp->taglen) <<2 );if (argp->taglen >NFSD4_MAX_TAGLEN ) goto xdr_error;
@@ -1684,7 +1658,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)*/ cachethis |=nfsd4_cache_this_op (op); - max_reply =max (max_reply,nfsd4_max_reply (op->opnum)); + max_reply +=nfsd4_max_reply (argp->rqstp, op);if (op->status) { argp->opcnt = i+1 ;
@@ -1694,8 +1668,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)/* Sessions make the DRC unnecessary: */ if (argp->minorversion) cachethis = false; -if (max_reply !=INT_MAX ) -svc_reserve (argp->rqstp, max_reply); +svc_reserve (argp->rqstp, max_reply); argp->rqstp->rq_cachetype = cachethis ?RC_REPLBUFF :RC_NOCACHE ;DECODE_TAIL ;
fs/nfsd/xdr4.h +1 -0
@@ -536,6 +536,7 @@ static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp)return argp->opcnt == resp->opcnt; } +int nfsd4_max_reply (struct svc_rqst *rqstp,struct nfsd4_op *op);void warn_on_nonidempotent_op (struct nfsd4_op *op);#define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs)
Signature · 1 line
1.9.0
PATCH 30/52 nfsd4: minor encode_read cleanup
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4xdr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/nfsd/nfs4xdr.c +6 -4
@@ -3076,18 +3076,20 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, len = maxcount; v =0 ; -while (len >0 ) { +while (len) { +int thislen; + page = *(resp->rqstp->rq_next_page);if (!page) {/* ran out of pages */ maxcount -= len;break ; } + thislen =min_t (long, len,PAGE_SIZE ); resp->rqstp->rq_vec[v].iov_base =page_address (page); - resp->rqstp->rq_vec[v].iov_len = - len <PAGE_SIZE ? len :PAGE_SIZE ; + resp->rqstp->rq_vec[v].iov_len = thislen; resp->rqstp->rq_next_page++; v++; - len -=PAGE_SIZE ; + len -= thislen; } read->rd_vlen = v;
Signature · 1 line
1.9.0
PATCH 31/52 nfsd4: nfsd4_check_resp_size should check against whole buffer
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4xdr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfs4xdr.c +1 -2
@@ -3762,7 +3762,6 @@ __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) {struct xdr_buf *buf = &resp->rqstp->rq_res;struct nfsd4_session *session = resp->cstate.session; -int slack_bytes = (char *)resp->xdr.end - (char *)resp->xdr.p;if (nfsd4_has_session (&resp->cstate)) {struct nfsd4_slot *slot = resp->cstate.slot;
@@ -3775,7 +3774,7 @@ __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize)return nfserr_rep_too_big_to_cache; } -if (respsize > slack_bytes) { +if (buf->len + respsize > buf->buflen) {WARN_ON_ONCE (nfsd4_has_session (&resp->cstate));return nfserr_resource; }
Signature · 1 line
1.9.0
PATCH 32/52 nfsd4: fix buflen calculation after read encoding
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We don't necessarily want to assume that the buflen is the same as the number of bytes available in the pages. We may have some reason to set it to something less (for example, later patches will use a smaller buflen to enforce session limits).
So, calculate the buflen relative to the previous buflen instead of recalculating it from scratch.
--- fs/nfsd/nfs4xdr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +7 -1
@@ -3053,6 +3053,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,unsigned long maxcount;struct xdr_stream *xdr = &resp->xdr;int starting_len = xdr->buf->len; +int space_left;long len;__be32 *p;
@@ -3117,7 +3118,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, resp->xdr.buf->page_len = maxcount; xdr->buf->len += maxcount; xdr->page_ptr += v; - xdr->buf->buflen = maxcount +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; xdr->iov = xdr->buf->tail;/* Use rest of head for padding and remaining ops: */
@@ -3130,6 +3130,12 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); xdr->buf->len -= (maxcount&3 ); } + + space_left =min_t (int, (void *)xdr->end - (void *)xdr->p, + xdr->buf->buflen - xdr->buf->len); + xdr->buf->buflen = xdr->buf->len + space_left; + xdr->end = (__be32 *)((void *)xdr->end + space_left); +return 0 ; }
Signature · 1 line
1.9.0
PATCH 33/52 rpc: define xdr_restrict_buflen
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
With this xdr_reserve_space can help us enforce various limits.
--- include/linux/sunrpc/xdr.h | 1 + net/sunrpc/xdr.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/linux/sunrpc/xdr.h +1 -0
@@ -217,6 +217,7 @@ extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32extern __be32 *xdr_reserve_space (struct xdr_stream *xdr,size_t nbytes);extern void xdr_commit_encode (struct xdr_stream *xdr);extern void xdr_truncate_encode (struct xdr_stream *xdr,size_t len); +extern int xdr_restrict_buflen (struct xdr_stream *xdr,int newbuflen);extern void xdr_write_pages (struct xdr_stream *xdr,struct page **pages,unsigned int base,unsigned int len);extern unsigned int xdr_stream_pos (const struct xdr_stream *xdr);
net/sunrpc/xdr.c +29 -0
@@ -650,6 +650,35 @@ void xdr_truncate_encode(struct xdr_stream *xdr, size_t len)EXPORT_SYMBOL (xdr_truncate_encode);/** +* xdr_restrict_buflen - decrease available buffer space +* @xdr: pointer to xdr_stream +* @newbuflen: new maximum number of bytes available +* +* Adjust our idea of how much space is available in the buffer. +* If we've already used too much space in the buffer, returns -1. +* If the available space is already smaller than newbuflen, returns 0 +* and does nothing. Otherwise, adjusts xdr->buf->buflen to newbuflen +* and ensures xdr->end is set at most offset newbuflen from the start +* of the buffer. +*/ +int xdr_restrict_buflen (struct xdr_stream *xdr,int newbuflen) +{ +struct xdr_buf *buf = xdr->buf; +int left_in_this_buf = (void *)xdr->end - (void *)xdr->p; +int end_offset = buf->len + left_in_this_buf; + +if (newbuflen <0 || newbuflen < buf->len) +return -1 ; +if (newbuflen > buf->buflen) +return 0 ; +if (newbuflen < end_offset) + xdr->end = (void *)xdr->end + newbuflen - end_offset; + buf->buflen = newbuflen; +return 0 ; +} +EXPORT_SYMBOL (xdr_restrict_buflen); + +/** * xdr_write_pages - Insert a list of pages into an XDR buffer for sending * @xdr: pointer to xdr_stream * @pages: list of pages
Signature · 1 line
1.9.0
PATCH 34/52 nfsd4: adjust buflen to session channel limit
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We can simplify session limit enforcement by restricting the xdr buflen to the session size.
Also fix a preexisting bug: we should really have been taking into account the auth-required space when comparing against session limits, which are limits on the size of the entire rpc reply, including any krb5 overhead.
--- fs/nfsd/nfs4state.c | 11 +++++++++++ fs/nfsd/nfs4xdr.c | 24 ++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-)
fs/nfsd/nfs4state.c +11 -0
@@ -2208,11 +2208,13 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_sequence *seq) {struct nfsd4_compoundres *resp = rqstp->rq_resp; +struct xdr_stream *xdr = &resp->xdr;struct nfsd4_session *session;struct nfs4_client *clp;struct nfsd4_slot *slot;struct nfsd4_conn *conn;__be32 status; +int buflen;struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);if (resp->opcnt !=1 )
@@ -2281,6 +2283,15 @@ nfsd4_sequence(struct svc_rqst *rqstp,if (status) goto out_put_session; + buflen = (seq->cachethis) ? + session->se_fchannel.maxresp_cached : + session->se_fchannel.maxresp_sz; + status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : + nfserr_rep_too_big; +if (xdr_restrict_buflen (xdr, buflen -2 *RPC_MAX_AUTH_SIZE )) + goto out_put_session; + + status = nfs_ok;/* Success! bump slot seqid */ slot->sl_seqid = seq->seqid; slot->sl_flags |=NFSD4_SLOT_INUSE ;
fs/nfsd/nfs4xdr.c +8 -16
@@ -3767,25 +3767,17 @@ static nfsd4_enc nfsd4_enc_ops[] = {__be32 nfsd4_check_resp_size (struct nfsd4_compoundres *resp,u32 respsize) {struct xdr_buf *buf = &resp->rqstp->rq_res; -struct nfsd4_session *session = resp->cstate.session; +struct nfsd4_slot *slot = resp->cstate.slot; -if (nfsd4_has_session (&resp->cstate)) { -struct nfsd4_slot *slot = resp->cstate.slot; - -if (buf->len + respsize > session->se_fchannel.maxresp_sz) -return nfserr_rep_too_big; - -if ((slot->sl_flags &NFSD4_SLOT_CACHETHIS ) && - buf->len + respsize > session->se_fchannel.maxresp_cached) -return nfserr_rep_too_big_to_cache; - } - -if (buf->len + respsize > buf->buflen) { -WARN_ON_ONCE (nfsd4_has_session (&resp->cstate)); +if (buf->len + respsize <= buf->buflen) +return nfs_ok; +if (!nfsd4_has_session (&resp->cstate))return nfserr_resource; +if (slot->sl_flags &NFSD4_SLOT_CACHETHIS ) { +WARN_ON_ONCE (1 ); +return nfserr_rep_too_big_to_cache; } - -return 0 ; +return nfserr_rep_too_big; }void
Signature · 1 line
1.9.0
PATCH 35/52 nfsd4: use session limits to release send buffer reservation
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Once we know the limits the session places on the size of the rpc, we can also use that information to release any unnecessary reserved reply buffer space.
--- fs/nfsd/nfs4state.c | 1 + 1 file changed, 1 insertion(+)
fs/nfsd/nfs4state.c +1 -0
@@ -2290,6 +2290,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, nfserr_rep_too_big;if (xdr_restrict_buflen (xdr, buflen -2 *RPC_MAX_AUTH_SIZE )) goto out_put_session; +svc_reserve (rqstp, buflen); status = nfs_ok;/* Success! bump slot seqid */
Signature · 1 line
1.9.0
PATCH 36/52 nfsd4: allow large readdirs
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Currently we limit readdir results to a single page. This can result in a performance regression compared to NFSv3 when reading large directories.
--- fs/nfsd/nfs4proc.c | 9 ++-- fs/nfsd/nfs4xdr.c | 137 +++++++++++++++++++++++++++++------------------------ fs/nfsd/xdr4.h | 5 +- 3 files changed, 82 insertions(+), 69 deletions(-)
fs/nfsd/nfs4proc.c +5 -4
@@ -1502,13 +1502,14 @@ static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)static inline u32 nfsd4_readdir_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op) { +u32 maxcount =svc_max_payload (rqstp);u32 rlen = op->u.readdir.rd_maxcount; -if (rlen >PAGE_SIZE ) - rlen =PAGE_SIZE ; +if (rlen > maxcount) + rlen = maxcount; -return (op_encode_hdr_size + op_encode_verifier_maxsz) - *sizeof (__be32) + rlen; +return (op_encode_hdr_size + op_encode_verifier_maxsz + +XDR_QUADLEN (rlen)) *sizeof (__be32); }static inline u32 nfsd4_remove_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op)
fs/nfsd/nfs4xdr.c +75 -62
229 lines not on this page · raw message
fs/nfsd/xdr4.h +2 -3
@@ -287,9 +287,8 @@ struct nfsd4_readdir {struct svc_fh * rd_fhp;/* response */ struct readdir_cd common; -__be32 * buffer; -int buflen; -__be32 * offset; +struct xdr_stream *xdr; +int cookie_offset; };struct nfsd4_release_lockowner {
Signature · 1 line
1.9.0
PATCH 37/52 nfsd4: enforce rd_dircount
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
As long as we're here, let's enforce the protocol's limit on the number of directory entries to return in a readdir.
I don't think anyone's ever noticed our lack of enforcement, but maybe there's more of a chance they will now that we allow larger readdirs.
--- fs/nfsd/nfs4xdr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +4 -1
@@ -1033,7 +1033,7 @@ nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readREAD_BUF (24 );READ64 (readdir->rd_cookie);COPYMEM (readdir->rd_verf.data,sizeof (readdir->rd_verf.data)); -READ32 (readdir->rd_dircount);/* just in case you needed a useless field... */ +READ32 (readdir->rd_dircount);READ32 (readdir->rd_maxcount);if ((status =nfsd4_decode_bitmap (argp, readdir->rd_bmval))) goto out;
@@ -2720,6 +2720,9 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,if (entry_bytes > cd->rd_maxcount) goto fail; cd->rd_maxcount -= entry_bytes; +if (!cd->rd_dircount) + goto fail; + cd->rd_dircount--; cd->cookie_offset = cookie_offset; skip_entry: cd->common.err = nfs_ok;
Signature · 1 line
1.9.0
PATCH 38/52 nfsd4: don't treat readlink like a zero-copy operation
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
There's no advantage to this zero-copy-style readlink encoding, and it unnecessarily limits the kinds of compounds we can handle. (In practice I can't see why a client would want e.g. multiple readlink calls in a comound, but it's probably a spec violation for us not to handle it.)
--- fs/nfsd/nfs4xdr.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)
fs/nfsd/nfs4xdr.c +12 -30
@@ -3160,8 +3160,9 @@ static __be32 nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink) { int maxcount; +__be32 wire_count; +int zero =0 ;struct xdr_stream *xdr = &resp->xdr; -char *page;int length_offset = xdr->buf->len;__be32 *p;
@@ -3171,26 +3172,19 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; - -if (resp->xdr.buf->page_len) -return nfserr_resource; -if (!*resp->rqstp->rq_next_page) -return nfserr_resource; - - page =page_address (*(resp->rqstp->rq_next_page++)); - maxcount =PAGE_SIZE ; -if (xdr->end - xdr->p <1 ) + p =xdr_reserve_space (xdr, maxcount); +if (!p)return nfserr_resource; -/* * XXX: By default, the ->readlink() VFS op will truncate symlinks * if they would overflow the buffer. Is this kosher in NFSv4? If * not, one easy fix is: if ->readlink() precisely fills the buffer, * assume that truncation occurred, and return NFS4ERR_RESOURCE. */ - nfserr =nfsd_readlink (readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount); + nfserr =nfsd_readlink (readlink->rl_rqstp, readlink->rl_fhp, + (char *)p, &maxcount);if (nfserr == nfserr_isdir) nfserr = nfserr_inval;if (nfserr) {
@@ -3198,24 +3192,12 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdreturn nfserr; } -WRITE32 (maxcount); - resp->xdr.buf->head[0 ].iov_len = (char *)p - - (char *)resp->xdr.buf->head[0 ].iov_base; - resp->xdr.buf->page_len = maxcount; - xdr->buf->len += maxcount; - xdr->page_ptr +=1 ; - xdr->buf->buflen -=PAGE_SIZE ; - xdr->iov = xdr->buf->tail; - -/* Use rest of head for padding and remaining ops: */ - resp->xdr.buf->tail[0 ].iov_base = p; - resp->xdr.buf->tail[0 ].iov_len =0 ; -if (maxcount&3 ) { - p =xdr_reserve_space (xdr,4 ); -WRITE32 (0 ); - resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; - resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); - } + wire_count =htonl (maxcount); +write_bytes_to_xdr_buf (xdr->buf, length_offset, &wire_count,4 ); +xdr_truncate_encode (xdr, length_offset +4 + maxcount); +if (maxcount &3 ) +write_bytes_to_xdr_buf (xdr->buf, length_offset +4 + maxcount, + &zero,4 - (maxcount&3 ));return 0 ; }
Signature · 1 line
1.9.0
PATCH 39/52 nfsd4: better estimate of getattr response size
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We plan to use this estimate to decide whether or not to allow zero-copy reads. Currently we're assuming all getattr's are a page, which can be both too small (ACLs e.g. may be arbitrarily long) and too large (after an upcoming read patch this will unnecessarily prevent zero copy reads in any read compound also containing a getattr).
--- fs/nfsd/nfs4proc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
fs/nfsd/nfs4proc.c +44 -0
@@ -1467,6 +1467,49 @@ static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); } +/* +* Note since this is an idempotent operation we won't insist on failing +* the op prematurely if the estimate is too large. We may turn off splice +* reads unnecessarily. +*/ +static inline u32 nfsd4_getattr_rsize (struct svc_rqst *rqstp, +struct nfsd4_op *op) +{ +u32 *bmap = op->u.getattr.ga_bmval; +u32 bmap0 = bmap[0 ], bmap1 = bmap[1 ], bmap2 = bmap[2 ]; +u32 ret =0 ; + +if (bmap0 &FATTR4_WORD0_ACL ) +return svc_max_payload (rqstp); +if (bmap0 &FATTR4_WORD0_FS_LOCATIONS ) +return svc_max_payload (rqstp); + +if (bmap1 &FATTR4_WORD1_OWNER ) { + ret +=IDMAP_NAMESZ +4 ; + bmap1 &= ~FATTR4_WORD1_OWNER ; + } +if (bmap1 &FATTR4_WORD1_OWNER_GROUP ) { + ret +=IDMAP_NAMESZ +4 ; + bmap1 &= ~FATTR4_WORD1_OWNER_GROUP ; + } +if (bmap0 &FATTR4_WORD0_FILEHANDLE ) { + ret +=NFS4_FHSIZE +4 ; + bmap0 &= ~FATTR4_WORD0_FILEHANDLE ; + } +if (bmap2 &FATTR4_WORD2_SECURITY_LABEL ) { + ret +=NFSD4_MAX_SEC_LABEL_LEN +12 ; + bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL ; + } +/* +* Largest of remaining attributes are 16 bytes (e.g., +* supported_attributes) +*/ + ret +=16 * (hweight32 (bmap0) +hweight32 (bmap1) +hweight32 (bmap2)); +/* bitmask, length */ + ret +=20 ; +return ret; +} +static inline u32 nfsd4_link_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op) {return (op_encode_hdr_size + op_encode_change_info_maxsz)
@@ -1605,6 +1648,7 @@ static struct nfsd4_operation nfsd4_ops[] = { [OP_GETATTR] = { .op_func = (nfsd4op_func)nfsd4_getattr, .op_flags = ALLOWED_ON_ABSENT_FS, + .op_rsize_bop = nfsd4_getattr_rsize, .op_name = "OP_GETATTR", }, [OP_GETFH] = {
Signature · 1 line
1.9.0
PATCH 40/52 nfsd4: estimate sequence response size
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Otherwise a following patch would turn off all 4.1 zero-copy reads.
--- fs/nfsd/nfs4proc.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/nfsd/nfs4proc.c +6 -0
@@ -1567,6 +1567,12 @@ static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op + op_encode_change_info_maxsz) * sizeof(__be32); } +static inline u32 nfsd4_sequence_rsize (struct svc_rqst *rqstp, +struct nfsd4_op *op) +{ +return NFS4_MAX_SESSIONID_LEN +20 ; +} +static inline u32 nfsd4_setattr_rsize (struct svc_rqst *rqstp,struct nfsd4_op *op) {return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) *sizeof (__be32);
Signature · 1 line
1.9.0
PATCH 41/52 nfsd4: turn off zero-copy-read in exotic cases
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We currently allow only one read per compound, with operations before and after whose responses will require no more than about a page to encode.
While we don't expect clients to violate those limits any time soon, this limitation isn't really condoned by the spec, so to future proof the server we should lift the limitation.
At the same time we'd like to continue to support zero-copy reads.
Supporting multiple zero-copy-reads per compound would require a new data structure to replace struct xdr_buf, which can represent only one set of included pages.
So for now we plan to modify encode_read() to support either zero-copy or non-zero-copy reads, and use some heuristics at the start of the compound processing to decide whether a zero-copy read will work.
This will allow us to support more exotic compounds without introducing a performance regression in the normal case.
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
--- fs/nfsd/nfs4xdr.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
fs/nfsd/nfs4xdr.c +17 -4
@@ -1612,6 +1612,8 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)struct nfsd4_op *op;bool cachethis = false;int max_reply =2 *RPC_MAX_AUTH_SIZE +8 ;/* opcnt, status */ +int readcount =0 ; +int readbytes =0 ;int i;READ_BUF (4 );
@@ -1658,7 +1660,11 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)*/ cachethis |=nfsd4_cache_this_op (op); - max_reply +=nfsd4_max_reply (argp->rqstp, op); +if (op->opnum ==OP_READ ) { + readcount++; + readbytes +=nfsd4_max_reply (argp->rqstp, op); + }else + max_reply +=nfsd4_max_reply (argp->rqstp, op);if (op->status) { argp->opcnt = i+1 ;
@@ -1668,9 +1674,12 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)/* Sessions make the DRC unnecessary: */ if (argp->minorversion) cachethis = false; -svc_reserve (argp->rqstp, max_reply); +svc_reserve (argp->rqstp, max_reply + readbytes); argp->rqstp->rq_cachetype = cachethis ?RC_REPLBUFF :RC_NOCACHE ; +if (readcount >1 || max_reply >PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ) + argp->rqstp->rq_splice_ok = false; +DECODE_TAIL ; }
@@ -3078,15 +3087,19 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,return nfserr; p =xdr_reserve_space (xdr,8 );/* eof flag and byte count */ -if (!p) +if (!p) { +WARN_ON_ONCE (resp->rqstp->rq_splice_ok);return nfserr_resource; + }/* Make sure there will be room for padding if needed: */ if (xdr->end - xdr->p <1 )return nfserr_resource; -if (resp->xdr.buf->page_len) +if (resp->xdr.buf->page_len) { +WARN_ON_ONCE (resp->rqstp->rq_splice_ok);return nfserr_resource; + } maxcount =svc_max_payload (resp->rqstp);if (maxcount > read->rd_length)
Signature · 1 line
1.9.0
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
I could really use more of those. Maybe I'm wrong, but I'm worried less about this case than the more finicky out-of-reply-space cases, where I do have patches puporting to fix problems that I haven't really verified.
--b.
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 7 lines · J. Bruce Fields
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
Quoted 7 lines
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
I could really use more of those. Maybe I'm wrong, but I'm worried less about this case than the more finicky out-of-reply-space cases, where I do have patches puporting to fix problems that I haven't really verified.
I'll eventually be using this case for READ_PLUS. I'll be sure to send problems your way! :)
Anna
Quoted 6 lines
--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 12 lines · Anna Schumaker
Quoted 11 lines · J. Bruce Fields
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
Quoted 7 lines
Quoted 4 lines
I could really use more of those. Maybe I'm wrong, but I'm worried less about this case than the more finicky out-of-reply-space cases, where I do have patches puporting to fix problems that I haven't really verified.
I'll eventually be using this case for
READ_PLUS. I'll be sure to send problems your way! :)
Great, thanks.
Actually my main question there is how to handle 4.2 in pynfs.
4.1 and 4.0 are entirely separate codebases. We definitely don't want to do that again.
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
--b.
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 17 lines · J. Bruce Fields
Quoted 16 lines · Anna Schumaker
Quoted 15 lines · J. Bruce Fields
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
I could really use more of those. Maybe I'm wrong, but I'm worried less about this case than the more finicky out-of-reply-space cases, where I do have patches puporting to fix problems that I haven't really verified.
Quoted 8 lines
Quoted 2 lines
I'll eventually be using this case for
READ_PLUS. I'll be sure to send problems your way! :)Great, thanks.
Actually my main question there is how to handle 4.2 in pynfs.
4.1 and 4.0 are entirely separate codebases. We definitely don't want to do that again.
Can you make v4.2 a new file that uses the v4.1 functions? That way all the v4.2 stuff is kept together. I want to try doing something similar on the client for functions in nfs4proc.c and nfs4xdr.c.
Anna
Quoted 9 lines
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
--b.
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
In reply to J. Bruce FieldsQuoted 21 lines · J. Bruce Fields
Quoted 12 lines · Anna Schumaker
Quoted 11 lines · J. Bruce Fields
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
Quoted 7 lines
Quoted 4 lines
I could really use more of those. Maybe I'm wrong, but I'm worried less about this case than the more finicky out-of-reply-space cases, where I do have patches puporting to fix problems that I haven't really verified.
I'll eventually be using this case for
READ_PLUS. I'll be sure to send problems your way! :)
Quoted 6 lines
Great, thanks.
Actually my main question there is how to handle 4.2 in pynfs.
4.1 and 4.0 are entirely separate codebases. We definitely don't want to do that again.
I strongly agree!
Quoted 7 lines
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
I’ve made a lot of pynfs cleanups recently - mostly on the client test side (the nfs4.1 server), but they may make this a bit easier. I’ll clean them up and share asap.
I was just adding new xdr to pynfs and AFAIK it's xdrgen has no include support, so we’re stuck tacking things on the end of nfs4.x. Would it be worthwhile for me to add some type of include support? Minor versions and layouts could stay in separate .x files - that sounds much cleaner to me.
-dros
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 8 lines · Weston Andros Adamson
Quoted 6 lines · J. Bruce Fields
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
Quoted 8 lines
I’ve made a lot of pynfs cleanups recently - mostly on the client test side (the nfs4.1 server), but they may make this a bit easier. I’ll clean them up and share asap.
I was just adding new xdr to pynfs and AFAIK it's xdrgen has no include support, so we’re stuck tacking things on the end of nfs4.x. Would it be worthwhile for me to add some type of include support? Minor versions and layouts could stay in separate .x files - that sounds much cleaner to me.
That does sound cleaner, but is that how the ietf's .x files work?
It looks like
http://www.ietf.org/id/draft-ietf-nfsv4-minorversion2-dot-x-26.txt
just copies all the 4.1 definitions.
I may not understand what you're proposing.
--b.
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 20 lines · J. Bruce Fields
Quoted 8 lines · Weston Andros Adamson
Quoted 6 lines · J. Bruce Fields
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
Quoted 8 lines
I’ve made a lot of pynfs cleanups recently - mostly on the client test side (the nfs4.1 server), but they may make this a bit easier. I’ll clean them up and share asap.
I was just adding new xdr to pynfs and AFAIK it's xdrgen has no include support, so we’re stuck tacking things on the end of nfs4.x. Would it be worthwhile for me to add some type of include support? Minor versions and layouts could stay in separate .x files - that sounds much cleaner to me.
That does sound cleaner, but is that how the ietf's .x files work?
Quoted 7 lines
It looks like
http://www.ietf.org/id/draft-ietf-nfsv4-minorversion2-dot-x-26.txt
just copies all the 4.1 definitions.
I may not understand what you're proposing.
Oh, yeah. I was thinking more about layouts - like the flex file draft - that don’t repeat definitions and instead reference other xdr definitions.
I don’t know if there is any restriction in the IETF that all types within a .x have to be defined by that .x. If not, does it make sense to change the 4.2 spec to only have new types, or to prune out the differences for pynfs?
-dros
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 24 lines · Weston Andros Adamson
Quoted 22 lines · J. Bruce Fields
Quoted 8 lines · Weston Andros Adamson
Quoted 6 lines · J. Bruce Fields
There's not much point re-running all the 4.1 tests over 4.2. Maybe all we may need is to say "use minor version 2 on this compound" in tests of the new features.
But I haven't even tried to figure out how to tell pynfs about the new .x files.
Quoted 8 lines
I’ve made a lot of pynfs cleanups recently - mostly on the client test side (the nfs4.1 server), but they may make this a bit easier. I’ll clean them up and share asap.
I was just adding new xdr to pynfs and AFAIK it's xdrgen has no include support, so we’re stuck tacking things on the end of nfs4.x. Would it be worthwhile for me to add some type of include support? Minor versions and layouts could stay in separate .x files - that sounds much cleaner to me.
That does sound cleaner, but is that how the ietf's .x files work?
It looks like
Quoted 8 lines
Quoted 5 lines
http://www.ietf.org/id/draft-ietf-nfsv4-minorversion2-dot-x-26.txt
just copies all the 4.1 definitions.
I may not understand what you're proposing.
Oh, yeah. I was thinking more about layouts - like the flex file draft - that don’t repeat definitions and instead reference other xdr definitions.
OK, I don't really care about those yet--however you think it makes sense is fine to me.... If we can use the ietf's files verbatim then that will simplify keeping up with drafts and verifying we have the protocol right, so we should support includes if they use them.
Quoted 3 lines
I don’t know if there is any restriction in the IETF that all types within a .x have to be defined by that .x. If not, does it make sense to change the 4.2 spec to only have new types, or to prune out the differences for pynfs?
I guess that's a question for Tom and/or the ietf list.
--b.
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
In reply to J. Bruce FieldsQuoted 8 lines · J. Bruce Fields
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
But, look, it wasn't turned on in my regular tests so, surprise, I regressed recently without noticing; I intend to fold in the below after some more testing.
Quoted 2 lines
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
Still working on that.
--b.
fs/nfsd/nfs4xdr.c +2 -4
@@ -3197,12 +3197,10 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,WARN_ON_ONCE (resp->rqstp->rq_splice_ok);return nfserr_resource; } - -if (resp->xdr.buf->page_len) { -WARN_ON_ONCE (resp->rqstp->rq_splice_ok); +if (resp->xdr.buf->page_len && resp->rqstp->rq_splice_ok) { +WARN_ON_ONCE (1 );return nfserr_resource; } -xdr_commit_encode (xdr); maxcount =svc_max_payload (resp->rqstp);
Re: [PATCH 41/52] nfsd4: turn off zero-copy-read in exotic cases
Quoted 10 lines · bfields
Quoted 8 lines · J. Bruce Fields
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · J. Bruce Fields
Later patches handle those "exotic compounds", this one just makes sure zero-copy is turned off in those cases.
How did you test these exotic compounds?
I have is a pynfs test that sends a compound with multiple reads in it.
Quoted 8 lines
But, look, it wasn't turned on in my regular tests so, surprise, I regressed recently without noticing; I intend to fold in the below after some more testing.
Quoted 2 lines
I don't think that's pushed out to my regular pynfs tree, I'll try to do that today.
Still working on that.
I've pushed out some minimal tests of the new xdr code to
git://linux-nfs.org/~bfields/pynfs.git master
Frank, some of those might not really be appropriate for any server, I'm not sure.
--b.
PATCH 42/52 nfsd4: nfsd_vfs_read doesn't use file handle parameter
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/vfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/nfsd/vfs.c +3 -3
@@ -821,7 +821,7 @@ static int nfsd_direct_splice_actor(struct pipe_inode_info *pipe, }static __be32 -nfsd_vfs_read (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file, +nfsd_vfs_read (struct svc_rqst *rqstp,struct file *file,loff_t offset,struct kvec *vec,int vlen,unsigned long *count) {mm_segment_t oldfs;
@@ -969,7 +969,7 @@ __be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,if (ra && ra->p_set) file->f_ra = ra->p_ra; - err =nfsd_vfs_read (rqstp, fhp, file, offset, vec, vlen, count); + err =nfsd_vfs_read (rqstp, file, offset, vec, vlen, count);/* Write back readahead params */ if (ra) {
@@ -998,7 +998,7 @@ nfsd_read_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE);if (err) goto out; - err =nfsd_vfs_read (rqstp, fhp, file, offset, vec, vlen, count); + err =nfsd_vfs_read (rqstp, file, offset, vec, vlen, count); }else /* Note file may still be NULL in NFSv4 special stateid case: */ err =nfsd_read (rqstp, fhp, offset, vec, vlen, count); out:
Signature · 1 line
1.9.0
PATCH 43/52 nfsd4: separate splice and readv cases
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
The splice and readv cases are actually quite different--for example the former case ignores the array of vectors we build up for the latter.
It is probably clearer to separate the two cases entirely.
There's some code duplication between the split out encoders, but this is only temporary and will be fixed by a later patch.
--- fs/nfsd/nfs4xdr.c | 173 +++++++++++++++++++++++++++++++++++++++++------------- fs/nfsd/vfs.c | 121 +++++++++++++++++++++++--------------- fs/nfsd/vfs.h | 8 +++ 3 files changed, 214 insertions(+), 88 deletions(-)
fs/nfsd/nfs4xdr.c +131 -42
@@ -3069,41 +3069,84 @@ nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, strucreturn nfserr; } -static __be32 -nfsd4_encode_read (struct nfsd4_compoundres *resp,__be32 nfserr, -struct nfsd4_read *read) +static __be32 nfsd4_encode_splice_read ( +struct nfsd4_compoundres *resp, +struct nfsd4_read *read, +struct file *file,unsigned long maxcount) { -u32 eof; -int v; -struct page *page; -unsigned long maxcount;struct xdr_stream *xdr = &resp->xdr; -int starting_len = xdr->buf->len; +u32 eof; +int starting_len = xdr->buf->len -8 ;int space_left; -long len; +__be32 nfserr; +__be32 tmp;__be32 *p; -if (nfserr) -return nfserr; - - p =xdr_reserve_space (xdr,8 );/* eof flag and byte count */ -if (!p) { -WARN_ON_ONCE (resp->rqstp->rq_splice_ok); +/* +* Don't inline pages unless we know there's room for eof, +* count, and possible padding: +*/ +if (xdr->end - xdr->p <3 )return nfserr_resource; + + nfserr =nfsd_splice_read (read->rd_rqstp, file, + read->rd_offset, &maxcount); +if (nfserr) { +/* +* nfsd_splice_actor may have already messed with the +* page length; reset it so as not to confuse +* xdr_truncate_encode: +*/ + xdr->buf->page_len =0 ; +return nfserr; } -/* Make sure there will be room for padding if needed: */ -if (xdr->end - xdr->p <1 ) -return nfserr_resource; + eof = (read->rd_offset + maxcount >= + read->rd_fhp->fh_dentry->d_inode->i_size); -if (resp->xdr.buf->page_len) { -WARN_ON_ONCE (resp->rqstp->rq_splice_ok); -return nfserr_resource; + tmp =htonl (eof); +write_bytes_to_xdr_buf (xdr->buf, starting_len , &tmp,4 ); + tmp =htonl (maxcount); +write_bytes_to_xdr_buf (xdr->buf, starting_len +4 , &tmp,4 ); + + resp->xdr.buf->page_len = maxcount; + xdr->buf->len += maxcount; + xdr->page_ptr += (maxcount +PAGE_SIZE -1 ) /PAGE_SIZE ; + xdr->iov = xdr->buf->tail; + +/* Use rest of head for padding and remaining ops: */ + resp->xdr.buf->tail[0 ].iov_base = xdr->p; + resp->xdr.buf->tail[0 ].iov_len =0 ; +if (maxcount&3 ) { + p =xdr_reserve_space (xdr,4 ); +WRITE32 (0 ); + resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; + resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); + xdr->buf->len -= (maxcount&3 ); } - maxcount =svc_max_payload (resp->rqstp); -if (maxcount > read->rd_length) - maxcount = read->rd_length; + space_left =min_t (int, (void *)xdr->end - (void *)xdr->p, + xdr->buf->buflen - xdr->buf->len); + xdr->buf->buflen = xdr->buf->len + space_left; + xdr->end = (__be32 *)((void *)xdr->end + space_left); + +return 0 ; +} + +static __be32 nfsd4_encode_readv (struct nfsd4_compoundres *resp, +struct nfsd4_read *read, +struct file *file,unsigned long maxcount) +{ +struct xdr_stream *xdr = &resp->xdr; +u32 eof; +int v; +struct page *page; +int starting_len = xdr->buf->len -8 ; +int space_left; +long len; +__be32 nfserr; +__be32 tmp; +__be32 *p; len = maxcount; v =0 ;
@@ -3124,34 +3167,26 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, } read->rd_vlen = v; - nfserr =nfsd_read_file (read->rd_rqstp, read->rd_fhp, read->rd_filp, - read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen, - &maxcount); - -if (nfserr) { -/* -* nfsd_splice_actor may have already messed with the -* page length; reset it so as not to confuse -* xdr_truncate_encode: -*/ - xdr->buf->page_len =0 ; -xdr_truncate_encode (xdr, starting_len); + nfserr =nfsd_readv (file, read->rd_offset, resp->rqstp->rq_vec, + read->rd_vlen, &maxcount); +if (nfserr)return nfserr; - } + eof = (read->rd_offset + maxcount >= read->rd_fhp->fh_dentry->d_inode->i_size); -WRITE32 (eof); -WRITE32 (maxcount); -WARN_ON_ONCE (resp->xdr.buf->head[0 ].iov_len != (char *)p - - (char *)resp->xdr.buf->head[0 ].iov_base); + tmp =htonl (eof); +write_bytes_to_xdr_buf (xdr->buf, starting_len , &tmp,4 ); + tmp =htonl (maxcount); +write_bytes_to_xdr_buf (xdr->buf, starting_len +4 , &tmp,4 ); + resp->xdr.buf->page_len = maxcount; xdr->buf->len += maxcount; xdr->page_ptr += v; xdr->iov = xdr->buf->tail;/* Use rest of head for padding and remaining ops: */ - resp->xdr.buf->tail[0 ].iov_base = p; + resp->xdr.buf->tail[0 ].iov_base = xdr->p; resp->xdr.buf->tail[0 ].iov_len =0 ;if (maxcount&3 ) { p =xdr_reserve_space (xdr,4 );
@@ -3167,6 +3202,60 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, xdr->end = (__be32 *)((void *)xdr->end + space_left);return 0 ; + +} + +static __be32 +nfsd4_encode_read (struct nfsd4_compoundres *resp,__be32 nfserr, +struct nfsd4_read *read) +{ +unsigned long maxcount; +struct xdr_stream *xdr = &resp->xdr; +struct file *file = read->rd_filp; +int starting_len = xdr->buf->len; +struct raparms *ra; +__be32 *p; +__be32 err; + +if (nfserr) +return nfserr; + + p =xdr_reserve_space (xdr,8 );/* eof flag and byte count */ +if (!p) { +WARN_ON_ONCE (resp->rqstp->rq_splice_ok); +return nfserr_resource; + } + +if (resp->xdr.buf->page_len) { +WARN_ON_ONCE (resp->rqstp->rq_splice_ok); +return nfserr_resource; + } + +xdr_commit_encode (xdr); + + maxcount =svc_max_payload (resp->rqstp); +if (maxcount > read->rd_length) + maxcount = read->rd_length; + +if (!read->rd_filp) { + err =nfsd_get_tmp_read_open (resp->rqstp, read->rd_fhp, + &file, &ra); +if (err) + goto err_truncate; + } + +if (file->f_op->splice_read && resp->rqstp->rq_splice_ok) + err =nfsd4_encode_splice_read (resp, read, file, maxcount); +else + err =nfsd4_encode_readv (resp, read, file, maxcount); + +if (!read->rd_filp) +nfsd_put_tmp_read_open (file, ra); + +err_truncate: +if (err) +xdr_truncate_encode (xdr, starting_len); +return err; } static __be32
fs/nfsd/vfs.c +75 -46
157 lines not on this page · raw message
fs/nfsd/vfs.h +8 -0
@@ -70,6 +70,14 @@ __be32 nfsd_commit(struct svc_rqst *, struct svc_fh *,__be32 nfsd_open (struct svc_rqst *,struct svc_fh *,umode_t ,int ,struct file **);void nfsd_close (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 *); +int nfsd_splice_read (struct svc_rqst *, +struct file *,loff_t ,unsigned long *); +int nfsd_readv (struct file *,loff_t ,struct kvec *,int , +unsigned long *);__be32 nfsd_read (struct svc_rqst *,struct svc_fh *,loff_t ,struct kvec *,int ,unsigned long *); __be32 nfsd_read_file(struct svc_rqst *, struct svc_fh *, struct file *,
Signature · 1 line
1.9.0
PATCH 44/52 nfsd4: read encoding cleanup
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Trivial cleanup, no change in functionality.
--- fs/nfsd/nfs4xdr.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
fs/nfsd/nfs4xdr.c +14 -13
@@ -3075,6 +3075,7 @@ static __be32 nfsd4_encode_splice_read( struct file *file, unsigned long maxcount) {struct xdr_stream *xdr = &resp->xdr; +struct xdr_buf *buf = xdr->buf;u32 eof;int starting_len = xdr->buf->len -8 ;int space_left;
@@ -3097,7 +3098,7 @@ static __be32 nfsd4_encode_splice_read(* page length; reset it so as not to confuse * xdr_truncate_encode: */ - xdr->buf->page_len =0 ; + buf->page_len =0 ;return nfserr; }
@@ -3105,29 +3106,29 @@ static __be32 nfsd4_encode_splice_read( read->rd_fhp->fh_dentry->d_inode->i_size); tmp =htonl (eof); -write_bytes_to_xdr_buf (xdr->buf, starting_len , &tmp,4 ); +write_bytes_to_xdr_buf (buf, starting_len , &tmp,4 ); tmp =htonl (maxcount); -write_bytes_to_xdr_buf (xdr->buf, starting_len +4 , &tmp,4 ); +write_bytes_to_xdr_buf (buf, starting_len +4 , &tmp,4 ); - resp->xdr.buf->page_len = maxcount; - xdr->buf->len += maxcount; + buf->page_len = maxcount; + buf->len += maxcount; xdr->page_ptr += (maxcount +PAGE_SIZE -1 ) /PAGE_SIZE ; - xdr->iov = xdr->buf->tail; + xdr->iov = buf->tail;/* Use rest of head for padding and remaining ops: */ - resp->xdr.buf->tail[0 ].iov_base = xdr->p; - resp->xdr.buf->tail[0 ].iov_len =0 ; + buf->tail[0 ].iov_base = xdr->p; + buf->tail[0 ].iov_len =0 ;if (maxcount&3 ) { p =xdr_reserve_space (xdr,4 );WRITE32 (0 ); - resp->xdr.buf->tail[0 ].iov_base += maxcount&3 ; - resp->xdr.buf->tail[0 ].iov_len =4 - (maxcount&3 ); - xdr->buf->len -= (maxcount&3 ); + buf->tail[0 ].iov_base += maxcount&3 ; + buf->tail[0 ].iov_len =4 - (maxcount&3 ); + buf->len -= (maxcount&3 ); } space_left =min_t (int, (void *)xdr->end - (void *)xdr->p, - xdr->buf->buflen - xdr->buf->len); - xdr->buf->buflen = xdr->buf->len + space_left; + buf->buflen - buf->len); + buf->buflen = buf->len + space_left; xdr->end = (__be32 *)((void *)xdr->end + space_left);return 0 ;
Signature · 1 line
1.9.0
PATCH 45/52 nfsd4: more read encoding cleanup
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
More cleanup, no change in functionality.
--- fs/nfsd/nfs4xdr.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/nfsd/nfs4xdr.c +10 -12
@@ -3077,11 +3077,9 @@ static __be32 nfsd4_encode_splice_read(struct xdr_stream *xdr = &resp->xdr;struct xdr_buf *buf = xdr->buf;u32 eof; -int starting_len = xdr->buf->len -8 ;int space_left;__be32 nfserr; -__be32 tmp; -__be32 *p; +__be32 *p = xdr->p -2 ;/* * Don't inline pages unless we know there's room for eof,
@@ -3105,25 +3103,25 @@ static __be32 nfsd4_encode_splice_read( eof = (read->rd_offset + maxcount >= read->rd_fhp->fh_dentry->d_inode->i_size); - tmp =htonl (eof); -write_bytes_to_xdr_buf (buf, starting_len , &tmp,4 ); - tmp =htonl (maxcount); -write_bytes_to_xdr_buf (buf, starting_len +4 , &tmp,4 ); + *(p++) =htonl (eof); + *(p++) =htonl (maxcount); buf->page_len = maxcount; buf->len += maxcount; xdr->page_ptr += (maxcount +PAGE_SIZE -1 ) /PAGE_SIZE ; - xdr->iov = buf->tail;/* Use rest of head for padding and remaining ops: */ buf->tail[0 ].iov_base = xdr->p; buf->tail[0 ].iov_len =0 ; + xdr->iov = buf->tail;if (maxcount&3 ) { - p =xdr_reserve_space (xdr,4 ); -WRITE32 (0 ); +int pad =4 - (maxcount&3 ); + + *(xdr->p++) =0 ; + buf->tail[0 ].iov_base += maxcount&3 ; - buf->tail[0 ].iov_len =4 - (maxcount&3 ); - buf->len -= (maxcount&3 ); + buf->tail[0 ].iov_len = pad; + buf->len += pad; } space_left = min_t(int, (void *)xdr->end - (void *)xdr->p,
Signature · 1 line
1.9.0
PATCH 46/52 nfsd4: allow exotic read compounds
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
I'm not sure why a client would want to stuff multiple reads in a single compound rpc, but it's legal for them to do it, and we should really support it.
--- Documentation/filesystems/nfs/nfs41-server.txt | 2 - fs/nfsd/nfs4xdr.c | 55 +++++++++++--------------- 2 files changed, 23 insertions(+), 34 deletions(-)
Documentation/filesystems/nfs/nfs41-server.txt +0 -2
@@ -176,7 +176,5 @@ Nonstandard compound limitations: ca_maxrequestsize request and a ca_maxresponsesize reply, so we may fail to live up to the promise we made in CREATE_SESSION fore channel negotiation. -* No more than one read-like operation allowed per compound; encoding - replies that cross page boundaries (except for read data) not handled. See also http://wiki.linux-nfs.org/wiki/index.php/Server_4.0_and_4.1_issues.
fs/nfsd/nfs4xdr.c +23 -32
90 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 47/52 nfsd4: really fix nfs4err_resource in 4.1 case
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
encode_getattr, for example, can return nfserr_resource to indicate it ran out of buffer space. That's not a legal error in the 4.1 case. And in the 4.1 case, if we ran out of buffer space, we should have exceeded a session limit too.
(Note in 1bc49d83c37cfaf46be357757e592711e67f9809 "nfsd4: fix nfs4err_resource in 4.1 case" we originally tried fixing this error return before fixing the problem that we could error out while we still had lots of available space. The result was to trade one illegal error for another in those cases. We decided that was helpful, so reverted the change in fc208d026be0c7d60db9118583fc62f6ca97743d, and are only reinstating it now that we've elimited almost all of those cases.)
--- fs/nfsd/nfs4xdr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/nfsd/nfs4xdr.c +8 -0
@@ -3903,6 +3903,14 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) space_needed =COMPOUND_ERR_SLACK_SPACE ; op->status =nfsd4_check_resp_size (resp, space_needed); } +if (op->status == nfserr_resource &&nfsd4_has_session (&resp->cstate)) { +struct nfsd4_slot *slot = resp->cstate.slot; + +if (slot->sl_flags &NFSD4_SLOT_CACHETHIS ) + op->status = nfserr_rep_too_big_to_cache; +else + op->status = nfserr_rep_too_big; + }if (op->status == nfserr_resource || op->status == nfserr_rep_too_big || op->status == nfserr_rep_too_big_to_cache) {
Signature · 1 line
1.9.0
PATCH 48/52 nfsd4: kill WRITE32
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
These macros just obscure what's going on. Adopt the convention of the client-side code.
--- fs/nfsd/nfs4xdr.c | 306 +++++++++++++++++++++++++++--------------------------- 1 file changed, 154 insertions(+), 152 deletions(-)
fs/nfsd/nfs4xdr.c +154 -152
@@ -1683,7 +1683,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)DECODE_TAIL ; } -#define WRITE32 (n) *p++ = htonl(n)#define WRITE64 (n) do { \ *p++ = htonl((u32)((n) >> 32)); \ *p++ = htonl((u32)(n)); \
@@ -1774,7 +1773,7 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, p =xdr_reserve_space (xdr, strlen +4 );if (!p)return nfserr_resource; -WRITE32 (strlen); + *p++ =cpu_to_be32 (strlen);WRITEMEM (str, strlen); count++; }
@@ -1857,7 +1856,7 @@ static __be32 nfsd4_encode_path(struct xdr_stream *xdr, p =xdr_reserve_space (xdr,4 );if (!p) goto out_free; -WRITE32 (ncomponents); + *p++ =cpu_to_be32 (ncomponents);while (ncomponents) {struct dentry *dentry = components[ncomponents -1 ];
@@ -1870,7 +1869,7 @@ static __be32 nfsd4_encode_path(struct xdr_stream *xdr,spin_unlock (&dentry->d_lock); goto out_free; } -WRITE32 (len); + *p++ =cpu_to_be32 (len);WRITEMEM (dentry->d_name.name, len);dprintk ("/%s" , dentry->d_name.name);spin_unlock (&dentry->d_lock);
@@ -1919,7 +1918,7 @@ static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; -WRITE32 (fslocs->locations_count); + *p++ =cpu_to_be32 (fslocs->locations_count);for (i=0 ; i<fslocs->locations_count; i++) { status =nfsd4_encode_fs_location4 (xdr, &fslocs->locations[i]);if (status)
@@ -1973,8 +1972,8 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,* For now we use a 0 here to indicate the null translation; in * the future we may place a call to translation code here. */ -WRITE32 (0 );/* lfs */ -WRITE32 (0 );/* pi */ + *p++ =cpu_to_be32 (0 );/* lfs */ + *p++ =cpu_to_be32 (0 );/* pi */ p =xdr_encode_opaque (p, context, len);return 0 ; }
@@ -2123,23 +2122,23 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,16 );if (!p) goto out_resource; -WRITE32 (3 ); -WRITE32 (bmval0); -WRITE32 (bmval1); -WRITE32 (bmval2); + *p++ =cpu_to_be32 (3 ); + *p++ =cpu_to_be32 (bmval0); + *p++ =cpu_to_be32 (bmval1); + *p++ =cpu_to_be32 (bmval2); }else if (bmval1) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE32 (2 ); -WRITE32 (bmval0); -WRITE32 (bmval1); + *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (bmval0); + *p++ =cpu_to_be32 (bmval1); }else { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE32 (1 ); -WRITE32 (bmval0); + *p++ =cpu_to_be32 (1 ); + *p++ =cpu_to_be32 (bmval0); } attrlen_offset = xdr->buf->len;
@@ -2161,17 +2160,17 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE32 (2 ); -WRITE32 (word0); -WRITE32 (word1); + *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (word0); + *p++ =cpu_to_be32 (word1); }else { p =xdr_reserve_space (xdr,16 );if (!p) goto out_resource; -WRITE32 (3 ); -WRITE32 (word0); -WRITE32 (word1); -WRITE32 (word2); + *p++ =cpu_to_be32 (3 ); + *p++ =cpu_to_be32 (word0); + *p++ =cpu_to_be32 (word1); + *p++ =cpu_to_be32 (word2); } }if (bmval0 &FATTR4_WORD0_TYPE ) {
@@ -2183,16 +2182,17 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, status = nfserr_serverfault; goto out; } -WRITE32 (dummy); + *p++ =cpu_to_be32 (dummy); }if (bmval0 &FATTR4_WORD0_FH_EXPIRE_TYPE ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource;if (exp->ex_flags &NFSEXP_NOSUBTREECHECK ) -WRITE32 (NFS4_FH_PERSISTENT ); + *p++ =cpu_to_be32 (NFS4_FH_PERSISTENT );else -WRITE32 (NFS4_FH_PERSISTENT |NFS4_FH_VOL_RENAME ); + *p++ =cpu_to_be32 (NFS4_FH_PERSISTENT | +NFS4_FH_VOL_RENAME ); }if (bmval0 &FATTR4_WORD0_CHANGE ) { p =xdr_reserve_space (xdr,8 );
@@ -2210,19 +2210,19 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_SYMLINK_SUPPORT ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_NAMED_ATTR ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); }if (bmval0 &FATTR4_WORD0_FSID ) { p =xdr_reserve_space (xdr,16 );
@@ -2237,10 +2237,10 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,WRITE64 ((u64 )0 );break ;case FSIDSOURCE_DEV : -WRITE32 (0 ); -WRITE32 (MAJOR (stat.dev)); -WRITE32 (0 ); -WRITE32 (MINOR (stat.dev)); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (MAJOR (stat.dev)); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (MINOR (stat.dev));break ;case FSIDSOURCE_UUID :WRITEMEM (exp->ex_uuid,16 );
@@ -2251,19 +2251,19 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); }if (bmval0 &FATTR4_WORD0_LEASE_TIME ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (nn->nfsd4_lease); + *p++ =cpu_to_be32 (nn->nfsd4_lease); }if (bmval0 &FATTR4_WORD0_RDATTR_ERROR ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (rdattr_err); + *p++ =cpu_to_be32 (rdattr_err); }if (bmval0 &FATTR4_WORD0_ACL ) {struct nfs4_ace *ace;
@@ -2273,21 +2273,22 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,if (!p) goto out_resource; -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); goto out_acl; } p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (acl->naces); + *p++ =cpu_to_be32 (acl->naces);for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { p =xdr_reserve_space (xdr,4 *3 );if (!p) goto out_resource; -WRITE32 (ace->type); -WRITE32 (ace->flag); -WRITE32 (ace->access_mask &NFS4_ACE_MASK_ALL ); + *p++ =cpu_to_be32 (ace->type); + *p++ =cpu_to_be32 (ace->flag); + *p++ =cpu_to_be32 (ace->access_mask & +NFS4_ACE_MASK_ALL ); status =nfsd4_encode_aclname (xdr, rqstp, ace);if (status) goto out;
@@ -2298,38 +2299,38 @@ out_acl: p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (aclsupport ? + *p++ =cpu_to_be32 (aclsupport ?ACL4_SUPPORT_ALLOW_ACL |ACL4_SUPPORT_DENY_ACL :0 ); }if (bmval0 &FATTR4_WORD0_CANSETTIME ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_CASE_INSENSITIVE ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); }if (bmval0 &FATTR4_WORD0_CASE_PRESERVING ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_CHOWN_RESTRICTED ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_FILEHANDLE ) { p =xdr_reserve_space (xdr, fhp->fh_handle.fh_size +4 );if (!p) goto out_resource; -WRITE32 (fhp->fh_handle.fh_size); + *p++ =cpu_to_be32 (fhp->fh_handle.fh_size);WRITEMEM (&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size); }if (bmval0 &FATTR4_WORD0_FILEID ) {
@@ -2365,7 +2366,7 @@ out_acl: p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval0 &FATTR4_WORD0_MAXFILESIZE ) { p =xdr_reserve_space (xdr,8 );
@@ -2377,13 +2378,13 @@ out_acl: p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (255 ); + *p++ =cpu_to_be32 (255 ); }if (bmval0 &FATTR4_WORD0_MAXNAME ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (statfs.f_namelen); + *p++ =cpu_to_be32 (statfs.f_namelen); }if (bmval0 &FATTR4_WORD0_MAXREAD ) { p =xdr_reserve_space (xdr,8 );
@@ -2401,19 +2402,19 @@ out_acl: p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (stat.mode &S_IALLUGO ); + *p++ =cpu_to_be32 (stat.mode &S_IALLUGO ); }if (bmval1 &FATTR4_WORD1_NO_TRUNC ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (1 ); + *p++ =cpu_to_be32 (1 ); }if (bmval1 &FATTR4_WORD1_NUMLINKS ) { p =xdr_reserve_space (xdr,4 );if (!p) goto out_resource; -WRITE32 (stat.nlink); + *p++ =cpu_to_be32 (stat.nlink); }if (bmval1 &FATTR4_WORD1_OWNER ) { status =nfsd4_encode_user (xdr, rqstp, stat.uid);
@@ -2429,8 +2430,8 @@ out_acl: p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE32 ((u32 )MAJOR (stat.rdev)); -WRITE32 ((u32 )MINOR (stat.rdev)); + *p++ =cpu_to_be32 ((u32 )MAJOR (stat.rdev)); + *p++ =cpu_to_be32 ((u32 )MINOR (stat.rdev)); }if (bmval1 &FATTR4_WORD1_SPACE_AVAIL ) { p =xdr_reserve_space (xdr,8 );
@@ -2465,29 +2466,29 @@ out_acl:if (!p) goto out_resource;WRITE64 ((s64 )stat.atime.tv_sec); -WRITE32 (stat.atime.tv_nsec); + *p++ =cpu_to_be32 (stat.atime.tv_nsec); }if (bmval1 &FATTR4_WORD1_TIME_DELTA ) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE32 (0 ); -WRITE32 (1 ); -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (1 ); + *p++ =cpu_to_be32 (0 ); }if (bmval1 &FATTR4_WORD1_TIME_METADATA ) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource;WRITE64 ((s64 )stat.ctime.tv_sec); -WRITE32 (stat.ctime.tv_nsec); + *p++ =cpu_to_be32 (stat.ctime.tv_nsec); }if (bmval1 &FATTR4_WORD1_TIME_MODIFY ) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource;WRITE64 ((s64 )stat.mtime.tv_sec); -WRITE32 (stat.mtime.tv_nsec); + *p++ =cpu_to_be32 (stat.mtime.tv_nsec); }if (bmval1 &FATTR4_WORD1_MOUNTED_ON_FILEID ) { p =xdr_reserve_space (xdr,8 );
@@ -2512,10 +2513,10 @@ out_acl: p =xdr_reserve_space (xdr,16 );if (!p) goto out_resource; -WRITE32 (3 ); -WRITE32 (NFSD_SUPPATTR_EXCLCREAT_WORD0 ); -WRITE32 (NFSD_SUPPATTR_EXCLCREAT_WORD1 ); -WRITE32 (NFSD_SUPPATTR_EXCLCREAT_WORD2 ); + *p++ =cpu_to_be32 (3 ); + *p++ =cpu_to_be32 (NFSD_SUPPATTR_EXCLCREAT_WORD0 ); + *p++ =cpu_to_be32 (NFSD_SUPPATTR_EXCLCREAT_WORD1 ); + *p++ =cpu_to_be32 (NFSD_SUPPATTR_EXCLCREAT_WORD2 ); } attrlen =htonl (xdr->buf->len - attrlen_offset -4 );
@@ -2750,7 +2751,7 @@ nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) p =xdr_reserve_space (xdr,sizeof (stateid_t));if (!p)return nfserr_resource; -WRITE32 (sid->si_generation); + *p++ =cpu_to_be32 (sid->si_generation);WRITEMEM (&sid->si_opaque,sizeof (stateid_opaque_t));return 0 ; }
@@ -2765,8 +2766,8 @@ nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ p =xdr_reserve_space (xdr,8 );if (!p)return nfserr_resource; -WRITE32 (access->ac_supported); -WRITE32 (access->ac_resp_access); + *p++ =cpu_to_be32 (access->ac_supported); + *p++ =cpu_to_be32 (access->ac_resp_access); }return nfserr; }
@@ -2781,9 +2782,9 @@ static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp,if (!p)return nfserr_resource;WRITEMEM (bcts->sessionid.data,NFS4_MAX_SESSIONID_LEN ); -WRITE32 (bcts->dir); + *p++ =cpu_to_be32 (bcts->dir);/* Sorry, we do not yet support RDMA over 4.1: */ -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); }return nfserr; }
@@ -2826,9 +2827,9 @@ nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_if (!p)return nfserr_resource;write_cinfo (&p, &create->cr_cinfo); -WRITE32 (2 ); -WRITE32 (create->cr_bmval[0 ]); -WRITE32 (create->cr_bmval[1 ]); + *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (create->cr_bmval[0 ]); + *p++ =cpu_to_be32 (create->cr_bmval[1 ]); }return nfserr; }
@@ -2861,7 +2862,7 @@ nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh p =xdr_reserve_space (xdr, len +4 );if (!p)return nfserr_resource; -WRITE32 (len); + *p++ =cpu_to_be32 (len);WRITEMEM (&fhp->fh_handle.fh_base, len); }return nfserr;
@@ -2893,14 +2894,14 @@ again: }WRITE64 (ld->ld_start);WRITE64 (ld->ld_length); -WRITE32 (ld->ld_type); + *p++ =cpu_to_be32 (ld->ld_type);if (conf->len) {WRITEMEM (&ld->ld_clientid,8 ); -WRITE32 (conf->len); + *p++ =cpu_to_be32 (conf->len);WRITEMEM (conf->data, conf->len); }else {/* non - nfsv4 lock in conflict, no clientid nor owner */ WRITE64 ((u64 )0 );/* clientid */ -WRITE32 (0 );/* length of owner name */ + *p++ =cpu_to_be32 (0 );/* length of owner name */ }return nfserr_denied; }
@@ -2972,11 +2973,11 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_opif (!p)return nfserr_resource;write_cinfo (&p, &open->op_cinfo); -WRITE32 (open->op_rflags); -WRITE32 (2 ); -WRITE32 (open->op_bmval[0 ]); -WRITE32 (open->op_bmval[1 ]); -WRITE32 (open->op_delegate_type); + *p++ =cpu_to_be32 (open->op_rflags); + *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (open->op_bmval[0 ]); + *p++ =cpu_to_be32 (open->op_bmval[1 ]); + *p++ =cpu_to_be32 (open->op_delegate_type);switch (open->op_delegate_type) {case NFS4_OPEN_DELEGATE_NONE :
@@ -2988,15 +2989,15 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op p =xdr_reserve_space (xdr,20 );if (!p)return nfserr_resource; -WRITE32 (open->op_recall); + *p++ =cpu_to_be32 (open->op_recall);/* * TODO: ACE's in delegations */ -WRITE32 (NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE ); -WRITE32 (0 ); -WRITE32 (0 ); -WRITE32 (0 );/* XXX: is NULL principal ok? */ + *p++ =cpu_to_be32 (NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 );/* XXX: is NULL principal ok? */ break ;case NFS4_OPEN_DELEGATE_WRITE : nfserr =nfsd4_encode_stateid (xdr, &open->op_delegate_stateid);
@@ -3005,22 +3006,22 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op p =xdr_reserve_space (xdr,32 );if (!p)return nfserr_resource; -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 );/* * TODO: space_limit's in delegations */ -WRITE32 (NFS4_LIMIT_SIZE ); -WRITE32 (~(u32 )0 ); -WRITE32 (~(u32 )0 ); + *p++ =cpu_to_be32 (NFS4_LIMIT_SIZE ); + *p++ =cpu_to_be32 (~(u32 )0 ); + *p++ =cpu_to_be32 (~(u32 )0 );/* * TODO: ACE's in delegations */ -WRITE32 (NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE ); -WRITE32 (0 ); -WRITE32 (0 ); -WRITE32 (0 );/* XXX: is NULL principal ok? */ + *p++ =cpu_to_be32 (NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 );/* XXX: is NULL principal ok? */ break ;case NFS4_OPEN_DELEGATE_NONE_EXT :/* 4.1 */ switch (open->op_why_no_deleg) {
@@ -3029,14 +3030,15 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op p =xdr_reserve_space (xdr,8 );if (!p)return nfserr_resource; -WRITE32 (open->op_why_no_deleg); -WRITE32 (0 );/* deleg signaling not supported yet */ + *p++ =cpu_to_be32 (open->op_why_no_deleg); +/* deleg signaling not supported yet: */ + *p++ =cpu_to_be32 (0 );break ;default : p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; -WRITE32 (open->op_why_no_deleg); + *p++ =cpu_to_be32 (open->op_why_no_deleg); }break ;default :
@@ -3312,8 +3314,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4return nfserr_resource;/* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ -WRITE32 (0 ); -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); resp->xdr.buf->head[0 ].iov_len = ((char *)resp->xdr.p) - (char *)resp->xdr.buf->head[0 ].iov_base;
@@ -3462,17 +3464,17 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, XDR_LEN(info.oid.len) + 4 + 4);if (!p) goto out; -WRITE32 (RPC_AUTH_GSS ); -WRITE32 (info.oid.len); + *p++ =cpu_to_be32 (RPC_AUTH_GSS ); + *p++ =cpu_to_be32 (info.oid.len);WRITEMEM (info.oid.data, info.oid.len); -WRITE32 (info.qop); -WRITE32 (info.service); + *p++ =cpu_to_be32 (info.qop); + *p++ =cpu_to_be32 (info.service); }else if (pf <RPC_AUTH_MAXFLAVOR ) { supported++; p =xdr_reserve_space (xdr,4 );if (!p) goto out; -WRITE32 (pf); + *p++ =cpu_to_be32 (pf); }else {if (report) pr_warn("NFS: SECINFO: security flavor %u "
@@ -3522,16 +3524,16 @@ nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4if (!p)return nfserr_resource;if (nfserr) { -WRITE32 (3 ); -WRITE32 (0 ); -WRITE32 (0 ); -WRITE32 (0 ); + *p++ =cpu_to_be32 (3 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); }else { -WRITE32 (3 ); -WRITE32 (setattr->sa_bmval[0 ]); -WRITE32 (setattr->sa_bmval[1 ]); -WRITE32 (setattr->sa_bmval[2 ]); + *p++ =cpu_to_be32 (3 ); + *p++ =cpu_to_be32 (setattr->sa_bmval[0 ]); + *p++ =cpu_to_be32 (setattr->sa_bmval[1 ]); + *p++ =cpu_to_be32 (setattr->sa_bmval[2 ]); }return nfserr; }
@@ -3553,8 +3555,8 @@ nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct n p =xdr_reserve_space (xdr,8 );if (!p)return nfserr_resource; -WRITE32 (0 ); -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 ); + *p++ =cpu_to_be32 (0 ); }return nfserr; }
@@ -3569,8 +3571,8 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_w p =xdr_reserve_space (xdr,16 );if (!p)return nfserr_resource; -WRITE32 (write->wr_bytes_written); -WRITE32 (write->wr_how_written); + *p++ =cpu_to_be32 (write->wr_bytes_written); + *p++ =cpu_to_be32 (write->wr_how_written);WRITEMEM (write->wr_verifier.data,NFS4_VERIFIER_SIZE ); }return nfserr;
@@ -3613,10 +3615,10 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,return nfserr_resource;WRITEMEM (&exid->clientid,8 ); -WRITE32 (exid->seqid); -WRITE32 (exid->flags); + *p++ =cpu_to_be32 (exid->seqid); + *p++ =cpu_to_be32 (exid->flags); -WRITE32 (exid->spa_how); + *p++ =cpu_to_be32 (exid->spa_how);switch (exid->spa_how) {case SP4_NONE :
@@ -3628,11 +3630,11 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,return nfserr_resource;/* spo_must_enforce bitmap: */ -WRITE32 (2 ); -WRITE32 (nfs4_minimal_spo_must_enforce[0 ]); -WRITE32 (nfs4_minimal_spo_must_enforce[1 ]); + *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (nfs4_minimal_spo_must_enforce[0 ]); + *p++ =cpu_to_be32 (nfs4_minimal_spo_must_enforce[1 ]);/* empty spo_must_allow bitmap: */ -WRITE32 (0 ); + *p++ =cpu_to_be32 (0 );break ;default :
@@ -3652,15 +3654,15 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,/* The server_owner struct */ WRITE64 (minor_id);/* Minor id */ /* major id */ -WRITE32 (major_id_sz); + *p++ =cpu_to_be32 (major_id_sz);WRITEMEM (major_id, major_id_sz);/* Server scope */ -WRITE32 (server_scope_sz); + *p++ =cpu_to_be32 (server_scope_sz);WRITEMEM (server_scope, server_scope_sz);/* Implementation id */ -WRITE32 (0 );/* zero length nfs_impl_id4 array */ + *p++ =cpu_to_be32 (0 );/* zero length nfs_impl_id4 array */ return 0 ; }
@@ -3678,43 +3680,43 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,if (!p)return nfserr_resource;WRITEMEM (sess->sessionid.data,NFS4_MAX_SESSIONID_LEN ); -WRITE32 (sess->seqid); -WRITE32 (sess->flags); + *p++ =cpu_to_be32 (sess->seqid); + *p++ =cpu_to_be32 (sess->flags); p =xdr_reserve_space (xdr,28 );if (!p)return nfserr_resource; -WRITE32 (0 );/* headerpadsz */ -WRITE32 (sess->fore_channel.maxreq_sz); -WRITE32 (sess->fore_channel.maxresp_sz); -WRITE32 (sess->fore_channel.maxresp_cached); -WRITE32 (sess->fore_channel.maxops); -WRITE32 (sess->fore_channel.maxreqs); -WRITE32 (sess->fore_channel.nr_rdma_attrs); + *p++ =cpu_to_be32 (0 );/* headerpadsz */ + *p++ =cpu_to_be32 (sess->fore_channel.maxreq_sz); + *p++ =cpu_to_be32 (sess->fore_channel.maxresp_sz); + *p++ =cpu_to_be32 (sess->fore_channel.maxresp_cached); + *p++ =cpu_to_be32 (sess->fore_channel.maxops); + *p++ =cpu_to_be32 (sess->fore_channel.maxreqs); + *p++ =cpu_to_be32 (sess->fore_channel.nr_rdma_attrs);if (sess->fore_channel.nr_rdma_attrs) { p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; -WRITE32 (sess->fore_channel.rdma_attrs); + *p++ =cpu_to_be32 (sess->fore_channel.rdma_attrs); } p =xdr_reserve_space (xdr,28 );if (!p)return nfserr_resource; -WRITE32 (0 );/* headerpadsz */ -WRITE32 (sess->back_channel.maxreq_sz); -WRITE32 (sess->back_channel.maxresp_sz); -WRITE32 (sess->back_channel.maxresp_cached); -WRITE32 (sess->back_channel.maxops); -WRITE32 (sess->back_channel.maxreqs); -WRITE32 (sess->back_channel.nr_rdma_attrs); + *p++ =cpu_to_be32 (0 );/* headerpadsz */ + *p++ =cpu_to_be32 (sess->back_channel.maxreq_sz); + *p++ =cpu_to_be32 (sess->back_channel.maxresp_sz); + *p++ =cpu_to_be32 (sess->back_channel.maxresp_cached); + *p++ =cpu_to_be32 (sess->back_channel.maxops); + *p++ =cpu_to_be32 (sess->back_channel.maxreqs); + *p++ =cpu_to_be32 (sess->back_channel.nr_rdma_attrs);if (sess->back_channel.nr_rdma_attrs) { p =xdr_reserve_space (xdr,4 );if (!p)return nfserr_resource; -WRITE32 (sess->back_channel.rdma_attrs); + *p++ =cpu_to_be32 (sess->back_channel.rdma_attrs); }return 0 ; }
@@ -3733,12 +3735,12 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,if (!p)return nfserr_resource;WRITEMEM (seq->sessionid.data,NFS4_MAX_SESSIONID_LEN ); -WRITE32 (seq->seqid); -WRITE32 (seq->slotid); + *p++ =cpu_to_be32 (seq->seqid); + *p++ =cpu_to_be32 (seq->slotid);/* Note slotid's are numbered from zero: */ -WRITE32 (seq->maxslots -1 );/* sr_highest_slotid */ -WRITE32 (seq->maxslots -1 );/* sr_target_highest_slotid */ -WRITE32 (seq->status_flags); + *p++ =cpu_to_be32 (seq->maxslots -1 );/* sr_highest_slotid */ + *p++ =cpu_to_be32 (seq->maxslots -1 );/* sr_target_highest_slotid */ + *p++ =cpu_to_be32 (seq->status_flags); resp->cstate.data_offset = xdr->buf->len;/* DRC cache data pointer */ return 0 ;
@@ -3885,7 +3887,7 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)WARN_ON_ONCE (1 );return ; } -WRITE32 (op->opnum); + *p++ =cpu_to_be32 (op->opnum); post_err_offset = xdr->buf->len;if (op->opnum ==OP_ILLEGAL )
@@ -3958,7 +3960,7 @@ nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)WARN_ON_ONCE (1 );return ; } -WRITE32 (op->opnum); + *p++ =cpu_to_be32 (op->opnum); *p++ = rp->rp_status;/* already xdr'ed */ WRITEMEM (rp->rp_buf, rp->rp_buflen);
Signature · 1 line
1.9.0
PATCH 49/52 nfsd4: kill WRITE64
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4xdr.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-)
fs/nfsd/nfs4xdr.c +24 -28
@@ -1683,10 +1683,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)DECODE_TAIL ; } -#define WRITE64 (n) do { \ - *p++ = htonl((u32)((n) >> 32)); \ - *p++ = htonl((u32)(n)); \ -} while (0)#define WRITEMEM (ptr,nbytes) do { if (nbytes > 0) { \ *(p + XDR_QUADLEN(nbytes) -1) = 0; \ memcpy(p, ptr, nbytes); \
@@ -2204,7 +2200,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 (stat.size); + p =xdr_encode_hyper (p, stat.size); }if (bmval0 &FATTR4_WORD0_LINK_SUPPORT ) { p =xdr_reserve_space (xdr,4 );
@@ -2229,12 +2225,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,if (!p) goto out_resource;if (exp->ex_fslocs.migrated) { -WRITE64 (NFS4_REFERRAL_FSID_MAJOR ); -WRITE64 (NFS4_REFERRAL_FSID_MINOR ); + p =xdr_encode_hyper (p,NFS4_REFERRAL_FSID_MAJOR ); + p =xdr_encode_hyper (p,NFS4_REFERRAL_FSID_MINOR ); }else switch (fsid_source (fhp)) {case FSIDSOURCE_FSID : -WRITE64 ((u64 )exp->ex_fsid); -WRITE64 ((u64 )0 ); + p =xdr_encode_hyper (p, (u64 )exp->ex_fsid); + p =xdr_encode_hyper (p, (u64 )0 );break ;case FSIDSOURCE_DEV : *p++ =cpu_to_be32 (0 );
@@ -2337,25 +2333,25 @@ out_acl: p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 (stat.ino); + p =xdr_encode_hyper (p, stat.ino); }if (bmval0 &FATTR4_WORD0_FILES_AVAIL ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 ((u64 ) statfs.f_ffree); + p =xdr_encode_hyper (p, (u64 ) statfs.f_ffree); }if (bmval0 &FATTR4_WORD0_FILES_FREE ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 ((u64 ) statfs.f_ffree); + p =xdr_encode_hyper (p, (u64 ) statfs.f_ffree); }if (bmval0 &FATTR4_WORD0_FILES_TOTAL ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 ((u64 ) statfs.f_files); + p =xdr_encode_hyper (p, (u64 ) statfs.f_files); }if (bmval0 &FATTR4_WORD0_FS_LOCATIONS ) { status =nfsd4_encode_fs_locations (xdr, rqstp, exp);
@@ -2372,7 +2368,7 @@ out_acl: p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 (exp->ex_path.mnt->mnt_sb->s_maxbytes); + p =xdr_encode_hyper (p, exp->ex_path.mnt->mnt_sb->s_maxbytes); }if (bmval0 &FATTR4_WORD0_MAXLINK ) { p =xdr_reserve_space (xdr,4 );
@@ -2390,13 +2386,13 @@ out_acl: p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 ((u64 )svc_max_payload (rqstp)); + p =xdr_encode_hyper (p, (u64 )svc_max_payload (rqstp)); }if (bmval0 &FATTR4_WORD0_MAXWRITE ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -WRITE64 ((u64 )svc_max_payload (rqstp)); + p =xdr_encode_hyper (p, (u64 )svc_max_payload (rqstp)); }if (bmval1 &FATTR4_WORD1_MODE ) { p =xdr_reserve_space (xdr,4 );
@@ -2438,34 +2434,34 @@ out_acl:if (!p) goto out_resource; dummy64 = (u64 )statfs.f_bavail * (u64 )statfs.f_bsize; -WRITE64 (dummy64); + p =xdr_encode_hyper (p, dummy64); }if (bmval1 &FATTR4_WORD1_SPACE_FREE ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; dummy64 = (u64 )statfs.f_bfree * (u64 )statfs.f_bsize; -WRITE64 (dummy64); + p =xdr_encode_hyper (p, dummy64); }if (bmval1 &FATTR4_WORD1_SPACE_TOTAL ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; dummy64 = (u64 )statfs.f_blocks * (u64 )statfs.f_bsize; -WRITE64 (dummy64); + p =xdr_encode_hyper (p, dummy64); }if (bmval1 &FATTR4_WORD1_SPACE_USED ) { p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; dummy64 = (u64 )stat.blocks <<9 ; -WRITE64 (dummy64); + p =xdr_encode_hyper (p, dummy64); }if (bmval1 &FATTR4_WORD1_TIME_ACCESS ) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE64 ((s64 )stat.atime.tv_sec); + p =xdr_encode_hyper (p, (s64 )stat.atime.tv_sec); *p++ =cpu_to_be32 (stat.atime.tv_nsec); }if (bmval1 &FATTR4_WORD1_TIME_DELTA ) {
@@ -2480,14 +2476,14 @@ out_acl: p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE64 ((s64 )stat.ctime.tv_sec); + p =xdr_encode_hyper (p, (s64 )stat.ctime.tv_sec); *p++ =cpu_to_be32 (stat.ctime.tv_nsec); }if (bmval1 &FATTR4_WORD1_TIME_MODIFY ) { p =xdr_reserve_space (xdr,12 );if (!p) goto out_resource; -WRITE64 ((s64 )stat.mtime.tv_sec); + p =xdr_encode_hyper (p, (s64 )stat.mtime.tv_sec); *p++ =cpu_to_be32 (stat.mtime.tv_nsec); }if (bmval1 &FATTR4_WORD1_MOUNTED_ON_FILEID ) {
@@ -2501,7 +2497,7 @@ out_acl:if (ignore_crossmnt ==0 && dentry == exp->ex_path.mnt->mnt_root)get_parent_attributes (exp, &stat); -WRITE64 (stat.ino); + p =xdr_encode_hyper (p, stat.ino); }if (bmval2 &FATTR4_WORD2_SECURITY_LABEL ) { status = nfsd4_encode_security_label(xdr, rqstp, context,
@@ -2892,15 +2888,15 @@ again: }return nfserr_resource; } -WRITE64 (ld->ld_start); -WRITE64 (ld->ld_length); + p =xdr_encode_hyper (p, ld->ld_start); + p =xdr_encode_hyper (p, ld->ld_length); *p++ =cpu_to_be32 (ld->ld_type);if (conf->len) {WRITEMEM (&ld->ld_clientid,8 ); *p++ =cpu_to_be32 (conf->len);WRITEMEM (conf->data, conf->len); }else {/* non - nfsv4 lock in conflict, no clientid nor owner */ -WRITE64 ((u64 )0 );/* clientid */ + p =xdr_encode_hyper (p, (u64 )0 );/* clientid */ *p++ =cpu_to_be32 (0 );/* length of owner name */ }return nfserr_denied;
@@ -3652,7 +3648,7 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,return nfserr_resource;/* The server_owner struct */ -WRITE64 (minor_id);/* Minor id */ + p =xdr_encode_hyper (p, minor_id);/* Minor id */ /* major id */ *p++ =cpu_to_be32 (major_id_sz);WRITEMEM (major_id, major_id_sz);
Signature · 1 line
1.9.0
PATCH 50/52 nfsd4: kill WRITEMEM
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
--- fs/nfsd/nfs4xdr.c | 62 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 34 deletions(-)
fs/nfsd/nfs4xdr.c +28 -34
@@ -1683,12 +1683,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)DECODE_TAIL ; } -#define WRITEMEM (ptr,nbytes) do { if (nbytes > 0) { \ - *(p + XDR_QUADLEN(nbytes) -1) = 0; \ - memcpy(p, ptr, nbytes); \ - p += XDR_QUADLEN(nbytes); \ -}} while (0) -static void write32 (__be32 **p,u32 n) { *(*p)++ =htonl (n);
@@ -1769,8 +1763,7 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, p =xdr_reserve_space (xdr, strlen +4 );if (!p)return nfserr_resource; - *p++ =cpu_to_be32 (strlen); -WRITEMEM (str, strlen); + p =xdr_encode_opaque (p, str, strlen); count++; }else
@@ -1865,8 +1858,7 @@ static __be32 nfsd4_encode_path(struct xdr_stream *xdr,spin_unlock (&dentry->d_lock); goto out_free; } - *p++ =cpu_to_be32 (len); -WRITEMEM (dentry->d_name.name, len); + p =xdr_encode_opaque (p, dentry->d_name.name, len);dprintk ("/%s" , dentry->d_name.name);spin_unlock (&dentry->d_lock);dput (dentry);
@@ -2239,7 +2231,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, *p++ =cpu_to_be32 (MINOR (stat.dev));break ;case FSIDSOURCE_UUID : -WRITEMEM (exp->ex_uuid,16 ); + p =xdr_encode_opaque_fixed (p, exp->ex_uuid,16 );break ; } }
@@ -2326,8 +2318,8 @@ out_acl: p =xdr_reserve_space (xdr, fhp->fh_handle.fh_size +4 );if (!p) goto out_resource; - *p++ =cpu_to_be32 (fhp->fh_handle.fh_size); -WRITEMEM (&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size); + p =xdr_encode_opaque (p, &fhp->fh_handle.fh_base, + fhp->fh_handle.fh_size); }if (bmval0 &FATTR4_WORD0_FILEID ) { p =xdr_reserve_space (xdr,8 );
@@ -2748,7 +2740,8 @@ nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid)if (!p)return nfserr_resource; *p++ =cpu_to_be32 (sid->si_generation); -WRITEMEM (&sid->si_opaque,sizeof (stateid_opaque_t)); + p =xdr_encode_opaque_fixed (p, &sid->si_opaque, +sizeof (stateid_opaque_t));return 0 ; }
@@ -2777,7 +2770,8 @@ static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, p =xdr_reserve_space (xdr,NFS4_MAX_SESSIONID_LEN +8 );if (!p)return nfserr_resource; -WRITEMEM (bcts->sessionid.data,NFS4_MAX_SESSIONID_LEN ); + p =xdr_encode_opaque_fixed (p, bcts->sessionid.data, +NFS4_MAX_SESSIONID_LEN ); *p++ =cpu_to_be32 (bcts->dir);/* Sorry, we do not yet support RDMA over 4.1: */ *p++ =cpu_to_be32 (0 );
@@ -2807,7 +2801,8 @@ nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ p =xdr_reserve_space (xdr,NFS4_VERIFIER_SIZE );if (!p)return nfserr_resource; -WRITEMEM (commit->co_verf.data,NFS4_VERIFIER_SIZE ); + p =xdr_encode_opaque_fixed (p, commit->co_verf.data, +NFS4_VERIFIER_SIZE ); }return nfserr; }
@@ -2858,8 +2853,7 @@ nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh p =xdr_reserve_space (xdr, len +4 );if (!p)return nfserr_resource; - *p++ =cpu_to_be32 (len); -WRITEMEM (&fhp->fh_handle.fh_base, len); + p =xdr_encode_opaque (p, &fhp->fh_handle.fh_base, len); }return nfserr; }
@@ -2892,9 +2886,8 @@ again: p =xdr_encode_hyper (p, ld->ld_length); *p++ =cpu_to_be32 (ld->ld_type);if (conf->len) { -WRITEMEM (&ld->ld_clientid,8 ); - *p++ =cpu_to_be32 (conf->len); -WRITEMEM (conf->data, conf->len); + p =xdr_encode_opaque_fixed (p, &ld->ld_clientid,8 ); + p =xdr_encode_opaque (p, conf->data, conf->len); }else {/* non - nfsv4 lock in conflict, no clientid nor owner */ p =xdr_encode_hyper (p, (u64 )0 );/* clientid */ *p++ =cpu_to_be32 (0 );/* length of owner name */
@@ -3461,8 +3454,7 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr,if (!p) goto out; *p++ =cpu_to_be32 (RPC_AUTH_GSS ); - *p++ =cpu_to_be32 (info.oid.len); -WRITEMEM (info.oid.data, info.oid.len); + p =xdr_encode_opaque (p, info.oid.data, info.oid.len); *p++ =cpu_to_be32 (info.qop); *p++ =cpu_to_be32 (info.service); }else if (pf <RPC_AUTH_MAXFLAVOR ) {
@@ -3544,8 +3536,9 @@ nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct n p =xdr_reserve_space (xdr,8 +NFS4_VERIFIER_SIZE );if (!p)return nfserr_resource; -WRITEMEM (&scd->se_clientid,8 ); -WRITEMEM (&scd->se_confirm,NFS4_VERIFIER_SIZE ); + p =xdr_encode_opaque_fixed (p, &scd->se_clientid,8 ); + p =xdr_encode_opaque_fixed (p, &scd->se_confirm, +NFS4_VERIFIER_SIZE ); }else if (nfserr == nfserr_clid_inuse) { p =xdr_reserve_space (xdr,8 );
@@ -3569,7 +3562,8 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_wreturn nfserr_resource; *p++ =cpu_to_be32 (write->wr_bytes_written); *p++ =cpu_to_be32 (write->wr_how_written); -WRITEMEM (write->wr_verifier.data,NFS4_VERIFIER_SIZE ); + p =xdr_encode_opaque_fixed (p, write->wr_verifier.data, +NFS4_VERIFIER_SIZE ); }return nfserr; }
@@ -3610,7 +3604,7 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,if (!p)return nfserr_resource; -WRITEMEM (&exid->clientid,8 ); + p =xdr_encode_opaque_fixed (p, &exid->clientid,8 ); *p++ =cpu_to_be32 (exid->seqid); *p++ =cpu_to_be32 (exid->flags);
@@ -3650,12 +3644,10 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,/* The server_owner struct */ p =xdr_encode_hyper (p, minor_id);/* Minor id */ /* major id */ - *p++ =cpu_to_be32 (major_id_sz); -WRITEMEM (major_id, major_id_sz); + p =xdr_encode_opaque (p, major_id, major_id_sz);/* Server scope */ - *p++ =cpu_to_be32 (server_scope_sz); -WRITEMEM (server_scope, server_scope_sz); + p =xdr_encode_opaque (p, server_scope, server_scope_sz);/* Implementation id */ *p++ =cpu_to_be32 (0 );/* zero length nfs_impl_id4 array */
@@ -3675,7 +3667,8 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, p =xdr_reserve_space (xdr,24 );if (!p)return nfserr_resource; -WRITEMEM (sess->sessionid.data,NFS4_MAX_SESSIONID_LEN ); + p =xdr_encode_opaque_fixed (p, sess->sessionid.data, +NFS4_MAX_SESSIONID_LEN ); *p++ =cpu_to_be32 (sess->seqid); *p++ =cpu_to_be32 (sess->flags);
@@ -3730,7 +3723,8 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, p =xdr_reserve_space (xdr,NFS4_MAX_SESSIONID_LEN +20 );if (!p)return nfserr_resource; -WRITEMEM (seq->sessionid.data,NFS4_MAX_SESSIONID_LEN ); + p =xdr_encode_opaque_fixed (p, seq->sessionid.data, +NFS4_MAX_SESSIONID_LEN ); *p++ =cpu_to_be32 (seq->seqid); *p++ =cpu_to_be32 (seq->slotid);/* Note slotid's are numbered from zero: */
@@ -3959,7 +3953,7 @@ nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) *p++ =cpu_to_be32 (op->opnum); *p++ = rp->rp_status;/* already xdr'ed */ -WRITEMEM (rp->rp_buf, rp->rp_buflen); + p =xdr_encode_opaque_fixed (p, rp->rp_buf, rp->rp_buflen); }int
Signature · 1 line
1.9.0
PATCH 51/52 nfsd4: kill write32, write64
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
And switch a couple other functions from the encode(&p,...) convention to the p = encode(p,...) convention mostly used elsewhere.
--- fs/nfsd/nfs4xdr.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-)
fs/nfsd/nfs4xdr.c +21 -30
@@ -1683,39 +1683,30 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)DECODE_TAIL ; } -static void write32 (__be32 **p,u32 n) -{ - *(*p)++ =htonl (n); -} - -static void write64 (__be32 **p,u64 n) -{ -write32 (p, (n >>32 )); -write32 (p, (u32 )n); -} - -static void write_change (__be32 **p,struct kstat *stat,struct inode *inode) +static __be32 *encode_change (__be32 *p,struct kstat *stat,struct inode *inode) {if (IS_I_VERSION (inode)) { -write64 (p, inode->i_version); + p =xdr_encode_hyper (p, inode->i_version); }else { -write32 (p, stat->ctime.tv_sec); -write32 (p, stat->ctime.tv_nsec); + *p++ =cpu_to_be32 (stat->ctime.tv_sec); + *p++ =cpu_to_be32 (stat->ctime.tv_nsec); } +return p; } -static void write_cinfo (__be32 **p,struct nfsd4_change_info *c) +static __be32 *encode_cinfo (__be32 *p,struct nfsd4_change_info *c) { -write32 (p, c->atomic); + *p++ =cpu_to_be32 (c->atomic);if (c->change_supported) { -write64 (p, c->before_change); -write64 (p, c->after_change); + p =xdr_encode_hyper (p, c->before_change); + p =xdr_encode_hyper (p, c->after_change); }else { -write32 (p, c->before_ctime_sec); -write32 (p, c->before_ctime_nsec); -write32 (p, c->after_ctime_sec); -write32 (p, c->after_ctime_nsec); + *p++ =cpu_to_be32 (c->before_ctime_sec); + *p++ =cpu_to_be32 (c->before_ctime_nsec); + *p++ =cpu_to_be32 (c->after_ctime_sec); + *p++ =cpu_to_be32 (c->after_ctime_nsec); } +return p; }/* Encode as an array of strings the string given with components
@@ -2186,7 +2177,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_reserve_space (xdr,8 );if (!p) goto out_resource; -write_change (&p, &stat, dentry->d_inode); + p =encode_change (p, &stat, dentry->d_inode); }if (bmval0 &FATTR4_WORD0_SIZE ) { p =xdr_reserve_space (xdr,8 );
@@ -2817,7 +2808,7 @@ nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ p =xdr_reserve_space (xdr,32 );if (!p)return nfserr_resource; -write_cinfo (&p, &create->cr_cinfo); + p =encode_cinfo (p, &create->cr_cinfo); *p++ =cpu_to_be32 (2 ); *p++ =cpu_to_be32 (create->cr_bmval[0 ]); *p++ =cpu_to_be32 (create->cr_bmval[1 ]);
@@ -2940,7 +2931,7 @@ nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_li p =xdr_reserve_space (xdr,20 );if (!p)return nfserr_resource; -write_cinfo (&p, &link->li_cinfo); + p =encode_cinfo (p, &link->li_cinfo); }return nfserr; }
@@ -2961,7 +2952,7 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op p =xdr_reserve_space (xdr,40 );if (!p)return nfserr_resource; -write_cinfo (&p, &open->op_cinfo); + p =encode_cinfo (p, &open->op_cinfo); *p++ =cpu_to_be32 (open->op_rflags); *p++ =cpu_to_be32 (2 ); *p++ =cpu_to_be32 (open->op_bmval[0 ]);
@@ -3383,7 +3374,7 @@ nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ p =xdr_reserve_space (xdr,20 );if (!p)return nfserr_resource; -write_cinfo (&p, &remove->rm_cinfo); + p =encode_cinfo (p, &remove->rm_cinfo); }return nfserr; }
@@ -3398,8 +3389,8 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ p =xdr_reserve_space (xdr,40 );if (!p)return nfserr_resource; -write_cinfo (&p, &rename->rn_sinfo); -write_cinfo (&p, &rename->rn_tinfo); + p =encode_cinfo (p, &rename->rn_sinfo); + p =encode_cinfo (p, &rename->rn_tinfo); }return nfserr; }
Signature · 1 line
1.9.0
PATCH 52/52 nfsd4: better reservation of head space for krb5
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
RPC_MAX_AUTH_SIZE is scattered around several places. Better to set it once in the auth code, where this kind of estimate should be made. And while we're at it we can leave it zero when we're not using krb5i or krb5p.
--- fs/nfsd/nfs4proc.c | 4 ++-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfs4xdr.c | 5 +++-- include/linux/sunrpc/svc.h | 11 +++++------ net/sunrpc/auth_gss/svcauth_gss.c | 2 ++ net/sunrpc/svcauth.c | 2 ++ 6 files changed, 15 insertions(+), 11 deletions(-)
fs/nfsd/nfs4proc.c +2 -2
@@ -1263,13 +1263,13 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, xdr->buf = buf; xdr->iov = head; xdr->p = head->iov_base + head->iov_len; - xdr->end = head->iov_base +PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ; + xdr->end = head->iov_base +PAGE_SIZE - rqstp->rq_auth_slack;/* Tail and page_len should be zero at this point: */ buf->len = buf->head[0 ].iov_len; xdr->scratch.iov_len =0 ; xdr->page_ptr = buf->pages; buf->buflen =PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) - -2 *RPC_MAX_AUTH_SIZE ; + - rqstp->rq_auth_slack; }/*
fs/nfsd/nfs4state.c +1 -1
@@ -2288,7 +2288,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, session->se_fchannel.maxresp_sz; status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : nfserr_rep_too_big; -if (xdr_restrict_buflen (xdr, buflen -2 *RPC_MAX_AUTH_SIZE )) +if (xdr_restrict_buflen (xdr, buflen - rqstp->rq_auth_slack)) goto out_put_session;svc_reserve (rqstp, buflen);
fs/nfsd/nfs4xdr.c +3 -2
@@ -1611,7 +1611,8 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)DECODE_HEAD ;struct nfsd4_op *op;bool cachethis = false; -int max_reply =2 *RPC_MAX_AUTH_SIZE +8 ;/* opcnt, status */ +int auth_slack= argp->rqstp->rq_auth_slack; +int max_reply = auth_slack +8 ;/* opcnt, status */ int readcount =0 ;int readbytes =0 ;int i;
@@ -1677,7 +1678,7 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)svc_reserve (argp->rqstp, max_reply + readbytes); argp->rqstp->rq_cachetype = cachethis ?RC_REPLBUFF :RC_NOCACHE ; -if (readcount >1 || max_reply >PAGE_SIZE -2 *RPC_MAX_AUTH_SIZE ) +if (readcount >1 || max_reply >PAGE_SIZE - auth_slack) argp->rqstp->rq_splice_ok = false;DECODE_TAIL ;
include/linux/sunrpc/svc.h +5 -6
@@ -259,7 +259,10 @@ struct svc_rqst {void * rq_argp;/* decoded arguments */ void * rq_resp;/* xdr'd results */ void * rq_auth_data;/* flavor-specific data */ - +int rq_auth_slack;/* extra space xdr code +* should leave in head +* for krb5i, krb5p. +*/ int rq_reserved;/* space on socket outq * reserved for this request */
@@ -455,11 +458,7 @@ char * svc_print_addr(struct svc_rqst *, char *, size_t);*/ static inline void svc_reserve_auth (struct svc_rqst *rqstp,int space) { -int added_space =0 ; - -if (rqstp->rq_authop->flavour) - added_space =RPC_MAX_AUTH_SIZE ; -svc_reserve (rqstp, space + added_space); +svc_reserve (rqstp, space + rqstp->rq_auth_slack); }#endif /* SUNRPC_SVC_H */
net/sunrpc/auth_gss/svcauth_gss.c +2 -0
@@ -1503,6 +1503,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)if (unwrap_integ_data (rqstp, &rqstp->rq_arg, gc->gc_seq, rsci->mechctx)) goto garbage_args; + rqstp->rq_auth_slack =RPC_MAX_AUTH_SIZE ;break ;case RPC_GSS_SVC_PRIVACY :/* placeholders for length and seq. number: */
@@ -1511,6 +1512,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)if (unwrap_priv_data (rqstp, &rqstp->rq_arg, gc->gc_seq, rsci->mechctx)) goto garbage_args; + rqstp->rq_auth_slack =RPC_MAX_AUTH_SIZE *2 ;break ;default : goto auth_err;
net/sunrpc/svcauth.c +2 -0
@@ -54,6 +54,8 @@ svc_authenticate(struct svc_rqst *rqstp, __be32 *authp) }spin_unlock (&authtab_lock); + rqstp->rq_auth_slack =0 ; + rqstp->rq_authop = aops;return aops->accept (rqstp, authp); }
Signature · 1 line
1.9.0