aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trondmy@gmail.com>2019-04-09 11:46:16 -0400
committerJ. Bruce Fields <bfields@redhat.com>2019-04-24 09:46:34 -0400
commit4532608d71c8ed6049c949a667eeed719cb9291d (patch)
tree5d678aa0b8fba37dc7bcb6738066f1f2dc9a2ec8
parent8e5b67731d088e66fc6a59d9e2fc9a5e4e187303 (diff)
SUNRPC: Clean up generic dispatcher code
Simplify the generic server dispatcher. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--net/sunrpc/svc.c75
1 files changed, 47 insertions, 28 deletions
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 69f3b9e015ce..791c8076793f 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -1160,6 +1160,45 @@ svc_get_autherr(struct svc_rqst *rqstp, __be32 *statp)
1160 return rpc_auth_ok; 1160 return rpc_auth_ok;
1161} 1161}
1162 1162
1163static int
1164svc_generic_dispatch(struct svc_rqst *rqstp, __be32 *statp)
1165{
1166 struct kvec *argv = &rqstp->rq_arg.head[0];
1167 struct kvec *resv = &rqstp->rq_res.head[0];
1168 const struct svc_procedure *procp = rqstp->rq_procinfo;
1169
1170 /*
1171 * Decode arguments
1172 * XXX: why do we ignore the return value?
1173 */
1174 if (procp->pc_decode &&
1175 !procp->pc_decode(rqstp, argv->iov_base)) {
1176 *statp = rpc_garbage_args;
1177 return 1;
1178 }
1179
1180 *statp = procp->pc_func(rqstp);
1181
1182 if (*statp == rpc_drop_reply ||
1183 test_bit(RQ_DROPME, &rqstp->rq_flags))
1184 return 0;
1185
1186 if (test_bit(RQ_AUTHERR, &rqstp->rq_flags))
1187 return 1;
1188
1189 if (*statp != rpc_success)
1190 return 1;
1191
1192 /* Encode reply */
1193 if (procp->pc_encode &&
1194 !procp->pc_encode(rqstp, resv->iov_base + resv->iov_len)) {
1195 dprintk("svc: failed to encode reply\n");
1196 /* serv->sv_stats->rpcsystemerr++; */
1197 *statp = rpc_system_err;
1198 }
1199 return 1;
1200}
1201
1163__be32 1202__be32
1164svc_generic_init_request(struct svc_rqst *rqstp, 1203svc_generic_init_request(struct svc_rqst *rqstp,
1165 const struct svc_program *progp, 1204 const struct svc_program *progp,
@@ -1328,40 +1367,17 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
1328 1367
1329 /* Call the function that processes the request. */ 1368 /* Call the function that processes the request. */
1330 if (!process.dispatch) { 1369 if (!process.dispatch) {
1331 /* 1370 if (!svc_generic_dispatch(rqstp, statp))
1332 * Decode arguments 1371 goto release_dropit;
1333 * XXX: why do we ignore the return value? 1372 if (*statp == rpc_garbage_args)
1334 */
1335 if (procp->pc_decode &&
1336 !procp->pc_decode(rqstp, argv->iov_base))
1337 goto err_garbage; 1373 goto err_garbage;
1338
1339 *statp = procp->pc_func(rqstp);
1340
1341 /* Encode reply */
1342 if (*statp == rpc_drop_reply ||
1343 test_bit(RQ_DROPME, &rqstp->rq_flags)) {
1344 if (procp->pc_release)
1345 procp->pc_release(rqstp);
1346 goto dropit;
1347 }
1348 auth_stat = svc_get_autherr(rqstp, statp); 1374 auth_stat = svc_get_autherr(rqstp, statp);
1349 if (auth_stat != rpc_auth_ok) 1375 if (auth_stat != rpc_auth_ok)
1350 goto err_release_bad_auth; 1376 goto err_release_bad_auth;
1351 if (*statp == rpc_success && procp->pc_encode &&
1352 !procp->pc_encode(rqstp, resv->iov_base + resv->iov_len)) {
1353 dprintk("svc: failed to encode reply\n");
1354 /* serv->sv_stats->rpcsystemerr++; */
1355 *statp = rpc_system_err;
1356 }
1357 } else { 1377 } else {
1358 dprintk("svc: calling dispatcher\n"); 1378 dprintk("svc: calling dispatcher\n");
1359 if (!process.dispatch(rqstp, statp)) { 1379 if (!process.dispatch(rqstp, statp))
1360 /* Release reply info */ 1380 goto release_dropit; /* Release reply info */
1361 if (procp->pc_release)
1362 procp->pc_release(rqstp);
1363 goto dropit;
1364 }
1365 } 1381 }
1366 1382
1367 /* Check RPC status result */ 1383 /* Check RPC status result */
@@ -1380,6 +1396,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
1380 goto close; 1396 goto close;
1381 return 1; /* Caller can now send it */ 1397 return 1; /* Caller can now send it */
1382 1398
1399release_dropit:
1400 if (procp->pc_release)
1401 procp->pc_release(rqstp);
1383 dropit: 1402 dropit:
1384 svc_authorise(rqstp); /* doesn't hurt to call this twice */ 1403 svc_authorise(rqstp); /* doesn't hurt to call this twice */
1385 dprintk("svc: svc_process dropit\n"); 1404 dprintk("svc: svc_process dropit\n");