Commit bddfdbcd authored by Chuck Lever's avatar Chuck Lever

NFSD: Extract the svcxdr_init_encode() helper

NFSD initializes an encode xdr_stream only after the RPC layer has
already inserted the RPC Reply header. Thus it behaves differently
than xdr_init_encode does, which assumes the passed-in xdr_buf is
entirely devoid of content.

nfs4proc.c has this server-side stream initialization helper, but
it is visible only to the NFSv4 code. Move this helper to a place
that can be accessed by NFSv2 and NFSv3 server XDR functions.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 0d02ec6b
...@@ -2262,25 +2262,6 @@ static bool need_wrongsec_check(struct svc_rqst *rqstp) ...@@ -2262,25 +2262,6 @@ static bool need_wrongsec_check(struct svc_rqst *rqstp)
return !(nextd->op_flags & OP_HANDLES_WRONGSEC); return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
} }
static void svcxdr_init_encode(struct svc_rqst *rqstp,
struct nfsd4_compoundres *resp)
{
struct xdr_stream *xdr = &resp->xdr;
struct xdr_buf *buf = &rqstp->rq_res;
struct kvec *head = buf->head;
xdr->buf = buf;
xdr->iov = head;
xdr->p = head->iov_base + head->iov_len;
xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
/* Tail and page_len should be zero at this point: */
buf->len = buf->head[0].iov_len;
xdr_reset_scratch_buffer(xdr);
xdr->page_ptr = buf->pages - 1;
buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
- rqstp->rq_auth_slack;
}
#ifdef CONFIG_NFSD_V4_2_INTER_SSC #ifdef CONFIG_NFSD_V4_2_INTER_SSC
static void static void
check_if_stalefh_allowed(struct nfsd4_compoundargs *args) check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
...@@ -2335,10 +2316,14 @@ nfsd4_proc_compound(struct svc_rqst *rqstp) ...@@ -2335,10 +2316,14 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
__be32 status; __be32 status;
svcxdr_init_encode(rqstp, resp); resp->xdr = &rqstp->rq_res_stream;
resp->tagp = resp->xdr.p;
/* reserve space for: NFS status code */
xdr_reserve_space(resp->xdr, XDR_UNIT);
resp->tagp = resp->xdr->p;
/* reserve space for: taglen, tag, and opcnt */ /* reserve space for: taglen, tag, and opcnt */
xdr_reserve_space(&resp->xdr, 8 + args->taglen); xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
resp->taglen = args->taglen; resp->taglen = args->taglen;
resp->tag = args->tag; resp->tag = args->tag;
resp->rqstp = rqstp; resp->rqstp = rqstp;
...@@ -2444,7 +2429,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp) ...@@ -2444,7 +2429,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
encode_op: encode_op:
if (op->status == nfserr_replay_me) { if (op->status == nfserr_replay_me) {
op->replay = &cstate->replay_owner->so_replay; op->replay = &cstate->replay_owner->so_replay;
nfsd4_encode_replay(&resp->xdr, op); nfsd4_encode_replay(resp->xdr, op);
status = op->status = op->replay->rp_status; status = op->status = op->replay->rp_status;
} else { } else {
nfsd4_encode_operation(resp, op); nfsd4_encode_operation(resp, op);
......
...@@ -2903,7 +2903,7 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se, struct svc_r ...@@ -2903,7 +2903,7 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se, struct svc_r
static void static void
nfsd4_store_cache_entry(struct nfsd4_compoundres *resp) nfsd4_store_cache_entry(struct nfsd4_compoundres *resp)
{ {
struct xdr_buf *buf = resp->xdr.buf; struct xdr_buf *buf = resp->xdr->buf;
struct nfsd4_slot *slot = resp->cstate.slot; struct nfsd4_slot *slot = resp->cstate.slot;
unsigned int base; unsigned int base;
...@@ -2973,7 +2973,7 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp, ...@@ -2973,7 +2973,7 @@ nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,
struct nfsd4_sequence *seq) struct nfsd4_sequence *seq)
{ {
struct nfsd4_slot *slot = resp->cstate.slot; struct nfsd4_slot *slot = resp->cstate.slot;
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = resp->xdr;
__be32 *p; __be32 *p;
__be32 status; __be32 status;
...@@ -3708,7 +3708,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -3708,7 +3708,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
{ {
struct nfsd4_sequence *seq = &u->sequence; struct nfsd4_sequence *seq = &u->sequence;
struct nfsd4_compoundres *resp = rqstp->rq_resp; struct nfsd4_compoundres *resp = rqstp->rq_resp;
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = resp->xdr;
struct nfsd4_session *session; struct nfsd4_session *session;
struct nfs4_client *clp; struct nfs4_client *clp;
struct nfsd4_slot *slot; struct nfsd4_slot *slot;
......
This diff is collapsed.
...@@ -997,7 +997,7 @@ int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) ...@@ -997,7 +997,7 @@ int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
* NFSv4 does some encoding while processing * NFSv4 does some encoding while processing
*/ */
p = resv->iov_base + resv->iov_len; p = resv->iov_base + resv->iov_len;
resv->iov_len += sizeof(__be32); svcxdr_init_encode(rqstp);
*statp = proc->pc_func(rqstp); *statp = proc->pc_func(rqstp);
if (*statp == rpc_drop_reply || test_bit(RQ_DROPME, &rqstp->rq_flags)) if (*statp == rpc_drop_reply || test_bit(RQ_DROPME, &rqstp->rq_flags))
...@@ -1052,7 +1052,7 @@ int nfssvc_decode_voidarg(struct svc_rqst *rqstp, __be32 *p) ...@@ -1052,7 +1052,7 @@ int nfssvc_decode_voidarg(struct svc_rqst *rqstp, __be32 *p)
*/ */
int nfssvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p) int nfssvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p)
{ {
return xdr_ressize_check(rqstp, p); return 1;
} }
int nfsd_pool_stats_open(struct inode *inode, struct file *file) int nfsd_pool_stats_open(struct inode *inode, struct file *file)
......
...@@ -698,7 +698,7 @@ struct nfsd4_compoundargs { ...@@ -698,7 +698,7 @@ struct nfsd4_compoundargs {
struct nfsd4_compoundres { struct nfsd4_compoundres {
/* scratch variables for XDR encode */ /* scratch variables for XDR encode */
struct xdr_stream xdr; struct xdr_stream *xdr;
struct svc_rqst * rqstp; struct svc_rqst * rqstp;
u32 taglen; u32 taglen;
......
...@@ -248,6 +248,7 @@ struct svc_rqst { ...@@ -248,6 +248,7 @@ struct svc_rqst {
size_t rq_xprt_hlen; /* xprt header len */ size_t rq_xprt_hlen; /* xprt header len */
struct xdr_buf rq_arg; struct xdr_buf rq_arg;
struct xdr_stream rq_arg_stream; struct xdr_stream rq_arg_stream;
struct xdr_stream rq_res_stream;
struct page *rq_scratch_page; struct page *rq_scratch_page;
struct xdr_buf rq_res; struct xdr_buf rq_res;
struct page *rq_pages[RPCSVC_MAXPAGES + 1]; struct page *rq_pages[RPCSVC_MAXPAGES + 1];
...@@ -574,4 +575,28 @@ static inline void svcxdr_init_decode(struct svc_rqst *rqstp) ...@@ -574,4 +575,28 @@ static inline void svcxdr_init_decode(struct svc_rqst *rqstp)
xdr_set_scratch_page(xdr, rqstp->rq_scratch_page); xdr_set_scratch_page(xdr, rqstp->rq_scratch_page);
} }
/**
* svcxdr_init_encode - Prepare an xdr_stream for svc Reply encoding
* @rqstp: controlling server RPC transaction context
*
*/
static inline void svcxdr_init_encode(struct svc_rqst *rqstp)
{
struct xdr_stream *xdr = &rqstp->rq_res_stream;
struct xdr_buf *buf = &rqstp->rq_res;
struct kvec *resv = buf->head;
xdr_reset_scratch_buffer(xdr);
xdr->buf = buf;
xdr->iov = resv;
xdr->p = resv->iov_base + resv->iov_len;
xdr->end = resv->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
buf->len = resv->iov_len;
xdr->page_ptr = buf->pages - 1;
buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages);
buf->buflen -= rqstp->rq_auth_slack;
xdr->rqst = NULL;
}
#endif /* SUNRPC_SVC_H */ #endif /* SUNRPC_SVC_H */
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