diff options
Diffstat (limited to 'net/sunrpc')
-rw-r--r-- | net/sunrpc/clnt.c | 8 | ||||
-rw-r--r-- | net/sunrpc/pmap_clnt.c | 158 | ||||
-rw-r--r-- | net/sunrpc/xprt.c | 1 |
3 files changed, 106 insertions, 61 deletions
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; |
260 | out_no_clnt: | 254 | out_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 | ||
27 | struct 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 | |||
27 | static struct rpc_procinfo pmap_procedures[]; | 35 | static struct rpc_procinfo pmap_procedures[]; |
28 | static struct rpc_clnt * pmap_create(char *, struct sockaddr_in *, int, int); | 36 | static struct rpc_clnt * pmap_create(char *, struct sockaddr_in *, int, int); |
29 | static void pmap_getport_done(struct rpc_task *); | 37 | static void pmap_getport_done(struct rpc_task *, void *); |
30 | static struct rpc_program pmap_program; | 38 | static struct rpc_program pmap_program; |
31 | static DEFINE_SPINLOCK(pmap_lock); | 39 | |
40 | static 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 | |||
52 | static inline struct portmap_args *pmap_map_alloc(void) | ||
53 | { | ||
54 | return kmalloc(sizeof(struct portmap_args), GFP_NOFS); | ||
55 | } | ||
56 | |||
57 | static inline void pmap_map_free(struct portmap_args *map) | ||
58 | { | ||
59 | kfree(map); | ||
60 | } | ||
61 | |||
62 | static void pmap_map_release(void *data) | ||
63 | { | ||
64 | pmap_map_free(data); | ||
65 | } | ||
66 | |||
67 | static 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 | |||
73 | static 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); | |||
37 | void | 83 | void |
38 | rpc_getport(struct rpc_task *task, struct rpc_clnt *clnt) | 84 | rpc_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 | ||
88 | bailout: | 140 | bailout: |
89 | spin_lock(&pmap_lock); | 141 | pmap_map_free(map); |
90 | map->pm_binding = 0; | 142 | bailout_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 |
97 | int | 147 | int |
98 | rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot) | 148 | rpc_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 | ||
135 | static void | 185 | static void |
136 | pmap_getport_done(struct rpc_task *task) | 186 | pmap_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 | */ |
241 | static int | 291 | static int |
242 | xdr_encode_mapping(struct rpc_rqst *req, u32 *p, struct rpc_portmap *map) | 292 | xdr_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"); |