Skip to content

Commit 1fcea5b

Browse files
author
J. Bruce Fields
committed
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>
1 parent 3e19ce7 commit 1fcea5b

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
20532053
struct svc_fh *tempfh = NULL;
20542054
struct kstatfs statfs;
20552055
__be32 *p;
2056-
__be32 *start = xdr->p;
2056+
int starting_len = xdr->buf->len;
20572057
__be32 *attrlenp;
20582058
u32 dummy;
20592059
u64 dummy64;
@@ -2547,13 +2547,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
25472547
fh_put(tempfh);
25482548
kfree(tempfh);
25492549
}
2550-
if (status) {
2551-
int nbytes = (char *)xdr->p - (char *)start;
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-
}
2550+
if (status)
2551+
xdr_truncate_encode(xdr, starting_len);
25572552
return status;
25582553
out_nfserr:
25592554
status = nfserrno(err);
@@ -3008,6 +3003,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
30083003
struct page *page;
30093004
unsigned long maxcount;
30103005
struct xdr_stream *xdr = &resp->xdr;
3006+
int starting_len = xdr->buf->len;
30113007
long len;
30123008
__be32 *p;
30133009

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

30463042
if (nfserr) {
3047-
xdr->p -= 2;
3048-
xdr->iov->iov_len -= 8;
3049-
xdr->buf->len -= 8;
3043+
/*
3044+
* nfsd_splice_actor may have already messed with the
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);
30503050
return nfserr;
30513051
}
30523052
eof = (read->rd_offset + maxcount >=
@@ -3079,6 +3079,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
30793079
int maxcount;
30803080
struct xdr_stream *xdr = &resp->xdr;
30813081
char *page;
3082+
int length_offset = xdr->buf->len;
30823083
__be32 *p;
30833084

30843085
if (nfserr)
@@ -3103,9 +3104,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
31033104
if (nfserr == nfserr_isdir)
31043105
nfserr = nfserr_inval;
31053106
if (nfserr) {
3106-
xdr->p--;
3107-
xdr->iov->iov_len -= 4;
3108-
xdr->buf->len -= 4;
3107+
xdr_truncate_encode(xdr, length_offset);
31093108
return nfserr;
31103109
}
31113110

@@ -3134,7 +3133,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
31343133
int maxcount;
31353134
loff_t offset;
31363135
struct xdr_stream *xdr = &resp->xdr;
3137-
__be32 *page, *savep, *tailbase;
3136+
int starting_len = xdr->buf->len;
3137+
__be32 *page, *tailbase;
31383138
__be32 *p;
31393139

31403140
if (nfserr)
@@ -3145,7 +3145,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
31453145
return nfserr_resource;
31463146

31473147
RESERVE_SPACE(NFS4_VERIFIER_SIZE);
3148-
savep = p;
31493148

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

32083207
return 0;
32093208
err_no_verf:
3210-
xdr->p = savep;
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;
3209+
xdr_truncate_encode(xdr, starting_len);
32143210
return nfserr;
32153211
}
32163212

0 commit comments

Comments
 (0)