aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2006-08-22 20:06:15 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-09-22 23:24:39 -0400
commit4a68179d38874c37be2802442a71b847f5d1a2a9 (patch)
tree688b345744d182e303f96891d396a0ee1e43520a
parentec739ef03dc926d05051c8c5838971445504470a (diff)
SUNRPC: Make RPC portmapper use per-transport storage
Move connection and bind state that was maintained in the rpc_clnt structure to the rpc_xprt structure. This will allow the creation of a clean API for plugging in different types of bind mechanisms. This brings improvements such as the elimination of a single spin lock to control serialization for all in-kernel RPC binding. A set of per-xprt bitops is used to serialize tasks during RPC binding, just like it now works for making RPC transport connections. Test-plan: Destructive testing (unplugging the network temporarily). Connectathon with UDP and TCP. NFSv2/3 and NFSv4 mounting should be carefully checked. Probably need to rig a server where certain services aren't running, or that returns an error for some typical operation. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--include/linux/sunrpc/clnt.h23
-rw-r--r--include/linux/sunrpc/xprt.h14
-rw-r--r--net/sunrpc/clnt.c8
-rw-r--r--net/sunrpc/pmap_clnt.c158
-rw-r--r--net/sunrpc/xprt.c1
5 files changed, 123 insertions, 81 deletions
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index 8fe9f35eba31..00e9dbaec9c5 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -18,18 +18,6 @@
18#include <linux/sunrpc/timer.h> 18#include <linux/sunrpc/timer.h>
19#include <asm/signal.h> 19#include <asm/signal.h>
20 20
21/*
22 * This defines an RPC port mapping
23 */
24struct rpc_portmap {
25 __u32 pm_prog;
26 __u32 pm_vers;
27 __u32 pm_prot;
28 __u16 pm_port;
29 unsigned char pm_binding : 1; /* doing a getport() */
30 struct rpc_wait_queue pm_bindwait; /* waiting on getport() */
31};
32
33struct rpc_inode; 21struct rpc_inode;
34 22
35/* 23/*
@@ -40,7 +28,9 @@ struct rpc_clnt {
40 atomic_t cl_users; /* number of references */ 28 atomic_t cl_users; /* number of references */
41 struct rpc_xprt * cl_xprt; /* transport */ 29 struct rpc_xprt * cl_xprt; /* transport */
42 struct rpc_procinfo * cl_procinfo; /* procedure info */ 30 struct rpc_procinfo * cl_procinfo; /* procedure info */
43 u32 cl_maxproc; /* max procedure number */ 31 u32 cl_prog, /* RPC program number */
32 cl_vers, /* RPC version number */
33 cl_maxproc; /* max procedure number */
44 34
45 char * cl_server; /* server machine name */ 35 char * cl_server; /* server machine name */
46 char * cl_protname; /* protocol name */ 36 char * cl_protname; /* protocol name */
@@ -55,7 +45,6 @@ struct rpc_clnt {
55 cl_dead : 1;/* abandoned */ 45 cl_dead : 1;/* abandoned */
56 46
57 struct rpc_rtt * cl_rtt; /* RTO estimator data */ 47 struct rpc_rtt * cl_rtt; /* RTO estimator data */
58 struct rpc_portmap * cl_pmap; /* port mapping */
59 48
60 int cl_nodelen; /* nodename length */ 49 int cl_nodelen; /* nodename length */
61 char cl_nodename[UNX_MAXNODENAME]; 50 char cl_nodename[UNX_MAXNODENAME];
@@ -64,14 +53,8 @@ struct rpc_clnt {
64 struct dentry * cl_dentry; /* inode */ 53 struct dentry * cl_dentry; /* inode */
65 struct rpc_clnt * cl_parent; /* Points to parent of clones */ 54 struct rpc_clnt * cl_parent; /* Points to parent of clones */
66 struct rpc_rtt cl_rtt_default; 55 struct rpc_rtt cl_rtt_default;
67 struct rpc_portmap cl_pmap_default;
68 char cl_inline_name[32]; 56 char cl_inline_name[32];
69}; 57};
70#define cl_timeout cl_xprt->timeout
71#define cl_prog cl_pmap->pm_prog
72#define cl_vers cl_pmap->pm_vers
73#define cl_port cl_pmap->pm_port
74#define cl_prot cl_pmap->pm_prot
75 58
76/* 59/*
77 * General RPC program info 60 * General RPC program info
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index a71106723d71..4ce82616873d 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -138,6 +138,7 @@ struct rpc_xprt {
138 unsigned int tsh_size; /* size of transport specific 138 unsigned int tsh_size; /* size of transport specific
139 header */ 139 header */
140 140
141 struct rpc_wait_queue binding; /* requests waiting on rpcbind */
141 struct rpc_wait_queue sending; /* requests waiting to send */ 142 struct rpc_wait_queue sending; /* requests waiting to send */
142 struct rpc_wait_queue resend; /* requests waiting to resend */ 143 struct rpc_wait_queue resend; /* requests waiting to resend */
143 struct rpc_wait_queue pending; /* requests in flight */ 144 struct rpc_wait_queue pending; /* requests in flight */
@@ -270,6 +271,7 @@ int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to);
270#define XPRT_CONNECTING (2) 271#define XPRT_CONNECTING (2)
271#define XPRT_CLOSE_WAIT (3) 272#define XPRT_CLOSE_WAIT (3)
272#define XPRT_BOUND (4) 273#define XPRT_BOUND (4)
274#define XPRT_BINDING (5)
273 275
274static inline void xprt_set_connected(struct rpc_xprt *xprt) 276static inline void xprt_set_connected(struct rpc_xprt *xprt)
275{ 277{
@@ -328,6 +330,18 @@ static inline void xprt_clear_bound(struct rpc_xprt *xprt)
328 clear_bit(XPRT_BOUND, &xprt->state); 330 clear_bit(XPRT_BOUND, &xprt->state);
329} 331}
330 332
333static inline void xprt_clear_binding(struct rpc_xprt *xprt)
334{
335 smp_mb__before_clear_bit();
336 clear_bit(XPRT_BINDING, &xprt->state);
337 smp_mb__after_clear_bit();
338}
339
340static inline int xprt_test_and_set_binding(struct rpc_xprt *xprt)
341{
342 return test_and_set_bit(XPRT_BINDING, &xprt->state);
343}
344
331#endif /* __KERNEL__*/ 345#endif /* __KERNEL__*/
332 346
333#endif /* _LINUX_SUNRPC_XPRT_H */ 347#endif /* _LINUX_SUNRPC_XPRT_H */
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 0b8d03d08561..cee504162a3f 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -147,13 +147,10 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname,
147 clnt->cl_procinfo = version->procs; 147 clnt->cl_procinfo = version->procs;
148 clnt->cl_maxproc = version->nrprocs; 148 clnt->cl_maxproc = version->nrprocs;
149 clnt->cl_protname = program->name; 149 clnt->cl_protname = program->name;
150 clnt->cl_pmap = &clnt->cl_pmap_default;
151 clnt->cl_prog = program->number; 150 clnt->cl_prog = program->number;
152 clnt->cl_vers = version->number; 151 clnt->cl_vers = version->number;
153 clnt->cl_prot = xprt->prot;
154 clnt->cl_stats = program->stats; 152 clnt->cl_stats = program->stats;
155 clnt->cl_metrics = rpc_alloc_iostats(clnt); 153 clnt->cl_metrics = rpc_alloc_iostats(clnt);
156 rpc_init_wait_queue(&clnt->cl_pmap_default.pm_bindwait, "bindwait");
157 154
158 if (!xprt_bound(clnt->cl_xprt)) 155 if (!xprt_bound(clnt->cl_xprt))
159 clnt->cl_autobind = 1; 156 clnt->cl_autobind = 1;
@@ -243,8 +240,6 @@ rpc_clone_client(struct rpc_clnt *clnt)
243 atomic_set(&new->cl_users, 0); 240 atomic_set(&new->cl_users, 0);
244 new->cl_parent = clnt; 241 new->cl_parent = clnt;
245 atomic_inc(&clnt->cl_count); 242 atomic_inc(&clnt->cl_count);
246 /* Duplicate portmapper */
247 rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
248 /* Turn off autobind on clones */ 243 /* Turn off autobind on clones */
249 new->cl_autobind = 0; 244 new->cl_autobind = 0;
250 new->cl_oneshot = 0; 245 new->cl_oneshot = 0;
@@ -254,8 +249,7 @@ rpc_clone_client(struct rpc_clnt *clnt)
254 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval); 249 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval);
255 if (new->cl_auth) 250 if (new->cl_auth)
256 atomic_inc(&new->cl_auth->au_count); 251 atomic_inc(&new->cl_auth->au_count);
257 new->cl_pmap = &new->cl_pmap_default; 252 new->cl_metrics = rpc_alloc_iostats(clnt);
258 new->cl_metrics = rpc_alloc_iostats(clnt);
259 return new; 253 return new;
260out_no_clnt: 254out_no_clnt:
261 printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__); 255 printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__);
diff --git a/net/sunrpc/pmap_clnt.c b/net/sunrpc/pmap_clnt.c
index 209ffdfee10b..59d542436ca9 100644
--- a/net/sunrpc/pmap_clnt.c
+++ b/net/sunrpc/pmap_clnt.c
@@ -24,11 +24,57 @@
24#define PMAP_UNSET 2 24#define PMAP_UNSET 2
25#define PMAP_GETPORT 3 25#define PMAP_GETPORT 3
26 26
27struct portmap_args {
28 u32 pm_prog;
29 u32 pm_vers;
30 u32 pm_prot;
31 unsigned short pm_port;
32 struct rpc_task * pm_task;
33};
34
27static struct rpc_procinfo pmap_procedures[]; 35static struct rpc_procinfo pmap_procedures[];
28static struct rpc_clnt * pmap_create(char *, struct sockaddr_in *, int, int); 36static struct rpc_clnt * pmap_create(char *, struct sockaddr_in *, int, int);
29static void pmap_getport_done(struct rpc_task *); 37static void pmap_getport_done(struct rpc_task *, void *);
30static struct rpc_program pmap_program; 38static struct rpc_program pmap_program;
31static DEFINE_SPINLOCK(pmap_lock); 39
40static void pmap_getport_prepare(struct rpc_task *task, void *calldata)
41{
42 struct portmap_args *map = calldata;
43 struct rpc_message msg = {
44 .rpc_proc = &pmap_procedures[PMAP_GETPORT],
45 .rpc_argp = map,
46 .rpc_resp = &map->pm_port,
47 };
48
49 rpc_call_setup(task, &msg, 0);
50}
51
52static inline struct portmap_args *pmap_map_alloc(void)
53{
54 return kmalloc(sizeof(struct portmap_args), GFP_NOFS);
55}
56
57static inline void pmap_map_free(struct portmap_args *map)
58{
59 kfree(map);
60}
61
62static void pmap_map_release(void *data)
63{
64 pmap_map_free(data);
65}
66
67static const struct rpc_call_ops pmap_getport_ops = {
68 .rpc_call_prepare = pmap_getport_prepare,
69 .rpc_call_done = pmap_getport_done,
70 .rpc_release = pmap_map_release,
71};
72
73static inline void pmap_wake_portmap_waiters(struct rpc_xprt *xprt)
74{
75 xprt_clear_binding(xprt);
76 rpc_wake_up(&xprt->binding);
77}
32 78
33/* 79/*
34 * Obtain the port for a given RPC service on a given host. This one can 80 * Obtain the port for a given RPC service on a given host. This one can
@@ -37,67 +83,71 @@ static DEFINE_SPINLOCK(pmap_lock);
37void 83void
38rpc_getport(struct rpc_task *task, struct rpc_clnt *clnt) 84rpc_getport(struct rpc_task *task, struct rpc_clnt *clnt)
39{ 85{
40 struct rpc_portmap *map = clnt->cl_pmap; 86 struct rpc_xprt *xprt = task->tk_xprt;
41 struct sockaddr_in *sap = &clnt->cl_xprt->addr; 87 struct sockaddr_in *sap = &xprt->addr;
42 struct rpc_message msg = { 88 struct portmap_args *map;
43 .rpc_proc = &pmap_procedures[PMAP_GETPORT],
44 .rpc_argp = map,
45 .rpc_resp = &clnt->cl_port,
46 .rpc_cred = NULL
47 };
48 struct rpc_clnt *pmap_clnt; 89 struct rpc_clnt *pmap_clnt;
49 struct rpc_task *child; 90 struct rpc_task *child;
50 91
51 dprintk("RPC: %4d rpc_getport(%s, %d, %d, %d)\n", 92 dprintk("RPC: %4d rpc_getport(%s, %u, %u, %d)\n",
52 task->tk_pid, clnt->cl_server, 93 task->tk_pid, clnt->cl_server,
53 map->pm_prog, map->pm_vers, map->pm_prot); 94 clnt->cl_prog, clnt->cl_vers, xprt->prot);
54 95
55 /* Autobind on cloned rpc clients is discouraged */ 96 /* Autobind on cloned rpc clients is discouraged */
56 BUG_ON(clnt->cl_parent != clnt); 97 BUG_ON(clnt->cl_parent != clnt);
57 98
58 spin_lock(&pmap_lock); 99 if (xprt_test_and_set_binding(xprt)) {
59 if (map->pm_binding) { 100 task->tk_status = -EACCES; /* tell caller to check again */
60 rpc_sleep_on(&map->pm_bindwait, task, NULL, NULL); 101 rpc_sleep_on(&xprt->binding, task, NULL, NULL);
61 spin_unlock(&pmap_lock);
62 return; 102 return;
63 } 103 }
64 map->pm_binding = 1; 104
65 spin_unlock(&pmap_lock); 105 /* Someone else may have bound if we slept */
106 if (xprt_bound(xprt)) {
107 task->tk_status = 0;
108 goto bailout_nofree;
109 }
110
111 map = pmap_map_alloc();
112 if (!map) {
113 task->tk_status = -ENOMEM;
114 goto bailout_nofree;
115 }
116 map->pm_prog = clnt->cl_prog;
117 map->pm_vers = clnt->cl_vers;
118 map->pm_prot = xprt->prot;
119 map->pm_port = 0;
120 map->pm_task = task;
66 121
67 pmap_clnt = pmap_create(clnt->cl_server, sap, map->pm_prot, 0); 122 pmap_clnt = pmap_create(clnt->cl_server, sap, map->pm_prot, 0);
68 if (IS_ERR(pmap_clnt)) { 123 if (IS_ERR(pmap_clnt)) {
69 task->tk_status = PTR_ERR(pmap_clnt); 124 task->tk_status = PTR_ERR(pmap_clnt);
70 goto bailout; 125 goto bailout;
71 } 126 }
72 task->tk_status = 0;
73 127
74 /* 128 child = rpc_run_task(pmap_clnt, RPC_TASK_ASYNC, &pmap_getport_ops, map);
75 * Note: rpc_new_child will release client after a failure. 129 if (IS_ERR(child)) {
76 */ 130 task->tk_status = -EIO;
77 if (!(child = rpc_new_child(pmap_clnt, task)))
78 goto bailout; 131 goto bailout;
132 }
133 rpc_release_task(child);
79 134
80 /* Setup the call info struct */ 135 rpc_sleep_on(&xprt->binding, task, NULL, NULL);
81 rpc_call_setup(child, &msg, 0);
82 136
83 /* ... and run the child task */
84 task->tk_xprt->stat.bind_count++; 137 task->tk_xprt->stat.bind_count++;
85 rpc_run_child(task, child, pmap_getport_done);
86 return; 138 return;
87 139
88bailout: 140bailout:
89 spin_lock(&pmap_lock); 141 pmap_map_free(map);
90 map->pm_binding = 0; 142bailout_nofree:
91 rpc_wake_up(&map->pm_bindwait); 143 pmap_wake_portmap_waiters(xprt);
92 spin_unlock(&pmap_lock);
93 rpc_exit(task, -EIO);
94} 144}
95 145
96#ifdef CONFIG_ROOT_NFS 146#ifdef CONFIG_ROOT_NFS
97int 147int
98rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot) 148rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot)
99{ 149{
100 struct rpc_portmap map = { 150 struct portmap_args map = {
101 .pm_prog = prog, 151 .pm_prog = prog,
102 .pm_vers = vers, 152 .pm_vers = vers,
103 .pm_prot = prot, 153 .pm_prot = prot,
@@ -133,32 +183,32 @@ rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot)
133#endif 183#endif
134 184
135static void 185static void
136pmap_getport_done(struct rpc_task *task) 186pmap_getport_done(struct rpc_task *child, void *data)
137{ 187{
138 struct rpc_clnt *clnt = task->tk_client; 188 struct portmap_args *map = data;
189 struct rpc_task *task = map->pm_task;
139 struct rpc_xprt *xprt = task->tk_xprt; 190 struct rpc_xprt *xprt = task->tk_xprt;
140 struct rpc_portmap *map = clnt->cl_pmap; 191 int status = child->tk_status;
141
142 dprintk("RPC: %4d pmap_getport_done(status %d, port %d)\n",
143 task->tk_pid, task->tk_status, clnt->cl_port);
144 192
145 if (task->tk_status < 0) { 193 if (status < 0) {
146 /* Make the calling task exit with an error */ 194 /* Portmapper not available */
147 xprt->ops->set_port(xprt, 0); 195 xprt->ops->set_port(xprt, 0);
148 task->tk_action = rpc_exit_task; 196 task->tk_status = status;
149 } else if (clnt->cl_port == 0) { 197 } else if (map->pm_port == 0) {
150 /* Program not registered */ 198 /* Requested RPC service wasn't registered */
151 xprt->ops->set_port(xprt, 0); 199 xprt->ops->set_port(xprt, 0);
152 rpc_exit(task, -EACCES); 200 task->tk_status = -EACCES;
153 } else { 201 } else {
154 xprt->ops->set_port(xprt, clnt->cl_port); 202 /* Succeeded */
203 xprt->ops->set_port(xprt, map->pm_port);
155 xprt_set_bound(xprt); 204 xprt_set_bound(xprt);
156 clnt->cl_port = htons(clnt->cl_port); 205 task->tk_status = 0;
157 } 206 }
158 spin_lock(&pmap_lock); 207
159 map->pm_binding = 0; 208 dprintk("RPC: %4d pmap_getport_done(status %d, port %u)\n",
160 rpc_wake_up(&map->pm_bindwait); 209 child->tk_pid, child->tk_status, map->pm_port);
161 spin_unlock(&pmap_lock); 210
211 pmap_wake_portmap_waiters(xprt);
162} 212}
163 213
164/* 214/*
@@ -172,7 +222,7 @@ rpc_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
172 .sin_family = AF_INET, 222 .sin_family = AF_INET,
173 .sin_addr.s_addr = htonl(INADDR_LOOPBACK), 223 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
174 }; 224 };
175 struct rpc_portmap map = { 225 struct portmap_args map = {
176 .pm_prog = prog, 226 .pm_prog = prog,
177 .pm_vers = vers, 227 .pm_vers = vers,
178 .pm_prot = prot, 228 .pm_prot = prot,
@@ -239,7 +289,7 @@ pmap_create(char *hostname, struct sockaddr_in *srvaddr, int proto, int privileg
239 * XDR encode/decode functions for PMAP 289 * XDR encode/decode functions for PMAP
240 */ 290 */
241static int 291static int
242xdr_encode_mapping(struct rpc_rqst *req, u32 *p, struct rpc_portmap *map) 292xdr_encode_mapping(struct rpc_rqst *req, u32 *p, struct portmap_args *map)
243{ 293{
244 dprintk("RPC: xdr_encode_mapping(%d, %d, %d, %d)\n", 294 dprintk("RPC: xdr_encode_mapping(%d, %d, %d, %d)\n",
245 map->pm_prog, map->pm_vers, map->pm_prot, map->pm_port); 295 map->pm_prog, map->pm_vers, map->pm_prot, map->pm_port);
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index e239ef985ef7..b45abd0743cb 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -928,6 +928,7 @@ static struct rpc_xprt *xprt_setup(int proto, struct sockaddr_in *ap, struct rpc
928 xprt->last_used = jiffies; 928 xprt->last_used = jiffies;
929 xprt->cwnd = RPC_INITCWND; 929 xprt->cwnd = RPC_INITCWND;
930 930
931 rpc_init_wait_queue(&xprt->binding, "xprt_binding");
931 rpc_init_wait_queue(&xprt->pending, "xprt_pending"); 932 rpc_init_wait_queue(&xprt->pending, "xprt_pending");
932 rpc_init_wait_queue(&xprt->sending, "xprt_sending"); 933 rpc_init_wait_queue(&xprt->sending, "xprt_sending");
933 rpc_init_wait_queue(&xprt->resend, "xprt_resend"); 934 rpc_init_wait_queue(&xprt->resend, "xprt_resend");