aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2010-12-14 09:59:18 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-16 12:37:25 -0500
commit9f06c719f474be7003763284a990bed6377bb0d4 (patch)
tree409ebc3505f943bfdb933ab0acd76ffb5347b372 /net/sunrpc
parent1ac7c23e4af5e83525137661595000099f1ce94f (diff)
SUNRPC: New xdr_streams XDR encoder API
Now that all client-side XDR encoder routines use xdr_streams, there should be no need to support the legacy calling sequence [rpc_rqst *, __be32 *, RPC arg *] anywhere. We can construct an xdr_stream in the generic RPC code, instead of in each encoder function. Also, all the client-side encoder functions return 0 now, making a return value superfluous. Take this opportunity to convert them to return void instead. This is a refactoring change. It should not cause different behavior. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Tested-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/auth.c14
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c31
-rw-r--r--net/sunrpc/clnt.c5
-rw-r--r--net/sunrpc/rpcb_clnt.c47
4 files changed, 54 insertions, 43 deletions
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index afe67849269f..651c9da703cb 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -563,8 +563,17 @@ rpcauth_checkverf(struct rpc_task *task, __be32 *p)
563 return cred->cr_ops->crvalidate(task, p); 563 return cred->cr_ops->crvalidate(task, p);
564} 564}
565 565
566static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
567 __be32 *data, void *obj)
568{
569 struct xdr_stream xdr;
570
571 xdr_init_encode(&xdr, &rqstp->rq_snd_buf, data);
572 encode(rqstp, &xdr, obj);
573}
574
566int 575int
567rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp, 576rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp,
568 __be32 *data, void *obj) 577 __be32 *data, void *obj)
569{ 578{
570 struct rpc_cred *cred = task->tk_rqstp->rq_cred; 579 struct rpc_cred *cred = task->tk_rqstp->rq_cred;
@@ -574,7 +583,8 @@ rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp,
574 if (cred->cr_ops->crwrap_req) 583 if (cred->cr_ops->crwrap_req)
575 return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj); 584 return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj);
576 /* By default, we encode the arguments normally. */ 585 /* By default, we encode the arguments normally. */
577 return encode(rqstp, data, obj); 586 rpcauth_wrap_req_encode(encode, rqstp, data, obj);
587 return 0;
578} 588}
579 589
580int 590int
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 3835ce35e224..42b46f9a670a 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1231,9 +1231,19 @@ out_bad:
1231 return NULL; 1231 return NULL;
1232} 1232}
1233 1233
1234static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
1235 __be32 *p, void *obj)
1236{
1237 struct xdr_stream xdr;
1238
1239 xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p);
1240 encode(rqstp, &xdr, obj);
1241}
1242
1234static inline int 1243static inline int
1235gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1244gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1236 kxdrproc_t encode, struct rpc_rqst *rqstp, __be32 *p, void *obj) 1245 kxdreproc_t encode, struct rpc_rqst *rqstp,
1246 __be32 *p, void *obj)
1237{ 1247{
1238 struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 1248 struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
1239 struct xdr_buf integ_buf; 1249 struct xdr_buf integ_buf;
@@ -1249,9 +1259,7 @@ gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1249 offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 1259 offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
1250 *p++ = htonl(rqstp->rq_seqno); 1260 *p++ = htonl(rqstp->rq_seqno);
1251 1261
1252 status = encode(rqstp, p, obj); 1262 gss_wrap_req_encode(encode, rqstp, p, obj);
1253 if (status)
1254 return status;
1255 1263
1256 if (xdr_buf_subsegment(snd_buf, &integ_buf, 1264 if (xdr_buf_subsegment(snd_buf, &integ_buf,
1257 offset, snd_buf->len - offset)) 1265 offset, snd_buf->len - offset))
@@ -1325,7 +1333,8 @@ out:
1325 1333
1326static inline int 1334static inline int
1327gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, 1335gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1328 kxdrproc_t encode, struct rpc_rqst *rqstp, __be32 *p, void *obj) 1336 kxdreproc_t encode, struct rpc_rqst *rqstp,
1337 __be32 *p, void *obj)
1329{ 1338{
1330 struct xdr_buf *snd_buf = &rqstp->rq_snd_buf; 1339 struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
1331 u32 offset; 1340 u32 offset;
@@ -1342,9 +1351,7 @@ gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1342 offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base; 1351 offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
1343 *p++ = htonl(rqstp->rq_seqno); 1352 *p++ = htonl(rqstp->rq_seqno);
1344 1353
1345 status = encode(rqstp, p, obj); 1354 gss_wrap_req_encode(encode, rqstp, p, obj);
1346 if (status)
1347 return status;
1348 1355
1349 status = alloc_enc_pages(rqstp); 1356 status = alloc_enc_pages(rqstp);
1350 if (status) 1357 if (status)
@@ -1394,7 +1401,7 @@ gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1394 1401
1395static int 1402static int
1396gss_wrap_req(struct rpc_task *task, 1403gss_wrap_req(struct rpc_task *task,
1397 kxdrproc_t encode, void *rqstp, __be32 *p, void *obj) 1404 kxdreproc_t encode, void *rqstp, __be32 *p, void *obj)
1398{ 1405{
1399 struct rpc_cred *cred = task->tk_rqstp->rq_cred; 1406 struct rpc_cred *cred = task->tk_rqstp->rq_cred;
1400 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, 1407 struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
@@ -1407,12 +1414,14 @@ gss_wrap_req(struct rpc_task *task,
1407 /* The spec seems a little ambiguous here, but I think that not 1414 /* The spec seems a little ambiguous here, but I think that not
1408 * wrapping context destruction requests makes the most sense. 1415 * wrapping context destruction requests makes the most sense.
1409 */ 1416 */
1410 status = encode(rqstp, p, obj); 1417 gss_wrap_req_encode(encode, rqstp, p, obj);
1418 status = 0;
1411 goto out; 1419 goto out;
1412 } 1420 }
1413 switch (gss_cred->gc_service) { 1421 switch (gss_cred->gc_service) {
1414 case RPC_GSS_SVC_NONE: 1422 case RPC_GSS_SVC_NONE:
1415 status = encode(rqstp, p, obj); 1423 gss_wrap_req_encode(encode, rqstp, p, obj);
1424 status = 0;
1416 break; 1425 break;
1417 case RPC_GSS_SVC_INTEGRITY: 1426 case RPC_GSS_SVC_INTEGRITY:
1418 status = gss_wrap_req_integ(cred, ctx, encode, 1427 status = gss_wrap_req_integ(cred, ctx, encode,
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 92ce94f5146b..d446a32be667 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -1095,7 +1095,7 @@ static void
1095rpc_xdr_encode(struct rpc_task *task) 1095rpc_xdr_encode(struct rpc_task *task)
1096{ 1096{
1097 struct rpc_rqst *req = task->tk_rqstp; 1097 struct rpc_rqst *req = task->tk_rqstp;
1098 kxdrproc_t encode; 1098 kxdreproc_t encode;
1099 __be32 *p; 1099 __be32 *p;
1100 1100
1101 dprint_status(task); 1101 dprint_status(task);
@@ -1776,9 +1776,8 @@ out_overflow:
1776 goto out_garbage; 1776 goto out_garbage;
1777} 1777}
1778 1778
1779static int rpcproc_encode_null(void *rqstp, __be32 *data, void *obj) 1779static void rpcproc_encode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
1780{ 1780{
1781 return 0;
1782} 1781}
1783 1782
1784static int rpcproc_decode_null(void *rqstp, __be32 *data, void *obj) 1783static int rpcproc_decode_null(void *rqstp, __be32 *data, void *obj)
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 43838c72b778..63912a1a2983 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -689,25 +689,21 @@ static void rpcb_getport_done(struct rpc_task *child, void *data)
689 * XDR functions for rpcbind 689 * XDR functions for rpcbind
690 */ 690 */
691 691
692static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p, 692static void rpcb_enc_mapping(struct rpc_rqst *req, struct xdr_stream *xdr,
693 const struct rpcbind_args *rpcb) 693 const struct rpcbind_args *rpcb)
694{ 694{
695 struct rpc_task *task = req->rq_task; 695 struct rpc_task *task = req->rq_task;
696 struct xdr_stream xdr; 696 __be32 *p;
697 697
698 dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n", 698 dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n",
699 task->tk_pid, task->tk_msg.rpc_proc->p_name, 699 task->tk_pid, task->tk_msg.rpc_proc->p_name,
700 rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); 700 rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port);
701 701
702 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 702 p = xdr_reserve_space(xdr, RPCB_mappingargs_sz << 2);
703
704 p = xdr_reserve_space(&xdr, RPCB_mappingargs_sz << 2);
705 *p++ = cpu_to_be32(rpcb->r_prog); 703 *p++ = cpu_to_be32(rpcb->r_prog);
706 *p++ = cpu_to_be32(rpcb->r_vers); 704 *p++ = cpu_to_be32(rpcb->r_vers);
707 *p++ = cpu_to_be32(rpcb->r_prot); 705 *p++ = cpu_to_be32(rpcb->r_prot);
708 *p = cpu_to_be32(rpcb->r_port); 706 *p = cpu_to_be32(rpcb->r_port);
709
710 return 0;
711} 707}
712 708
713static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, 709static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p,
@@ -769,27 +765,24 @@ static void encode_rpcb_string(struct xdr_stream *xdr, const char *string,
769 xdr_encode_opaque(p, string, len); 765 xdr_encode_opaque(p, string, len);
770} 766}
771 767
772static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, 768static void rpcb_enc_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,
773 const struct rpcbind_args *rpcb) 769 const struct rpcbind_args *rpcb)
774{ 770{
775 struct rpc_task *task = req->rq_task; 771 struct rpc_task *task = req->rq_task;
776 struct xdr_stream xdr; 772 __be32 *p;
777 773
778 dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n", 774 dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n",
779 task->tk_pid, task->tk_msg.rpc_proc->p_name, 775 task->tk_pid, task->tk_msg.rpc_proc->p_name,
780 rpcb->r_prog, rpcb->r_vers, 776 rpcb->r_prog, rpcb->r_vers,
781 rpcb->r_netid, rpcb->r_addr); 777 rpcb->r_netid, rpcb->r_addr);
782 778
783 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 779 p = xdr_reserve_space(xdr, (RPCB_program_sz + RPCB_version_sz) << 2);
784
785 p = xdr_reserve_space(&xdr, (RPCB_program_sz + RPCB_version_sz) << 2);
786 *p++ = cpu_to_be32(rpcb->r_prog); 780 *p++ = cpu_to_be32(rpcb->r_prog);
787 *p = cpu_to_be32(rpcb->r_vers); 781 *p = cpu_to_be32(rpcb->r_vers);
788 782
789 encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN); 783 encode_rpcb_string(xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN);
790 encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN); 784 encode_rpcb_string(xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN);
791 encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN); 785 encode_rpcb_string(xdr, rpcb->r_owner, RPCB_MAXOWNERLEN);
792 return 0;
793} 786}
794 787
795static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, 788static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p,
@@ -849,7 +842,7 @@ out_fail:
849static struct rpc_procinfo rpcb_procedures2[] = { 842static struct rpc_procinfo rpcb_procedures2[] = {
850 [RPCBPROC_SET] = { 843 [RPCBPROC_SET] = {
851 .p_proc = RPCBPROC_SET, 844 .p_proc = RPCBPROC_SET,
852 .p_encode = (kxdrproc_t)rpcb_enc_mapping, 845 .p_encode = (kxdreproc_t)rpcb_enc_mapping,
853 .p_decode = (kxdrproc_t)rpcb_dec_set, 846 .p_decode = (kxdrproc_t)rpcb_dec_set,
854 .p_arglen = RPCB_mappingargs_sz, 847 .p_arglen = RPCB_mappingargs_sz,
855 .p_replen = RPCB_setres_sz, 848 .p_replen = RPCB_setres_sz,
@@ -859,7 +852,7 @@ static struct rpc_procinfo rpcb_procedures2[] = {
859 }, 852 },
860 [RPCBPROC_UNSET] = { 853 [RPCBPROC_UNSET] = {
861 .p_proc = RPCBPROC_UNSET, 854 .p_proc = RPCBPROC_UNSET,
862 .p_encode = (kxdrproc_t)rpcb_enc_mapping, 855 .p_encode = (kxdreproc_t)rpcb_enc_mapping,
863 .p_decode = (kxdrproc_t)rpcb_dec_set, 856 .p_decode = (kxdrproc_t)rpcb_dec_set,
864 .p_arglen = RPCB_mappingargs_sz, 857 .p_arglen = RPCB_mappingargs_sz,
865 .p_replen = RPCB_setres_sz, 858 .p_replen = RPCB_setres_sz,
@@ -869,7 +862,7 @@ static struct rpc_procinfo rpcb_procedures2[] = {
869 }, 862 },
870 [RPCBPROC_GETPORT] = { 863 [RPCBPROC_GETPORT] = {
871 .p_proc = RPCBPROC_GETPORT, 864 .p_proc = RPCBPROC_GETPORT,
872 .p_encode = (kxdrproc_t)rpcb_enc_mapping, 865 .p_encode = (kxdreproc_t)rpcb_enc_mapping,
873 .p_decode = (kxdrproc_t)rpcb_dec_getport, 866 .p_decode = (kxdrproc_t)rpcb_dec_getport,
874 .p_arglen = RPCB_mappingargs_sz, 867 .p_arglen = RPCB_mappingargs_sz,
875 .p_replen = RPCB_getportres_sz, 868 .p_replen = RPCB_getportres_sz,
@@ -882,7 +875,7 @@ static struct rpc_procinfo rpcb_procedures2[] = {
882static struct rpc_procinfo rpcb_procedures3[] = { 875static struct rpc_procinfo rpcb_procedures3[] = {
883 [RPCBPROC_SET] = { 876 [RPCBPROC_SET] = {
884 .p_proc = RPCBPROC_SET, 877 .p_proc = RPCBPROC_SET,
885 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 878 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
886 .p_decode = (kxdrproc_t)rpcb_dec_set, 879 .p_decode = (kxdrproc_t)rpcb_dec_set,
887 .p_arglen = RPCB_getaddrargs_sz, 880 .p_arglen = RPCB_getaddrargs_sz,
888 .p_replen = RPCB_setres_sz, 881 .p_replen = RPCB_setres_sz,
@@ -892,7 +885,7 @@ static struct rpc_procinfo rpcb_procedures3[] = {
892 }, 885 },
893 [RPCBPROC_UNSET] = { 886 [RPCBPROC_UNSET] = {
894 .p_proc = RPCBPROC_UNSET, 887 .p_proc = RPCBPROC_UNSET,
895 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 888 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
896 .p_decode = (kxdrproc_t)rpcb_dec_set, 889 .p_decode = (kxdrproc_t)rpcb_dec_set,
897 .p_arglen = RPCB_getaddrargs_sz, 890 .p_arglen = RPCB_getaddrargs_sz,
898 .p_replen = RPCB_setres_sz, 891 .p_replen = RPCB_setres_sz,
@@ -902,7 +895,7 @@ static struct rpc_procinfo rpcb_procedures3[] = {
902 }, 895 },
903 [RPCBPROC_GETADDR] = { 896 [RPCBPROC_GETADDR] = {
904 .p_proc = RPCBPROC_GETADDR, 897 .p_proc = RPCBPROC_GETADDR,
905 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 898 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
906 .p_decode = (kxdrproc_t)rpcb_dec_getaddr, 899 .p_decode = (kxdrproc_t)rpcb_dec_getaddr,
907 .p_arglen = RPCB_getaddrargs_sz, 900 .p_arglen = RPCB_getaddrargs_sz,
908 .p_replen = RPCB_getaddrres_sz, 901 .p_replen = RPCB_getaddrres_sz,
@@ -915,7 +908,7 @@ static struct rpc_procinfo rpcb_procedures3[] = {
915static struct rpc_procinfo rpcb_procedures4[] = { 908static struct rpc_procinfo rpcb_procedures4[] = {
916 [RPCBPROC_SET] = { 909 [RPCBPROC_SET] = {
917 .p_proc = RPCBPROC_SET, 910 .p_proc = RPCBPROC_SET,
918 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 911 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
919 .p_decode = (kxdrproc_t)rpcb_dec_set, 912 .p_decode = (kxdrproc_t)rpcb_dec_set,
920 .p_arglen = RPCB_getaddrargs_sz, 913 .p_arglen = RPCB_getaddrargs_sz,
921 .p_replen = RPCB_setres_sz, 914 .p_replen = RPCB_setres_sz,
@@ -925,7 +918,7 @@ static struct rpc_procinfo rpcb_procedures4[] = {
925 }, 918 },
926 [RPCBPROC_UNSET] = { 919 [RPCBPROC_UNSET] = {
927 .p_proc = RPCBPROC_UNSET, 920 .p_proc = RPCBPROC_UNSET,
928 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 921 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
929 .p_decode = (kxdrproc_t)rpcb_dec_set, 922 .p_decode = (kxdrproc_t)rpcb_dec_set,
930 .p_arglen = RPCB_getaddrargs_sz, 923 .p_arglen = RPCB_getaddrargs_sz,
931 .p_replen = RPCB_setres_sz, 924 .p_replen = RPCB_setres_sz,
@@ -935,7 +928,7 @@ static struct rpc_procinfo rpcb_procedures4[] = {
935 }, 928 },
936 [RPCBPROC_GETADDR] = { 929 [RPCBPROC_GETADDR] = {
937 .p_proc = RPCBPROC_GETADDR, 930 .p_proc = RPCBPROC_GETADDR,
938 .p_encode = (kxdrproc_t)rpcb_enc_getaddr, 931 .p_encode = (kxdreproc_t)rpcb_enc_getaddr,
939 .p_decode = (kxdrproc_t)rpcb_dec_getaddr, 932 .p_decode = (kxdrproc_t)rpcb_dec_getaddr,
940 .p_arglen = RPCB_getaddrargs_sz, 933 .p_arglen = RPCB_getaddrargs_sz,
941 .p_replen = RPCB_getaddrres_sz, 934 .p_replen = RPCB_getaddrres_sz,