Commit 92200412 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

SUNRPC: transport switch API for setting port number

 At some point, transport endpoint addresses will no longer be IPv4.  To hide
 the structure of the rpc_xprt's address field from ULPs and port mappers,
 add an API for setting the port number during an RPC bind operation.

 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: default avatarChuck Lever <cel@netapp.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 35f5a422
...@@ -104,6 +104,7 @@ struct rpc_xprt_ops { ...@@ -104,6 +104,7 @@ struct rpc_xprt_ops {
void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize); void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize);
int (*reserve_xprt)(struct rpc_task *task); int (*reserve_xprt)(struct rpc_task *task);
void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task); void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
void (*set_port)(struct rpc_xprt *xprt, unsigned short port);
void (*connect)(struct rpc_task *task); void (*connect)(struct rpc_task *task);
void * (*buf_alloc)(struct rpc_task *task, size_t size); void * (*buf_alloc)(struct rpc_task *task, size_t size);
void (*buf_free)(struct rpc_task *task); void (*buf_free)(struct rpc_task *task);
......
...@@ -131,10 +131,13 @@ static void ...@@ -131,10 +131,13 @@ static void
pmap_getport_done(struct rpc_task *task) pmap_getport_done(struct rpc_task *task)
{ {
struct rpc_clnt *clnt = task->tk_client; struct rpc_clnt *clnt = task->tk_client;
struct rpc_xprt *xprt = task->tk_xprt;
struct rpc_portmap *map = clnt->cl_pmap; struct rpc_portmap *map = clnt->cl_pmap;
dprintk("RPC: %4d pmap_getport_done(status %d, port %d)\n", dprintk("RPC: %4d pmap_getport_done(status %d, port %d)\n",
task->tk_pid, task->tk_status, clnt->cl_port); task->tk_pid, task->tk_status, clnt->cl_port);
xprt->ops->set_port(xprt, 0);
if (task->tk_status < 0) { if (task->tk_status < 0) {
/* Make the calling task exit with an error */ /* Make the calling task exit with an error */
task->tk_action = rpc_exit_task; task->tk_action = rpc_exit_task;
...@@ -142,9 +145,8 @@ pmap_getport_done(struct rpc_task *task) ...@@ -142,9 +145,8 @@ pmap_getport_done(struct rpc_task *task)
/* Program not registered */ /* Program not registered */
rpc_exit(task, -EACCES); rpc_exit(task, -EACCES);
} else { } else {
/* byte-swap port number first */ xprt->ops->set_port(xprt, clnt->cl_port);
clnt->cl_port = htons(clnt->cl_port); clnt->cl_port = htons(clnt->cl_port);
clnt->cl_xprt->addr.sin_port = clnt->cl_port;
} }
spin_lock(&pmap_lock); spin_lock(&pmap_lock);
map->pm_binding = 0; map->pm_binding = 0;
...@@ -205,7 +207,7 @@ pmap_create(char *hostname, struct sockaddr_in *srvaddr, int proto, int privileg ...@@ -205,7 +207,7 @@ pmap_create(char *hostname, struct sockaddr_in *srvaddr, int proto, int privileg
xprt = xprt_create_proto(proto, srvaddr, NULL); xprt = xprt_create_proto(proto, srvaddr, NULL);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
return (struct rpc_clnt *)xprt; return (struct rpc_clnt *)xprt;
xprt->addr.sin_port = htons(RPC_PMAP_PORT); xprt->ops->set_port(xprt, RPC_PMAP_PORT);
if (!privileged) if (!privileged)
xprt->resvport = 0; xprt->resvport = 0;
......
...@@ -921,6 +921,18 @@ static void xs_udp_timer(struct rpc_task *task) ...@@ -921,6 +921,18 @@ static void xs_udp_timer(struct rpc_task *task)
xprt_adjust_cwnd(task, -ETIMEDOUT); xprt_adjust_cwnd(task, -ETIMEDOUT);
} }
/**
* xs_set_port - reset the port number in the remote endpoint address
* @xprt: generic transport
* @port: new port number
*
*/
static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
{
dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
xprt->addr.sin_port = htons(port);
}
static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock) static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock)
{ {
struct sockaddr_in myaddr = { struct sockaddr_in myaddr = {
...@@ -1161,6 +1173,7 @@ static struct rpc_xprt_ops xs_udp_ops = { ...@@ -1161,6 +1173,7 @@ static struct rpc_xprt_ops xs_udp_ops = {
.set_buffer_size = xs_udp_set_buffer_size, .set_buffer_size = xs_udp_set_buffer_size,
.reserve_xprt = xprt_reserve_xprt_cong, .reserve_xprt = xprt_reserve_xprt_cong,
.release_xprt = xprt_release_xprt_cong, .release_xprt = xprt_release_xprt_cong,
.set_port = xs_set_port,
.connect = xs_connect, .connect = xs_connect,
.buf_alloc = rpc_malloc, .buf_alloc = rpc_malloc,
.buf_free = rpc_free, .buf_free = rpc_free,
...@@ -1175,6 +1188,7 @@ static struct rpc_xprt_ops xs_udp_ops = { ...@@ -1175,6 +1188,7 @@ static struct rpc_xprt_ops xs_udp_ops = {
static struct rpc_xprt_ops xs_tcp_ops = { static struct rpc_xprt_ops xs_tcp_ops = {
.reserve_xprt = xprt_reserve_xprt, .reserve_xprt = xprt_reserve_xprt,
.release_xprt = xprt_release_xprt, .release_xprt = xprt_release_xprt,
.set_port = xs_set_port,
.connect = xs_connect, .connect = xs_connect,
.buf_alloc = rpc_malloc, .buf_alloc = rpc_malloc,
.buf_free = rpc_free, .buf_free = rpc_free,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment