diff options
author | Stanislav Kinsbursky <skinsbursky@parallels.com> | 2012-01-13 03:52:18 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-01-31 19:28:09 -0500 |
commit | 2ea75a10add779b722650aa10836247e7d609fd7 (patch) | |
tree | ad5a78886546f8c16523424f928c1b2e7c0960e9 /net/sunrpc/rpcb_clnt.c | |
parent | dff02d499c067bdde589b764321b35fe763569f6 (diff) |
SUNRPC: optimize net_ns dereferencing in rpcbind creation calls
Static rpcbind creation functions can be parametrized by network namespace
pointer, calculated only once, instead of using init_net pointer (or taking it
from current when virtualization will be comleted) in many places.
Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc/rpcb_clnt.c')
-rw-r--r-- | net/sunrpc/rpcb_clnt.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 7d32f19ba868..3df276a74d1b 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
@@ -161,10 +161,10 @@ static void rpcb_map_release(void *data) | |||
161 | kfree(map); | 161 | kfree(map); |
162 | } | 162 | } |
163 | 163 | ||
164 | static int rpcb_get_local(void) | 164 | static int rpcb_get_local(struct net *net) |
165 | { | 165 | { |
166 | int cnt; | 166 | int cnt; |
167 | struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id); | 167 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
168 | 168 | ||
169 | spin_lock(&sn->rpcb_clnt_lock); | 169 | spin_lock(&sn->rpcb_clnt_lock); |
170 | if (sn->rpcb_users) | 170 | if (sn->rpcb_users) |
@@ -201,9 +201,10 @@ void rpcb_put_local(void) | |||
201 | } | 201 | } |
202 | } | 202 | } |
203 | 203 | ||
204 | static void rpcb_set_local(struct rpc_clnt *clnt, struct rpc_clnt *clnt4) | 204 | static void rpcb_set_local(struct net *net, struct rpc_clnt *clnt, |
205 | struct rpc_clnt *clnt4) | ||
205 | { | 206 | { |
206 | struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id); | 207 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
207 | 208 | ||
208 | /* Protected by rpcb_create_local_mutex */ | 209 | /* Protected by rpcb_create_local_mutex */ |
209 | sn->rpcb_local_clnt = clnt; | 210 | sn->rpcb_local_clnt = clnt; |
@@ -211,22 +212,23 @@ static void rpcb_set_local(struct rpc_clnt *clnt, struct rpc_clnt *clnt4) | |||
211 | smp_wmb(); | 212 | smp_wmb(); |
212 | sn->rpcb_users = 1; | 213 | sn->rpcb_users = 1; |
213 | dprintk("RPC: created new rpcb local clients (rpcb_local_clnt: " | 214 | dprintk("RPC: created new rpcb local clients (rpcb_local_clnt: " |
214 | "%p, rpcb_local_clnt4: %p)\n", sn->rpcb_local_clnt, | 215 | "%p, rpcb_local_clnt4: %p) for net %p%s\n", |
215 | sn->rpcb_local_clnt4); | 216 | sn->rpcb_local_clnt, sn->rpcb_local_clnt4, |
217 | net, (net == &init_net) ? " (init_net)" : ""); | ||
216 | } | 218 | } |
217 | 219 | ||
218 | /* | 220 | /* |
219 | * Returns zero on success, otherwise a negative errno value | 221 | * Returns zero on success, otherwise a negative errno value |
220 | * is returned. | 222 | * is returned. |
221 | */ | 223 | */ |
222 | static int rpcb_create_local_unix(void) | 224 | static int rpcb_create_local_unix(struct net *net) |
223 | { | 225 | { |
224 | static const struct sockaddr_un rpcb_localaddr_rpcbind = { | 226 | static const struct sockaddr_un rpcb_localaddr_rpcbind = { |
225 | .sun_family = AF_LOCAL, | 227 | .sun_family = AF_LOCAL, |
226 | .sun_path = RPCBIND_SOCK_PATHNAME, | 228 | .sun_path = RPCBIND_SOCK_PATHNAME, |
227 | }; | 229 | }; |
228 | struct rpc_create_args args = { | 230 | struct rpc_create_args args = { |
229 | .net = &init_net, | 231 | .net = net, |
230 | .protocol = XPRT_TRANSPORT_LOCAL, | 232 | .protocol = XPRT_TRANSPORT_LOCAL, |
231 | .address = (struct sockaddr *)&rpcb_localaddr_rpcbind, | 233 | .address = (struct sockaddr *)&rpcb_localaddr_rpcbind, |
232 | .addrsize = sizeof(rpcb_localaddr_rpcbind), | 234 | .addrsize = sizeof(rpcb_localaddr_rpcbind), |
@@ -259,7 +261,7 @@ static int rpcb_create_local_unix(void) | |||
259 | clnt4 = NULL; | 261 | clnt4 = NULL; |
260 | } | 262 | } |
261 | 263 | ||
262 | rpcb_set_local(clnt, clnt4); | 264 | rpcb_set_local(net, clnt, clnt4); |
263 | 265 | ||
264 | out: | 266 | out: |
265 | return result; | 267 | return result; |
@@ -269,7 +271,7 @@ out: | |||
269 | * Returns zero on success, otherwise a negative errno value | 271 | * Returns zero on success, otherwise a negative errno value |
270 | * is returned. | 272 | * is returned. |
271 | */ | 273 | */ |
272 | static int rpcb_create_local_net(void) | 274 | static int rpcb_create_local_net(struct net *net) |
273 | { | 275 | { |
274 | static const struct sockaddr_in rpcb_inaddr_loopback = { | 276 | static const struct sockaddr_in rpcb_inaddr_loopback = { |
275 | .sin_family = AF_INET, | 277 | .sin_family = AF_INET, |
@@ -277,7 +279,7 @@ static int rpcb_create_local_net(void) | |||
277 | .sin_port = htons(RPCBIND_PORT), | 279 | .sin_port = htons(RPCBIND_PORT), |
278 | }; | 280 | }; |
279 | struct rpc_create_args args = { | 281 | struct rpc_create_args args = { |
280 | .net = &init_net, | 282 | .net = net, |
281 | .protocol = XPRT_TRANSPORT_TCP, | 283 | .protocol = XPRT_TRANSPORT_TCP, |
282 | .address = (struct sockaddr *)&rpcb_inaddr_loopback, | 284 | .address = (struct sockaddr *)&rpcb_inaddr_loopback, |
283 | .addrsize = sizeof(rpcb_inaddr_loopback), | 285 | .addrsize = sizeof(rpcb_inaddr_loopback), |
@@ -311,7 +313,7 @@ static int rpcb_create_local_net(void) | |||
311 | clnt4 = NULL; | 313 | clnt4 = NULL; |
312 | } | 314 | } |
313 | 315 | ||
314 | rpcb_set_local(clnt, clnt4); | 316 | rpcb_set_local(net, clnt, clnt4); |
315 | 317 | ||
316 | out: | 318 | out: |
317 | return result; | 319 | return result; |
@@ -325,16 +327,17 @@ int rpcb_create_local(void) | |||
325 | { | 327 | { |
326 | static DEFINE_MUTEX(rpcb_create_local_mutex); | 328 | static DEFINE_MUTEX(rpcb_create_local_mutex); |
327 | int result = 0; | 329 | int result = 0; |
330 | struct net *net = &init_net; | ||
328 | 331 | ||
329 | if (rpcb_get_local()) | 332 | if (rpcb_get_local(net)) |
330 | return result; | 333 | return result; |
331 | 334 | ||
332 | mutex_lock(&rpcb_create_local_mutex); | 335 | mutex_lock(&rpcb_create_local_mutex); |
333 | if (rpcb_get_local()) | 336 | if (rpcb_get_local(net)) |
334 | goto out; | 337 | goto out; |
335 | 338 | ||
336 | if (rpcb_create_local_unix() != 0) | 339 | if (rpcb_create_local_unix(net) != 0) |
337 | result = rpcb_create_local_net(); | 340 | result = rpcb_create_local_net(net); |
338 | 341 | ||
339 | out: | 342 | out: |
340 | mutex_unlock(&rpcb_create_local_mutex); | 343 | mutex_unlock(&rpcb_create_local_mutex); |