diff options
Diffstat (limited to 'rpc/rpc-transport/rdma/src/name.c')
| -rw-r--r-- | rpc/rpc-transport/rdma/src/name.c | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c index 5d6c81d5f..c57428ad6 100644 --- a/rpc/rpc-transport/rdma/src/name.c +++ b/rpc/rpc-transport/rdma/src/name.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #include <sys/types.h> @@ -22,12 +13,7 @@ #include <errno.h> #include <netdb.h> #include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 +#include <rdma/rdma_cma.h> #ifndef AF_INET_SDP #define AF_INET_SDP 27 @@ -35,6 +21,8 @@ #include "rpc-transport.h" #include "rdma.h" +#include "common-utils.h" + int32_t gf_resolve_ip6 (const char *hostname, @@ -44,28 +32,43 @@ gf_resolve_ip6 (const char *hostname, struct addrinfo **addr_info); static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, +af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id, + struct sockaddr *sockaddr, socklen_t sockaddr_len, int ceiling) { - int32_t ret = -1; - /* struct sockaddr_in sin = {0, }; */ - uint16_t port = ceiling - 1; + int32_t ret = -1; + uint16_t port = ceiling - 1; + // by default assume none of the ports are blocked and all are available + gf_boolean_t ports[1024] = {_gf_false,}; + int i = 0; + + ret = gf_process_reserved_ports (ports); + if (ret != 0) { + for (i = 0; i < 1024; i++) + ports[i] = _gf_false; + } while (port) { switch (sockaddr->sa_family) { case AF_INET6: - ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); + ((struct sockaddr_in6 *)sockaddr)->sin6_port + = htons (port); break; case AF_INET_SDP: case AF_INET: - ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); + ((struct sockaddr_in *)sockaddr)->sin_port + = htons (port); break; } - - ret = bind (fd, sockaddr, sockaddr_len); + // ignore the reserved ports + if (ports[port] == _gf_true) { + port--; + continue; + } + ret = rdma_bind_addr (cm_id, sockaddr); if (ret == 0) break; @@ -79,11 +82,10 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, return ret; } +#if 0 static int32_t -af_unix_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t sockaddr_len, - int sock) +af_unix_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t sockaddr_len, struct rdma_cm_id *cm_id) { data_t *path_data = NULL; struct sockaddr_un *addr = NULL; @@ -95,7 +97,7 @@ af_unix_client_bind (rpc_transport_t *this, char *path = data_to_str (path_data); if (!path || strlen (path) > UNIX_PATH_MAX) { gf_log (this->name, GF_LOG_DEBUG, - "transport.rdma.bind-path not specfied " + "transport.rdma.bind-path not specified " "for unix socket, letting connect to assign " "default value"); goto err; @@ -115,6 +117,7 @@ af_unix_client_bind (rpc_transport_t *this, err: return ret; } +#endif static int32_t client_fill_address_family (rpc_transport_t *this, struct sockaddr *sockaddr) @@ -162,13 +165,11 @@ client_fill_address_family (rpc_transport_t *this, struct sockaddr *sockaddr) sockaddr->sa_family = AF_INET6; } else if (!strcasecmp (address_family, "inet-sdp")) { sockaddr->sa_family = AF_INET_SDP; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - sockaddr->sa_family = AF_UNSPEC; } else { gf_log (this->name, GF_LOG_ERROR, "unknown address-family (%s) specified", address_family); + sockaddr->sa_family = AF_UNSPEC; return -1; } } @@ -363,6 +364,8 @@ af_inet_server_get_local_sockaddr (rpc_transport_t *this, if (listen_port_data) { listen_port = data_to_uint16 (listen_port_data); } else { + listen_port = GF_DEFAULT_RDMA_LISTEN_PORT; + if (addr->sa_family == AF_INET6) { struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; in->sin6_addr = in6addr_any; @@ -413,10 +416,8 @@ out: } int32_t -gf_rdma_client_bind (rpc_transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len, - int sock) +gf_rdma_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, struct rdma_cm_id *cm_id) { int ret = 0; @@ -428,22 +429,24 @@ gf_rdma_client_bind (rpc_transport_t *this, *sockaddr_len = sizeof (struct sockaddr_in); case AF_INET6: - ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr, + ret = af_inet_bind_to_port_lt_ceiling (cm_id, sockaddr, *sockaddr_len, - CLIENT_PORT_CEILING); + GF_CLIENT_PORT_CEILING); if (ret == -1) { gf_log (this->name, GF_LOG_WARNING, - "cannot bind inet socket (%d) to port " - "less than %d (%s)", - sock, CLIENT_PORT_CEILING, strerror (errno)); + "cannot bind rdma_cm_id to port " + "less than %d (%s)", GF_CLIENT_PORT_CEILING, + strerror (errno)); ret = 0; } break; case AF_UNIX: *sockaddr_len = sizeof (struct sockaddr_un); +#if 0 ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr, *sockaddr_len, sock); +#endif break; default: @@ -530,21 +533,19 @@ gf_rdma_server_get_local_sockaddr (rpc_transport_t *this, addr->sa_family = AF_INET_SDP; } else if (!strcasecmp (address_family, "unix")) { addr->sa_family = AF_UNIX; - } else if (!strcasecmp (address_family, "inet/inet6") - || !strcasecmp (address_family, "inet6/inet")) { - addr->sa_family = AF_UNSPEC; } else { gf_log (this->name, GF_LOG_ERROR, "unknown address family (%s) specified", address_family); + addr->sa_family = AF_UNSPEC; ret = -1; goto err; } } else { gf_log (this->name, GF_LOG_DEBUG, "option address-family not specified, defaulting " - "to inet/inet6"); - addr->sa_family = AF_UNSPEC; + "to inet"); + addr->sa_family = AF_INET; } switch (addr->sa_family) |
