Commit 96802a09 authored by Frank van Maarseveen's avatar Frank van Maarseveen Committed by Trond Myklebust

SUNRPC: cleanup transport creation argument passing

Cleanup argument passing to functions for creating an RPC transport.
Signed-off-by: default avatarFrank van Maarseveen <frankvm@frankvm.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 6f2e64d3
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/sunrpc/xdr.h> #include <linux/sunrpc/xdr.h>
#include <linux/sunrpc/msg_prot.h> #include <linux/sunrpc/msg_prot.h>
#ifdef __KERNEL__
extern unsigned int xprt_udp_slot_table_entries; extern unsigned int xprt_udp_slot_table_entries;
extern unsigned int xprt_tcp_slot_table_entries; extern unsigned int xprt_tcp_slot_table_entries;
...@@ -194,7 +196,12 @@ struct rpc_xprt { ...@@ -194,7 +196,12 @@ struct rpc_xprt {
char * address_strings[RPC_DISPLAY_MAX]; char * address_strings[RPC_DISPLAY_MAX];
}; };
#ifdef __KERNEL__ struct rpc_xprtsock_create {
int proto; /* IPPROTO_UDP or IPPROTO_TCP */
struct sockaddr * dstaddr; /* remote peer address */
size_t addrlen;
struct rpc_timeout * timeout; /* optional timeout parameters */
};
/* /*
* Transport operations used by ULPs * Transport operations used by ULPs
...@@ -204,7 +211,7 @@ void xprt_set_timeout(struct rpc_timeout *to, unsigned int retr, unsigned long ...@@ -204,7 +211,7 @@ void xprt_set_timeout(struct rpc_timeout *to, unsigned int retr, unsigned long
/* /*
* Generic internal transport functions * Generic internal transport functions
*/ */
struct rpc_xprt * xprt_create_transport(int proto, struct sockaddr *addr, size_t size, struct rpc_timeout *toparms); struct rpc_xprt * xprt_create_transport(struct rpc_xprtsock_create *args);
void xprt_connect(struct rpc_task *task); void xprt_connect(struct rpc_task *task);
void xprt_reserve(struct rpc_task *task); void xprt_reserve(struct rpc_task *task);
int xprt_reserve_xprt(struct rpc_task *task); int xprt_reserve_xprt(struct rpc_task *task);
...@@ -242,8 +249,8 @@ void xprt_disconnect(struct rpc_xprt *xprt); ...@@ -242,8 +249,8 @@ void xprt_disconnect(struct rpc_xprt *xprt);
/* /*
* Socket transport setup operations * Socket transport setup operations
*/ */
struct rpc_xprt * xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_timeout *to); struct rpc_xprt * xs_setup_udp(struct rpc_xprtsock_create *args);
struct rpc_xprt * xs_setup_tcp(struct sockaddr *addr, size_t addrlen, struct rpc_timeout *to); struct rpc_xprt * xs_setup_tcp(struct rpc_xprtsock_create *args);
int init_socket_xprt(void); int init_socket_xprt(void);
void cleanup_socket_xprt(void); void cleanup_socket_xprt(void);
......
...@@ -234,10 +234,15 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args) ...@@ -234,10 +234,15 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct rpc_clnt *clnt; struct rpc_clnt *clnt;
struct rpc_xprtsock_create xprtargs = {
.proto = args->protocol,
.dstaddr = args->address,
.addrlen = args->addrsize,
.timeout = args->timeout
};
char servername[20]; char servername[20];
xprt = xprt_create_transport(args->protocol, args->address, xprt = xprt_create_transport(&xprtargs);
args->addrsize, args->timeout);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
return (struct rpc_clnt *)xprt; return (struct rpc_clnt *)xprt;
......
...@@ -886,27 +886,24 @@ void xprt_set_timeout(struct rpc_timeout *to, unsigned int retr, unsigned long i ...@@ -886,27 +886,24 @@ void xprt_set_timeout(struct rpc_timeout *to, unsigned int retr, unsigned long i
/** /**
* xprt_create_transport - create an RPC transport * xprt_create_transport - create an RPC transport
* @proto: requested transport protocol * @args: rpc transport creation arguments
* @ap: remote peer address
* @size: length of address
* @to: timeout parameters
* *
*/ */
struct rpc_xprt *xprt_create_transport(int proto, struct sockaddr *ap, size_t size, struct rpc_timeout *to) struct rpc_xprt *xprt_create_transport(struct rpc_xprtsock_create *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct rpc_rqst *req; struct rpc_rqst *req;
switch (proto) { switch (args->proto) {
case IPPROTO_UDP: case IPPROTO_UDP:
xprt = xs_setup_udp(ap, size, to); xprt = xs_setup_udp(args);
break; break;
case IPPROTO_TCP: case IPPROTO_TCP:
xprt = xs_setup_tcp(ap, size, to); xprt = xs_setup_tcp(args);
break; break;
default: default:
printk(KERN_ERR "RPC: unrecognized transport protocol: %d\n", printk(KERN_ERR "RPC: unrecognized transport protocol: %d\n",
proto); args->proto);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
if (IS_ERR(xprt)) { if (IS_ERR(xprt)) {
......
...@@ -1502,12 +1502,12 @@ static struct rpc_xprt_ops xs_tcp_ops = { ...@@ -1502,12 +1502,12 @@ static struct rpc_xprt_ops xs_tcp_ops = {
.print_stats = xs_tcp_print_stats, .print_stats = xs_tcp_print_stats,
}; };
static struct rpc_xprt *xs_setup_xprt(struct sockaddr *addr, size_t addrlen, unsigned int slot_table_size) static struct rpc_xprt *xs_setup_xprt(struct rpc_xprtsock_create *args, unsigned int slot_table_size)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct sock_xprt *new; struct sock_xprt *new;
if (addrlen > sizeof(xprt->addr)) { if (args->addrlen > sizeof(xprt->addr)) {
dprintk("RPC: xs_setup_xprt: address too large\n"); dprintk("RPC: xs_setup_xprt: address too large\n");
return ERR_PTR(-EBADF); return ERR_PTR(-EBADF);
} }
...@@ -1529,8 +1529,8 @@ static struct rpc_xprt *xs_setup_xprt(struct sockaddr *addr, size_t addrlen, uns ...@@ -1529,8 +1529,8 @@ static struct rpc_xprt *xs_setup_xprt(struct sockaddr *addr, size_t addrlen, uns
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
memcpy(&xprt->addr, addr, addrlen); memcpy(&xprt->addr, args->dstaddr, args->addrlen);
xprt->addrlen = addrlen; xprt->addrlen = args->addrlen;
new->port = xs_get_random_port(); new->port = xs_get_random_port();
return xprt; return xprt;
...@@ -1538,22 +1538,20 @@ static struct rpc_xprt *xs_setup_xprt(struct sockaddr *addr, size_t addrlen, uns ...@@ -1538,22 +1538,20 @@ static struct rpc_xprt *xs_setup_xprt(struct sockaddr *addr, size_t addrlen, uns
/** /**
* xs_setup_udp - Set up transport to use a UDP socket * xs_setup_udp - Set up transport to use a UDP socket
* @addr: address of remote server * @args: rpc transport creation arguments
* @addrlen: length of address in bytes
* @to: timeout parameters
* *
*/ */
struct rpc_xprt *xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_timeout *to) struct rpc_xprt *xs_setup_udp(struct rpc_xprtsock_create *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct sock_xprt *transport; struct sock_xprt *transport;
xprt = xs_setup_xprt(addr, addrlen, xprt_udp_slot_table_entries); xprt = xs_setup_xprt(args, xprt_udp_slot_table_entries);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
return xprt; return xprt;
transport = container_of(xprt, struct sock_xprt, xprt); transport = container_of(xprt, struct sock_xprt, xprt);
if (ntohs(((struct sockaddr_in *)addr)->sin_port) != 0) if (ntohs(((struct sockaddr_in *)args->dstaddr)->sin_port) != 0)
xprt_set_bound(xprt); xprt_set_bound(xprt);
xprt->prot = IPPROTO_UDP; xprt->prot = IPPROTO_UDP;
...@@ -1569,8 +1567,8 @@ struct rpc_xprt *xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_ ...@@ -1569,8 +1567,8 @@ struct rpc_xprt *xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_
xprt->ops = &xs_udp_ops; xprt->ops = &xs_udp_ops;
if (to) if (args->timeout)
xprt->timeout = *to; xprt->timeout = *args->timeout;
else else
xprt_set_timeout(&xprt->timeout, 5, 5 * HZ); xprt_set_timeout(&xprt->timeout, 5, 5 * HZ);
...@@ -1583,22 +1581,20 @@ struct rpc_xprt *xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_ ...@@ -1583,22 +1581,20 @@ struct rpc_xprt *xs_setup_udp(struct sockaddr *addr, size_t addrlen, struct rpc_
/** /**
* xs_setup_tcp - Set up transport to use a TCP socket * xs_setup_tcp - Set up transport to use a TCP socket
* @addr: address of remote server * @args: rpc transport creation arguments
* @addrlen: length of address in bytes
* @to: timeout parameters
* *
*/ */
struct rpc_xprt *xs_setup_tcp(struct sockaddr *addr, size_t addrlen, struct rpc_timeout *to) struct rpc_xprt *xs_setup_tcp(struct rpc_xprtsock_create *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct sock_xprt *transport; struct sock_xprt *transport;
xprt = xs_setup_xprt(addr, addrlen, xprt_tcp_slot_table_entries); xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
return xprt; return xprt;
transport = container_of(xprt, struct sock_xprt, xprt); transport = container_of(xprt, struct sock_xprt, xprt);
if (ntohs(((struct sockaddr_in *)addr)->sin_port) != 0) if (ntohs(((struct sockaddr_in *)args->dstaddr)->sin_port) != 0)
xprt_set_bound(xprt); xprt_set_bound(xprt);
xprt->prot = IPPROTO_TCP; xprt->prot = IPPROTO_TCP;
...@@ -1613,8 +1609,8 @@ struct rpc_xprt *xs_setup_tcp(struct sockaddr *addr, size_t addrlen, struct rpc_ ...@@ -1613,8 +1609,8 @@ struct rpc_xprt *xs_setup_tcp(struct sockaddr *addr, size_t addrlen, struct rpc_
xprt->ops = &xs_tcp_ops; xprt->ops = &xs_tcp_ops;
if (to) if (args->timeout)
xprt->timeout = *to; xprt->timeout = *args->timeout;
else else
xprt_set_timeout(&xprt->timeout, 2, 60 * HZ); xprt_set_timeout(&xprt->timeout, 2, 60 * HZ);
......
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