Skip to content

Commit

Permalink
nfsd4: use xdr_truncate_encode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
J. Bruce Fields committed May 30, 2014
1 parent 3e19ce7 commit 1fcea5b
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions fs/nfsd/nfs4xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2547,13 +2547,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -3044,9 +3040,13 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
&maxcount);

if (nfserr) {
xdr->p -= 2;
xdr->iov->iov_len -= 8;
xdr->buf->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 >=
Expand Down Expand Up @@ -3079,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
int maxcount;
struct xdr_stream *xdr = &resp->xdr;
char *page;
int length_offset = xdr->buf->len;
__be32 *p;

if (nfserr)
Expand All @@ -3103,9 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
if (nfserr == nfserr_isdir)
nfserr = nfserr_inval;
if (nfserr) {
xdr->p--;
xdr->iov->iov_len -= 4;
xdr->buf->len -= 4;
xdr_truncate_encode(xdr, length_offset);
return nfserr;
}

Expand Down Expand Up @@ -3134,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
int 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)
Expand All @@ -3145,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
return nfserr_resource;

RESERVE_SPACE(NFS4_VERIFIER_SIZE);
savep = p;

/* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
WRITE32(0);
Expand Down Expand Up @@ -3207,10 +3206,7 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4

return 0;
err_no_verf:
xdr->p = savep;
xdr->iov->iov_len = ((char *)resp->xdr.p)
- (char *)resp->xdr.buf->head[0].iov_base;
xdr->buf->len = xdr->iov->iov_len;
xdr_truncate_encode(xdr, starting_len);
return nfserr;
}

Expand Down

0 comments on commit 1fcea5b

Please sign in to comment.