hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/sunrpc/clnt.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/net/sunrpc/clnt.c
34 *
....@@ -46,10 +47,6 @@
4647 # define RPCDBG_FACILITY RPCDBG_CALL
4748 #endif
4849
49
-#define dprint_status(t) \
50
- dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \
51
- __func__, t->tk_status)
52
-
5350 /*
5451 * All RPC clients are linked into this list
5552 */
....@@ -61,24 +58,24 @@
6158 static void call_reserve(struct rpc_task *task);
6259 static void call_reserveresult(struct rpc_task *task);
6360 static void call_allocate(struct rpc_task *task);
61
+static void call_encode(struct rpc_task *task);
6462 static void call_decode(struct rpc_task *task);
6563 static void call_bind(struct rpc_task *task);
6664 static void call_bind_status(struct rpc_task *task);
6765 static void call_transmit(struct rpc_task *task);
68
-#if defined(CONFIG_SUNRPC_BACKCHANNEL)
69
-static void call_bc_transmit(struct rpc_task *task);
70
-#endif /* CONFIG_SUNRPC_BACKCHANNEL */
7166 static void call_status(struct rpc_task *task);
7267 static void call_transmit_status(struct rpc_task *task);
7368 static void call_refresh(struct rpc_task *task);
7469 static void call_refreshresult(struct rpc_task *task);
75
-static void call_timeout(struct rpc_task *task);
7670 static void call_connect(struct rpc_task *task);
7771 static void call_connect_status(struct rpc_task *task);
7872
79
-static __be32 *rpc_encode_header(struct rpc_task *task);
80
-static __be32 *rpc_verify_header(struct rpc_task *task);
73
+static int rpc_encode_header(struct rpc_task *task,
74
+ struct xdr_stream *xdr);
75
+static int rpc_decode_header(struct rpc_task *task,
76
+ struct xdr_stream *xdr);
8177 static int rpc_ping(struct rpc_clnt *clnt);
78
+static void rpc_check_timeout(struct rpc_task *task);
8279
8380 static void rpc_register_client(struct rpc_clnt *clnt)
8481 {
....@@ -369,10 +366,6 @@
369366 const char *nodename = args->nodename;
370367 int err;
371368
372
- /* sanity check the name before trying to print it */
373
- dprintk("RPC: creating %s client for %s (xprt %p)\n",
374
- program->name, args->servername, xprt);
375
-
376369 err = rpciod_up();
377370 if (err)
378371 goto out_no_rpciod;
....@@ -394,6 +387,7 @@
394387 if (err)
395388 goto out_no_clid;
396389
390
+ clnt->cl_cred = get_cred(args->cred);
397391 clnt->cl_procinfo = version->procs;
398392 clnt->cl_maxproc = version->nrprocs;
399393 clnt->cl_prog = args->prognumber ? : program->number;
....@@ -434,11 +428,14 @@
434428 goto out_no_path;
435429 if (parent)
436430 atomic_inc(&parent->cl_count);
431
+
432
+ trace_rpc_clnt_new(clnt, xprt, program->name, args->servername);
437433 return clnt;
438434
439435 out_no_path:
440436 rpc_free_iostats(clnt->cl_metrics);
441437 out_no_stats:
438
+ put_cred(clnt->cl_cred);
442439 rpc_free_clid(clnt);
443440 out_no_clid:
444441 kfree(clnt);
....@@ -447,6 +444,7 @@
447444 out_no_rpciod:
448445 xprt_switch_put(xps);
449446 xprt_put(xprt);
447
+ trace_rpc_clnt_new_err(program->name, args->servername, err);
450448 return ERR_PTR(err);
451449 }
452450
....@@ -484,8 +482,11 @@
484482 }
485483
486484 clnt->cl_softrtry = 1;
487
- if (args->flags & RPC_CLNT_CREATE_HARDRTRY)
485
+ if (args->flags & (RPC_CLNT_CREATE_HARDRTRY|RPC_CLNT_CREATE_SOFTERR)) {
488486 clnt->cl_softrtry = 0;
487
+ if (args->flags & RPC_CLNT_CREATE_SOFTERR)
488
+ clnt->cl_softerr = 1;
489
+ }
489490
490491 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
491492 clnt->cl_autobind = 1;
....@@ -522,6 +523,8 @@
522523 .bc_xprt = args->bc_xprt,
523524 };
524525 char servername[48];
526
+ struct rpc_clnt *clnt;
527
+ int i;
525528
526529 if (args->bc_xprt) {
527530 WARN_ON_ONCE(!(args->protocol & XPRT_TRANSPORT_BC));
....@@ -583,8 +586,19 @@
583586 xprt->resvport = 1;
584587 if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT)
585588 xprt->resvport = 0;
589
+ xprt->reuseport = 0;
590
+ if (args->flags & RPC_CLNT_CREATE_REUSEPORT)
591
+ xprt->reuseport = 1;
586592
587
- return rpc_create_xprt(args, xprt);
593
+ clnt = rpc_create_xprt(args, xprt);
594
+ if (IS_ERR(clnt) || args->nconnect <= 1)
595
+ return clnt;
596
+
597
+ for (i = 0; i < args->nconnect - 1; i++) {
598
+ if (rpc_clnt_add_xprt(clnt, &xprtargs, NULL, NULL) < 0)
599
+ break;
600
+ }
601
+ return clnt;
588602 }
589603 EXPORT_SYMBOL_GPL(rpc_create);
590604
....@@ -615,21 +629,21 @@
615629 args->nodename = clnt->cl_nodename;
616630
617631 new = rpc_new_client(args, xps, xprt, clnt);
618
- if (IS_ERR(new)) {
619
- err = PTR_ERR(new);
620
- goto out_err;
621
- }
632
+ if (IS_ERR(new))
633
+ return new;
622634
623635 /* Turn off autobind on clones */
624636 new->cl_autobind = 0;
625637 new->cl_softrtry = clnt->cl_softrtry;
638
+ new->cl_softerr = clnt->cl_softerr;
626639 new->cl_noretranstimeo = clnt->cl_noretranstimeo;
627640 new->cl_discrtry = clnt->cl_discrtry;
628641 new->cl_chatty = clnt->cl_chatty;
642
+ new->cl_principal = clnt->cl_principal;
629643 return new;
630644
631645 out_err:
632
- dprintk("RPC: %s: returned error %d\n", __func__, err);
646
+ trace_rpc_clnt_clone_err(clnt, err);
633647 return ERR_PTR(err);
634648 }
635649
....@@ -647,6 +661,7 @@
647661 .prognumber = clnt->cl_prog,
648662 .version = clnt->cl_vers,
649663 .authflavor = clnt->cl_auth->au_flavor,
664
+ .cred = clnt->cl_cred,
650665 };
651666 return __rpc_clone_client(&args, clnt);
652667 }
....@@ -668,6 +683,7 @@
668683 .prognumber = clnt->cl_prog,
669684 .version = clnt->cl_vers,
670685 .authflavor = flavor,
686
+ .cred = clnt->cl_cred,
671687 };
672688 return __rpc_clone_client(&args, clnt);
673689 }
....@@ -700,11 +716,8 @@
700716 int err;
701717
702718 xprt = xprt_create_transport(args);
703
- if (IS_ERR(xprt)) {
704
- dprintk("RPC: failed to create new xprt for clnt %p\n",
705
- clnt);
719
+ if (IS_ERR(xprt))
706720 return PTR_ERR(xprt);
707
- }
708721
709722 xps = xprt_switch_alloc(xprt, GFP_KERNEL);
710723 if (xps == NULL) {
....@@ -744,7 +757,7 @@
744757 rpc_release_client(parent);
745758 xprt_switch_put(oldxps);
746759 xprt_put(old);
747
- dprintk("RPC: replaced xprt for clnt %p\n", clnt);
760
+ trace_rpc_clnt_replace_xprt(clnt);
748761 return 0;
749762
750763 out_revert:
....@@ -754,7 +767,7 @@
754767 rpc_client_register(clnt, pseudoflavor, NULL);
755768 xprt_switch_put(xps);
756769 xprt_put(xprt);
757
- dprintk("RPC: failed to switch xprt for clnt %p\n", clnt);
770
+ trace_rpc_clnt_replace_xprt_err(clnt);
758771 return err;
759772 }
760773 EXPORT_SYMBOL_GPL(rpc_switch_client_transport);
....@@ -821,22 +834,14 @@
821834
822835 if (list_empty(&clnt->cl_tasks))
823836 return;
824
- dprintk("RPC: killing all tasks for client %p\n", clnt);
837
+
825838 /*
826839 * Spin lock all_tasks to prevent changes...
827840 */
841
+ trace_rpc_clnt_killall(clnt);
828842 spin_lock(&clnt->cl_lock);
829
- list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) {
830
- if (!RPC_IS_ACTIVATED(rovr))
831
- continue;
832
- if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
833
- rovr->tk_flags |= RPC_TASK_KILLED;
834
- rpc_exit(rovr, -EIO);
835
- if (RPC_IS_QUEUED(rovr))
836
- rpc_wake_up_queued_task(rovr->tk_waitqueue,
837
- rovr);
838
- }
839
- }
843
+ list_for_each_entry(rovr, &clnt->cl_tasks, tk_task)
844
+ rpc_signal_task(rovr);
840845 spin_unlock(&clnt->cl_lock);
841846 }
842847 EXPORT_SYMBOL_GPL(rpc_killall_tasks);
....@@ -849,9 +854,7 @@
849854 {
850855 might_sleep();
851856
852
- dprintk_rcu("RPC: shutting down %s client for %s\n",
853
- clnt->cl_program->name,
854
- rcu_dereference(clnt->cl_xprt)->servername);
857
+ trace_rpc_clnt_shutdown(clnt);
855858
856859 while (!list_empty(&clnt->cl_tasks)) {
857860 rpc_killall_tasks(clnt);
....@@ -866,26 +869,40 @@
866869 /*
867870 * Free an RPC client
868871 */
872
+static void rpc_free_client_work(struct work_struct *work)
873
+{
874
+ struct rpc_clnt *clnt = container_of(work, struct rpc_clnt, cl_work);
875
+
876
+ trace_rpc_clnt_free(clnt);
877
+
878
+ /* These might block on processes that might allocate memory,
879
+ * so they cannot be called in rpciod, so they are handled separately
880
+ * here.
881
+ */
882
+ rpc_clnt_debugfs_unregister(clnt);
883
+ rpc_free_clid(clnt);
884
+ rpc_clnt_remove_pipedir(clnt);
885
+ xprt_put(rcu_dereference_raw(clnt->cl_xprt));
886
+
887
+ kfree(clnt);
888
+ rpciod_down();
889
+}
869890 static struct rpc_clnt *
870891 rpc_free_client(struct rpc_clnt *clnt)
871892 {
872893 struct rpc_clnt *parent = NULL;
873894
874
- dprintk_rcu("RPC: destroying %s client for %s\n",
875
- clnt->cl_program->name,
876
- rcu_dereference(clnt->cl_xprt)->servername);
895
+ trace_rpc_clnt_release(clnt);
877896 if (clnt->cl_parent != clnt)
878897 parent = clnt->cl_parent;
879
- rpc_clnt_debugfs_unregister(clnt);
880
- rpc_clnt_remove_pipedir(clnt);
881898 rpc_unregister_client(clnt);
882899 rpc_free_iostats(clnt->cl_metrics);
883900 clnt->cl_metrics = NULL;
884
- xprt_put(rcu_dereference_raw(clnt->cl_xprt));
885901 xprt_iter_destroy(&clnt->cl_xpi);
886
- rpciod_down();
887
- rpc_free_clid(clnt);
888
- kfree(clnt);
902
+ put_cred(clnt->cl_cred);
903
+
904
+ INIT_WORK(&clnt->cl_work, rpc_free_client_work);
905
+ schedule_work(&clnt->cl_work);
889906 return parent;
890907 }
891908
....@@ -917,8 +934,6 @@
917934 void
918935 rpc_release_client(struct rpc_clnt *clnt)
919936 {
920
- dprintk("RPC: rpc_release_client(%p)\n", clnt);
921
-
922937 do {
923938 if (list_empty(&clnt->cl_tasks))
924939 wake_up(&destroy_wait);
....@@ -948,6 +963,7 @@
948963 .prognumber = program->number,
949964 .version = vers,
950965 .authflavor = old->cl_auth->au_flavor,
966
+ .cred = old->cl_cred,
951967 };
952968 struct rpc_clnt *clnt;
953969 int err;
....@@ -965,13 +981,46 @@
965981 }
966982 EXPORT_SYMBOL_GPL(rpc_bind_new_program);
967983
984
+struct rpc_xprt *
985
+rpc_task_get_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
986
+{
987
+ struct rpc_xprt_switch *xps;
988
+
989
+ if (!xprt)
990
+ return NULL;
991
+ rcu_read_lock();
992
+ xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
993
+ atomic_long_inc(&xps->xps_queuelen);
994
+ rcu_read_unlock();
995
+ atomic_long_inc(&xprt->queuelen);
996
+
997
+ return xprt;
998
+}
999
+
1000
+static void
1001
+rpc_task_release_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
1002
+{
1003
+ struct rpc_xprt_switch *xps;
1004
+
1005
+ atomic_long_dec(&xprt->queuelen);
1006
+ rcu_read_lock();
1007
+ xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
1008
+ atomic_long_dec(&xps->xps_queuelen);
1009
+ rcu_read_unlock();
1010
+
1011
+ xprt_put(xprt);
1012
+}
1013
+
9681014 void rpc_task_release_transport(struct rpc_task *task)
9691015 {
9701016 struct rpc_xprt *xprt = task->tk_xprt;
9711017
9721018 if (xprt) {
9731019 task->tk_xprt = NULL;
974
- xprt_put(xprt);
1020
+ if (task->tk_client)
1021
+ rpc_task_release_xprt(task->tk_client, xprt);
1022
+ else
1023
+ xprt_put(xprt);
9751024 }
9761025 }
9771026 EXPORT_SYMBOL_GPL(rpc_task_release_transport);
....@@ -980,6 +1029,7 @@
9801029 {
9811030 struct rpc_clnt *clnt = task->tk_client;
9821031
1032
+ rpc_task_release_transport(task);
9831033 if (clnt != NULL) {
9841034 /* Remove from client task list */
9851035 spin_lock(&clnt->cl_lock);
....@@ -989,14 +1039,34 @@
9891039
9901040 rpc_release_client(clnt);
9911041 }
992
- rpc_task_release_transport(task);
1042
+}
1043
+
1044
+static struct rpc_xprt *
1045
+rpc_task_get_first_xprt(struct rpc_clnt *clnt)
1046
+{
1047
+ struct rpc_xprt *xprt;
1048
+
1049
+ rcu_read_lock();
1050
+ xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
1051
+ rcu_read_unlock();
1052
+ return rpc_task_get_xprt(clnt, xprt);
1053
+}
1054
+
1055
+static struct rpc_xprt *
1056
+rpc_task_get_next_xprt(struct rpc_clnt *clnt)
1057
+{
1058
+ return rpc_task_get_xprt(clnt, xprt_iter_get_next(&clnt->cl_xpi));
9931059 }
9941060
9951061 static
9961062 void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt)
9971063 {
998
- if (!task->tk_xprt)
999
- task->tk_xprt = xprt_iter_get_next(&clnt->cl_xpi);
1064
+ if (task->tk_xprt)
1065
+ return;
1066
+ if (task->tk_flags & RPC_TASK_NO_ROUND_ROBIN)
1067
+ task->tk_xprt = rpc_task_get_first_xprt(clnt);
1068
+ else
1069
+ task->tk_xprt = rpc_task_get_next_xprt(clnt);
10001070 }
10011071
10021072 static
....@@ -1009,6 +1079,8 @@
10091079 atomic_inc(&clnt->cl_count);
10101080 if (clnt->cl_softrtry)
10111081 task->tk_flags |= RPC_TASK_SOFT;
1082
+ if (clnt->cl_softerr)
1083
+ task->tk_flags |= RPC_TASK_TIMEOUT;
10121084 if (clnt->cl_noretranstimeo)
10131085 task->tk_flags |= RPC_TASK_NO_RETRANS_TIMEOUT;
10141086 if (atomic_read(&clnt->cl_swapper))
....@@ -1027,8 +1099,9 @@
10271099 task->tk_msg.rpc_proc = msg->rpc_proc;
10281100 task->tk_msg.rpc_argp = msg->rpc_argp;
10291101 task->tk_msg.rpc_resp = msg->rpc_resp;
1030
- if (msg->rpc_cred != NULL)
1031
- task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred);
1102
+ task->tk_msg.rpc_cred = msg->rpc_cred;
1103
+ if (!(task->tk_flags & RPC_TASK_CRED_NOREF))
1104
+ get_cred(task->tk_msg.rpc_cred);
10321105 }
10331106 }
10341107
....@@ -1053,6 +1126,9 @@
10531126 struct rpc_task *task;
10541127
10551128 task = rpc_new_task(task_setup_data);
1129
+
1130
+ if (!RPC_IS_ASYNC(task))
1131
+ task->tk_flags |= RPC_TASK_CRED_NOREF;
10561132
10571133 rpc_task_set_client(task, task_setup_data->rpc_client);
10581134 rpc_task_set_rpc_message(task, task_setup_data->rpc_message);
....@@ -1129,6 +1205,8 @@
11291205 EXPORT_SYMBOL_GPL(rpc_call_async);
11301206
11311207 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1208
+static void call_bc_encode(struct rpc_task *task);
1209
+
11321210 /**
11331211 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run
11341212 * rpc_execute against it
....@@ -1137,10 +1215,10 @@
11371215 struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req)
11381216 {
11391217 struct rpc_task *task;
1140
- struct xdr_buf *xbufp = &req->rq_snd_buf;
11411218 struct rpc_task_setup task_setup_data = {
11421219 .callback_ops = &rpc_default_ops,
1143
- .flags = RPC_TASK_SOFTCONN,
1220
+ .flags = RPC_TASK_SOFTCONN |
1221
+ RPC_TASK_NO_RETRANS_TIMEOUT,
11441222 };
11451223
11461224 dprintk("RPC: rpc_run_bc_task req= %p\n", req);
....@@ -1148,16 +1226,9 @@
11481226 * Create an rpc_task to send the data
11491227 */
11501228 task = rpc_new_task(&task_setup_data);
1151
- task->tk_rqstp = req;
1229
+ xprt_init_bc_request(req, task);
11521230
1153
- /*
1154
- * Set up the xdr_buf length.
1155
- * This also indicates that the buffer is XDR encoded already.
1156
- */
1157
- xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
1158
- xbufp->tail[0].iov_len;
1159
-
1160
- task->tk_action = call_bc_transmit;
1231
+ task->tk_action = call_bc_encode;
11611232 atomic_inc(&task->tk_count);
11621233 WARN_ON_ONCE(atomic_read(&task->tk_count) != 2);
11631234 rpc_execute(task);
....@@ -1166,6 +1237,29 @@
11661237 return task;
11671238 }
11681239 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1240
+
1241
+/**
1242
+ * rpc_prepare_reply_pages - Prepare to receive a reply data payload into pages
1243
+ * @req: RPC request to prepare
1244
+ * @pages: vector of struct page pointers
1245
+ * @base: offset in first page where receive should start, in bytes
1246
+ * @len: expected size of the upper layer data payload, in bytes
1247
+ * @hdrsize: expected size of upper layer reply header, in XDR words
1248
+ *
1249
+ */
1250
+void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
1251
+ unsigned int base, unsigned int len,
1252
+ unsigned int hdrsize)
1253
+{
1254
+ /* Subtract one to force an extra word of buffer space for the
1255
+ * payload's XDR pad to fall into the rcv_buf's tail iovec.
1256
+ */
1257
+ hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_ralign - 1;
1258
+
1259
+ xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
1260
+ trace_rpc_xdr_reply_pages(req->rq_task, &req->rq_rcv_buf);
1261
+}
1262
+EXPORT_SYMBOL_GPL(rpc_prepare_reply_pages);
11691263
11701264 void
11711265 rpc_call_start(struct rpc_task *task)
....@@ -1267,7 +1361,7 @@
12671361 break;
12681362 default:
12691363 err = -EAFNOSUPPORT;
1270
- goto out;
1364
+ goto out_release;
12711365 }
12721366 if (err < 0) {
12731367 dprintk("RPC: can't bind UDP socket (%d)\n", err);
....@@ -1439,6 +1533,19 @@
14391533 }
14401534 EXPORT_SYMBOL_GPL(rpc_max_bc_payload);
14411535
1536
+unsigned int rpc_num_bc_slots(struct rpc_clnt *clnt)
1537
+{
1538
+ struct rpc_xprt *xprt;
1539
+ unsigned int ret;
1540
+
1541
+ rcu_read_lock();
1542
+ xprt = rcu_dereference(clnt->cl_xprt);
1543
+ ret = xprt->ops->bc_num_slots(xprt);
1544
+ rcu_read_unlock();
1545
+ return ret;
1546
+}
1547
+EXPORT_SYMBOL_GPL(rpc_num_bc_slots);
1548
+
14421549 /**
14431550 * rpc_force_rebind - force transport to check that remote port is unchanged
14441551 * @clnt: client to rebind
....@@ -1454,22 +1561,14 @@
14541561 }
14551562 EXPORT_SYMBOL_GPL(rpc_force_rebind);
14561563
1457
-/*
1458
- * Restart an (async) RPC call from the call_prepare state.
1459
- * Usually called from within the exit handler.
1460
- */
1461
-int
1462
-rpc_restart_call_prepare(struct rpc_task *task)
1564
+static int
1565
+__rpc_restart_call(struct rpc_task *task, void (*action)(struct rpc_task *))
14631566 {
1464
- if (RPC_ASSASSINATED(task))
1465
- return 0;
1466
- task->tk_action = call_start;
14671567 task->tk_status = 0;
1468
- if (task->tk_ops->rpc_call_prepare != NULL)
1469
- task->tk_action = rpc_prepare_task;
1568
+ task->tk_rpc_status = 0;
1569
+ task->tk_action = action;
14701570 return 1;
14711571 }
1472
-EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
14731572
14741573 /*
14751574 * Restart an (async) RPC call. Usually called from within the
....@@ -1478,13 +1577,22 @@
14781577 int
14791578 rpc_restart_call(struct rpc_task *task)
14801579 {
1481
- if (RPC_ASSASSINATED(task))
1482
- return 0;
1483
- task->tk_action = call_start;
1484
- task->tk_status = 0;
1485
- return 1;
1580
+ return __rpc_restart_call(task, call_start);
14861581 }
14871582 EXPORT_SYMBOL_GPL(rpc_restart_call);
1583
+
1584
+/*
1585
+ * Restart an (async) RPC call from the call_prepare state.
1586
+ * Usually called from within the exit handler.
1587
+ */
1588
+int
1589
+rpc_restart_call_prepare(struct rpc_task *task)
1590
+{
1591
+ if (task->tk_ops->rpc_call_prepare != NULL)
1592
+ return __rpc_restart_call(task, rpc_prepare_task);
1593
+ return rpc_restart_call(task);
1594
+}
1595
+EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
14881596
14891597 const char
14901598 *rpc_proc_name(const struct rpc_task *task)
....@@ -1500,6 +1608,20 @@
15001608 return "no proc";
15011609 }
15021610
1611
+static void
1612
+__rpc_call_rpcerror(struct rpc_task *task, int tk_status, int rpc_status)
1613
+{
1614
+ trace_rpc_call_rpcerror(task, tk_status, rpc_status);
1615
+ task->tk_rpc_status = rpc_status;
1616
+ rpc_exit(task, tk_status);
1617
+}
1618
+
1619
+static void
1620
+rpc_call_rpcerror(struct rpc_task *task, int status)
1621
+{
1622
+ __rpc_call_rpcerror(task, status, status);
1623
+}
1624
+
15031625 /*
15041626 * 0. Initial state
15051627 *
....@@ -1513,10 +1635,6 @@
15131635 int idx = task->tk_msg.rpc_proc->p_statidx;
15141636
15151637 trace_rpc_request(task);
1516
- dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid,
1517
- clnt->cl_program->name, clnt->cl_vers,
1518
- rpc_proc_name(task),
1519
- (RPC_IS_ASYNC(task) ? "async" : "sync"));
15201638
15211639 /* Increment call count (version might not be valid for ping) */
15221640 if (clnt->cl_program->version[clnt->cl_vers])
....@@ -1532,8 +1650,6 @@
15321650 static void
15331651 call_reserve(struct rpc_task *task)
15341652 {
1535
- dprint_status(task);
1536
-
15371653 task->tk_status = 0;
15381654 task->tk_action = call_reserveresult;
15391655 xprt_reserve(task);
....@@ -1549,8 +1665,6 @@
15491665 {
15501666 int status = task->tk_status;
15511667
1552
- dprint_status(task);
1553
-
15541668 /*
15551669 * After a call to xprt_reserve(), we must have either
15561670 * a request slot or else an error status.
....@@ -1562,37 +1676,20 @@
15621676 return;
15631677 }
15641678
1565
- printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
1566
- __func__, status);
1567
- rpc_exit(task, -EIO);
1679
+ rpc_call_rpcerror(task, -EIO);
15681680 return;
1569
- }
1570
-
1571
- /*
1572
- * Even though there was an error, we may have acquired
1573
- * a request slot somehow. Make sure not to leak it.
1574
- */
1575
- if (task->tk_rqstp) {
1576
- printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
1577
- __func__, status);
1578
- xprt_release(task);
15791681 }
15801682
15811683 switch (status) {
15821684 case -ENOMEM:
15831685 rpc_delay(task, HZ >> 2);
1584
- /* fall through */
1686
+ fallthrough;
15851687 case -EAGAIN: /* woken up; retry */
15861688 task->tk_action = call_retry_reserve;
15871689 return;
1588
- case -EIO: /* probably a shutdown */
1589
- break;
15901690 default:
1591
- printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
1592
- __func__, status);
1593
- break;
1691
+ rpc_call_rpcerror(task, status);
15941692 }
1595
- rpc_exit(task, status);
15961693 }
15971694
15981695 /*
....@@ -1601,8 +1698,6 @@
16011698 static void
16021699 call_retry_reserve(struct rpc_task *task)
16031700 {
1604
- dprint_status(task);
1605
-
16061701 task->tk_status = 0;
16071702 task->tk_action = call_reserveresult;
16081703 xprt_retry_reserve(task);
....@@ -1614,8 +1709,6 @@
16141709 static void
16151710 call_refresh(struct rpc_task *task)
16161711 {
1617
- dprint_status(task);
1618
-
16191712 task->tk_action = call_refreshresult;
16201713 task->tk_status = 0;
16211714 task->tk_client->cl_stats->rpcauthrefresh++;
....@@ -1630,8 +1723,6 @@
16301723 {
16311724 int status = task->tk_status;
16321725
1633
- dprint_status(task);
1634
-
16351726 task->tk_status = 0;
16361727 task->tk_action = call_refresh;
16371728 switch (status) {
....@@ -1643,24 +1734,22 @@
16431734 /* Use rate-limiting and a max number of retries if refresh
16441735 * had status 0 but failed to update the cred.
16451736 */
1646
- /* fall through */
1737
+ fallthrough;
16471738 case -ETIMEDOUT:
16481739 rpc_delay(task, 3*HZ);
1649
- /* fall through */
1740
+ fallthrough;
16501741 case -EAGAIN:
16511742 status = -EACCES;
1652
- /* fall through */
1743
+ fallthrough;
16531744 case -EKEYEXPIRED:
16541745 if (!task->tk_cred_retry)
16551746 break;
16561747 task->tk_cred_retry--;
1657
- dprintk("RPC: %5u %s: retry refresh creds\n",
1658
- task->tk_pid, __func__);
1748
+ trace_rpc_retry_refresh_status(task);
16591749 return;
16601750 }
1661
- dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1662
- task->tk_pid, __func__, status);
1663
- rpc_exit(task, status);
1751
+ trace_rpc_refresh_status(task);
1752
+ rpc_call_rpcerror(task, status);
16641753 }
16651754
16661755 /*
....@@ -1670,16 +1759,14 @@
16701759 static void
16711760 call_allocate(struct rpc_task *task)
16721761 {
1673
- unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack;
1762
+ const struct rpc_auth *auth = task->tk_rqstp->rq_cred->cr_auth;
16741763 struct rpc_rqst *req = task->tk_rqstp;
16751764 struct rpc_xprt *xprt = req->rq_xprt;
16761765 const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
16771766 int status;
16781767
1679
- dprint_status(task);
1680
-
16811768 task->tk_status = 0;
1682
- task->tk_action = call_bind;
1769
+ task->tk_action = call_encode;
16831770
16841771 if (req->rq_buffer)
16851772 return;
....@@ -1695,21 +1782,25 @@
16951782 * and reply headers, and convert both values
16961783 * to byte sizes.
16971784 */
1698
- req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen;
1785
+ req->rq_callsize = RPC_CALLHDRSIZE + (auth->au_cslack << 1) +
1786
+ proc->p_arglen;
16991787 req->rq_callsize <<= 2;
1700
- req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen;
1788
+ /*
1789
+ * Note: the reply buffer must at minimum allocate enough space
1790
+ * for the 'struct accepted_reply' from RFC5531.
1791
+ */
1792
+ req->rq_rcvsize = RPC_REPHDRSIZE + auth->au_rslack + \
1793
+ max_t(size_t, proc->p_replen, 2);
17011794 req->rq_rcvsize <<= 2;
17021795
17031796 status = xprt->ops->buf_alloc(task);
1704
- xprt_inject_disconnect(xprt);
1797
+ trace_rpc_buf_alloc(task, status);
17051798 if (status == 0)
17061799 return;
17071800 if (status != -ENOMEM) {
1708
- rpc_exit(task, status);
1801
+ rpc_call_rpcerror(task, status);
17091802 return;
17101803 }
1711
-
1712
- dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid);
17131804
17141805 if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) {
17151806 task->tk_action = call_allocate;
....@@ -1717,33 +1808,23 @@
17171808 return;
17181809 }
17191810
1720
- rpc_exit(task, -ERESTARTSYS);
1811
+ rpc_call_rpcerror(task, -ERESTARTSYS);
17211812 }
17221813
1723
-static inline int
1814
+static int
17241815 rpc_task_need_encode(struct rpc_task *task)
17251816 {
1726
- return task->tk_rqstp->rq_snd_buf.len == 0;
1817
+ return test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate) == 0 &&
1818
+ (!(task->tk_flags & RPC_TASK_SENT) ||
1819
+ !(task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT) ||
1820
+ xprt_request_need_retransmit(task));
17271821 }
17281822
1729
-static inline void
1730
-rpc_task_force_reencode(struct rpc_task *task)
1731
-{
1732
- task->tk_rqstp->rq_snd_buf.len = 0;
1733
- task->tk_rqstp->rq_bytes_sent = 0;
1734
-}
1735
-
1736
-/*
1737
- * 3. Encode arguments of an RPC call
1738
- */
17391823 static void
17401824 rpc_xdr_encode(struct rpc_task *task)
17411825 {
17421826 struct rpc_rqst *req = task->tk_rqstp;
1743
- kxdreproc_t encode;
1744
- __be32 *p;
1745
-
1746
- dprint_status(task);
1827
+ struct xdr_stream xdr;
17471828
17481829 xdr_buf_init(&req->rq_snd_buf,
17491830 req->rq_buffer,
....@@ -1752,19 +1833,81 @@
17521833 req->rq_rbuffer,
17531834 req->rq_rcvsize);
17541835
1755
- p = rpc_encode_header(task);
1756
- if (p == NULL) {
1757
- printk(KERN_INFO "RPC: couldn't encode RPC header, exit EIO\n");
1758
- rpc_exit(task, -EIO);
1836
+ req->rq_reply_bytes_recvd = 0;
1837
+ req->rq_snd_buf.head[0].iov_len = 0;
1838
+ xdr_init_encode(&xdr, &req->rq_snd_buf,
1839
+ req->rq_snd_buf.head[0].iov_base, req);
1840
+ xdr_free_bvec(&req->rq_snd_buf);
1841
+ if (rpc_encode_header(task, &xdr))
1842
+ return;
1843
+
1844
+ task->tk_status = rpcauth_wrap_req(task, &xdr);
1845
+}
1846
+
1847
+/*
1848
+ * 3. Encode arguments of an RPC call
1849
+ */
1850
+static void
1851
+call_encode(struct rpc_task *task)
1852
+{
1853
+ if (!rpc_task_need_encode(task))
1854
+ goto out;
1855
+
1856
+ /* Dequeue task from the receive queue while we're encoding */
1857
+ xprt_request_dequeue_xprt(task);
1858
+ /* Encode here so that rpcsec_gss can use correct sequence number. */
1859
+ rpc_xdr_encode(task);
1860
+ /* Did the encode result in an error condition? */
1861
+ if (task->tk_status != 0) {
1862
+ /* Was the error nonfatal? */
1863
+ switch (task->tk_status) {
1864
+ case -EAGAIN:
1865
+ case -ENOMEM:
1866
+ rpc_delay(task, HZ >> 4);
1867
+ break;
1868
+ case -EKEYEXPIRED:
1869
+ if (!task->tk_cred_retry) {
1870
+ rpc_call_rpcerror(task, task->tk_status);
1871
+ } else {
1872
+ task->tk_action = call_refresh;
1873
+ task->tk_cred_retry--;
1874
+ trace_rpc_retry_refresh_status(task);
1875
+ }
1876
+ break;
1877
+ default:
1878
+ rpc_call_rpcerror(task, task->tk_status);
1879
+ }
17591880 return;
17601881 }
17611882
1762
- encode = task->tk_msg.rpc_proc->p_encode;
1763
- if (encode == NULL)
1764
- return;
1883
+ /* Add task to reply queue before transmission to avoid races */
1884
+ if (rpc_reply_expected(task))
1885
+ xprt_request_enqueue_receive(task);
1886
+ xprt_request_enqueue_transmit(task);
1887
+out:
1888
+ task->tk_action = call_transmit;
1889
+ /* Check that the connection is OK */
1890
+ if (!xprt_bound(task->tk_xprt))
1891
+ task->tk_action = call_bind;
1892
+ else if (!xprt_connected(task->tk_xprt))
1893
+ task->tk_action = call_connect;
1894
+}
17651895
1766
- task->tk_status = rpcauth_wrap_req(task, encode, req, p,
1767
- task->tk_msg.rpc_argp);
1896
+/*
1897
+ * Helpers to check if the task was already transmitted, and
1898
+ * to take action when that is the case.
1899
+ */
1900
+static bool
1901
+rpc_task_transmitted(struct rpc_task *task)
1902
+{
1903
+ return !test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate);
1904
+}
1905
+
1906
+static void
1907
+rpc_task_handle_transmitted(struct rpc_task *task)
1908
+{
1909
+ xprt_end_transmit(task);
1910
+ task->tk_action = call_transmit_status;
17681911 }
17691912
17701913 /*
....@@ -1775,14 +1918,21 @@
17751918 {
17761919 struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
17771920
1778
- dprint_status(task);
1779
-
1780
- task->tk_action = call_connect;
1781
- if (!xprt_bound(xprt)) {
1782
- task->tk_action = call_bind_status;
1783
- task->tk_timeout = xprt->bind_timeout;
1784
- xprt->ops->rpcbind(task);
1921
+ if (rpc_task_transmitted(task)) {
1922
+ rpc_task_handle_transmitted(task);
1923
+ return;
17851924 }
1925
+
1926
+ if (xprt_bound(xprt)) {
1927
+ task->tk_action = call_connect;
1928
+ return;
1929
+ }
1930
+
1931
+ task->tk_action = call_bind_status;
1932
+ if (!xprt_prepare_transmit(task))
1933
+ return;
1934
+
1935
+ xprt->ops->rpcbind(task);
17861936 }
17871937
17881938 /*
....@@ -1791,46 +1941,48 @@
17911941 static void
17921942 call_bind_status(struct rpc_task *task)
17931943 {
1944
+ struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
17941945 int status = -EIO;
17951946
1796
- if (task->tk_status >= 0) {
1797
- dprint_status(task);
1798
- task->tk_status = 0;
1799
- task->tk_action = call_connect;
1947
+ if (rpc_task_transmitted(task)) {
1948
+ rpc_task_handle_transmitted(task);
18001949 return;
18011950 }
18021951
1803
- trace_rpc_bind_status(task);
1952
+ if (task->tk_status >= 0)
1953
+ goto out_next;
1954
+ if (xprt_bound(xprt)) {
1955
+ task->tk_status = 0;
1956
+ goto out_next;
1957
+ }
1958
+
18041959 switch (task->tk_status) {
18051960 case -ENOMEM:
1806
- dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid);
18071961 rpc_delay(task, HZ >> 2);
18081962 goto retry_timeout;
18091963 case -EACCES:
1810
- dprintk("RPC: %5u remote rpcbind: RPC program/version "
1811
- "unavailable\n", task->tk_pid);
1964
+ trace_rpcb_prog_unavail_err(task);
18121965 /* fail immediately if this is an RPC ping */
18131966 if (task->tk_msg.rpc_proc->p_proc == 0) {
18141967 status = -EOPNOTSUPP;
18151968 break;
18161969 }
1817
- if (task->tk_rebind_retry == 0)
1818
- break;
1819
- task->tk_rebind_retry--;
18201970 rpc_delay(task, 3*HZ);
18211971 goto retry_timeout;
1972
+ case -ENOBUFS:
1973
+ rpc_delay(task, HZ >> 2);
1974
+ goto retry_timeout;
1975
+ case -EAGAIN:
1976
+ goto retry_timeout;
18221977 case -ETIMEDOUT:
1823
- dprintk("RPC: %5u rpcbind request timed out\n",
1824
- task->tk_pid);
1978
+ trace_rpcb_timeout_err(task);
18251979 goto retry_timeout;
18261980 case -EPFNOSUPPORT:
18271981 /* server doesn't support any rpcbind version we know of */
1828
- dprintk("RPC: %5u unrecognized remote rpcbind service\n",
1829
- task->tk_pid);
1982
+ trace_rpcb_bind_version_err(task);
18301983 break;
18311984 case -EPROTONOSUPPORT:
1832
- dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n",
1833
- task->tk_pid);
1985
+ trace_rpcb_bind_version_err(task);
18341986 goto retry_timeout;
18351987 case -ECONNREFUSED: /* connection problems */
18361988 case -ECONNRESET:
....@@ -1840,10 +1992,8 @@
18401992 case -ENETDOWN:
18411993 case -EHOSTUNREACH:
18421994 case -ENETUNREACH:
1843
- case -ENOBUFS:
18441995 case -EPIPE:
1845
- dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
1846
- task->tk_pid, task->tk_status);
1996
+ trace_rpcb_unreachable_err(task);
18471997 if (!RPC_IS_SOFTCONN(task)) {
18481998 rpc_delay(task, 5*HZ);
18491999 goto retry_timeout;
....@@ -1851,16 +2001,18 @@
18512001 status = task->tk_status;
18522002 break;
18532003 default:
1854
- dprintk("RPC: %5u unrecognized rpcbind error (%d)\n",
1855
- task->tk_pid, -task->tk_status);
2004
+ trace_rpcb_unrecognized_err(task);
18562005 }
18572006
1858
- rpc_exit(task, status);
2007
+ rpc_call_rpcerror(task, status);
18592008 return;
1860
-
2009
+out_next:
2010
+ task->tk_action = call_connect;
2011
+ return;
18612012 retry_timeout:
18622013 task->tk_status = 0;
1863
- task->tk_action = call_timeout;
2014
+ task->tk_action = call_bind;
2015
+ rpc_check_timeout(task);
18642016 }
18652017
18662018 /*
....@@ -1871,21 +2023,26 @@
18712023 {
18722024 struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
18732025
1874
- dprintk("RPC: %5u call_connect xprt %p %s connected\n",
1875
- task->tk_pid, xprt,
1876
- (xprt_connected(xprt) ? "is" : "is not"));
1877
-
1878
- task->tk_action = call_transmit;
1879
- if (!xprt_connected(xprt)) {
1880
- task->tk_action = call_connect_status;
1881
- if (task->tk_status < 0)
1882
- return;
1883
- if (task->tk_flags & RPC_TASK_NOCONNECT) {
1884
- rpc_exit(task, -ENOTCONN);
1885
- return;
1886
- }
1887
- xprt_connect(task);
2026
+ if (rpc_task_transmitted(task)) {
2027
+ rpc_task_handle_transmitted(task);
2028
+ return;
18882029 }
2030
+
2031
+ if (xprt_connected(xprt)) {
2032
+ task->tk_action = call_transmit;
2033
+ return;
2034
+ }
2035
+
2036
+ task->tk_action = call_connect_status;
2037
+ if (task->tk_status < 0)
2038
+ return;
2039
+ if (task->tk_flags & RPC_TASK_NOCONNECT) {
2040
+ rpc_call_rpcerror(task, -ENOTCONN);
2041
+ return;
2042
+ }
2043
+ if (!xprt_prepare_transmit(task))
2044
+ return;
2045
+ xprt_connect(task);
18892046 }
18902047
18912048 /*
....@@ -1894,12 +2051,26 @@
18942051 static void
18952052 call_connect_status(struct rpc_task *task)
18962053 {
2054
+ struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
18972055 struct rpc_clnt *clnt = task->tk_client;
18982056 int status = task->tk_status;
18992057
1900
- dprint_status(task);
2058
+ if (rpc_task_transmitted(task)) {
2059
+ rpc_task_handle_transmitted(task);
2060
+ return;
2061
+ }
19012062
19022063 trace_rpc_connect_status(task);
2064
+
2065
+ if (task->tk_status == 0) {
2066
+ clnt->cl_stats->netreconn++;
2067
+ goto out_next;
2068
+ }
2069
+ if (xprt_connected(xprt)) {
2070
+ task->tk_status = 0;
2071
+ goto out_next;
2072
+ }
2073
+
19032074 task->tk_status = 0;
19042075 switch (status) {
19052076 case -ECONNREFUSED:
....@@ -1908,36 +2079,41 @@
19082079 break;
19092080 if (clnt->cl_autobind) {
19102081 rpc_force_rebind(clnt);
1911
- task->tk_action = call_bind;
1912
- return;
2082
+ goto out_retry;
19132083 }
1914
- /* fall through */
2084
+ fallthrough;
19152085 case -ECONNRESET:
19162086 case -ECONNABORTED:
19172087 case -ENETDOWN:
19182088 case -ENETUNREACH:
19192089 case -EHOSTUNREACH:
1920
- case -EADDRINUSE:
1921
- case -ENOBUFS:
19222090 case -EPIPE:
2091
+ case -EPROTO:
19232092 xprt_conditional_disconnect(task->tk_rqstp->rq_xprt,
19242093 task->tk_rqstp->rq_connect_cookie);
19252094 if (RPC_IS_SOFTCONN(task))
19262095 break;
19272096 /* retry with existing socket, after a delay */
19282097 rpc_delay(task, 3*HZ);
1929
- /* fall through */
2098
+ fallthrough;
2099
+ case -EADDRINUSE:
2100
+ case -ENOTCONN:
19302101 case -EAGAIN:
1931
- /* Check for timeouts before looping back to call_bind */
19322102 case -ETIMEDOUT:
1933
- task->tk_action = call_timeout;
1934
- return;
1935
- case 0:
1936
- clnt->cl_stats->netreconn++;
1937
- task->tk_action = call_transmit;
1938
- return;
2103
+ goto out_retry;
2104
+ case -ENOBUFS:
2105
+ rpc_delay(task, HZ >> 2);
2106
+ goto out_retry;
19392107 }
1940
- rpc_exit(task, status);
2108
+ rpc_call_rpcerror(task, status);
2109
+ return;
2110
+out_next:
2111
+ task->tk_action = call_transmit;
2112
+ return;
2113
+out_retry:
2114
+ /* Check for timeouts before looping back to call_bind */
2115
+ task->tk_action = call_bind;
2116
+ rpc_check_timeout(task);
19412117 }
19422118
19432119 /*
....@@ -1946,43 +2122,23 @@
19462122 static void
19472123 call_transmit(struct rpc_task *task)
19482124 {
1949
- int is_retrans = RPC_WAS_SENT(task);
1950
-
1951
- dprint_status(task);
1952
-
1953
- task->tk_action = call_status;
1954
- if (task->tk_status < 0)
2125
+ if (rpc_task_transmitted(task)) {
2126
+ rpc_task_handle_transmitted(task);
19552127 return;
2128
+ }
2129
+
2130
+ task->tk_action = call_transmit_status;
19562131 if (!xprt_prepare_transmit(task))
19572132 return;
1958
- task->tk_action = call_transmit_status;
1959
- /* Encode here so that rpcsec_gss can use correct sequence number. */
1960
- if (rpc_task_need_encode(task)) {
1961
- rpc_xdr_encode(task);
1962
- /* Did the encode result in an error condition? */
1963
- if (task->tk_status != 0) {
1964
- /* Was the error nonfatal? */
1965
- if (task->tk_status == -EAGAIN)
1966
- rpc_delay(task, HZ >> 4);
1967
- else
1968
- rpc_exit(task, task->tk_status);
2133
+ task->tk_status = 0;
2134
+ if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate)) {
2135
+ if (!xprt_connected(task->tk_xprt)) {
2136
+ task->tk_status = -ENOTCONN;
19692137 return;
19702138 }
2139
+ xprt_transmit(task);
19712140 }
1972
- xprt_transmit(task);
1973
- if (task->tk_status < 0)
1974
- return;
1975
- if (is_retrans)
1976
- task->tk_client->cl_stats->rpcretrans++;
1977
- /*
1978
- * On success, ensure that we call xprt_end_transmit() before sleeping
1979
- * in order to allow access to the socket to other RPC requests.
1980
- */
1981
- call_transmit_status(task);
1982
- if (rpc_reply_expected(task))
1983
- return;
1984
- task->tk_action = rpc_exit_task;
1985
- rpc_wake_up_queued_task(&task->tk_rqstp->rq_xprt->pending, task);
2141
+ xprt_end_transmit(task);
19862142 }
19872143
19882144 /*
....@@ -1991,28 +2147,24 @@
19912147 static void
19922148 call_transmit_status(struct rpc_task *task)
19932149 {
1994
- struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
19952150 task->tk_action = call_status;
19962151
19972152 /*
19982153 * Common case: success. Force the compiler to put this
1999
- * test first. Or, if any error and xprt_close_wait,
2000
- * release the xprt lock so the socket can close.
2154
+ * test first.
20012155 */
2002
- if (task->tk_status == 0 || xprt_close_wait(xprt)) {
2003
- xprt_end_transmit(task);
2004
- rpc_task_force_reencode(task);
2156
+ if (rpc_task_transmitted(task)) {
2157
+ task->tk_status = 0;
2158
+ xprt_request_wait_receive(task);
20052159 return;
20062160 }
20072161
20082162 switch (task->tk_status) {
2009
- case -EAGAIN:
2010
- case -ENOBUFS:
2011
- break;
20122163 default:
2013
- dprint_status(task);
2014
- xprt_end_transmit(task);
2015
- rpc_task_force_reencode(task);
2164
+ break;
2165
+ case -EBADMSG:
2166
+ task->tk_status = 0;
2167
+ task->tk_action = call_encode;
20162168 break;
20172169 /*
20182170 * Special cases: if we've been waiting on the
....@@ -2020,6 +2172,15 @@
20202172 * socket just returned a connection error,
20212173 * then hold onto the transport lock.
20222174 */
2175
+ case -ENOMEM:
2176
+ case -ENOBUFS:
2177
+ rpc_delay(task, HZ>>2);
2178
+ fallthrough;
2179
+ case -EBADSLT:
2180
+ case -EAGAIN:
2181
+ task->tk_action = call_transmit;
2182
+ task->tk_status = 0;
2183
+ break;
20232184 case -ECONNREFUSED:
20242185 case -EHOSTDOWN:
20252186 case -ENETDOWN:
....@@ -2027,24 +2188,36 @@
20272188 case -ENETUNREACH:
20282189 case -EPERM:
20292190 if (RPC_IS_SOFTCONN(task)) {
2030
- xprt_end_transmit(task);
20312191 if (!task->tk_msg.rpc_proc->p_proc)
20322192 trace_xprt_ping(task->tk_xprt,
20332193 task->tk_status);
2034
- rpc_exit(task, task->tk_status);
2035
- break;
2194
+ rpc_call_rpcerror(task, task->tk_status);
2195
+ return;
20362196 }
2037
- /* fall through */
2197
+ fallthrough;
20382198 case -ECONNRESET:
20392199 case -ECONNABORTED:
20402200 case -EADDRINUSE:
20412201 case -ENOTCONN:
20422202 case -EPIPE:
2043
- rpc_task_force_reencode(task);
2203
+ task->tk_action = call_bind;
2204
+ task->tk_status = 0;
2205
+ break;
20442206 }
2207
+ rpc_check_timeout(task);
20452208 }
20462209
20472210 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
2211
+static void call_bc_transmit(struct rpc_task *task);
2212
+static void call_bc_transmit_status(struct rpc_task *task);
2213
+
2214
+static void
2215
+call_bc_encode(struct rpc_task *task)
2216
+{
2217
+ xprt_request_enqueue_transmit(task);
2218
+ task->tk_action = call_bc_transmit;
2219
+}
2220
+
20482221 /*
20492222 * 5b. Send the backchannel RPC reply. On error, drop the reply. In
20502223 * addition, disconnect on connectivity errors.
....@@ -2052,26 +2225,24 @@
20522225 static void
20532226 call_bc_transmit(struct rpc_task *task)
20542227 {
2228
+ task->tk_action = call_bc_transmit_status;
2229
+ if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate)) {
2230
+ if (!xprt_prepare_transmit(task))
2231
+ return;
2232
+ task->tk_status = 0;
2233
+ xprt_transmit(task);
2234
+ }
2235
+ xprt_end_transmit(task);
2236
+}
2237
+
2238
+static void
2239
+call_bc_transmit_status(struct rpc_task *task)
2240
+{
20552241 struct rpc_rqst *req = task->tk_rqstp;
20562242
2057
- if (!xprt_prepare_transmit(task))
2058
- goto out_retry;
2243
+ if (rpc_task_transmitted(task))
2244
+ task->tk_status = 0;
20592245
2060
- if (task->tk_status < 0) {
2061
- printk(KERN_NOTICE "RPC: Could not send backchannel reply "
2062
- "error: %d\n", task->tk_status);
2063
- goto out_done;
2064
- }
2065
- if (req->rq_connect_cookie != req->rq_xprt->connect_cookie)
2066
- req->rq_bytes_sent = 0;
2067
-
2068
- xprt_transmit(task);
2069
-
2070
- if (task->tk_status == -EAGAIN)
2071
- goto out_nospace;
2072
-
2073
- xprt_end_transmit(task);
2074
- dprint_status(task);
20752246 switch (task->tk_status) {
20762247 case 0:
20772248 /* Success */
....@@ -2085,6 +2256,15 @@
20852256 case -ENOTCONN:
20862257 case -EPIPE:
20872258 break;
2259
+ case -ENOMEM:
2260
+ case -ENOBUFS:
2261
+ rpc_delay(task, HZ>>2);
2262
+ fallthrough;
2263
+ case -EBADSLT:
2264
+ case -EAGAIN:
2265
+ task->tk_status = 0;
2266
+ task->tk_action = call_bc_transmit;
2267
+ return;
20882268 case -ETIMEDOUT:
20892269 /*
20902270 * Problem reaching the server. Disconnect and let the
....@@ -2103,19 +2283,11 @@
21032283 * We were unable to reply and will have to drop the
21042284 * request. The server should reconnect and retransmit.
21052285 */
2106
- WARN_ON_ONCE(task->tk_status == -EAGAIN);
21072286 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
21082287 "error: %d\n", task->tk_status);
21092288 break;
21102289 }
2111
- rpc_wake_up_queued_task(&req->rq_xprt->pending, task);
2112
-out_done:
21132290 task->tk_action = rpc_exit_task;
2114
- return;
2115
-out_nospace:
2116
- req->rq_connect_cookie = req->rq_xprt->connect_cookie;
2117
-out_retry:
2118
- task->tk_status = 0;
21192291 }
21202292 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
21212293
....@@ -2126,16 +2298,10 @@
21262298 call_status(struct rpc_task *task)
21272299 {
21282300 struct rpc_clnt *clnt = task->tk_client;
2129
- struct rpc_rqst *req = task->tk_rqstp;
21302301 int status;
21312302
21322303 if (!task->tk_msg.rpc_proc->p_proc)
21332304 trace_xprt_ping(task->tk_xprt, task->tk_status);
2134
-
2135
- if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent)
2136
- task->tk_status = req->rq_reply_bytes_recvd;
2137
-
2138
- dprint_status(task);
21392305
21402306 status = task->tk_status;
21412307 if (status >= 0) {
....@@ -2151,90 +2317,109 @@
21512317 case -EHOSTUNREACH:
21522318 case -ENETUNREACH:
21532319 case -EPERM:
2154
- if (RPC_IS_SOFTCONN(task)) {
2155
- rpc_exit(task, status);
2156
- break;
2157
- }
2320
+ if (RPC_IS_SOFTCONN(task))
2321
+ goto out_exit;
21582322 /*
21592323 * Delay any retries for 3 seconds, then handle as if it
21602324 * were a timeout.
21612325 */
21622326 rpc_delay(task, 3*HZ);
2163
- /* fall through */
2327
+ fallthrough;
21642328 case -ETIMEDOUT:
2165
- task->tk_action = call_timeout;
21662329 break;
21672330 case -ECONNREFUSED:
21682331 case -ECONNRESET:
21692332 case -ECONNABORTED:
2333
+ case -ENOTCONN:
21702334 rpc_force_rebind(clnt);
2171
- /* fall through */
2335
+ break;
21722336 case -EADDRINUSE:
21732337 rpc_delay(task, 3*HZ);
2174
- /* fall through */
2338
+ fallthrough;
21752339 case -EPIPE:
2176
- case -ENOTCONN:
2177
- task->tk_action = call_bind;
2178
- break;
2179
- case -ENOBUFS:
2180
- rpc_delay(task, HZ>>2);
2181
- /* fall through */
21822340 case -EAGAIN:
2183
- task->tk_action = call_transmit;
2341
+ break;
2342
+ case -ENFILE:
2343
+ case -ENOBUFS:
2344
+ case -ENOMEM:
2345
+ rpc_delay(task, HZ>>2);
21842346 break;
21852347 case -EIO:
21862348 /* shutdown or soft timeout */
2187
- rpc_exit(task, status);
2188
- break;
2349
+ goto out_exit;
21892350 default:
21902351 if (clnt->cl_chatty)
21912352 printk("%s: RPC call returned error %d\n",
21922353 clnt->cl_program->name, -status);
2193
- rpc_exit(task, status);
2354
+ goto out_exit;
21942355 }
2356
+ task->tk_action = call_encode;
2357
+ rpc_check_timeout(task);
2358
+ return;
2359
+out_exit:
2360
+ rpc_call_rpcerror(task, status);
21952361 }
21962362
2197
-/*
2198
- * 6a. Handle RPC timeout
2199
- * We do not release the request slot, so we keep using the
2200
- * same XID for all retransmits.
2201
- */
2363
+static bool
2364
+rpc_check_connected(const struct rpc_rqst *req)
2365
+{
2366
+ /* No allocated request or transport? return true */
2367
+ if (!req || !req->rq_xprt)
2368
+ return true;
2369
+ return xprt_connected(req->rq_xprt);
2370
+}
2371
+
22022372 static void
2203
-call_timeout(struct rpc_task *task)
2373
+rpc_check_timeout(struct rpc_task *task)
22042374 {
22052375 struct rpc_clnt *clnt = task->tk_client;
22062376
2207
- if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
2208
- dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid);
2209
- goto retry;
2210
- }
2211
-
2212
- dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
2213
- task->tk_timeouts++;
2214
-
2215
- if (RPC_IS_SOFTCONN(task)) {
2216
- rpc_exit(task, -ETIMEDOUT);
2377
+ if (RPC_SIGNALLED(task)) {
2378
+ rpc_call_rpcerror(task, -ERESTARTSYS);
22172379 return;
22182380 }
2381
+
2382
+ if (xprt_adjust_timeout(task->tk_rqstp) == 0)
2383
+ return;
2384
+
2385
+ trace_rpc_timeout_status(task);
2386
+ task->tk_timeouts++;
2387
+
2388
+ if (RPC_IS_SOFTCONN(task) && !rpc_check_connected(task->tk_rqstp)) {
2389
+ rpc_call_rpcerror(task, -ETIMEDOUT);
2390
+ return;
2391
+ }
2392
+
22192393 if (RPC_IS_SOFT(task)) {
2394
+ /*
2395
+ * Once a "no retrans timeout" soft tasks (a.k.a NFSv4) has
2396
+ * been sent, it should time out only if the transport
2397
+ * connection gets terminally broken.
2398
+ */
2399
+ if ((task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT) &&
2400
+ rpc_check_connected(task->tk_rqstp))
2401
+ return;
2402
+
22202403 if (clnt->cl_chatty) {
2221
- printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
2404
+ pr_notice_ratelimited(
2405
+ "%s: server %s not responding, timed out\n",
22222406 clnt->cl_program->name,
22232407 task->tk_xprt->servername);
22242408 }
22252409 if (task->tk_flags & RPC_TASK_TIMEOUT)
2226
- rpc_exit(task, -ETIMEDOUT);
2410
+ rpc_call_rpcerror(task, -ETIMEDOUT);
22272411 else
2228
- rpc_exit(task, -EIO);
2412
+ __rpc_call_rpcerror(task, -EIO, -ETIMEDOUT);
22292413 return;
22302414 }
22312415
22322416 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
22332417 task->tk_flags |= RPC_CALL_MAJORSEEN;
22342418 if (clnt->cl_chatty) {
2235
- printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
2236
- clnt->cl_program->name,
2237
- task->tk_xprt->servername);
2419
+ pr_notice_ratelimited(
2420
+ "%s: server %s not responding, still trying\n",
2421
+ clnt->cl_program->name,
2422
+ task->tk_xprt->servername);
22382423 }
22392424 }
22402425 rpc_force_rebind(clnt);
....@@ -2243,10 +2428,6 @@
22432428 * event? RFC2203 requires the server to drop all such requests.
22442429 */
22452430 rpcauth_invalcred(task);
2246
-
2247
-retry:
2248
- task->tk_action = call_bind;
2249
- task->tk_status = 0;
22502431 }
22512432
22522433 /*
....@@ -2257,14 +2438,17 @@
22572438 {
22582439 struct rpc_clnt *clnt = task->tk_client;
22592440 struct rpc_rqst *req = task->tk_rqstp;
2260
- kxdrdproc_t decode = task->tk_msg.rpc_proc->p_decode;
2261
- __be32 *p;
2441
+ struct xdr_stream xdr;
2442
+ int err;
22622443
2263
- dprint_status(task);
2444
+ if (!task->tk_msg.rpc_proc->p_decode) {
2445
+ task->tk_action = rpc_exit_task;
2446
+ return;
2447
+ }
22642448
22652449 if (task->tk_flags & RPC_CALL_MAJORSEEN) {
22662450 if (clnt->cl_chatty) {
2267
- printk(KERN_NOTICE "%s: server %s OK\n",
2451
+ pr_notice_ratelimited("%s: server %s OK\n",
22682452 clnt->cl_program->name,
22692453 task->tk_xprt->servername);
22702454 }
....@@ -2272,233 +2456,203 @@
22722456 }
22732457
22742458 /*
2275
- * Ensure that we see all writes made by xprt_complete_rqst()
2459
+ * Did we ever call xprt_complete_rqst()? If not, we should assume
2460
+ * the message is incomplete.
2461
+ */
2462
+ err = -EAGAIN;
2463
+ if (!req->rq_reply_bytes_recvd)
2464
+ goto out;
2465
+
2466
+ /* Ensure that we see all writes made by xprt_complete_rqst()
22762467 * before it changed req->rq_reply_bytes_recvd.
22772468 */
22782469 smp_rmb();
2470
+
22792471 req->rq_rcv_buf.len = req->rq_private_buf.len;
2472
+ trace_rpc_xdr_recvfrom(task, &req->rq_rcv_buf);
22802473
22812474 /* Check that the softirq receive buffer is valid */
22822475 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
22832476 sizeof(req->rq_rcv_buf)) != 0);
22842477
2285
- if (req->rq_rcv_buf.len < 12) {
2286
- if (!RPC_IS_SOFT(task)) {
2287
- task->tk_action = call_bind;
2288
- goto out_retry;
2289
- }
2290
- dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
2291
- clnt->cl_program->name, task->tk_status);
2292
- task->tk_action = call_timeout;
2293
- goto out_retry;
2294
- }
2295
-
2296
- p = rpc_verify_header(task);
2297
- if (IS_ERR(p)) {
2298
- if (p == ERR_PTR(-EAGAIN))
2299
- goto out_retry;
2478
+ xdr_init_decode(&xdr, &req->rq_rcv_buf,
2479
+ req->rq_rcv_buf.head[0].iov_base, req);
2480
+ err = rpc_decode_header(task, &xdr);
2481
+out:
2482
+ switch (err) {
2483
+ case 0:
2484
+ task->tk_action = rpc_exit_task;
2485
+ task->tk_status = rpcauth_unwrap_resp(task, &xdr);
23002486 return;
2301
- }
2302
-
2303
- task->tk_action = rpc_exit_task;
2304
-
2305
- if (decode) {
2306
- task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
2307
- task->tk_msg.rpc_resp);
2308
- }
2309
- dprintk("RPC: %5u call_decode result %d\n", task->tk_pid,
2310
- task->tk_status);
2311
- return;
2312
-out_retry:
2313
- task->tk_status = 0;
2314
- /* Note: rpc_verify_header() may have freed the RPC slot */
2315
- if (task->tk_rqstp == req) {
2316
- req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0;
2487
+ case -EAGAIN:
2488
+ task->tk_status = 0;
23172489 if (task->tk_client->cl_discrtry)
23182490 xprt_conditional_disconnect(req->rq_xprt,
2319
- req->rq_connect_cookie);
2491
+ req->rq_connect_cookie);
2492
+ task->tk_action = call_encode;
2493
+ rpc_check_timeout(task);
2494
+ break;
2495
+ case -EKEYREJECTED:
2496
+ task->tk_action = call_reserve;
2497
+ rpc_check_timeout(task);
2498
+ rpcauth_invalcred(task);
2499
+ /* Ensure we obtain a new XID if we retry! */
2500
+ xprt_release(task);
23202501 }
23212502 }
23222503
2323
-static __be32 *
2324
-rpc_encode_header(struct rpc_task *task)
2504
+static int
2505
+rpc_encode_header(struct rpc_task *task, struct xdr_stream *xdr)
23252506 {
23262507 struct rpc_clnt *clnt = task->tk_client;
23272508 struct rpc_rqst *req = task->tk_rqstp;
2328
- __be32 *p = req->rq_svec[0].iov_base;
2509
+ __be32 *p;
2510
+ int error;
23292511
2330
- /* FIXME: check buffer size? */
2512
+ error = -EMSGSIZE;
2513
+ p = xdr_reserve_space(xdr, RPC_CALLHDRSIZE << 2);
2514
+ if (!p)
2515
+ goto out_fail;
2516
+ *p++ = req->rq_xid;
2517
+ *p++ = rpc_call;
2518
+ *p++ = cpu_to_be32(RPC_VERSION);
2519
+ *p++ = cpu_to_be32(clnt->cl_prog);
2520
+ *p++ = cpu_to_be32(clnt->cl_vers);
2521
+ *p = cpu_to_be32(task->tk_msg.rpc_proc->p_proc);
23312522
2332
- p = xprt_skip_transport_header(req->rq_xprt, p);
2333
- *p++ = req->rq_xid; /* XID */
2334
- *p++ = htonl(RPC_CALL); /* CALL */
2335
- *p++ = htonl(RPC_VERSION); /* RPC version */
2336
- *p++ = htonl(clnt->cl_prog); /* program number */
2337
- *p++ = htonl(clnt->cl_vers); /* program version */
2338
- *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
2339
- p = rpcauth_marshcred(task, p);
2340
- req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
2341
- return p;
2523
+ error = rpcauth_marshcred(task, xdr);
2524
+ if (error < 0)
2525
+ goto out_fail;
2526
+ return 0;
2527
+out_fail:
2528
+ trace_rpc_bad_callhdr(task);
2529
+ rpc_call_rpcerror(task, error);
2530
+ return error;
23422531 }
23432532
2344
-static __be32 *
2345
-rpc_verify_header(struct rpc_task *task)
2533
+static noinline int
2534
+rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)
23462535 {
23472536 struct rpc_clnt *clnt = task->tk_client;
2348
- struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
2349
- int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
2350
- __be32 *p = iov->iov_base;
2351
- u32 n;
2352
- int error = -EACCES;
2537
+ int error;
2538
+ __be32 *p;
23532539
2354
- if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
2355
- /* RFC-1014 says that the representation of XDR data must be a
2356
- * multiple of four bytes
2357
- * - if it isn't pointer subtraction in the NFS client may give
2358
- * undefined results
2359
- */
2360
- dprintk("RPC: %5u %s: XDR representation not a multiple of"
2361
- " 4 bytes: 0x%x\n", task->tk_pid, __func__,
2362
- task->tk_rqstp->rq_rcv_buf.len);
2363
- error = -EIO;
2364
- goto out_err;
2365
- }
2366
- if ((len -= 3) < 0)
2367
- goto out_overflow;
2540
+ /* RFC-1014 says that the representation of XDR data must be a
2541
+ * multiple of four bytes
2542
+ * - if it isn't pointer subtraction in the NFS client may give
2543
+ * undefined results
2544
+ */
2545
+ if (task->tk_rqstp->rq_rcv_buf.len & 3)
2546
+ goto out_unparsable;
23682547
2369
- p += 1; /* skip XID */
2370
- if ((n = ntohl(*p++)) != RPC_REPLY) {
2371
- dprintk("RPC: %5u %s: not an RPC reply: %x\n",
2372
- task->tk_pid, __func__, n);
2373
- error = -EIO;
2374
- goto out_garbage;
2375
- }
2548
+ p = xdr_inline_decode(xdr, 3 * sizeof(*p));
2549
+ if (!p)
2550
+ goto out_unparsable;
2551
+ p++; /* skip XID */
2552
+ if (*p++ != rpc_reply)
2553
+ goto out_unparsable;
2554
+ if (*p++ != rpc_msg_accepted)
2555
+ goto out_msg_denied;
23762556
2377
- if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
2378
- if (--len < 0)
2379
- goto out_overflow;
2380
- switch ((n = ntohl(*p++))) {
2381
- case RPC_AUTH_ERROR:
2382
- break;
2383
- case RPC_MISMATCH:
2384
- dprintk("RPC: %5u %s: RPC call version mismatch!\n",
2385
- task->tk_pid, __func__);
2386
- error = -EPROTONOSUPPORT;
2387
- goto out_err;
2388
- default:
2389
- dprintk("RPC: %5u %s: RPC call rejected, "
2390
- "unknown error: %x\n",
2391
- task->tk_pid, __func__, n);
2392
- error = -EIO;
2393
- goto out_err;
2394
- }
2395
- if (--len < 0)
2396
- goto out_overflow;
2397
- switch ((n = ntohl(*p++))) {
2398
- case RPC_AUTH_REJECTEDCRED:
2399
- case RPC_AUTH_REJECTEDVERF:
2400
- case RPCSEC_GSS_CREDPROBLEM:
2401
- case RPCSEC_GSS_CTXPROBLEM:
2402
- if (!task->tk_cred_retry)
2403
- break;
2404
- task->tk_cred_retry--;
2405
- dprintk("RPC: %5u %s: retry stale creds\n",
2406
- task->tk_pid, __func__);
2407
- rpcauth_invalcred(task);
2408
- /* Ensure we obtain a new XID! */
2409
- xprt_release(task);
2410
- task->tk_action = call_reserve;
2411
- goto out_retry;
2412
- case RPC_AUTH_BADCRED:
2413
- case RPC_AUTH_BADVERF:
2414
- /* possibly garbled cred/verf? */
2415
- if (!task->tk_garb_retry)
2416
- break;
2417
- task->tk_garb_retry--;
2418
- dprintk("RPC: %5u %s: retry garbled creds\n",
2419
- task->tk_pid, __func__);
2420
- task->tk_action = call_bind;
2421
- goto out_retry;
2422
- case RPC_AUTH_TOOWEAK:
2423
- printk(KERN_NOTICE "RPC: server %s requires stronger "
2424
- "authentication.\n",
2425
- task->tk_xprt->servername);
2426
- break;
2427
- default:
2428
- dprintk("RPC: %5u %s: unknown auth error: %x\n",
2429
- task->tk_pid, __func__, n);
2430
- error = -EIO;
2431
- }
2432
- dprintk("RPC: %5u %s: call rejected %d\n",
2433
- task->tk_pid, __func__, n);
2434
- goto out_err;
2435
- }
2436
- p = rpcauth_checkverf(task, p);
2437
- if (IS_ERR(p)) {
2438
- error = PTR_ERR(p);
2439
- dprintk("RPC: %5u %s: auth check failed with %d\n",
2440
- task->tk_pid, __func__, error);
2441
- goto out_garbage; /* bad verifier, retry */
2442
- }
2443
- len = p - (__be32 *)iov->iov_base - 1;
2444
- if (len < 0)
2445
- goto out_overflow;
2446
- switch ((n = ntohl(*p++))) {
2447
- case RPC_SUCCESS:
2448
- return p;
2449
- case RPC_PROG_UNAVAIL:
2450
- dprintk("RPC: %5u %s: program %u is unsupported "
2451
- "by server %s\n", task->tk_pid, __func__,
2452
- (unsigned int)clnt->cl_prog,
2453
- task->tk_xprt->servername);
2557
+ error = rpcauth_checkverf(task, xdr);
2558
+ if (error)
2559
+ goto out_verifier;
2560
+
2561
+ p = xdr_inline_decode(xdr, sizeof(*p));
2562
+ if (!p)
2563
+ goto out_unparsable;
2564
+ switch (*p) {
2565
+ case rpc_success:
2566
+ return 0;
2567
+ case rpc_prog_unavail:
2568
+ trace_rpc__prog_unavail(task);
24542569 error = -EPFNOSUPPORT;
24552570 goto out_err;
2456
- case RPC_PROG_MISMATCH:
2457
- dprintk("RPC: %5u %s: program %u, version %u unsupported "
2458
- "by server %s\n", task->tk_pid, __func__,
2459
- (unsigned int)clnt->cl_prog,
2460
- (unsigned int)clnt->cl_vers,
2461
- task->tk_xprt->servername);
2571
+ case rpc_prog_mismatch:
2572
+ trace_rpc__prog_mismatch(task);
24622573 error = -EPROTONOSUPPORT;
24632574 goto out_err;
2464
- case RPC_PROC_UNAVAIL:
2465
- dprintk("RPC: %5u %s: proc %s unsupported by program %u, "
2466
- "version %u on server %s\n",
2467
- task->tk_pid, __func__,
2468
- rpc_proc_name(task),
2469
- clnt->cl_prog, clnt->cl_vers,
2470
- task->tk_xprt->servername);
2575
+ case rpc_proc_unavail:
2576
+ trace_rpc__proc_unavail(task);
24712577 error = -EOPNOTSUPP;
24722578 goto out_err;
2473
- case RPC_GARBAGE_ARGS:
2474
- dprintk("RPC: %5u %s: server saw garbage\n",
2475
- task->tk_pid, __func__);
2476
- break; /* retry */
2579
+ case rpc_garbage_args:
2580
+ case rpc_system_err:
2581
+ trace_rpc__garbage_args(task);
2582
+ error = -EIO;
2583
+ break;
24772584 default:
2478
- dprintk("RPC: %5u %s: server accept status: %x\n",
2479
- task->tk_pid, __func__, n);
2480
- /* Also retry */
2585
+ goto out_unparsable;
24812586 }
24822587
24832588 out_garbage:
24842589 clnt->cl_stats->rpcgarbage++;
24852590 if (task->tk_garb_retry) {
24862591 task->tk_garb_retry--;
2487
- dprintk("RPC: %5u %s: retrying\n",
2488
- task->tk_pid, __func__);
2489
- task->tk_action = call_bind;
2490
-out_retry:
2491
- return ERR_PTR(-EAGAIN);
2592
+ task->tk_action = call_encode;
2593
+ return -EAGAIN;
24922594 }
24932595 out_err:
2494
- rpc_exit(task, error);
2495
- dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid,
2496
- __func__, error);
2497
- return ERR_PTR(error);
2498
-out_overflow:
2499
- dprintk("RPC: %5u %s: server reply was truncated.\n", task->tk_pid,
2500
- __func__);
2596
+ rpc_call_rpcerror(task, error);
2597
+ return error;
2598
+
2599
+out_unparsable:
2600
+ trace_rpc__unparsable(task);
2601
+ error = -EIO;
25012602 goto out_garbage;
2603
+
2604
+out_verifier:
2605
+ trace_rpc_bad_verifier(task);
2606
+ goto out_garbage;
2607
+
2608
+out_msg_denied:
2609
+ error = -EACCES;
2610
+ p = xdr_inline_decode(xdr, sizeof(*p));
2611
+ if (!p)
2612
+ goto out_unparsable;
2613
+ switch (*p++) {
2614
+ case rpc_auth_error:
2615
+ break;
2616
+ case rpc_mismatch:
2617
+ trace_rpc__mismatch(task);
2618
+ error = -EPROTONOSUPPORT;
2619
+ goto out_err;
2620
+ default:
2621
+ goto out_unparsable;
2622
+ }
2623
+
2624
+ p = xdr_inline_decode(xdr, sizeof(*p));
2625
+ if (!p)
2626
+ goto out_unparsable;
2627
+ switch (*p++) {
2628
+ case rpc_autherr_rejectedcred:
2629
+ case rpc_autherr_rejectedverf:
2630
+ case rpcsec_gsserr_credproblem:
2631
+ case rpcsec_gsserr_ctxproblem:
2632
+ rpcauth_invalcred(task);
2633
+ if (!task->tk_cred_retry)
2634
+ break;
2635
+ task->tk_cred_retry--;
2636
+ trace_rpc__stale_creds(task);
2637
+ return -EKEYREJECTED;
2638
+ case rpc_autherr_badcred:
2639
+ case rpc_autherr_badverf:
2640
+ /* possibly garbled cred/verf? */
2641
+ if (!task->tk_garb_retry)
2642
+ break;
2643
+ task->tk_garb_retry--;
2644
+ trace_rpc__bad_creds(task);
2645
+ task->tk_action = call_encode;
2646
+ return -EAGAIN;
2647
+ case rpc_autherr_tooweak:
2648
+ trace_rpc__auth_tooweak(task);
2649
+ pr_warn("RPC: server %s requires stronger authentication.\n",
2650
+ task->tk_xprt->servername);
2651
+ break;
2652
+ default:
2653
+ goto out_unparsable;
2654
+ }
2655
+ goto out_err;
25022656 }
25032657
25042658 static void rpcproc_encode_null(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
....@@ -2523,9 +2677,8 @@
25232677 .rpc_proc = &rpcproc_null,
25242678 };
25252679 int err;
2526
- msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
2527
- err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN);
2528
- put_rpccred(msg.rpc_cred);
2680
+ err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN |
2681
+ RPC_TASK_NULLCREDS);
25292682 return err;
25302683 }
25312684
....@@ -2536,15 +2689,16 @@
25362689 {
25372690 struct rpc_message msg = {
25382691 .rpc_proc = &rpcproc_null,
2539
- .rpc_cred = cred,
25402692 };
25412693 struct rpc_task_setup task_setup_data = {
25422694 .rpc_client = clnt,
25432695 .rpc_xprt = xprt,
25442696 .rpc_message = &msg,
2697
+ .rpc_op_cred = cred,
25452698 .callback_ops = (ops != NULL) ? ops : &rpc_default_ops,
25462699 .callback_data = data,
2547
- .flags = flags,
2700
+ .flags = flags | RPC_TASK_SOFT | RPC_TASK_SOFTCONN |
2701
+ RPC_TASK_NULLCREDS,
25482702 };
25492703
25502704 return rpc_run_task(&task_setup_data);
....@@ -2595,7 +2749,6 @@
25952749 void *dummy)
25962750 {
25972751 struct rpc_cb_add_xprt_calldata *data;
2598
- struct rpc_cred *cred;
25992752 struct rpc_task *task;
26002753
26012754 data = kmalloc(sizeof(*data), GFP_NOFS);
....@@ -2603,15 +2756,16 @@
26032756 return -ENOMEM;
26042757 data->xps = xprt_switch_get(xps);
26052758 data->xprt = xprt_get(xprt);
2759
+ if (rpc_xprt_switch_has_addr(data->xps, (struct sockaddr *)&xprt->addr)) {
2760
+ rpc_cb_add_xprt_release(data);
2761
+ goto success;
2762
+ }
26062763
2607
- cred = authnull_ops.lookup_cred(NULL, NULL, 0);
2608
- task = rpc_call_null_helper(clnt, xprt, cred,
2609
- RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC,
2764
+ task = rpc_call_null_helper(clnt, xprt, NULL, RPC_TASK_ASYNC,
26102765 &rpc_cb_add_xprt_call_ops, data);
2611
- put_rpccred(cred);
2612
- if (IS_ERR(task))
2613
- return PTR_ERR(task);
2766
+
26142767 rpc_put_task(task);
2768
+success:
26152769 return 1;
26162770 }
26172771 EXPORT_SYMBOL_GPL(rpc_clnt_test_and_add_xprt);
....@@ -2639,7 +2793,6 @@
26392793 struct rpc_xprt *xprt,
26402794 void *data)
26412795 {
2642
- struct rpc_cred *cred;
26432796 struct rpc_task *task;
26442797 struct rpc_add_xprt_test *xtest = (struct rpc_add_xprt_test *)data;
26452798 int status = -EADDRINUSE;
....@@ -2651,11 +2804,7 @@
26512804 goto out_err;
26522805
26532806 /* Test the connection */
2654
- cred = authnull_ops.lookup_cred(NULL, NULL, 0);
2655
- task = rpc_call_null_helper(clnt, xprt, cred,
2656
- RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
2657
- NULL, NULL);
2658
- put_rpccred(cred);
2807
+ task = rpc_call_null_helper(clnt, xprt, NULL, 0, NULL, NULL);
26592808 if (IS_ERR(task)) {
26602809 status = PTR_ERR(task);
26612810 goto out_err;
....@@ -2668,6 +2817,9 @@
26682817
26692818 /* rpc_xprt_switch and rpc_xprt are deferrenced by add_xprt_test() */
26702819 xtest->add_xprt_test(clnt, xprt, xtest->data);
2820
+
2821
+ xprt_put(xprt);
2822
+ xprt_switch_put(xps);
26712823
26722824 /* so that rpc_clnt_add_xprt does not call rpc_xprt_switch_add_xprt */
26732825 return 1;
....@@ -2705,7 +2857,7 @@
27052857 struct rpc_xprt *xprt;
27062858 unsigned long connect_timeout;
27072859 unsigned long reconnect_timeout;
2708
- unsigned char resvport;
2860
+ unsigned char resvport, reuseport;
27092861 int ret = 0;
27102862
27112863 rcu_read_lock();
....@@ -2717,6 +2869,7 @@
27172869 return -EAGAIN;
27182870 }
27192871 resvport = xprt->resvport;
2872
+ reuseport = xprt->reuseport;
27202873 connect_timeout = xprt->connect_timeout;
27212874 reconnect_timeout = xprt->max_reconnect_timeout;
27222875 rcu_read_unlock();
....@@ -2727,6 +2880,7 @@
27272880 goto out_put_switch;
27282881 }
27292882 xprt->resvport = resvport;
2883
+ xprt->reuseport = reuseport;
27302884 if (xprt->ops->set_connect_timeout != NULL)
27312885 xprt->ops->set_connect_timeout(xprt,
27322886 connect_timeout,
....@@ -2829,7 +2983,7 @@
28292983
28302984 printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n",
28312985 task->tk_pid, task->tk_flags, task->tk_status,
2832
- clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops,
2986
+ clnt, task->tk_rqstp, rpc_task_timeout(task), task->tk_ops,
28332987 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
28342988 task->tk_action, rpc_waitq);
28352989 }
....@@ -2869,6 +3023,8 @@
28693023 int
28703024 rpc_clnt_swap_activate(struct rpc_clnt *clnt)
28713025 {
3026
+ while (clnt != clnt->cl_parent)
3027
+ clnt = clnt->cl_parent;
28723028 if (atomic_inc_return(&clnt->cl_swapper) == 1)
28733029 return rpc_clnt_iterate_for_each_xprt(clnt,
28743030 rpc_clnt_swap_activate_callback, NULL);
....@@ -2888,6 +3044,8 @@
28883044 void
28893045 rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
28903046 {
3047
+ while (clnt != clnt->cl_parent)
3048
+ clnt = clnt->cl_parent;
28913049 if (atomic_dec_if_positive(&clnt->cl_swapper) == 0)
28923050 rpc_clnt_iterate_for_each_xprt(clnt,
28933051 rpc_clnt_swap_deactivate_callback, NULL);