Commit 76ce4dce authored by Chuck Lever's avatar Chuck Lever

NFSD: Cap rsize_bop result based on send buffer size

Since before the git era, NFSD has conserved the number of pages
held by each nfsd thread by combining the RPC receive and send
buffers into a single array of pages. This works because there are
no cases where an operation needs a large RPC Call message and a
large RPC Reply at the same time.

Once an RPC Call has been received, svc_process() updates
svc_rqst::rq_res to describe the part of rq_pages that can be
used for constructing the Reply. This means that the send buffer
(rq_res) shrinks when the received RPC record containing the RPC
Call is large.

Add an NFSv4 helper that computes the size of the send buffer. It
replaces svc_max_payload() in spots where svc_max_payload() returns
a value that might be larger than the remaining send buffer space.
Callers who need to know the transport's actual maximum payload size
will continue to use svc_max_payload().
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 781fde1a
...@@ -2771,6 +2771,22 @@ nfsd4_proc_compound(struct svc_rqst *rqstp) ...@@ -2771,6 +2771,22 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
#define op_encode_channel_attrs_maxsz (6 + 1 + 1) #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
/*
* The _rsize() helpers are invoked by the NFSv4 COMPOUND decoder, which
* is called before sunrpc sets rq_res.buflen. Thus we have to compute
* the maximum payload size here, based on transport limits and the size
* of the remaining space in the rq_pages array.
*/
static u32 nfsd4_max_payload(const struct svc_rqst *rqstp)
{
u32 buflen;
buflen = (rqstp->rq_page_end - rqstp->rq_next_page) * PAGE_SIZE;
buflen -= rqstp->rq_auth_slack;
buflen -= rqstp->rq_res.head[0].iov_len;
return min_t(u32, buflen, svc_max_payload(rqstp));
}
static u32 nfsd4_only_status_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_only_status_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
...@@ -2816,9 +2832,9 @@ static u32 nfsd4_getattr_rsize(const struct svc_rqst *rqstp, ...@@ -2816,9 +2832,9 @@ static u32 nfsd4_getattr_rsize(const struct svc_rqst *rqstp,
u32 ret = 0; u32 ret = 0;
if (bmap0 & FATTR4_WORD0_ACL) if (bmap0 & FATTR4_WORD0_ACL)
return svc_max_payload(rqstp); return nfsd4_max_payload(rqstp);
if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
return svc_max_payload(rqstp); return nfsd4_max_payload(rqstp);
if (bmap1 & FATTR4_WORD1_OWNER) { if (bmap1 & FATTR4_WORD1_OWNER) {
ret += IDMAP_NAMESZ + 4; ret += IDMAP_NAMESZ + 4;
...@@ -2878,10 +2894,7 @@ static u32 nfsd4_open_rsize(const struct svc_rqst *rqstp, ...@@ -2878,10 +2894,7 @@ static u32 nfsd4_open_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_read_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_read_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount = 0, rlen = 0; u32 rlen = min(op->u.read.rd_length, nfsd4_max_payload(rqstp));
maxcount = svc_max_payload(rqstp);
rlen = min(op->u.read.rd_length, maxcount);
return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
} }
...@@ -2889,8 +2902,7 @@ static u32 nfsd4_read_rsize(const struct svc_rqst *rqstp, ...@@ -2889,8 +2902,7 @@ static u32 nfsd4_read_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_read_plus_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_read_plus_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount = svc_max_payload(rqstp); u32 rlen = min(op->u.read.rd_length, nfsd4_max_payload(rqstp));
u32 rlen = min(op->u.read.rd_length, maxcount);
/* /*
* If we detect that the file changed during hole encoding, then we * If we detect that the file changed during hole encoding, then we
* recover by encoding the remaining reply as data. This means we need * recover by encoding the remaining reply as data. This means we need
...@@ -2904,10 +2916,7 @@ static u32 nfsd4_read_plus_rsize(const struct svc_rqst *rqstp, ...@@ -2904,10 +2916,7 @@ static u32 nfsd4_read_plus_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_readdir_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_readdir_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount = 0, rlen = 0; u32 rlen = min(op->u.readdir.rd_maxcount, nfsd4_max_payload(rqstp));
maxcount = svc_max_payload(rqstp);
rlen = min(op->u.readdir.rd_maxcount, maxcount);
return (op_encode_hdr_size + op_encode_verifier_maxsz + return (op_encode_hdr_size + op_encode_verifier_maxsz +
XDR_QUADLEN(rlen)) * sizeof(__be32); XDR_QUADLEN(rlen)) * sizeof(__be32);
...@@ -3046,10 +3055,7 @@ static u32 nfsd4_copy_notify_rsize(const struct svc_rqst *rqstp, ...@@ -3046,10 +3055,7 @@ static u32 nfsd4_copy_notify_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_getdeviceinfo_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_getdeviceinfo_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount = 0, rlen = 0; u32 rlen = min(op->u.getdeviceinfo.gd_maxcount, nfsd4_max_payload(rqstp));
maxcount = svc_max_payload(rqstp);
rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount);
return (op_encode_hdr_size + return (op_encode_hdr_size +
1 /* gd_layout_type*/ + 1 /* gd_layout_type*/ +
...@@ -3099,10 +3105,7 @@ static u32 nfsd4_seek_rsize(const struct svc_rqst *rqstp, ...@@ -3099,10 +3105,7 @@ static u32 nfsd4_seek_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_getxattr_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_getxattr_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount, rlen; u32 rlen = min_t(u32, XATTR_SIZE_MAX, nfsd4_max_payload(rqstp));
maxcount = svc_max_payload(rqstp);
rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32); return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
} }
...@@ -3116,10 +3119,7 @@ static u32 nfsd4_setxattr_rsize(const struct svc_rqst *rqstp, ...@@ -3116,10 +3119,7 @@ static u32 nfsd4_setxattr_rsize(const struct svc_rqst *rqstp,
static u32 nfsd4_listxattrs_rsize(const struct svc_rqst *rqstp, static u32 nfsd4_listxattrs_rsize(const struct svc_rqst *rqstp,
const struct nfsd4_op *op) const struct nfsd4_op *op)
{ {
u32 maxcount, rlen; u32 rlen = min(op->u.listxattrs.lsxa_maxcount, nfsd4_max_payload(rqstp));
maxcount = svc_max_payload(rqstp);
rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32); return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
} }
......
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