diff options
| author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-07-15 18:34:16 -0400 |
|---|---|---|
| committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-07-15 18:34:16 -0400 |
| commit | e89e896d31b11a51a54ddcd3f72a76bd286dd86c (patch) | |
| tree | 105a9a93a4021caeeba76e479778ad2dd2b87b57 /net/sunrpc/rpcb_clnt.c | |
| parent | 3a628b0fd42f7eaf9d052447784d48ceae9ffb8e (diff) | |
| parent | d67d1c7bf948341fd8678c8e337ec27f4b46b206 (diff) | |
Merge branch 'devel' into next
Conflicts:
fs/nfs/file.c
Fix up the conflict with Jon Corbet's bkl-removal tree
Diffstat (limited to 'net/sunrpc/rpcb_clnt.c')
| -rw-r--r-- | net/sunrpc/rpcb_clnt.c | 356 |
1 files changed, 287 insertions, 69 deletions
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index e6fb21b19b86..24db2b4d12d3 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
| @@ -32,6 +32,10 @@ | |||
| 32 | #define RPCBIND_PROGRAM (100000u) | 32 | #define RPCBIND_PROGRAM (100000u) |
| 33 | #define RPCBIND_PORT (111u) | 33 | #define RPCBIND_PORT (111u) |
| 34 | 34 | ||
| 35 | #define RPCBVERS_2 (2u) | ||
| 36 | #define RPCBVERS_3 (3u) | ||
| 37 | #define RPCBVERS_4 (4u) | ||
| 38 | |||
| 35 | enum { | 39 | enum { |
| 36 | RPCBPROC_NULL, | 40 | RPCBPROC_NULL, |
| 37 | RPCBPROC_SET, | 41 | RPCBPROC_SET, |
| @@ -64,6 +68,7 @@ enum { | |||
| 64 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) | 68 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) |
| 65 | 69 | ||
| 66 | static void rpcb_getport_done(struct rpc_task *, void *); | 70 | static void rpcb_getport_done(struct rpc_task *, void *); |
| 71 | static void rpcb_map_release(void *data); | ||
| 67 | static struct rpc_program rpcb_program; | 72 | static struct rpc_program rpcb_program; |
| 68 | 73 | ||
| 69 | struct rpcbind_args { | 74 | struct rpcbind_args { |
| @@ -76,41 +81,73 @@ struct rpcbind_args { | |||
| 76 | const char * r_netid; | 81 | const char * r_netid; |
| 77 | const char * r_addr; | 82 | const char * r_addr; |
| 78 | const char * r_owner; | 83 | const char * r_owner; |
| 84 | |||
| 85 | int r_status; | ||
| 79 | }; | 86 | }; |
| 80 | 87 | ||
| 81 | static struct rpc_procinfo rpcb_procedures2[]; | 88 | static struct rpc_procinfo rpcb_procedures2[]; |
| 82 | static struct rpc_procinfo rpcb_procedures3[]; | 89 | static struct rpc_procinfo rpcb_procedures3[]; |
| 90 | static struct rpc_procinfo rpcb_procedures4[]; | ||
| 83 | 91 | ||
| 84 | struct rpcb_info { | 92 | struct rpcb_info { |
| 85 | int rpc_vers; | 93 | u32 rpc_vers; |
| 86 | struct rpc_procinfo * rpc_proc; | 94 | struct rpc_procinfo * rpc_proc; |
| 87 | }; | 95 | }; |
| 88 | 96 | ||
| 89 | static struct rpcb_info rpcb_next_version[]; | 97 | static struct rpcb_info rpcb_next_version[]; |
| 90 | static struct rpcb_info rpcb_next_version6[]; | 98 | static struct rpcb_info rpcb_next_version6[]; |
| 91 | 99 | ||
| 100 | static const struct rpc_call_ops rpcb_getport_ops = { | ||
| 101 | .rpc_call_done = rpcb_getport_done, | ||
| 102 | .rpc_release = rpcb_map_release, | ||
| 103 | }; | ||
| 104 | |||
| 105 | static void rpcb_wake_rpcbind_waiters(struct rpc_xprt *xprt, int status) | ||
| 106 | { | ||
| 107 | xprt_clear_binding(xprt); | ||
| 108 | rpc_wake_up_status(&xprt->binding, status); | ||
| 109 | } | ||
| 110 | |||
| 92 | static void rpcb_map_release(void *data) | 111 | static void rpcb_map_release(void *data) |
| 93 | { | 112 | { |
| 94 | struct rpcbind_args *map = data; | 113 | struct rpcbind_args *map = data; |
| 95 | 114 | ||
| 115 | rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); | ||
| 96 | xprt_put(map->r_xprt); | 116 | xprt_put(map->r_xprt); |
| 97 | kfree(map); | 117 | kfree(map); |
| 98 | } | 118 | } |
| 99 | 119 | ||
| 100 | static const struct rpc_call_ops rpcb_getport_ops = { | 120 | static const struct sockaddr_in rpcb_inaddr_loopback = { |
| 101 | .rpc_call_done = rpcb_getport_done, | 121 | .sin_family = AF_INET, |
| 102 | .rpc_release = rpcb_map_release, | 122 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), |
| 123 | .sin_port = htons(RPCBIND_PORT), | ||
| 103 | }; | 124 | }; |
| 104 | 125 | ||
| 105 | static void rpcb_wake_rpcbind_waiters(struct rpc_xprt *xprt, int status) | 126 | static const struct sockaddr_in6 rpcb_in6addr_loopback = { |
| 127 | .sin6_family = AF_INET6, | ||
| 128 | .sin6_addr = IN6ADDR_LOOPBACK_INIT, | ||
| 129 | .sin6_port = htons(RPCBIND_PORT), | ||
| 130 | }; | ||
| 131 | |||
| 132 | static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr, | ||
| 133 | size_t addrlen, u32 version) | ||
| 106 | { | 134 | { |
| 107 | xprt_clear_binding(xprt); | 135 | struct rpc_create_args args = { |
| 108 | rpc_wake_up_status(&xprt->binding, status); | 136 | .protocol = XPRT_TRANSPORT_UDP, |
| 137 | .address = addr, | ||
| 138 | .addrsize = addrlen, | ||
| 139 | .servername = "localhost", | ||
| 140 | .program = &rpcb_program, | ||
| 141 | .version = version, | ||
| 142 | .authflavor = RPC_AUTH_UNIX, | ||
| 143 | .flags = RPC_CLNT_CREATE_NOPING, | ||
| 144 | }; | ||
| 145 | |||
| 146 | return rpc_create(&args); | ||
| 109 | } | 147 | } |
| 110 | 148 | ||
| 111 | static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, | 149 | static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, |
| 112 | size_t salen, int proto, u32 version, | 150 | size_t salen, int proto, u32 version) |
| 113 | int privileged) | ||
| 114 | { | 151 | { |
| 115 | struct rpc_create_args args = { | 152 | struct rpc_create_args args = { |
| 116 | .protocol = proto, | 153 | .protocol = proto, |
| @@ -120,7 +157,8 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, | |||
| 120 | .program = &rpcb_program, | 157 | .program = &rpcb_program, |
| 121 | .version = version, | 158 | .version = version, |
| 122 | .authflavor = RPC_AUTH_UNIX, | 159 | .authflavor = RPC_AUTH_UNIX, |
| 123 | .flags = RPC_CLNT_CREATE_NOPING, | 160 | .flags = (RPC_CLNT_CREATE_NOPING | |
| 161 | RPC_CLNT_CREATE_NONPRIVPORT), | ||
| 124 | }; | 162 | }; |
| 125 | 163 | ||
| 126 | switch (srvaddr->sa_family) { | 164 | switch (srvaddr->sa_family) { |
| @@ -134,29 +172,72 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, | |||
| 134 | return NULL; | 172 | return NULL; |
| 135 | } | 173 | } |
| 136 | 174 | ||
| 137 | if (!privileged) | ||
| 138 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; | ||
| 139 | return rpc_create(&args); | 175 | return rpc_create(&args); |
| 140 | } | 176 | } |
| 141 | 177 | ||
| 178 | static int rpcb_register_call(struct sockaddr *addr, size_t addrlen, | ||
| 179 | u32 version, struct rpc_message *msg, | ||
| 180 | int *result) | ||
| 181 | { | ||
| 182 | struct rpc_clnt *rpcb_clnt; | ||
| 183 | int error = 0; | ||
| 184 | |||
| 185 | *result = 0; | ||
| 186 | |||
| 187 | rpcb_clnt = rpcb_create_local(addr, addrlen, version); | ||
| 188 | if (!IS_ERR(rpcb_clnt)) { | ||
| 189 | error = rpc_call_sync(rpcb_clnt, msg, 0); | ||
| 190 | rpc_shutdown_client(rpcb_clnt); | ||
| 191 | } else | ||
| 192 | error = PTR_ERR(rpcb_clnt); | ||
| 193 | |||
| 194 | if (error < 0) | ||
| 195 | printk(KERN_WARNING "RPC: failed to contact local rpcbind " | ||
| 196 | "server (errno %d).\n", -error); | ||
| 197 | dprintk("RPC: registration status %d/%d\n", error, *result); | ||
| 198 | |||
| 199 | return error; | ||
| 200 | } | ||
| 201 | |||
| 142 | /** | 202 | /** |
| 143 | * rpcb_register - set or unset a port registration with the local rpcbind svc | 203 | * rpcb_register - set or unset a port registration with the local rpcbind svc |
| 144 | * @prog: RPC program number to bind | 204 | * @prog: RPC program number to bind |
| 145 | * @vers: RPC version number to bind | 205 | * @vers: RPC version number to bind |
| 146 | * @prot: transport protocol to use to make this request | 206 | * @prot: transport protocol to register |
| 147 | * @port: port value to register | 207 | * @port: port value to register |
| 148 | * @okay: result code | 208 | * @okay: OUT: result code |
| 209 | * | ||
| 210 | * RPC services invoke this function to advertise their contact | ||
| 211 | * information via the system's rpcbind daemon. RPC services | ||
| 212 | * invoke this function once for each [program, version, transport] | ||
| 213 | * tuple they wish to advertise. | ||
| 214 | * | ||
| 215 | * Callers may also unregister RPC services that are no longer | ||
| 216 | * available by setting the passed-in port to zero. This removes | ||
| 217 | * all registered transports for [program, version] from the local | ||
| 218 | * rpcbind database. | ||
| 219 | * | ||
| 220 | * Returns zero if the registration request was dispatched | ||
| 221 | * successfully and a reply was received. The rpcbind daemon's | ||
| 222 | * boolean result code is stored in *okay. | ||
| 223 | * | ||
| 224 | * Returns an errno value and sets *result to zero if there was | ||
| 225 | * some problem that prevented the rpcbind request from being | ||
| 226 | * dispatched, or if the rpcbind daemon did not respond within | ||
| 227 | * the timeout. | ||
| 149 | * | 228 | * |
| 150 | * port == 0 means unregister, port != 0 means register. | 229 | * This function uses rpcbind protocol version 2 to contact the |
| 230 | * local rpcbind daemon. | ||
| 151 | * | 231 | * |
| 152 | * This routine supports only rpcbind version 2. | 232 | * Registration works over both AF_INET and AF_INET6, and services |
| 233 | * registered via this function are advertised as available for any | ||
| 234 | * address. If the local rpcbind daemon is listening on AF_INET6, | ||
| 235 | * services registered via this function will be advertised on | ||
| 236 | * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6 | ||
| 237 | * addresses). | ||
| 153 | */ | 238 | */ |
| 154 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) | 239 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) |
| 155 | { | 240 | { |
| 156 | struct sockaddr_in sin = { | ||
| 157 | .sin_family = AF_INET, | ||
| 158 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), | ||
| 159 | }; | ||
| 160 | struct rpcbind_args map = { | 241 | struct rpcbind_args map = { |
| 161 | .r_prog = prog, | 242 | .r_prog = prog, |
| 162 | .r_vers = vers, | 243 | .r_vers = vers, |
| @@ -164,32 +245,159 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) | |||
| 164 | .r_port = port, | 245 | .r_port = port, |
| 165 | }; | 246 | }; |
| 166 | struct rpc_message msg = { | 247 | struct rpc_message msg = { |
| 167 | .rpc_proc = &rpcb_procedures2[port ? | ||
| 168 | RPCBPROC_SET : RPCBPROC_UNSET], | ||
| 169 | .rpc_argp = &map, | 248 | .rpc_argp = &map, |
| 170 | .rpc_resp = okay, | 249 | .rpc_resp = okay, |
| 171 | }; | 250 | }; |
| 172 | struct rpc_clnt *rpcb_clnt; | ||
| 173 | int error = 0; | ||
| 174 | 251 | ||
| 175 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " | 252 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " |
| 176 | "rpcbind\n", (port ? "" : "un"), | 253 | "rpcbind\n", (port ? "" : "un"), |
| 177 | prog, vers, prot, port); | 254 | prog, vers, prot, port); |
| 178 | 255 | ||
| 179 | rpcb_clnt = rpcb_create("localhost", (struct sockaddr *) &sin, | 256 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_UNSET]; |
| 180 | sizeof(sin), XPRT_TRANSPORT_UDP, 2, 1); | 257 | if (port) |
| 181 | if (IS_ERR(rpcb_clnt)) | 258 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET]; |
| 182 | return PTR_ERR(rpcb_clnt); | ||
| 183 | 259 | ||
| 184 | error = rpc_call_sync(rpcb_clnt, &msg, 0); | 260 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, |
| 261 | sizeof(rpcb_inaddr_loopback), | ||
| 262 | RPCBVERS_2, &msg, okay); | ||
| 263 | } | ||
| 185 | 264 | ||
| 186 | rpc_shutdown_client(rpcb_clnt); | 265 | /* |
| 187 | if (error < 0) | 266 | * Fill in AF_INET family-specific arguments to register |
| 188 | printk(KERN_WARNING "RPC: failed to contact local rpcbind " | 267 | */ |
| 189 | "server (errno %d).\n", -error); | 268 | static int rpcb_register_netid4(struct sockaddr_in *address_to_register, |
| 190 | dprintk("RPC: registration status %d/%d\n", error, *okay); | 269 | struct rpc_message *msg) |
| 270 | { | ||
| 271 | struct rpcbind_args *map = msg->rpc_argp; | ||
| 272 | unsigned short port = ntohs(address_to_register->sin_port); | ||
| 273 | char buf[32]; | ||
| 274 | |||
| 275 | /* Construct AF_INET universal address */ | ||
| 276 | snprintf(buf, sizeof(buf), | ||
| 277 | NIPQUAD_FMT".%u.%u", | ||
| 278 | NIPQUAD(address_to_register->sin_addr.s_addr), | ||
| 279 | port >> 8, port & 0xff); | ||
| 280 | map->r_addr = buf; | ||
| 281 | |||
| 282 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | ||
| 283 | "local rpcbind\n", (port ? "" : "un"), | ||
| 284 | map->r_prog, map->r_vers, | ||
| 285 | map->r_addr, map->r_netid); | ||
| 286 | |||
| 287 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; | ||
| 288 | if (port) | ||
| 289 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | ||
| 290 | |||
| 291 | return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback, | ||
| 292 | sizeof(rpcb_inaddr_loopback), | ||
| 293 | RPCBVERS_4, msg, msg->rpc_resp); | ||
| 294 | } | ||
| 191 | 295 | ||
| 192 | return error; | 296 | /* |
| 297 | * Fill in AF_INET6 family-specific arguments to register | ||
| 298 | */ | ||
| 299 | static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register, | ||
| 300 | struct rpc_message *msg) | ||
| 301 | { | ||
| 302 | struct rpcbind_args *map = msg->rpc_argp; | ||
| 303 | unsigned short port = ntohs(address_to_register->sin6_port); | ||
| 304 | char buf[64]; | ||
| 305 | |||
| 306 | /* Construct AF_INET6 universal address */ | ||
| 307 | snprintf(buf, sizeof(buf), | ||
| 308 | NIP6_FMT".%u.%u", | ||
| 309 | NIP6(address_to_register->sin6_addr), | ||
| 310 | port >> 8, port & 0xff); | ||
| 311 | map->r_addr = buf; | ||
| 312 | |||
| 313 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | ||
| 314 | "local rpcbind\n", (port ? "" : "un"), | ||
| 315 | map->r_prog, map->r_vers, | ||
| 316 | map->r_addr, map->r_netid); | ||
| 317 | |||
| 318 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; | ||
| 319 | if (port) | ||
| 320 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | ||
| 321 | |||
| 322 | return rpcb_register_call((struct sockaddr *)&rpcb_in6addr_loopback, | ||
| 323 | sizeof(rpcb_in6addr_loopback), | ||
| 324 | RPCBVERS_4, msg, msg->rpc_resp); | ||
| 325 | } | ||
| 326 | |||
| 327 | /** | ||
| 328 | * rpcb_v4_register - set or unset a port registration with the local rpcbind | ||
| 329 | * @program: RPC program number of service to (un)register | ||
| 330 | * @version: RPC version number of service to (un)register | ||
| 331 | * @address: address family, IP address, and port to (un)register | ||
| 332 | * @netid: netid of transport protocol to (un)register | ||
| 333 | * @result: result code from rpcbind RPC call | ||
| 334 | * | ||
| 335 | * RPC services invoke this function to advertise their contact | ||
| 336 | * information via the system's rpcbind daemon. RPC services | ||
| 337 | * invoke this function once for each [program, version, address, | ||
| 338 | * netid] tuple they wish to advertise. | ||
| 339 | * | ||
| 340 | * Callers may also unregister RPC services that are no longer | ||
| 341 | * available by setting the port number in the passed-in address | ||
| 342 | * to zero. Callers pass a netid of "" to unregister all | ||
| 343 | * transport netids associated with [program, version, address]. | ||
| 344 | * | ||
| 345 | * Returns zero if the registration request was dispatched | ||
| 346 | * successfully and a reply was received. The rpcbind daemon's | ||
| 347 | * result code is stored in *result. | ||
| 348 | * | ||
| 349 | * Returns an errno value and sets *result to zero if there was | ||
| 350 | * some problem that prevented the rpcbind request from being | ||
| 351 | * dispatched, or if the rpcbind daemon did not respond within | ||
| 352 | * the timeout. | ||
| 353 | * | ||
| 354 | * This function uses rpcbind protocol version 4 to contact the | ||
| 355 | * local rpcbind daemon. The local rpcbind daemon must support | ||
| 356 | * version 4 of the rpcbind protocol in order for these functions | ||
| 357 | * to register a service successfully. | ||
| 358 | * | ||
| 359 | * Supported netids include "udp" and "tcp" for UDP and TCP over | ||
| 360 | * IPv4, and "udp6" and "tcp6" for UDP and TCP over IPv6, | ||
| 361 | * respectively. | ||
| 362 | * | ||
| 363 | * The contents of @address determine the address family and the | ||
| 364 | * port to be registered. The usual practice is to pass INADDR_ANY | ||
| 365 | * as the raw address, but specifying a non-zero address is also | ||
| 366 | * supported by this API if the caller wishes to advertise an RPC | ||
| 367 | * service on a specific network interface. | ||
| 368 | * | ||
| 369 | * Note that passing in INADDR_ANY does not create the same service | ||
| 370 | * registration as IN6ADDR_ANY. The former advertises an RPC | ||
| 371 | * service on any IPv4 address, but not on IPv6. The latter | ||
| 372 | * advertises the service on all IPv4 and IPv6 addresses. | ||
| 373 | */ | ||
| 374 | int rpcb_v4_register(const u32 program, const u32 version, | ||
| 375 | const struct sockaddr *address, const char *netid, | ||
| 376 | int *result) | ||
| 377 | { | ||
| 378 | struct rpcbind_args map = { | ||
| 379 | .r_prog = program, | ||
| 380 | .r_vers = version, | ||
| 381 | .r_netid = netid, | ||
| 382 | .r_owner = RPCB_OWNER_STRING, | ||
| 383 | }; | ||
| 384 | struct rpc_message msg = { | ||
| 385 | .rpc_argp = &map, | ||
| 386 | .rpc_resp = result, | ||
| 387 | }; | ||
| 388 | |||
| 389 | *result = 0; | ||
| 390 | |||
| 391 | switch (address->sa_family) { | ||
| 392 | case AF_INET: | ||
| 393 | return rpcb_register_netid4((struct sockaddr_in *)address, | ||
| 394 | &msg); | ||
| 395 | case AF_INET6: | ||
| 396 | return rpcb_register_netid6((struct sockaddr_in6 *)address, | ||
| 397 | &msg); | ||
| 398 | } | ||
| 399 | |||
| 400 | return -EAFNOSUPPORT; | ||
| 193 | } | 401 | } |
| 194 | 402 | ||
| 195 | /** | 403 | /** |
| @@ -227,7 +435,7 @@ int rpcb_getport_sync(struct sockaddr_in *sin, u32 prog, u32 vers, int prot) | |||
| 227 | __func__, NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot); | 435 | __func__, NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot); |
| 228 | 436 | ||
| 229 | rpcb_clnt = rpcb_create(NULL, (struct sockaddr *)sin, | 437 | rpcb_clnt = rpcb_create(NULL, (struct sockaddr *)sin, |
| 230 | sizeof(*sin), prot, 2, 0); | 438 | sizeof(*sin), prot, RPCBVERS_2); |
| 231 | if (IS_ERR(rpcb_clnt)) | 439 | if (IS_ERR(rpcb_clnt)) |
| 232 | return PTR_ERR(rpcb_clnt); | 440 | return PTR_ERR(rpcb_clnt); |
| 233 | 441 | ||
| @@ -289,17 +497,16 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 289 | /* Autobind on cloned rpc clients is discouraged */ | 497 | /* Autobind on cloned rpc clients is discouraged */ |
| 290 | BUG_ON(clnt->cl_parent != clnt); | 498 | BUG_ON(clnt->cl_parent != clnt); |
| 291 | 499 | ||
| 500 | /* Put self on the wait queue to ensure we get notified if | ||
| 501 | * some other task is already attempting to bind the port */ | ||
| 502 | rpc_sleep_on(&xprt->binding, task, NULL); | ||
| 503 | |||
| 292 | if (xprt_test_and_set_binding(xprt)) { | 504 | if (xprt_test_and_set_binding(xprt)) { |
| 293 | status = -EAGAIN; /* tell caller to check again */ | ||
| 294 | dprintk("RPC: %5u %s: waiting for another binder\n", | 505 | dprintk("RPC: %5u %s: waiting for another binder\n", |
| 295 | task->tk_pid, __func__); | 506 | task->tk_pid, __func__); |
| 296 | goto bailout_nowake; | 507 | return; |
| 297 | } | 508 | } |
| 298 | 509 | ||
| 299 | /* Put self on queue before sending rpcbind request, in case | ||
| 300 | * rpcb_getport_done completes before we return from rpc_run_task */ | ||
| 301 | rpc_sleep_on(&xprt->binding, task, NULL); | ||
| 302 | |||
| 303 | /* Someone else may have bound if we slept */ | 510 | /* Someone else may have bound if we slept */ |
| 304 | if (xprt_bound(xprt)) { | 511 | if (xprt_bound(xprt)) { |
| 305 | status = 0; | 512 | status = 0; |
| @@ -338,7 +545,7 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 338 | task->tk_pid, __func__, bind_version); | 545 | task->tk_pid, __func__, bind_version); |
| 339 | 546 | ||
| 340 | rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot, | 547 | rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot, |
| 341 | bind_version, 0); | 548 | bind_version); |
| 342 | if (IS_ERR(rpcb_clnt)) { | 549 | if (IS_ERR(rpcb_clnt)) { |
| 343 | status = PTR_ERR(rpcb_clnt); | 550 | status = PTR_ERR(rpcb_clnt); |
| 344 | dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", | 551 | dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", |
| @@ -361,15 +568,15 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 361 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); | 568 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); |
| 362 | map->r_addr = rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR); | 569 | map->r_addr = rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR); |
| 363 | map->r_owner = RPCB_OWNER_STRING; /* ignored for GETADDR */ | 570 | map->r_owner = RPCB_OWNER_STRING; /* ignored for GETADDR */ |
| 571 | map->r_status = -EIO; | ||
| 364 | 572 | ||
| 365 | child = rpcb_call_async(rpcb_clnt, map, proc); | 573 | child = rpcb_call_async(rpcb_clnt, map, proc); |
| 366 | rpc_release_client(rpcb_clnt); | 574 | rpc_release_client(rpcb_clnt); |
| 367 | if (IS_ERR(child)) { | 575 | if (IS_ERR(child)) { |
| 368 | status = -EIO; | ||
| 369 | /* rpcb_map_release() has freed the arguments */ | 576 | /* rpcb_map_release() has freed the arguments */ |
| 370 | dprintk("RPC: %5u %s: rpc_run_task failed\n", | 577 | dprintk("RPC: %5u %s: rpc_run_task failed\n", |
| 371 | task->tk_pid, __func__); | 578 | task->tk_pid, __func__); |
| 372 | goto bailout_nofree; | 579 | return; |
| 373 | } | 580 | } |
| 374 | rpc_put_task(child); | 581 | rpc_put_task(child); |
| 375 | 582 | ||
| @@ -378,7 +585,6 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 378 | 585 | ||
| 379 | bailout_nofree: | 586 | bailout_nofree: |
| 380 | rpcb_wake_rpcbind_waiters(xprt, status); | 587 | rpcb_wake_rpcbind_waiters(xprt, status); |
| 381 | bailout_nowake: | ||
| 382 | task->tk_status = status; | 588 | task->tk_status = status; |
| 383 | } | 589 | } |
| 384 | EXPORT_SYMBOL_GPL(rpcb_getport_async); | 590 | EXPORT_SYMBOL_GPL(rpcb_getport_async); |
| @@ -417,9 +623,13 @@ static void rpcb_getport_done(struct rpc_task *child, void *data) | |||
| 417 | dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n", | 623 | dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n", |
| 418 | child->tk_pid, status, map->r_port); | 624 | child->tk_pid, status, map->r_port); |
| 419 | 625 | ||
| 420 | rpcb_wake_rpcbind_waiters(xprt, status); | 626 | map->r_status = status; |
| 421 | } | 627 | } |
| 422 | 628 | ||
| 629 | /* | ||
| 630 | * XDR functions for rpcbind | ||
| 631 | */ | ||
| 632 | |||
| 423 | static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, | 633 | static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, |
| 424 | struct rpcbind_args *rpcb) | 634 | struct rpcbind_args *rpcb) |
| 425 | { | 635 | { |
| @@ -438,7 +648,7 @@ static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p, | |||
| 438 | unsigned short *portp) | 648 | unsigned short *portp) |
| 439 | { | 649 | { |
| 440 | *portp = (unsigned short) ntohl(*p++); | 650 | *portp = (unsigned short) ntohl(*p++); |
| 441 | dprintk("RPC: rpcb_decode_getport result %u\n", | 651 | dprintk("RPC: rpcb_decode_getport result %u\n", |
| 442 | *portp); | 652 | *portp); |
| 443 | return 0; | 653 | return 0; |
| 444 | } | 654 | } |
| @@ -447,8 +657,8 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p, | |||
| 447 | unsigned int *boolp) | 657 | unsigned int *boolp) |
| 448 | { | 658 | { |
| 449 | *boolp = (unsigned int) ntohl(*p++); | 659 | *boolp = (unsigned int) ntohl(*p++); |
| 450 | dprintk("RPC: rpcb_decode_set result %u\n", | 660 | dprintk("RPC: rpcb_decode_set: call %s\n", |
| 451 | *boolp); | 661 | (*boolp ? "succeeded" : "failed")); |
| 452 | return 0; | 662 | return 0; |
| 453 | } | 663 | } |
| 454 | 664 | ||
| @@ -571,52 +781,60 @@ out_err: | |||
| 571 | static struct rpc_procinfo rpcb_procedures2[] = { | 781 | static struct rpc_procinfo rpcb_procedures2[] = { |
| 572 | PROC(SET, mapping, set), | 782 | PROC(SET, mapping, set), |
| 573 | PROC(UNSET, mapping, set), | 783 | PROC(UNSET, mapping, set), |
| 574 | PROC(GETADDR, mapping, getport), | 784 | PROC(GETPORT, mapping, getport), |
| 575 | }; | 785 | }; |
| 576 | 786 | ||
| 577 | static struct rpc_procinfo rpcb_procedures3[] = { | 787 | static struct rpc_procinfo rpcb_procedures3[] = { |
| 578 | PROC(SET, mapping, set), | 788 | PROC(SET, getaddr, set), |
| 579 | PROC(UNSET, mapping, set), | 789 | PROC(UNSET, getaddr, set), |
| 580 | PROC(GETADDR, getaddr, getaddr), | 790 | PROC(GETADDR, getaddr, getaddr), |
| 581 | }; | 791 | }; |
| 582 | 792 | ||
| 583 | static struct rpc_procinfo rpcb_procedures4[] = { | 793 | static struct rpc_procinfo rpcb_procedures4[] = { |
| 584 | PROC(SET, mapping, set), | 794 | PROC(SET, getaddr, set), |
| 585 | PROC(UNSET, mapping, set), | 795 | PROC(UNSET, getaddr, set), |
| 796 | PROC(GETADDR, getaddr, getaddr), | ||
| 586 | PROC(GETVERSADDR, getaddr, getaddr), | 797 | PROC(GETVERSADDR, getaddr, getaddr), |
| 587 | }; | 798 | }; |
| 588 | 799 | ||
| 589 | static struct rpcb_info rpcb_next_version[] = { | 800 | static struct rpcb_info rpcb_next_version[] = { |
| 590 | #ifdef CONFIG_SUNRPC_BIND34 | 801 | { |
| 591 | { 4, &rpcb_procedures4[RPCBPROC_GETVERSADDR] }, | 802 | .rpc_vers = RPCBVERS_2, |
| 592 | { 3, &rpcb_procedures3[RPCBPROC_GETADDR] }, | 803 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], |
| 593 | #endif | 804 | }, |
| 594 | { 2, &rpcb_procedures2[RPCBPROC_GETPORT] }, | 805 | { |
| 595 | { 0, NULL }, | 806 | .rpc_proc = NULL, |
| 807 | }, | ||
| 596 | }; | 808 | }; |
| 597 | 809 | ||
| 598 | static struct rpcb_info rpcb_next_version6[] = { | 810 | static struct rpcb_info rpcb_next_version6[] = { |
| 599 | #ifdef CONFIG_SUNRPC_BIND34 | 811 | { |
| 600 | { 4, &rpcb_procedures4[RPCBPROC_GETVERSADDR] }, | 812 | .rpc_vers = RPCBVERS_4, |
| 601 | { 3, &rpcb_procedures3[RPCBPROC_GETADDR] }, | 813 | .rpc_proc = &rpcb_procedures4[RPCBPROC_GETADDR], |
| 602 | #endif | 814 | }, |
| 603 | { 0, NULL }, | 815 | { |
| 816 | .rpc_vers = RPCBVERS_3, | ||
| 817 | .rpc_proc = &rpcb_procedures3[RPCBPROC_GETADDR], | ||
| 818 | }, | ||
| 819 | { | ||
| 820 | .rpc_proc = NULL, | ||
| 821 | }, | ||
| 604 | }; | 822 | }; |
| 605 | 823 | ||
| 606 | static struct rpc_version rpcb_version2 = { | 824 | static struct rpc_version rpcb_version2 = { |
| 607 | .number = 2, | 825 | .number = RPCBVERS_2, |
| 608 | .nrprocs = RPCB_HIGHPROC_2, | 826 | .nrprocs = RPCB_HIGHPROC_2, |
| 609 | .procs = rpcb_procedures2 | 827 | .procs = rpcb_procedures2 |
| 610 | }; | 828 | }; |
| 611 | 829 | ||
| 612 | static struct rpc_version rpcb_version3 = { | 830 | static struct rpc_version rpcb_version3 = { |
| 613 | .number = 3, | 831 | .number = RPCBVERS_3, |
| 614 | .nrprocs = RPCB_HIGHPROC_3, | 832 | .nrprocs = RPCB_HIGHPROC_3, |
| 615 | .procs = rpcb_procedures3 | 833 | .procs = rpcb_procedures3 |
| 616 | }; | 834 | }; |
| 617 | 835 | ||
| 618 | static struct rpc_version rpcb_version4 = { | 836 | static struct rpc_version rpcb_version4 = { |
| 619 | .number = 4, | 837 | .number = RPCBVERS_4, |
| 620 | .nrprocs = RPCB_HIGHPROC_4, | 838 | .nrprocs = RPCB_HIGHPROC_4, |
| 621 | .procs = rpcb_procedures4 | 839 | .procs = rpcb_procedures4 |
| 622 | }; | 840 | }; |
