diff options
author | J. Bruce Fields <bfields@redhat.com> | 2014-02-26 20:17:02 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2014-05-30 17:31:48 -0400 |
commit | 1fcea5b20b74cb856f5cd27161fea5329079dbd7 (patch) | |
tree | 3dfb58f4606307b84a72a3163cf726d01f04e363 | |
parent | 3e19ce762b537dd9aeefdd0849ba5f2f01ff83cf (diff) |
nfsd4: use xdr_truncate_encode
Now that lengths are reliable, we can use xdr_truncate instead of
open-coding it everywhere.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfs4xdr.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 57f60810b745..c2815f4849bf 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -2053,7 +2053,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, | |||
2053 | struct svc_fh *tempfh = NULL; | 2053 | struct svc_fh *tempfh = NULL; |
2054 | struct kstatfs statfs; | 2054 | struct kstatfs statfs; |
2055 | __be32 *p; | 2055 | __be32 *p; |
2056 | __be32 *start = xdr->p; | 2056 | int starting_len = xdr->buf->len; |
2057 | __be32 *attrlenp; | 2057 | __be32 *attrlenp; |
2058 | u32 dummy; | 2058 | u32 dummy; |
2059 | u64 dummy64; | 2059 | u64 dummy64; |
@@ -2547,13 +2547,8 @@ out: | |||
2547 | fh_put(tempfh); | 2547 | fh_put(tempfh); |
2548 | kfree(tempfh); | 2548 | kfree(tempfh); |
2549 | } | 2549 | } |
2550 | if (status) { | 2550 | if (status) |
2551 | int nbytes = (char *)xdr->p - (char *)start; | 2551 | xdr_truncate_encode(xdr, starting_len); |
2552 | /* open code what *should* be xdr_truncate(xdr, len); */ | ||
2553 | xdr->iov->iov_len -= nbytes; | ||
2554 | xdr->buf->len -= nbytes; | ||
2555 | xdr->p = start; | ||
2556 | } | ||
2557 | return status; | 2552 | return status; |
2558 | out_nfserr: | 2553 | out_nfserr: |
2559 | status = nfserrno(err); | 2554 | status = nfserrno(err); |
@@ -3008,6 +3003,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
3008 | struct page *page; | 3003 | struct page *page; |
3009 | unsigned long maxcount; | 3004 | unsigned long maxcount; |
3010 | struct xdr_stream *xdr = &resp->xdr; | 3005 | struct xdr_stream *xdr = &resp->xdr; |
3006 | int starting_len = xdr->buf->len; | ||
3011 | long len; | 3007 | long len; |
3012 | __be32 *p; | 3008 | __be32 *p; |
3013 | 3009 | ||
@@ -3044,9 +3040,13 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, | |||
3044 | &maxcount); | 3040 | &maxcount); |
3045 | 3041 | ||
3046 | if (nfserr) { | 3042 | if (nfserr) { |
3047 | xdr->p -= 2; | 3043 | /* |
3048 | xdr->iov->iov_len -= 8; | 3044 | * nfsd_splice_actor may have already messed with the |
3049 | xdr->buf->len -= 8; | 3045 | * page length; reset it so as not to confuse |
3046 | * xdr_truncate_encode: | ||
3047 | */ | ||
3048 | xdr->buf->page_len = 0; | ||
3049 | xdr_truncate_encode(xdr, starting_len); | ||
3050 | return nfserr; | 3050 | return nfserr; |
3051 | } | 3051 | } |
3052 | eof = (read->rd_offset + maxcount >= | 3052 | eof = (read->rd_offset + maxcount >= |
@@ -3079,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd | |||
3079 | int maxcount; | 3079 | int maxcount; |
3080 | struct xdr_stream *xdr = &resp->xdr; | 3080 | struct xdr_stream *xdr = &resp->xdr; |
3081 | char *page; | 3081 | char *page; |
3082 | int length_offset = xdr->buf->len; | ||
3082 | __be32 *p; | 3083 | __be32 *p; |
3083 | 3084 | ||
3084 | if (nfserr) | 3085 | if (nfserr) |
@@ -3103,9 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd | |||
3103 | if (nfserr == nfserr_isdir) | 3104 | if (nfserr == nfserr_isdir) |
3104 | nfserr = nfserr_inval; | 3105 | nfserr = nfserr_inval; |
3105 | if (nfserr) { | 3106 | if (nfserr) { |
3106 | xdr->p--; | 3107 | xdr_truncate_encode(xdr, length_offset); |
3107 | xdr->iov->iov_len -= 4; | ||
3108 | xdr->buf->len -= 4; | ||
3109 | return nfserr; | 3108 | return nfserr; |
3110 | } | 3109 | } |
3111 | 3110 | ||
@@ -3134,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 | |||
3134 | int maxcount; | 3133 | int maxcount; |
3135 | loff_t offset; | 3134 | loff_t offset; |
3136 | struct xdr_stream *xdr = &resp->xdr; | 3135 | struct xdr_stream *xdr = &resp->xdr; |
3137 | __be32 *page, *savep, *tailbase; | 3136 | int starting_len = xdr->buf->len; |
3137 | __be32 *page, *tailbase; | ||
3138 | __be32 *p; | 3138 | __be32 *p; |
3139 | 3139 | ||
3140 | if (nfserr) | 3140 | if (nfserr) |
@@ -3145,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 | |||
3145 | return nfserr_resource; | 3145 | return nfserr_resource; |
3146 | 3146 | ||
3147 | RESERVE_SPACE(NFS4_VERIFIER_SIZE); | 3147 | RESERVE_SPACE(NFS4_VERIFIER_SIZE); |
3148 | savep = p; | ||
3149 | 3148 | ||
3150 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ | 3149 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
3151 | WRITE32(0); | 3150 | WRITE32(0); |
@@ -3207,10 +3206,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 | |||
3207 | 3206 | ||
3208 | return 0; | 3207 | return 0; |
3209 | err_no_verf: | 3208 | err_no_verf: |
3210 | xdr->p = savep; | 3209 | xdr_truncate_encode(xdr, starting_len); |
3211 | xdr->iov->iov_len = ((char *)resp->xdr.p) | ||
3212 | - (char *)resp->xdr.buf->head[0].iov_base; | ||
3213 | xdr->buf->len = xdr->iov->iov_len; | ||
3214 | return nfserr; | 3210 | return nfserr; |
3215 | } | 3211 | } |
3216 | 3212 | ||