diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index e69aeb864a8d..7950a2ce0a27 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -608,6 +608,41 @@ static inline void svcxdr_encode_opaque_pages(struct svc_rqst *rqstp, xdr->page_ptr = rqstp->rq_next_page - 1; } +/** + * svcxdr_encode_opaque_payload - Encode a page-resident opaque data item + * @xdr: xdr_stream to be updated + * @len: number of octets of content in the data item + * + * Context: Process context. @xdr must have been initialized by + * svcxdr_init_encode() and still be positioned in the reply + * head. + * + * Return: + * %true: Success + * %false: The reply head cannot hold the length prefix and XDR + * padding, or the transport could not accommodate the result payload + */ +static inline bool svcxdr_encode_opaque_payload(struct xdr_stream *xdr, u32 len) +{ + struct svc_rqst *rqstp = svcxdr_rqst(xdr); + struct xdr_buf *buf = xdr->buf; + + /* + * The length prefix and any pad word must land in the reply + * head. A prefix that spills into the first Reply page lands + * on the payload itself, and xdr_write_pages() BUGs when the + * pad word does not fit. + */ + if ((xdr->end - xdr->p) * XDR_UNIT < XDR_UNIT + xdr_pad_size(len)) + return false; + if (xdr_stream_encode_u32(xdr, len) < 0) + return false; + svcxdr_encode_opaque_pages(rqstp, xdr, buf->pages, buf->page_base, len); + if (svc_encode_result_payload(rqstp, buf->head->iov_len, len) < 0) + return false; + return true; +} + /** * svcxdr_set_auth_slack - * @rqstp: RPC transaction