Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf269551 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust
Browse files

SUNRPC: New xdr_streams XDR decoder API



Now that all client-side XDR decoder routines use xdr_streams, there
should be no need to support the legacy calling sequence [rpc_rqst *,
__be32 *, RPC res *] anywhere.  We can construct an xdr_stream in the
generic RPC code, instead of in each decoder function.

This is a refactoring change.  It should not cause different behavior.

Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Tested-by: default avatarJ. Bruce Fields <bfields@redhat.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 9f06c719
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -529,17 +529,16 @@ static int decode_nlm4_testrply(struct xdr_stream *xdr,
	return error;
}

static int nlm4_xdr_dec_testres(struct rpc_rqst *req, __be32 *p,
static int nlm4_xdr_dec_testres(struct rpc_rqst *req,
				struct xdr_stream *xdr,
				struct nlm_res *result)
{
	struct xdr_stream xdr;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_cookie(&xdr, &result->cookie);
	error = decode_cookie(xdr, &result->cookie);
	if (unlikely(error))
		goto out;
	error = decode_nlm4_testrply(&xdr, result);
	error = decode_nlm4_testrply(xdr, result);
out:
	return error;
}
@@ -550,17 +549,16 @@ static int nlm4_xdr_dec_testres(struct rpc_rqst *req, __be32 *p,
 *		nlm4_stat stat;
 *	};
 */
static int nlm4_xdr_dec_res(struct rpc_rqst *req, __be32 *p,
static int nlm4_xdr_dec_res(struct rpc_rqst *req,
			    struct xdr_stream *xdr,
			    struct nlm_res *result)
{
	struct xdr_stream xdr;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_cookie(&xdr, &result->cookie);
	error = decode_cookie(xdr, &result->cookie);
	if (unlikely(error))
		goto out;
	error = decode_nlm4_stat(&xdr, &result->status);
	error = decode_nlm4_stat(xdr, &result->status);
out:
	return error;
}
@@ -575,7 +573,7 @@ static int nlm4_xdr_dec_res(struct rpc_rqst *req, __be32 *p,
[NLMPROC_##proc] = {							\
	.p_proc      = NLMPROC_##proc,					\
	.p_encode    = (kxdreproc_t)nlm4_xdr_enc_##argtype,		\
	.p_decode    = (kxdrproc_t)nlm4_xdr_dec_##restype,		\
	.p_decode    = (kxdrdproc_t)nlm4_xdr_dec_##restype,		\
	.p_arglen    = NLM4_##argtype##_sz,				\
	.p_replen    = NLM4_##restype##_sz,				\
	.p_statidx   = NLMPROC_##proc,					\
+9 −11
Original line number Diff line number Diff line
@@ -527,17 +527,16 @@ static int decode_nlm_testrply(struct xdr_stream *xdr,
	return error;
}

static int nlm_xdr_dec_testres(struct rpc_rqst *req, __be32 *p,
static int nlm_xdr_dec_testres(struct rpc_rqst *req,
			       struct xdr_stream *xdr,
			       struct nlm_res *result)
{
	struct xdr_stream xdr;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_cookie(&xdr, &result->cookie);
	error = decode_cookie(xdr, &result->cookie);
	if (unlikely(error))
		goto out;
	error = decode_nlm_testrply(&xdr, result);
	error = decode_nlm_testrply(xdr, result);
out:
	return error;
}
@@ -548,17 +547,16 @@ static int nlm_xdr_dec_testres(struct rpc_rqst *req, __be32 *p,
 *		nlm_stat stat;
 *	};
 */
static int nlm_xdr_dec_res(struct rpc_rqst *req, __be32 *p,
static int nlm_xdr_dec_res(struct rpc_rqst *req,
			   struct xdr_stream *xdr,
			   struct nlm_res *result)
{
	struct xdr_stream xdr;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_cookie(&xdr, &result->cookie);
	error = decode_cookie(xdr, &result->cookie);
	if (unlikely(error))
		goto out;
	error = decode_nlm_stat(&xdr, &result->status);
	error = decode_nlm_stat(xdr, &result->status);
out:
	return error;
}
@@ -573,7 +571,7 @@ static int nlm_xdr_dec_res(struct rpc_rqst *req, __be32 *p,
[NLMPROC_##proc] = {							\
	.p_proc      = NLMPROC_##proc,					\
	.p_encode    = (kxdreproc_t)nlm_xdr_enc_##argtype,		\
	.p_decode    = (kxdrproc_t)nlm_xdr_dec_##restype,		\
	.p_decode    = (kxdrdproc_t)nlm_xdr_dec_##restype,		\
	.p_arglen    = NLM_##argtype##_sz,				\
	.p_replen    = NLM_##restype##_sz,				\
	.p_statidx   = NLMPROC_##proc,					\
+15 −15
Original line number Diff line number Diff line
@@ -472,35 +472,35 @@ static void nsm_xdr_enc_unmon(struct rpc_rqst *req, struct xdr_stream *xdr,
	encode_mon_id(xdr, argp);
}

static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p,
static int nsm_xdr_dec_stat_res(struct rpc_rqst *rqstp,
				struct xdr_stream *xdr,
				struct nsm_res *resp)
{
	struct xdr_stream xdr;
	__be32 *p;

	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
	p = xdr_inline_decode(&xdr, 4 + 4);
	p = xdr_inline_decode(xdr, 4 + 4);
	if (unlikely(p == NULL))
		return -EIO;
	resp->status = be32_to_cpup(p++);
	resp->state = be32_to_cpup(p);

	dprintk("lockd: xdr_dec_stat_res status %d state %d\n",
			resp->status, resp->state);
	dprintk("lockd: %s status %d state %d\n",
		__func__, resp->status, resp->state);
	return 0;
}

static int xdr_dec_stat(struct rpc_rqst *rqstp, __be32 *p,
static int nsm_xdr_dec_stat(struct rpc_rqst *rqstp,
			    struct xdr_stream *xdr,
			    struct nsm_res *resp)
{
	struct xdr_stream xdr;
	__be32 *p;

	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
	p = xdr_inline_decode(&xdr, 4);
	p = xdr_inline_decode(xdr, 4);
	if (unlikely(p == NULL))
		return -EIO;
	resp->state = be32_to_cpup(p);

	dprintk("lockd: xdr_dec_stat state %d\n", resp->state);
	dprintk("lockd: %s state %d\n", __func__, resp->state);
	return 0;
}

@@ -517,7 +517,7 @@ static struct rpc_procinfo nsm_procedures[] = {
[NSMPROC_MON] = {
		.p_proc		= NSMPROC_MON,
		.p_encode	= (kxdreproc_t)nsm_xdr_enc_mon,
		.p_decode	= (kxdrproc_t)xdr_dec_stat_res,
		.p_decode	= (kxdrdproc_t)nsm_xdr_dec_stat_res,
		.p_arglen	= SM_mon_sz,
		.p_replen	= SM_monres_sz,
		.p_statidx	= NSMPROC_MON,
@@ -526,7 +526,7 @@ static struct rpc_procinfo nsm_procedures[] = {
[NSMPROC_UNMON] = {
		.p_proc		= NSMPROC_UNMON,
		.p_encode	= (kxdreproc_t)nsm_xdr_enc_unmon,
		.p_decode	= (kxdrproc_t)xdr_dec_stat,
		.p_decode	= (kxdrdproc_t)nsm_xdr_dec_stat,
		.p_arglen	= SM_mon_id_sz,
		.p_replen	= SM_unmonres_sz,
		.p_statidx	= NSMPROC_UNMON,
+13 −17
Original line number Diff line number Diff line
@@ -340,18 +340,16 @@ static int decode_fhandle(struct xdr_stream *xdr, struct mountres *res)
	return 0;
}

static int mnt_dec_mountres(struct rpc_rqst *req, __be32 *p,
static int mnt_xdr_dec_mountres(struct rpc_rqst *req,
				struct xdr_stream *xdr,
				struct mountres *res)
{
	struct xdr_stream xdr;
	int status;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);

	status = decode_status(&xdr, res);
	status = decode_status(xdr, res);
	if (unlikely(status != 0 || res->errno != 0))
		return status;
	return decode_fhandle(&xdr, res);
	return decode_fhandle(xdr, res);
}

static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res)
@@ -434,30 +432,28 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)
	return 0;
}

static int mnt_dec_mountres3(struct rpc_rqst *req, __be32 *p,
static int mnt_xdr_dec_mountres3(struct rpc_rqst *req,
				 struct xdr_stream *xdr,
				 struct mountres *res)
{
	struct xdr_stream xdr;
	int status;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);

	status = decode_fhs_status(&xdr, res);
	status = decode_fhs_status(xdr, res);
	if (unlikely(status != 0 || res->errno != 0))
		return status;
	status = decode_fhandle3(&xdr, res);
	status = decode_fhandle3(xdr, res);
	if (unlikely(status != 0)) {
		res->errno = -EBADHANDLE;
		return 0;
	}
	return decode_auth_flavors(&xdr, res);
	return decode_auth_flavors(xdr, res);
}

static struct rpc_procinfo mnt_procedures[] = {
	[MOUNTPROC_MNT] = {
		.p_proc		= MOUNTPROC_MNT,
		.p_encode	= (kxdreproc_t)mnt_xdr_enc_dirpath,
		.p_decode	= (kxdrproc_t)mnt_dec_mountres,
		.p_decode	= (kxdrdproc_t)mnt_xdr_dec_mountres,
		.p_arglen	= MNT_enc_dirpath_sz,
		.p_replen	= MNT_dec_mountres_sz,
		.p_statidx	= MOUNTPROC_MNT,
@@ -476,7 +472,7 @@ static struct rpc_procinfo mnt3_procedures[] = {
	[MOUNTPROC3_MNT] = {
		.p_proc		= MOUNTPROC3_MNT,
		.p_encode	= (kxdreproc_t)mnt_xdr_enc_dirpath,
		.p_decode	= (kxdrproc_t)mnt_dec_mountres3,
		.p_decode	= (kxdrdproc_t)mnt_xdr_dec_mountres3,
		.p_arglen	= MNT_enc_dirpath_sz,
		.p_replen	= MNT_dec_mountres3_sz,
		.p_statidx	= MOUNTPROC3_MNT,
+24 −44
Original line number Diff line number Diff line
@@ -783,15 +783,13 @@ static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req,
 * "NFS: Network File System Protocol Specification".
 */

static int nfs2_xdr_dec_stat(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr,
			     void *__unused)
{
	struct xdr_stream xdr;
	enum nfs_stat status;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_stat(&xdr, &status);
	error = decode_stat(xdr, &status);
	if (unlikely(error))
		goto out;
	if (status != NFS_OK)
@@ -802,22 +800,16 @@ static int nfs2_xdr_dec_stat(struct rpc_rqst *req, __be32 *p,
	return nfs_stat_to_errno(status);
}

static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr,
				 struct nfs_fattr *result)
{
	struct xdr_stream xdr;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	return decode_attrstat(&xdr, result);
	return decode_attrstat(xdr, result);
}

static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr,
				 struct nfs_diropok *result)
{
	struct xdr_stream xdr;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	return decode_diropres(&xdr, result);
	return decode_diropres(xdr, result);
}

/*
@@ -830,20 +822,18 @@ static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, __be32 *p,
 *		void;
 *	};
 */
static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req, __be32 *p,
				    void *__unused)
static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req,
				    struct xdr_stream *xdr, void *__unused)
{
	struct xdr_stream xdr;
	enum nfs_stat status;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_stat(&xdr, &status);
	error = decode_stat(xdr, &status);
	if (unlikely(error))
		goto out;
	if (status != NFS_OK)
		goto out_default;
	error = decode_path(&xdr);
	error = decode_path(xdr);
out:
	return error;
out_default:
@@ -861,39 +851,33 @@ static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req, __be32 *p,
 *		void;
 *	};
 */
static int nfs2_xdr_dec_readres(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr,
				struct nfs_readres *result)
{
	struct xdr_stream xdr;
	enum nfs_stat status;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_stat(&xdr, &status);
	error = decode_stat(xdr, &status);
	if (unlikely(error))
		goto out;
	if (status != NFS_OK)
		goto out_default;
	error = decode_fattr(&xdr, result->fattr);
	error = decode_fattr(xdr, result->fattr);
	if (unlikely(error))
		goto out;
	error = decode_nfsdata(&xdr, result);
	error = decode_nfsdata(xdr, result);
out:
	return error;
out_default:
	return nfs_stat_to_errno(status);
}

static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr,
				 struct nfs_writeres *result)
{
	struct xdr_stream xdr;

	/* All NFSv2 writes are "file sync" writes */
	result->verf->committed = NFS_FILE_SYNC;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	return decode_attrstat(&xdr, result->fattr);
	return decode_attrstat(xdr, result->fattr);
}

/**
@@ -1008,20 +992,18 @@ static int decode_readdirok(struct xdr_stream *xdr)
	goto out;
}

static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req, __be32 *p,
				   void *__unused)
static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req,
				   struct xdr_stream *xdr, void *__unused)
{
	struct xdr_stream xdr;
	enum nfs_stat status;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_stat(&xdr, &status);
	error = decode_stat(xdr, &status);
	if (unlikely(error))
		goto out;
	if (status != NFS_OK)
		goto out_default;
	error = decode_readdirok(&xdr);
	error = decode_readdirok(xdr);
out:
	return error;
out_default:
@@ -1062,20 +1044,18 @@ static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result)
	return -EIO;
}

static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, __be32 *p,
static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
				  struct nfs2_fsstat *result)
{
	struct xdr_stream xdr;
	enum nfs_stat status;
	int error;

	xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
	error = decode_stat(&xdr, &status);
	error = decode_stat(xdr, &status);
	if (unlikely(error))
		goto out;
	if (status != NFS_OK)
		goto out_default;
	error = decode_info(&xdr, result);
	error = decode_info(xdr, result);
out:
	return error;
out_default:
@@ -1150,7 +1130,7 @@ int nfs_stat_to_errno(enum nfs_stat status)
[NFSPROC_##proc] = {							\
	.p_proc	    =  NFSPROC_##proc,					\
	.p_encode   =  (kxdreproc_t)nfs2_xdr_enc_##argtype,		\
	.p_decode   =  (kxdrproc_t)nfs2_xdr_dec_##restype,		\
	.p_decode   =  (kxdrdproc_t)nfs2_xdr_dec_##restype,		\
	.p_arglen   =  NFS_##argtype##_sz,				\
	.p_replen   =  NFS_##restype##_sz,				\
	.p_timer    =  timer,						\
Loading