Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 3 | * linux/net/sunrpc/clnt.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file contains the high-level RPC interface. |
| 6 | * It is modeled as a finite state machine to support both synchronous |
| 7 | * and asynchronous requests. |
| 8 | * |
| 9 | * - RPC header generation and argument serialization. |
| 10 | * - Credential refresh. |
| 11 | * - TCP connect handling. |
| 12 | * - Retry of operation when it is suspected the operation failed because |
| 13 | * of uid squashing on the server, or when the credentials were stale |
| 14 | * and need to be refreshed, or when a packet was damaged in transit. |
| 15 | * This may be have to be moved to the VFS layer. |
| 16 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com> |
| 18 | * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de> |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 24 | #include <linux/kallsyms.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 26 | #include <linux/namei.h> |
| 27 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/slab.h> |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 29 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/utsname.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 31 | #include <linux/workqueue.h> |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 32 | #include <linux/in.h> |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 33 | #include <linux/in6.h> |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 34 | #include <linux/un.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <linux/sunrpc/clnt.h> |
Jeff Layton | 5976687 | 2013-02-04 12:50:00 -0500 | [diff] [blame] | 37 | #include <linux/sunrpc/addr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/sunrpc/rpc_pipe_fs.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 39 | #include <linux/sunrpc/metrics.h> |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 40 | #include <linux/sunrpc/bc_xprt.h> |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 41 | #include <trace/events/sunrpc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 43 | #include "sunrpc.h" |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 44 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 46 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | # define RPCDBG_FACILITY RPCDBG_CALL |
| 48 | #endif |
| 49 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 50 | #define dprint_status(t) \ |
| 51 | dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 52 | __func__, t->tk_status) |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 53 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 54 | /* |
| 55 | * All RPC clients are linked into this list |
| 56 | */ |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static DECLARE_WAIT_QUEUE_HEAD(destroy_wait); |
| 59 | |
| 60 | |
| 61 | static void call_start(struct rpc_task *task); |
| 62 | static void call_reserve(struct rpc_task *task); |
| 63 | static void call_reserveresult(struct rpc_task *task); |
| 64 | static void call_allocate(struct rpc_task *task); |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 65 | static void call_encode(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void call_decode(struct rpc_task *task); |
| 67 | static void call_bind(struct rpc_task *task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 68 | static void call_bind_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static void call_transmit(struct rpc_task *task); |
| 70 | static void call_status(struct rpc_task *task); |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 71 | static void call_transmit_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static void call_refresh(struct rpc_task *task); |
| 73 | static void call_refreshresult(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static void call_connect(struct rpc_task *task); |
| 75 | static void call_connect_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 77 | static int rpc_encode_header(struct rpc_task *task, |
| 78 | struct xdr_stream *xdr); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 79 | static int rpc_decode_header(struct rpc_task *task, |
| 80 | struct xdr_stream *xdr); |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 81 | static int rpc_ping(struct rpc_clnt *clnt); |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 82 | static void rpc_check_timeout(struct rpc_task *task); |
Trond Myklebust | 64c91a1 | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 83 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 84 | static void rpc_register_client(struct rpc_clnt *clnt) |
| 85 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 86 | struct net *net = rpc_net_ns(clnt); |
| 87 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 88 | |
| 89 | spin_lock(&sn->rpc_client_lock); |
| 90 | list_add(&clnt->cl_clients, &sn->all_clients); |
| 91 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void rpc_unregister_client(struct rpc_clnt *clnt) |
| 95 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 96 | struct net *net = rpc_net_ns(clnt); |
| 97 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 98 | |
| 99 | spin_lock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 100 | list_del(&clnt->cl_clients); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 101 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 104 | static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) |
| 105 | { |
Trond Myklebust | c36dcfe1 | 2013-08-26 17:44:26 -0400 | [diff] [blame] | 106 | rpc_remove_client_dir(clnt); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) |
| 110 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 111 | struct net *net = rpc_net_ns(clnt); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 112 | struct super_block *pipefs_sb; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 113 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 114 | pipefs_sb = rpc_get_sb_net(net); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 115 | if (pipefs_sb) { |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 116 | __rpc_clnt_remove_pipedir(clnt); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 117 | rpc_put_sb_net(net); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 118 | } |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb, |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 122 | struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 124 | static uint32_t clntid; |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 125 | const char *dir_name = clnt->cl_program->pipe_dir_name; |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 126 | char name[15]; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 127 | struct dentry *dir, *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 129 | dir = rpc_d_lookup_sb(sb, dir_name); |
Weston Andros Adamson | 922eeac | 2012-10-23 10:43:25 -0400 | [diff] [blame] | 130 | if (dir == NULL) { |
| 131 | pr_info("RPC: pipefs directory doesn't exist: %s\n", dir_name); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 132 | return dir; |
Weston Andros Adamson | 922eeac | 2012-10-23 10:43:25 -0400 | [diff] [blame] | 133 | } |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 134 | for (;;) { |
Al Viro | a95e691 | 2013-07-14 16:43:54 +0400 | [diff] [blame] | 135 | snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 136 | name[sizeof(name) - 1] = '\0'; |
Al Viro | a95e691 | 2013-07-14 16:43:54 +0400 | [diff] [blame] | 137 | dentry = rpc_create_client_dir(dir, name, clnt); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 138 | if (!IS_ERR(dentry)) |
| 139 | break; |
Al Viro | a95e691 | 2013-07-14 16:43:54 +0400 | [diff] [blame] | 140 | if (dentry == ERR_PTR(-EEXIST)) |
| 141 | continue; |
| 142 | printk(KERN_INFO "RPC: Couldn't create pipefs entry" |
| 143 | " %s/%s, error %ld\n", |
| 144 | dir_name, name, PTR_ERR(dentry)); |
| 145 | break; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 146 | } |
| 147 | dput(dir); |
| 148 | return dentry; |
| 149 | } |
| 150 | |
| 151 | static int |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 152 | rpc_setup_pipedir(struct super_block *pipefs_sb, struct rpc_clnt *clnt) |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 153 | { |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 154 | struct dentry *dentry; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 155 | |
Trond Myklebust | c36dcfe1 | 2013-08-26 17:44:26 -0400 | [diff] [blame] | 156 | if (clnt->cl_program->pipe_dir_name != NULL) { |
| 157 | dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt); |
| 158 | if (IS_ERR(dentry)) |
| 159 | return PTR_ERR(dentry); |
| 160 | } |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 161 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 164 | static int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event) |
Stanislav Kinsbursky | ea8cfa0 | 2012-04-27 13:00:17 +0400 | [diff] [blame] | 165 | { |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 166 | if (clnt->cl_program->pipe_dir_name == NULL) |
Stanislav Kinsbursky | ea8cfa0 | 2012-04-27 13:00:17 +0400 | [diff] [blame] | 167 | return 1; |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 168 | |
Trond Myklebust | c36dcfe1 | 2013-08-26 17:44:26 -0400 | [diff] [blame] | 169 | switch (event) { |
| 170 | case RPC_PIPEFS_MOUNT: |
| 171 | if (clnt->cl_pipedir_objects.pdh_dentry != NULL) |
| 172 | return 1; |
| 173 | if (atomic_read(&clnt->cl_count) == 0) |
| 174 | return 1; |
| 175 | break; |
| 176 | case RPC_PIPEFS_UMOUNT: |
| 177 | if (clnt->cl_pipedir_objects.pdh_dentry == NULL) |
| 178 | return 1; |
| 179 | break; |
| 180 | } |
Stanislav Kinsbursky | ea8cfa0 | 2012-04-27 13:00:17 +0400 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event, |
| 185 | struct super_block *sb) |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 186 | { |
| 187 | struct dentry *dentry; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 188 | |
| 189 | switch (event) { |
| 190 | case RPC_PIPEFS_MOUNT: |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 191 | dentry = rpc_setup_pipedir_sb(sb, clnt); |
Weston Andros Adamson | 922eeac | 2012-10-23 10:43:25 -0400 | [diff] [blame] | 192 | if (!dentry) |
| 193 | return -ENOENT; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 194 | if (IS_ERR(dentry)) |
| 195 | return PTR_ERR(dentry); |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 196 | break; |
| 197 | case RPC_PIPEFS_UMOUNT: |
| 198 | __rpc_clnt_remove_pipedir(clnt); |
| 199 | break; |
| 200 | default: |
| 201 | printk(KERN_ERR "%s: unknown event: %ld\n", __func__, event); |
| 202 | return -ENOTSUPP; |
| 203 | } |
Amitoj Kaur Chawla | 2813b62 | 2016-08-08 14:43:49 +0530 | [diff] [blame] | 204 | return 0; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 205 | } |
| 206 | |
Stanislav Kinsbursky | ea8cfa0 | 2012-04-27 13:00:17 +0400 | [diff] [blame] | 207 | static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event, |
| 208 | struct super_block *sb) |
| 209 | { |
| 210 | int error = 0; |
| 211 | |
| 212 | for (;; clnt = clnt->cl_parent) { |
| 213 | if (!rpc_clnt_skip_event(clnt, event)) |
| 214 | error = __rpc_clnt_handle_event(clnt, event, sb); |
| 215 | if (error || clnt == clnt->cl_parent) |
| 216 | break; |
| 217 | } |
| 218 | return error; |
| 219 | } |
| 220 | |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 221 | static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event) |
| 222 | { |
| 223 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
| 224 | struct rpc_clnt *clnt; |
| 225 | |
| 226 | spin_lock(&sn->rpc_client_lock); |
| 227 | list_for_each_entry(clnt, &sn->all_clients, cl_clients) { |
Stanislav Kinsbursky | ea8cfa0 | 2012-04-27 13:00:17 +0400 | [diff] [blame] | 228 | if (rpc_clnt_skip_event(clnt, event)) |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 229 | continue; |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 230 | spin_unlock(&sn->rpc_client_lock); |
| 231 | return clnt; |
| 232 | } |
| 233 | spin_unlock(&sn->rpc_client_lock); |
| 234 | return NULL; |
| 235 | } |
| 236 | |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 237 | static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, |
| 238 | void *ptr) |
| 239 | { |
| 240 | struct super_block *sb = ptr; |
| 241 | struct rpc_clnt *clnt; |
| 242 | int error = 0; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 243 | |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 244 | while ((clnt = rpc_get_client_for_event(sb->s_fs_info, event))) { |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 245 | error = __rpc_pipefs_event(clnt, event, sb); |
| 246 | if (error) |
| 247 | break; |
| 248 | } |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 249 | return error; |
| 250 | } |
| 251 | |
| 252 | static struct notifier_block rpc_clients_block = { |
| 253 | .notifier_call = rpc_pipefs_event, |
Stanislav Kinsbursky | eee17325 | 2012-01-10 16:13:19 +0400 | [diff] [blame] | 254 | .priority = SUNRPC_PIPEFS_RPC_PRIO, |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | int rpc_clients_notifier_register(void) |
| 258 | { |
| 259 | return rpc_pipefs_notifier_register(&rpc_clients_block); |
| 260 | } |
| 261 | |
| 262 | void rpc_clients_notifier_unregister(void) |
| 263 | { |
| 264 | return rpc_pipefs_notifier_unregister(&rpc_clients_block); |
| 265 | } |
| 266 | |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 267 | static struct rpc_xprt *rpc_clnt_set_transport(struct rpc_clnt *clnt, |
| 268 | struct rpc_xprt *xprt, |
| 269 | const struct rpc_timeout *timeout) |
| 270 | { |
| 271 | struct rpc_xprt *old; |
| 272 | |
| 273 | spin_lock(&clnt->cl_lock); |
Trond Myklebust | 34751b9 | 2013-10-28 16:42:44 -0400 | [diff] [blame] | 274 | old = rcu_dereference_protected(clnt->cl_xprt, |
| 275 | lockdep_is_held(&clnt->cl_lock)); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 276 | |
| 277 | if (!xprt_bound(xprt)) |
| 278 | clnt->cl_autobind = 1; |
| 279 | |
| 280 | clnt->cl_timeout = timeout; |
| 281 | rcu_assign_pointer(clnt->cl_xprt, xprt); |
| 282 | spin_unlock(&clnt->cl_lock); |
| 283 | |
| 284 | return old; |
| 285 | } |
| 286 | |
Trond Myklebust | cbbb344 | 2012-04-30 11:52:40 -0400 | [diff] [blame] | 287 | static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename) |
| 288 | { |
Trond Myklebust | 03a9a42 | 2015-01-30 18:12:28 -0500 | [diff] [blame] | 289 | clnt->cl_nodelen = strlcpy(clnt->cl_nodename, |
| 290 | nodename, sizeof(clnt->cl_nodename)); |
Trond Myklebust | cbbb344 | 2012-04-30 11:52:40 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Chuck Lever | d746e54 | 2013-10-17 14:12:17 -0400 | [diff] [blame] | 293 | static int rpc_client_register(struct rpc_clnt *clnt, |
| 294 | rpc_authflavor_t pseudoflavor, |
| 295 | const char *client_name) |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 296 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 297 | struct rpc_auth_create_args auth_args = { |
Chuck Lever | d746e54 | 2013-10-17 14:12:17 -0400 | [diff] [blame] | 298 | .pseudoflavor = pseudoflavor, |
| 299 | .target_name = client_name, |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 300 | }; |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 301 | struct rpc_auth *auth; |
| 302 | struct net *net = rpc_net_ns(clnt); |
| 303 | struct super_block *pipefs_sb; |
Trond Myklebust | eeee245 | 2013-07-10 15:33:01 -0400 | [diff] [blame] | 304 | int err; |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 305 | |
Jeff Layton | f9c72d1 | 2015-03-31 12:03:28 -0400 | [diff] [blame] | 306 | rpc_clnt_debugfs_register(clnt); |
Jeff Layton | b4b9d2c | 2014-11-26 14:44:43 -0500 | [diff] [blame] | 307 | |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 308 | pipefs_sb = rpc_get_sb_net(net); |
| 309 | if (pipefs_sb) { |
Trond Myklebust | 41b6b4d | 2013-08-23 13:03:50 -0400 | [diff] [blame] | 310 | err = rpc_setup_pipedir(pipefs_sb, clnt); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 311 | if (err) |
| 312 | goto out; |
| 313 | } |
| 314 | |
Trond Myklebust | eeee245 | 2013-07-10 15:33:01 -0400 | [diff] [blame] | 315 | rpc_register_client(clnt); |
| 316 | if (pipefs_sb) |
| 317 | rpc_put_sb_net(net); |
| 318 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 319 | auth = rpcauth_create(&auth_args, clnt); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 320 | if (IS_ERR(auth)) { |
| 321 | dprintk("RPC: Couldn't create auth handle (flavor %u)\n", |
Chuck Lever | d746e54 | 2013-10-17 14:12:17 -0400 | [diff] [blame] | 322 | pseudoflavor); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 323 | err = PTR_ERR(auth); |
| 324 | goto err_auth; |
| 325 | } |
Trond Myklebust | eeee245 | 2013-07-10 15:33:01 -0400 | [diff] [blame] | 326 | return 0; |
| 327 | err_auth: |
| 328 | pipefs_sb = rpc_get_sb_net(net); |
Trond Myklebust | 1540c5d | 2013-07-14 22:57:50 -0400 | [diff] [blame] | 329 | rpc_unregister_client(clnt); |
Trond Myklebust | eeee245 | 2013-07-10 15:33:01 -0400 | [diff] [blame] | 330 | __rpc_clnt_remove_pipedir(clnt); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 331 | out: |
| 332 | if (pipefs_sb) |
| 333 | rpc_put_sb_net(net); |
Jeff Layton | b4b9d2c | 2014-11-26 14:44:43 -0500 | [diff] [blame] | 334 | rpc_clnt_debugfs_unregister(clnt); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 335 | return err; |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 336 | } |
| 337 | |
Trond Myklebust | 2f048db | 2013-09-04 21:51:44 -0400 | [diff] [blame] | 338 | static DEFINE_IDA(rpc_clids); |
| 339 | |
Kinglong Mee | c929ea0 | 2017-01-20 16:48:39 +0800 | [diff] [blame] | 340 | void rpc_cleanup_clids(void) |
| 341 | { |
| 342 | ida_destroy(&rpc_clids); |
| 343 | } |
| 344 | |
Trond Myklebust | 2f048db | 2013-09-04 21:51:44 -0400 | [diff] [blame] | 345 | static int rpc_alloc_clid(struct rpc_clnt *clnt) |
| 346 | { |
| 347 | int clid; |
| 348 | |
| 349 | clid = ida_simple_get(&rpc_clids, 0, 0, GFP_KERNEL); |
| 350 | if (clid < 0) |
| 351 | return clid; |
| 352 | clnt->cl_clid = clid; |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static void rpc_free_clid(struct rpc_clnt *clnt) |
| 357 | { |
| 358 | ida_simple_remove(&rpc_clids, clnt->cl_clid); |
| 359 | } |
| 360 | |
Trond Myklebust | 280ebcf | 2013-09-02 13:28:04 -0400 | [diff] [blame] | 361 | static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 362 | struct rpc_xprt_switch *xps, |
Trond Myklebust | 280ebcf | 2013-09-02 13:28:04 -0400 | [diff] [blame] | 363 | struct rpc_xprt *xprt, |
| 364 | struct rpc_clnt *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 366 | const struct rpc_program *program = args->program; |
| 367 | const struct rpc_version *version; |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 368 | struct rpc_clnt *clnt = NULL; |
| 369 | const struct rpc_timeout *timeout; |
Trond Myklebust | 03a9a42 | 2015-01-30 18:12:28 -0500 | [diff] [blame] | 370 | const char *nodename = args->nodename; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | int err; |
Chuck Lever | 06b8d25 | 2007-09-11 18:00:20 -0400 | [diff] [blame] | 372 | |
| 373 | /* sanity check the name before trying to print it */ |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 374 | dprintk("RPC: creating %s client for %s (xprt %p)\n", |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 375 | program->name, args->servername, xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 377 | err = rpciod_up(); |
| 378 | if (err) |
| 379 | goto out_no_rpciod; |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 380 | |
Trond Myklebust | f05c124 | 2013-04-05 14:13:21 -0400 | [diff] [blame] | 381 | err = -EINVAL; |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 382 | if (args->version >= program->nrvers) |
| 383 | goto out_err; |
| 384 | version = program->version[args->version]; |
| 385 | if (version == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | goto out_err; |
| 387 | |
| 388 | err = -ENOMEM; |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 389 | clnt = kzalloc(sizeof(*clnt), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | if (!clnt) |
| 391 | goto out_err; |
Trond Myklebust | 280ebcf | 2013-09-02 13:28:04 -0400 | [diff] [blame] | 392 | clnt->cl_parent = parent ? : clnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Trond Myklebust | 2f048db | 2013-09-04 21:51:44 -0400 | [diff] [blame] | 394 | err = rpc_alloc_clid(clnt); |
| 395 | if (err) |
| 396 | goto out_no_clid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 398 | clnt->cl_cred = get_cred(args->cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | clnt->cl_procinfo = version->procs; |
| 400 | clnt->cl_maxproc = version->nrprocs; |
Benny Halevy | d5b337b | 2008-09-28 09:21:26 +0300 | [diff] [blame] | 401 | clnt->cl_prog = args->prognumber ? : program->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | clnt->cl_vers = version->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | clnt->cl_stats = program->stats; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 404 | clnt->cl_metrics = rpc_alloc_iostats(clnt); |
Trond Myklebust | 6739ffb | 2013-08-26 15:38:11 -0400 | [diff] [blame] | 405 | rpc_init_pipe_dir_head(&clnt->cl_pipedir_objects); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 406 | err = -ENOMEM; |
| 407 | if (clnt->cl_metrics == NULL) |
| 408 | goto out_no_stats; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 409 | clnt->cl_program = program; |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 410 | INIT_LIST_HEAD(&clnt->cl_tasks); |
Trond Myklebust | 4bef61f | 2007-06-16 14:17:01 -0400 | [diff] [blame] | 411 | spin_lock_init(&clnt->cl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 413 | timeout = xprt->timeout; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 414 | if (args->timeout != NULL) { |
| 415 | memcpy(&clnt->cl_timeout_default, args->timeout, |
| 416 | sizeof(clnt->cl_timeout_default)); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 417 | timeout = &clnt->cl_timeout_default; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 418 | } |
| 419 | |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 420 | rpc_clnt_set_transport(clnt, xprt, timeout); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 421 | xprt_iter_init(&clnt->cl_xpi, xps); |
| 422 | xprt_switch_put(xps); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | clnt->cl_rtt = &clnt->cl_rtt_default; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 425 | rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 427 | atomic_set(&clnt->cl_count, 1); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 428 | |
Trond Myklebust | 03a9a42 | 2015-01-30 18:12:28 -0500 | [diff] [blame] | 429 | if (nodename == NULL) |
| 430 | nodename = utsname()->nodename; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* save the nodename */ |
Trond Myklebust | 03a9a42 | 2015-01-30 18:12:28 -0500 | [diff] [blame] | 432 | rpc_clnt_set_nodename(clnt, nodename); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 433 | |
Chuck Lever | d746e54 | 2013-10-17 14:12:17 -0400 | [diff] [blame] | 434 | err = rpc_client_register(clnt, args->authflavor, args->client_name); |
Stanislav Kinsbursky | e73f4cc | 2013-06-24 11:52:52 +0400 | [diff] [blame] | 435 | if (err) |
| 436 | goto out_no_path; |
Trond Myklebust | 280ebcf | 2013-09-02 13:28:04 -0400 | [diff] [blame] | 437 | if (parent) |
| 438 | atomic_inc(&parent->cl_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | return clnt; |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | out_no_path: |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 442 | rpc_free_iostats(clnt->cl_metrics); |
| 443 | out_no_stats: |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 444 | put_cred(clnt->cl_cred); |
Trond Myklebust | 2f048db | 2013-09-04 21:51:44 -0400 | [diff] [blame] | 445 | rpc_free_clid(clnt); |
| 446 | out_no_clid: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | kfree(clnt); |
| 448 | out_err: |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 449 | rpciod_down(); |
| 450 | out_no_rpciod: |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 451 | xprt_switch_put(xps); |
Trond Myklebust | f05c124 | 2013-04-05 14:13:21 -0400 | [diff] [blame] | 452 | xprt_put(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return ERR_PTR(err); |
| 454 | } |
| 455 | |
J. Bruce Fields | d50039e | 2016-05-16 17:03:42 -0400 | [diff] [blame] | 456 | static struct rpc_clnt *rpc_create_xprt(struct rpc_create_args *args, |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 457 | struct rpc_xprt *xprt) |
| 458 | { |
| 459 | struct rpc_clnt *clnt = NULL; |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 460 | struct rpc_xprt_switch *xps; |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 461 | |
J. Bruce Fields | 39a9beab | 2016-05-17 12:38:21 -0400 | [diff] [blame] | 462 | if (args->bc_xprt && args->bc_xprt->xpt_bc_xps) { |
Chuck Lever | 16590a2 | 2016-08-22 14:57:42 -0400 | [diff] [blame] | 463 | WARN_ON_ONCE(!(args->protocol & XPRT_TRANSPORT_BC)); |
J. Bruce Fields | 39a9beab | 2016-05-17 12:38:21 -0400 | [diff] [blame] | 464 | xps = args->bc_xprt->xpt_bc_xps; |
| 465 | xprt_switch_get(xps); |
| 466 | } else { |
| 467 | xps = xprt_switch_alloc(xprt, GFP_KERNEL); |
| 468 | if (xps == NULL) { |
| 469 | xprt_put(xprt); |
| 470 | return ERR_PTR(-ENOMEM); |
| 471 | } |
| 472 | if (xprt->bc_xprt) { |
| 473 | xprt_switch_get(xps); |
| 474 | xprt->bc_xprt->xpt_bc_xps = xps; |
| 475 | } |
J. Bruce Fields | 1208fd5 | 2016-05-20 17:07:17 -0400 | [diff] [blame] | 476 | } |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 477 | clnt = rpc_new_client(args, xps, xprt, NULL); |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 478 | if (IS_ERR(clnt)) |
| 479 | return clnt; |
| 480 | |
| 481 | if (!(args->flags & RPC_CLNT_CREATE_NOPING)) { |
| 482 | int err = rpc_ping(clnt); |
| 483 | if (err != 0) { |
| 484 | rpc_shutdown_client(clnt); |
| 485 | return ERR_PTR(err); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | clnt->cl_softrtry = 1; |
Trond Myklebust | ae6ec91 | 2019-04-07 13:58:58 -0400 | [diff] [blame] | 490 | if (args->flags & (RPC_CLNT_CREATE_HARDRTRY|RPC_CLNT_CREATE_SOFTERR)) { |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 491 | clnt->cl_softrtry = 0; |
Trond Myklebust | ae6ec91 | 2019-04-07 13:58:58 -0400 | [diff] [blame] | 492 | if (args->flags & RPC_CLNT_CREATE_SOFTERR) |
| 493 | clnt->cl_softerr = 1; |
| 494 | } |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 495 | |
| 496 | if (args->flags & RPC_CLNT_CREATE_AUTOBIND) |
| 497 | clnt->cl_autobind = 1; |
Trond Myklebust | 2aca5b8 | 2014-09-24 22:35:58 -0400 | [diff] [blame] | 498 | if (args->flags & RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT) |
| 499 | clnt->cl_noretranstimeo = 1; |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 500 | if (args->flags & RPC_CLNT_CREATE_DISCRTRY) |
| 501 | clnt->cl_discrtry = 1; |
| 502 | if (!(args->flags & RPC_CLNT_CREATE_QUIET)) |
| 503 | clnt->cl_chatty = 1; |
| 504 | |
| 505 | return clnt; |
| 506 | } |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 507 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 508 | /** |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 509 | * rpc_create - create an RPC client and transport with one call |
| 510 | * @args: rpc_clnt create argument structure |
| 511 | * |
| 512 | * Creates and initializes an RPC transport and an RPC client. |
| 513 | * |
| 514 | * It can ping the server in order to determine if it is up, and to see if |
| 515 | * it supports this program and version. RPC_CLNT_CREATE_NOPING disables |
| 516 | * this behavior so asynchronous tasks can also use rpc_create. |
| 517 | */ |
| 518 | struct rpc_clnt *rpc_create(struct rpc_create_args *args) |
| 519 | { |
| 520 | struct rpc_xprt *xprt; |
\"Talpey, Thomas\ | 3c341b0b | 2007-09-10 13:47:07 -0400 | [diff] [blame] | 521 | struct xprt_create xprtargs = { |
Pavel Emelyanov | 9a23e33 | 2010-09-29 16:05:12 +0400 | [diff] [blame] | 522 | .net = args->net, |
\"Talpey, Thomas\ | 4fa016e | 2007-09-10 13:47:57 -0400 | [diff] [blame] | 523 | .ident = args->protocol, |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 524 | .srcaddr = args->saddress, |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 525 | .dstaddr = args->address, |
| 526 | .addrlen = args->addrsize, |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 527 | .servername = args->servername, |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 528 | .bc_xprt = args->bc_xprt, |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 529 | }; |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 530 | char servername[48]; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 531 | |
J. Bruce Fields | d50039e | 2016-05-16 17:03:42 -0400 | [diff] [blame] | 532 | if (args->bc_xprt) { |
Chuck Lever | 16590a2 | 2016-08-22 14:57:42 -0400 | [diff] [blame] | 533 | WARN_ON_ONCE(!(args->protocol & XPRT_TRANSPORT_BC)); |
J. Bruce Fields | d50039e | 2016-05-16 17:03:42 -0400 | [diff] [blame] | 534 | xprt = args->bc_xprt->xpt_bc_xprt; |
| 535 | if (xprt) { |
| 536 | xprt_get(xprt); |
| 537 | return rpc_create_xprt(args, xprt); |
| 538 | } |
| 539 | } |
| 540 | |
Trond Myklebust | b7993ce | 2013-04-14 11:42:00 -0400 | [diff] [blame] | 541 | if (args->flags & RPC_CLNT_CREATE_INFINITE_SLOTS) |
| 542 | xprtargs.flags |= XPRT_CREATE_INFINITE_SLOTS; |
J. Bruce Fields | 33d90ac | 2013-04-11 15:06:36 -0400 | [diff] [blame] | 543 | if (args->flags & RPC_CLNT_CREATE_NO_IDLE_TIMEOUT) |
| 544 | xprtargs.flags |= XPRT_CREATE_NO_IDLE_TIMEOUT; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 545 | /* |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 546 | * If the caller chooses not to specify a hostname, whip |
| 547 | * up a string representation of the passed-in address. |
| 548 | */ |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 549 | if (xprtargs.servername == NULL) { |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 550 | struct sockaddr_un *sun = |
| 551 | (struct sockaddr_un *)args->address; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 552 | struct sockaddr_in *sin = |
| 553 | (struct sockaddr_in *)args->address; |
| 554 | struct sockaddr_in6 *sin6 = |
| 555 | (struct sockaddr_in6 *)args->address; |
| 556 | |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 557 | servername[0] = '\0'; |
| 558 | switch (args->address->sa_family) { |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 559 | case AF_LOCAL: |
| 560 | snprintf(servername, sizeof(servername), "%s", |
| 561 | sun->sun_path); |
| 562 | break; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 563 | case AF_INET: |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 564 | snprintf(servername, sizeof(servername), "%pI4", |
| 565 | &sin->sin_addr.s_addr); |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 566 | break; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 567 | case AF_INET6: |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 568 | snprintf(servername, sizeof(servername), "%pI6", |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 569 | &sin6->sin6_addr); |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 570 | break; |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 571 | default: |
| 572 | /* caller wants default server name, but |
| 573 | * address family isn't recognized. */ |
| 574 | return ERR_PTR(-EINVAL); |
| 575 | } |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 576 | xprtargs.servername = servername; |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 579 | xprt = xprt_create_transport(&xprtargs); |
| 580 | if (IS_ERR(xprt)) |
| 581 | return (struct rpc_clnt *)xprt; |
| 582 | |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 583 | /* |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 584 | * By default, kernel RPC client connects from a reserved port. |
| 585 | * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters, |
| 586 | * but it is always enabled for rpciod, which handles the connect |
| 587 | * operation. |
| 588 | */ |
| 589 | xprt->resvport = 1; |
| 590 | if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT) |
| 591 | xprt->resvport = 0; |
| 592 | |
Kinglong Mee | 83ddfeb | 2014-03-24 11:58:59 +0800 | [diff] [blame] | 593 | return rpc_create_xprt(args, xprt); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 594 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 595 | EXPORT_SYMBOL_GPL(rpc_create); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* |
| 598 | * This function clones the RPC client structure. It allows us to share the |
| 599 | * same transport while varying parameters such as the authentication |
| 600 | * flavour. |
| 601 | */ |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 602 | static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args, |
| 603 | struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 605 | struct rpc_xprt_switch *xps; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 606 | struct rpc_xprt *xprt; |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 607 | struct rpc_clnt *new; |
| 608 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 610 | err = -ENOMEM; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 611 | rcu_read_lock(); |
| 612 | xprt = xprt_get(rcu_dereference(clnt->cl_xprt)); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 613 | xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 614 | rcu_read_unlock(); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 615 | if (xprt == NULL || xps == NULL) { |
| 616 | xprt_put(xprt); |
| 617 | xprt_switch_put(xps); |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 618 | goto out_err; |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 619 | } |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 620 | args->servername = xprt->servername; |
Trond Myklebust | 03a9a42 | 2015-01-30 18:12:28 -0500 | [diff] [blame] | 621 | args->nodename = clnt->cl_nodename; |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 622 | |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 623 | new = rpc_new_client(args, xps, xprt, clnt); |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 624 | if (IS_ERR(new)) { |
| 625 | err = PTR_ERR(new); |
Chuck Lever | a58e0be | 2013-03-22 12:52:59 -0400 | [diff] [blame] | 626 | goto out_err; |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 629 | /* Turn off autobind on clones */ |
| 630 | new->cl_autobind = 0; |
| 631 | new->cl_softrtry = clnt->cl_softrtry; |
Trond Myklebust | ae6ec91 | 2019-04-07 13:58:58 -0400 | [diff] [blame] | 632 | new->cl_softerr = clnt->cl_softerr; |
Trond Myklebust | 2aca5b8 | 2014-09-24 22:35:58 -0400 | [diff] [blame] | 633 | new->cl_noretranstimeo = clnt->cl_noretranstimeo; |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 634 | new->cl_discrtry = clnt->cl_discrtry; |
| 635 | new->cl_chatty = clnt->cl_chatty; |
NeilBrown | 5e16923 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 636 | new->cl_principal = clnt->cl_principal; |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 637 | new->cl_cred = get_cred(clnt->cl_cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return new; |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 639 | |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 640 | out_err: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 641 | dprintk("RPC: %s: returned error %d\n", __func__, err); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 642 | return ERR_PTR(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 644 | |
| 645 | /** |
| 646 | * rpc_clone_client - Clone an RPC client structure |
| 647 | * |
| 648 | * @clnt: RPC client whose parameters are copied |
| 649 | * |
| 650 | * Returns a fresh RPC client or an ERR_PTR. |
| 651 | */ |
| 652 | struct rpc_clnt *rpc_clone_client(struct rpc_clnt *clnt) |
| 653 | { |
| 654 | struct rpc_create_args args = { |
| 655 | .program = clnt->cl_program, |
| 656 | .prognumber = clnt->cl_prog, |
| 657 | .version = clnt->cl_vers, |
| 658 | .authflavor = clnt->cl_auth->au_flavor, |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 659 | .cred = clnt->cl_cred, |
Chuck Lever | 1b63a75 | 2012-09-14 17:23:52 -0400 | [diff] [blame] | 660 | }; |
| 661 | return __rpc_clone_client(&args, clnt); |
| 662 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 663 | EXPORT_SYMBOL_GPL(rpc_clone_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Chuck Lever | ba9b584 | 2012-09-14 17:24:02 -0400 | [diff] [blame] | 665 | /** |
| 666 | * rpc_clone_client_set_auth - Clone an RPC client structure and set its auth |
| 667 | * |
| 668 | * @clnt: RPC client whose parameters are copied |
Randy Dunlap | 7144bca | 2013-01-09 17:12:35 -0800 | [diff] [blame] | 669 | * @flavor: security flavor for new client |
Chuck Lever | ba9b584 | 2012-09-14 17:24:02 -0400 | [diff] [blame] | 670 | * |
| 671 | * Returns a fresh RPC client or an ERR_PTR. |
| 672 | */ |
| 673 | struct rpc_clnt * |
| 674 | rpc_clone_client_set_auth(struct rpc_clnt *clnt, rpc_authflavor_t flavor) |
| 675 | { |
| 676 | struct rpc_create_args args = { |
| 677 | .program = clnt->cl_program, |
| 678 | .prognumber = clnt->cl_prog, |
| 679 | .version = clnt->cl_vers, |
| 680 | .authflavor = flavor, |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 681 | .cred = clnt->cl_cred, |
Chuck Lever | ba9b584 | 2012-09-14 17:24:02 -0400 | [diff] [blame] | 682 | }; |
| 683 | return __rpc_clone_client(&args, clnt); |
| 684 | } |
| 685 | EXPORT_SYMBOL_GPL(rpc_clone_client_set_auth); |
| 686 | |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 687 | /** |
| 688 | * rpc_switch_client_transport: switch the RPC transport on the fly |
| 689 | * @clnt: pointer to a struct rpc_clnt |
| 690 | * @args: pointer to the new transport arguments |
| 691 | * @timeout: pointer to the new timeout parameters |
| 692 | * |
| 693 | * This function allows the caller to switch the RPC transport for the |
| 694 | * rpc_clnt structure 'clnt' to allow it to connect to a mirrored NFS |
| 695 | * server, for instance. It assumes that the caller has ensured that |
| 696 | * there are no active RPC tasks by using some form of locking. |
| 697 | * |
| 698 | * Returns zero if "clnt" is now using the new xprt. Otherwise a |
| 699 | * negative errno is returned, and "clnt" continues to use the old |
| 700 | * xprt. |
| 701 | */ |
| 702 | int rpc_switch_client_transport(struct rpc_clnt *clnt, |
| 703 | struct xprt_create *args, |
| 704 | const struct rpc_timeout *timeout) |
| 705 | { |
| 706 | const struct rpc_timeout *old_timeo; |
| 707 | rpc_authflavor_t pseudoflavor; |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 708 | struct rpc_xprt_switch *xps, *oldxps; |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 709 | struct rpc_xprt *xprt, *old; |
| 710 | struct rpc_clnt *parent; |
| 711 | int err; |
| 712 | |
| 713 | xprt = xprt_create_transport(args); |
| 714 | if (IS_ERR(xprt)) { |
| 715 | dprintk("RPC: failed to create new xprt for clnt %p\n", |
| 716 | clnt); |
| 717 | return PTR_ERR(xprt); |
| 718 | } |
| 719 | |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 720 | xps = xprt_switch_alloc(xprt, GFP_KERNEL); |
| 721 | if (xps == NULL) { |
| 722 | xprt_put(xprt); |
| 723 | return -ENOMEM; |
| 724 | } |
| 725 | |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 726 | pseudoflavor = clnt->cl_auth->au_flavor; |
| 727 | |
| 728 | old_timeo = clnt->cl_timeout; |
| 729 | old = rpc_clnt_set_transport(clnt, xprt, timeout); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 730 | oldxps = xprt_iter_xchg_switch(&clnt->cl_xpi, xps); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 731 | |
| 732 | rpc_unregister_client(clnt); |
| 733 | __rpc_clnt_remove_pipedir(clnt); |
Jeff Layton | b4b9d2c | 2014-11-26 14:44:43 -0500 | [diff] [blame] | 734 | rpc_clnt_debugfs_unregister(clnt); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * A new transport was created. "clnt" therefore |
| 738 | * becomes the root of a new cl_parent tree. clnt's |
| 739 | * children, if it has any, still point to the old xprt. |
| 740 | */ |
| 741 | parent = clnt->cl_parent; |
| 742 | clnt->cl_parent = clnt; |
| 743 | |
| 744 | /* |
| 745 | * The old rpc_auth cache cannot be re-used. GSS |
| 746 | * contexts in particular are between a single |
| 747 | * client and server. |
| 748 | */ |
| 749 | err = rpc_client_register(clnt, pseudoflavor, NULL); |
| 750 | if (err) |
| 751 | goto out_revert; |
| 752 | |
| 753 | synchronize_rcu(); |
| 754 | if (parent != clnt) |
| 755 | rpc_release_client(parent); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 756 | xprt_switch_put(oldxps); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 757 | xprt_put(old); |
| 758 | dprintk("RPC: replaced xprt for clnt %p\n", clnt); |
| 759 | return 0; |
| 760 | |
| 761 | out_revert: |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 762 | xps = xprt_iter_xchg_switch(&clnt->cl_xpi, oldxps); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 763 | rpc_clnt_set_transport(clnt, old, old_timeo); |
| 764 | clnt->cl_parent = parent; |
| 765 | rpc_client_register(clnt, pseudoflavor, NULL); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 766 | xprt_switch_put(xps); |
Trond Myklebust | 40b00b6b | 2013-10-17 14:12:23 -0400 | [diff] [blame] | 767 | xprt_put(xprt); |
| 768 | dprintk("RPC: failed to switch xprt for clnt %p\n", clnt); |
| 769 | return err; |
| 770 | } |
| 771 | EXPORT_SYMBOL_GPL(rpc_switch_client_transport); |
| 772 | |
Trond Myklebust | 3227886 | 2016-01-30 20:39:19 -0500 | [diff] [blame] | 773 | static |
| 774 | int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi) |
| 775 | { |
| 776 | struct rpc_xprt_switch *xps; |
| 777 | |
| 778 | rcu_read_lock(); |
| 779 | xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); |
| 780 | rcu_read_unlock(); |
| 781 | if (xps == NULL) |
| 782 | return -EAGAIN; |
| 783 | xprt_iter_init_listall(xpi, xps); |
| 784 | xprt_switch_put(xps); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * rpc_clnt_iterate_for_each_xprt - Apply a function to all transports |
| 790 | * @clnt: pointer to client |
| 791 | * @fn: function to apply |
| 792 | * @data: void pointer to function data |
| 793 | * |
| 794 | * Iterates through the list of RPC transports currently attached to the |
| 795 | * client and applies the function fn(clnt, xprt, data). |
| 796 | * |
| 797 | * On error, the iteration stops, and the function returns the error value. |
| 798 | */ |
| 799 | int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt, |
| 800 | int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *), |
| 801 | void *data) |
| 802 | { |
| 803 | struct rpc_xprt_iter xpi; |
| 804 | int ret; |
| 805 | |
| 806 | ret = rpc_clnt_xprt_iter_init(clnt, &xpi); |
| 807 | if (ret) |
| 808 | return ret; |
| 809 | for (;;) { |
| 810 | struct rpc_xprt *xprt = xprt_iter_get_next(&xpi); |
| 811 | |
| 812 | if (!xprt) |
| 813 | break; |
| 814 | ret = fn(clnt, xprt, data); |
| 815 | xprt_put(xprt); |
| 816 | if (ret < 0) |
| 817 | break; |
| 818 | } |
| 819 | xprt_iter_destroy(&xpi); |
| 820 | return ret; |
| 821 | } |
| 822 | EXPORT_SYMBOL_GPL(rpc_clnt_iterate_for_each_xprt); |
| 823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | /* |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 825 | * Kill all tasks for the given client. |
| 826 | * XXX: kill their descendants as well? |
| 827 | */ |
| 828 | void rpc_killall_tasks(struct rpc_clnt *clnt) |
| 829 | { |
| 830 | struct rpc_task *rovr; |
| 831 | |
| 832 | |
| 833 | if (list_empty(&clnt->cl_tasks)) |
| 834 | return; |
| 835 | dprintk("RPC: killing all tasks for client %p\n", clnt); |
| 836 | /* |
| 837 | * Spin lock all_tasks to prevent changes... |
| 838 | */ |
| 839 | spin_lock(&clnt->cl_lock); |
Trond Myklebust | ae67bd3 | 2019-04-07 13:58:44 -0400 | [diff] [blame] | 840 | list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) |
| 841 | rpc_signal_task(rovr); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 842 | spin_unlock(&clnt->cl_lock); |
| 843 | } |
| 844 | EXPORT_SYMBOL_GPL(rpc_killall_tasks); |
| 845 | |
| 846 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | * Properly shut down an RPC client, terminating all outstanding |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 848 | * requests. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | */ |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 850 | void rpc_shutdown_client(struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
Weston Andros Adamson | 168e4b3 | 2012-10-30 17:01:40 -0400 | [diff] [blame] | 852 | might_sleep(); |
| 853 | |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 854 | dprintk_rcu("RPC: shutting down %s client for %s\n", |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 855 | clnt->cl_program->name, |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 856 | rcu_dereference(clnt->cl_xprt)->servername); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 858 | while (!list_empty(&clnt->cl_tasks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | rpc_killall_tasks(clnt); |
Ingo Molnar | 532347e | 2006-01-09 20:52:53 -0800 | [diff] [blame] | 860 | wait_event_timeout(destroy_wait, |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 861 | list_empty(&clnt->cl_tasks), 1*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 864 | rpc_release_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 866 | EXPORT_SYMBOL_GPL(rpc_shutdown_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 869 | * Free an RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | */ |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 871 | static struct rpc_clnt * |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 872 | rpc_free_client(struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 874 | struct rpc_clnt *parent = NULL; |
| 875 | |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 876 | dprintk_rcu("RPC: destroying %s client for %s\n", |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 877 | clnt->cl_program->name, |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 878 | rcu_dereference(clnt->cl_xprt)->servername); |
Trond Myklebust | 6eac7d3 | 2012-01-20 13:53:37 -0500 | [diff] [blame] | 879 | if (clnt->cl_parent != clnt) |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 880 | parent = clnt->cl_parent; |
Jeff Layton | b4b9d2c | 2014-11-26 14:44:43 -0500 | [diff] [blame] | 881 | rpc_clnt_debugfs_unregister(clnt); |
Stanislav Kinsbursky | f513125 | 2012-01-11 19:18:26 +0400 | [diff] [blame] | 882 | rpc_clnt_remove_pipedir(clnt); |
Stanislav Kinsbursky | adb6fa7 | 2013-06-26 10:15:14 +0400 | [diff] [blame] | 883 | rpc_unregister_client(clnt); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 884 | rpc_free_iostats(clnt->cl_metrics); |
| 885 | clnt->cl_metrics = NULL; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 886 | xprt_put(rcu_dereference_raw(clnt->cl_xprt)); |
Trond Myklebust | ad01b2c | 2016-01-30 14:17:26 -0500 | [diff] [blame] | 887 | xprt_iter_destroy(&clnt->cl_xpi); |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 888 | rpciod_down(); |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 889 | put_cred(clnt->cl_cred); |
Trond Myklebust | 2f048db | 2013-09-04 21:51:44 -0400 | [diff] [blame] | 890 | rpc_free_clid(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | kfree(clnt); |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 892 | return parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /* |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 896 | * Free an RPC client |
| 897 | */ |
Stephen Hemminger | 8fdee4c | 2018-07-24 12:29:15 -0700 | [diff] [blame] | 898 | static struct rpc_clnt * |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 899 | rpc_free_auth(struct rpc_clnt *clnt) |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 900 | { |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 901 | if (clnt->cl_auth == NULL) |
| 902 | return rpc_free_client(clnt); |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 903 | |
| 904 | /* |
| 905 | * Note: RPCSEC_GSS may need to send NULL RPC calls in order to |
| 906 | * release remaining GSS contexts. This mechanism ensures |
| 907 | * that it can do so safely. |
| 908 | */ |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 909 | atomic_inc(&clnt->cl_count); |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 910 | rpcauth_release(clnt->cl_auth); |
| 911 | clnt->cl_auth = NULL; |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 912 | if (atomic_dec_and_test(&clnt->cl_count)) |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 913 | return rpc_free_client(clnt); |
| 914 | return NULL; |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 918 | * Release reference to the RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | */ |
| 920 | void |
| 921 | rpc_release_client(struct rpc_clnt *clnt) |
| 922 | { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 923 | dprintk("RPC: rpc_release_client(%p)\n", clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Trond Myklebust | d07ba84 | 2013-11-12 17:24:36 -0500 | [diff] [blame] | 925 | do { |
| 926 | if (list_empty(&clnt->cl_tasks)) |
| 927 | wake_up(&destroy_wait); |
| 928 | if (!atomic_dec_and_test(&clnt->cl_count)) |
| 929 | break; |
| 930 | clnt = rpc_free_auth(clnt); |
| 931 | } while (clnt != NULL); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 932 | } |
Simo Sorce | 1d65833 | 2012-05-25 18:09:55 -0400 | [diff] [blame] | 933 | EXPORT_SYMBOL_GPL(rpc_release_client); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 934 | |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 935 | /** |
| 936 | * rpc_bind_new_program - bind a new RPC program to an existing client |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 937 | * @old: old rpc_client |
| 938 | * @program: rpc program to set |
| 939 | * @vers: rpc program version |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 940 | * |
| 941 | * Clones the rpc client and sets up a new RPC program. This is mainly |
| 942 | * of use for enabling different RPC programs to share the same transport. |
| 943 | * The Sun NFSv2/v3 ACL protocol can do this. |
| 944 | */ |
| 945 | struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old, |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 946 | const struct rpc_program *program, |
Chuck Lever | 89eb21c | 2007-09-11 18:00:09 -0400 | [diff] [blame] | 947 | u32 vers) |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 948 | { |
Trond Myklebust | f994c43 | 2012-11-01 12:14:14 -0400 | [diff] [blame] | 949 | struct rpc_create_args args = { |
| 950 | .program = program, |
| 951 | .prognumber = program->number, |
| 952 | .version = vers, |
| 953 | .authflavor = old->cl_auth->au_flavor, |
Trond Myklebust | 79caa5f | 2019-04-24 17:46:42 -0400 | [diff] [blame] | 954 | .cred = old->cl_cred, |
Trond Myklebust | f994c43 | 2012-11-01 12:14:14 -0400 | [diff] [blame] | 955 | }; |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 956 | struct rpc_clnt *clnt; |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 957 | int err; |
| 958 | |
Trond Myklebust | f994c43 | 2012-11-01 12:14:14 -0400 | [diff] [blame] | 959 | clnt = __rpc_clone_client(&args, old); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 960 | if (IS_ERR(clnt)) |
| 961 | goto out; |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 962 | err = rpc_ping(clnt); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 963 | if (err != 0) { |
| 964 | rpc_shutdown_client(clnt); |
| 965 | clnt = ERR_PTR(err); |
| 966 | } |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 967 | out: |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 968 | return clnt; |
| 969 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 970 | EXPORT_SYMBOL_GPL(rpc_bind_new_program); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 971 | |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 972 | void rpc_task_release_transport(struct rpc_task *task) |
| 973 | { |
| 974 | struct rpc_xprt *xprt = task->tk_xprt; |
| 975 | |
| 976 | if (xprt) { |
| 977 | task->tk_xprt = NULL; |
| 978 | xprt_put(xprt); |
| 979 | } |
| 980 | } |
| 981 | EXPORT_SYMBOL_GPL(rpc_task_release_transport); |
| 982 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 983 | void rpc_task_release_client(struct rpc_task *task) |
| 984 | { |
| 985 | struct rpc_clnt *clnt = task->tk_client; |
| 986 | |
| 987 | if (clnt != NULL) { |
| 988 | /* Remove from client task list */ |
| 989 | spin_lock(&clnt->cl_lock); |
| 990 | list_del(&task->tk_task); |
| 991 | spin_unlock(&clnt->cl_lock); |
| 992 | task->tk_client = NULL; |
| 993 | |
| 994 | rpc_release_client(clnt); |
| 995 | } |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 996 | rpc_task_release_transport(task); |
| 997 | } |
Trond Myklebust | fb43d17 | 2016-01-30 16:39:26 -0500 | [diff] [blame] | 998 | |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 999 | static |
| 1000 | void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt) |
| 1001 | { |
| 1002 | if (!task->tk_xprt) |
| 1003 | task->tk_xprt = xprt_iter_get_next(&clnt->cl_xpi); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static |
| 1007 | void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt) |
| 1008 | { |
Trond Myklebust | fb43d17 | 2016-01-30 16:39:26 -0500 | [diff] [blame] | 1009 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1010 | if (clnt != NULL) { |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 1011 | rpc_task_set_transport(task, clnt); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1012 | task->tk_client = clnt; |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1013 | atomic_inc(&clnt->cl_count); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1014 | if (clnt->cl_softrtry) |
| 1015 | task->tk_flags |= RPC_TASK_SOFT; |
Trond Myklebust | ae6ec91 | 2019-04-07 13:58:58 -0400 | [diff] [blame] | 1016 | if (clnt->cl_softerr) |
| 1017 | task->tk_flags |= RPC_TASK_TIMEOUT; |
Trond Myklebust | 8a19a0b | 2013-09-24 12:00:27 -0400 | [diff] [blame] | 1018 | if (clnt->cl_noretranstimeo) |
| 1019 | task->tk_flags |= RPC_TASK_NO_RETRANS_TIMEOUT; |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 1020 | if (atomic_read(&clnt->cl_swapper)) |
| 1021 | task->tk_flags |= RPC_TASK_SWAPPER; |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1022 | /* Add to the client's list of all tasks */ |
| 1023 | spin_lock(&clnt->cl_lock); |
| 1024 | list_add_tail(&task->tk_task, &clnt->cl_tasks); |
| 1025 | spin_unlock(&clnt->cl_lock); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | static void |
| 1030 | rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg) |
| 1031 | { |
| 1032 | if (msg != NULL) { |
| 1033 | task->tk_msg.rpc_proc = msg->rpc_proc; |
| 1034 | task->tk_msg.rpc_argp = msg->rpc_argp; |
| 1035 | task->tk_msg.rpc_resp = msg->rpc_resp; |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1036 | if (msg->rpc_cred != NULL) |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 1037 | task->tk_msg.rpc_cred = get_cred(msg->rpc_cred); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | /* |
| 1042 | * Default callback for async RPC calls |
| 1043 | */ |
| 1044 | static void |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1045 | rpc_default_callback(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | { |
| 1047 | } |
| 1048 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1049 | static const struct rpc_call_ops rpc_default_ops = { |
| 1050 | .rpc_call_done = rpc_default_callback, |
| 1051 | }; |
| 1052 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1053 | /** |
| 1054 | * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it |
| 1055 | * @task_setup_data: pointer to task initialisation data |
| 1056 | */ |
| 1057 | struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data) |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1058 | { |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 1059 | struct rpc_task *task; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1060 | |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1061 | task = rpc_new_task(task_setup_data); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1062 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1063 | rpc_task_set_client(task, task_setup_data->rpc_client); |
| 1064 | rpc_task_set_rpc_message(task, task_setup_data->rpc_message); |
| 1065 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1066 | if (task->tk_action == NULL) |
| 1067 | rpc_call_start(task); |
| 1068 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1069 | atomic_inc(&task->tk_count); |
| 1070 | rpc_execute(task); |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 1071 | return task; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1072 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1073 | EXPORT_SYMBOL_GPL(rpc_run_task); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1074 | |
| 1075 | /** |
| 1076 | * rpc_call_sync - Perform a synchronous RPC call |
| 1077 | * @clnt: pointer to RPC client |
| 1078 | * @msg: RPC call parameters |
| 1079 | * @flags: RPC call flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | */ |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 1081 | int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
| 1083 | struct rpc_task *task; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1084 | struct rpc_task_setup task_setup_data = { |
| 1085 | .rpc_client = clnt, |
| 1086 | .rpc_message = msg, |
| 1087 | .callback_ops = &rpc_default_ops, |
| 1088 | .flags = flags, |
| 1089 | }; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1090 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Weston Andros Adamson | 50d2bdb | 2012-11-01 16:04:40 -0400 | [diff] [blame] | 1092 | WARN_ON_ONCE(flags & RPC_TASK_ASYNC); |
| 1093 | if (flags & RPC_TASK_ASYNC) { |
| 1094 | rpc_release_calldata(task_setup_data.callback_ops, |
| 1095 | task_setup_data.callback_data); |
| 1096 | return -EINVAL; |
| 1097 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1099 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1100 | if (IS_ERR(task)) |
| 1101 | return PTR_ERR(task); |
Trond Myklebust | e60859a | 2006-01-03 09:55:10 +0100 | [diff] [blame] | 1102 | status = task->tk_status; |
Trond Myklebust | bde8f00 | 2007-01-24 11:54:53 -0800 | [diff] [blame] | 1103 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | return status; |
| 1105 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1106 | EXPORT_SYMBOL_GPL(rpc_call_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1108 | /** |
| 1109 | * rpc_call_async - Perform an asynchronous RPC call |
| 1110 | * @clnt: pointer to RPC client |
| 1111 | * @msg: RPC call parameters |
| 1112 | * @flags: RPC call flags |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 1113 | * @tk_ops: RPC call ops |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1114 | * @data: user call data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | */ |
| 1116 | int |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 1117 | rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1118 | const struct rpc_call_ops *tk_ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | { |
| 1120 | struct rpc_task *task; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1121 | struct rpc_task_setup task_setup_data = { |
| 1122 | .rpc_client = clnt, |
| 1123 | .rpc_message = msg, |
| 1124 | .callback_ops = tk_ops, |
| 1125 | .callback_data = data, |
| 1126 | .flags = flags|RPC_TASK_ASYNC, |
| 1127 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1129 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 1130 | if (IS_ERR(task)) |
| 1131 | return PTR_ERR(task); |
| 1132 | rpc_put_task(task); |
| 1133 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1135 | EXPORT_SYMBOL_GPL(rpc_call_async); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 1137 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 1138 | static void call_bc_encode(struct rpc_task *task); |
| 1139 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1140 | /** |
| 1141 | * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run |
| 1142 | * rpc_execute against it |
Jaswinder Singh Rajput | 7a73fdd | 2009-09-24 14:58:42 -0400 | [diff] [blame] | 1143 | * @req: RPC request |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1144 | */ |
Trond Myklebust | 0f41979 | 2015-06-01 22:59:08 -0400 | [diff] [blame] | 1145 | struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1146 | { |
| 1147 | struct rpc_task *task; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1148 | struct rpc_task_setup task_setup_data = { |
Trond Myklebust | 0f41979 | 2015-06-01 22:59:08 -0400 | [diff] [blame] | 1149 | .callback_ops = &rpc_default_ops, |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1150 | .flags = RPC_TASK_SOFTCONN | |
| 1151 | RPC_TASK_NO_RETRANS_TIMEOUT, |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | dprintk("RPC: rpc_run_bc_task req= %p\n", req); |
| 1155 | /* |
| 1156 | * Create an rpc_task to send the data |
| 1157 | */ |
| 1158 | task = rpc_new_task(&task_setup_data); |
Trond Myklebust | 902c588 | 2018-09-01 17:21:01 -0400 | [diff] [blame] | 1159 | xprt_init_bc_request(req, task); |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1160 | |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 1161 | task->tk_action = call_bc_encode; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1162 | atomic_inc(&task->tk_count); |
Weston Andros Adamson | 9a6478f | 2012-10-23 10:43:27 -0400 | [diff] [blame] | 1163 | WARN_ON_ONCE(atomic_read(&task->tk_count) != 2); |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1164 | rpc_execute(task); |
| 1165 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1166 | dprintk("RPC: rpc_run_bc_task: task= %p\n", task); |
| 1167 | return task; |
| 1168 | } |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 1169 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1170 | |
Chuck Lever | cf500ba | 2019-02-11 11:25:20 -0500 | [diff] [blame] | 1171 | /** |
| 1172 | * rpc_prepare_reply_pages - Prepare to receive a reply data payload into pages |
| 1173 | * @req: RPC request to prepare |
| 1174 | * @pages: vector of struct page pointers |
| 1175 | * @base: offset in first page where receive should start, in bytes |
| 1176 | * @len: expected size of the upper layer data payload, in bytes |
| 1177 | * @hdrsize: expected size of upper layer reply header, in XDR words |
| 1178 | * |
| 1179 | */ |
| 1180 | void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages, |
| 1181 | unsigned int base, unsigned int len, |
| 1182 | unsigned int hdrsize) |
| 1183 | { |
Chuck Lever | 02ef04e | 2019-02-11 11:25:25 -0500 | [diff] [blame] | 1184 | /* Subtract one to force an extra word of buffer space for the |
| 1185 | * payload's XDR pad to fall into the rcv_buf's tail iovec. |
| 1186 | */ |
Chuck Lever | 35e77d2 | 2019-02-11 11:25:36 -0500 | [diff] [blame] | 1187 | hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_ralign - 1; |
Chuck Lever | 02ef04e | 2019-02-11 11:25:25 -0500 | [diff] [blame] | 1188 | |
Chuck Lever | cf500ba | 2019-02-11 11:25:20 -0500 | [diff] [blame] | 1189 | xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len); |
| 1190 | trace_rpc_reply_pages(req); |
| 1191 | } |
| 1192 | EXPORT_SYMBOL_GPL(rpc_prepare_reply_pages); |
| 1193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | void |
Trond Myklebust | 77de2c5 | 2007-10-25 18:40:21 -0400 | [diff] [blame] | 1195 | rpc_call_start(struct rpc_task *task) |
| 1196 | { |
| 1197 | task->tk_action = call_start; |
| 1198 | } |
| 1199 | EXPORT_SYMBOL_GPL(rpc_call_start); |
| 1200 | |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1201 | /** |
| 1202 | * rpc_peeraddr - extract remote peer address from clnt's xprt |
| 1203 | * @clnt: RPC client structure |
| 1204 | * @buf: target buffer |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 1205 | * @bufsize: length of target buffer |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1206 | * |
| 1207 | * Returns the number of bytes that are actually in the stored address. |
| 1208 | */ |
| 1209 | size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize) |
| 1210 | { |
| 1211 | size_t bytes; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1212 | struct rpc_xprt *xprt; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1213 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1214 | rcu_read_lock(); |
| 1215 | xprt = rcu_dereference(clnt->cl_xprt); |
| 1216 | |
| 1217 | bytes = xprt->addrlen; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1218 | if (bytes > bufsize) |
| 1219 | bytes = bufsize; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1220 | memcpy(buf, &xprt->addr, bytes); |
| 1221 | rcu_read_unlock(); |
| 1222 | |
| 1223 | return bytes; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1224 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 1225 | EXPORT_SYMBOL_GPL(rpc_peeraddr); |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 1226 | |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1227 | /** |
| 1228 | * rpc_peeraddr2str - return remote peer address in printable format |
| 1229 | * @clnt: RPC client structure |
| 1230 | * @format: address format |
| 1231 | * |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1232 | * NB: the lifetime of the memory referenced by the returned pointer is |
| 1233 | * the same as the rpc_xprt itself. As long as the caller uses this |
| 1234 | * pointer, it must hold the RCU read lock. |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1235 | */ |
Chuck Lever | b454ae9 | 2008-01-07 18:34:48 -0500 | [diff] [blame] | 1236 | const char *rpc_peeraddr2str(struct rpc_clnt *clnt, |
| 1237 | enum rpc_display_format_t format) |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1238 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1239 | struct rpc_xprt *xprt; |
| 1240 | |
| 1241 | xprt = rcu_dereference(clnt->cl_xprt); |
Chuck Lever | 7559c7a | 2006-12-05 16:35:37 -0500 | [diff] [blame] | 1242 | |
| 1243 | if (xprt->address_strings[format] != NULL) |
| 1244 | return xprt->address_strings[format]; |
| 1245 | else |
| 1246 | return "unprintable"; |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1247 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 1248 | EXPORT_SYMBOL_GPL(rpc_peeraddr2str); |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1249 | |
Chuck Lever | 2e738fd | 2012-03-01 17:01:14 -0500 | [diff] [blame] | 1250 | static const struct sockaddr_in rpc_inaddr_loopback = { |
| 1251 | .sin_family = AF_INET, |
| 1252 | .sin_addr.s_addr = htonl(INADDR_ANY), |
| 1253 | }; |
| 1254 | |
| 1255 | static const struct sockaddr_in6 rpc_in6addr_loopback = { |
| 1256 | .sin6_family = AF_INET6, |
| 1257 | .sin6_addr = IN6ADDR_ANY_INIT, |
| 1258 | }; |
| 1259 | |
| 1260 | /* |
| 1261 | * Try a getsockname() on a connected datagram socket. Using a |
| 1262 | * connected datagram socket prevents leaving a socket in TIME_WAIT. |
| 1263 | * This conserves the ephemeral port number space. |
| 1264 | * |
| 1265 | * Returns zero and fills in "buf" if successful; otherwise, a |
| 1266 | * negative errno is returned. |
| 1267 | */ |
| 1268 | static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 1269 | struct sockaddr *buf) |
Chuck Lever | 2e738fd | 2012-03-01 17:01:14 -0500 | [diff] [blame] | 1270 | { |
| 1271 | struct socket *sock; |
| 1272 | int err; |
| 1273 | |
| 1274 | err = __sock_create(net, sap->sa_family, |
| 1275 | SOCK_DGRAM, IPPROTO_UDP, &sock, 1); |
| 1276 | if (err < 0) { |
| 1277 | dprintk("RPC: can't create UDP socket (%d)\n", err); |
| 1278 | goto out; |
| 1279 | } |
| 1280 | |
| 1281 | switch (sap->sa_family) { |
| 1282 | case AF_INET: |
| 1283 | err = kernel_bind(sock, |
| 1284 | (struct sockaddr *)&rpc_inaddr_loopback, |
| 1285 | sizeof(rpc_inaddr_loopback)); |
| 1286 | break; |
| 1287 | case AF_INET6: |
| 1288 | err = kernel_bind(sock, |
| 1289 | (struct sockaddr *)&rpc_in6addr_loopback, |
| 1290 | sizeof(rpc_in6addr_loopback)); |
| 1291 | break; |
| 1292 | default: |
| 1293 | err = -EAFNOSUPPORT; |
| 1294 | goto out; |
| 1295 | } |
| 1296 | if (err < 0) { |
| 1297 | dprintk("RPC: can't bind UDP socket (%d)\n", err); |
| 1298 | goto out_release; |
| 1299 | } |
| 1300 | |
| 1301 | err = kernel_connect(sock, sap, salen, 0); |
| 1302 | if (err < 0) { |
| 1303 | dprintk("RPC: can't connect UDP socket (%d)\n", err); |
| 1304 | goto out_release; |
| 1305 | } |
| 1306 | |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 1307 | err = kernel_getsockname(sock, buf); |
Chuck Lever | 2e738fd | 2012-03-01 17:01:14 -0500 | [diff] [blame] | 1308 | if (err < 0) { |
| 1309 | dprintk("RPC: getsockname failed (%d)\n", err); |
| 1310 | goto out_release; |
| 1311 | } |
| 1312 | |
| 1313 | err = 0; |
| 1314 | if (buf->sa_family == AF_INET6) { |
| 1315 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf; |
| 1316 | sin6->sin6_scope_id = 0; |
| 1317 | } |
| 1318 | dprintk("RPC: %s succeeded\n", __func__); |
| 1319 | |
| 1320 | out_release: |
| 1321 | sock_release(sock); |
| 1322 | out: |
| 1323 | return err; |
| 1324 | } |
| 1325 | |
| 1326 | /* |
| 1327 | * Scraping a connected socket failed, so we don't have a useable |
| 1328 | * local address. Fallback: generate an address that will prevent |
| 1329 | * the server from calling us back. |
| 1330 | * |
| 1331 | * Returns zero and fills in "buf" if successful; otherwise, a |
| 1332 | * negative errno is returned. |
| 1333 | */ |
| 1334 | static int rpc_anyaddr(int family, struct sockaddr *buf, size_t buflen) |
| 1335 | { |
| 1336 | switch (family) { |
| 1337 | case AF_INET: |
| 1338 | if (buflen < sizeof(rpc_inaddr_loopback)) |
| 1339 | return -EINVAL; |
| 1340 | memcpy(buf, &rpc_inaddr_loopback, |
| 1341 | sizeof(rpc_inaddr_loopback)); |
| 1342 | break; |
| 1343 | case AF_INET6: |
| 1344 | if (buflen < sizeof(rpc_in6addr_loopback)) |
| 1345 | return -EINVAL; |
| 1346 | memcpy(buf, &rpc_in6addr_loopback, |
| 1347 | sizeof(rpc_in6addr_loopback)); |
Trond Myklebust | 0b161e6 | 2015-12-30 18:14:06 -0500 | [diff] [blame] | 1348 | break; |
Chuck Lever | 2e738fd | 2012-03-01 17:01:14 -0500 | [diff] [blame] | 1349 | default: |
| 1350 | dprintk("RPC: %s: address family not supported\n", |
| 1351 | __func__); |
| 1352 | return -EAFNOSUPPORT; |
| 1353 | } |
| 1354 | dprintk("RPC: %s: succeeded\n", __func__); |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * rpc_localaddr - discover local endpoint address for an RPC client |
| 1360 | * @clnt: RPC client structure |
| 1361 | * @buf: target buffer |
| 1362 | * @buflen: size of target buffer, in bytes |
| 1363 | * |
| 1364 | * Returns zero and fills in "buf" and "buflen" if successful; |
| 1365 | * otherwise, a negative errno is returned. |
| 1366 | * |
| 1367 | * This works even if the underlying transport is not currently connected, |
| 1368 | * or if the upper layer never previously provided a source address. |
| 1369 | * |
| 1370 | * The result of this function call is transient: multiple calls in |
| 1371 | * succession may give different results, depending on how local |
| 1372 | * networking configuration changes over time. |
| 1373 | */ |
| 1374 | int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t buflen) |
| 1375 | { |
| 1376 | struct sockaddr_storage address; |
| 1377 | struct sockaddr *sap = (struct sockaddr *)&address; |
| 1378 | struct rpc_xprt *xprt; |
| 1379 | struct net *net; |
| 1380 | size_t salen; |
| 1381 | int err; |
| 1382 | |
| 1383 | rcu_read_lock(); |
| 1384 | xprt = rcu_dereference(clnt->cl_xprt); |
| 1385 | salen = xprt->addrlen; |
| 1386 | memcpy(sap, &xprt->addr, salen); |
| 1387 | net = get_net(xprt->xprt_net); |
| 1388 | rcu_read_unlock(); |
| 1389 | |
| 1390 | rpc_set_port(sap, 0); |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 1391 | err = rpc_sockname(net, sap, salen, buf); |
Chuck Lever | 2e738fd | 2012-03-01 17:01:14 -0500 | [diff] [blame] | 1392 | put_net(net); |
| 1393 | if (err != 0) |
| 1394 | /* Couldn't discover local address, return ANYADDR */ |
| 1395 | return rpc_anyaddr(sap->sa_family, buf, buflen); |
| 1396 | return 0; |
| 1397 | } |
| 1398 | EXPORT_SYMBOL_GPL(rpc_localaddr); |
| 1399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | void |
| 1401 | rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize) |
| 1402 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1403 | struct rpc_xprt *xprt; |
| 1404 | |
| 1405 | rcu_read_lock(); |
| 1406 | xprt = rcu_dereference(clnt->cl_xprt); |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1407 | if (xprt->ops->set_buffer_size) |
| 1408 | xprt->ops->set_buffer_size(xprt, sndsize, rcvsize); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1409 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1411 | EXPORT_SYMBOL_GPL(rpc_setbufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1413 | /** |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1414 | * rpc_net_ns - Get the network namespace for this RPC client |
| 1415 | * @clnt: RPC client to query |
| 1416 | * |
| 1417 | */ |
| 1418 | struct net *rpc_net_ns(struct rpc_clnt *clnt) |
| 1419 | { |
| 1420 | struct net *ret; |
| 1421 | |
| 1422 | rcu_read_lock(); |
| 1423 | ret = rcu_dereference(clnt->cl_xprt)->xprt_net; |
| 1424 | rcu_read_unlock(); |
| 1425 | return ret; |
| 1426 | } |
| 1427 | EXPORT_SYMBOL_GPL(rpc_net_ns); |
| 1428 | |
| 1429 | /** |
| 1430 | * rpc_max_payload - Get maximum payload size for a transport, in bytes |
| 1431 | * @clnt: RPC client to query |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | * |
| 1433 | * For stream transports, this is one RPC record fragment (see RFC |
| 1434 | * 1831), as we don't support multi-record requests yet. For datagram |
| 1435 | * transports, this is the size of an IP packet minus the IP, UDP, and |
| 1436 | * RPC header sizes. |
| 1437 | */ |
| 1438 | size_t rpc_max_payload(struct rpc_clnt *clnt) |
| 1439 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1440 | size_t ret; |
| 1441 | |
| 1442 | rcu_read_lock(); |
| 1443 | ret = rcu_dereference(clnt->cl_xprt)->max_payload; |
| 1444 | rcu_read_unlock(); |
| 1445 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 1447 | EXPORT_SYMBOL_GPL(rpc_max_payload); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1449 | /** |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 1450 | * rpc_max_bc_payload - Get maximum backchannel payload size, in bytes |
| 1451 | * @clnt: RPC client to query |
| 1452 | */ |
| 1453 | size_t rpc_max_bc_payload(struct rpc_clnt *clnt) |
| 1454 | { |
| 1455 | struct rpc_xprt *xprt; |
| 1456 | size_t ret; |
| 1457 | |
| 1458 | rcu_read_lock(); |
| 1459 | xprt = rcu_dereference(clnt->cl_xprt); |
| 1460 | ret = xprt->ops->bc_maxpayload(xprt); |
| 1461 | rcu_read_unlock(); |
| 1462 | return ret; |
| 1463 | } |
| 1464 | EXPORT_SYMBOL_GPL(rpc_max_bc_payload); |
| 1465 | |
| 1466 | /** |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1467 | * rpc_force_rebind - force transport to check that remote port is unchanged |
| 1468 | * @clnt: client to rebind |
| 1469 | * |
| 1470 | */ |
| 1471 | void rpc_force_rebind(struct rpc_clnt *clnt) |
| 1472 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1473 | if (clnt->cl_autobind) { |
| 1474 | rcu_read_lock(); |
| 1475 | xprt_clear_bound(rcu_dereference(clnt->cl_xprt)); |
| 1476 | rcu_read_unlock(); |
| 1477 | } |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1478 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 1479 | EXPORT_SYMBOL_GPL(rpc_force_rebind); |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1480 | |
Trond Myklebust | 9e6fa0b | 2019-04-07 13:58:45 -0400 | [diff] [blame] | 1481 | static int |
| 1482 | __rpc_restart_call(struct rpc_task *task, void (*action)(struct rpc_task *)) |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 1483 | { |
Trond Myklebust | 494314c | 2014-03-20 12:59:09 -0400 | [diff] [blame] | 1484 | task->tk_status = 0; |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1485 | task->tk_rpc_status = 0; |
Trond Myklebust | 9e6fa0b | 2019-04-07 13:58:45 -0400 | [diff] [blame] | 1486 | task->tk_action = action; |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1487 | return 1; |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 1488 | } |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 1489 | |
| 1490 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | * Restart an (async) RPC call. Usually called from within the |
| 1492 | * exit handler. |
| 1493 | */ |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1494 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | rpc_restart_call(struct rpc_task *task) |
| 1496 | { |
Trond Myklebust | 9e6fa0b | 2019-04-07 13:58:45 -0400 | [diff] [blame] | 1497 | return __rpc_restart_call(task, call_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1499 | EXPORT_SYMBOL_GPL(rpc_restart_call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Trond Myklebust | 9e6fa0b | 2019-04-07 13:58:45 -0400 | [diff] [blame] | 1501 | /* |
| 1502 | * Restart an (async) RPC call from the call_prepare state. |
| 1503 | * Usually called from within the exit handler. |
| 1504 | */ |
| 1505 | int |
| 1506 | rpc_restart_call_prepare(struct rpc_task *task) |
| 1507 | { |
| 1508 | if (task->tk_ops->rpc_call_prepare != NULL) |
| 1509 | return __rpc_restart_call(task, rpc_prepare_task); |
| 1510 | return rpc_restart_call(task); |
| 1511 | } |
| 1512 | EXPORT_SYMBOL_GPL(rpc_restart_call_prepare); |
| 1513 | |
Jeff Layton | b4b9d2c | 2014-11-26 14:44:43 -0500 | [diff] [blame] | 1514 | const char |
| 1515 | *rpc_proc_name(const struct rpc_task *task) |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1516 | { |
| 1517 | const struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
| 1518 | |
| 1519 | if (proc) { |
| 1520 | if (proc->p_name) |
| 1521 | return proc->p_name; |
| 1522 | else |
| 1523 | return "NULL"; |
| 1524 | } else |
| 1525 | return "no proc"; |
| 1526 | } |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1527 | |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1528 | static void |
| 1529 | __rpc_call_rpcerror(struct rpc_task *task, int tk_status, int rpc_status) |
| 1530 | { |
| 1531 | task->tk_rpc_status = rpc_status; |
| 1532 | rpc_exit(task, tk_status); |
| 1533 | } |
| 1534 | |
| 1535 | static void |
| 1536 | rpc_call_rpcerror(struct rpc_task *task, int status) |
| 1537 | { |
| 1538 | __rpc_call_rpcerror(task, status, status); |
| 1539 | } |
| 1540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | /* |
| 1542 | * 0. Initial state |
| 1543 | * |
| 1544 | * Other FSM states can be visited zero or more times, but |
| 1545 | * this state is visited exactly once for each RPC. |
| 1546 | */ |
| 1547 | static void |
| 1548 | call_start(struct rpc_task *task) |
| 1549 | { |
| 1550 | struct rpc_clnt *clnt = task->tk_client; |
Christoph Hellwig | 1c5876d | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 1551 | int idx = task->tk_msg.rpc_proc->p_statidx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
Chuck Lever | c435da6 | 2017-11-03 13:46:14 -0400 | [diff] [blame] | 1553 | trace_rpc_request(task); |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1554 | dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid, |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 1555 | clnt->cl_program->name, clnt->cl_vers, |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1556 | rpc_proc_name(task), |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1557 | (RPC_IS_ASYNC(task) ? "async" : "sync")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Christoph Hellwig | 1c5876d | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 1559 | /* Increment call count (version might not be valid for ping) */ |
| 1560 | if (clnt->cl_program->version[clnt->cl_vers]) |
| 1561 | clnt->cl_program->version[clnt->cl_vers]->counts[idx]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | clnt->cl_stats->rpccnt++; |
| 1563 | task->tk_action = call_reserve; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 1564 | rpc_task_set_transport(task, clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | /* |
| 1568 | * 1. Reserve an RPC call slot |
| 1569 | */ |
| 1570 | static void |
| 1571 | call_reserve(struct rpc_task *task) |
| 1572 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1573 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | task->tk_status = 0; |
| 1576 | task->tk_action = call_reserveresult; |
| 1577 | xprt_reserve(task); |
| 1578 | } |
| 1579 | |
Trond Myklebust | ba60eb2 | 2013-04-14 10:49:37 -0400 | [diff] [blame] | 1580 | static void call_retry_reserve(struct rpc_task *task); |
| 1581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | /* |
| 1583 | * 1b. Grok the result of xprt_reserve() |
| 1584 | */ |
| 1585 | static void |
| 1586 | call_reserveresult(struct rpc_task *task) |
| 1587 | { |
| 1588 | int status = task->tk_status; |
| 1589 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1590 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
| 1592 | /* |
| 1593 | * After a call to xprt_reserve(), we must have either |
| 1594 | * a request slot or else an error status. |
| 1595 | */ |
| 1596 | task->tk_status = 0; |
| 1597 | if (status >= 0) { |
| 1598 | if (task->tk_rqstp) { |
J. Bruce Fields | f2d47d0 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1599 | task->tk_action = call_refresh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1604 | __func__, status); |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1605 | rpc_call_rpcerror(task, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | return; |
| 1607 | } |
| 1608 | |
| 1609 | /* |
| 1610 | * Even though there was an error, we may have acquired |
| 1611 | * a request slot somehow. Make sure not to leak it. |
| 1612 | */ |
| 1613 | if (task->tk_rqstp) { |
| 1614 | printk(KERN_ERR "%s: status=%d, request allocated anyway\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1615 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | xprt_release(task); |
| 1617 | } |
| 1618 | |
| 1619 | switch (status) { |
Trond Myklebust | 1afeaf5 | 2012-05-19 12:12:53 -0400 | [diff] [blame] | 1620 | case -ENOMEM: |
| 1621 | rpc_delay(task, HZ >> 2); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 1622 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | case -EAGAIN: /* woken up; retry */ |
Trond Myklebust | ba60eb2 | 2013-04-14 10:49:37 -0400 | [diff] [blame] | 1624 | task->tk_action = call_retry_reserve; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | return; |
| 1626 | case -EIO: /* probably a shutdown */ |
| 1627 | break; |
| 1628 | default: |
| 1629 | printk(KERN_ERR "%s: unrecognized error %d, exiting\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1630 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | break; |
| 1632 | } |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1633 | rpc_call_rpcerror(task, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /* |
Trond Myklebust | ba60eb2 | 2013-04-14 10:49:37 -0400 | [diff] [blame] | 1637 | * 1c. Retry reserving an RPC call slot |
| 1638 | */ |
| 1639 | static void |
| 1640 | call_retry_reserve(struct rpc_task *task) |
| 1641 | { |
| 1642 | dprint_status(task); |
| 1643 | |
| 1644 | task->tk_status = 0; |
| 1645 | task->tk_action = call_reserveresult; |
| 1646 | xprt_retry_reserve(task); |
| 1647 | } |
| 1648 | |
| 1649 | /* |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1650 | * 2. Bind and/or refresh the credentials |
| 1651 | */ |
| 1652 | static void |
| 1653 | call_refresh(struct rpc_task *task) |
| 1654 | { |
| 1655 | dprint_status(task); |
| 1656 | |
| 1657 | task->tk_action = call_refreshresult; |
| 1658 | task->tk_status = 0; |
| 1659 | task->tk_client->cl_stats->rpcauthrefresh++; |
| 1660 | rpcauth_refreshcred(task); |
| 1661 | } |
| 1662 | |
| 1663 | /* |
| 1664 | * 2a. Process the results of a credential refresh |
| 1665 | */ |
| 1666 | static void |
| 1667 | call_refreshresult(struct rpc_task *task) |
| 1668 | { |
| 1669 | int status = task->tk_status; |
| 1670 | |
| 1671 | dprint_status(task); |
| 1672 | |
| 1673 | task->tk_status = 0; |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1674 | task->tk_action = call_refresh; |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1675 | switch (status) { |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1676 | case 0: |
Weston Andros Adamson | 6ff33b7 | 2013-12-17 12:16:11 -0500 | [diff] [blame] | 1677 | if (rpcauth_uptodatecred(task)) { |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1678 | task->tk_action = call_allocate; |
Weston Andros Adamson | 6ff33b7 | 2013-12-17 12:16:11 -0500 | [diff] [blame] | 1679 | return; |
| 1680 | } |
| 1681 | /* Use rate-limiting and a max number of retries if refresh |
| 1682 | * had status 0 but failed to update the cred. |
| 1683 | */ |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 1684 | /* fall through */ |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1685 | case -ETIMEDOUT: |
| 1686 | rpc_delay(task, 3*HZ); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 1687 | /* fall through */ |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1688 | case -EAGAIN: |
| 1689 | status = -EACCES; |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 1690 | /* fall through */ |
Andy Adamson | f1ff0c2 | 2013-08-14 11:59:13 -0400 | [diff] [blame] | 1691 | case -EKEYEXPIRED: |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1692 | if (!task->tk_cred_retry) |
| 1693 | break; |
| 1694 | task->tk_cred_retry--; |
| 1695 | dprintk("RPC: %5u %s: retry refresh creds\n", |
| 1696 | task->tk_pid, __func__); |
| 1697 | return; |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1698 | } |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1699 | dprintk("RPC: %5u %s: refresh creds failed with error %d\n", |
| 1700 | task->tk_pid, __func__, status); |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1701 | rpc_call_rpcerror(task, status); |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | /* |
| 1705 | * 2b. Allocate the buffer. For details, see sched.c:rpc_malloc. |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1706 | * (Note: buffer memory is freed in xprt_release). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | */ |
| 1708 | static void |
| 1709 | call_allocate(struct rpc_task *task) |
| 1710 | { |
Chuck Lever | 2c94b8e | 2019-02-11 11:25:41 -0500 | [diff] [blame] | 1711 | const struct rpc_auth *auth = task->tk_rqstp->rq_cred->cr_auth; |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1712 | struct rpc_rqst *req = task->tk_rqstp; |
Trond Myklebust | a4f0835 | 2013-01-08 09:10:21 -0500 | [diff] [blame] | 1713 | struct rpc_xprt *xprt = req->rq_xprt; |
Christoph Hellwig | 499b498 | 2017-05-12 15:36:49 +0200 | [diff] [blame] | 1714 | const struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
Chuck Lever | 5fe6eaa | 2016-09-15 10:55:20 -0400 | [diff] [blame] | 1715 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1717 | dprint_status(task); |
| 1718 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1719 | task->tk_status = 0; |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1720 | task->tk_action = call_encode; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1721 | |
Trond Myklebust | af6b61d | 2019-04-11 15:16:52 -0400 | [diff] [blame] | 1722 | if (req->rq_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | return; |
| 1724 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1725 | if (proc->p_proc != 0) { |
| 1726 | BUG_ON(proc->p_arglen == 0); |
| 1727 | if (proc->p_decode != NULL) |
| 1728 | BUG_ON(proc->p_replen == 0); |
| 1729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1731 | /* |
| 1732 | * Calculate the size (in quads) of the RPC call |
| 1733 | * and reply headers, and convert both values |
| 1734 | * to byte sizes. |
| 1735 | */ |
Chuck Lever | 2c94b8e | 2019-02-11 11:25:41 -0500 | [diff] [blame] | 1736 | req->rq_callsize = RPC_CALLHDRSIZE + (auth->au_cslack << 1) + |
| 1737 | proc->p_arglen; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1738 | req->rq_callsize <<= 2; |
Trond Myklebust | 5131496 | 2019-03-15 12:55:59 -0400 | [diff] [blame] | 1739 | /* |
| 1740 | * Note: the reply buffer must at minimum allocate enough space |
| 1741 | * for the 'struct accepted_reply' from RFC5531. |
| 1742 | */ |
| 1743 | req->rq_rcvsize = RPC_REPHDRSIZE + auth->au_rslack + \ |
| 1744 | max_t(size_t, proc->p_replen, 2); |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1745 | req->rq_rcvsize <<= 2; |
| 1746 | |
Chuck Lever | 5fe6eaa | 2016-09-15 10:55:20 -0400 | [diff] [blame] | 1747 | status = xprt->ops->buf_alloc(task); |
Chuck Lever | 4a06825 | 2015-05-11 14:02:25 -0400 | [diff] [blame] | 1748 | xprt_inject_disconnect(xprt); |
Trond Myklebust | af6b61d | 2019-04-11 15:16:52 -0400 | [diff] [blame] | 1749 | if (status == 0) |
Chuck Lever | 5fe6eaa | 2016-09-15 10:55:20 -0400 | [diff] [blame] | 1750 | return; |
| 1751 | if (status != -ENOMEM) { |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1752 | rpc_call_rpcerror(task, status); |
Chuck Lever | 5fe6eaa | 2016-09-15 10:55:20 -0400 | [diff] [blame] | 1753 | return; |
| 1754 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1755 | |
| 1756 | dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | |
Trond Myklebust | 5afa9133 | 2011-06-17 10:14:59 -0400 | [diff] [blame] | 1758 | if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) { |
Trond Myklebust | b6e9c71 | 2007-10-01 12:06:44 -0400 | [diff] [blame] | 1759 | task->tk_action = call_allocate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | rpc_delay(task, HZ>>4); |
| 1761 | return; |
| 1762 | } |
| 1763 | |
| 1764 | rpc_exit(task, -ERESTARTSYS); |
| 1765 | } |
| 1766 | |
Trond Myklebust | 7ebbbc6 | 2018-08-28 09:00:27 -0400 | [diff] [blame] | 1767 | static int |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1768 | rpc_task_need_encode(struct rpc_task *task) |
| 1769 | { |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1770 | return test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate) == 0 && |
| 1771 | (!(task->tk_flags & RPC_TASK_SENT) || |
| 1772 | !(task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT) || |
| 1773 | xprt_request_need_retransmit(task)); |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1774 | } |
| 1775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | static void |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1777 | rpc_xdr_encode(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | struct rpc_rqst *req = task->tk_rqstp; |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 1780 | struct xdr_stream xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Chuck Lever | b9c5bc0 | 2016-09-15 10:55:12 -0400 | [diff] [blame] | 1782 | xdr_buf_init(&req->rq_snd_buf, |
| 1783 | req->rq_buffer, |
| 1784 | req->rq_callsize); |
| 1785 | xdr_buf_init(&req->rq_rcv_buf, |
Chuck Lever | 6877894 | 2016-09-15 10:55:37 -0400 | [diff] [blame] | 1786 | req->rq_rbuffer, |
Chuck Lever | b9c5bc0 | 2016-09-15 10:55:12 -0400 | [diff] [blame] | 1787 | req->rq_rcvsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 1789 | req->rq_snd_buf.head[0].iov_len = 0; |
| 1790 | xdr_init_encode(&xdr, &req->rq_snd_buf, |
| 1791 | req->rq_snd_buf.head[0].iov_base, req); |
| 1792 | if (rpc_encode_header(task, &xdr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | return; |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1794 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 1795 | task->tk_status = rpcauth_wrap_req(task, &xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | /* |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1799 | * 3. Encode arguments of an RPC call |
| 1800 | */ |
| 1801 | static void |
| 1802 | call_encode(struct rpc_task *task) |
| 1803 | { |
| 1804 | if (!rpc_task_need_encode(task)) |
| 1805 | goto out; |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 1806 | dprint_status(task); |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1807 | /* Encode here so that rpcsec_gss can use correct sequence number. */ |
| 1808 | rpc_xdr_encode(task); |
| 1809 | /* Did the encode result in an error condition? */ |
| 1810 | if (task->tk_status != 0) { |
| 1811 | /* Was the error nonfatal? */ |
Trond Myklebust | 97b78ae | 2019-01-02 17:53:13 -0500 | [diff] [blame] | 1812 | switch (task->tk_status) { |
| 1813 | case -EAGAIN: |
| 1814 | case -ENOMEM: |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1815 | rpc_delay(task, HZ >> 4); |
Trond Myklebust | 97b78ae | 2019-01-02 17:53:13 -0500 | [diff] [blame] | 1816 | break; |
| 1817 | case -EKEYEXPIRED: |
ZhangXiaoxu | 9c5948c | 2019-04-29 17:32:31 +0800 | [diff] [blame] | 1818 | if (!task->tk_cred_retry) { |
| 1819 | rpc_exit(task, task->tk_status); |
| 1820 | } else { |
| 1821 | task->tk_action = call_refresh; |
| 1822 | task->tk_cred_retry--; |
| 1823 | dprintk("RPC: %5u %s: retry refresh creds\n", |
| 1824 | task->tk_pid, __func__); |
| 1825 | } |
Trond Myklebust | 97b78ae | 2019-01-02 17:53:13 -0500 | [diff] [blame] | 1826 | break; |
| 1827 | default: |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1828 | rpc_call_rpcerror(task, task->tk_status); |
Trond Myklebust | 97b78ae | 2019-01-02 17:53:13 -0500 | [diff] [blame] | 1829 | } |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1830 | return; |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 1831 | } else { |
| 1832 | xprt_request_prepare(task->tk_rqstp); |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /* Add task to reply queue before transmission to avoid races */ |
| 1836 | if (rpc_reply_expected(task)) |
| 1837 | xprt_request_enqueue_receive(task); |
| 1838 | xprt_request_enqueue_transmit(task); |
| 1839 | out: |
Trond Myklebust | af6b61d | 2019-04-11 15:16:52 -0400 | [diff] [blame] | 1840 | task->tk_action = call_transmit; |
| 1841 | /* Check that the connection is OK */ |
| 1842 | if (!xprt_bound(task->tk_xprt)) |
| 1843 | task->tk_action = call_bind; |
| 1844 | else if (!xprt_connected(task->tk_xprt)) |
| 1845 | task->tk_action = call_connect; |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | /* |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 1849 | * Helpers to check if the task was already transmitted, and |
| 1850 | * to take action when that is the case. |
| 1851 | */ |
| 1852 | static bool |
| 1853 | rpc_task_transmitted(struct rpc_task *task) |
| 1854 | { |
| 1855 | return !test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate); |
| 1856 | } |
| 1857 | |
| 1858 | static void |
| 1859 | rpc_task_handle_transmitted(struct rpc_task *task) |
| 1860 | { |
| 1861 | xprt_end_transmit(task); |
| 1862 | task->tk_action = call_transmit_status; |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | * 4. Get the server port number if not yet set |
| 1867 | */ |
| 1868 | static void |
| 1869 | call_bind(struct rpc_task *task) |
| 1870 | { |
Trond Myklebust | ad2368d | 2013-01-08 10:08:33 -0500 | [diff] [blame] | 1871 | struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 1873 | if (rpc_task_transmitted(task)) { |
| 1874 | rpc_task_handle_transmitted(task); |
| 1875 | return; |
| 1876 | } |
| 1877 | |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1878 | if (xprt_bound(xprt)) { |
| 1879 | task->tk_action = call_connect; |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1880 | return; |
| 1881 | } |
| 1882 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1883 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1885 | task->tk_action = call_bind_status; |
Trond Myklebust | 4d6c671 | 2019-03-10 12:22:39 -0400 | [diff] [blame] | 1886 | if (!xprt_prepare_transmit(task)) |
| 1887 | return; |
| 1888 | |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1889 | xprt->ops->rpcbind(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1893 | * 4a. Sort out bind result |
| 1894 | */ |
| 1895 | static void |
| 1896 | call_bind_status(struct rpc_task *task) |
| 1897 | { |
Chuck Lever | 906462a | 2007-09-11 18:00:47 -0400 | [diff] [blame] | 1898 | int status = -EIO; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1899 | |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 1900 | if (rpc_task_transmitted(task)) { |
| 1901 | rpc_task_handle_transmitted(task); |
| 1902 | return; |
| 1903 | } |
| 1904 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1905 | if (task->tk_status >= 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1906 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1907 | task->tk_status = 0; |
| 1908 | task->tk_action = call_connect; |
| 1909 | return; |
| 1910 | } |
| 1911 | |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 1912 | trace_rpc_bind_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1913 | switch (task->tk_status) { |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 1914 | case -ENOMEM: |
| 1915 | dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid); |
| 1916 | rpc_delay(task, HZ >> 2); |
Chuck Lever | 2429cbf | 2007-09-11 18:00:41 -0400 | [diff] [blame] | 1917 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1918 | case -EACCES: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1919 | dprintk("RPC: %5u remote rpcbind: RPC program/version " |
| 1920 | "unavailable\n", task->tk_pid); |
Chuck Lever | b79dc8c | 2007-09-11 18:00:52 -0400 | [diff] [blame] | 1921 | /* fail immediately if this is an RPC ping */ |
| 1922 | if (task->tk_msg.rpc_proc->p_proc == 0) { |
| 1923 | status = -EOPNOTSUPP; |
| 1924 | break; |
| 1925 | } |
Trond Myklebust | 0b76011 | 2011-05-31 15:15:34 -0400 | [diff] [blame] | 1926 | if (task->tk_rebind_retry == 0) |
| 1927 | break; |
| 1928 | task->tk_rebind_retry--; |
Chuck Lever | ea635a5 | 2005-10-06 23:12:58 -0400 | [diff] [blame] | 1929 | rpc_delay(task, 3*HZ); |
Trond Myklebust | da45828e | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1930 | goto retry_timeout; |
Trond Myklebust | 4d6c671 | 2019-03-10 12:22:39 -0400 | [diff] [blame] | 1931 | case -EAGAIN: |
| 1932 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1933 | case -ETIMEDOUT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1934 | dprintk("RPC: %5u rpcbind request timed out\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1935 | task->tk_pid); |
Trond Myklebust | da45828e | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1936 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1937 | case -EPFNOSUPPORT: |
Chuck Lever | 906462a | 2007-09-11 18:00:47 -0400 | [diff] [blame] | 1938 | /* server doesn't support any rpcbind version we know of */ |
Chuck Lever | 012da158 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1939 | dprintk("RPC: %5u unrecognized remote rpcbind service\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1940 | task->tk_pid); |
| 1941 | break; |
| 1942 | case -EPROTONOSUPPORT: |
Chuck Lever | 00a6e7b | 2007-03-29 16:48:33 -0400 | [diff] [blame] | 1943 | dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1944 | task->tk_pid); |
Trond Myklebust | fdb63dc | 2014-03-17 12:57:31 -0400 | [diff] [blame] | 1945 | goto retry_timeout; |
Chuck Lever | 012da158 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1946 | case -ECONNREFUSED: /* connection problems */ |
| 1947 | case -ECONNRESET: |
Trond Myklebust | df27727 | 2013-12-31 13:11:43 -0500 | [diff] [blame] | 1948 | case -ECONNABORTED: |
Chuck Lever | 012da158 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1949 | case -ENOTCONN: |
| 1950 | case -EHOSTDOWN: |
Trond Myklebust | eb5b46f | 2017-11-30 07:21:33 -0500 | [diff] [blame] | 1951 | case -ENETDOWN: |
Chuck Lever | 012da158 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1952 | case -EHOSTUNREACH: |
| 1953 | case -ENETUNREACH: |
Trond Myklebust | 3601c4a | 2014-06-30 13:42:19 -0400 | [diff] [blame] | 1954 | case -ENOBUFS: |
Chuck Lever | 012da158 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1955 | case -EPIPE: |
| 1956 | dprintk("RPC: %5u remote rpcbind unreachable: %d\n", |
| 1957 | task->tk_pid, task->tk_status); |
| 1958 | if (!RPC_IS_SOFTCONN(task)) { |
| 1959 | rpc_delay(task, 5*HZ); |
| 1960 | goto retry_timeout; |
| 1961 | } |
| 1962 | status = task->tk_status; |
| 1963 | break; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1964 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1965 | dprintk("RPC: %5u unrecognized rpcbind error (%d)\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1966 | task->tk_pid, -task->tk_status); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 1969 | rpc_call_rpcerror(task, status); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1970 | return; |
| 1971 | |
Trond Myklebust | da45828e | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1972 | retry_timeout: |
Trond Myklebust | fdb63dc | 2014-03-17 12:57:31 -0400 | [diff] [blame] | 1973 | task->tk_status = 0; |
Trond Myklebust | 4d6c671 | 2019-03-10 12:22:39 -0400 | [diff] [blame] | 1974 | task->tk_action = call_bind; |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 1975 | rpc_check_timeout(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | /* |
| 1979 | * 4b. Connect to the RPC server |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | */ |
| 1981 | static void |
| 1982 | call_connect(struct rpc_task *task) |
| 1983 | { |
Trond Myklebust | ad2368d | 2013-01-08 10:08:33 -0500 | [diff] [blame] | 1984 | struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 1986 | if (rpc_task_transmitted(task)) { |
| 1987 | rpc_task_handle_transmitted(task); |
| 1988 | return; |
| 1989 | } |
| 1990 | |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1991 | if (xprt_connected(xprt)) { |
| 1992 | task->tk_action = call_transmit; |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 1993 | return; |
| 1994 | } |
| 1995 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1996 | dprintk("RPC: %5u call_connect xprt %p %s connected\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1997 | task->tk_pid, xprt, |
| 1998 | (xprt_connected(xprt) ? "is" : "is not")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2000 | task->tk_action = call_connect_status; |
| 2001 | if (task->tk_status < 0) |
| 2002 | return; |
| 2003 | if (task->tk_flags & RPC_TASK_NOCONNECT) { |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2004 | rpc_call_rpcerror(task, -ENOTCONN); |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2005 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | } |
Trond Myklebust | 4d6c671 | 2019-03-10 12:22:39 -0400 | [diff] [blame] | 2007 | if (!xprt_prepare_transmit(task)) |
| 2008 | return; |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2009 | xprt_connect(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 2013 | * 4c. Sort out connect result |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | */ |
| 2015 | static void |
| 2016 | call_connect_status(struct rpc_task *task) |
| 2017 | { |
| 2018 | struct rpc_clnt *clnt = task->tk_client; |
| 2019 | int status = task->tk_status; |
| 2020 | |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 2021 | if (rpc_task_transmitted(task)) { |
| 2022 | rpc_task_handle_transmitted(task); |
Trond Myklebust | 9bd1152 | 2018-11-30 12:48:47 -0500 | [diff] [blame] | 2023 | return; |
| 2024 | } |
| 2025 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2026 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 2027 | |
Chuck Lever | e671edb | 2018-03-16 10:33:44 -0400 | [diff] [blame] | 2028 | trace_rpc_connect_status(task); |
Trond Myklebust | 561ec16 | 2013-09-26 15:22:45 -0400 | [diff] [blame] | 2029 | task->tk_status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | switch (status) { |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2031 | case -ECONNREFUSED: |
NeilBrown | fd01b25 | 2017-08-18 17:12:51 +1000 | [diff] [blame] | 2032 | /* A positive refusal suggests a rebind is needed. */ |
| 2033 | if (RPC_IS_SOFTCONN(task)) |
| 2034 | break; |
| 2035 | if (clnt->cl_autobind) { |
| 2036 | rpc_force_rebind(clnt); |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2037 | goto out_retry; |
NeilBrown | fd01b25 | 2017-08-18 17:12:51 +1000 | [diff] [blame] | 2038 | } |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2039 | /* fall through */ |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2040 | case -ECONNRESET: |
Trond Myklebust | df27727 | 2013-12-31 13:11:43 -0500 | [diff] [blame] | 2041 | case -ECONNABORTED: |
Trond Myklebust | eb5b46f | 2017-11-30 07:21:33 -0500 | [diff] [blame] | 2042 | case -ENETDOWN: |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2043 | case -ENETUNREACH: |
Trond Myklebust | df27727 | 2013-12-31 13:11:43 -0500 | [diff] [blame] | 2044 | case -EHOSTUNREACH: |
Trond Myklebust | 3913c78 | 2015-02-08 21:44:04 -0500 | [diff] [blame] | 2045 | case -EADDRINUSE: |
Trond Myklebust | 3601c4a | 2014-06-30 13:42:19 -0400 | [diff] [blame] | 2046 | case -ENOBUFS: |
Trond Myklebust | 2fc193c | 2014-07-03 00:02:57 -0400 | [diff] [blame] | 2047 | case -EPIPE: |
NeilBrown | 2c2ee6d | 2016-11-23 14:44:58 +1100 | [diff] [blame] | 2048 | xprt_conditional_disconnect(task->tk_rqstp->rq_xprt, |
| 2049 | task->tk_rqstp->rq_connect_cookie); |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2050 | if (RPC_IS_SOFTCONN(task)) |
| 2051 | break; |
Steve Dickson | 1fa3e2e | 2014-03-20 11:23:03 -0400 | [diff] [blame] | 2052 | /* retry with existing socket, after a delay */ |
| 2053 | rpc_delay(task, 3*HZ); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2054 | /* fall through */ |
Trond Myklebust | 0445f92 | 2018-12-17 13:34:59 -0500 | [diff] [blame] | 2055 | case -ENOTCONN: |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2056 | case -EAGAIN: |
Trond Myklebust | 485f225 | 2014-03-17 12:51:44 -0400 | [diff] [blame] | 2057 | case -ETIMEDOUT: |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2058 | goto out_retry; |
Trond Myklebust | 561ec16 | 2013-09-26 15:22:45 -0400 | [diff] [blame] | 2059 | case 0: |
Trond Myklebust | 3ed5e2a | 2013-03-04 17:29:33 -0500 | [diff] [blame] | 2060 | clnt->cl_stats->netreconn++; |
| 2061 | task->tk_action = call_transmit; |
| 2062 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2064 | rpc_call_rpcerror(task, status); |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2065 | return; |
| 2066 | out_retry: |
| 2067 | /* Check for timeouts before looping back to call_bind */ |
| 2068 | task->tk_action = call_bind; |
| 2069 | rpc_check_timeout(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | /* |
| 2073 | * 5. Transmit the RPC request, and wait for reply |
| 2074 | */ |
| 2075 | static void |
| 2076 | call_transmit(struct rpc_task *task) |
| 2077 | { |
Trond Myklebust | 03e51d3 | 2019-03-10 11:17:13 -0400 | [diff] [blame] | 2078 | if (rpc_task_transmitted(task)) { |
| 2079 | rpc_task_handle_transmitted(task); |
| 2080 | return; |
| 2081 | } |
| 2082 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2083 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | |
Trond Myklebust | ed7dc97 | 2019-03-04 14:19:31 -0500 | [diff] [blame] | 2085 | task->tk_action = call_transmit_status; |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2086 | if (!xprt_prepare_transmit(task)) |
| 2087 | return; |
| 2088 | task->tk_status = 0; |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2089 | if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate)) { |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2090 | if (!xprt_connected(task->tk_xprt)) { |
| 2091 | task->tk_status = -ENOTCONN; |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2092 | return; |
Trond Myklebust | ed7dc97 | 2019-03-04 14:19:31 -0500 | [diff] [blame] | 2093 | } |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2094 | xprt_transmit(task); |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2095 | } |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2096 | xprt_end_transmit(task); |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /* |
| 2100 | * 5a. Handle cleanup after a transmission |
| 2101 | */ |
| 2102 | static void |
| 2103 | call_transmit_status(struct rpc_task *task) |
| 2104 | { |
| 2105 | task->tk_action = call_status; |
Chuck Lever | 206a134 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2106 | |
| 2107 | /* |
| 2108 | * Common case: success. Force the compiler to put this |
| 2109 | * test first. |
| 2110 | */ |
Trond Myklebust | 009a82f | 2019-03-09 12:07:17 -0500 | [diff] [blame] | 2111 | if (rpc_task_transmitted(task)) { |
Trond Myklebust | a7b1a48 | 2019-04-15 11:54:13 -0400 | [diff] [blame] | 2112 | task->tk_status = 0; |
| 2113 | xprt_request_wait_receive(task); |
Chuck Lever | 206a134 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2114 | return; |
| 2115 | } |
| 2116 | |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2117 | switch (task->tk_status) { |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2118 | default: |
Chuck Lever | 206a134 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2119 | dprint_status(task); |
Trond Myklebust | 75891f5 | 2018-09-03 17:37:36 -0400 | [diff] [blame] | 2120 | break; |
Trond Myklebust | 78b576c | 2018-08-28 09:20:10 -0400 | [diff] [blame] | 2121 | case -EBADMSG: |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 2122 | task->tk_status = 0; |
| 2123 | task->tk_action = call_encode; |
Trond Myklebust | 78b576c | 2018-08-28 09:20:10 -0400 | [diff] [blame] | 2124 | break; |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2125 | /* |
| 2126 | * Special cases: if we've been waiting on the |
| 2127 | * socket's write_space() callback, or if the |
| 2128 | * socket just returned a connection error, |
| 2129 | * then hold onto the transport lock. |
| 2130 | */ |
Trond Myklebust | 78b576c | 2018-08-28 09:20:10 -0400 | [diff] [blame] | 2131 | case -ENOBUFS: |
| 2132 | rpc_delay(task, HZ>>2); |
| 2133 | /* fall through */ |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2134 | case -EBADSLT: |
Trond Myklebust | 78b576c | 2018-08-28 09:20:10 -0400 | [diff] [blame] | 2135 | case -EAGAIN: |
| 2136 | task->tk_action = call_transmit; |
| 2137 | task->tk_status = 0; |
| 2138 | break; |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2139 | case -ECONNREFUSED: |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2140 | case -EHOSTDOWN: |
Trond Myklebust | eb5b46f | 2017-11-30 07:21:33 -0500 | [diff] [blame] | 2141 | case -ENETDOWN: |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2142 | case -EHOSTUNREACH: |
| 2143 | case -ENETUNREACH: |
Jason Baron | 3dedbb5 | 2014-09-24 18:08:04 +0000 | [diff] [blame] | 2144 | case -EPERM: |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2145 | if (RPC_IS_SOFTCONN(task)) { |
Chuck Lever | a25a4cb | 2018-03-16 10:33:55 -0400 | [diff] [blame] | 2146 | if (!task->tk_msg.rpc_proc->p_proc) |
| 2147 | trace_xprt_ping(task->tk_xprt, |
| 2148 | task->tk_status); |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2149 | rpc_call_rpcerror(task, task->tk_status); |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2150 | return; |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2151 | } |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2152 | /* fall through */ |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2153 | case -ECONNRESET: |
Trond Myklebust | df27727 | 2013-12-31 13:11:43 -0500 | [diff] [blame] | 2154 | case -ECONNABORTED: |
Trond Myklebust | 3913c78 | 2015-02-08 21:44:04 -0500 | [diff] [blame] | 2155 | case -EADDRINUSE: |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2156 | case -ENOTCONN: |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 2157 | case -EPIPE: |
Trond Myklebust | ed7dc97 | 2019-03-04 14:19:31 -0500 | [diff] [blame] | 2158 | task->tk_action = call_bind; |
| 2159 | task->tk_status = 0; |
Trond Myklebust | 7ebbbc6 | 2018-08-28 09:00:27 -0400 | [diff] [blame] | 2160 | break; |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 2161 | } |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2162 | rpc_check_timeout(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 2165 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 2166 | static void call_bc_transmit(struct rpc_task *task); |
| 2167 | static void call_bc_transmit_status(struct rpc_task *task); |
| 2168 | |
| 2169 | static void |
| 2170 | call_bc_encode(struct rpc_task *task) |
| 2171 | { |
| 2172 | xprt_request_enqueue_transmit(task); |
| 2173 | task->tk_action = call_bc_transmit; |
| 2174 | } |
| 2175 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2176 | /* |
| 2177 | * 5b. Send the backchannel RPC reply. On error, drop the reply. In |
| 2178 | * addition, disconnect on connectivity errors. |
| 2179 | */ |
| 2180 | static void |
| 2181 | call_bc_transmit(struct rpc_task *task) |
| 2182 | { |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 2183 | task->tk_action = call_bc_transmit_status; |
| 2184 | if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate)) { |
| 2185 | if (!xprt_prepare_transmit(task)) |
| 2186 | return; |
| 2187 | task->tk_status = 0; |
| 2188 | xprt_transmit(task); |
| 2189 | } |
| 2190 | xprt_end_transmit(task); |
| 2191 | } |
| 2192 | |
| 2193 | static void |
| 2194 | call_bc_transmit_status(struct rpc_task *task) |
| 2195 | { |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2196 | struct rpc_rqst *req = task->tk_rqstp; |
| 2197 | |
Trond Myklebust | a7b1a48 | 2019-04-15 11:54:13 -0400 | [diff] [blame] | 2198 | if (rpc_task_transmitted(task)) |
| 2199 | task->tk_status = 0; |
| 2200 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2201 | dprint_status(task); |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 2202 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2203 | switch (task->tk_status) { |
| 2204 | case 0: |
| 2205 | /* Success */ |
Trond Myklebust | eb5b46f | 2017-11-30 07:21:33 -0500 | [diff] [blame] | 2206 | case -ENETDOWN: |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2207 | case -EHOSTDOWN: |
| 2208 | case -EHOSTUNREACH: |
| 2209 | case -ENETUNREACH: |
Trond Myklebust | 3832591 | 2015-06-19 13:04:13 -0400 | [diff] [blame] | 2210 | case -ECONNRESET: |
| 2211 | case -ECONNREFUSED: |
| 2212 | case -EADDRINUSE: |
| 2213 | case -ENOTCONN: |
| 2214 | case -EPIPE: |
| 2215 | break; |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 2216 | case -ENOBUFS: |
| 2217 | rpc_delay(task, HZ>>2); |
| 2218 | /* fall through */ |
| 2219 | case -EBADSLT: |
Trond Myklebust | c544577 | 2018-09-03 23:39:27 -0400 | [diff] [blame] | 2220 | case -EAGAIN: |
Trond Myklebust | 477687e | 2019-03-05 07:30:48 -0500 | [diff] [blame] | 2221 | task->tk_status = 0; |
| 2222 | task->tk_action = call_bc_transmit; |
| 2223 | return; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2224 | case -ETIMEDOUT: |
| 2225 | /* |
| 2226 | * Problem reaching the server. Disconnect and let the |
| 2227 | * forechannel reestablish the connection. The server will |
| 2228 | * have to retransmit the backchannel request and we'll |
| 2229 | * reprocess it. Since these ops are idempotent, there's no |
| 2230 | * need to cache our reply at this time. |
| 2231 | */ |
| 2232 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
| 2233 | "error: %d\n", task->tk_status); |
Trond Myklebust | a4f0835 | 2013-01-08 09:10:21 -0500 | [diff] [blame] | 2234 | xprt_conditional_disconnect(req->rq_xprt, |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2235 | req->rq_connect_cookie); |
| 2236 | break; |
| 2237 | default: |
| 2238 | /* |
| 2239 | * We were unable to reply and will have to drop the |
| 2240 | * request. The server should reconnect and retransmit. |
| 2241 | */ |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2242 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
| 2243 | "error: %d\n", task->tk_status); |
| 2244 | break; |
| 2245 | } |
Trond Myklebust | 1193d58 | 2015-06-02 11:53:21 -0400 | [diff] [blame] | 2246 | task->tk_action = rpc_exit_task; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2247 | } |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 2248 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 2249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | /* |
| 2251 | * 6. Sort out the RPC call status |
| 2252 | */ |
| 2253 | static void |
| 2254 | call_status(struct rpc_task *task) |
| 2255 | { |
| 2256 | struct rpc_clnt *clnt = task->tk_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | int status; |
| 2258 | |
Chuck Lever | a25a4cb | 2018-03-16 10:33:55 -0400 | [diff] [blame] | 2259 | if (!task->tk_msg.rpc_proc->p_proc) |
| 2260 | trace_xprt_ping(task->tk_xprt, task->tk_status); |
| 2261 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2262 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | |
| 2264 | status = task->tk_status; |
| 2265 | if (status >= 0) { |
| 2266 | task->tk_action = call_decode; |
| 2267 | return; |
| 2268 | } |
| 2269 | |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 2270 | trace_rpc_call_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | task->tk_status = 0; |
| 2272 | switch(status) { |
Trond Myklebust | 7630399 | 2006-08-30 14:32:49 -0400 | [diff] [blame] | 2273 | case -EHOSTDOWN: |
Trond Myklebust | eb5b46f | 2017-11-30 07:21:33 -0500 | [diff] [blame] | 2274 | case -ENETDOWN: |
Trond Myklebust | 7630399 | 2006-08-30 14:32:49 -0400 | [diff] [blame] | 2275 | case -EHOSTUNREACH: |
| 2276 | case -ENETUNREACH: |
Jason Baron | 3dedbb5 | 2014-09-24 18:08:04 +0000 | [diff] [blame] | 2277 | case -EPERM: |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 2278 | if (RPC_IS_SOFTCONN(task)) |
| 2279 | goto out_exit; |
Trond Myklebust | 7630399 | 2006-08-30 14:32:49 -0400 | [diff] [blame] | 2280 | /* |
| 2281 | * Delay any retries for 3 seconds, then handle as if it |
| 2282 | * were a timeout. |
| 2283 | */ |
| 2284 | rpc_delay(task, 3*HZ); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2285 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | case -ETIMEDOUT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | break; |
| 2288 | case -ECONNREFUSED: |
Trond Myklebust | df27727 | 2013-12-31 13:11:43 -0500 | [diff] [blame] | 2289 | case -ECONNRESET: |
| 2290 | case -ECONNABORTED: |
Olga Kornievskaia | ec6017d | 2019-05-29 10:46:00 -0400 | [diff] [blame] | 2291 | case -ENOTCONN: |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 2292 | rpc_force_rebind(clnt); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2293 | /* fall through */ |
Trond Myklebust | 3913c78 | 2015-02-08 21:44:04 -0500 | [diff] [blame] | 2294 | case -EADDRINUSE: |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 2295 | rpc_delay(task, 3*HZ); |
Gustavo A. R. Silva | e9d4763 | 2017-10-20 11:48:30 -0500 | [diff] [blame] | 2296 | /* fall through */ |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 2297 | case -EPIPE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | case -EAGAIN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | break; |
| 2300 | case -EIO: |
| 2301 | /* shutdown or soft timeout */ |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 2302 | goto out_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | default: |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 2304 | if (clnt->cl_chatty) |
| 2305 | printk("%s: RPC call returned error %d\n", |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 2306 | clnt->cl_program->name, -status); |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 2307 | goto out_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 2309 | task->tk_action = call_encode; |
| 2310 | rpc_check_timeout(task); |
| 2311 | return; |
| 2312 | out_exit: |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2313 | rpc_call_rpcerror(task, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Trond Myklebust | d84dd3f | 2019-03-19 11:24:54 -0400 | [diff] [blame] | 2316 | static bool |
| 2317 | rpc_check_connected(const struct rpc_rqst *req) |
| 2318 | { |
| 2319 | /* No allocated request or transport? return true */ |
| 2320 | if (!req || !req->rq_xprt) |
| 2321 | return true; |
| 2322 | return xprt_connected(req->rq_xprt); |
| 2323 | } |
| 2324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | static void |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2326 | rpc_check_timeout(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | { |
| 2328 | struct rpc_clnt *clnt = task->tk_client; |
| 2329 | |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2330 | if (xprt_adjust_timeout(task->tk_rqstp) == 0) |
| 2331 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2333 | dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid); |
Chuck Lever | ef759a2 | 2006-03-20 13:44:17 -0500 | [diff] [blame] | 2334 | task->tk_timeouts++; |
| 2335 | |
Trond Myklebust | d84dd3f | 2019-03-19 11:24:54 -0400 | [diff] [blame] | 2336 | if (RPC_IS_SOFTCONN(task) && !rpc_check_connected(task->tk_rqstp)) { |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2337 | rpc_call_rpcerror(task, -ETIMEDOUT); |
Chuck Lever | 3a28bec | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2338 | return; |
| 2339 | } |
Trond Myklebust | d84dd3f | 2019-03-19 11:24:54 -0400 | [diff] [blame] | 2340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | if (RPC_IS_SOFT(task)) { |
Trond Myklebust | e4ec48d | 2019-04-07 13:58:55 -0400 | [diff] [blame] | 2342 | /* |
| 2343 | * Once a "no retrans timeout" soft tasks (a.k.a NFSv4) has |
| 2344 | * been sent, it should time out only if the transport |
| 2345 | * connection gets terminally broken. |
| 2346 | */ |
| 2347 | if ((task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT) && |
| 2348 | rpc_check_connected(task->tk_rqstp)) |
| 2349 | return; |
| 2350 | |
Joe Perches | cac5d07 | 2012-07-18 11:17:11 -0700 | [diff] [blame] | 2351 | if (clnt->cl_chatty) { |
Trond Myklebust | 0729d99 | 2019-04-07 13:58:57 -0400 | [diff] [blame] | 2352 | pr_notice_ratelimited( |
| 2353 | "%s: server %s not responding, timed out\n", |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 2354 | clnt->cl_program->name, |
Trond Myklebust | fb43d17 | 2016-01-30 16:39:26 -0500 | [diff] [blame] | 2355 | task->tk_xprt->servername); |
Joe Perches | cac5d07 | 2012-07-18 11:17:11 -0700 | [diff] [blame] | 2356 | } |
Trond Myklebust | 7494d00 | 2011-04-24 14:28:45 -0400 | [diff] [blame] | 2357 | if (task->tk_flags & RPC_TASK_TIMEOUT) |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2358 | rpc_call_rpcerror(task, -ETIMEDOUT); |
Trond Myklebust | 7494d00 | 2011-04-24 14:28:45 -0400 | [diff] [blame] | 2359 | else |
Trond Myklebust | 5ad64b3 | 2019-04-07 13:58:54 -0400 | [diff] [blame] | 2360 | __rpc_call_rpcerror(task, -EIO, -ETIMEDOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | return; |
| 2362 | } |
| 2363 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 2364 | if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | task->tk_flags |= RPC_CALL_MAJORSEEN; |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2366 | if (clnt->cl_chatty) { |
Trond Myklebust | 0729d99 | 2019-04-07 13:58:57 -0400 | [diff] [blame] | 2367 | pr_notice_ratelimited( |
| 2368 | "%s: server %s not responding, still trying\n", |
| 2369 | clnt->cl_program->name, |
| 2370 | task->tk_xprt->servername); |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | } |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 2373 | rpc_force_rebind(clnt); |
Trond Myklebust | b48633b | 2008-04-22 16:47:55 -0400 | [diff] [blame] | 2374 | /* |
| 2375 | * Did our request time out due to an RPCSEC_GSS out-of-sequence |
| 2376 | * event? RFC2203 requires the server to drop all such requests. |
| 2377 | */ |
| 2378 | rpcauth_invalcred(task); |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | |
Trond Myklebust | 7b3fef8 | 2019-03-07 14:10:32 -0500 | [diff] [blame] | 2381 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | * 7. Decode the RPC reply |
| 2383 | */ |
| 2384 | static void |
| 2385 | call_decode(struct rpc_task *task) |
| 2386 | { |
| 2387 | struct rpc_clnt *clnt = task->tk_client; |
| 2388 | struct rpc_rqst *req = task->tk_rqstp; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2389 | struct xdr_stream xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
Vasily Averin | 726fd6a | 2011-06-01 16:23:59 +0400 | [diff] [blame] | 2391 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2393 | if (!task->tk_msg.rpc_proc->p_decode) { |
Trond Myklebust | 9ee94d3 | 2018-08-28 16:27:31 -0400 | [diff] [blame] | 2394 | task->tk_action = rpc_exit_task; |
| 2395 | return; |
| 2396 | } |
| 2397 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 2398 | if (task->tk_flags & RPC_CALL_MAJORSEEN) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2399 | if (clnt->cl_chatty) { |
Trond Myklebust | 0729d99 | 2019-04-07 13:58:57 -0400 | [diff] [blame] | 2400 | pr_notice_ratelimited("%s: server %s OK\n", |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 2401 | clnt->cl_program->name, |
Trond Myklebust | fb43d17 | 2016-01-30 16:39:26 -0500 | [diff] [blame] | 2402 | task->tk_xprt->servername); |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | task->tk_flags &= ~RPC_CALL_MAJORSEEN; |
| 2405 | } |
| 2406 | |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 2407 | /* |
| 2408 | * Ensure that we see all writes made by xprt_complete_rqst() |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 2409 | * before it changed req->rq_reply_bytes_recvd. |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 2410 | */ |
| 2411 | smp_rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | req->rq_rcv_buf.len = req->rq_private_buf.len; |
| 2413 | |
| 2414 | /* Check that the softirq receive buffer is valid */ |
| 2415 | WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, |
| 2416 | sizeof(req->rq_rcv_buf)) != 0); |
| 2417 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2418 | xdr_init_decode(&xdr, &req->rq_rcv_buf, |
| 2419 | req->rq_rcv_buf.head[0].iov_base, req); |
| 2420 | switch (rpc_decode_header(task, &xdr)) { |
| 2421 | case 0: |
| 2422 | task->tk_action = rpc_exit_task; |
| 2423 | task->tk_status = rpcauth_unwrap_resp(task, &xdr); |
| 2424 | dprintk("RPC: %5u %s result %d\n", |
| 2425 | task->tk_pid, __func__, task->tk_status); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 2426 | return; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2427 | case -EAGAIN: |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2428 | task->tk_status = 0; |
Trond Myklebust | 7987b69 | 2019-05-29 12:49:52 -0400 | [diff] [blame] | 2429 | xdr_free_bvec(&req->rq_rcv_buf); |
| 2430 | req->rq_reply_bytes_recvd = 0; |
| 2431 | req->rq_rcv_buf.len = 0; |
| 2432 | if (task->tk_client->cl_discrtry) |
| 2433 | xprt_conditional_disconnect(req->rq_xprt, |
| 2434 | req->rq_connect_cookie); |
Trond Myklebust | cea5778 | 2019-03-09 16:06:47 -0500 | [diff] [blame] | 2435 | task->tk_action = call_encode; |
| 2436 | rpc_check_timeout(task); |
Trond Myklebust | 7987b69 | 2019-05-29 12:49:52 -0400 | [diff] [blame] | 2437 | break; |
| 2438 | case -EKEYREJECTED: |
| 2439 | task->tk_action = call_reserve; |
| 2440 | rpc_check_timeout(task); |
| 2441 | rpcauth_invalcred(task); |
| 2442 | /* Ensure we obtain a new XID if we retry! */ |
| 2443 | xprt_release(task); |
Trond Myklebust | 24b74bf | 2008-04-19 13:15:47 -0400 | [diff] [blame] | 2444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 2447 | static int |
| 2448 | rpc_encode_header(struct rpc_task *task, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | { |
| 2450 | struct rpc_clnt *clnt = task->tk_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | struct rpc_rqst *req = task->tk_rqstp; |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 2452 | __be32 *p; |
| 2453 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 2455 | error = -EMSGSIZE; |
| 2456 | p = xdr_reserve_space(xdr, RPC_CALLHDRSIZE << 2); |
| 2457 | if (!p) |
| 2458 | goto out_fail; |
| 2459 | *p++ = req->rq_xid; |
| 2460 | *p++ = rpc_call; |
| 2461 | *p++ = cpu_to_be32(RPC_VERSION); |
| 2462 | *p++ = cpu_to_be32(clnt->cl_prog); |
| 2463 | *p++ = cpu_to_be32(clnt->cl_vers); |
| 2464 | *p = cpu_to_be32(task->tk_msg.rpc_proc->p_proc); |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 2465 | |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 2466 | error = rpcauth_marshcred(task, xdr); |
| 2467 | if (error < 0) |
| 2468 | goto out_fail; |
| 2469 | return 0; |
| 2470 | out_fail: |
| 2471 | trace_rpc_bad_callhdr(task); |
| 2472 | rpc_exit(task, error); |
| 2473 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2476 | static noinline int |
| 2477 | rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2479 | struct rpc_clnt *clnt = task->tk_client; |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2480 | int error; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2481 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2483 | /* RFC-1014 says that the representation of XDR data must be a |
| 2484 | * multiple of four bytes |
| 2485 | * - if it isn't pointer subtraction in the NFS client may give |
| 2486 | * undefined results |
| 2487 | */ |
| 2488 | if (task->tk_rqstp->rq_rcv_buf.len & 3) |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2489 | goto out_unparsable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2491 | p = xdr_inline_decode(xdr, 3 * sizeof(*p)); |
| 2492 | if (!p) |
| 2493 | goto out_unparsable; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2494 | p++; /* skip XID */ |
| 2495 | if (*p++ != rpc_reply) |
| 2496 | goto out_unparsable; |
| 2497 | if (*p++ != rpc_msg_accepted) |
| 2498 | goto out_msg_denied; |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 2499 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2500 | error = rpcauth_checkverf(task, xdr); |
| 2501 | if (error) |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2502 | goto out_verifier; |
| 2503 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2504 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 2505 | if (!p) |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2506 | goto out_unparsable; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2507 | switch (*p) { |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2508 | case rpc_success: |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2509 | return 0; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2510 | case rpc_prog_unavail: |
| 2511 | trace_rpc__prog_unavail(task); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2512 | error = -EPFNOSUPPORT; |
| 2513 | goto out_err; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2514 | case rpc_prog_mismatch: |
| 2515 | trace_rpc__prog_mismatch(task); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2516 | error = -EPROTONOSUPPORT; |
| 2517 | goto out_err; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2518 | case rpc_proc_unavail: |
| 2519 | trace_rpc__proc_unavail(task); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2520 | error = -EOPNOTSUPP; |
| 2521 | goto out_err; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2522 | case rpc_garbage_args: |
Trond Myklebust | 928d42f | 2019-03-15 10:12:30 -0400 | [diff] [blame] | 2523 | case rpc_system_err: |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2524 | trace_rpc__garbage_args(task); |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2525 | error = -EIO; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2526 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | default: |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2528 | goto out_unparsable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | } |
| 2530 | |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 2531 | out_garbage: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 2532 | clnt->cl_stats->rpcgarbage++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | if (task->tk_garb_retry) { |
| 2534 | task->tk_garb_retry--; |
Trond Myklebust | 762e4e6 | 2018-08-24 16:28:28 -0400 | [diff] [blame] | 2535 | task->tk_action = call_encode; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2536 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | out_err: |
| 2539 | rpc_exit(task, error); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2540 | return error; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2541 | |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2542 | out_unparsable: |
| 2543 | trace_rpc__unparsable(task); |
| 2544 | error = -EIO; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 2545 | goto out_garbage; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2546 | |
| 2547 | out_verifier: |
| 2548 | trace_rpc_bad_verifier(task); |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2549 | goto out_garbage; |
| 2550 | |
| 2551 | out_msg_denied: |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2552 | error = -EACCES; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2553 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 2554 | if (!p) |
| 2555 | goto out_unparsable; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2556 | switch (*p++) { |
| 2557 | case rpc_auth_error: |
| 2558 | break; |
| 2559 | case rpc_mismatch: |
| 2560 | trace_rpc__mismatch(task); |
| 2561 | error = -EPROTONOSUPPORT; |
| 2562 | goto out_err; |
| 2563 | default: |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2564 | goto out_unparsable; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2565 | } |
| 2566 | |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2567 | p = xdr_inline_decode(xdr, sizeof(*p)); |
| 2568 | if (!p) |
| 2569 | goto out_unparsable; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2570 | switch (*p++) { |
| 2571 | case rpc_autherr_rejectedcred: |
| 2572 | case rpc_autherr_rejectedverf: |
| 2573 | case rpcsec_gsserr_credproblem: |
| 2574 | case rpcsec_gsserr_ctxproblem: |
| 2575 | if (!task->tk_cred_retry) |
| 2576 | break; |
| 2577 | task->tk_cred_retry--; |
| 2578 | trace_rpc__stale_creds(task); |
Trond Myklebust | 7987b69 | 2019-05-29 12:49:52 -0400 | [diff] [blame] | 2579 | return -EKEYREJECTED; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2580 | case rpc_autherr_badcred: |
| 2581 | case rpc_autherr_badverf: |
| 2582 | /* possibly garbled cred/verf? */ |
| 2583 | if (!task->tk_garb_retry) |
| 2584 | break; |
| 2585 | task->tk_garb_retry--; |
| 2586 | trace_rpc__bad_creds(task); |
| 2587 | task->tk_action = call_encode; |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 2588 | return -EAGAIN; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2589 | case rpc_autherr_tooweak: |
| 2590 | trace_rpc__auth_tooweak(task); |
| 2591 | pr_warn("RPC: server %s requires stronger authentication.\n", |
| 2592 | task->tk_xprt->servername); |
| 2593 | break; |
| 2594 | default: |
Trond Myklebust | eb90a16 | 2019-03-15 09:29:00 -0400 | [diff] [blame] | 2595 | goto out_unparsable; |
Chuck Lever | 7f5667a5 | 2019-02-11 11:24:53 -0500 | [diff] [blame] | 2596 | } |
| 2597 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | } |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2599 | |
Christoph Hellwig | c512f36 | 2017-05-08 09:31:19 +0200 | [diff] [blame] | 2600 | static void rpcproc_encode_null(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
| 2601 | const void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2602 | { |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
Christoph Hellwig | 73c8dc1 | 2017-05-08 14:58:11 +0200 | [diff] [blame] | 2605 | static int rpcproc_decode_null(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
| 2606 | void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2607 | { |
| 2608 | return 0; |
| 2609 | } |
| 2610 | |
Christoph Hellwig | 499b498 | 2017-05-12 15:36:49 +0200 | [diff] [blame] | 2611 | static const struct rpc_procinfo rpcproc_null = { |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2612 | .p_encode = rpcproc_encode_null, |
| 2613 | .p_decode = rpcproc_decode_null, |
| 2614 | }; |
| 2615 | |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2616 | static int rpc_ping(struct rpc_clnt *clnt) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2617 | { |
| 2618 | struct rpc_message msg = { |
| 2619 | .rpc_proc = &rpcproc_null, |
| 2620 | }; |
| 2621 | int err; |
NeilBrown | a68a72e | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 2622 | err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN | |
| 2623 | RPC_TASK_NULLCREDS); |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 2624 | return err; |
| 2625 | } |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2626 | |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2627 | static |
| 2628 | struct rpc_task *rpc_call_null_helper(struct rpc_clnt *clnt, |
| 2629 | struct rpc_xprt *xprt, struct rpc_cred *cred, int flags, |
| 2630 | const struct rpc_call_ops *ops, void *data) |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2631 | { |
| 2632 | struct rpc_message msg = { |
| 2633 | .rpc_proc = &rpcproc_null, |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2634 | }; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2635 | struct rpc_task_setup task_setup_data = { |
| 2636 | .rpc_client = clnt, |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2637 | .rpc_xprt = xprt, |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2638 | .rpc_message = &msg, |
NeilBrown | 1de7eea | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 2639 | .rpc_op_cred = cred, |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2640 | .callback_ops = (ops != NULL) ? ops : &rpc_default_ops, |
| 2641 | .callback_data = data, |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 2642 | .flags = flags | RPC_TASK_NULLCREDS, |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2643 | }; |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2644 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2645 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2646 | } |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2647 | |
| 2648 | struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags) |
| 2649 | { |
| 2650 | return rpc_call_null_helper(clnt, NULL, cred, flags, NULL, NULL); |
| 2651 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2652 | EXPORT_SYMBOL_GPL(rpc_call_null); |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2653 | |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2654 | struct rpc_cb_add_xprt_calldata { |
| 2655 | struct rpc_xprt_switch *xps; |
| 2656 | struct rpc_xprt *xprt; |
| 2657 | }; |
| 2658 | |
| 2659 | static void rpc_cb_add_xprt_done(struct rpc_task *task, void *calldata) |
| 2660 | { |
| 2661 | struct rpc_cb_add_xprt_calldata *data = calldata; |
| 2662 | |
| 2663 | if (task->tk_status == 0) |
| 2664 | rpc_xprt_switch_add_xprt(data->xps, data->xprt); |
| 2665 | } |
| 2666 | |
| 2667 | static void rpc_cb_add_xprt_release(void *calldata) |
| 2668 | { |
| 2669 | struct rpc_cb_add_xprt_calldata *data = calldata; |
| 2670 | |
| 2671 | xprt_put(data->xprt); |
| 2672 | xprt_switch_put(data->xps); |
| 2673 | kfree(data); |
| 2674 | } |
| 2675 | |
Trond Myklebust | ce27230 | 2016-07-24 17:06:28 -0400 | [diff] [blame] | 2676 | static const struct rpc_call_ops rpc_cb_add_xprt_call_ops = { |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2677 | .rpc_call_done = rpc_cb_add_xprt_done, |
| 2678 | .rpc_release = rpc_cb_add_xprt_release, |
| 2679 | }; |
| 2680 | |
| 2681 | /** |
| 2682 | * rpc_clnt_test_and_add_xprt - Test and add a new transport to a rpc_clnt |
| 2683 | * @clnt: pointer to struct rpc_clnt |
| 2684 | * @xps: pointer to struct rpc_xprt_switch, |
| 2685 | * @xprt: pointer struct rpc_xprt |
| 2686 | * @dummy: unused |
| 2687 | */ |
| 2688 | int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt, |
| 2689 | struct rpc_xprt_switch *xps, struct rpc_xprt *xprt, |
| 2690 | void *dummy) |
| 2691 | { |
| 2692 | struct rpc_cb_add_xprt_calldata *data; |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2693 | struct rpc_task *task; |
| 2694 | |
| 2695 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 2696 | if (!data) |
| 2697 | return -ENOMEM; |
| 2698 | data->xps = xprt_switch_get(xps); |
| 2699 | data->xprt = xprt_get(xprt); |
| 2700 | |
NeilBrown | a68a72e | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 2701 | task = rpc_call_null_helper(clnt, xprt, NULL, |
| 2702 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC|RPC_TASK_NULLCREDS, |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2703 | &rpc_cb_add_xprt_call_ops, data); |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2704 | if (IS_ERR(task)) |
| 2705 | return PTR_ERR(task); |
| 2706 | rpc_put_task(task); |
| 2707 | return 1; |
| 2708 | } |
| 2709 | EXPORT_SYMBOL_GPL(rpc_clnt_test_and_add_xprt); |
| 2710 | |
| 2711 | /** |
Andy Adamson | fda0ab4 | 2016-09-09 09:22:26 -0400 | [diff] [blame] | 2712 | * rpc_clnt_setup_test_and_add_xprt() |
| 2713 | * |
| 2714 | * This is an rpc_clnt_add_xprt setup() function which returns 1 so: |
| 2715 | * 1) caller of the test function must dereference the rpc_xprt_switch |
| 2716 | * and the rpc_xprt. |
| 2717 | * 2) test function must call rpc_xprt_switch_add_xprt, usually in |
| 2718 | * the rpc_call_done routine. |
| 2719 | * |
| 2720 | * Upon success (return of 1), the test function adds the new |
| 2721 | * transport to the rpc_clnt xprt switch |
| 2722 | * |
| 2723 | * @clnt: struct rpc_clnt to get the new transport |
| 2724 | * @xps: the rpc_xprt_switch to hold the new transport |
| 2725 | * @xprt: the rpc_xprt to test |
| 2726 | * @data: a struct rpc_add_xprt_test pointer that holds the test function |
| 2727 | * and test function call data |
| 2728 | */ |
| 2729 | int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *clnt, |
| 2730 | struct rpc_xprt_switch *xps, |
| 2731 | struct rpc_xprt *xprt, |
| 2732 | void *data) |
| 2733 | { |
Andy Adamson | fda0ab4 | 2016-09-09 09:22:26 -0400 | [diff] [blame] | 2734 | struct rpc_task *task; |
| 2735 | struct rpc_add_xprt_test *xtest = (struct rpc_add_xprt_test *)data; |
| 2736 | int status = -EADDRINUSE; |
| 2737 | |
| 2738 | xprt = xprt_get(xprt); |
| 2739 | xprt_switch_get(xps); |
| 2740 | |
| 2741 | if (rpc_xprt_switch_has_addr(xps, (struct sockaddr *)&xprt->addr)) |
| 2742 | goto out_err; |
| 2743 | |
| 2744 | /* Test the connection */ |
NeilBrown | a68a72e | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 2745 | task = rpc_call_null_helper(clnt, xprt, NULL, |
| 2746 | RPC_TASK_SOFT | RPC_TASK_SOFTCONN | RPC_TASK_NULLCREDS, |
Andy Adamson | fda0ab4 | 2016-09-09 09:22:26 -0400 | [diff] [blame] | 2747 | NULL, NULL); |
Andy Adamson | fda0ab4 | 2016-09-09 09:22:26 -0400 | [diff] [blame] | 2748 | if (IS_ERR(task)) { |
| 2749 | status = PTR_ERR(task); |
| 2750 | goto out_err; |
| 2751 | } |
| 2752 | status = task->tk_status; |
| 2753 | rpc_put_task(task); |
| 2754 | |
| 2755 | if (status < 0) |
| 2756 | goto out_err; |
| 2757 | |
| 2758 | /* rpc_xprt_switch and rpc_xprt are deferrenced by add_xprt_test() */ |
| 2759 | xtest->add_xprt_test(clnt, xprt, xtest->data); |
| 2760 | |
Santosh kumar pradhan | 10e037d | 2018-12-19 12:29:57 +0530 | [diff] [blame] | 2761 | xprt_put(xprt); |
| 2762 | xprt_switch_put(xps); |
| 2763 | |
Andy Adamson | fda0ab4 | 2016-09-09 09:22:26 -0400 | [diff] [blame] | 2764 | /* so that rpc_clnt_add_xprt does not call rpc_xprt_switch_add_xprt */ |
| 2765 | return 1; |
| 2766 | out_err: |
| 2767 | xprt_put(xprt); |
| 2768 | xprt_switch_put(xps); |
| 2769 | pr_info("RPC: rpc_clnt_test_xprt failed: %d addr %s not added\n", |
| 2770 | status, xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 2771 | return status; |
| 2772 | } |
| 2773 | EXPORT_SYMBOL_GPL(rpc_clnt_setup_test_and_add_xprt); |
| 2774 | |
| 2775 | /** |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2776 | * rpc_clnt_add_xprt - Add a new transport to a rpc_clnt |
| 2777 | * @clnt: pointer to struct rpc_clnt |
| 2778 | * @xprtargs: pointer to struct xprt_create |
| 2779 | * @setup: callback to test and/or set up the connection |
| 2780 | * @data: pointer to setup function data |
| 2781 | * |
| 2782 | * Creates a new transport using the parameters set in args and |
| 2783 | * adds it to clnt. |
| 2784 | * If ping is set, then test that connectivity succeeds before |
| 2785 | * adding the new transport. |
| 2786 | * |
| 2787 | */ |
| 2788 | int rpc_clnt_add_xprt(struct rpc_clnt *clnt, |
| 2789 | struct xprt_create *xprtargs, |
| 2790 | int (*setup)(struct rpc_clnt *, |
| 2791 | struct rpc_xprt_switch *, |
| 2792 | struct rpc_xprt *, |
| 2793 | void *), |
| 2794 | void *data) |
| 2795 | { |
| 2796 | struct rpc_xprt_switch *xps; |
| 2797 | struct rpc_xprt *xprt; |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2798 | unsigned long connect_timeout; |
Trond Myklebust | 3851f1c | 2016-08-04 00:08:45 -0400 | [diff] [blame] | 2799 | unsigned long reconnect_timeout; |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2800 | unsigned char resvport; |
| 2801 | int ret = 0; |
| 2802 | |
| 2803 | rcu_read_lock(); |
| 2804 | xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); |
| 2805 | xprt = xprt_iter_xprt(&clnt->cl_xpi); |
| 2806 | if (xps == NULL || xprt == NULL) { |
| 2807 | rcu_read_unlock(); |
| 2808 | return -EAGAIN; |
| 2809 | } |
| 2810 | resvport = xprt->resvport; |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2811 | connect_timeout = xprt->connect_timeout; |
Trond Myklebust | 3851f1c | 2016-08-04 00:08:45 -0400 | [diff] [blame] | 2812 | reconnect_timeout = xprt->max_reconnect_timeout; |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2813 | rcu_read_unlock(); |
| 2814 | |
| 2815 | xprt = xprt_create_transport(xprtargs); |
| 2816 | if (IS_ERR(xprt)) { |
| 2817 | ret = PTR_ERR(xprt); |
| 2818 | goto out_put_switch; |
| 2819 | } |
| 2820 | xprt->resvport = resvport; |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2821 | if (xprt->ops->set_connect_timeout != NULL) |
| 2822 | xprt->ops->set_connect_timeout(xprt, |
| 2823 | connect_timeout, |
| 2824 | reconnect_timeout); |
Trond Myklebust | 7f55489 | 2016-01-30 23:43:35 -0500 | [diff] [blame] | 2825 | |
| 2826 | rpc_xprt_switch_set_roundrobin(xps); |
| 2827 | if (setup) { |
| 2828 | ret = setup(clnt, xps, xprt, data); |
| 2829 | if (ret != 0) |
| 2830 | goto out_put_xprt; |
| 2831 | } |
| 2832 | rpc_xprt_switch_add_xprt(xps, xprt); |
| 2833 | out_put_xprt: |
| 2834 | xprt_put(xprt); |
| 2835 | out_put_switch: |
| 2836 | xprt_switch_put(xps); |
| 2837 | return ret; |
| 2838 | } |
| 2839 | EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt); |
| 2840 | |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2841 | struct connect_timeout_data { |
| 2842 | unsigned long connect_timeout; |
| 2843 | unsigned long reconnect_timeout; |
| 2844 | }; |
| 2845 | |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2846 | static int |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2847 | rpc_xprt_set_connect_timeout(struct rpc_clnt *clnt, |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2848 | struct rpc_xprt *xprt, |
| 2849 | void *data) |
| 2850 | { |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2851 | struct connect_timeout_data *timeo = data; |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2852 | |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2853 | if (xprt->ops->set_connect_timeout) |
| 2854 | xprt->ops->set_connect_timeout(xprt, |
| 2855 | timeo->connect_timeout, |
| 2856 | timeo->reconnect_timeout); |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2857 | return 0; |
| 2858 | } |
| 2859 | |
| 2860 | void |
Trond Myklebust | 26ae102 | 2017-02-08 11:17:55 -0500 | [diff] [blame] | 2861 | rpc_set_connect_timeout(struct rpc_clnt *clnt, |
| 2862 | unsigned long connect_timeout, |
| 2863 | unsigned long reconnect_timeout) |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2864 | { |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2865 | struct connect_timeout_data timeout = { |
Trond Myklebust | 26ae102 | 2017-02-08 11:17:55 -0500 | [diff] [blame] | 2866 | .connect_timeout = connect_timeout, |
| 2867 | .reconnect_timeout = reconnect_timeout, |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2868 | }; |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2869 | rpc_clnt_iterate_for_each_xprt(clnt, |
Trond Myklebust | 7196dbb | 2017-02-08 11:17:54 -0500 | [diff] [blame] | 2870 | rpc_xprt_set_connect_timeout, |
| 2871 | &timeout); |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2872 | } |
Trond Myklebust | 26ae102 | 2017-02-08 11:17:55 -0500 | [diff] [blame] | 2873 | EXPORT_SYMBOL_GPL(rpc_set_connect_timeout); |
Trond Myklebust | 8d48032 | 2016-08-05 19:03:31 -0400 | [diff] [blame] | 2874 | |
Andy Adamson | 3b58a8a | 2016-09-09 09:22:23 -0400 | [diff] [blame] | 2875 | void rpc_clnt_xprt_switch_put(struct rpc_clnt *clnt) |
| 2876 | { |
Anna Schumaker | bb29dd8 | 2016-10-26 10:33:31 -0400 | [diff] [blame] | 2877 | rcu_read_lock(); |
Andy Adamson | 3b58a8a | 2016-09-09 09:22:23 -0400 | [diff] [blame] | 2878 | xprt_switch_put(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); |
Anna Schumaker | bb29dd8 | 2016-10-26 10:33:31 -0400 | [diff] [blame] | 2879 | rcu_read_unlock(); |
Andy Adamson | 3b58a8a | 2016-09-09 09:22:23 -0400 | [diff] [blame] | 2880 | } |
| 2881 | EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_put); |
| 2882 | |
Andy Adamson | dd69171 | 2016-09-09 09:22:24 -0400 | [diff] [blame] | 2883 | void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt) |
| 2884 | { |
Anna Schumaker | bb29dd8 | 2016-10-26 10:33:31 -0400 | [diff] [blame] | 2885 | rcu_read_lock(); |
Andy Adamson | dd69171 | 2016-09-09 09:22:24 -0400 | [diff] [blame] | 2886 | rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch), |
| 2887 | xprt); |
Anna Schumaker | bb29dd8 | 2016-10-26 10:33:31 -0400 | [diff] [blame] | 2888 | rcu_read_unlock(); |
Andy Adamson | dd69171 | 2016-09-09 09:22:24 -0400 | [diff] [blame] | 2889 | } |
| 2890 | EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt); |
| 2891 | |
Andy Adamson | 39e5d2d | 2016-09-09 09:22:25 -0400 | [diff] [blame] | 2892 | bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt, |
| 2893 | const struct sockaddr *sap) |
| 2894 | { |
| 2895 | struct rpc_xprt_switch *xps; |
| 2896 | bool ret; |
| 2897 | |
Andy Adamson | 39e5d2d | 2016-09-09 09:22:25 -0400 | [diff] [blame] | 2898 | rcu_read_lock(); |
Anna Schumaker | bb29dd8 | 2016-10-26 10:33:31 -0400 | [diff] [blame] | 2899 | xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch); |
Andy Adamson | 39e5d2d | 2016-09-09 09:22:25 -0400 | [diff] [blame] | 2900 | ret = rpc_xprt_switch_has_addr(xps, sap); |
| 2901 | rcu_read_unlock(); |
| 2902 | return ret; |
| 2903 | } |
| 2904 | EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_has_addr); |
| 2905 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 2906 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2907 | static void rpc_show_header(void) |
| 2908 | { |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 2909 | printk(KERN_INFO "-pid- flgs status -client- --rqstp- " |
| 2910 | "-timeout ---ops--\n"); |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2911 | } |
| 2912 | |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2913 | static void rpc_show_task(const struct rpc_clnt *clnt, |
| 2914 | const struct rpc_task *task) |
| 2915 | { |
| 2916 | const char *rpc_waitq = "none"; |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2917 | |
| 2918 | if (RPC_IS_QUEUED(task)) |
| 2919 | rpc_waitq = rpc_qname(task->tk_waitqueue); |
| 2920 | |
Joe Perches | b3bceda | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2921 | printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n", |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 2922 | task->tk_pid, task->tk_flags, task->tk_status, |
Trond Myklebust | 5efd187 | 2019-04-07 13:58:50 -0400 | [diff] [blame] | 2923 | clnt, task->tk_rqstp, rpc_task_timeout(task), task->tk_ops, |
Trond Myklebust | 55909f2 | 2013-08-23 11:48:15 -0400 | [diff] [blame] | 2924 | clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task), |
Joe Perches | b3bceda | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2925 | task->tk_action, rpc_waitq); |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2928 | void rpc_show_tasks(struct net *net) |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2929 | { |
| 2930 | struct rpc_clnt *clnt; |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2931 | struct rpc_task *task; |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2932 | int header = 0; |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2933 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2934 | |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2935 | spin_lock(&sn->rpc_client_lock); |
| 2936 | list_for_each_entry(clnt, &sn->all_clients, cl_clients) { |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2937 | spin_lock(&clnt->cl_lock); |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2938 | list_for_each_entry(task, &clnt->cl_tasks, tk_task) { |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2939 | if (!header) { |
| 2940 | rpc_show_header(); |
| 2941 | header++; |
| 2942 | } |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2943 | rpc_show_task(clnt, task); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2944 | } |
| 2945 | spin_unlock(&clnt->cl_lock); |
| 2946 | } |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2947 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2948 | } |
| 2949 | #endif |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 2950 | |
| 2951 | #if IS_ENABLED(CONFIG_SUNRPC_SWAP) |
Trond Myklebust | 15001e5 | 2016-01-30 20:05:34 -0500 | [diff] [blame] | 2952 | static int |
| 2953 | rpc_clnt_swap_activate_callback(struct rpc_clnt *clnt, |
| 2954 | struct rpc_xprt *xprt, |
| 2955 | void *dummy) |
| 2956 | { |
| 2957 | return xprt_enable_swap(xprt); |
| 2958 | } |
| 2959 | |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 2960 | int |
| 2961 | rpc_clnt_swap_activate(struct rpc_clnt *clnt) |
| 2962 | { |
Trond Myklebust | 15001e5 | 2016-01-30 20:05:34 -0500 | [diff] [blame] | 2963 | if (atomic_inc_return(&clnt->cl_swapper) == 1) |
| 2964 | return rpc_clnt_iterate_for_each_xprt(clnt, |
| 2965 | rpc_clnt_swap_activate_callback, NULL); |
| 2966 | return 0; |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 2967 | } |
| 2968 | EXPORT_SYMBOL_GPL(rpc_clnt_swap_activate); |
| 2969 | |
Trond Myklebust | 15001e5 | 2016-01-30 20:05:34 -0500 | [diff] [blame] | 2970 | static int |
| 2971 | rpc_clnt_swap_deactivate_callback(struct rpc_clnt *clnt, |
| 2972 | struct rpc_xprt *xprt, |
| 2973 | void *dummy) |
| 2974 | { |
| 2975 | xprt_disable_swap(xprt); |
| 2976 | return 0; |
| 2977 | } |
| 2978 | |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 2979 | void |
| 2980 | rpc_clnt_swap_deactivate(struct rpc_clnt *clnt) |
| 2981 | { |
Trond Myklebust | 15001e5 | 2016-01-30 20:05:34 -0500 | [diff] [blame] | 2982 | if (atomic_dec_if_positive(&clnt->cl_swapper) == 0) |
| 2983 | rpc_clnt_iterate_for_each_xprt(clnt, |
| 2984 | rpc_clnt_swap_deactivate_callback, NULL); |
Jeff Layton | 3c87ef6 | 2015-06-03 16:14:25 -0400 | [diff] [blame] | 2985 | } |
| 2986 | EXPORT_SYMBOL_GPL(rpc_clnt_swap_deactivate); |
| 2987 | #endif /* CONFIG_SUNRPC_SWAP */ |