.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/net/sunrpc/clnt.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
46 | 47 | # define RPCDBG_FACILITY RPCDBG_CALL |
---|
47 | 48 | #endif |
---|
48 | 49 | |
---|
49 | | -#define dprint_status(t) \ |
---|
50 | | - dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \ |
---|
51 | | - __func__, t->tk_status) |
---|
52 | | - |
---|
53 | 50 | /* |
---|
54 | 51 | * All RPC clients are linked into this list |
---|
55 | 52 | */ |
---|
.. | .. |
---|
61 | 58 | static void call_reserve(struct rpc_task *task); |
---|
62 | 59 | static void call_reserveresult(struct rpc_task *task); |
---|
63 | 60 | static void call_allocate(struct rpc_task *task); |
---|
| 61 | +static void call_encode(struct rpc_task *task); |
---|
64 | 62 | static void call_decode(struct rpc_task *task); |
---|
65 | 63 | static void call_bind(struct rpc_task *task); |
---|
66 | 64 | static void call_bind_status(struct rpc_task *task); |
---|
67 | 65 | 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 */ |
---|
71 | 66 | static void call_status(struct rpc_task *task); |
---|
72 | 67 | static void call_transmit_status(struct rpc_task *task); |
---|
73 | 68 | static void call_refresh(struct rpc_task *task); |
---|
74 | 69 | static void call_refreshresult(struct rpc_task *task); |
---|
75 | | -static void call_timeout(struct rpc_task *task); |
---|
76 | 70 | static void call_connect(struct rpc_task *task); |
---|
77 | 71 | static void call_connect_status(struct rpc_task *task); |
---|
78 | 72 | |
---|
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); |
---|
81 | 77 | static int rpc_ping(struct rpc_clnt *clnt); |
---|
| 78 | +static void rpc_check_timeout(struct rpc_task *task); |
---|
82 | 79 | |
---|
83 | 80 | static void rpc_register_client(struct rpc_clnt *clnt) |
---|
84 | 81 | { |
---|
.. | .. |
---|
369 | 366 | const char *nodename = args->nodename; |
---|
370 | 367 | int err; |
---|
371 | 368 | |
---|
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 | | - |
---|
376 | 369 | err = rpciod_up(); |
---|
377 | 370 | if (err) |
---|
378 | 371 | goto out_no_rpciod; |
---|
.. | .. |
---|
394 | 387 | if (err) |
---|
395 | 388 | goto out_no_clid; |
---|
396 | 389 | |
---|
| 390 | + clnt->cl_cred = get_cred(args->cred); |
---|
397 | 391 | clnt->cl_procinfo = version->procs; |
---|
398 | 392 | clnt->cl_maxproc = version->nrprocs; |
---|
399 | 393 | clnt->cl_prog = args->prognumber ? : program->number; |
---|
.. | .. |
---|
434 | 428 | goto out_no_path; |
---|
435 | 429 | if (parent) |
---|
436 | 430 | atomic_inc(&parent->cl_count); |
---|
| 431 | + |
---|
| 432 | + trace_rpc_clnt_new(clnt, xprt, program->name, args->servername); |
---|
437 | 433 | return clnt; |
---|
438 | 434 | |
---|
439 | 435 | out_no_path: |
---|
440 | 436 | rpc_free_iostats(clnt->cl_metrics); |
---|
441 | 437 | out_no_stats: |
---|
| 438 | + put_cred(clnt->cl_cred); |
---|
442 | 439 | rpc_free_clid(clnt); |
---|
443 | 440 | out_no_clid: |
---|
444 | 441 | kfree(clnt); |
---|
.. | .. |
---|
447 | 444 | out_no_rpciod: |
---|
448 | 445 | xprt_switch_put(xps); |
---|
449 | 446 | xprt_put(xprt); |
---|
| 447 | + trace_rpc_clnt_new_err(program->name, args->servername, err); |
---|
450 | 448 | return ERR_PTR(err); |
---|
451 | 449 | } |
---|
452 | 450 | |
---|
.. | .. |
---|
484 | 482 | } |
---|
485 | 483 | |
---|
486 | 484 | clnt->cl_softrtry = 1; |
---|
487 | | - if (args->flags & RPC_CLNT_CREATE_HARDRTRY) |
---|
| 485 | + if (args->flags & (RPC_CLNT_CREATE_HARDRTRY|RPC_CLNT_CREATE_SOFTERR)) { |
---|
488 | 486 | clnt->cl_softrtry = 0; |
---|
| 487 | + if (args->flags & RPC_CLNT_CREATE_SOFTERR) |
---|
| 488 | + clnt->cl_softerr = 1; |
---|
| 489 | + } |
---|
489 | 490 | |
---|
490 | 491 | if (args->flags & RPC_CLNT_CREATE_AUTOBIND) |
---|
491 | 492 | clnt->cl_autobind = 1; |
---|
.. | .. |
---|
522 | 523 | .bc_xprt = args->bc_xprt, |
---|
523 | 524 | }; |
---|
524 | 525 | char servername[48]; |
---|
| 526 | + struct rpc_clnt *clnt; |
---|
| 527 | + int i; |
---|
525 | 528 | |
---|
526 | 529 | if (args->bc_xprt) { |
---|
527 | 530 | WARN_ON_ONCE(!(args->protocol & XPRT_TRANSPORT_BC)); |
---|
.. | .. |
---|
583 | 586 | xprt->resvport = 1; |
---|
584 | 587 | if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT) |
---|
585 | 588 | xprt->resvport = 0; |
---|
| 589 | + xprt->reuseport = 0; |
---|
| 590 | + if (args->flags & RPC_CLNT_CREATE_REUSEPORT) |
---|
| 591 | + xprt->reuseport = 1; |
---|
586 | 592 | |
---|
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; |
---|
588 | 602 | } |
---|
589 | 603 | EXPORT_SYMBOL_GPL(rpc_create); |
---|
590 | 604 | |
---|
.. | .. |
---|
615 | 629 | args->nodename = clnt->cl_nodename; |
---|
616 | 630 | |
---|
617 | 631 | 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; |
---|
622 | 634 | |
---|
623 | 635 | /* Turn off autobind on clones */ |
---|
624 | 636 | new->cl_autobind = 0; |
---|
625 | 637 | new->cl_softrtry = clnt->cl_softrtry; |
---|
| 638 | + new->cl_softerr = clnt->cl_softerr; |
---|
626 | 639 | new->cl_noretranstimeo = clnt->cl_noretranstimeo; |
---|
627 | 640 | new->cl_discrtry = clnt->cl_discrtry; |
---|
628 | 641 | new->cl_chatty = clnt->cl_chatty; |
---|
| 642 | + new->cl_principal = clnt->cl_principal; |
---|
629 | 643 | return new; |
---|
630 | 644 | |
---|
631 | 645 | out_err: |
---|
632 | | - dprintk("RPC: %s: returned error %d\n", __func__, err); |
---|
| 646 | + trace_rpc_clnt_clone_err(clnt, err); |
---|
633 | 647 | return ERR_PTR(err); |
---|
634 | 648 | } |
---|
635 | 649 | |
---|
.. | .. |
---|
647 | 661 | .prognumber = clnt->cl_prog, |
---|
648 | 662 | .version = clnt->cl_vers, |
---|
649 | 663 | .authflavor = clnt->cl_auth->au_flavor, |
---|
| 664 | + .cred = clnt->cl_cred, |
---|
650 | 665 | }; |
---|
651 | 666 | return __rpc_clone_client(&args, clnt); |
---|
652 | 667 | } |
---|
.. | .. |
---|
668 | 683 | .prognumber = clnt->cl_prog, |
---|
669 | 684 | .version = clnt->cl_vers, |
---|
670 | 685 | .authflavor = flavor, |
---|
| 686 | + .cred = clnt->cl_cred, |
---|
671 | 687 | }; |
---|
672 | 688 | return __rpc_clone_client(&args, clnt); |
---|
673 | 689 | } |
---|
.. | .. |
---|
700 | 716 | int err; |
---|
701 | 717 | |
---|
702 | 718 | 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)) |
---|
706 | 720 | return PTR_ERR(xprt); |
---|
707 | | - } |
---|
708 | 721 | |
---|
709 | 722 | xps = xprt_switch_alloc(xprt, GFP_KERNEL); |
---|
710 | 723 | if (xps == NULL) { |
---|
.. | .. |
---|
744 | 757 | rpc_release_client(parent); |
---|
745 | 758 | xprt_switch_put(oldxps); |
---|
746 | 759 | xprt_put(old); |
---|
747 | | - dprintk("RPC: replaced xprt for clnt %p\n", clnt); |
---|
| 760 | + trace_rpc_clnt_replace_xprt(clnt); |
---|
748 | 761 | return 0; |
---|
749 | 762 | |
---|
750 | 763 | out_revert: |
---|
.. | .. |
---|
754 | 767 | rpc_client_register(clnt, pseudoflavor, NULL); |
---|
755 | 768 | xprt_switch_put(xps); |
---|
756 | 769 | xprt_put(xprt); |
---|
757 | | - dprintk("RPC: failed to switch xprt for clnt %p\n", clnt); |
---|
| 770 | + trace_rpc_clnt_replace_xprt_err(clnt); |
---|
758 | 771 | return err; |
---|
759 | 772 | } |
---|
760 | 773 | EXPORT_SYMBOL_GPL(rpc_switch_client_transport); |
---|
.. | .. |
---|
821 | 834 | |
---|
822 | 835 | if (list_empty(&clnt->cl_tasks)) |
---|
823 | 836 | return; |
---|
824 | | - dprintk("RPC: killing all tasks for client %p\n", clnt); |
---|
| 837 | + |
---|
825 | 838 | /* |
---|
826 | 839 | * Spin lock all_tasks to prevent changes... |
---|
827 | 840 | */ |
---|
| 841 | + trace_rpc_clnt_killall(clnt); |
---|
828 | 842 | 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); |
---|
840 | 845 | spin_unlock(&clnt->cl_lock); |
---|
841 | 846 | } |
---|
842 | 847 | EXPORT_SYMBOL_GPL(rpc_killall_tasks); |
---|
.. | .. |
---|
849 | 854 | { |
---|
850 | 855 | might_sleep(); |
---|
851 | 856 | |
---|
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); |
---|
855 | 858 | |
---|
856 | 859 | while (!list_empty(&clnt->cl_tasks)) { |
---|
857 | 860 | rpc_killall_tasks(clnt); |
---|
.. | .. |
---|
866 | 869 | /* |
---|
867 | 870 | * Free an RPC client |
---|
868 | 871 | */ |
---|
| 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 | +} |
---|
869 | 890 | static struct rpc_clnt * |
---|
870 | 891 | rpc_free_client(struct rpc_clnt *clnt) |
---|
871 | 892 | { |
---|
872 | 893 | struct rpc_clnt *parent = NULL; |
---|
873 | 894 | |
---|
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); |
---|
877 | 896 | if (clnt->cl_parent != clnt) |
---|
878 | 897 | parent = clnt->cl_parent; |
---|
879 | | - rpc_clnt_debugfs_unregister(clnt); |
---|
880 | | - rpc_clnt_remove_pipedir(clnt); |
---|
881 | 898 | rpc_unregister_client(clnt); |
---|
882 | 899 | rpc_free_iostats(clnt->cl_metrics); |
---|
883 | 900 | clnt->cl_metrics = NULL; |
---|
884 | | - xprt_put(rcu_dereference_raw(clnt->cl_xprt)); |
---|
885 | 901 | 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); |
---|
889 | 906 | return parent; |
---|
890 | 907 | } |
---|
891 | 908 | |
---|
.. | .. |
---|
917 | 934 | void |
---|
918 | 935 | rpc_release_client(struct rpc_clnt *clnt) |
---|
919 | 936 | { |
---|
920 | | - dprintk("RPC: rpc_release_client(%p)\n", clnt); |
---|
921 | | - |
---|
922 | 937 | do { |
---|
923 | 938 | if (list_empty(&clnt->cl_tasks)) |
---|
924 | 939 | wake_up(&destroy_wait); |
---|
.. | .. |
---|
948 | 963 | .prognumber = program->number, |
---|
949 | 964 | .version = vers, |
---|
950 | 965 | .authflavor = old->cl_auth->au_flavor, |
---|
| 966 | + .cred = old->cl_cred, |
---|
951 | 967 | }; |
---|
952 | 968 | struct rpc_clnt *clnt; |
---|
953 | 969 | int err; |
---|
.. | .. |
---|
965 | 981 | } |
---|
966 | 982 | EXPORT_SYMBOL_GPL(rpc_bind_new_program); |
---|
967 | 983 | |
---|
| 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 | + |
---|
968 | 1014 | void rpc_task_release_transport(struct rpc_task *task) |
---|
969 | 1015 | { |
---|
970 | 1016 | struct rpc_xprt *xprt = task->tk_xprt; |
---|
971 | 1017 | |
---|
972 | 1018 | if (xprt) { |
---|
973 | 1019 | 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); |
---|
975 | 1024 | } |
---|
976 | 1025 | } |
---|
977 | 1026 | EXPORT_SYMBOL_GPL(rpc_task_release_transport); |
---|
.. | .. |
---|
980 | 1029 | { |
---|
981 | 1030 | struct rpc_clnt *clnt = task->tk_client; |
---|
982 | 1031 | |
---|
| 1032 | + rpc_task_release_transport(task); |
---|
983 | 1033 | if (clnt != NULL) { |
---|
984 | 1034 | /* Remove from client task list */ |
---|
985 | 1035 | spin_lock(&clnt->cl_lock); |
---|
.. | .. |
---|
989 | 1039 | |
---|
990 | 1040 | rpc_release_client(clnt); |
---|
991 | 1041 | } |
---|
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)); |
---|
993 | 1059 | } |
---|
994 | 1060 | |
---|
995 | 1061 | static |
---|
996 | 1062 | void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt) |
---|
997 | 1063 | { |
---|
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); |
---|
1000 | 1070 | } |
---|
1001 | 1071 | |
---|
1002 | 1072 | static |
---|
.. | .. |
---|
1009 | 1079 | atomic_inc(&clnt->cl_count); |
---|
1010 | 1080 | if (clnt->cl_softrtry) |
---|
1011 | 1081 | task->tk_flags |= RPC_TASK_SOFT; |
---|
| 1082 | + if (clnt->cl_softerr) |
---|
| 1083 | + task->tk_flags |= RPC_TASK_TIMEOUT; |
---|
1012 | 1084 | if (clnt->cl_noretranstimeo) |
---|
1013 | 1085 | task->tk_flags |= RPC_TASK_NO_RETRANS_TIMEOUT; |
---|
1014 | 1086 | if (atomic_read(&clnt->cl_swapper)) |
---|
.. | .. |
---|
1027 | 1099 | task->tk_msg.rpc_proc = msg->rpc_proc; |
---|
1028 | 1100 | task->tk_msg.rpc_argp = msg->rpc_argp; |
---|
1029 | 1101 | 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); |
---|
1032 | 1105 | } |
---|
1033 | 1106 | } |
---|
1034 | 1107 | |
---|
.. | .. |
---|
1053 | 1126 | struct rpc_task *task; |
---|
1054 | 1127 | |
---|
1055 | 1128 | task = rpc_new_task(task_setup_data); |
---|
| 1129 | + |
---|
| 1130 | + if (!RPC_IS_ASYNC(task)) |
---|
| 1131 | + task->tk_flags |= RPC_TASK_CRED_NOREF; |
---|
1056 | 1132 | |
---|
1057 | 1133 | rpc_task_set_client(task, task_setup_data->rpc_client); |
---|
1058 | 1134 | rpc_task_set_rpc_message(task, task_setup_data->rpc_message); |
---|
.. | .. |
---|
1129 | 1205 | EXPORT_SYMBOL_GPL(rpc_call_async); |
---|
1130 | 1206 | |
---|
1131 | 1207 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
---|
| 1208 | +static void call_bc_encode(struct rpc_task *task); |
---|
| 1209 | + |
---|
1132 | 1210 | /** |
---|
1133 | 1211 | * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run |
---|
1134 | 1212 | * rpc_execute against it |
---|
.. | .. |
---|
1137 | 1215 | struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req) |
---|
1138 | 1216 | { |
---|
1139 | 1217 | struct rpc_task *task; |
---|
1140 | | - struct xdr_buf *xbufp = &req->rq_snd_buf; |
---|
1141 | 1218 | struct rpc_task_setup task_setup_data = { |
---|
1142 | 1219 | .callback_ops = &rpc_default_ops, |
---|
1143 | | - .flags = RPC_TASK_SOFTCONN, |
---|
| 1220 | + .flags = RPC_TASK_SOFTCONN | |
---|
| 1221 | + RPC_TASK_NO_RETRANS_TIMEOUT, |
---|
1144 | 1222 | }; |
---|
1145 | 1223 | |
---|
1146 | 1224 | dprintk("RPC: rpc_run_bc_task req= %p\n", req); |
---|
.. | .. |
---|
1148 | 1226 | * Create an rpc_task to send the data |
---|
1149 | 1227 | */ |
---|
1150 | 1228 | task = rpc_new_task(&task_setup_data); |
---|
1151 | | - task->tk_rqstp = req; |
---|
| 1229 | + xprt_init_bc_request(req, task); |
---|
1152 | 1230 | |
---|
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; |
---|
1161 | 1232 | atomic_inc(&task->tk_count); |
---|
1162 | 1233 | WARN_ON_ONCE(atomic_read(&task->tk_count) != 2); |
---|
1163 | 1234 | rpc_execute(task); |
---|
.. | .. |
---|
1166 | 1237 | return task; |
---|
1167 | 1238 | } |
---|
1168 | 1239 | #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); |
---|
1169 | 1263 | |
---|
1170 | 1264 | void |
---|
1171 | 1265 | rpc_call_start(struct rpc_task *task) |
---|
.. | .. |
---|
1267 | 1361 | break; |
---|
1268 | 1362 | default: |
---|
1269 | 1363 | err = -EAFNOSUPPORT; |
---|
1270 | | - goto out; |
---|
| 1364 | + goto out_release; |
---|
1271 | 1365 | } |
---|
1272 | 1366 | if (err < 0) { |
---|
1273 | 1367 | dprintk("RPC: can't bind UDP socket (%d)\n", err); |
---|
.. | .. |
---|
1439 | 1533 | } |
---|
1440 | 1534 | EXPORT_SYMBOL_GPL(rpc_max_bc_payload); |
---|
1441 | 1535 | |
---|
| 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 | + |
---|
1442 | 1549 | /** |
---|
1443 | 1550 | * rpc_force_rebind - force transport to check that remote port is unchanged |
---|
1444 | 1551 | * @clnt: client to rebind |
---|
.. | .. |
---|
1454 | 1561 | } |
---|
1455 | 1562 | EXPORT_SYMBOL_GPL(rpc_force_rebind); |
---|
1456 | 1563 | |
---|
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 *)) |
---|
1463 | 1566 | { |
---|
1464 | | - if (RPC_ASSASSINATED(task)) |
---|
1465 | | - return 0; |
---|
1466 | | - task->tk_action = call_start; |
---|
1467 | 1567 | 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; |
---|
1470 | 1570 | return 1; |
---|
1471 | 1571 | } |
---|
1472 | | -EXPORT_SYMBOL_GPL(rpc_restart_call_prepare); |
---|
1473 | 1572 | |
---|
1474 | 1573 | /* |
---|
1475 | 1574 | * Restart an (async) RPC call. Usually called from within the |
---|
.. | .. |
---|
1478 | 1577 | int |
---|
1479 | 1578 | rpc_restart_call(struct rpc_task *task) |
---|
1480 | 1579 | { |
---|
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); |
---|
1486 | 1581 | } |
---|
1487 | 1582 | 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); |
---|
1488 | 1596 | |
---|
1489 | 1597 | const char |
---|
1490 | 1598 | *rpc_proc_name(const struct rpc_task *task) |
---|
.. | .. |
---|
1500 | 1608 | return "no proc"; |
---|
1501 | 1609 | } |
---|
1502 | 1610 | |
---|
| 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 | + |
---|
1503 | 1625 | /* |
---|
1504 | 1626 | * 0. Initial state |
---|
1505 | 1627 | * |
---|
.. | .. |
---|
1513 | 1635 | int idx = task->tk_msg.rpc_proc->p_statidx; |
---|
1514 | 1636 | |
---|
1515 | 1637 | 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")); |
---|
1520 | 1638 | |
---|
1521 | 1639 | /* Increment call count (version might not be valid for ping) */ |
---|
1522 | 1640 | if (clnt->cl_program->version[clnt->cl_vers]) |
---|
.. | .. |
---|
1532 | 1650 | static void |
---|
1533 | 1651 | call_reserve(struct rpc_task *task) |
---|
1534 | 1652 | { |
---|
1535 | | - dprint_status(task); |
---|
1536 | | - |
---|
1537 | 1653 | task->tk_status = 0; |
---|
1538 | 1654 | task->tk_action = call_reserveresult; |
---|
1539 | 1655 | xprt_reserve(task); |
---|
.. | .. |
---|
1549 | 1665 | { |
---|
1550 | 1666 | int status = task->tk_status; |
---|
1551 | 1667 | |
---|
1552 | | - dprint_status(task); |
---|
1553 | | - |
---|
1554 | 1668 | /* |
---|
1555 | 1669 | * After a call to xprt_reserve(), we must have either |
---|
1556 | 1670 | * a request slot or else an error status. |
---|
.. | .. |
---|
1562 | 1676 | return; |
---|
1563 | 1677 | } |
---|
1564 | 1678 | |
---|
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); |
---|
1568 | 1680 | 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); |
---|
1579 | 1681 | } |
---|
1580 | 1682 | |
---|
1581 | 1683 | switch (status) { |
---|
1582 | 1684 | case -ENOMEM: |
---|
1583 | 1685 | rpc_delay(task, HZ >> 2); |
---|
1584 | | - /* fall through */ |
---|
| 1686 | + fallthrough; |
---|
1585 | 1687 | case -EAGAIN: /* woken up; retry */ |
---|
1586 | 1688 | task->tk_action = call_retry_reserve; |
---|
1587 | 1689 | return; |
---|
1588 | | - case -EIO: /* probably a shutdown */ |
---|
1589 | | - break; |
---|
1590 | 1690 | default: |
---|
1591 | | - printk(KERN_ERR "%s: unrecognized error %d, exiting\n", |
---|
1592 | | - __func__, status); |
---|
1593 | | - break; |
---|
| 1691 | + rpc_call_rpcerror(task, status); |
---|
1594 | 1692 | } |
---|
1595 | | - rpc_exit(task, status); |
---|
1596 | 1693 | } |
---|
1597 | 1694 | |
---|
1598 | 1695 | /* |
---|
.. | .. |
---|
1601 | 1698 | static void |
---|
1602 | 1699 | call_retry_reserve(struct rpc_task *task) |
---|
1603 | 1700 | { |
---|
1604 | | - dprint_status(task); |
---|
1605 | | - |
---|
1606 | 1701 | task->tk_status = 0; |
---|
1607 | 1702 | task->tk_action = call_reserveresult; |
---|
1608 | 1703 | xprt_retry_reserve(task); |
---|
.. | .. |
---|
1614 | 1709 | static void |
---|
1615 | 1710 | call_refresh(struct rpc_task *task) |
---|
1616 | 1711 | { |
---|
1617 | | - dprint_status(task); |
---|
1618 | | - |
---|
1619 | 1712 | task->tk_action = call_refreshresult; |
---|
1620 | 1713 | task->tk_status = 0; |
---|
1621 | 1714 | task->tk_client->cl_stats->rpcauthrefresh++; |
---|
.. | .. |
---|
1630 | 1723 | { |
---|
1631 | 1724 | int status = task->tk_status; |
---|
1632 | 1725 | |
---|
1633 | | - dprint_status(task); |
---|
1634 | | - |
---|
1635 | 1726 | task->tk_status = 0; |
---|
1636 | 1727 | task->tk_action = call_refresh; |
---|
1637 | 1728 | switch (status) { |
---|
.. | .. |
---|
1643 | 1734 | /* Use rate-limiting and a max number of retries if refresh |
---|
1644 | 1735 | * had status 0 but failed to update the cred. |
---|
1645 | 1736 | */ |
---|
1646 | | - /* fall through */ |
---|
| 1737 | + fallthrough; |
---|
1647 | 1738 | case -ETIMEDOUT: |
---|
1648 | 1739 | rpc_delay(task, 3*HZ); |
---|
1649 | | - /* fall through */ |
---|
| 1740 | + fallthrough; |
---|
1650 | 1741 | case -EAGAIN: |
---|
1651 | 1742 | status = -EACCES; |
---|
1652 | | - /* fall through */ |
---|
| 1743 | + fallthrough; |
---|
1653 | 1744 | case -EKEYEXPIRED: |
---|
1654 | 1745 | if (!task->tk_cred_retry) |
---|
1655 | 1746 | break; |
---|
1656 | 1747 | 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); |
---|
1659 | 1749 | return; |
---|
1660 | 1750 | } |
---|
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); |
---|
1664 | 1753 | } |
---|
1665 | 1754 | |
---|
1666 | 1755 | /* |
---|
.. | .. |
---|
1670 | 1759 | static void |
---|
1671 | 1760 | call_allocate(struct rpc_task *task) |
---|
1672 | 1761 | { |
---|
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; |
---|
1674 | 1763 | struct rpc_rqst *req = task->tk_rqstp; |
---|
1675 | 1764 | struct rpc_xprt *xprt = req->rq_xprt; |
---|
1676 | 1765 | const struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
---|
1677 | 1766 | int status; |
---|
1678 | 1767 | |
---|
1679 | | - dprint_status(task); |
---|
1680 | | - |
---|
1681 | 1768 | task->tk_status = 0; |
---|
1682 | | - task->tk_action = call_bind; |
---|
| 1769 | + task->tk_action = call_encode; |
---|
1683 | 1770 | |
---|
1684 | 1771 | if (req->rq_buffer) |
---|
1685 | 1772 | return; |
---|
.. | .. |
---|
1695 | 1782 | * and reply headers, and convert both values |
---|
1696 | 1783 | * to byte sizes. |
---|
1697 | 1784 | */ |
---|
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; |
---|
1699 | 1787 | 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); |
---|
1701 | 1794 | req->rq_rcvsize <<= 2; |
---|
1702 | 1795 | |
---|
1703 | 1796 | status = xprt->ops->buf_alloc(task); |
---|
1704 | | - xprt_inject_disconnect(xprt); |
---|
| 1797 | + trace_rpc_buf_alloc(task, status); |
---|
1705 | 1798 | if (status == 0) |
---|
1706 | 1799 | return; |
---|
1707 | 1800 | if (status != -ENOMEM) { |
---|
1708 | | - rpc_exit(task, status); |
---|
| 1801 | + rpc_call_rpcerror(task, status); |
---|
1709 | 1802 | return; |
---|
1710 | 1803 | } |
---|
1711 | | - |
---|
1712 | | - dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid); |
---|
1713 | 1804 | |
---|
1714 | 1805 | if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) { |
---|
1715 | 1806 | task->tk_action = call_allocate; |
---|
.. | .. |
---|
1717 | 1808 | return; |
---|
1718 | 1809 | } |
---|
1719 | 1810 | |
---|
1720 | | - rpc_exit(task, -ERESTARTSYS); |
---|
| 1811 | + rpc_call_rpcerror(task, -ERESTARTSYS); |
---|
1721 | 1812 | } |
---|
1722 | 1813 | |
---|
1723 | | -static inline int |
---|
| 1814 | +static int |
---|
1724 | 1815 | rpc_task_need_encode(struct rpc_task *task) |
---|
1725 | 1816 | { |
---|
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)); |
---|
1727 | 1821 | } |
---|
1728 | 1822 | |
---|
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 | | - */ |
---|
1739 | 1823 | static void |
---|
1740 | 1824 | rpc_xdr_encode(struct rpc_task *task) |
---|
1741 | 1825 | { |
---|
1742 | 1826 | struct rpc_rqst *req = task->tk_rqstp; |
---|
1743 | | - kxdreproc_t encode; |
---|
1744 | | - __be32 *p; |
---|
1745 | | - |
---|
1746 | | - dprint_status(task); |
---|
| 1827 | + struct xdr_stream xdr; |
---|
1747 | 1828 | |
---|
1748 | 1829 | xdr_buf_init(&req->rq_snd_buf, |
---|
1749 | 1830 | req->rq_buffer, |
---|
.. | .. |
---|
1752 | 1833 | req->rq_rbuffer, |
---|
1753 | 1834 | req->rq_rcvsize); |
---|
1754 | 1835 | |
---|
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 | + } |
---|
1759 | 1880 | return; |
---|
1760 | 1881 | } |
---|
1761 | 1882 | |
---|
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 | +} |
---|
1765 | 1895 | |
---|
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; |
---|
1768 | 1911 | } |
---|
1769 | 1912 | |
---|
1770 | 1913 | /* |
---|
.. | .. |
---|
1775 | 1918 | { |
---|
1776 | 1919 | struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
---|
1777 | 1920 | |
---|
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; |
---|
1785 | 1924 | } |
---|
| 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); |
---|
1786 | 1936 | } |
---|
1787 | 1937 | |
---|
1788 | 1938 | /* |
---|
.. | .. |
---|
1791 | 1941 | static void |
---|
1792 | 1942 | call_bind_status(struct rpc_task *task) |
---|
1793 | 1943 | { |
---|
| 1944 | + struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
---|
1794 | 1945 | int status = -EIO; |
---|
1795 | 1946 | |
---|
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); |
---|
1800 | 1949 | return; |
---|
1801 | 1950 | } |
---|
1802 | 1951 | |
---|
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 | + |
---|
1804 | 1959 | switch (task->tk_status) { |
---|
1805 | 1960 | case -ENOMEM: |
---|
1806 | | - dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid); |
---|
1807 | 1961 | rpc_delay(task, HZ >> 2); |
---|
1808 | 1962 | goto retry_timeout; |
---|
1809 | 1963 | case -EACCES: |
---|
1810 | | - dprintk("RPC: %5u remote rpcbind: RPC program/version " |
---|
1811 | | - "unavailable\n", task->tk_pid); |
---|
| 1964 | + trace_rpcb_prog_unavail_err(task); |
---|
1812 | 1965 | /* fail immediately if this is an RPC ping */ |
---|
1813 | 1966 | if (task->tk_msg.rpc_proc->p_proc == 0) { |
---|
1814 | 1967 | status = -EOPNOTSUPP; |
---|
1815 | 1968 | break; |
---|
1816 | 1969 | } |
---|
1817 | | - if (task->tk_rebind_retry == 0) |
---|
1818 | | - break; |
---|
1819 | | - task->tk_rebind_retry--; |
---|
1820 | 1970 | rpc_delay(task, 3*HZ); |
---|
1821 | 1971 | goto retry_timeout; |
---|
| 1972 | + case -ENOBUFS: |
---|
| 1973 | + rpc_delay(task, HZ >> 2); |
---|
| 1974 | + goto retry_timeout; |
---|
| 1975 | + case -EAGAIN: |
---|
| 1976 | + goto retry_timeout; |
---|
1822 | 1977 | case -ETIMEDOUT: |
---|
1823 | | - dprintk("RPC: %5u rpcbind request timed out\n", |
---|
1824 | | - task->tk_pid); |
---|
| 1978 | + trace_rpcb_timeout_err(task); |
---|
1825 | 1979 | goto retry_timeout; |
---|
1826 | 1980 | case -EPFNOSUPPORT: |
---|
1827 | 1981 | /* 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); |
---|
1830 | 1983 | break; |
---|
1831 | 1984 | case -EPROTONOSUPPORT: |
---|
1832 | | - dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n", |
---|
1833 | | - task->tk_pid); |
---|
| 1985 | + trace_rpcb_bind_version_err(task); |
---|
1834 | 1986 | goto retry_timeout; |
---|
1835 | 1987 | case -ECONNREFUSED: /* connection problems */ |
---|
1836 | 1988 | case -ECONNRESET: |
---|
.. | .. |
---|
1840 | 1992 | case -ENETDOWN: |
---|
1841 | 1993 | case -EHOSTUNREACH: |
---|
1842 | 1994 | case -ENETUNREACH: |
---|
1843 | | - case -ENOBUFS: |
---|
1844 | 1995 | case -EPIPE: |
---|
1845 | | - dprintk("RPC: %5u remote rpcbind unreachable: %d\n", |
---|
1846 | | - task->tk_pid, task->tk_status); |
---|
| 1996 | + trace_rpcb_unreachable_err(task); |
---|
1847 | 1997 | if (!RPC_IS_SOFTCONN(task)) { |
---|
1848 | 1998 | rpc_delay(task, 5*HZ); |
---|
1849 | 1999 | goto retry_timeout; |
---|
.. | .. |
---|
1851 | 2001 | status = task->tk_status; |
---|
1852 | 2002 | break; |
---|
1853 | 2003 | default: |
---|
1854 | | - dprintk("RPC: %5u unrecognized rpcbind error (%d)\n", |
---|
1855 | | - task->tk_pid, -task->tk_status); |
---|
| 2004 | + trace_rpcb_unrecognized_err(task); |
---|
1856 | 2005 | } |
---|
1857 | 2006 | |
---|
1858 | | - rpc_exit(task, status); |
---|
| 2007 | + rpc_call_rpcerror(task, status); |
---|
1859 | 2008 | return; |
---|
1860 | | - |
---|
| 2009 | +out_next: |
---|
| 2010 | + task->tk_action = call_connect; |
---|
| 2011 | + return; |
---|
1861 | 2012 | retry_timeout: |
---|
1862 | 2013 | task->tk_status = 0; |
---|
1863 | | - task->tk_action = call_timeout; |
---|
| 2014 | + task->tk_action = call_bind; |
---|
| 2015 | + rpc_check_timeout(task); |
---|
1864 | 2016 | } |
---|
1865 | 2017 | |
---|
1866 | 2018 | /* |
---|
.. | .. |
---|
1871 | 2023 | { |
---|
1872 | 2024 | struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
---|
1873 | 2025 | |
---|
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; |
---|
1888 | 2029 | } |
---|
| 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); |
---|
1889 | 2046 | } |
---|
1890 | 2047 | |
---|
1891 | 2048 | /* |
---|
.. | .. |
---|
1894 | 2051 | static void |
---|
1895 | 2052 | call_connect_status(struct rpc_task *task) |
---|
1896 | 2053 | { |
---|
| 2054 | + struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
---|
1897 | 2055 | struct rpc_clnt *clnt = task->tk_client; |
---|
1898 | 2056 | int status = task->tk_status; |
---|
1899 | 2057 | |
---|
1900 | | - dprint_status(task); |
---|
| 2058 | + if (rpc_task_transmitted(task)) { |
---|
| 2059 | + rpc_task_handle_transmitted(task); |
---|
| 2060 | + return; |
---|
| 2061 | + } |
---|
1901 | 2062 | |
---|
1902 | 2063 | 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 | + |
---|
1903 | 2074 | task->tk_status = 0; |
---|
1904 | 2075 | switch (status) { |
---|
1905 | 2076 | case -ECONNREFUSED: |
---|
.. | .. |
---|
1908 | 2079 | break; |
---|
1909 | 2080 | if (clnt->cl_autobind) { |
---|
1910 | 2081 | rpc_force_rebind(clnt); |
---|
1911 | | - task->tk_action = call_bind; |
---|
1912 | | - return; |
---|
| 2082 | + goto out_retry; |
---|
1913 | 2083 | } |
---|
1914 | | - /* fall through */ |
---|
| 2084 | + fallthrough; |
---|
1915 | 2085 | case -ECONNRESET: |
---|
1916 | 2086 | case -ECONNABORTED: |
---|
1917 | 2087 | case -ENETDOWN: |
---|
1918 | 2088 | case -ENETUNREACH: |
---|
1919 | 2089 | case -EHOSTUNREACH: |
---|
1920 | | - case -EADDRINUSE: |
---|
1921 | | - case -ENOBUFS: |
---|
1922 | 2090 | case -EPIPE: |
---|
| 2091 | + case -EPROTO: |
---|
1923 | 2092 | xprt_conditional_disconnect(task->tk_rqstp->rq_xprt, |
---|
1924 | 2093 | task->tk_rqstp->rq_connect_cookie); |
---|
1925 | 2094 | if (RPC_IS_SOFTCONN(task)) |
---|
1926 | 2095 | break; |
---|
1927 | 2096 | /* retry with existing socket, after a delay */ |
---|
1928 | 2097 | rpc_delay(task, 3*HZ); |
---|
1929 | | - /* fall through */ |
---|
| 2098 | + fallthrough; |
---|
| 2099 | + case -EADDRINUSE: |
---|
| 2100 | + case -ENOTCONN: |
---|
1930 | 2101 | case -EAGAIN: |
---|
1931 | | - /* Check for timeouts before looping back to call_bind */ |
---|
1932 | 2102 | 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; |
---|
1939 | 2107 | } |
---|
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); |
---|
1941 | 2117 | } |
---|
1942 | 2118 | |
---|
1943 | 2119 | /* |
---|
.. | .. |
---|
1946 | 2122 | static void |
---|
1947 | 2123 | call_transmit(struct rpc_task *task) |
---|
1948 | 2124 | { |
---|
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); |
---|
1955 | 2127 | return; |
---|
| 2128 | + } |
---|
| 2129 | + |
---|
| 2130 | + task->tk_action = call_transmit_status; |
---|
1956 | 2131 | if (!xprt_prepare_transmit(task)) |
---|
1957 | 2132 | 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; |
---|
1969 | 2137 | return; |
---|
1970 | 2138 | } |
---|
| 2139 | + xprt_transmit(task); |
---|
1971 | 2140 | } |
---|
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); |
---|
1986 | 2142 | } |
---|
1987 | 2143 | |
---|
1988 | 2144 | /* |
---|
.. | .. |
---|
1991 | 2147 | static void |
---|
1992 | 2148 | call_transmit_status(struct rpc_task *task) |
---|
1993 | 2149 | { |
---|
1994 | | - struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
---|
1995 | 2150 | task->tk_action = call_status; |
---|
1996 | 2151 | |
---|
1997 | 2152 | /* |
---|
1998 | 2153 | * 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. |
---|
2001 | 2155 | */ |
---|
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); |
---|
2005 | 2159 | return; |
---|
2006 | 2160 | } |
---|
2007 | 2161 | |
---|
2008 | 2162 | switch (task->tk_status) { |
---|
2009 | | - case -EAGAIN: |
---|
2010 | | - case -ENOBUFS: |
---|
2011 | | - break; |
---|
2012 | 2163 | 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; |
---|
2016 | 2168 | break; |
---|
2017 | 2169 | /* |
---|
2018 | 2170 | * Special cases: if we've been waiting on the |
---|
.. | .. |
---|
2020 | 2172 | * socket just returned a connection error, |
---|
2021 | 2173 | * then hold onto the transport lock. |
---|
2022 | 2174 | */ |
---|
| 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; |
---|
2023 | 2184 | case -ECONNREFUSED: |
---|
2024 | 2185 | case -EHOSTDOWN: |
---|
2025 | 2186 | case -ENETDOWN: |
---|
.. | .. |
---|
2027 | 2188 | case -ENETUNREACH: |
---|
2028 | 2189 | case -EPERM: |
---|
2029 | 2190 | if (RPC_IS_SOFTCONN(task)) { |
---|
2030 | | - xprt_end_transmit(task); |
---|
2031 | 2191 | if (!task->tk_msg.rpc_proc->p_proc) |
---|
2032 | 2192 | trace_xprt_ping(task->tk_xprt, |
---|
2033 | 2193 | task->tk_status); |
---|
2034 | | - rpc_exit(task, task->tk_status); |
---|
2035 | | - break; |
---|
| 2194 | + rpc_call_rpcerror(task, task->tk_status); |
---|
| 2195 | + return; |
---|
2036 | 2196 | } |
---|
2037 | | - /* fall through */ |
---|
| 2197 | + fallthrough; |
---|
2038 | 2198 | case -ECONNRESET: |
---|
2039 | 2199 | case -ECONNABORTED: |
---|
2040 | 2200 | case -EADDRINUSE: |
---|
2041 | 2201 | case -ENOTCONN: |
---|
2042 | 2202 | case -EPIPE: |
---|
2043 | | - rpc_task_force_reencode(task); |
---|
| 2203 | + task->tk_action = call_bind; |
---|
| 2204 | + task->tk_status = 0; |
---|
| 2205 | + break; |
---|
2044 | 2206 | } |
---|
| 2207 | + rpc_check_timeout(task); |
---|
2045 | 2208 | } |
---|
2046 | 2209 | |
---|
2047 | 2210 | #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 | + |
---|
2048 | 2221 | /* |
---|
2049 | 2222 | * 5b. Send the backchannel RPC reply. On error, drop the reply. In |
---|
2050 | 2223 | * addition, disconnect on connectivity errors. |
---|
.. | .. |
---|
2052 | 2225 | static void |
---|
2053 | 2226 | call_bc_transmit(struct rpc_task *task) |
---|
2054 | 2227 | { |
---|
| 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 | +{ |
---|
2055 | 2241 | struct rpc_rqst *req = task->tk_rqstp; |
---|
2056 | 2242 | |
---|
2057 | | - if (!xprt_prepare_transmit(task)) |
---|
2058 | | - goto out_retry; |
---|
| 2243 | + if (rpc_task_transmitted(task)) |
---|
| 2244 | + task->tk_status = 0; |
---|
2059 | 2245 | |
---|
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); |
---|
2075 | 2246 | switch (task->tk_status) { |
---|
2076 | 2247 | case 0: |
---|
2077 | 2248 | /* Success */ |
---|
.. | .. |
---|
2085 | 2256 | case -ENOTCONN: |
---|
2086 | 2257 | case -EPIPE: |
---|
2087 | 2258 | 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; |
---|
2088 | 2268 | case -ETIMEDOUT: |
---|
2089 | 2269 | /* |
---|
2090 | 2270 | * Problem reaching the server. Disconnect and let the |
---|
.. | .. |
---|
2103 | 2283 | * We were unable to reply and will have to drop the |
---|
2104 | 2284 | * request. The server should reconnect and retransmit. |
---|
2105 | 2285 | */ |
---|
2106 | | - WARN_ON_ONCE(task->tk_status == -EAGAIN); |
---|
2107 | 2286 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
---|
2108 | 2287 | "error: %d\n", task->tk_status); |
---|
2109 | 2288 | break; |
---|
2110 | 2289 | } |
---|
2111 | | - rpc_wake_up_queued_task(&req->rq_xprt->pending, task); |
---|
2112 | | -out_done: |
---|
2113 | 2290 | 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; |
---|
2119 | 2291 | } |
---|
2120 | 2292 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
---|
2121 | 2293 | |
---|
.. | .. |
---|
2126 | 2298 | call_status(struct rpc_task *task) |
---|
2127 | 2299 | { |
---|
2128 | 2300 | struct rpc_clnt *clnt = task->tk_client; |
---|
2129 | | - struct rpc_rqst *req = task->tk_rqstp; |
---|
2130 | 2301 | int status; |
---|
2131 | 2302 | |
---|
2132 | 2303 | if (!task->tk_msg.rpc_proc->p_proc) |
---|
2133 | 2304 | 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); |
---|
2139 | 2305 | |
---|
2140 | 2306 | status = task->tk_status; |
---|
2141 | 2307 | if (status >= 0) { |
---|
.. | .. |
---|
2151 | 2317 | case -EHOSTUNREACH: |
---|
2152 | 2318 | case -ENETUNREACH: |
---|
2153 | 2319 | 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; |
---|
2158 | 2322 | /* |
---|
2159 | 2323 | * Delay any retries for 3 seconds, then handle as if it |
---|
2160 | 2324 | * were a timeout. |
---|
2161 | 2325 | */ |
---|
2162 | 2326 | rpc_delay(task, 3*HZ); |
---|
2163 | | - /* fall through */ |
---|
| 2327 | + fallthrough; |
---|
2164 | 2328 | case -ETIMEDOUT: |
---|
2165 | | - task->tk_action = call_timeout; |
---|
2166 | 2329 | break; |
---|
2167 | 2330 | case -ECONNREFUSED: |
---|
2168 | 2331 | case -ECONNRESET: |
---|
2169 | 2332 | case -ECONNABORTED: |
---|
| 2333 | + case -ENOTCONN: |
---|
2170 | 2334 | rpc_force_rebind(clnt); |
---|
2171 | | - /* fall through */ |
---|
| 2335 | + break; |
---|
2172 | 2336 | case -EADDRINUSE: |
---|
2173 | 2337 | rpc_delay(task, 3*HZ); |
---|
2174 | | - /* fall through */ |
---|
| 2338 | + fallthrough; |
---|
2175 | 2339 | 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 */ |
---|
2182 | 2340 | 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); |
---|
2184 | 2346 | break; |
---|
2185 | 2347 | case -EIO: |
---|
2186 | 2348 | /* shutdown or soft timeout */ |
---|
2187 | | - rpc_exit(task, status); |
---|
2188 | | - break; |
---|
| 2349 | + goto out_exit; |
---|
2189 | 2350 | default: |
---|
2190 | 2351 | if (clnt->cl_chatty) |
---|
2191 | 2352 | printk("%s: RPC call returned error %d\n", |
---|
2192 | 2353 | clnt->cl_program->name, -status); |
---|
2193 | | - rpc_exit(task, status); |
---|
| 2354 | + goto out_exit; |
---|
2194 | 2355 | } |
---|
| 2356 | + task->tk_action = call_encode; |
---|
| 2357 | + rpc_check_timeout(task); |
---|
| 2358 | + return; |
---|
| 2359 | +out_exit: |
---|
| 2360 | + rpc_call_rpcerror(task, status); |
---|
2195 | 2361 | } |
---|
2196 | 2362 | |
---|
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 | + |
---|
2202 | 2372 | static void |
---|
2203 | | -call_timeout(struct rpc_task *task) |
---|
| 2373 | +rpc_check_timeout(struct rpc_task *task) |
---|
2204 | 2374 | { |
---|
2205 | 2375 | struct rpc_clnt *clnt = task->tk_client; |
---|
2206 | 2376 | |
---|
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); |
---|
2217 | 2379 | return; |
---|
2218 | 2380 | } |
---|
| 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 | + |
---|
2219 | 2393 | 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 | + |
---|
2220 | 2403 | 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", |
---|
2222 | 2406 | clnt->cl_program->name, |
---|
2223 | 2407 | task->tk_xprt->servername); |
---|
2224 | 2408 | } |
---|
2225 | 2409 | if (task->tk_flags & RPC_TASK_TIMEOUT) |
---|
2226 | | - rpc_exit(task, -ETIMEDOUT); |
---|
| 2410 | + rpc_call_rpcerror(task, -ETIMEDOUT); |
---|
2227 | 2411 | else |
---|
2228 | | - rpc_exit(task, -EIO); |
---|
| 2412 | + __rpc_call_rpcerror(task, -EIO, -ETIMEDOUT); |
---|
2229 | 2413 | return; |
---|
2230 | 2414 | } |
---|
2231 | 2415 | |
---|
2232 | 2416 | if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) { |
---|
2233 | 2417 | task->tk_flags |= RPC_CALL_MAJORSEEN; |
---|
2234 | 2418 | 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); |
---|
2238 | 2423 | } |
---|
2239 | 2424 | } |
---|
2240 | 2425 | rpc_force_rebind(clnt); |
---|
.. | .. |
---|
2243 | 2428 | * event? RFC2203 requires the server to drop all such requests. |
---|
2244 | 2429 | */ |
---|
2245 | 2430 | rpcauth_invalcred(task); |
---|
2246 | | - |
---|
2247 | | -retry: |
---|
2248 | | - task->tk_action = call_bind; |
---|
2249 | | - task->tk_status = 0; |
---|
2250 | 2431 | } |
---|
2251 | 2432 | |
---|
2252 | 2433 | /* |
---|
.. | .. |
---|
2257 | 2438 | { |
---|
2258 | 2439 | struct rpc_clnt *clnt = task->tk_client; |
---|
2259 | 2440 | 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; |
---|
2262 | 2443 | |
---|
2263 | | - dprint_status(task); |
---|
| 2444 | + if (!task->tk_msg.rpc_proc->p_decode) { |
---|
| 2445 | + task->tk_action = rpc_exit_task; |
---|
| 2446 | + return; |
---|
| 2447 | + } |
---|
2264 | 2448 | |
---|
2265 | 2449 | if (task->tk_flags & RPC_CALL_MAJORSEEN) { |
---|
2266 | 2450 | if (clnt->cl_chatty) { |
---|
2267 | | - printk(KERN_NOTICE "%s: server %s OK\n", |
---|
| 2451 | + pr_notice_ratelimited("%s: server %s OK\n", |
---|
2268 | 2452 | clnt->cl_program->name, |
---|
2269 | 2453 | task->tk_xprt->servername); |
---|
2270 | 2454 | } |
---|
.. | .. |
---|
2272 | 2456 | } |
---|
2273 | 2457 | |
---|
2274 | 2458 | /* |
---|
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() |
---|
2276 | 2467 | * before it changed req->rq_reply_bytes_recvd. |
---|
2277 | 2468 | */ |
---|
2278 | 2469 | smp_rmb(); |
---|
| 2470 | + |
---|
2279 | 2471 | req->rq_rcv_buf.len = req->rq_private_buf.len; |
---|
| 2472 | + trace_rpc_xdr_recvfrom(task, &req->rq_rcv_buf); |
---|
2280 | 2473 | |
---|
2281 | 2474 | /* Check that the softirq receive buffer is valid */ |
---|
2282 | 2475 | WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, |
---|
2283 | 2476 | sizeof(req->rq_rcv_buf)) != 0); |
---|
2284 | 2477 | |
---|
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); |
---|
2300 | 2486 | 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; |
---|
2317 | 2489 | if (task->tk_client->cl_discrtry) |
---|
2318 | 2490 | 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); |
---|
2320 | 2501 | } |
---|
2321 | 2502 | } |
---|
2322 | 2503 | |
---|
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) |
---|
2325 | 2506 | { |
---|
2326 | 2507 | struct rpc_clnt *clnt = task->tk_client; |
---|
2327 | 2508 | struct rpc_rqst *req = task->tk_rqstp; |
---|
2328 | | - __be32 *p = req->rq_svec[0].iov_base; |
---|
| 2509 | + __be32 *p; |
---|
| 2510 | + int error; |
---|
2329 | 2511 | |
---|
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); |
---|
2331 | 2522 | |
---|
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; |
---|
2342 | 2531 | } |
---|
2343 | 2532 | |
---|
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) |
---|
2346 | 2535 | { |
---|
2347 | 2536 | 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; |
---|
2353 | 2539 | |
---|
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; |
---|
2368 | 2547 | |
---|
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; |
---|
2376 | 2556 | |
---|
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); |
---|
2454 | 2569 | error = -EPFNOSUPPORT; |
---|
2455 | 2570 | 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); |
---|
2462 | 2573 | error = -EPROTONOSUPPORT; |
---|
2463 | 2574 | 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); |
---|
2471 | 2577 | error = -EOPNOTSUPP; |
---|
2472 | 2578 | 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; |
---|
2477 | 2584 | default: |
---|
2478 | | - dprintk("RPC: %5u %s: server accept status: %x\n", |
---|
2479 | | - task->tk_pid, __func__, n); |
---|
2480 | | - /* Also retry */ |
---|
| 2585 | + goto out_unparsable; |
---|
2481 | 2586 | } |
---|
2482 | 2587 | |
---|
2483 | 2588 | out_garbage: |
---|
2484 | 2589 | clnt->cl_stats->rpcgarbage++; |
---|
2485 | 2590 | if (task->tk_garb_retry) { |
---|
2486 | 2591 | 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; |
---|
2492 | 2594 | } |
---|
2493 | 2595 | 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; |
---|
2501 | 2602 | 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; |
---|
2502 | 2656 | } |
---|
2503 | 2657 | |
---|
2504 | 2658 | static void rpcproc_encode_null(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
---|
.. | .. |
---|
2523 | 2677 | .rpc_proc = &rpcproc_null, |
---|
2524 | 2678 | }; |
---|
2525 | 2679 | 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); |
---|
2529 | 2682 | return err; |
---|
2530 | 2683 | } |
---|
2531 | 2684 | |
---|
.. | .. |
---|
2536 | 2689 | { |
---|
2537 | 2690 | struct rpc_message msg = { |
---|
2538 | 2691 | .rpc_proc = &rpcproc_null, |
---|
2539 | | - .rpc_cred = cred, |
---|
2540 | 2692 | }; |
---|
2541 | 2693 | struct rpc_task_setup task_setup_data = { |
---|
2542 | 2694 | .rpc_client = clnt, |
---|
2543 | 2695 | .rpc_xprt = xprt, |
---|
2544 | 2696 | .rpc_message = &msg, |
---|
| 2697 | + .rpc_op_cred = cred, |
---|
2545 | 2698 | .callback_ops = (ops != NULL) ? ops : &rpc_default_ops, |
---|
2546 | 2699 | .callback_data = data, |
---|
2547 | | - .flags = flags, |
---|
| 2700 | + .flags = flags | RPC_TASK_SOFT | RPC_TASK_SOFTCONN | |
---|
| 2701 | + RPC_TASK_NULLCREDS, |
---|
2548 | 2702 | }; |
---|
2549 | 2703 | |
---|
2550 | 2704 | return rpc_run_task(&task_setup_data); |
---|
.. | .. |
---|
2595 | 2749 | void *dummy) |
---|
2596 | 2750 | { |
---|
2597 | 2751 | struct rpc_cb_add_xprt_calldata *data; |
---|
2598 | | - struct rpc_cred *cred; |
---|
2599 | 2752 | struct rpc_task *task; |
---|
2600 | 2753 | |
---|
2601 | 2754 | data = kmalloc(sizeof(*data), GFP_NOFS); |
---|
.. | .. |
---|
2603 | 2756 | return -ENOMEM; |
---|
2604 | 2757 | data->xps = xprt_switch_get(xps); |
---|
2605 | 2758 | 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 | + } |
---|
2606 | 2763 | |
---|
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, |
---|
2610 | 2765 | &rpc_cb_add_xprt_call_ops, data); |
---|
2611 | | - put_rpccred(cred); |
---|
2612 | | - if (IS_ERR(task)) |
---|
2613 | | - return PTR_ERR(task); |
---|
| 2766 | + |
---|
2614 | 2767 | rpc_put_task(task); |
---|
| 2768 | +success: |
---|
2615 | 2769 | return 1; |
---|
2616 | 2770 | } |
---|
2617 | 2771 | EXPORT_SYMBOL_GPL(rpc_clnt_test_and_add_xprt); |
---|
.. | .. |
---|
2639 | 2793 | struct rpc_xprt *xprt, |
---|
2640 | 2794 | void *data) |
---|
2641 | 2795 | { |
---|
2642 | | - struct rpc_cred *cred; |
---|
2643 | 2796 | struct rpc_task *task; |
---|
2644 | 2797 | struct rpc_add_xprt_test *xtest = (struct rpc_add_xprt_test *)data; |
---|
2645 | 2798 | int status = -EADDRINUSE; |
---|
.. | .. |
---|
2651 | 2804 | goto out_err; |
---|
2652 | 2805 | |
---|
2653 | 2806 | /* 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); |
---|
2659 | 2808 | if (IS_ERR(task)) { |
---|
2660 | 2809 | status = PTR_ERR(task); |
---|
2661 | 2810 | goto out_err; |
---|
.. | .. |
---|
2668 | 2817 | |
---|
2669 | 2818 | /* rpc_xprt_switch and rpc_xprt are deferrenced by add_xprt_test() */ |
---|
2670 | 2819 | xtest->add_xprt_test(clnt, xprt, xtest->data); |
---|
| 2820 | + |
---|
| 2821 | + xprt_put(xprt); |
---|
| 2822 | + xprt_switch_put(xps); |
---|
2671 | 2823 | |
---|
2672 | 2824 | /* so that rpc_clnt_add_xprt does not call rpc_xprt_switch_add_xprt */ |
---|
2673 | 2825 | return 1; |
---|
.. | .. |
---|
2705 | 2857 | struct rpc_xprt *xprt; |
---|
2706 | 2858 | unsigned long connect_timeout; |
---|
2707 | 2859 | unsigned long reconnect_timeout; |
---|
2708 | | - unsigned char resvport; |
---|
| 2860 | + unsigned char resvport, reuseport; |
---|
2709 | 2861 | int ret = 0; |
---|
2710 | 2862 | |
---|
2711 | 2863 | rcu_read_lock(); |
---|
.. | .. |
---|
2717 | 2869 | return -EAGAIN; |
---|
2718 | 2870 | } |
---|
2719 | 2871 | resvport = xprt->resvport; |
---|
| 2872 | + reuseport = xprt->reuseport; |
---|
2720 | 2873 | connect_timeout = xprt->connect_timeout; |
---|
2721 | 2874 | reconnect_timeout = xprt->max_reconnect_timeout; |
---|
2722 | 2875 | rcu_read_unlock(); |
---|
.. | .. |
---|
2727 | 2880 | goto out_put_switch; |
---|
2728 | 2881 | } |
---|
2729 | 2882 | xprt->resvport = resvport; |
---|
| 2883 | + xprt->reuseport = reuseport; |
---|
2730 | 2884 | if (xprt->ops->set_connect_timeout != NULL) |
---|
2731 | 2885 | xprt->ops->set_connect_timeout(xprt, |
---|
2732 | 2886 | connect_timeout, |
---|
.. | .. |
---|
2829 | 2983 | |
---|
2830 | 2984 | printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n", |
---|
2831 | 2985 | 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, |
---|
2833 | 2987 | clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task), |
---|
2834 | 2988 | task->tk_action, rpc_waitq); |
---|
2835 | 2989 | } |
---|
.. | .. |
---|
2869 | 3023 | int |
---|
2870 | 3024 | rpc_clnt_swap_activate(struct rpc_clnt *clnt) |
---|
2871 | 3025 | { |
---|
| 3026 | + while (clnt != clnt->cl_parent) |
---|
| 3027 | + clnt = clnt->cl_parent; |
---|
2872 | 3028 | if (atomic_inc_return(&clnt->cl_swapper) == 1) |
---|
2873 | 3029 | return rpc_clnt_iterate_for_each_xprt(clnt, |
---|
2874 | 3030 | rpc_clnt_swap_activate_callback, NULL); |
---|
.. | .. |
---|
2888 | 3044 | void |
---|
2889 | 3045 | rpc_clnt_swap_deactivate(struct rpc_clnt *clnt) |
---|
2890 | 3046 | { |
---|
| 3047 | + while (clnt != clnt->cl_parent) |
---|
| 3048 | + clnt = clnt->cl_parent; |
---|
2891 | 3049 | if (atomic_dec_if_positive(&clnt->cl_swapper) == 0) |
---|
2892 | 3050 | rpc_clnt_iterate_for_each_xprt(clnt, |
---|
2893 | 3051 | rpc_clnt_swap_deactivate_callback, NULL); |
---|