Commit 1fcea5b2 authored by J. Bruce Fields's avatar J. Bruce Fields

nfsd4: use xdr_truncate_encode

Now that lengths are reliable, we can use xdr_truncate instead of
open-coding it everywhere.
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 3e19ce76
...@@ -2053,7 +2053,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, ...@@ -2053,7 +2053,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
struct svc_fh *tempfh = NULL; struct svc_fh *tempfh = NULL;
struct kstatfs statfs; struct kstatfs statfs;
__be32 *p; __be32 *p;
__be32 *start = xdr->p; int starting_len = xdr->buf->len;
__be32 *attrlenp; __be32 *attrlenp;
u32 dummy; u32 dummy;
u64 dummy64; u64 dummy64;
...@@ -2547,13 +2547,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, ...@@ -2547,13 +2547,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
fh_put(tempfh); fh_put(tempfh);
kfree(tempfh); kfree(tempfh);
} }
if (status) { if (status)
int nbytes = (char *)xdr->p - (char *)start; xdr_truncate_encode(xdr, starting_len);
/* open code what *should* be xdr_truncate(xdr, len); */
xdr->iov->iov_len -= nbytes;
xdr->buf->len -= nbytes;
xdr->p = start;
}
return status; return status;
out_nfserr: out_nfserr:
status = nfserrno(err); status = nfserrno(err);
...@@ -3008,6 +3003,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -3008,6 +3003,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
struct page *page; struct page *page;
unsigned long maxcount; unsigned long maxcount;
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = &resp->xdr;
int starting_len = xdr->buf->len;
long len; long len;
__be32 *p; __be32 *p;
...@@ -3044,9 +3040,13 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -3044,9 +3040,13 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
&maxcount); &maxcount);
if (nfserr) { if (nfserr) {
xdr->p -= 2; /*
xdr->iov->iov_len -= 8; * nfsd_splice_actor may have already messed with the
xdr->buf->len -= 8; * 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; return nfserr;
} }
eof = (read->rd_offset + maxcount >= eof = (read->rd_offset + maxcount >=
...@@ -3079,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd ...@@ -3079,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
int maxcount; int maxcount;
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = &resp->xdr;
char *page; char *page;
int length_offset = xdr->buf->len;
__be32 *p; __be32 *p;
if (nfserr) if (nfserr)
...@@ -3103,9 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd ...@@ -3103,9 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
if (nfserr == nfserr_isdir) if (nfserr == nfserr_isdir)
nfserr = nfserr_inval; nfserr = nfserr_inval;
if (nfserr) { if (nfserr) {
xdr->p--; xdr_truncate_encode(xdr, length_offset);
xdr->iov->iov_len -= 4;
xdr->buf->len -= 4;
return nfserr; return nfserr;
} }
...@@ -3134,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 ...@@ -3134,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
int maxcount; int maxcount;
loff_t offset; loff_t offset;
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = &resp->xdr;
__be32 *page, *savep, *tailbase; int starting_len = xdr->buf->len;
__be32 *page, *tailbase;
__be32 *p; __be32 *p;
if (nfserr) if (nfserr)
...@@ -3145,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 ...@@ -3145,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
return nfserr_resource; return nfserr_resource;
RESERVE_SPACE(NFS4_VERIFIER_SIZE); RESERVE_SPACE(NFS4_VERIFIER_SIZE);
savep = p;
/* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
WRITE32(0); WRITE32(0);
...@@ -3207,10 +3206,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 ...@@ -3207,10 +3206,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
return 0; return 0;
err_no_verf: err_no_verf:
xdr->p = savep; xdr_truncate_encode(xdr, starting_len);
xdr->iov->iov_len = ((char *)resp->xdr.p)
- (char *)resp->xdr.buf->head[0].iov_base;
xdr->buf->len = xdr->iov->iov_len;
return nfserr; return nfserr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment