Skip to content

Commit 3059676

Browse files
author
J. Bruce Fields
committed
nfsd4: fix buflen calculation after read encoding
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. Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 89ff884 commit 3059676

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
30533053
unsigned long maxcount;
30543054
struct xdr_stream *xdr = &resp->xdr;
30553055
int starting_len = xdr->buf->len;
3056+
int space_left;
30563057
long len;
30573058
__be32 *p;
30583059

@@ -3117,7 +3118,6 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
31173118
resp->xdr.buf->page_len = maxcount;
31183119
xdr->buf->len += maxcount;
31193120
xdr->page_ptr += v;
3120-
xdr->buf->buflen = maxcount + PAGE_SIZE - 2 * RPC_MAX_AUTH_SIZE;
31213121
xdr->iov = xdr->buf->tail;
31223122

31233123
/* Use rest of head for padding and remaining ops: */
@@ -3130,6 +3130,12 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
31303130
resp->xdr.buf->tail[0].iov_len = 4 - (maxcount&3);
31313131
xdr->buf->len -= (maxcount&3);
31323132
}
3133+
3134+
space_left = min_t(int, (void *)xdr->end - (void *)xdr->p,
3135+
xdr->buf->buflen - xdr->buf->len);
3136+
xdr->buf->buflen = xdr->buf->len + space_left;
3137+
xdr->end = (__be32 *)((void *)xdr->end + space_left);
3138+
31333139
return 0;
31343140
}
31353141

0 commit comments

Comments
 (0)