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