summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-transport
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2018-09-23 23:53:39 +0530
committerRaghavendra G <rgowdapp@redhat.com>2018-10-02 11:07:32 +0000
commitc96778b354ea82943442aab158adbb854ca43a52 (patch)
tree059544726c6424583d75b6fceba200abc7a83789 /rpc/rpc-transport
parentff00ce1d55e34ec77e93e742533928edf653e2d2 (diff)
rpc: make binding to port 0 as the default if no option is provided
Right now, if no option is provided, the default port is assumed, which is 24007. Ideally, for 'glusterfsd' processes, it is better to not assume there are any ports given, so it can start listening on any port which is available. This helps us to cleanup the dependencies on glusterd from glusterfsd at the moment. No changes would be done to glusterd code, but making the right defaults helps to make glusterfsd more independent process later. NOTE: This patch is a reduced version of below set of patches: * https://review.gluster.org/14613/ & * https://review.gluster.org/14670/ & * https://review.gluster.org/14671/ Credits: Prasanna Kumar Kalever <pkalever@redhat.com> updates: bz#1343926 Change-Id: Ib874e10505e7366dc56ba754458252b67052e653 Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'rpc/rpc-transport')
-rw-r--r--rpc/rpc-transport/rdma/src/name.c18
-rw-r--r--rpc/rpc-transport/rdma/src/rdma.c10
-rw-r--r--rpc/rpc-transport/socket/src/name.c8
-rw-r--r--rpc/rpc-transport/socket/src/socket.c25
4 files changed, 38 insertions, 23 deletions
diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c
index ea960cba4eb..e7d56fcc1a8 100644
--- a/rpc/rpc-transport/rdma/src/name.c
+++ b/rpc/rpc-transport/rdma/src/name.c
@@ -365,7 +365,7 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
{
struct addrinfo hints, *res = 0;
data_t *listen_port_data = NULL, *listen_host_data = NULL;
- uint16_t listen_port = -1;
+ uint16_t listen_port = 0;
char service[NI_MAXSERV], *listen_host = NULL;
dict_t *options = NULL;
int32_t ret = 0;
@@ -373,13 +373,14 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
options = this->options;
listen_port_data = dict_get(options, "transport.rdma.listen-port");
- listen_host_data = dict_get(options, "transport.rdma.bind-address");
-
if (listen_port_data) {
listen_port = data_to_uint16(listen_port_data);
- } else {
- listen_port = GF_DEFAULT_RDMA_LISTEN_PORT;
+ }
+ listen_host_data = dict_get(options, "transport.rdma.bind-address");
+ if (listen_host_data) {
+ listen_host = data_to_str(listen_host_data);
+ } else {
if (addr->sa_family == AF_INET6) {
struct sockaddr_in6 *in = (struct sockaddr_in6 *)addr;
in->sin6_addr = in6addr_any;
@@ -395,13 +396,6 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
}
}
- if (listen_port == (uint16_t)-1)
- listen_port = GF_DEFAULT_RDMA_LISTEN_PORT;
-
- if (listen_host_data) {
- listen_host = data_to_str(listen_host_data);
- }
-
sprintf(service, "%d", listen_port);
memset(&hints, 0, sizeof(hints));
diff --git a/rpc/rpc-transport/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c
index 92c9ce95929..d5d93d13481 100644
--- a/rpc/rpc-transport/rdma/src/rdma.c
+++ b/rpc/rpc-transport/rdma/src/rdma.c
@@ -4670,6 +4670,7 @@ gf_rdma_listen(rpc_transport_t *this)
gf_rdma_peer_t *peer = NULL;
int ret = 0;
gf_rdma_ctx_t *rdma_ctx = NULL;
+ cmd_args_t *cmd_args = NULL;
char service[NI_MAXSERV], host[NI_MAXHOST];
int optval = 2;
@@ -4725,15 +4726,20 @@ gf_rdma_listen(rpc_transport_t *this)
RDMA_MSG_RDMA_BIND_ADDR_FAILED, "rdma_bind_addr failed");
goto err;
}
-
ret = rdma_listen(peer->cm_id, priv->backlog);
-
if (ret != 0) {
gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_LISTEN_FAILED,
"rdma_listen failed");
goto err;
}
+ cmd_args = &(this->ctx->cmd_args);
+ if (!cmd_args->brick_port2) {
+ cmd_args->brick_port2 = rdma_get_src_port(peer->cm_id);
+ gf_log(this->name, GF_LOG_INFO,
+ "process started listening on port (%d)", cmd_args->brick_port2);
+ }
+
rpc_transport_ref(this);
ret = 0;
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index 3194a7cf369..39c0530b08e 100644
--- a/rpc/rpc-transport/socket/src/name.c
+++ b/rpc/rpc-transport/socket/src/name.c
@@ -357,7 +357,7 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
{
struct addrinfo hints, *res = 0, *rp = NULL;
data_t *listen_port_data = NULL, *listen_host_data = NULL;
- uint16_t listen_port = -1;
+ uint16_t listen_port = 0;
char service[NI_MAXSERV], *listen_host = NULL;
dict_t *options = NULL;
int32_t ret = 0;
@@ -365,15 +365,11 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
options = this->options;
listen_port_data = dict_get(options, "transport.socket.listen-port");
- listen_host_data = dict_get(options, "transport.socket.bind-address");
-
if (listen_port_data) {
listen_port = data_to_uint16(listen_port_data);
}
- if (listen_port == (uint16_t)-1)
- listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
-
+ listen_host_data = dict_get(options, "transport.socket.bind-address");
if (listen_host_data) {
listen_host = data_to_str(listen_host_data);
} else {
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index dd3e1e91992..06b5af2e5b2 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -861,15 +861,19 @@ static int
__socket_server_bind(rpc_transport_t *this)
{
socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ cmd_args_t *cmd_args = NULL;
+ struct sockaddr_storage unix_addr = {0};
int ret = -1;
int opt = 1;
int reuse_check_sock = -1;
- struct sockaddr_storage unix_addr = {0};
GF_VALIDATE_OR_GOTO("socket", this, out);
GF_VALIDATE_OR_GOTO("socket", this->private, out);
priv = this->private;
+ ctx = this->ctx;
+ cmd_args = &ctx->cmd_args;
ret = setsockopt(priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
@@ -901,8 +905,23 @@ __socket_server_bind(rpc_transport_t *this)
this->myinfo.identifier, strerror(errno));
if (errno == EADDRINUSE) {
gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
-
- ret = -EADDRINUSE;
+ }
+ }
+ if (AF_UNIX != SA(&this->myinfo.sockaddr)->sa_family) {
+ if (getsockname(priv->sock, SA(&this->myinfo.sockaddr),
+ &this->myinfo.sockaddr_len) == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "getsockname on (%d) failed (%s)", priv->sock,
+ strerror(errno));
+ ret = -1;
+ goto out;
+ }
+ if (!cmd_args->brick_port) {
+ cmd_args->brick_port = (int)ntohs(
+ ((struct sockaddr_in *)&this->myinfo.sockaddr)->sin_port);
+ gf_log(this->name, GF_LOG_INFO,
+ "process started listening on port (%d)",
+ cmd_args->brick_port);
}
}