diff options
author | Anand V. Avati <avati@blackhole.gluster.com> | 2010-08-12 05:05:02 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-12 03:55:16 -0700 |
commit | 12ce6a962aee3674eb722a09241b43923712ee8e (patch) | |
tree | 61b9e822a8dc398e24c654378fcfd886ce51c447 | |
parent | b69a4f1e31726260a07f883cefac28ed29cc6a12 (diff) |
rpc-clnt/socket: rpc_clnt_reconfig() API to support overriding of port numbers
Signed-off-by: Anand V. Avati <avati@blackhole.gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1314 (portmapper functionality)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1314
-rw-r--r-- | rpc/rpc-lib/src/rpc-clnt.c | 22 | ||||
-rw-r--r-- | rpc/rpc-lib/src/rpc-clnt.h | 41 | ||||
-rw-r--r-- | rpc/rpc-lib/src/rpc-transport.c | 4 | ||||
-rw-r--r-- | rpc/rpc-lib/src/rpc-transport.h | 4 | ||||
-rw-r--r-- | rpc/rpc-transport/socket/src/socket.c | 7 |
5 files changed, 52 insertions, 26 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index dd28c60e0a5..7e3d90bfeaa 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -379,7 +379,7 @@ rpc_clnt_reconnect (void *trans_ptr) gf_log (trans->name, GF_LOG_TRACE, "attempting reconnect"); - ret = rpc_transport_connect (trans); + ret = rpc_transport_connect (trans, conn->config.remote_port); conn->reconnect = gf_timer_call_after (clnt->ctx, tv, @@ -1261,7 +1261,8 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, pthread_mutex_lock (&conn->lock); { if (conn->connected == 0) { - rpc_transport_connect (conn->trans); + rpc_transport_connect (conn->trans, + conn->config.remote_port); } ret = -1; @@ -1348,3 +1349,20 @@ rpc_clnt_destroy (struct rpc_clnt *rpc) GF_FREE (rpc); return; } + + +void +rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config) +{ + if (config->rpc_timeout) + rpc->conn.config.rpc_timeout = config->rpc_timeout; + + if (config->remote_port) + rpc->conn.config.remote_port = config->remote_port; + + if (config->remote_host) { + if (rpc->conn.config.remote_host) + FREE (rpc->conn.config.remote_host); + rpc->conn.config.remote_host = gf_strdup (config->remote_host); + } +} diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h index b9d39b3320a..0e7dfa39613 100644 --- a/rpc/rpc-lib/src/rpc-clnt.h +++ b/rpc/rpc-lib/src/rpc-clnt.h @@ -90,21 +90,30 @@ typedef struct rpc_auth_data { char authdata[RPC_MAX_AUTH_BYTES]; } rpc_auth_data_t; + +struct rpc_clnt_config { + int rpc_timeout; + int remote_port; + char * remote_host; +}; + + #define rpc_auth_flavour(au) ((au).flavour) struct rpc_clnt_connection { - pthread_mutex_t lock; - rpc_transport_t *trans; - gf_timer_t *reconnect; - gf_timer_t *timer; - gf_timer_t *ping_timer; - struct rpc_clnt *rpc_clnt; - char connected; - struct saved_frames *saved_frames; - int32_t frame_timeout; - struct timeval last_sent; - struct timeval last_received; - int32_t ping_started; + pthread_mutex_t lock; + rpc_transport_t *trans; + struct rpc_clnt_config config; + gf_timer_t *reconnect; + gf_timer_t *timer; + gf_timer_t *ping_timer; + struct rpc_clnt *rpc_clnt; + char connected; + struct saved_frames *saved_frames; + int32_t frame_timeout; + struct timeval last_sent; + struct timeval last_received; + int32_t ping_started; }; typedef struct rpc_clnt_connection rpc_clnt_connection_t; @@ -140,12 +149,6 @@ struct rpc_clnt { glusterfs_ctx_t *ctx; }; -struct rpc_clnt_config { - int rpc_timeout; - int remote_port; - char * remote_host; -}; - struct rpc_clnt * rpc_clnt_init (struct rpc_clnt_config *config, dict_t *options, glusterfs_ctx_t *ctx, @@ -185,4 +188,6 @@ void rpc_clnt_unset_connected (rpc_clnt_connection_t *conn); void rpc_clnt_reconnect (void *trans_ptr); +void rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config); + #endif /* !_RPC_CLNT_H */ diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index c21d5ecfccd..f3a9798102c 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.c @@ -1010,13 +1010,13 @@ fail: int32_t -rpc_transport_connect (rpc_transport_t *this) +rpc_transport_connect (rpc_transport_t *this, int port) { int ret = -1; GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); - ret = this->ops->connect (this); + ret = this->ops->connect (this, port); fail: return ret; } diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h index 14ec8bc5719..50ebe52a2c6 100644 --- a/rpc/rpc-lib/src/rpc-transport.h +++ b/rpc/rpc-lib/src/rpc-transport.h @@ -196,7 +196,7 @@ struct rpc_transport_ops { rpc_transport_req_t *req); int32_t (*submit_reply) (rpc_transport_t *this, rpc_transport_reply_t *reply); - int32_t (*connect) (rpc_transport_t *this); + int32_t (*connect) (rpc_transport_t *this, int port); int32_t (*listen) (rpc_transport_t *this); int32_t (*disconnect) (rpc_transport_t *this); int32_t (*get_peername) (rpc_transport_t *this, char *hostname, @@ -216,7 +216,7 @@ int32_t rpc_transport_listen (rpc_transport_t *this); int32_t -rpc_transport_connect (rpc_transport_t *this); +rpc_transport_connect (rpc_transport_t *this, int port); int32_t rpc_transport_disconnect (rpc_transport_t *this); diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index e544332c0b7..31b5a82eae7 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.c @@ -1672,7 +1672,7 @@ socket_disconnect (rpc_transport_t *this) int -socket_connect (rpc_transport_t *this) +socket_connect (rpc_transport_t *this, int port) { int ret = -1; int sock = -1; @@ -1711,6 +1711,9 @@ socket_connect (rpc_transport_t *this) goto err; } + if (port > 0) + ((struct sockaddr_in *) (&sockaddr))->sin_port = htons (port); + pthread_mutex_lock (&priv->lock); { if (priv->sock != -1) { @@ -2228,7 +2231,7 @@ struct rpc_transport_ops tops = { .get_peername = socket_getpeername, .get_peeraddr = socket_getpeeraddr, .get_myname = socket_getmyname, - .get_myaddr = socket_getmyaddr + .get_myaddr = socket_getmyaddr, }; |