summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-transport
diff options
context:
space:
mode:
authorGluster Ant <bugzilla-bot@gluster.org>2018-09-12 17:52:45 +0530
committerNigel Babu <nigelb@redhat.com>2018-09-12 17:52:45 +0530
commite16868dede6455cab644805af6fe1ac312775e13 (patch)
tree15aebdb4fff2d87cf8a72f836816b3aa634da58d /rpc/rpc-transport
parent45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff)
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'rpc/rpc-transport')
-rw-r--r--rpc/rpc-transport/rdma/src/name.c1002
-rw-r--r--rpc/rpc-transport/rdma/src/rdma.c8091
-rw-r--r--rpc/rpc-transport/socket/src/name.c1151
-rw-r--r--rpc/rpc-transport/socket/src/socket.c7444
4 files changed, 8615 insertions, 9073 deletions
diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c
index 2db1f08c751..ea960cba4eb 100644
--- a/rpc/rpc-transport/rdma/src/name.c
+++ b/rpc/rpc-transport/rdma/src/name.c
@@ -25,85 +25,82 @@
#include "rpc-lib-messages.h"
#include "rpc-trans-rdma-messages.h"
-
int32_t
-gf_resolve_ip6 (const char *hostname,
- uint16_t port,
- int family,
- void **dnscache,
- struct addrinfo **addr_info);
-
+gf_resolve_ip6(const char *hostname, uint16_t port, int family, void **dnscache,
+ struct addrinfo **addr_info);
static void
-_assign_port (struct sockaddr *sockaddr, uint16_t port)
+_assign_port(struct sockaddr *sockaddr, uint16_t port)
{
- switch (sockaddr->sa_family) {
+ switch (sockaddr->sa_family) {
case AF_INET6:
- ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port);
- break;
+ ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons(port);
+ break;
case AF_INET_SDP:
case AF_INET:
- ((struct sockaddr_in *)sockaddr)->sin_port = htons (port);
- break;
- }
+ ((struct sockaddr_in *)sockaddr)->sin_port = htons(port);
+ break;
+ }
}
static int32_t
-af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id,
- struct sockaddr *sockaddr,
- socklen_t sockaddr_len, uint32_t ceiling)
+af_inet_bind_to_port_lt_ceiling(struct rdma_cm_id *cm_id,
+ struct sockaddr *sockaddr,
+ socklen_t sockaddr_len, uint32_t ceiling)
{
#if GF_DISABLE_PRIVPORT_TRACKING
- _assign_port (sockaddr, 0);
- return rdma_bind_addr (cm_id, sockaddr);
+ _assign_port(sockaddr, 0);
+ return rdma_bind_addr(cm_id, sockaddr);
#else
- int32_t ret = -1;
- uint16_t port = ceiling - 1;
- unsigned char ports[GF_PORT_ARRAY_SIZE] = {0,};
- int i = 0;
+ int32_t ret = -1;
+ uint16_t port = ceiling - 1;
+ unsigned char ports[GF_PORT_ARRAY_SIZE] = {
+ 0,
+ };
+ int i = 0;
loop:
- ret = gf_process_reserved_ports (ports, ceiling);
+ ret = gf_process_reserved_ports(ports, ceiling);
- while (port) {
- if (port == GF_CLIENT_PORT_CEILING) {
- ret = -1;
- break;
- }
+ while (port) {
+ if (port == GF_CLIENT_PORT_CEILING) {
+ ret = -1;
+ break;
+ }
- /* ignore the reserved ports */
- if (BIT_VALUE (ports, port)) {
- port--;
- continue;
- }
+ /* ignore the reserved ports */
+ if (BIT_VALUE(ports, port)) {
+ port--;
+ continue;
+ }
- _assign_port (sockaddr, port);
+ _assign_port(sockaddr, port);
- ret = rdma_bind_addr (cm_id, sockaddr);
+ ret = rdma_bind_addr(cm_id, sockaddr);
- if (ret == 0)
- break;
+ if (ret == 0)
+ break;
- if (ret == -1 && errno == EACCES)
- break;
+ if (ret == -1 && errno == EACCES)
+ break;
- port--;
- }
+ port--;
+ }
- /* In case if all the secure ports are exhausted, we are no more
- * binding to secure ports, hence instead of getting a random
- * port, lets define the range to restrict it from getting from
- * ports reserved for bricks i.e from range of 49152 - 65535
- * which further may lead to port clash */
- if (!port) {
- ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
- for (i = 0; i <= ceiling; i++)
- BIT_CLEAR (ports, i);
- goto loop;
- }
+ /* In case if all the secure ports are exhausted, we are no more
+ * binding to secure ports, hence instead of getting a random
+ * port, lets define the range to restrict it from getting from
+ * ports reserved for bricks i.e from range of 49152 - 65535
+ * which further may lead to port clash */
+ if (!port) {
+ ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
+ for (i = 0; i <= ceiling; i++)
+ BIT_CLEAR(ports, i);
+ goto loop;
+ }
- return ret;
+ return ret;
#endif /* GF_DISABLE_PRIVPORT_TRACKING */
}
@@ -146,596 +143,573 @@ err:
#endif
static int32_t
-client_fill_address_family (rpc_transport_t *this, struct sockaddr *sockaddr)
+client_fill_address_family(rpc_transport_t *this, struct sockaddr *sockaddr)
{
- data_t *address_family_data = NULL;
-
- address_family_data = dict_get (this->options,
- "transport.address-family");
- if (!address_family_data) {
- data_t *remote_host_data = NULL, *connect_path_data = NULL;
- remote_host_data = dict_get (this->options, "remote-host");
- connect_path_data = dict_get (this->options,
- "transport.rdma.connect-path");
-
- if (!(remote_host_data || connect_path_data) ||
- (remote_host_data && connect_path_data)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_ADDR_FAMILY_NOT_SPECIFIED,
- "address-family not specified and not able to "
- "determine the same from other options "
- "(remote-host:%s and connect-path:%s)",
- data_to_str (remote_host_data),
- data_to_str (connect_path_data));
- return -1;
- }
+ data_t *address_family_data = NULL;
+
+ address_family_data = dict_get(this->options, "transport.address-family");
+ if (!address_family_data) {
+ data_t *remote_host_data = NULL, *connect_path_data = NULL;
+ remote_host_data = dict_get(this->options, "remote-host");
+ connect_path_data = dict_get(this->options,
+ "transport.rdma.connect-path");
+
+ if (!(remote_host_data || connect_path_data) ||
+ (remote_host_data && connect_path_data)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ TRANS_MSG_ADDR_FAMILY_NOT_SPECIFIED,
+ "address-family not specified and not able to "
+ "determine the same from other options "
+ "(remote-host:%s and connect-path:%s)",
+ data_to_str(remote_host_data),
+ data_to_str(connect_path_data));
+ return -1;
+ }
- if (remote_host_data) {
- gf_msg_debug (this->name, 0, "address-family not "
- "specified, guessing it to be "
- "inet/inet6");
- sockaddr->sa_family = AF_UNSPEC;
- } else {
- gf_msg_debug (this->name, 0, "address-family not "
- "specified, guessing it to be unix");
- sockaddr->sa_family = AF_UNIX;
- }
+ if (remote_host_data) {
+ gf_msg_debug(this->name, 0,
+ "address-family not "
+ "specified, guessing it to be "
+ "inet/inet6");
+ sockaddr->sa_family = AF_UNSPEC;
+ } else {
+ gf_msg_debug(this->name, 0,
+ "address-family not "
+ "specified, guessing it to be unix");
+ sockaddr->sa_family = AF_UNIX;
+ }
+ } else {
+ char *address_family = data_to_str(address_family_data);
+ if (!strcasecmp(address_family, "unix")) {
+ sockaddr->sa_family = AF_UNIX;
+ } else if (!strcasecmp(address_family, "inet")) {
+ sockaddr->sa_family = AF_INET;
+ } else if (!strcasecmp(address_family, "inet6")) {
+ sockaddr->sa_family = AF_INET6;
+ } else if (!strcasecmp(address_family, "inet-sdp")) {
+ sockaddr->sa_family = AF_INET_SDP;
} else {
- char *address_family = data_to_str (address_family_data);
- if (!strcasecmp (address_family, "unix")) {
- sockaddr->sa_family = AF_UNIX;
- } else if (!strcasecmp (address_family, "inet")) {
- sockaddr->sa_family = AF_INET;
- } else if (!strcasecmp (address_family, "inet6")) {
- sockaddr->sa_family = AF_INET6;
- } else if (!strcasecmp (address_family, "inet-sdp")) {
- sockaddr->sa_family = AF_INET_SDP;
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_UNKNOWN_ADDR_FAMILY,
- "unknown address-family (%s) specified",
- address_family);
- sockaddr->sa_family = AF_UNSPEC;
- return -1;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY,
+ "unknown address-family (%s) specified", address_family);
+ sockaddr->sa_family = AF_UNSPEC;
+ return -1;
}
+ }
- return 0;
+ return 0;
}
static int32_t
-af_inet_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len,
- int16_t remote_port)
+af_inet_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len, int16_t remote_port)
{
- dict_t *options = this->options;
- data_t *remote_host_data = NULL;
- data_t *remote_port_data = NULL;
- char *remote_host = NULL;
- struct addrinfo *addr_info = NULL;
- int32_t ret = 0;
-
- remote_host_data = dict_get (options, "remote-host");
- if (remote_host_data == NULL) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_REMOTE_HOST_ERROR, "option remote-host "
- "missing in volume %s", this->name);
- ret = -1;
- goto err;
- }
-
- remote_host = data_to_str (remote_host_data);
- if (remote_host == NULL) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_REMOTE_HOST_ERROR, "option remote-host "
- "has data NULL in volume %s", this->name);
- ret = -1;
- goto err;
- }
-
- if (remote_port == 0) {
- remote_port_data = dict_get (options, "remote-port");
- if (remote_port_data == NULL) {
- gf_msg_debug (this->name, 0, "option remote-port "
- "missing in volume %s. Defaulting to %d",
- this->name, GF_DEFAULT_RDMA_LISTEN_PORT);
-
- remote_port = GF_DEFAULT_RDMA_LISTEN_PORT;
- } else {
- remote_port = data_to_uint16 (remote_port_data);
- }
- }
-
- if (remote_port == -1) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- RDMA_MSG_INVALID_ENTRY, "option remote-port has "
- "invalid port in volume %s", this->name);
- ret = -1;
- goto err;
- }
-
- /* TODO: gf_resolve is a blocking call. kick in some
- non blocking dns techniques */
- ret = gf_resolve_ip6 (remote_host, remote_port,
- sockaddr->sa_family,
- &this->dnscache, &addr_info);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, TRANS_MSG_DNS_RESOL_FAILED,
- "DNS resolution failed on host %s", remote_host);
- goto err;
+ dict_t *options = this->options;
+ data_t *remote_host_data = NULL;
+ data_t *remote_port_data = NULL;
+ char *remote_host = NULL;
+ struct addrinfo *addr_info = NULL;
+ int32_t ret = 0;
+
+ remote_host_data = dict_get(options, "remote-host");
+ if (remote_host_data == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_REMOTE_HOST_ERROR,
+ "option remote-host "
+ "missing in volume %s",
+ this->name);
+ ret = -1;
+ goto err;
+ }
+
+ remote_host = data_to_str(remote_host_data);
+ if (remote_host == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_REMOTE_HOST_ERROR,
+ "option remote-host "
+ "has data NULL in volume %s",
+ this->name);
+ ret = -1;
+ goto err;
+ }
+
+ if (remote_port == 0) {
+ remote_port_data = dict_get(options, "remote-port");
+ if (remote_port_data == NULL) {
+ gf_msg_debug(this->name, 0,
+ "option remote-port "
+ "missing in volume %s. Defaulting to %d",
+ this->name, GF_DEFAULT_RDMA_LISTEN_PORT);
+
+ remote_port = GF_DEFAULT_RDMA_LISTEN_PORT;
+ } else {
+ remote_port = data_to_uint16(remote_port_data);
}
-
- memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen);
- *sockaddr_len = addr_info->ai_addrlen;
+ }
+
+ if (remote_port == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, RDMA_MSG_INVALID_ENTRY,
+ "option remote-port has "
+ "invalid port in volume %s",
+ this->name);
+ ret = -1;
+ goto err;
+ }
+
+ /* TODO: gf_resolve is a blocking call. kick in some
+ non blocking dns techniques */
+ ret = gf_resolve_ip6(remote_host, remote_port, sockaddr->sa_family,
+ &this->dnscache, &addr_info);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_DNS_RESOL_FAILED,
+ "DNS resolution failed on host %s", remote_host);
+ goto err;
+ }
+
+ memcpy(sockaddr, addr_info->ai_addr, addr_info->ai_addrlen);
+ *sockaddr_len = addr_info->ai_addrlen;
err:
- return ret;
+ return ret;
}
static int32_t
-af_unix_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len)
+af_unix_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len)
{
- struct sockaddr_un *sockaddr_un = NULL;
- char *connect_path = NULL;
- data_t *connect_path_data = NULL;
- int32_t ret = 0;
-
- connect_path_data = dict_get (this->options,
- "transport.rdma.connect-path");
- if (!connect_path_data) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_CONNECT_PATH_ERROR, "option "
- "transport.rdma.connect-path not specified for "
- "address-family unix");
- ret = -1;
- goto err;
- }
-
- connect_path = data_to_str (connect_path_data);
- if (!connect_path) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- RDMA_MSG_INVALID_ENTRY, "connect-path is null-string");
- ret = -1;
- goto err;
- }
-
- if (strlen (connect_path) > UNIX_PATH_MAX) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_CONNECT_PATH_ERROR,
- "connect-path value length %"GF_PRI_SIZET" > "
- "%d octets", strlen (connect_path), UNIX_PATH_MAX);
- ret = -1;
- goto err;
- }
-
- gf_msg_debug (this->name, 0, "using connect-path %s", connect_path);
- sockaddr_un = (struct sockaddr_un *)sockaddr;
- strcpy (sockaddr_un->sun_path, connect_path);
- *sockaddr_len = sizeof (struct sockaddr_un);
+ struct sockaddr_un *sockaddr_un = NULL;
+ char *connect_path = NULL;
+ data_t *connect_path_data = NULL;
+ int32_t ret = 0;
+
+ connect_path_data = dict_get(this->options, "transport.rdma.connect-path");
+ if (!connect_path_data) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_CONNECT_PATH_ERROR,
+ "option "
+ "transport.rdma.connect-path not specified for "
+ "address-family unix");
+ ret = -1;
+ goto err;
+ }
+
+ connect_path = data_to_str(connect_path_data);
+ if (!connect_path) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, RDMA_MSG_INVALID_ENTRY,
+ "connect-path is null-string");
+ ret = -1;
+ goto err;
+ }
+
+ if (strlen(connect_path) > UNIX_PATH_MAX) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_CONNECT_PATH_ERROR,
+ "connect-path value length %" GF_PRI_SIZET
+ " > "
+ "%d octets",
+ strlen(connect_path), UNIX_PATH_MAX);
+ ret = -1;
+ goto err;
+ }
+
+ gf_msg_debug(this->name, 0, "using connect-path %s", connect_path);
+ sockaddr_un = (struct sockaddr_un *)sockaddr;
+ strcpy(sockaddr_un->sun_path, connect_path);
+ *sockaddr_len = sizeof(struct sockaddr_un);
err:
- return ret;
+ return ret;
}
static int32_t
-af_unix_server_get_local_sockaddr (rpc_transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len)
{
- data_t *listen_path_data = NULL;
- char *listen_path = NULL;
- int32_t ret = 0;
- struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
-
-
- listen_path_data = dict_get (this->options,
- "transport.rdma.listen-path");
- if (!listen_path_data) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_LISTEN_PATH_ERROR,
- "missing option listen-path");
- ret = -1;
- goto err;
- }
+ data_t *listen_path_data = NULL;
+ char *listen_path = NULL;
+ int32_t ret = 0;
+ struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
+
+ listen_path_data = dict_get(this->options, "transport.rdma.listen-path");
+ if (!listen_path_data) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_LISTEN_PATH_ERROR,
+ "missing option listen-path");
+ ret = -1;
+ goto err;
+ }
- listen_path = data_to_str (listen_path_data);
+ listen_path = data_to_str(listen_path_data);
#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif
- if (strlen (listen_path) > UNIX_PATH_MAX) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_LISTEN_PATH_ERROR, "option listen-path has "
- "value length %"GF_PRI_SIZET" > %d",
- strlen (listen_path), UNIX_PATH_MAX);
- ret = -1;
- goto err;
- }
+ if (strlen(listen_path) > UNIX_PATH_MAX) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_LISTEN_PATH_ERROR,
+ "option listen-path has "
+ "value length %" GF_PRI_SIZET " > %d",
+ strlen(listen_path), UNIX_PATH_MAX);
+ ret = -1;
+ goto err;
+ }
- sunaddr->sun_family = AF_UNIX;
- strcpy (sunaddr->sun_path, listen_path);
- *addr_len = sizeof (struct sockaddr_un);
+ sunaddr->sun_family = AF_UNIX;
+ strcpy(sunaddr->sun_path, listen_path);
+ *addr_len = sizeof(struct sockaddr_un);
err:
- return ret;
+ return ret;
}
static int32_t
-af_inet_server_get_local_sockaddr (rpc_transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len)
{
- struct addrinfo hints, *res = 0;
- data_t *listen_port_data = NULL, *listen_host_data = NULL;
- uint16_t listen_port = -1;
- char service[NI_MAXSERV], *listen_host = NULL;
- dict_t *options = NULL;
- int32_t ret = 0;
-
- 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;
-
- if (addr->sa_family == AF_INET6) {
- struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr;
- in->sin6_addr = in6addr_any;
- in->sin6_port = htons(listen_port);
- *addr_len = sizeof(struct sockaddr_in6);
- goto out;
- } else if (addr->sa_family == AF_INET) {
- struct sockaddr_in *in = (struct sockaddr_in *) addr;
- in->sin_addr.s_addr = htonl(INADDR_ANY);
- in->sin_port = htons(listen_port);
- *addr_len = sizeof(struct sockaddr_in);
- goto out;
- }
+ struct addrinfo hints, *res = 0;
+ data_t *listen_port_data = NULL, *listen_host_data = NULL;
+ uint16_t listen_port = -1;
+ char service[NI_MAXSERV], *listen_host = NULL;
+ dict_t *options = NULL;
+ int32_t ret = 0;
+
+ 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;
+
+ if (addr->sa_family == AF_INET6) {
+ struct sockaddr_in6 *in = (struct sockaddr_in6 *)addr;
+ in->sin6_addr = in6addr_any;
+ in->sin6_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in6);
+ goto out;
+ } else if (addr->sa_family == AF_INET) {
+ struct sockaddr_in *in = (struct sockaddr_in *)addr;
+ in->sin_addr.s_addr = htonl(INADDR_ANY);
+ in->sin_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in);
+ goto out;
}
+ }
- if (listen_port == (uint16_t) -1)
- listen_port = GF_DEFAULT_RDMA_LISTEN_PORT;
+ 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);
+ }
- if (listen_host_data) {
- listen_host = data_to_str (listen_host_data);
- }
+ sprintf(service, "%d", listen_port);
- sprintf (service, "%d", listen_port);
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = addr->sa_family;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
-
- ret = getaddrinfo(listen_host, service, &hints, &res);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- TRANS_MSG_GET_ADDR_INFO_FAILED,
- "getaddrinfo failed for host %s, service %s",
- listen_host, service);
- ret = -1;
- goto out;
- }
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = addr->sa_family;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
+
+ ret = getaddrinfo(listen_host, service, &hints, &res);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_ADDR_INFO_FAILED,
+ "getaddrinfo failed for host %s, service %s", listen_host,
+ service);
+ ret = -1;
+ goto out;
+ }
- memcpy (addr, res->ai_addr, res->ai_addrlen);
- *addr_len = res->ai_addrlen;
+ memcpy(addr, res->ai_addr, res->ai_addrlen);
+ *addr_len = res->ai_addrlen;
- freeaddrinfo (res);
+ freeaddrinfo(res);
out:
- return ret;
+ return ret;
}
int32_t
-gf_rdma_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr,
- socklen_t *sockaddr_len, struct rdma_cm_id *cm_id)
+gf_rdma_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len, struct rdma_cm_id *cm_id)
{
- int ret = 0;
+ int ret = 0;
- *sockaddr_len = sizeof (struct sockaddr_in6);
- switch (sockaddr->sa_family) {
+ *sockaddr_len = sizeof(struct sockaddr_in6);
+ switch (sockaddr->sa_family) {
case AF_INET_SDP:
case AF_INET:
- *sockaddr_len = sizeof (struct sockaddr_in);
+ *sockaddr_len = sizeof(struct sockaddr_in);
/* Fall through */
case AF_INET6:
- if (!this->bind_insecure) {
- ret = af_inet_bind_to_port_lt_ceiling (cm_id, sockaddr,
- *sockaddr_len,
- GF_CLIENT_PORT_CEILING);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_PORT_BIND_FAILED,
- "cannot bind rdma_cm_id to port "
- "less than %d", GF_CLIENT_PORT_CEILING);
- }
- } else {
- ret = af_inet_bind_to_port_lt_ceiling (cm_id, sockaddr,
- *sockaddr_len,
- GF_IANA_PRIV_PORTS_START);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_PORT_BIND_FAILED,
- "cannot bind rdma_cm_id to port "
- "less than %d",
- GF_IANA_PRIV_PORTS_START);
- }
+ if (!this->bind_insecure) {
+ ret = af_inet_bind_to_port_lt_ceiling(
+ cm_id, sockaddr, *sockaddr_len, GF_CLIENT_PORT_CEILING);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ RDMA_MSG_PORT_BIND_FAILED,
+ "cannot bind rdma_cm_id to port "
+ "less than %d",
+ GF_CLIENT_PORT_CEILING);
+ }
+ } else {
+ ret = af_inet_bind_to_port_lt_ceiling(
+ cm_id, sockaddr, *sockaddr_len, GF_IANA_PRIV_PORTS_START);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ RDMA_MSG_PORT_BIND_FAILED,
+ "cannot bind rdma_cm_id to port "
+ "less than %d",
+ GF_IANA_PRIV_PORTS_START);
}
- break;
+ }
+ break;
case AF_UNIX:
- *sockaddr_len = sizeof (struct sockaddr_un);
+ *sockaddr_len = sizeof(struct sockaddr_un);
#if 0
ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr,
*sockaddr_len, sock);
#endif
- break;
+ break;
default:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_UNKNOWN_ADDR_FAMILY,
- "unknown address family %d", sockaddr->sa_family);
- ret = -1;
- break;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY,
+ "unknown address family %d", sockaddr->sa_family);
+ ret = -1;
+ break;
+ }
- return ret;
+ return ret;
}
int32_t
-gf_rdma_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len,
- int16_t remote_port)
+gf_rdma_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len, int16_t remote_port)
{
- int32_t ret = 0;
- char is_inet_sdp = 0;
+ int32_t ret = 0;
+ char is_inet_sdp = 0;
- ret = client_fill_address_family (this, sockaddr);
- if (ret) {
- ret = -1;
- goto err;
- }
+ ret = client_fill_address_family(this, sockaddr);
+ if (ret) {
+ ret = -1;
+ goto err;
+ }
- switch (sockaddr->sa_family) {
+ switch (sockaddr->sa_family) {
case AF_INET_SDP:
- sockaddr->sa_family = AF_INET;
- is_inet_sdp = 1;
+ sockaddr->sa_family = AF_INET;
+ is_inet_sdp = 1;
/* Fall through */
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
- ret = af_inet_client_get_remote_sockaddr (this,
- sockaddr,
- sockaddr_len,
- remote_port);
+ ret = af_inet_client_get_remote_sockaddr(this, sockaddr,
+ sockaddr_len, remote_port);
- if (is_inet_sdp) {
- sockaddr->sa_family = AF_INET_SDP;
- }
+ if (is_inet_sdp) {
+ sockaddr->sa_family = AF_INET_SDP;
+ }
- break;
+ break;
case AF_UNIX:
- ret = af_unix_client_get_remote_sockaddr (this,
- sockaddr,
- sockaddr_len);
- break;
+ ret = af_unix_client_get_remote_sockaddr(this, sockaddr,
+ sockaddr_len);
+ break;
default:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_UNKNOWN_ADDR_FAMILY,
- "unknown address-family %d", sockaddr->sa_family);
- ret = -1;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY,
+ "unknown address-family %d", sockaddr->sa_family);
+ ret = -1;
+ }
err:
- return ret;
+ return ret;
}
int32_t
-gf_rdma_server_get_local_sockaddr (rpc_transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+gf_rdma_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len)
{
- data_t *address_family_data = NULL;
- int32_t ret = 0;
- char is_inet_sdp = 0;
-
- address_family_data = dict_get (this->options,
- "transport.address-family");
- if (address_family_data) {
- char *address_family = NULL;
- address_family = data_to_str (address_family_data);
-
- if (!strcasecmp (address_family, "inet")) {
- addr->sa_family = AF_INET;
- } else if (!strcasecmp (address_family, "inet6")) {
- addr->sa_family = AF_INET6;
- } else if (!strcasecmp (address_family, "inet-sdp")) {
- addr->sa_family = AF_INET_SDP;
- } else if (!strcasecmp (address_family, "unix")) {
- addr->sa_family = AF_UNIX;
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_UNKNOWN_ADDR_FAMILY, "unknown address"
- " family (%s) specified", address_family);
- addr->sa_family = AF_UNSPEC;
- ret = -1;
- goto err;
- }
+ data_t *address_family_data = NULL;
+ int32_t ret = 0;
+ char is_inet_sdp = 0;
+
+ address_family_data = dict_get(this->options, "transport.address-family");
+ if (address_family_data) {
+ char *address_family = NULL;
+ address_family = data_to_str(address_family_data);
+
+ if (!strcasecmp(address_family, "inet")) {
+ addr->sa_family = AF_INET;
+ } else if (!strcasecmp(address_family, "inet6")) {
+ addr->sa_family = AF_INET6;
+ } else if (!strcasecmp(address_family, "inet-sdp")) {
+ addr->sa_family = AF_INET_SDP;
+ } else if (!strcasecmp(address_family, "unix")) {
+ addr->sa_family = AF_UNIX;
} else {
- gf_msg_debug (this->name, 0, "option address-family not "
- "specified, defaulting to inet");
- addr->sa_family = AF_INET;
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY,
+ "unknown address"
+ " family (%s) specified",
+ address_family);
+ addr->sa_family = AF_UNSPEC;
+ ret = -1;
+ goto err;
}
-
- switch (addr->sa_family) {
+ } else {
+ gf_msg_debug(this->name, 0,
+ "option address-family not "
+ "specified, defaulting to inet");
+ addr->sa_family = AF_INET;
+ }
+
+ switch (addr->sa_family) {
case AF_INET_SDP:
- is_inet_sdp = 1;
- addr->sa_family = AF_INET;
- /* Fall through */
+ is_inet_sdp = 1;
+ addr->sa_family = AF_INET;
+ /* Fall through */
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
- ret = af_inet_server_get_local_sockaddr (this, addr, addr_len);
- if (is_inet_sdp && !ret) {
- addr->sa_family = AF_INET_SDP;
- }
- break;
+ ret = af_inet_server_get_local_sockaddr(this, addr, addr_len);
+ if (is_inet_sdp && !ret) {
+ addr->sa_family = AF_INET_SDP;
+ }
+ break;
case AF_UNIX:
- ret = af_unix_server_get_local_sockaddr (this, addr, addr_len);
- break;
- }
+ ret = af_unix_server_get_local_sockaddr(this, addr, addr_len);
+ break;
+ }
err:
- return ret;
+ return ret;
}
int32_t
-fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *addr,
- int32_t addr_len, char *identifier)
+fill_inet6_inet_identifiers(rpc_transport_t *this,
+ struct sockaddr_storage *addr, int32_t addr_len,
+ char *identifier)
{
- int32_t ret = 0, tmpaddr_len = 0;
- char service[NI_MAXSERV], host[NI_MAXHOST];
- union gf_sock_union sock_union;
+ int32_t ret = 0, tmpaddr_len = 0;
+ char service[NI_MAXSERV], host[NI_MAXHOST];
+ union gf_sock_union sock_union;
- memset (&sock_union, 0, sizeof (sock_union));
- sock_union.storage = *addr;
- tmpaddr_len = addr_len;
+ memset(&sock_union, 0, sizeof(sock_union));
+ sock_union.storage = *addr;
+ tmpaddr_len = addr_len;
- if (sock_union.sa.sa_family == AF_INET6) {
- int32_t one_to_four, four_to_eight, twelve_to_sixteen;
- int16_t eight_to_ten, ten_to_twelve;
+ if (sock_union.sa.sa_family == AF_INET6) {
+ int32_t one_to_four, four_to_eight, twelve_to_sixteen;
+ int16_t eight_to_ten, ten_to_twelve;
- one_to_four = four_to_eight = twelve_to_sixteen = 0;
- eight_to_ten = ten_to_twelve = 0;
+ one_to_four = four_to_eight = twelve_to_sixteen = 0;
+ eight_to_ten = ten_to_twelve = 0;
- one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0];
- four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1];
+ one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0];
+ four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1];
#ifdef GF_SOLARIS_HOST_OS
- eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4];
+ eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4];
#else
- eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4];
+ eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4];
#endif
#ifdef GF_SOLARIS_HOST_OS
- ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5];
+ ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5];
#else
- ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5];
+ ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5];
#endif
- twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3];
-
- /* ipv4 mapped ipv6 address has
- bits 0-80: 0
- bits 80-96: 0xffff
- bits 96-128: ipv4 address
- */
-
- if (one_to_four == 0 &&
- four_to_eight == 0 &&
- eight_to_ten == 0 &&
- ten_to_twelve == -1) {
- struct sockaddr_in *in_ptr = &sock_union.sin;
- memset (&sock_union, 0, sizeof (sock_union));
-
- in_ptr->sin_family = AF_INET;
- in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port;
- in_ptr->sin_addr.s_addr = twelve_to_sixteen;
- tmpaddr_len = sizeof (*in_ptr);
- }
+ twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3];
+
+ /* ipv4 mapped ipv6 address has
+ bits 0-80: 0
+ bits 80-96: 0xffff
+ bits 96-128: ipv4 address
+ */
+
+ if (one_to_four == 0 && four_to_eight == 0 && eight_to_ten == 0 &&
+ ten_to_twelve == -1) {
+ struct sockaddr_in *in_ptr = &sock_union.sin;
+ memset(&sock_union, 0, sizeof(sock_union));
+
+ in_ptr->sin_family = AF_INET;
+ in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port;
+ in_ptr->sin_addr.s_addr = twelve_to_sixteen;
+ tmpaddr_len = sizeof(*in_ptr);
}
+ }
- ret = getnameinfo (&sock_union.sa,
- tmpaddr_len,
- host, sizeof (host),
- service, sizeof (service),
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- TRANS_MSG_GET_NAME_INFO_FAILED,
- "getnameinfo failed");
- }
+ ret = getnameinfo(&sock_union.sa, tmpaddr_len, host, sizeof(host), service,
+ sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_NAME_INFO_FAILED,
+ "getnameinfo failed");
+ }
- sprintf (identifier, "%s:%s", host, service);
+ sprintf(identifier, "%s:%s", host, service);
- return ret;
+ return ret;
}
int32_t
-gf_rdma_get_transport_identifiers (rpc_transport_t *this)
+gf_rdma_get_transport_identifiers(rpc_transport_t *this)
{
- int32_t ret = 0;
- char is_inet_sdp = 0;
+ int32_t ret = 0;
+ char is_inet_sdp = 0;
- switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) {
+ switch (((struct sockaddr *)&this->myinfo.sockaddr)->sa_family) {
case AF_INET_SDP:
- is_inet_sdp = 1;
- ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET;
- /* Fall through */
+ is_inet_sdp = 1;
+ ((struct sockaddr *)&this->peerinfo.sockaddr)
+ ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr)
+ ->sa_family = AF_INET;
+ /* Fall through */
case AF_INET:
case AF_INET6: {
- ret = fill_inet6_inet_identifiers (this,
- &this->myinfo.sockaddr,
- this->myinfo.sockaddr_len,
- this->myinfo.identifier);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_INET_ERROR,
- "can't fill inet/inet6 identifier for server");
- goto err;
- }
-
- ret = fill_inet6_inet_identifiers (this,
- &this->peerinfo.sockaddr,
- this->peerinfo.sockaddr_len,
- this->peerinfo.identifier);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_INET_ERROR,
- "can't fill inet/inet6 identifier for client");
- goto err;
- }
+ ret = fill_inet6_inet_identifiers(this, &this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len,
+ this->myinfo.identifier);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_INET_ERROR,
+ "can't fill inet/inet6 identifier for server");
+ goto err;
+ }
+
+ ret = fill_inet6_inet_identifiers(this, &this->peerinfo.sockaddr,
+ this->peerinfo.sockaddr_len,
+ this->peerinfo.identifier);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_INET_ERROR,
+ "can't fill inet/inet6 identifier for client");
+ goto err;
+ }
- if (is_inet_sdp) {
- ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP;
- }
- }
- break;
+ if (is_inet_sdp) {
+ ((struct sockaddr *)&this->peerinfo.sockaddr)
+ ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr)
+ ->sa_family = AF_INET_SDP;
+ }
+ } break;
- case AF_UNIX:
- {
- struct sockaddr_un *sunaddr = NULL;
+ case AF_UNIX: {
+ struct sockaddr_un *sunaddr = NULL;
- sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr;
- strcpy (this->myinfo.identifier, sunaddr->sun_path);
+ sunaddr = (struct sockaddr_un *)&this->myinfo.sockaddr;
+ strcpy(this->myinfo.identifier, sunaddr->sun_path);
- sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr;
- strcpy (this->peerinfo.identifier, sunaddr->sun_path);
- }
- break;
+ sunaddr = (struct sockaddr_un *)&this->peerinfo.sockaddr;
+ strcpy(this->peerinfo.identifier, sunaddr->sun_path);
+ } break;
default:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- TRANS_MSG_UNKNOWN_ADDR_FAMILY,
- "unknown address family (%d)",
- ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family);
- ret = -1;
- break;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, TRANS_MSG_UNKNOWN_ADDR_FAMILY,
+ "unknown address family (%d)",
+ ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family);
+ ret = -1;
+ break;
+ }
err:
- return ret;
+ return ret;
}
diff --git a/rpc/rpc-transport/rdma/src/rdma.c b/rpc/rpc-transport/rdma/src/rdma.c
index f1859a73bdf..92c9ce95929 100644
--- a/rpc/rpc-transport/rdma/src/rdma.c
+++ b/rpc/rpc-transport/rdma/src/rdma.c
@@ -24,1363 +24,1322 @@
#define GF_RDMA_LOG_NAME "rpc-transport/rdma"
static int32_t
-__gf_rdma_ioq_churn (gf_rdma_peer_t *peer);
+__gf_rdma_ioq_churn(gf_rdma_peer_t *peer);
gf_rdma_post_t *
-gf_rdma_post_ref (gf_rdma_post_t *post);
+gf_rdma_post_ref(gf_rdma_post_t *post);
int
-gf_rdma_post_unref (gf_rdma_post_t *post);
+gf_rdma_post_unref(gf_rdma_post_t *post);
static void *
-gf_rdma_send_completion_proc (void *data);
+gf_rdma_send_completion_proc(void *data);
static void *
-gf_rdma_recv_completion_proc (void *data);
+gf_rdma_recv_completion_proc(void *data);
void *
-gf_rdma_async_event_thread (void *context);
+gf_rdma_async_event_thread(void *context);
static int32_t
-gf_rdma_create_qp (rpc_transport_t *this);
+gf_rdma_create_qp(rpc_transport_t *this);
static int32_t
-__gf_rdma_teardown (rpc_transport_t *this);
+__gf_rdma_teardown(rpc_transport_t *this);
static int32_t
-gf_rdma_teardown (rpc_transport_t *this);
+gf_rdma_teardown(rpc_transport_t *this);
static int32_t
-gf_rdma_disconnect (rpc_transport_t *this, gf_boolean_t wait);
+gf_rdma_disconnect(rpc_transport_t *this, gf_boolean_t wait);
static void
-gf_rdma_cm_handle_disconnect (rpc_transport_t *this);
+gf_rdma_cm_handle_disconnect(rpc_transport_t *this);
static int
-gf_rdma_cm_handle_connect_init (struct rdma_cm_event *event);
+gf_rdma_cm_handle_connect_init(struct rdma_cm_event *event);
static void
-gf_rdma_put_post (gf_rdma_queue_t *queue, gf_rdma_post_t *post)
+gf_rdma_put_post(gf_rdma_queue_t *queue, gf_rdma_post_t *post)
{
- post->ctx.is_request = 0;
+ post->ctx.is_request = 0;
- pthread_mutex_lock (&queue->lock);
- {
- if (post->prev) {
- queue->active_count--;
- post->prev->next = post->next;
- }
-
- if (post->next) {
- post->next->prev = post->prev;
- }
+ pthread_mutex_lock(&queue->lock);
+ {
+ if (post->prev) {
+ queue->active_count--;
+ post->prev->next = post->next;
+ }
- post->prev = &queue->passive_posts;
- post->next = post->prev->next;
- post->prev->next = post;
- post->next->prev = post;
- queue->passive_count++;
+ if (post->next) {
+ post->next->prev = post->prev;
}
- pthread_mutex_unlock (&queue->lock);
-}
+ post->prev = &queue->passive_posts;
+ post->next = post->prev->next;
+ post->prev->next = post;
+ post->next->prev = post;
+ queue->passive_count++;
+ }
+ pthread_mutex_unlock(&queue->lock);
+}
static gf_rdma_post_t *
-gf_rdma_new_post (rpc_transport_t *this, gf_rdma_device_t *device, int32_t len,
- gf_rdma_post_type_t type)
+gf_rdma_new_post(rpc_transport_t *this, gf_rdma_device_t *device, int32_t len,
+ gf_rdma_post_type_t type)
{
- gf_rdma_post_t *post = NULL;
- int ret = -1;
+ gf_rdma_post_t *post = NULL;
+ int ret = -1;
- post = (gf_rdma_post_t *) GF_CALLOC (1, sizeof (*post),
- gf_common_mt_rdma_post_t);
- if (post == NULL) {
- goto out;
- }
+ post = (gf_rdma_post_t *)GF_CALLOC(1, sizeof(*post),
+ gf_common_mt_rdma_post_t);
+ if (post == NULL) {
+ goto out;
+ }
- pthread_mutex_init (&post->lock, NULL);
+ pthread_mutex_init(&post->lock, NULL);
- post->buf_size = len;
+ post->buf_size = len;
- post->buf = valloc (len);
- if (!post->buf) {
- gf_msg_nomem (GF_RDMA_LOG_NAME, GF_LOG_ERROR, len);
- goto out;
- }
+ post->buf = valloc(len);
+ if (!post->buf) {
+ gf_msg_nomem(GF_RDMA_LOG_NAME, GF_LOG_ERROR, len);
+ goto out;
+ }
- post->mr = ibv_reg_mr (device->pd,
- post->buf,
- post->buf_size,
- IBV_ACCESS_LOCAL_WRITE);
- if (!post->mr) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_MR_ALOC_FAILED,
- "memory registration failed");
- goto out;
- }
+ post->mr = ibv_reg_mr(device->pd, post->buf, post->buf_size,
+ IBV_ACCESS_LOCAL_WRITE);
+ if (!post->mr) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_MR_ALOC_FAILED,
+ "memory registration failed");
+ goto out;
+ }
- post->device = device;
- post->type = type;
+ post->device = device;
+ post->type = type;
- ret = 0;
+ ret = 0;
out:
- if (ret != 0 && post) {
- free (post->buf);
+ if (ret != 0 && post) {
+ free(post->buf);
- GF_FREE (post);
- post = NULL;
- }
+ GF_FREE(post);
+ post = NULL;
+ }
- return post;
+ return post;
}
-
static gf_rdma_post_t *
-gf_rdma_get_post (gf_rdma_queue_t *queue)
+gf_rdma_get_post(gf_rdma_queue_t *queue)
{
- gf_rdma_post_t *post = NULL;
-
- pthread_mutex_lock (&queue->lock);
- {
- post = queue->passive_posts.next;
- if (post == &queue->passive_posts)
- post = NULL;
-
- if (post) {
- if (post->prev)
- post->prev->next = post->next;
- if (post->next)
- post->next->prev = post->prev;
- post->prev = &queue->active_posts;
- post->next = post->prev->next;
- post->prev->next = post;
- post->next->prev = post;
- post->reused++;
- queue->active_count++;
- }
- }
- pthread_mutex_unlock (&queue->lock);
-
- return post;
+ gf_rdma_post_t *post = NULL;
+
+ pthread_mutex_lock(&queue->lock);
+ {
+ post = queue->passive_posts.next;
+ if (post == &queue->passive_posts)
+ post = NULL;
+
+ if (post) {
+ if (post->prev)
+ post->prev->next = post->next;
+ if (post->next)
+ post->next->prev = post->prev;
+ post->prev = &queue->active_posts;
+ post->next = post->prev->next;
+ post->prev->next = post;
+ post->next->prev = post;
+ post->reused++;
+ queue->active_count++;
+ }
+ }
+ pthread_mutex_unlock(&queue->lock);
+
+ return post;
}
void
-gf_rdma_destroy_post (gf_rdma_post_t *post)
+gf_rdma_destroy_post(gf_rdma_post_t *post)
{
- ibv_dereg_mr (post->mr);
- free (post->buf);
- GF_FREE (post);
+ ibv_dereg_mr(post->mr);
+ free(post->buf);
+ GF_FREE(post);
}
-
static int32_t
-__gf_rdma_quota_get (gf_rdma_peer_t *peer)
+__gf_rdma_quota_get(gf_rdma_peer_t *peer)
{
- int32_t ret = -1;
- gf_rdma_private_t *priv = NULL;
+ int32_t ret = -1;
+ gf_rdma_private_t *priv = NULL;
- priv = peer->trans->private;
+ priv = peer->trans->private;
- if (priv->connected && peer->quota > 0) {
- ret = peer->quota--;
- }
+ if (priv->connected && peer->quota > 0) {
+ ret = peer->quota--;
+ }
- return ret;
+ return ret;
}
-
static void
-__gf_rdma_ioq_entry_free (gf_rdma_ioq_t *entry)
+__gf_rdma_ioq_entry_free(gf_rdma_ioq_t *entry)
{
- list_del_init (&entry->list);
+ list_del_init(&entry->list);
- if (entry->iobref) {
- iobref_unref (entry->iobref);
- entry->iobref = NULL;
- }
+ if (entry->iobref) {
+ iobref_unref(entry->iobref);
+ entry->iobref = NULL;
+ }
- if (entry->msg.request.rsp_iobref) {
- iobref_unref (entry->msg.request.rsp_iobref);
- entry->msg.request.rsp_iobref = NULL;
- }
+ if (entry->msg.request.rsp_iobref) {
+ iobref_unref(entry->msg.request.rsp_iobref);
+ entry->msg.request.rsp_iobref = NULL;
+ }
- mem_put (entry);
+ mem_put(entry);
}
-
static void
-__gf_rdma_ioq_flush (gf_rdma_peer_t *peer)
+__gf_rdma_ioq_flush(gf_rdma_peer_t *peer)
{
- gf_rdma_ioq_t *entry = NULL, *dummy = NULL;
+ gf_rdma_ioq_t *entry = NULL, *dummy = NULL;
- list_for_each_entry_safe (entry, dummy, &peer->ioq, list) {
- __gf_rdma_ioq_entry_free (entry);
- }
+ list_for_each_entry_safe(entry, dummy, &peer->ioq, list)
+ {
+ __gf_rdma_ioq_entry_free(entry);
+ }
}
-
static int32_t
-__gf_rdma_disconnect (rpc_transport_t *this)
+__gf_rdma_disconnect(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (priv->connected) {
- rdma_disconnect (priv->peer.cm_id);
- }
+ if (priv->connected) {
+ rdma_disconnect(priv->peer.cm_id);
+ }
- return 0;
+ return 0;
}
-
static void
-gf_rdma_queue_init (gf_rdma_queue_t *queue)
+gf_rdma_queue_init(gf_rdma_queue_t *queue)
{
- pthread_mutex_init (&queue->lock, NULL);
+ pthread_mutex_init(&queue->lock, NULL);
- queue->active_posts.next = &queue->active_posts;
- queue->active_posts.prev = &queue->active_posts;
- queue->passive_posts.next = &queue->passive_posts;
- queue->passive_posts.prev = &queue->passive_posts;
+ queue->active_posts.next = &queue->active_posts;
+ queue->active_posts.prev = &queue->active_posts;
+ queue->passive_posts.next = &queue->passive_posts;
+ queue->passive_posts.prev = &queue->passive_posts;
}
-
static void
-__gf_rdma_destroy_queue (gf_rdma_post_t *post)
+__gf_rdma_destroy_queue(gf_rdma_post_t *post)
{
- gf_rdma_post_t *tmp = NULL;
+ gf_rdma_post_t *tmp = NULL;
- while (post->next != post) {
- tmp = post->next;
+ while (post->next != post) {
+ tmp = post->next;
- post->next = post->next->next;
- post->next->prev = post;
+ post->next = post->next->next;
+ post->next->prev = post;
- gf_rdma_destroy_post (tmp);
- }
+ gf_rdma_destroy_post(tmp);
+ }
}
-
static void
-gf_rdma_destroy_queue (gf_rdma_queue_t *queue)
+gf_rdma_destroy_queue(gf_rdma_queue_t *queue)
{
- if (queue == NULL) {
- goto out;
- }
+ if (queue == NULL) {
+ goto out;
+ }
- pthread_mutex_lock (&queue->lock);
- {
- if (queue->passive_count > 0) {
- __gf_rdma_destroy_queue (&queue->passive_posts);
- queue->passive_count = 0;
- }
+ pthread_mutex_lock(&queue->lock);
+ {
+ if (queue->passive_count > 0) {
+ __gf_rdma_destroy_queue(&queue->passive_posts);
+ queue->passive_count = 0;
+ }
- if (queue->active_count > 0) {
- __gf_rdma_destroy_queue (&queue->active_posts);
- queue->active_count = 0;
- }
+ if (queue->active_count > 0) {
+ __gf_rdma_destroy_queue(&queue->active_posts);
+ queue->active_count = 0;
}
- pthread_mutex_unlock (&queue->lock);
+ }
+ pthread_mutex_unlock(&queue->lock);
out:
- return;
+ return;
}
-
static void
-gf_rdma_destroy_posts (rpc_transport_t *this)
+gf_rdma_destroy_posts(rpc_transport_t *this)
{
- gf_rdma_device_t *device = NULL;
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ gf_rdma_private_t *priv = NULL;
- if (this == NULL) {
- goto out;
- }
+ if (this == NULL) {
+ goto out;
+ }
- priv = this->private;
- device = priv->device;
+ priv = this->private;
+ device = priv->device;
- gf_rdma_destroy_queue (&device->sendq);
- gf_rdma_destroy_queue (&device->recvq);
+ gf_rdma_destroy_queue(&device->sendq);
+ gf_rdma_destroy_queue(&device->recvq);
out:
- return;
+ return;
}
-
static int32_t
-__gf_rdma_create_posts (rpc_transport_t *this, int32_t count, int32_t size,
- gf_rdma_queue_t *q, gf_rdma_post_type_t type)
+__gf_rdma_create_posts(rpc_transport_t *this, int32_t count, int32_t size,
+ gf_rdma_queue_t *q, gf_rdma_post_type_t type)
{
- int32_t i = 0;
- int32_t ret = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
-
- priv = this->private;
- device = priv->device;
-
- for (i = 0 ; i < count ; i++) {
- gf_rdma_post_t *post = NULL;
-
- post = gf_rdma_new_post (this, device, size + 2048, type);
- if (!post) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_POST_CREATION_FAILED,
- "post creation failed");
- ret = -1;
- break;
- }
+ int32_t i = 0;
+ int32_t ret = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+
+ priv = this->private;
+ device = priv->device;
- gf_rdma_put_post (q, post);
+ for (i = 0; i < count; i++) {
+ gf_rdma_post_t *post = NULL;
+
+ post = gf_rdma_new_post(this, device, size + 2048, type);
+ if (!post) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_POST_CREATION_FAILED,
+ "post creation failed");
+ ret = -1;
+ break;
}
- return ret;
-}
+ gf_rdma_put_post(q, post);
+ }
+ return ret;
+}
static int32_t
-gf_rdma_post_recv (struct ibv_srq *srq,
- gf_rdma_post_t *post)
+gf_rdma_post_recv(struct ibv_srq *srq, gf_rdma_post_t *post)
{
- struct ibv_sge list = {
- .addr = (unsigned long) post->buf,
- .length = post->buf_size,
- .lkey = post->mr->lkey
- };
+ struct ibv_sge list = {.addr = (unsigned long)post->buf,
+ .length = post->buf_size,
+ .lkey = post->mr->lkey};
- struct ibv_recv_wr wr = {
- .wr_id = (unsigned long) post,
- .sg_list = &list,
- .num_sge = 1,
- }, *bad_wr;
+ struct ibv_recv_wr wr =
+ {
+ .wr_id = (unsigned long)post,
+ .sg_list = &list,
+ .num_sge = 1,
+ },
+ *bad_wr;
- gf_rdma_post_ref (post);
+ gf_rdma_post_ref(post);
- return ibv_post_srq_recv (srq, &wr, &bad_wr);
+ return ibv_post_srq_recv(srq, &wr, &bad_wr);
}
static void
-gf_rdma_deregister_iobuf_pool (gf_rdma_device_t *device)
+gf_rdma_deregister_iobuf_pool(gf_rdma_device_t *device)
{
+ gf_rdma_arena_mr *arena_mr = NULL;
+ gf_rdma_arena_mr *tmp = NULL;
- gf_rdma_arena_mr *arena_mr = NULL;
- gf_rdma_arena_mr *tmp = NULL;
-
- while (device) {
- pthread_mutex_lock (&device->all_mr_lock);
+ while (device) {
+ pthread_mutex_lock(&device->all_mr_lock);
+ {
+ if (!list_empty(&device->all_mr)) {
+ list_for_each_entry_safe(arena_mr, tmp, &device->all_mr, list)
{
- if (!list_empty(&device->all_mr)) {
- list_for_each_entry_safe (arena_mr, tmp,
- &device->all_mr, list) {
- if (ibv_dereg_mr(arena_mr->mr)) {
- gf_msg ("rdma", GF_LOG_WARNING, 0,
- RDMA_MSG_DEREGISTER_ARENA_FAILED,
- "deallocation of memory region "
- "failed");
- pthread_mutex_unlock (&device->all_mr_lock);
- return;
- }
- list_del(&arena_mr->list);
- GF_FREE(arena_mr);
- }
- }
+ if (ibv_dereg_mr(arena_mr->mr)) {
+ gf_msg("rdma", GF_LOG_WARNING, 0,
+ RDMA_MSG_DEREGISTER_ARENA_FAILED,
+ "deallocation of memory region "
+ "failed");
+ pthread_mutex_unlock(&device->all_mr_lock);
+ return;
+ }
+ list_del(&arena_mr->list);
+ GF_FREE(arena_mr);
}
- pthread_mutex_unlock (&device->all_mr_lock);
-
- device = device->next;
+ }
}
+ pthread_mutex_unlock(&device->all_mr_lock);
+
+ device = device->next;
+ }
}
int
-gf_rdma_deregister_arena (struct list_head **mr_list,
- struct iobuf_arena *iobuf_arena)
+gf_rdma_deregister_arena(struct list_head **mr_list,
+ struct iobuf_arena *iobuf_arena)
{
- gf_rdma_arena_mr *tmp = NULL;
- gf_rdma_arena_mr *dummy = NULL;
- gf_rdma_device_t *device = NULL;
- int count = 0, i = 0;
-
- count = iobuf_arena->iobuf_pool->rdma_device_count;
- for (i = 0; i < count; i++) {
- device = iobuf_arena->iobuf_pool->device[i];
- pthread_mutex_lock (&device->all_mr_lock);
- {
- list_for_each_entry_safe (tmp, dummy, mr_list[i], list) {
- if (tmp->iobuf_arena == iobuf_arena) {
- if (ibv_dereg_mr(tmp->mr)) {
- gf_msg ("rdma", GF_LOG_WARNING, 0,
- RDMA_MSG_DEREGISTER_ARENA_FAILED,
- "deallocation of memory region "
- "failed");
- pthread_mutex_unlock (&device->all_mr_lock);
- return -1;
- }
- list_del(&tmp->list);
- GF_FREE(tmp);
- break;
- }
- }
+ gf_rdma_arena_mr *tmp = NULL;
+ gf_rdma_arena_mr *dummy = NULL;
+ gf_rdma_device_t *device = NULL;
+ int count = 0, i = 0;
+
+ count = iobuf_arena->iobuf_pool->rdma_device_count;
+ for (i = 0; i < count; i++) {
+ device = iobuf_arena->iobuf_pool->device[i];
+ pthread_mutex_lock(&device->all_mr_lock);
+ {
+ list_for_each_entry_safe(tmp, dummy, mr_list[i], list)
+ {
+ if (tmp->iobuf_arena == iobuf_arena) {
+ if (ibv_dereg_mr(tmp->mr)) {
+ gf_msg("rdma", GF_LOG_WARNING, 0,
+ RDMA_MSG_DEREGISTER_ARENA_FAILED,
+ "deallocation of memory region "
+ "failed");
+ pthread_mutex_unlock(&device->all_mr_lock);
+ return -1;
+ }
+ list_del(&tmp->list);
+ GF_FREE(tmp);
+ break;
}
- pthread_mutex_unlock (&device->all_mr_lock);
+ }
}
+ pthread_mutex_unlock(&device->all_mr_lock);
+ }
- return 0;
+ return 0;
}
-
int
-gf_rdma_register_arena (void **arg1, void *arg2)
+gf_rdma_register_arena(void **arg1, void *arg2)
{
- struct ibv_mr *mr = NULL;
- gf_rdma_arena_mr *new = NULL;
- struct iobuf_pool *iobuf_pool = NULL;
- gf_rdma_device_t **device = (gf_rdma_device_t **)arg1;
- struct iobuf_arena *iobuf_arena = arg2;
- int count = 0, i = 0;
-
- iobuf_pool = iobuf_arena->iobuf_pool;
- count = iobuf_pool->rdma_device_count;
- for (i = 0; i < count; i++) {
- new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr),
- gf_common_mt_rdma_arena_mr);
- if (new == NULL) {
- gf_msg ("rdma", GF_LOG_INFO, ENOMEM,
- RDMA_MSG_MR_ALOC_FAILED, "Out of "
- "memory: registering pre allocated buffer "
- "with rdma device failed.");
- return -1;
- }
- INIT_LIST_HEAD (&new->list);
- new->iobuf_arena = iobuf_arena;
-
- mr = ibv_reg_mr(device[i]->pd, iobuf_arena->mem_base,
- iobuf_arena->arena_size,
- IBV_ACCESS_REMOTE_READ |
- IBV_ACCESS_LOCAL_WRITE |
- IBV_ACCESS_REMOTE_WRITE
- );
- if (!mr)
- gf_msg ("rdma", GF_LOG_WARNING, 0,
- RDMA_MSG_MR_ALOC_FAILED, "allocation of mr "
- "failed");
-
- new->mr = mr;
- pthread_mutex_lock (&device[i]->all_mr_lock);
- {
- list_add (&new->list, &device[i]->all_mr);
- }
- pthread_mutex_unlock (&device[i]->all_mr_lock);
- new = NULL;
+ struct ibv_mr *mr = NULL;
+ gf_rdma_arena_mr *new = NULL;
+ struct iobuf_pool *iobuf_pool = NULL;
+ gf_rdma_device_t **device = (gf_rdma_device_t **)arg1;
+ struct iobuf_arena *iobuf_arena = arg2;
+ int count = 0, i = 0;
+
+ iobuf_pool = iobuf_arena->iobuf_pool;
+ count = iobuf_pool->rdma_device_count;
+ for (i = 0; i < count; i++) {
+ new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr),
+ gf_common_mt_rdma_arena_mr);
+ if (new == NULL) {
+ gf_msg("rdma", GF_LOG_INFO, ENOMEM, RDMA_MSG_MR_ALOC_FAILED,
+ "Out of "
+ "memory: registering pre allocated buffer "
+ "with rdma device failed.");
+ return -1;
+ }
+ INIT_LIST_HEAD(&new->list);
+ new->iobuf_arena = iobuf_arena;
+
+ mr = ibv_reg_mr(device[i]->pd, iobuf_arena->mem_base,
+ iobuf_arena->arena_size,
+ IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE |
+ IBV_ACCESS_REMOTE_WRITE);
+ if (!mr)
+ gf_msg("rdma", GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED,
+ "allocation of mr "
+ "failed");
+
+ new->mr = mr;
+ pthread_mutex_lock(&device[i]->all_mr_lock);
+ {
+ list_add(&new->list, &device[i]->all_mr);
}
+ pthread_mutex_unlock(&device[i]->all_mr_lock);
+ new = NULL;
+ }
- return 0;
-
+ return 0;
}
static void
-gf_rdma_register_iobuf_pool (gf_rdma_device_t *device,
- struct iobuf_pool *iobuf_pool)
+gf_rdma_register_iobuf_pool(gf_rdma_device_t *device,
+ struct iobuf_pool *iobuf_pool)
{
- struct iobuf_arena *tmp = NULL;
- struct iobuf_arena *dummy = NULL;
- struct ibv_mr *mr = NULL;
- gf_rdma_arena_mr *new = NULL;
-
- if (!list_empty(&iobuf_pool->all_arenas)) {
-
- list_for_each_entry_safe (tmp, dummy, &iobuf_pool->all_arenas,
- all_list) {
- new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr),
- gf_common_mt_rdma_arena_mr);
- if (new == NULL) {
- gf_msg ("rdma", GF_LOG_INFO, ENOMEM,
- RDMA_MSG_MR_ALOC_FAILED, "Out of "
- "memory: registering pre allocated "
- "buffer with rdma device failed.");
- return;
- }
- INIT_LIST_HEAD (&new->list);
- new->iobuf_arena = tmp;
-
- mr = ibv_reg_mr(device->pd, tmp->mem_base,
- tmp->arena_size,
- IBV_ACCESS_REMOTE_READ |
- IBV_ACCESS_LOCAL_WRITE |
- IBV_ACCESS_REMOTE_WRITE);
- if (!mr) {
- gf_msg ("rdma", GF_LOG_WARNING, 0,
- RDMA_MSG_MR_ALOC_FAILED, "failed"
- " to pre register buffers with rdma "
- "devices.");
-
- }
- new->mr = mr;
- pthread_mutex_lock (&device->all_mr_lock);
- {
- list_add (&new->list, &device->all_mr);
- }
- pthread_mutex_unlock (&device->all_mr_lock);
+ struct iobuf_arena *tmp = NULL;
+ struct iobuf_arena *dummy = NULL;
+ struct ibv_mr *mr = NULL;
+ gf_rdma_arena_mr *new = NULL;
- new = NULL;
- }
- }
-
- return;
+ if (!list_empty(&iobuf_pool->all_arenas)) {
+ list_for_each_entry_safe(tmp, dummy, &iobuf_pool->all_arenas, all_list)
+ {
+ new = GF_CALLOC(1, sizeof(gf_rdma_arena_mr),
+ gf_common_mt_rdma_arena_mr);
+ if (new == NULL) {
+ gf_msg("rdma", GF_LOG_INFO, ENOMEM, RDMA_MSG_MR_ALOC_FAILED,
+ "Out of "
+ "memory: registering pre allocated "
+ "buffer with rdma device failed.");
+ return;
+ }
+ INIT_LIST_HEAD(&new->list);
+ new->iobuf_arena = tmp;
+
+ mr = ibv_reg_mr(device->pd, tmp->mem_base, tmp->arena_size,
+ IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE |
+ IBV_ACCESS_REMOTE_WRITE);
+ if (!mr) {
+ gf_msg("rdma", GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED,
+ "failed"
+ " to pre register buffers with rdma "
+ "devices.");
+ }
+ new->mr = mr;
+ pthread_mutex_lock(&device->all_mr_lock);
+ {
+ list_add(&new->list, &device->all_mr);
+ }
+ pthread_mutex_unlock(&device->all_mr_lock);
+
+ new = NULL;
+ }
+ }
+
+ return;
}
static void
-gf_rdma_register_iobuf_pool_with_device (gf_rdma_device_t *device,
- struct iobuf_pool *iobuf_pool)
+gf_rdma_register_iobuf_pool_with_device(gf_rdma_device_t *device,
+ struct iobuf_pool *iobuf_pool)
{
- while (device) {
- gf_rdma_register_iobuf_pool (device, iobuf_pool);
- device = device->next;
- }
+ while (device) {
+ gf_rdma_register_iobuf_pool(device, iobuf_pool);
+ device = device->next;
+ }
}
-static struct ibv_mr*
+static struct ibv_mr *
gf_rdma_get_pre_registred_mr(rpc_transport_t *this, void *ptr, int size)
{
- gf_rdma_arena_mr *tmp = NULL;
- gf_rdma_arena_mr *dummy = NULL;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
-
- priv = this->private;
- device = priv->device;
-
- pthread_mutex_lock (&device->all_mr_lock);
- {
- if (!list_empty(&device->all_mr)) {
- list_for_each_entry_safe (tmp, dummy, &device->all_mr, list) {
- if (tmp->iobuf_arena->mem_base <= ptr &&
- ptr < tmp->iobuf_arena->mem_base +
- tmp->iobuf_arena->arena_size) {
- pthread_mutex_unlock (&device->all_mr_lock);
- return tmp->mr;
- }
- }
+ gf_rdma_arena_mr *tmp = NULL;
+ gf_rdma_arena_mr *dummy = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+
+ priv = this->private;
+ device = priv->device;
+
+ pthread_mutex_lock(&device->all_mr_lock);
+ {
+ if (!list_empty(&device->all_mr)) {
+ list_for_each_entry_safe(tmp, dummy, &device->all_mr, list)
+ {
+ if (tmp->iobuf_arena->mem_base <= ptr &&
+ ptr < tmp->iobuf_arena->mem_base +
+ tmp->iobuf_arena->arena_size) {
+ pthread_mutex_unlock(&device->all_mr_lock);
+ return tmp->mr;
}
+ }
}
- pthread_mutex_unlock (&device->all_mr_lock);
+ }
+ pthread_mutex_unlock(&device->all_mr_lock);
- return NULL;
+ return NULL;
}
static int32_t
-gf_rdma_create_posts (rpc_transport_t *this)
+gf_rdma_create_posts(rpc_transport_t *this)
{
- int32_t i = 0, ret = 0;
- gf_rdma_post_t *post = NULL;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_options_t *options = NULL;
- gf_rdma_device_t *device = NULL;
-
- priv = this->private;
- options = &priv->options;
- device = priv->device;
-
- ret = __gf_rdma_create_posts (this, options->send_count,
- options->send_size,
- &device->sendq, GF_RDMA_SEND_POST);
- if (!ret)
- ret = __gf_rdma_create_posts (this, options->recv_count,
- options->recv_size,
- &device->recvq,
- GF_RDMA_RECV_POST);
-
- if (!ret) {
- for (i = 0 ; i < options->recv_count ; i++) {
- post = gf_rdma_get_post (&device->recvq);
- if (gf_rdma_post_recv (device->srq, post) != 0) {
- ret = -1;
- break;
- }
- }
+ int32_t i = 0, ret = 0;
+ gf_rdma_post_t *post = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_options_t *options = NULL;
+ gf_rdma_device_t *device = NULL;
+
+ priv = this->private;
+ options = &priv->options;
+ device = priv->device;
+
+ ret = __gf_rdma_create_posts(this, options->send_count, options->send_size,
+ &device->sendq, GF_RDMA_SEND_POST);
+ if (!ret)
+ ret = __gf_rdma_create_posts(this, options->recv_count,
+ options->recv_size, &device->recvq,
+ GF_RDMA_RECV_POST);
+
+ if (!ret) {
+ for (i = 0; i < options->recv_count; i++) {
+ post = gf_rdma_get_post(&device->recvq);
+ if (gf_rdma_post_recv(device->srq, post) != 0) {
+ ret = -1;
+ break;
+ }
}
+ }
- if (ret)
- gf_rdma_destroy_posts (this);
+ if (ret)
+ gf_rdma_destroy_posts(this);
- return ret;
+ return ret;
}
-
static void
-gf_rdma_destroy_cq (rpc_transport_t *this)
+gf_rdma_destroy_cq(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
- priv = this->private;
- device = priv->device;
+ priv = this->private;
+ device = priv->device;
- if (device->recv_cq)
- ibv_destroy_cq (device->recv_cq);
- device->recv_cq = NULL;
+ if (device->recv_cq)
+ ibv_destroy_cq(device->recv_cq);
+ device->recv_cq = NULL;
- if (device->send_cq)
- ibv_destroy_cq (device->send_cq);
- device->send_cq = NULL;
+ if (device->send_cq)
+ ibv_destroy_cq(device->send_cq);
+ device->send_cq = NULL;
- return;
+ return;
}
-
static int32_t
-gf_rdma_create_cq (rpc_transport_t *this)
+gf_rdma_create_cq(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_options_t *options = NULL;
- gf_rdma_device_t *device = NULL;
- uint64_t send_cqe = 0;
- int32_t ret = 0;
- struct ibv_device_attr device_attr = {{0}, };
-
- priv = this->private;
- options = &priv->options;
- device = priv->device;
-
- device->recv_cq = ibv_create_cq (priv->device->context,
- options->recv_count * 2,
- device,
- device->recv_chan,
- 0);
- if (!device->recv_cq) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_CQ_CREATION_FAILED, "creation of CQ for "
- "device %s failed", device->device_name);
- ret = -1;
- goto out;
- } else if (ibv_req_notify_cq (device->recv_cq, 0)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_REQ_NOTIFY_CQ_REVQ_FAILED, "ibv_req_notify_"
- "cq on recv CQ of device %s failed",
- device->device_name);
- ret = -1;
- goto out;
- }
-
- do {
- ret = ibv_query_device (priv->device->context, &device_attr);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_QUERY_DEVICE_FAILED, "ibv_query_"
- "device on %s returned %d (%s)",
- priv->device->device_name, ret,
- (ret > 0) ? strerror (ret) : "");
- ret = -1;
- goto out;
- }
-
- send_cqe = (uint64_t)options->send_count * 128;
- send_cqe = (send_cqe > device_attr.max_cqe)
- ? device_attr.max_cqe : send_cqe;
-
- /* TODO: make send_cq size dynamically adaptive */
- device->send_cq = ibv_create_cq (priv->device->context,
- send_cqe, device,
- device->send_chan, 0);
- if (!device->send_cq) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_CQ_CREATION_FAILED,
- "creation of send_cq "
- "for device %s failed", device->device_name);
- ret = -1;
- goto out;
- }
-
- if (ibv_req_notify_cq (device->send_cq, 0)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_REQ_NOTIFY_CQ_SENDQ_FAILED,
- "ibv_req_notify_cq on send_cq for device %s"
- " failed", device->device_name);
- ret = -1;
- goto out;
- }
- } while (0);
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_options_t *options = NULL;
+ gf_rdma_device_t *device = NULL;
+ uint64_t send_cqe = 0;
+ int32_t ret = 0;
+ struct ibv_device_attr device_attr = {
+ {0},
+ };
+
+ priv = this->private;
+ options = &priv->options;
+ device = priv->device;
+
+ device->recv_cq = ibv_create_cq(priv->device->context,
+ options->recv_count * 2, device,
+ device->recv_chan, 0);
+ if (!device->recv_cq) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED,
+ "creation of CQ for "
+ "device %s failed",
+ device->device_name);
+ ret = -1;
+ goto out;
+ } else if (ibv_req_notify_cq(device->recv_cq, 0)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_REQ_NOTIFY_CQ_REVQ_FAILED,
+ "ibv_req_notify_"
+ "cq on recv CQ of device %s failed",
+ device->device_name);
+ ret = -1;
+ goto out;
+ }
+
+ do {
+ ret = ibv_query_device(priv->device->context, &device_attr);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_QUERY_DEVICE_FAILED,
+ "ibv_query_"
+ "device on %s returned %d (%s)",
+ priv->device->device_name, ret,
+ (ret > 0) ? strerror(ret) : "");
+ ret = -1;
+ goto out;
+ }
+
+ send_cqe = (uint64_t)options->send_count * 128;
+ send_cqe = (send_cqe > device_attr.max_cqe) ? device_attr.max_cqe
+ : send_cqe;
+
+ /* TODO: make send_cq size dynamically adaptive */
+ device->send_cq = ibv_create_cq(priv->device->context, send_cqe, device,
+ device->send_chan, 0);
+ if (!device->send_cq) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED,
+ "creation of send_cq "
+ "for device %s failed",
+ device->device_name);
+ ret = -1;
+ goto out;
+ }
+
+ if (ibv_req_notify_cq(device->send_cq, 0)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ RDMA_MSG_REQ_NOTIFY_CQ_SENDQ_FAILED,
+ "ibv_req_notify_cq on send_cq for device %s"
+ " failed",
+ device->device_name);
+ ret = -1;
+ goto out;
+ }
+ } while (0);
out:
- if (ret != 0)
- gf_rdma_destroy_cq (this);
+ if (ret != 0)
+ gf_rdma_destroy_cq(this);
- return ret;
+ return ret;
}
-
static gf_rdma_device_t *
-gf_rdma_get_device (rpc_transport_t *this, struct ibv_context *ibctx,
- char *device_name)
+gf_rdma_get_device(rpc_transport_t *this, struct ibv_context *ibctx,
+ char *device_name)
{
- glusterfs_ctx_t *ctx = NULL;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_options_t *options = NULL;
- int32_t ret = 0;
- int32_t i = 0;
- gf_rdma_device_t *trav = NULL, *device = NULL;
- gf_rdma_ctx_t *rdma_ctx = NULL;
- struct iobuf_pool *iobuf_pool = NULL;
-
- priv = this->private;
- options = &priv->options;
- ctx = this->ctx;
- rdma_ctx = ctx->ib;
- iobuf_pool = ctx->iobuf_pool;
-
- trav = rdma_ctx->device;
-
- while (trav) {
- if (!strcmp (trav->device_name, device_name))
- break;
- trav = trav->next;
- }
-
- if (!trav) {
- trav = GF_CALLOC (1, sizeof (*trav),
- gf_common_mt_rdma_device_t);
- if (trav == NULL) {
- goto out;
- }
- priv->device = trav;
- trav->context = ibctx;
-
- trav->next = rdma_ctx->device;
- rdma_ctx->device = trav;
-
- iobuf_pool->device[iobuf_pool->rdma_device_count] = trav;
- iobuf_pool->mr_list[iobuf_pool->rdma_device_count++] = &trav->all_mr;
- trav->request_ctx_pool
- = mem_pool_new (gf_rdma_request_context_t,
- GF_RDMA_POOL_SIZE);
- if (trav->request_ctx_pool == NULL) {
- goto out;
- }
+ glusterfs_ctx_t *ctx = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_options_t *options = NULL;
+ int32_t ret = 0;
+ int32_t i = 0;
+ gf_rdma_device_t *trav = NULL, *device = NULL;
+ gf_rdma_ctx_t *rdma_ctx = NULL;
+ struct iobuf_pool *iobuf_pool = NULL;
- trav->ioq_pool
- = mem_pool_new (gf_rdma_ioq_t, GF_RDMA_POOL_SIZE);
- if (trav->ioq_pool == NULL) {
- goto out;
- }
-
- trav->reply_info_pool = mem_pool_new (gf_rdma_reply_info_t,
- GF_RDMA_POOL_SIZE);
- if (trav->reply_info_pool == NULL) {
- goto out;
- }
+ priv = this->private;
+ options = &priv->options;
+ ctx = this->ctx;
+ rdma_ctx = ctx->ib;
+ iobuf_pool = ctx->iobuf_pool;
- trav->device_name = gf_strdup (device_name);
+ trav = rdma_ctx->device;
- trav->send_chan = ibv_create_comp_channel (trav->context);
- if (!trav->send_chan) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_SEND_COMP_CHAN_FAILED, "could not "
- "create send completion channel for "
- "device (%s)", device_name);
- goto out;
- }
-
- trav->recv_chan = ibv_create_comp_channel (trav->context);
- if (!trav->recv_chan) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_RECV_COMP_CHAN_FAILED, "could not "
- "create recv completion channel for "
- "device (%s)", device_name);
-
- /* TODO: cleanup current mess */
- goto out;
- }
-
- if (gf_rdma_create_cq (this) < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_CQ_CREATION_FAILED,
- "could not create CQ for device (%s)",
- device_name);
- goto out;
- }
-
- /* protection domain */
- trav->pd = ibv_alloc_pd (trav->context);
-
- if (!trav->pd) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_ALOC_PROT_DOM_FAILED, "could not "
- "allocate protection domain for device (%s)",
- device_name);
- goto out;
- }
+ while (trav) {
+ if (!strcmp(trav->device_name, device_name))
+ break;
+ trav = trav->next;
+ }
- struct ibv_srq_init_attr attr = {
- .attr = {
- .max_wr = options->recv_count,
- .max_sge = 1,
- .srq_limit = 10
- }
- };
- trav->srq = ibv_create_srq (trav->pd, &attr);
-
- if (!trav->srq) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_CRE_SRQ_FAILED, "could not create SRQ"
- " for device (%s)",
- device_name);
- goto out;
- }
-
- /* queue init */
- gf_rdma_queue_init (&trav->sendq);
- gf_rdma_queue_init (&trav->recvq);
-
- INIT_LIST_HEAD (&trav->all_mr);
- pthread_mutex_init (&trav->all_mr_lock, NULL);
- gf_rdma_register_iobuf_pool(trav, iobuf_pool);
-
- if (gf_rdma_create_posts (this) < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_ALOC_POST_FAILED, "could not allocate"
- "posts for device (%s)", device_name);
- goto out;
- }
-
- /* completion threads */
- ret = gf_thread_create (&trav->send_thread, NULL,
- gf_rdma_send_completion_proc,
- trav->send_chan, "rdmascom");
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_SEND_COMP_THREAD_FAILED,
- "could not create send completion thread for "
- "device (%s)", device_name);
- goto out;
- }
-
- ret = gf_thread_create (&trav->recv_thread, NULL,
- gf_rdma_recv_completion_proc,
- trav->recv_chan, "rdmarcom");
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_RECV_COMP_THREAD_FAILED,
- "could not create recv completion thread "
- "for device (%s)", device_name);
- return NULL;
- }
-
- ret = gf_thread_create (&trav->async_event_thread, NULL,
- gf_rdma_async_event_thread,
- ibctx, "rdmaAsyn");
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- RDMA_MSG_ASYNC_EVENT_THEAD_FAILED,
- "could not create async_event_thread");
- return NULL;
- }
-
- /* qpreg */
- pthread_mutex_init (&trav->qpreg.lock, NULL);
- for (i = 0; i < 42; i++) {
- trav->qpreg.ents[i].next = &trav->qpreg.ents[i];
- trav->qpreg.ents[i].prev = &trav->qpreg.ents[i];
- }
+ if (!trav) {
+ trav = GF_CALLOC(1, sizeof(*trav), gf_common_mt_rdma_device_t);
+ if (trav == NULL) {
+ goto out;
}
+ priv->device = trav;
+ trav->context = ibctx;
- device = trav;
- trav = NULL;
-out:
+ trav->next = rdma_ctx->device;
+ rdma_ctx->device = trav;
- if (trav != NULL) {
- rdma_ctx->device = trav->next;
- gf_rdma_destroy_posts (this);
- mem_pool_destroy (trav->ioq_pool);
- mem_pool_destroy (trav->request_ctx_pool);
- mem_pool_destroy (trav->reply_info_pool);
- if (trav->pd != NULL) {
- ibv_dealloc_pd (trav->pd);
- }
- gf_rdma_destroy_cq (this);
- ibv_destroy_comp_channel (trav->recv_chan);
- ibv_destroy_comp_channel (trav->send_chan);
- GF_FREE ((char *)trav->device_name);
- GF_FREE (trav);
+ iobuf_pool->device[iobuf_pool->rdma_device_count] = trav;
+ iobuf_pool->mr_list[iobuf_pool->rdma_device_count++] = &trav->all_mr;
+ trav->request_ctx_pool = mem_pool_new(gf_rdma_request_context_t,
+ GF_RDMA_POOL_SIZE);
+ if (trav->request_ctx_pool == NULL) {
+ goto out;
}
- return device;
-}
-
-
-static rpc_transport_t *
-gf_rdma_transport_new (rpc_transport_t *listener, struct rdma_cm_id *cm_id)
-{
- gf_rdma_private_t *listener_priv = NULL, *priv = NULL;
- rpc_transport_t *this = NULL, *new = NULL;
- gf_rdma_options_t *options = NULL;
- char *device_name = NULL;
-
- listener_priv = listener->private;
-
- this = GF_CALLOC (1, sizeof (rpc_transport_t),
- gf_common_mt_rpc_transport_t);
- if (this == NULL) {
- goto out;
+ trav->ioq_pool = mem_pool_new(gf_rdma_ioq_t, GF_RDMA_POOL_SIZE);
+ if (trav->ioq_pool == NULL) {
+ goto out;
}
- this->listener = listener;
-
- priv = GF_CALLOC (1, sizeof (gf_rdma_private_t),
- gf_common_mt_rdma_private_t);
- if (priv == NULL) {
- goto out;
+ trav->reply_info_pool = mem_pool_new(gf_rdma_reply_info_t,
+ GF_RDMA_POOL_SIZE);
+ if (trav->reply_info_pool == NULL) {
+ goto out;
}
- this->private = priv;
- priv->options = listener_priv->options;
-
- priv->listener = listener;
- priv->entity = GF_RDMA_SERVER;
-
- options = &priv->options;
+ trav->device_name = gf_strdup(device_name);
- this->ops = listener->ops;
- this->init = listener->init;
- this->fini = listener->fini;
- this->ctx = listener->ctx;
- this->name = gf_strdup (listener->name);
- this->notify = listener->notify;
- this->mydata = listener->mydata;
- this->xl = listener->xl;
-
- this->myinfo.sockaddr_len = sizeof (cm_id->route.addr.src_addr);
- memcpy (&this->myinfo.sockaddr, &cm_id->route.addr.src_addr,
- this->myinfo.sockaddr_len);
-
- this->peerinfo.sockaddr_len = sizeof (cm_id->route.addr.dst_addr);
- memcpy (&this->peerinfo.sockaddr, &cm_id->route.addr.dst_addr,
- this->peerinfo.sockaddr_len);
+ trav->send_chan = ibv_create_comp_channel(trav->context);
+ if (!trav->send_chan) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_SEND_COMP_CHAN_FAILED,
+ "could not "
+ "create send completion channel for "
+ "device (%s)",
+ device_name);
+ goto out;
+ }
- priv->peer.trans = this;
- gf_rdma_get_transport_identifiers (this);
+ trav->recv_chan = ibv_create_comp_channel(trav->context);
+ if (!trav->recv_chan) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_RECV_COMP_CHAN_FAILED,
+ "could not "
+ "create recv completion channel for "
+ "device (%s)",
+ device_name);
- device_name = (char *)ibv_get_device_name (cm_id->verbs->device);
- if (device_name == NULL) {
- gf_msg (listener->name, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_DEVICE_NAME_FAILED, "cannot get device "
- "name (peer:%s me:%s)", this->peerinfo.identifier,
- this->myinfo.identifier);
- goto out;
+ /* TODO: cleanup current mess */
+ goto out;
}
- priv->device = gf_rdma_get_device (this, cm_id->verbs,
- device_name);
- if (priv->device == NULL) {
- gf_msg (listener->name, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_IB_DEVICE_FAILED, "cannot get infiniband"
- " device %s (peer:%s me:%s)", device_name,
- this->peerinfo.identifier, this->myinfo.identifier);
- goto out;
+ if (gf_rdma_create_cq(this) < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CQ_CREATION_FAILED,
+ "could not create CQ for device (%s)", device_name);
+ goto out;
}
- priv->peer.send_count = options->send_count;
- priv->peer.recv_count = options->recv_count;
- priv->peer.send_size = options->send_size;
- priv->peer.recv_size = options->recv_size;
- priv->peer.cm_id = cm_id;
- INIT_LIST_HEAD (&priv->peer.ioq);
+ /* protection domain */
+ trav->pd = ibv_alloc_pd(trav->context);
- pthread_mutex_init (&priv->write_mutex, NULL);
- pthread_mutex_init (&priv->recv_mutex, NULL);
-
- cm_id->context = this;
-
- new = rpc_transport_ref (this);
- this = NULL;
-out:
- if (this != NULL) {
- if (this->private != NULL) {
- GF_FREE (this->private);
- }
+ if (!trav->pd) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_ALOC_PROT_DOM_FAILED,
+ "could not "
+ "allocate protection domain for device (%s)",
+ device_name);
+ goto out;
+ }
- if (this->name != NULL) {
- GF_FREE (this->name);
- }
+ struct ibv_srq_init_attr attr = {.attr = {.max_wr = options->recv_count,
+ .max_sge = 1,
+ .srq_limit = 10}};
+ trav->srq = ibv_create_srq(trav->pd, &attr);
- GF_FREE (this);
+ if (!trav->srq) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_CRE_SRQ_FAILED,
+ "could not create SRQ"
+ " for device (%s)",
+ device_name);
+ goto out;
}
- return new;
-}
+ /* queue init */
+ gf_rdma_queue_init(&trav->sendq);
+ gf_rdma_queue_init(&trav->recvq);
+ INIT_LIST_HEAD(&trav->all_mr);
+ pthread_mutex_init(&trav->all_mr_lock, NULL);
+ gf_rdma_register_iobuf_pool(trav, iobuf_pool);
-static int
-gf_rdma_cm_handle_connect_request (struct rdma_cm_event *event)
-{
- int ret = -1;
- rpc_transport_t *this = NULL, *listener = NULL;
- struct rdma_cm_id *child_cm_id = NULL, *listener_cm_id = NULL;
- struct rdma_conn_param conn_param = {0, };
- gf_rdma_private_t *priv = NULL;
- gf_rdma_options_t *options = NULL;
-
- child_cm_id = event->id;
- listener_cm_id = event->listen_id;
-
- listener = listener_cm_id->context;
- priv = listener->private;
- options = &priv->options;
-
- this = gf_rdma_transport_new (listener, child_cm_id);
- if (this == NULL) {
- gf_msg (listener->name, GF_LOG_WARNING, 0,
- RDMA_MSG_CREAT_INC_TRANS_FAILED, "could not create "
- "a transport for incoming connection"
- " (me.name:%s me.identifier:%s)", listener->name,
- listener->myinfo.identifier);
- rdma_destroy_id (child_cm_id);
- goto out;
+ if (gf_rdma_create_posts(this) < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, RDMA_MSG_ALOC_POST_FAILED,
+ "could not allocate"
+ "posts for device (%s)",
+ device_name);
+ goto out;
}
- gf_msg_trace (listener->name, 0, "got a connect request (me:%s peer:"
- "%s)", listener->myinfo.identifier,
- this->peerinfo.identifier);
+ /* completion threads */
+ ret = gf_thread_create(&trav->send_thread, NULL,
+ gf_rdma_send_completion_proc, trav->send_chan,
+ "rdmascom");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ RDMA_MSG_SEND_COMP_THREAD_FAILED,
+ "could not create send completion thread for "
+ "device (%s)",
+ device_name);
+ goto out;
+ }
- ret = gf_rdma_create_qp (this);
- if (ret < 0) {
- gf_msg (listener->name, GF_LOG_WARNING, 0,
- RDMA_MSG_CREAT_QP_FAILED, "could not create QP "
- "(peer:%s me:%s)", this->peerinfo.identifier,
- this->myinfo.identifier);
- gf_rdma_cm_handle_disconnect (this);
- goto out;
+ ret = gf_thread_create(&trav->recv_thread, NULL,
+ gf_rdma_recv_completion_proc, trav->recv_chan,
+ "rdmarcom");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ RDMA_MSG_RECV_COMP_THREAD_FAILED,
+ "could not create recv completion thread "
+ "for device (%s)",
+ device_name);
+ return NULL;
}
- conn_param.responder_resources = 1;
- conn_param.initiator_depth = 1;
- conn_param.retry_count = options->attr_retry_cnt;
- conn_param.rnr_retry_count = options->attr_rnr_retry;
+ ret = gf_thread_create(&trav->async_event_thread, NULL,
+ gf_rdma_async_event_thread, ibctx, "rdmaAsyn");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ RDMA_MSG_ASYNC_EVENT_THEAD_FAILED,
+ "could not create async_event_thread");
+ return NULL;
+ }
- ret = rdma_accept(child_cm_id, &conn_param);
- if (ret < 0) {
- gf_msg (listener->name, GF_LOG_WARNING, errno,
- RDMA_MSG_ACCEPT_FAILED, "rdma_accept failed peer:%s "
- "me:%s", this->peerinfo.identifier,
- this->myinfo.identifier);
- gf_rdma_cm_handle_disconnect (this);
- goto out;
+ /* qpreg */
+ pthread_mutex_init(&trav->qpreg.lock, NULL);
+ for (i = 0; i < 42; i++) {
+ trav->qpreg.ents[i].next = &trav->qpreg.ents[i];
+ trav->qpreg.ents[i].prev = &trav->qpreg.ents[i];
}
- gf_rdma_cm_handle_connect_init (event);
- ret = 0;
+ }
+ device = trav;
+ trav = NULL;
out:
- return ret;
-}
+ if (trav != NULL) {
+ rdma_ctx->device = trav->next;
+ gf_rdma_destroy_posts(this);
+ mem_pool_destroy(trav->ioq_pool);
+ mem_pool_destroy(trav->request_ctx_pool);
+ mem_pool_destroy(trav->reply_info_pool);
+ if (trav->pd != NULL) {
+ ibv_dealloc_pd(trav->pd);
+ }
+ gf_rdma_destroy_cq(this);
+ ibv_destroy_comp_channel(trav->recv_chan);
+ ibv_destroy_comp_channel(trav->send_chan);
+ GF_FREE((char *)trav->device_name);
+ GF_FREE(trav);
+ }
+
+ return device;
+}
-static int
-gf_rdma_cm_handle_route_resolved (struct rdma_cm_event *event)
+static rpc_transport_t *
+gf_rdma_transport_new(rpc_transport_t *listener, struct rdma_cm_id *cm_id)
{
- struct rdma_conn_param conn_param = {0, };
- int ret = 0;
- rpc_transport_t *this = NULL;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_peer_t *peer = NULL;
- gf_rdma_options_t *options = NULL;
-
- if (event == NULL) {
- goto out;
+ gf_rdma_private_t *listener_priv = NULL, *priv = NULL;
+ rpc_transport_t *this = NULL, *new = NULL;
+ gf_rdma_options_t *options = NULL;
+ char *device_name = NULL;
+
+ listener_priv = listener->private;
+
+ this = GF_CALLOC(1, sizeof(rpc_transport_t), gf_common_mt_rpc_transport_t);
+ if (this == NULL) {
+ goto out;
+ }
+
+ this->listener = listener;
+
+ priv = GF_CALLOC(1, sizeof(gf_rdma_private_t), gf_common_mt_rdma_private_t);
+ if (priv == NULL) {
+ goto out;
+ }
+
+ this->private = priv;
+ priv->options = listener_priv->options;
+
+ priv->listener = listener;
+ priv->entity = GF_RDMA_SERVER;
+
+ options = &priv->options;
+
+ this->ops = listener->ops;
+ this->init = listener->init;
+ this->fini = listener->fini;
+ this->ctx = listener->ctx;
+ this->name = gf_strdup(listener->name);
+ this->notify = listener->notify;
+ this->mydata = listener->mydata;
+ this->xl = listener->xl;
+
+ this->myinfo.sockaddr_len = sizeof(cm_id->route.addr.src_addr);
+ memcpy(&this->myinfo.sockaddr, &cm_id->route.addr.src_addr,
+ this->myinfo.sockaddr_len);
+
+ this->peerinfo.sockaddr_len = sizeof(cm_id->route.addr.dst_addr);
+ memcpy(&this->peerinfo.sockaddr, &cm_id->route.addr.dst_addr,
+ this->peerinfo.sockaddr_len);
+
+ priv->peer.trans = this;
+ gf_rdma_get_transport_identifiers(this);
+
+ device_name = (char *)ibv_get_device_name(cm_id->verbs->device);
+ if (device_name == NULL) {
+ gf_msg(listener->name, GF_LOG_WARNING, 0,
+ RDMA_MSG_GET_DEVICE_NAME_FAILED,
+ "cannot get device "
+ "name (peer:%s me:%s)",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ goto out;
+ }
+
+ priv->device = gf_rdma_get_device(this, cm_id->verbs, device_name);
+ if (priv->device == NULL) {
+ gf_msg(listener->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_IB_DEVICE_FAILED,
+ "cannot get infiniband"
+ " device %s (peer:%s me:%s)",
+ device_name, this->peerinfo.identifier, this->myinfo.identifier);
+ goto out;
+ }
+
+ priv->peer.send_count = options->send_count;
+ priv->peer.recv_count = options->recv_count;
+ priv->peer.send_size = options->send_size;
+ priv->peer.recv_size = options->recv_size;
+ priv->peer.cm_id = cm_id;
+ INIT_LIST_HEAD(&priv->peer.ioq);
+
+ pthread_mutex_init(&priv->write_mutex, NULL);
+ pthread_mutex_init(&priv->recv_mutex, NULL);
+
+ cm_id->context = this;
+
+ new = rpc_transport_ref(this);
+ this = NULL;
+out:
+ if (this != NULL) {
+ if (this->private != NULL) {
+ GF_FREE(this->private);
}
- this = event->id->context;
-
- priv = this->private;
- peer = &priv->peer;
- options = &priv->options;
-
- ret = gf_rdma_create_qp (this);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_CREAT_QP_FAILED, "could not create QP "
- "(peer:%s me:%s)", this->peerinfo.identifier,
- this->myinfo.identifier);
- gf_rdma_cm_handle_disconnect (this);
- goto out;
+ if (this->name != NULL) {
+ GF_FREE(this->name);
}
- memset(&conn_param, 0, sizeof conn_param);
- conn_param.responder_resources = 1;
- conn_param.initiator_depth = 1;
- conn_param.retry_count = options->attr_retry_cnt;
- conn_param.rnr_retry_count = options->attr_rnr_retry;
+ GF_FREE(this);
+ }
- ret = rdma_connect(peer->cm_id, &conn_param);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_CONNECT_FAILED,
- "rdma_connect failed");
- gf_rdma_cm_handle_disconnect (this);
- goto out;
- }
+ return new;
+}
- gf_msg_trace (this->name, 0, "route resolved (me:%s peer:%s)",
- this->myinfo.identifier, this->peerinfo.identifier);
+static int
+gf_rdma_cm_handle_connect_request(struct rdma_cm_event *event)
+{
+ int ret = -1;
+ rpc_transport_t *this = NULL, *listener = NULL;
+ struct rdma_cm_id *child_cm_id = NULL, *listener_cm_id = NULL;
+ struct rdma_conn_param conn_param = {
+ 0,
+ };
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_options_t *options = NULL;
+
+ child_cm_id = event->id;
+ listener_cm_id = event->listen_id;
+
+ listener = listener_cm_id->context;
+ priv = listener->private;
+ options = &priv->options;
+
+ this = gf_rdma_transport_new(listener, child_cm_id);
+ if (this == NULL) {
+ gf_msg(listener->name, GF_LOG_WARNING, 0,
+ RDMA_MSG_CREAT_INC_TRANS_FAILED,
+ "could not create "
+ "a transport for incoming connection"
+ " (me.name:%s me.identifier:%s)",
+ listener->name, listener->myinfo.identifier);
+ rdma_destroy_id(child_cm_id);
+ goto out;
+ }
+
+ gf_msg_trace(listener->name, 0,
+ "got a connect request (me:%s peer:"
+ "%s)",
+ listener->myinfo.identifier, this->peerinfo.identifier);
+
+ ret = gf_rdma_create_qp(this);
+ if (ret < 0) {
+ gf_msg(listener->name, GF_LOG_WARNING, 0, RDMA_MSG_CREAT_QP_FAILED,
+ "could not create QP "
+ "(peer:%s me:%s)",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ gf_rdma_cm_handle_disconnect(this);
+ goto out;
+ }
+
+ conn_param.responder_resources = 1;
+ conn_param.initiator_depth = 1;
+ conn_param.retry_count = options->attr_retry_cnt;
+ conn_param.rnr_retry_count = options->attr_rnr_retry;
+
+ ret = rdma_accept(child_cm_id, &conn_param);
+ if (ret < 0) {
+ gf_msg(listener->name, GF_LOG_WARNING, errno, RDMA_MSG_ACCEPT_FAILED,
+ "rdma_accept failed peer:%s "
+ "me:%s",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ gf_rdma_cm_handle_disconnect(this);
+ goto out;
+ }
+ gf_rdma_cm_handle_connect_init(event);
+ ret = 0;
- ret = 0;
out:
- return ret;
+ return ret;
}
+static int
+gf_rdma_cm_handle_route_resolved(struct rdma_cm_event *event)
+{
+ struct rdma_conn_param conn_param = {
+ 0,
+ };
+ int ret = 0;
+ rpc_transport_t *this = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ gf_rdma_options_t *options = NULL;
+
+ if (event == NULL) {
+ goto out;
+ }
+
+ this = event->id->context;
+
+ priv = this->private;
+ peer = &priv->peer;
+ options = &priv->options;
+
+ ret = gf_rdma_create_qp(this);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_CREAT_QP_FAILED,
+ "could not create QP "
+ "(peer:%s me:%s)",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ gf_rdma_cm_handle_disconnect(this);
+ goto out;
+ }
+
+ memset(&conn_param, 0, sizeof conn_param);
+ conn_param.responder_resources = 1;
+ conn_param.initiator_depth = 1;
+ conn_param.retry_count = options->attr_retry_cnt;
+ conn_param.rnr_retry_count = options->attr_rnr_retry;
+
+ ret = rdma_connect(peer->cm_id, &conn_param);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_CONNECT_FAILED,
+ "rdma_connect failed");
+ gf_rdma_cm_handle_disconnect(this);
+ goto out;
+ }
+
+ gf_msg_trace(this->name, 0, "route resolved (me:%s peer:%s)",
+ this->myinfo.identifier, this->peerinfo.identifier);
+
+ ret = 0;
+out:
+ return ret;
+}
static int
-gf_rdma_cm_handle_addr_resolved (struct rdma_cm_event *event)
+gf_rdma_cm_handle_addr_resolved(struct rdma_cm_event *event)
{
- rpc_transport_t *this = NULL;
- gf_rdma_peer_t *peer = NULL;
- gf_rdma_private_t *priv = NULL;
- int ret = 0;
+ rpc_transport_t *this = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ gf_rdma_private_t *priv = NULL;
+ int ret = 0;
- this = event->id->context;
+ this = event->id->context;
- priv = this->private;
- peer = &priv->peer;
+ priv = this->private;
+ peer = &priv->peer;
- GF_ASSERT (peer->cm_id == event->id);
+ GF_ASSERT(peer->cm_id == event->id);
- this->myinfo.sockaddr_len = sizeof (peer->cm_id->route.addr.src_addr);
- memcpy (&this->myinfo.sockaddr, &peer->cm_id->route.addr.src_addr,
- this->myinfo.sockaddr_len);
+ this->myinfo.sockaddr_len = sizeof(peer->cm_id->route.addr.src_addr);
+ memcpy(&this->myinfo.sockaddr, &peer->cm_id->route.addr.src_addr,
+ this->myinfo.sockaddr_len);
- this->peerinfo.sockaddr_len = sizeof (peer->cm_id->route.addr.dst_addr);
- memcpy (&this->peerinfo.sockaddr, &peer->cm_id->route.addr.dst_addr,
- this->peerinfo.sockaddr_len);
+ this->peerinfo.sockaddr_len = sizeof(peer->cm_id->route.addr.dst_addr);
+ memcpy(&this->peerinfo.sockaddr, &peer->cm_id->route.addr.dst_addr,
+ this->peerinfo.sockaddr_len);
- gf_rdma_get_transport_identifiers (this);
+ gf_rdma_get_transport_identifiers(this);
- ret = rdma_resolve_route(peer->cm_id, 2000);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_ROUTE_RESOLVE_FAILED, "rdma_resolve_route "
- "failed (me:%s peer:%s)",
- this->myinfo.identifier, this->peerinfo.identifier);
- gf_rdma_cm_handle_disconnect (this);
- return ret;
- }
+ ret = rdma_resolve_route(peer->cm_id, 2000);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_ROUTE_RESOLVE_FAILED,
+ "rdma_resolve_route "
+ "failed (me:%s peer:%s)",
+ this->myinfo.identifier, this->peerinfo.identifier);
+ gf_rdma_cm_handle_disconnect(this);
+ return ret;
+ }
- gf_msg_trace (this->name, 0, "Address resolved (me:%s peer:%s)",
- this->myinfo.identifier, this->peerinfo.identifier);
+ gf_msg_trace(this->name, 0, "Address resolved (me:%s peer:%s)",
+ this->myinfo.identifier, this->peerinfo.identifier);
- return ret;
+ return ret;
}
-
static void
-gf_rdma_cm_handle_disconnect (rpc_transport_t *this)
+gf_rdma_cm_handle_disconnect(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- char need_unref = 0;
+ gf_rdma_private_t *priv = NULL;
+ char need_unref = 0;
- priv = this->private;
- gf_msg_debug (this->name, 0, "peer disconnected, cleaning up");
+ priv = this->private;
+ gf_msg_debug(this->name, 0, "peer disconnected, cleaning up");
- pthread_mutex_lock (&priv->write_mutex);
- {
- if (priv->peer.cm_id != NULL) {
- need_unref = 1;
- priv->connected = 0;
- }
-
- __gf_rdma_teardown (this);
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ if (priv->peer.cm_id != NULL) {
+ need_unref = 1;
+ priv->connected = 0;
}
- pthread_mutex_unlock (&priv->write_mutex);
- rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, this);
+ __gf_rdma_teardown(this);
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
- if (need_unref)
- rpc_transport_unref (this);
+ rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, this);
+ if (need_unref)
+ rpc_transport_unref(this);
}
-
static int
-gf_rdma_cm_handle_connect_init (struct rdma_cm_event *event)
+gf_rdma_cm_handle_connect_init(struct rdma_cm_event *event)
{
- rpc_transport_t *this = NULL;
- gf_rdma_private_t *priv = NULL;
- struct rdma_cm_id *cm_id = NULL;
- int ret = 0;
-
- cm_id = event->id;
- this = cm_id->context;
- priv = this->private;
-
- if (priv->connected == 1) {
- gf_msg_trace (this->name, 0, "received event "
- "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)",
- this->myinfo.identifier,
- this->peerinfo.identifier);
- return ret;
- }
+ rpc_transport_t *this = NULL;
+ gf_rdma_private_t *priv = NULL;
+ struct rdma_cm_id *cm_id = NULL;
+ int ret = 0;
+
+ cm_id = event->id;
+ this = cm_id->context;
+ priv = this->private;
+
+ if (priv->connected == 1) {
+ gf_msg_trace(this->name, 0,
+ "received event "
+ "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)",
+ this->myinfo.identifier, this->peerinfo.identifier);
+ return ret;
+ }
- priv->connected = 1;
+ priv->connected = 1;
- pthread_mutex_lock (&priv->write_mutex);
- {
- priv->peer.quota = 1;
- priv->peer.quota_set = 0;
- }
- pthread_mutex_unlock (&priv->write_mutex);
-
- if (priv->entity == GF_RDMA_CLIENT) {
- gf_msg_trace (this->name, 0, "received event "
- "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)",
- this->myinfo.identifier,
- this->peerinfo.identifier);
- ret = rpc_transport_notify (this, RPC_TRANSPORT_CONNECT, this);
-
- } else if (priv->entity == GF_RDMA_SERVER) {
- ret = rpc_transport_notify (priv->listener,
- RPC_TRANSPORT_ACCEPT, this);
- }
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ priv->peer.quota = 1;
+ priv->peer.quota_set = 0;
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
- if (ret < 0) {
- gf_rdma_disconnect (this, _gf_false);
- }
+ if (priv->entity == GF_RDMA_CLIENT) {
+ gf_msg_trace(this->name, 0,
+ "received event "
+ "RDMA_CM_EVENT_ESTABLISHED (me:%s peer:%s)",
+ this->myinfo.identifier, this->peerinfo.identifier);
+ ret = rpc_transport_notify(this, RPC_TRANSPORT_CONNECT, this);
- return ret;
-}
+ } else if (priv->entity == GF_RDMA_SERVER) {
+ ret = rpc_transport_notify(priv->listener, RPC_TRANSPORT_ACCEPT, this);
+ }
+
+ if (ret < 0) {
+ gf_rdma_disconnect(this, _gf_false);
+ }
+ return ret;
+}
static int
-gf_rdma_cm_handle_event_error (rpc_transport_t *this)
+gf_rdma_cm_handle_event_error(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (priv->entity != GF_RDMA_SERVER_LISTENER) {
- gf_rdma_cm_handle_disconnect (this);
- }
+ if (priv->entity != GF_RDMA_SERVER_LISTENER) {
+ gf_rdma_cm_handle_disconnect(this);
+ }
- return 0;
+ return 0;
}
-
static int
-gf_rdma_cm_handle_device_removal (struct rdma_cm_event *event)
+gf_rdma_cm_handle_device_removal(struct rdma_cm_event *event)
{
- return 0;
+ return 0;
}
-
static void *
-gf_rdma_cm_event_handler (void *data)
+gf_rdma_cm_event_handler(void *data)
{
- struct rdma_cm_event *event = NULL;
- int ret = 0;
- rpc_transport_t *this = NULL;
- struct rdma_event_channel *event_channel = NULL;
-
- event_channel = data;
-
- while (1) {
- ret = rdma_get_cm_event (event_channel, &event);
- if (ret != 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_CM_EVENT_FAILED,
- "rdma_cm_get_event failed");
- break;
- }
+ struct rdma_cm_event *event = NULL;
+ int ret = 0;
+ rpc_transport_t *this = NULL;
+ struct rdma_event_channel *event_channel = NULL;
- switch (event->event) {
- case RDMA_CM_EVENT_ADDR_RESOLVED:
- gf_rdma_cm_handle_addr_resolved (event);
- break;
+ event_channel = data;
- case RDMA_CM_EVENT_ROUTE_RESOLVED:
- gf_rdma_cm_handle_route_resolved (event);
- break;
+ while (1) {
+ ret = rdma_get_cm_event(event_channel, &event);
+ if (ret != 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_CM_EVENT_FAILED, "rdma_cm_get_event failed");
+ break;
+ }
- case RDMA_CM_EVENT_CONNECT_REQUEST:
- gf_rdma_cm_handle_connect_request (event);
- break;
+ switch (event->event) {
+ case RDMA_CM_EVENT_ADDR_RESOLVED:
+ gf_rdma_cm_handle_addr_resolved(event);
+ break;
- case RDMA_CM_EVENT_ESTABLISHED:
- gf_rdma_cm_handle_connect_init (event);
- break;
+ case RDMA_CM_EVENT_ROUTE_RESOLVED:
+ gf_rdma_cm_handle_route_resolved(event);
+ break;
- case RDMA_CM_EVENT_ADDR_ERROR:
- case RDMA_CM_EVENT_ROUTE_ERROR:
- case RDMA_CM_EVENT_CONNECT_ERROR:
- case RDMA_CM_EVENT_UNREACHABLE:
- case RDMA_CM_EVENT_REJECTED:
- this = event->id->context;
-
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_CM_EVENT_FAILED, "cma event %s, "
- "error %d (me:%s peer:%s)\n",
- rdma_event_str(event->event), event->status,
- this->myinfo.identifier,
- this->peerinfo.identifier);
-
- rdma_ack_cm_event (event);
- event = NULL;
-
- gf_rdma_cm_handle_event_error (this);
- continue;
-
- case RDMA_CM_EVENT_DISCONNECTED:
- this = event->id->context;
-
- gf_msg_debug (this->name, 0, "received disconnect "
- "(me:%s peer:%s)\n",
- this->myinfo.identifier,
- this->peerinfo.identifier);
-
- rdma_ack_cm_event (event);
- event = NULL;
-
- gf_rdma_cm_handle_disconnect (this);
- continue;
-
- case RDMA_CM_EVENT_DEVICE_REMOVAL:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CM_EVENT_FAILED, "device "
- "removed");
- gf_rdma_cm_handle_device_removal (event);
- break;
+ case RDMA_CM_EVENT_CONNECT_REQUEST:
+ gf_rdma_cm_handle_connect_request(event);
+ break;
- default:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CM_EVENT_FAILED,
- "unhandled event: %s, ignoring",
- rdma_event_str(event->event));
- break;
- }
+ case RDMA_CM_EVENT_ESTABLISHED:
+ gf_rdma_cm_handle_connect_init(event);
+ break;
- rdma_ack_cm_event (event);
+ case RDMA_CM_EVENT_ADDR_ERROR:
+ case RDMA_CM_EVENT_ROUTE_ERROR:
+ case RDMA_CM_EVENT_CONNECT_ERROR:
+ case RDMA_CM_EVENT_UNREACHABLE:
+ case RDMA_CM_EVENT_REJECTED:
+ this = event->id->context;
+
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_CM_EVENT_FAILED,
+ "cma event %s, "
+ "error %d (me:%s peer:%s)\n",
+ rdma_event_str(event->event), event->status,
+ this->myinfo.identifier, this->peerinfo.identifier);
+
+ rdma_ack_cm_event(event);
+ event = NULL;
+
+ gf_rdma_cm_handle_event_error(this);
+ continue;
+
+ case RDMA_CM_EVENT_DISCONNECTED:
+ this = event->id->context;
+
+ gf_msg_debug(this->name, 0,
+ "received disconnect "
+ "(me:%s peer:%s)\n",
+ this->myinfo.identifier,
+ this->peerinfo.identifier);
+
+ rdma_ack_cm_event(event);
+ event = NULL;
+
+ gf_rdma_cm_handle_disconnect(this);
+ continue;
+
+ case RDMA_CM_EVENT_DEVICE_REMOVAL:
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CM_EVENT_FAILED,
+ "device "
+ "removed");
+ gf_rdma_cm_handle_device_removal(event);
+ break;
+
+ default:
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CM_EVENT_FAILED,
+ "unhandled event: %s, ignoring",
+ rdma_event_str(event->event));
+ break;
}
- return NULL;
-}
+ rdma_ack_cm_event(event);
+ }
+ return NULL;
+}
static int32_t
-gf_rdma_post_send (struct ibv_qp *qp, gf_rdma_post_t *post, int32_t len)
+gf_rdma_post_send(struct ibv_qp *qp, gf_rdma_post_t *post, int32_t len)
{
- struct ibv_sge list = {
- .addr = (unsigned long) post->buf,
- .length = len,
- .lkey = post->mr->lkey
- };
-
- struct ibv_send_wr wr = {
- .wr_id = (unsigned long) post,
- .sg_list = &list,
- .num_sge = 1,
- .opcode = IBV_WR_SEND,
- .send_flags = IBV_SEND_SIGNALED,
- }, *bad_wr;
-
- if (!qp)
- return EINVAL;
-
- return ibv_post_send (qp, &wr, &bad_wr);
+ struct ibv_sge list = {.addr = (unsigned long)post->buf,
+ .length = len,
+ .lkey = post->mr->lkey};
+
+ struct ibv_send_wr wr =
+ {
+ .wr_id = (unsigned long)post,
+ .sg_list = &list,
+ .num_sge = 1,
+ .opcode = IBV_WR_SEND,
+ .send_flags = IBV_SEND_SIGNALED,
+ },
+ *bad_wr;
+
+ if (!qp)
+ return EINVAL;
+
+ return ibv_post_send(qp, &wr, &bad_wr);
}
int
@@ -1388,1945 +1347,1853 @@ __gf_rdma_encode_error(gf_rdma_peer_t *peer, gf_rdma_reply_info_t *reply_info,
struct iovec *rpchdr, gf_rdma_header_t *hdr,
gf_rdma_errcode_t err)
{
- struct rpc_msg *rpc_msg = NULL;
-
- if (reply_info != NULL) {
- hdr->rm_xid = hton32(reply_info->rm_xid);
- } else {
- rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains
- * only one vector.
- * (which is true)
- */
- hdr->rm_xid = rpc_msg->rm_xid;
- }
-
- hdr->rm_vers = hton32(GF_RDMA_VERSION);
- hdr->rm_credit = hton32(peer->send_count);
- hdr->rm_type = hton32(GF_RDMA_ERROR);
- hdr->rm_body.rm_error.rm_type = hton32(err);
- if (err == ERR_VERS) {
- hdr->rm_body.rm_error.rm_version.gf_rdma_vers_low
- = hton32(GF_RDMA_VERSION);
- hdr->rm_body.rm_error.rm_version.gf_rdma_vers_high
- = hton32(GF_RDMA_VERSION);
- }
-
- return sizeof (*hdr);
+ struct rpc_msg *rpc_msg = NULL;
+
+ if (reply_info != NULL) {
+ hdr->rm_xid = hton32(reply_info->rm_xid);
+ } else {
+ rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains
+ * only one vector.
+ * (which is true)
+ */
+ hdr->rm_xid = rpc_msg->rm_xid;
+ }
+
+ hdr->rm_vers = hton32(GF_RDMA_VERSION);
+ hdr->rm_credit = hton32(peer->send_count);
+ hdr->rm_type = hton32(GF_RDMA_ERROR);
+ hdr->rm_body.rm_error.rm_type = hton32(err);
+ if (err == ERR_VERS) {
+ hdr->rm_body.rm_error.rm_version.gf_rdma_vers_low = hton32(
+ GF_RDMA_VERSION);
+ hdr->rm_body.rm_error.rm_version.gf_rdma_vers_high = hton32(
+ GF_RDMA_VERSION);
+ }
+
+ return sizeof(*hdr);
}
-
int32_t
-__gf_rdma_send_error (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post, gf_rdma_reply_info_t *reply_info,
- gf_rdma_errcode_t err)
+__gf_rdma_send_error(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post, gf_rdma_reply_info_t *reply_info,
+ gf_rdma_errcode_t err)
{
- int32_t ret = -1, len = 0;
-
- len = __gf_rdma_encode_error (peer, reply_info, entry->rpchdr,
- (gf_rdma_header_t *)post->buf, err);
- if (len == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0,
- RDMA_MSG_ENCODE_ERROR, "encode error returned -1");
- goto out;
- }
-
- gf_rdma_post_ref (post);
-
- ret = gf_rdma_post_send (peer->qp, post, len);
- if (!ret) {
- ret = len;
- } else {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_SEND_FAILED,
- "gf_rdma_post_send (to %s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- gf_rdma_post_unref (post);
- __gf_rdma_disconnect (peer->trans);
- ret = -1;
- }
+ int32_t ret = -1, len = 0;
+
+ len = __gf_rdma_encode_error(peer, reply_info, entry->rpchdr,
+ (gf_rdma_header_t *)post->buf, err);
+ if (len == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0, RDMA_MSG_ENCODE_ERROR,
+ "encode error returned -1");
+ goto out;
+ }
+
+ gf_rdma_post_ref(post);
+
+ ret = gf_rdma_post_send(peer->qp, post, len);
+ if (!ret) {
+ ret = len;
+ } else {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED,
+ "gf_rdma_post_send (to %s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ gf_rdma_post_unref(post);
+ __gf_rdma_disconnect(peer->trans);
+ ret = -1;
+ }
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_create_read_chunks_from_vector (gf_rdma_peer_t *peer,
- gf_rdma_read_chunk_t **readch_ptr,
- int32_t *pos, struct iovec *vector,
- int count,
- gf_rdma_request_context_t *request_ctx)
+__gf_rdma_create_read_chunks_from_vector(gf_rdma_peer_t *peer,
+ gf_rdma_read_chunk_t **readch_ptr,
+ int32_t *pos, struct iovec *vector,
+ int count,
+ gf_rdma_request_context_t *request_ctx)
{
- int i = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- struct ibv_mr *mr = NULL;
- gf_rdma_read_chunk_t *readch = NULL;
- int32_t ret = -1;
-
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, readch_ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, *readch_ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, request_ctx, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, vector, out);
-
- priv = peer->trans->private;
- device = priv->device;
- readch = *readch_ptr;
-
- for (i = 0; i < count; i++) {
- readch->rc_discrim = hton32 (1);
- readch->rc_position = hton32 (*pos);
-
- mr = gf_rdma_get_pre_registred_mr(peer->trans,
- (void *)vector[i].iov_base, vector[i].iov_len);
- if (!mr) {
- mr = ibv_reg_mr (device->pd, vector[i].iov_base,
- vector[i].iov_len,
- IBV_ACCESS_REMOTE_READ);
- }
- if (!mr) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_MR_ALOC_FAILED,
- "memory registration failed (peer:%s)",
- peer->trans->peerinfo.identifier);
- goto out;
- }
-
- request_ctx->mr[request_ctx->mr_count++] = mr;
-
- readch->rc_target.rs_handle = hton32 (mr->rkey);
- readch->rc_target.rs_length
- = hton32 (vector[i].iov_len);
- readch->rc_target.rs_offset
- = hton64 ((uint64_t)(unsigned long)vector[i].iov_base);
-
- *pos = *pos + vector[i].iov_len;
- readch++;
- }
-
- *readch_ptr = readch;
-
- ret = 0;
+ int i = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ struct ibv_mr *mr = NULL;
+ gf_rdma_read_chunk_t *readch = NULL;
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, readch_ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *readch_ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out);
+
+ priv = peer->trans->private;
+ device = priv->device;
+ readch = *readch_ptr;
+
+ for (i = 0; i < count; i++) {
+ readch->rc_discrim = hton32(1);
+ readch->rc_position = hton32(*pos);
+
+ mr = gf_rdma_get_pre_registred_mr(
+ peer->trans, (void *)vector[i].iov_base, vector[i].iov_len);
+ if (!mr) {
+ mr = ibv_reg_mr(device->pd, vector[i].iov_base, vector[i].iov_len,
+ IBV_ACCESS_REMOTE_READ);
+ }
+ if (!mr) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_MR_ALOC_FAILED,
+ "memory registration failed (peer:%s)",
+ peer->trans->peerinfo.identifier);
+ goto out;
+ }
+
+ request_ctx->mr[request_ctx->mr_count++] = mr;
+
+ readch->rc_target.rs_handle = hton32(mr->rkey);
+ readch->rc_target.rs_length = hton32(vector[i].iov_len);
+ readch->rc_target.rs_offset = hton64(
+ (uint64_t)(unsigned long)vector[i].iov_base);
+
+ *pos = *pos + vector[i].iov_len;
+ readch++;
+ }
+
+ *readch_ptr = readch;
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_create_read_chunks (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_chunktype_t type, uint32_t **ptr,
- gf_rdma_request_context_t *request_ctx)
+__gf_rdma_create_read_chunks(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_chunktype_t type, uint32_t **ptr,
+ gf_rdma_request_context_t *request_ctx)
{
- int32_t ret = -1;
- int pos = 0;
-
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, entry, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, *ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, request_ctx, out);
-
- request_ctx->iobref = iobref_ref (entry->iobref);
-
- if (type == gf_rdma_areadch) {
- pos = 0;
- ret = __gf_rdma_create_read_chunks_from_vector (peer,
- (gf_rdma_read_chunk_t **)ptr,
- &pos,
- entry->rpchdr,
- entry->rpchdr_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
- "cannot create read chunks from vector "
- "entry->rpchdr");
- goto out;
- }
+ int32_t ret = -1;
+ int pos = 0;
+
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out);
+
+ request_ctx->iobref = iobref_ref(entry->iobref);
+
+ if (type == gf_rdma_areadch) {
+ pos = 0;
+ ret = __gf_rdma_create_read_chunks_from_vector(
+ peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->rpchdr,
+ entry->rpchdr_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
+ "cannot create read chunks from vector "
+ "entry->rpchdr");
+ goto out;
+ }
- ret = __gf_rdma_create_read_chunks_from_vector (peer,
- (gf_rdma_read_chunk_t **)ptr,
- &pos,
- entry->proghdr,
- entry->proghdr_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
- "cannot create read chunks from vector "
- "entry->proghdr");
- }
+ ret = __gf_rdma_create_read_chunks_from_vector(
+ peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->proghdr,
+ entry->proghdr_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
+ "cannot create read chunks from vector "
+ "entry->proghdr");
+ }
- if (entry->prog_payload_count != 0) {
- ret = __gf_rdma_create_read_chunks_from_vector (peer,
- (gf_rdma_read_chunk_t **)ptr,
- &pos,
- entry->prog_payload,
- entry->prog_payload_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
- "cannot create read chunks from vector"
- " entry->prog_payload");
- }
- }
- } else {
- pos = iov_length (entry->rpchdr, entry->rpchdr_count);
- ret = __gf_rdma_create_read_chunks_from_vector (peer,
- (gf_rdma_read_chunk_t **)ptr,
- &pos,
- entry->prog_payload,
- entry->prog_payload_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
- "cannot create read chunks from vector "
- "entry->prog_payload");
- }
+ if (entry->prog_payload_count != 0) {
+ ret = __gf_rdma_create_read_chunks_from_vector(
+ peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->prog_payload,
+ entry->prog_payload_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
+ "cannot create read chunks from vector"
+ " entry->prog_payload");
+ }
+ }
+ } else {
+ pos = iov_length(entry->rpchdr, entry->rpchdr_count);
+ ret = __gf_rdma_create_read_chunks_from_vector(
+ peer, (gf_rdma_read_chunk_t **)ptr, &pos, entry->prog_payload,
+ entry->prog_payload_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_READ_CHUNK_VECTOR_FAILED,
+ "cannot create read chunks from vector "
+ "entry->prog_payload");
}
+ }
- /* terminate read-chunk list*/
- **ptr = 0;
- *ptr = *ptr + 1;
+ /* terminate read-chunk list*/
+ **ptr = 0;
+ *ptr = *ptr + 1;
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_create_write_chunks_from_vector (gf_rdma_peer_t *peer,
- gf_rdma_write_chunk_t **writech_ptr,
- struct iovec *vector, int count,
- gf_rdma_request_context_t *request_ctx)
+__gf_rdma_create_write_chunks_from_vector(
+ gf_rdma_peer_t *peer, gf_rdma_write_chunk_t **writech_ptr,
+ struct iovec *vector, int count, gf_rdma_request_context_t *request_ctx)
{
- int i = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- struct ibv_mr *mr = NULL;
- gf_rdma_write_chunk_t *writech = NULL;
- int32_t ret = -1;
+ int i = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ struct ibv_mr *mr = NULL;
+ gf_rdma_write_chunk_t *writech = NULL;
+ int32_t ret = -1;
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, writech_ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, *writech_ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, request_ctx, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, vector, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, writech_ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *writech_ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out);
- writech = *writech_ptr;
+ writech = *writech_ptr;
- priv = peer->trans->private;
- device = priv->device;
-
- for (i = 0; i < count; i++) {
+ priv = peer->trans->private;
+ device = priv->device;
- mr = gf_rdma_get_pre_registred_mr(peer->trans,
- (void *)vector[i].iov_base, vector[i].iov_len);
- if (!mr) {
- mr = ibv_reg_mr (device->pd, vector[i].iov_base,
- vector[i].iov_len,
- IBV_ACCESS_REMOTE_WRITE
- | IBV_ACCESS_LOCAL_WRITE);
- }
+ for (i = 0; i < count; i++) {
+ mr = gf_rdma_get_pre_registred_mr(
+ peer->trans, (void *)vector[i].iov_base, vector[i].iov_len);
+ if (!mr) {
+ mr = ibv_reg_mr(device->pd, vector[i].iov_base, vector[i].iov_len,
+ IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE);
+ }
- if (!mr) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_MR_ALOC_FAILED, "memory "
- "registration failed (peer:%s)",
- peer->trans->peerinfo.identifier);
- goto out;
- }
+ if (!mr) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_MR_ALOC_FAILED,
+ "memory "
+ "registration failed (peer:%s)",
+ peer->trans->peerinfo.identifier);
+ goto out;
+ }
- request_ctx->mr[request_ctx->mr_count++] = mr;
+ request_ctx->mr[request_ctx->mr_count++] = mr;
- writech->wc_target.rs_handle = hton32 (mr->rkey);
- writech->wc_target.rs_length = hton32 (vector[i].iov_len);
- writech->wc_target.rs_offset
- = hton64 (((uint64_t)(unsigned long)vector[i].iov_base));
+ writech->wc_target.rs_handle = hton32(mr->rkey);
+ writech->wc_target.rs_length = hton32(vector[i].iov_len);
+ writech->wc_target.rs_offset = hton64(
+ ((uint64_t)(unsigned long)vector[i].iov_base));
- writech++;
- }
+ writech++;
+ }
- *writech_ptr = writech;
+ *writech_ptr = writech;
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_create_write_chunks (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_chunktype_t chunk_type, uint32_t **ptr,
- gf_rdma_request_context_t *request_ctx)
+__gf_rdma_create_write_chunks(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_chunktype_t chunk_type, uint32_t **ptr,
+ gf_rdma_request_context_t *request_ctx)
{
- int32_t ret = -1;
- gf_rdma_write_array_t *warray = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, *ptr, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, request_ctx, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, entry, out);
-
- if ((chunk_type == gf_rdma_replych)
- && ((entry->msg.request.rsphdr_count != 1) ||
- (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_BUFFER_ERROR,
- (entry->msg.request.rsphdr_count == 1)
- ? "chunktype specified as reply chunk but the vector "
- "specifying the buffer to be used for holding reply"
- " header is not correct" :
- "chunktype specified as reply chunk, but more than one "
- "buffer provided for holding reply");
- goto out;
+ int32_t ret = -1;
+ gf_rdma_write_array_t *warray = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, *ptr, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, request_ctx, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out);
+
+ if ((chunk_type == gf_rdma_replych) &&
+ ((entry->msg.request.rsphdr_count != 1) ||
+ (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_BUFFER_ERROR,
+ (entry->msg.request.rsphdr_count == 1)
+ ? "chunktype specified as reply chunk but the vector "
+ "specifying the buffer to be used for holding reply"
+ " header is not correct"
+ : "chunktype specified as reply chunk, but more than one "
+ "buffer provided for holding reply");
+ goto out;
+ }
+
+ /*
+ if ((chunk_type == gf_rdma_writech)
+ && ((entry->msg.request.rsphdr_count == 0)
+ || (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) {
+ gf_msg_debug (GF_RDMA_LOG_NAME, 0,
+ "vector specifying buffer to hold the program's reply "
+ "header should also be provided when buffers are "
+ "provided for holding the program's payload in reply");
+ goto out;
+ }
+ */
+
+ if (chunk_type == gf_rdma_writech) {
+ warray = (gf_rdma_write_array_t *)*ptr;
+ warray->wc_discrim = hton32(1);
+ warray->wc_nchunks = hton32(entry->msg.request.rsp_payload_count);
+
+ *ptr = (uint32_t *)&warray->wc_array[0];
+
+ ret = __gf_rdma_create_write_chunks_from_vector(
+ peer, (gf_rdma_write_chunk_t **)ptr, entry->msg.request.rsp_payload,
+ entry->msg.request.rsp_payload_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED,
+ "cannot create write chunks from vector "
+ "entry->rpc_payload");
+ goto out;
}
-/*
- if ((chunk_type == gf_rdma_writech)
- && ((entry->msg.request.rsphdr_count == 0)
- || (entry->msg.request.rsphdr_vec[0].iov_base == NULL))) {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0,
- "vector specifying buffer to hold the program's reply "
- "header should also be provided when buffers are "
- "provided for holding the program's payload in reply");
- goto out;
- }
-*/
-
- if (chunk_type == gf_rdma_writech) {
- warray = (gf_rdma_write_array_t *)*ptr;
- warray->wc_discrim = hton32 (1);
- warray->wc_nchunks
- = hton32 (entry->msg.request.rsp_payload_count);
-
- *ptr = (uint32_t *)&warray->wc_array[0];
-
- ret = __gf_rdma_create_write_chunks_from_vector (peer,
- (gf_rdma_write_chunk_t **)ptr,
- entry->msg.request.rsp_payload,
- entry->msg.request.rsp_payload_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED,
- "cannot create write chunks from vector "
- "entry->rpc_payload");
- goto out;
- }
-
- /* terminate write chunklist */
- **ptr = 0;
- *ptr = *ptr + 1;
-
- /* no reply chunklist */
- **ptr = 0;
- *ptr = *ptr + 1;
- } else {
- /* no write chunklist */
- **ptr = 0;
- *ptr = *ptr + 1;
+ /* terminate write chunklist */
+ **ptr = 0;
+ *ptr = *ptr + 1;
- warray = (gf_rdma_write_array_t *)*ptr;
- warray->wc_discrim = hton32 (1);
- warray->wc_nchunks = hton32 (entry->msg.request.rsphdr_count);
+ /* no reply chunklist */
+ **ptr = 0;
+ *ptr = *ptr + 1;
+ } else {
+ /* no write chunklist */
+ **ptr = 0;
+ *ptr = *ptr + 1;
- *ptr = (uint32_t *)&warray->wc_array[0];
+ warray = (gf_rdma_write_array_t *)*ptr;
+ warray->wc_discrim = hton32(1);
+ warray->wc_nchunks = hton32(entry->msg.request.rsphdr_count);
- ret = __gf_rdma_create_write_chunks_from_vector (peer,
- (gf_rdma_write_chunk_t **)ptr,
- entry->msg.request.rsphdr_vec,
- entry->msg.request.rsphdr_count,
- request_ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED,
- "cannot create write chunks from vector "
- "entry->rpchdr");
- goto out;
- }
+ *ptr = (uint32_t *)&warray->wc_array[0];
- /* terminate reply chunklist */
- **ptr = 0;
- *ptr = *ptr + 1;
+ ret = __gf_rdma_create_write_chunks_from_vector(
+ peer, (gf_rdma_write_chunk_t **)ptr, entry->msg.request.rsphdr_vec,
+ entry->msg.request.rsphdr_count, request_ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_WRITE_CHUNK_VECTOR_FAILED,
+ "cannot create write chunks from vector "
+ "entry->rpchdr");
+ goto out;
}
+ /* terminate reply chunklist */
+ **ptr = 0;
+ *ptr = *ptr + 1;
+ }
+
out:
- return ret;
+ return ret;
}
-
static void
-__gf_rdma_deregister_mr (gf_rdma_device_t *device,
- struct ibv_mr **mr, int count)
+__gf_rdma_deregister_mr(gf_rdma_device_t *device, struct ibv_mr **mr, int count)
{
- gf_rdma_arena_mr *tmp = NULL;
- gf_rdma_arena_mr *dummy = NULL;
- int i = 0;
- int found = 0;
-
- if (mr == NULL) {
- goto out;
- }
-
- for (i = 0; i < count; i++) {
- found = 0;
- pthread_mutex_lock (&device->all_mr_lock);
- {
- if (!list_empty(&device->all_mr)) {
- list_for_each_entry_safe (tmp, dummy, &device->all_mr, list) {
- if (tmp->mr == mr[i]) {
- found = 1;
- break;
- }
- }
- }
+ gf_rdma_arena_mr *tmp = NULL;
+ gf_rdma_arena_mr *dummy = NULL;
+ int i = 0;
+ int found = 0;
+
+ if (mr == NULL) {
+ goto out;
+ }
+
+ for (i = 0; i < count; i++) {
+ found = 0;
+ pthread_mutex_lock(&device->all_mr_lock);
+ {
+ if (!list_empty(&device->all_mr)) {
+ list_for_each_entry_safe(tmp, dummy, &device->all_mr, list)
+ {
+ if (tmp->mr == mr[i]) {
+ found = 1;
+ break;
+ }
}
- pthread_mutex_unlock (&device->all_mr_lock);
- if (!found)
- ibv_dereg_mr (mr[i]);
-
+ }
}
+ pthread_mutex_unlock(&device->all_mr_lock);
+ if (!found)
+ ibv_dereg_mr(mr[i]);
+ }
out:
- return;
+ return;
}
-
static int32_t
-__gf_rdma_quota_put (gf_rdma_peer_t *peer)
+__gf_rdma_quota_put(gf_rdma_peer_t *peer)
{
- int32_t ret = 0;
+ int32_t ret = 0;
- peer->quota++;
- ret = peer->quota;
+ peer->quota++;
+ ret = peer->quota;
- if (!list_empty (&peer->ioq)) {
- ret = __gf_rdma_ioq_churn (peer);
- }
+ if (!list_empty(&peer->ioq)) {
+ ret = __gf_rdma_ioq_churn(peer);
+ }
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_quota_put (gf_rdma_peer_t *peer)
+gf_rdma_quota_put(gf_rdma_peer_t *peer)
{
- int32_t ret = 0;
- gf_rdma_private_t *priv = NULL;
+ int32_t ret = 0;
+ gf_rdma_private_t *priv = NULL;
- priv = peer->trans->private;
- pthread_mutex_lock (&priv->write_mutex);
- {
- ret = __gf_rdma_quota_put (peer);
- }
- pthread_mutex_unlock (&priv->write_mutex);
+ priv = peer->trans->private;
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ ret = __gf_rdma_quota_put(peer);
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
- return ret;
+ return ret;
}
-
/* to be called with priv->mutex held */
void
-__gf_rdma_request_context_destroy (gf_rdma_request_context_t *context)
+__gf_rdma_request_context_destroy(gf_rdma_request_context_t *context)
{
- gf_rdma_peer_t *peer = NULL;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- int32_t ret = 0;
+ gf_rdma_peer_t *peer = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ int32_t ret = 0;
- if (context == NULL) {
- goto out;
- }
-
- peer = context->peer;
+ if (context == NULL) {
+ goto out;
+ }
- priv = peer->trans->private;
- device = priv->device;
- __gf_rdma_deregister_mr (device, context->mr, context->mr_count);
+ peer = context->peer;
+ priv = peer->trans->private;
+ device = priv->device;
+ __gf_rdma_deregister_mr(device, context->mr, context->mr_count);
- if (priv->connected) {
- ret = __gf_rdma_quota_put (peer);
- if (ret < 0) {
- gf_msg_debug ("rdma", 0, "failed to send message");
- mem_put (context);
- __gf_rdma_disconnect (peer->trans);
- goto out;
- }
+ if (priv->connected) {
+ ret = __gf_rdma_quota_put(peer);
+ if (ret < 0) {
+ gf_msg_debug("rdma", 0, "failed to send message");
+ mem_put(context);
+ __gf_rdma_disconnect(peer->trans);
+ goto out;
}
+ }
- if (context->iobref != NULL) {
- iobref_unref (context->iobref);
- context->iobref = NULL;
- }
+ if (context->iobref != NULL) {
+ iobref_unref(context->iobref);
+ context->iobref = NULL;
+ }
- if (context->rsp_iobref != NULL) {
- iobref_unref (context->rsp_iobref);
- context->rsp_iobref = NULL;
- }
+ if (context->rsp_iobref != NULL) {
+ iobref_unref(context->rsp_iobref);
+ context->rsp_iobref = NULL;
+ }
- mem_put (context);
+ mem_put(context);
out:
- return;
+ return;
}
-
void
-gf_rdma_post_context_destroy (gf_rdma_device_t *device,
- gf_rdma_post_context_t *ctx)
+gf_rdma_post_context_destroy(gf_rdma_device_t *device,
+ gf_rdma_post_context_t *ctx)
{
- if (ctx == NULL) {
- goto out;
- }
+ if (ctx == NULL) {
+ goto out;
+ }
- __gf_rdma_deregister_mr (device, ctx->mr, ctx->mr_count);
+ __gf_rdma_deregister_mr(device, ctx->mr, ctx->mr_count);
- if (ctx->iobref != NULL) {
- iobref_unref (ctx->iobref);
- }
+ if (ctx->iobref != NULL) {
+ iobref_unref(ctx->iobref);
+ }
- if (ctx->hdr_iobuf != NULL) {
- iobuf_unref (ctx->hdr_iobuf);
- }
+ if (ctx->hdr_iobuf != NULL) {
+ iobuf_unref(ctx->hdr_iobuf);
+ }
- memset (ctx, 0, sizeof (*ctx));
+ memset(ctx, 0, sizeof(*ctx));
out:
- return;
+ return;
}
-
int
-gf_rdma_post_unref (gf_rdma_post_t *post)
+gf_rdma_post_unref(gf_rdma_post_t *post)
{
- int refcount = -1;
-
- if (post == NULL) {
- goto out;
- }
-
- pthread_mutex_lock (&post->lock);
- {
- refcount = --post->refcount;
- }
- pthread_mutex_unlock (&post->lock);
-
- if (refcount == 0) {
- gf_rdma_post_context_destroy (post->device, &post->ctx);
- if (post->type == GF_RDMA_SEND_POST) {
- gf_rdma_put_post (&post->device->sendq, post);
- } else {
- gf_rdma_post_recv (post->device->srq, post);
- }
+ int refcount = -1;
+
+ if (post == NULL) {
+ goto out;
+ }
+
+ pthread_mutex_lock(&post->lock);
+ {
+ refcount = --post->refcount;
+ }
+ pthread_mutex_unlock(&post->lock);
+
+ if (refcount == 0) {
+ gf_rdma_post_context_destroy(post->device, &post->ctx);
+ if (post->type == GF_RDMA_SEND_POST) {
+ gf_rdma_put_post(&post->device->sendq, post);
+ } else {
+ gf_rdma_post_recv(post->device->srq, post);
}
+ }
out:
- return refcount;
+ return refcount;
}
-
int
-gf_rdma_post_get_refcount (gf_rdma_post_t *post)
+gf_rdma_post_get_refcount(gf_rdma_post_t *post)
{
- int refcount = -1;
+ int refcount = -1;
- if (post == NULL) {
- goto out;
- }
+ if (post == NULL) {
+ goto out;
+ }
- pthread_mutex_lock (&post->lock);
- {
- refcount = post->refcount;
- }
- pthread_mutex_unlock (&post->lock);
+ pthread_mutex_lock(&post->lock);
+ {
+ refcount = post->refcount;
+ }
+ pthread_mutex_unlock(&post->lock);
out:
- return refcount;
+ return refcount;
}
gf_rdma_post_t *
-gf_rdma_post_ref (gf_rdma_post_t *post)
+gf_rdma_post_ref(gf_rdma_post_t *post)
{
- if (post == NULL) {
- goto out;
- }
+ if (post == NULL) {
+ goto out;
+ }
- pthread_mutex_lock (&post->lock);
- {
- post->refcount++;
- }
- pthread_mutex_unlock (&post->lock);
+ pthread_mutex_lock(&post->lock);
+ {
+ post->refcount++;
+ }
+ pthread_mutex_unlock(&post->lock);
out:
- return post;
+ return post;
}
-
int32_t
-__gf_rdma_ioq_churn_request (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post)
+__gf_rdma_ioq_churn_request(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post)
{
- gf_rdma_chunktype_t rtype = gf_rdma_noch;
- gf_rdma_chunktype_t wtype = gf_rdma_noch;
- uint64_t send_size = 0;
- gf_rdma_header_t *hdr = NULL;
- struct rpc_msg *rpc_msg = NULL;
- uint32_t *chunkptr = NULL;
- char *buf = NULL;
- int32_t ret = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- int chunk_count = 0;
- gf_rdma_request_context_t *request_ctx = NULL;
- uint32_t prog_payload_length = 0, len = 0;
- struct rpc_req *rpc_req = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, entry, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, post, out);
-
- if ((entry->msg.request.rsphdr_count != 0)
- && (entry->msg.request.rsp_payload_count != 0)) {
- ret = -1;
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_REPLY_CHUNCK_CONFLICT,
- "both write-chunklist and reply-chunk cannot be "
- "present");
- goto out;
- }
-
- post->ctx.is_request = 1;
- priv = peer->trans->private;
- device = priv->device;
-
- hdr = (gf_rdma_header_t *)post->buf;
-
- send_size = iov_length (entry->rpchdr, entry->rpchdr_count)
- + iov_length (entry->proghdr, entry->proghdr_count)
- + GLUSTERFS_RDMA_MAX_HEADER_SIZE;
-
- if (entry->prog_payload_count != 0) {
- prog_payload_length
- = iov_length (entry->prog_payload,
- entry->prog_payload_count);
- }
-
- if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
- rtype = gf_rdma_areadch;
- } else if ((send_size + prog_payload_length)
- < GLUSTERFS_RDMA_INLINE_THRESHOLD) {
- rtype = gf_rdma_noch;
- } else if (entry->prog_payload_count != 0) {
- rtype = gf_rdma_readch;
- }
-
- if (entry->msg.request.rsphdr_count != 0) {
- wtype = gf_rdma_replych;
- } else if (entry->msg.request.rsp_payload_count != 0) {
- wtype = gf_rdma_writech;
- }
-
- if (rtype == gf_rdma_readch) {
- chunk_count += entry->prog_payload_count;
- } else if (rtype == gf_rdma_areadch) {
- chunk_count += entry->rpchdr_count;
- chunk_count += entry->proghdr_count;
- }
-
- if (wtype == gf_rdma_writech) {
- chunk_count += entry->msg.request.rsp_payload_count;
- } else if (wtype == gf_rdma_replych) {
- chunk_count += entry->msg.request.rsphdr_count;
- }
-
- if (chunk_count > GF_RDMA_MAX_SEGMENTS) {
- ret = -1;
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CHUNK_COUNT_GREAT_MAX_SEGMENTS,
- "chunk count(%d) exceeding maximum allowed RDMA "
- "segment count(%d)", chunk_count, GF_RDMA_MAX_SEGMENTS);
- goto out;
- }
-
- if ((wtype != gf_rdma_noch) || (rtype != gf_rdma_noch)) {
- request_ctx = mem_get (device->request_ctx_pool);
- if (request_ctx == NULL) {
- ret = -1;
- goto out;
- }
-
- memset (request_ctx, 0, sizeof (*request_ctx));
-
- request_ctx->pool = device->request_ctx_pool;
- request_ctx->peer = peer;
-
- entry->msg.request.rpc_req->conn_private = request_ctx;
-
- if (entry->msg.request.rsp_iobref != NULL) {
- request_ctx->rsp_iobref
- = iobref_ref (entry->msg.request.rsp_iobref);
- }
- }
-
- rpc_msg = (struct rpc_msg *) entry->rpchdr[0].iov_base;
-
- hdr->rm_xid = rpc_msg->rm_xid; /* no need of hton32(rpc_msg->rm_xid),
- * since rpc_msg->rm_xid is already
- * hton32ed value of actual xid
- */
- hdr->rm_vers = hton32 (GF_RDMA_VERSION);
- hdr->rm_credit = hton32 (peer->send_count);
- if (rtype == gf_rdma_areadch) {
- hdr->rm_type = hton32 (GF_RDMA_NOMSG);
- } else {
- hdr->rm_type = hton32 (GF_RDMA_MSG);
- }
-
- chunkptr = &hdr->rm_body.rm_chunks[0];
- if (rtype != gf_rdma_noch) {
- ret = __gf_rdma_create_read_chunks (peer, entry, rtype,
- &chunkptr,
- request_ctx);
- if (ret != 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CREATE_READ_CHUNK_FAILED,
- "creation of read chunks failed");
- goto out;
- }
- } else {
- *chunkptr++ = 0; /* no read chunks */
- }
-
- if (wtype != gf_rdma_noch) {
- ret = __gf_rdma_create_write_chunks (peer, entry, wtype,
- &chunkptr,
- request_ctx);
- if (ret != 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CREATE_WRITE_REPLAY_FAILED,
- "creation of write/reply chunk failed");
- goto out;
- }
- } else {
- *chunkptr++ = 0; /* no write chunks */
- *chunkptr++ = 0; /* no reply chunk */
+ gf_rdma_chunktype_t rtype = gf_rdma_noch;
+ gf_rdma_chunktype_t wtype = gf_rdma_noch;
+ uint64_t send_size = 0;
+ gf_rdma_header_t *hdr = NULL;
+ struct rpc_msg *rpc_msg = NULL;
+ uint32_t *chunkptr = NULL;
+ char *buf = NULL;
+ int32_t ret = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ int chunk_count = 0;
+ gf_rdma_request_context_t *request_ctx = NULL;
+ uint32_t prog_payload_length = 0, len = 0;
+ struct rpc_req *rpc_req = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, post, out);
+
+ if ((entry->msg.request.rsphdr_count != 0) &&
+ (entry->msg.request.rsp_payload_count != 0)) {
+ ret = -1;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_WRITE_REPLY_CHUNCK_CONFLICT,
+ "both write-chunklist and reply-chunk cannot be "
+ "present");
+ goto out;
+ }
+
+ post->ctx.is_request = 1;
+ priv = peer->trans->private;
+ device = priv->device;
+
+ hdr = (gf_rdma_header_t *)post->buf;
+
+ send_size = iov_length(entry->rpchdr, entry->rpchdr_count) +
+ iov_length(entry->proghdr, entry->proghdr_count) +
+ GLUSTERFS_RDMA_MAX_HEADER_SIZE;
+
+ if (entry->prog_payload_count != 0) {
+ prog_payload_length = iov_length(entry->prog_payload,
+ entry->prog_payload_count);
+ }
+
+ if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
+ rtype = gf_rdma_areadch;
+ } else if ((send_size + prog_payload_length) <
+ GLUSTERFS_RDMA_INLINE_THRESHOLD) {
+ rtype = gf_rdma_noch;
+ } else if (entry->prog_payload_count != 0) {
+ rtype = gf_rdma_readch;
+ }
+
+ if (entry->msg.request.rsphdr_count != 0) {
+ wtype = gf_rdma_replych;
+ } else if (entry->msg.request.rsp_payload_count != 0) {
+ wtype = gf_rdma_writech;
+ }
+
+ if (rtype == gf_rdma_readch) {
+ chunk_count += entry->prog_payload_count;
+ } else if (rtype == gf_rdma_areadch) {
+ chunk_count += entry->rpchdr_count;
+ chunk_count += entry->proghdr_count;
+ }
+
+ if (wtype == gf_rdma_writech) {
+ chunk_count += entry->msg.request.rsp_payload_count;
+ } else if (wtype == gf_rdma_replych) {
+ chunk_count += entry->msg.request.rsphdr_count;
+ }
+
+ if (chunk_count > GF_RDMA_MAX_SEGMENTS) {
+ ret = -1;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CHUNK_COUNT_GREAT_MAX_SEGMENTS,
+ "chunk count(%d) exceeding maximum allowed RDMA "
+ "segment count(%d)",
+ chunk_count, GF_RDMA_MAX_SEGMENTS);
+ goto out;
+ }
+
+ if ((wtype != gf_rdma_noch) || (rtype != gf_rdma_noch)) {
+ request_ctx = mem_get(device->request_ctx_pool);
+ if (request_ctx == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ memset(request_ctx, 0, sizeof(*request_ctx));
+
+ request_ctx->pool = device->request_ctx_pool;
+ request_ctx->peer = peer;
+
+ entry->msg.request.rpc_req->conn_private = request_ctx;
+
+ if (entry->msg.request.rsp_iobref != NULL) {
+ request_ctx->rsp_iobref = iobref_ref(entry->msg.request.rsp_iobref);
+ }
+ }
+
+ rpc_msg = (struct rpc_msg *)entry->rpchdr[0].iov_base;
+
+ hdr->rm_xid = rpc_msg->rm_xid; /* no need of hton32(rpc_msg->rm_xid),
+ * since rpc_msg->rm_xid is already
+ * hton32ed value of actual xid
+ */
+ hdr->rm_vers = hton32(GF_RDMA_VERSION);
+ hdr->rm_credit = hton32(peer->send_count);
+ if (rtype == gf_rdma_areadch) {
+ hdr->rm_type = hton32(GF_RDMA_NOMSG);
+ } else {
+ hdr->rm_type = hton32(GF_RDMA_MSG);
+ }
+
+ chunkptr = &hdr->rm_body.rm_chunks[0];
+ if (rtype != gf_rdma_noch) {
+ ret = __gf_rdma_create_read_chunks(peer, entry, rtype, &chunkptr,
+ request_ctx);
+ if (ret != 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CREATE_READ_CHUNK_FAILED,
+ "creation of read chunks failed");
+ goto out;
+ }
+ } else {
+ *chunkptr++ = 0; /* no read chunks */
+ }
+
+ if (wtype != gf_rdma_noch) {
+ ret = __gf_rdma_create_write_chunks(peer, entry, wtype, &chunkptr,
+ request_ctx);
+ if (ret != 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CREATE_WRITE_REPLAY_FAILED,
+ "creation of write/reply chunk failed");
+ goto out;
}
+ } else {
+ *chunkptr++ = 0; /* no write chunks */
+ *chunkptr++ = 0; /* no reply chunk */
+ }
- buf = (char *)chunkptr;
+ buf = (char *)chunkptr;
- if (rtype != gf_rdma_areadch) {
- iov_unload (buf, entry->rpchdr, entry->rpchdr_count);
- buf += iov_length (entry->rpchdr, entry->rpchdr_count);
+ if (rtype != gf_rdma_areadch) {
+ iov_unload(buf, entry->rpchdr, entry->rpchdr_count);
+ buf += iov_length(entry->rpchdr, entry->rpchdr_count);
- iov_unload (buf, entry->proghdr, entry->proghdr_count);
- buf += iov_length (entry->proghdr, entry->proghdr_count);
+ iov_unload(buf, entry->proghdr, entry->proghdr_count);
+ buf += iov_length(entry->proghdr, entry->proghdr_count);
- if (rtype != gf_rdma_readch) {
- iov_unload (buf, entry->prog_payload,
- entry->prog_payload_count);
- buf += iov_length (entry->prog_payload,
- entry->prog_payload_count);
- }
+ if (rtype != gf_rdma_readch) {
+ iov_unload(buf, entry->prog_payload, entry->prog_payload_count);
+ buf += iov_length(entry->prog_payload, entry->prog_payload_count);
}
+ }
- len = buf - post->buf;
+ len = buf - post->buf;
- gf_rdma_post_ref (post);
+ gf_rdma_post_ref(post);
- ret = gf_rdma_post_send (peer->qp, post, len);
- if (!ret) {
- ret = len;
- } else {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_SEND_FAILED,
- "gf_rdma_post_send (to %s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- gf_rdma_post_unref (post);
- __gf_rdma_disconnect (peer->trans);
- ret = -1;
- }
+ ret = gf_rdma_post_send(peer->qp, post, len);
+ if (!ret) {
+ ret = len;
+ } else {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED,
+ "gf_rdma_post_send (to %s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ gf_rdma_post_unref(post);
+ __gf_rdma_disconnect(peer->trans);
+ ret = -1;
+ }
out:
- if (ret == -1) {
- rpc_req = entry->msg.request.rpc_req;
-
- if (request_ctx != NULL) {
- __gf_rdma_request_context_destroy (rpc_req->conn_private);
- }
+ if (ret == -1) {
+ rpc_req = entry->msg.request.rpc_req;
- rpc_req->conn_private = NULL;
+ if (request_ctx != NULL) {
+ __gf_rdma_request_context_destroy(rpc_req->conn_private);
}
- return ret;
-}
+ rpc_req->conn_private = NULL;
+ }
+ return ret;
+}
static void
-__gf_rdma_fill_reply_header (gf_rdma_header_t *header, struct iovec *rpchdr,
- gf_rdma_reply_info_t *reply_info, int credits)
+__gf_rdma_fill_reply_header(gf_rdma_header_t *header, struct iovec *rpchdr,
+ gf_rdma_reply_info_t *reply_info, int credits)
{
- struct rpc_msg *rpc_msg = NULL;
-
- if (reply_info != NULL) {
- header->rm_xid = hton32 (reply_info->rm_xid);
- } else {
- rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains
- * only one vector.
- * (which is true)
- */
- header->rm_xid = rpc_msg->rm_xid;
- }
-
- header->rm_type = hton32 (GF_RDMA_MSG);
- header->rm_vers = hton32 (GF_RDMA_VERSION);
- header->rm_credit = hton32 (credits);
-
- header->rm_body.rm_chunks[0] = 0; /* no read chunks */
- header->rm_body.rm_chunks[1] = 0; /* no write chunks */
- header->rm_body.rm_chunks[2] = 0; /* no reply chunks */
-
- return;
+ struct rpc_msg *rpc_msg = NULL;
+
+ if (reply_info != NULL) {
+ header->rm_xid = hton32(reply_info->rm_xid);
+ } else {
+ rpc_msg = rpchdr[0].iov_base; /* assume rpchdr contains
+ * only one vector.
+ * (which is true)
+ */
+ header->rm_xid = rpc_msg->rm_xid;
+ }
+
+ header->rm_type = hton32(GF_RDMA_MSG);
+ header->rm_vers = hton32(GF_RDMA_VERSION);
+ header->rm_credit = hton32(credits);
+
+ header->rm_body.rm_chunks[0] = 0; /* no read chunks */
+ header->rm_body.rm_chunks[1] = 0; /* no write chunks */
+ header->rm_body.rm_chunks[2] = 0; /* no reply chunks */
+
+ return;
}
-
int32_t
-__gf_rdma_send_reply_inline (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post,
- gf_rdma_reply_info_t *reply_info)
+__gf_rdma_send_reply_inline(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post,
+ gf_rdma_reply_info_t *reply_info)
{
- gf_rdma_header_t *header = NULL;
- int32_t send_size = 0, ret = 0;
- char *buf = NULL;
-
- send_size = iov_length (entry->rpchdr, entry->rpchdr_count)
- + iov_length (entry->proghdr, entry->proghdr_count)
- + iov_length (entry->prog_payload, entry->prog_payload_count)
- + sizeof (gf_rdma_header_t); /*
- * remember, no chunklists in the
- * reply
- */
-
- if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
- ret = __gf_rdma_send_error (peer, entry, post, reply_info,
- ERR_CHUNK);
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD,
- "msg size (%d) is greater than maximum size "
- "of msg that can be sent inlined (%d)",
- send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD);
- goto out;
- }
-
- header = (gf_rdma_header_t *)post->buf;
-
- __gf_rdma_fill_reply_header (header, entry->rpchdr, reply_info,
- peer->send_count);
-
- buf = (char *)&header->rm_body.rm_chunks[3];
-
- if (entry->rpchdr_count != 0) {
- iov_unload (buf, entry->rpchdr, entry->rpchdr_count);
- buf += iov_length (entry->rpchdr, entry->rpchdr_count);
- }
-
- if (entry->proghdr_count != 0) {
- iov_unload (buf, entry->proghdr, entry->proghdr_count);
- buf += iov_length (entry->proghdr, entry->proghdr_count);
- }
-
- if (entry->prog_payload_count != 0) {
- iov_unload (buf, entry->prog_payload,
- entry->prog_payload_count);
- buf += iov_length (entry->prog_payload,
- entry->prog_payload_count);
- }
-
- gf_rdma_post_ref (post);
+ gf_rdma_header_t *header = NULL;
+ int32_t send_size = 0, ret = 0;
+ char *buf = NULL;
+
+ send_size = iov_length(entry->rpchdr, entry->rpchdr_count) +
+ iov_length(entry->proghdr, entry->proghdr_count) +
+ iov_length(entry->prog_payload, entry->prog_payload_count) +
+ sizeof(gf_rdma_header_t); /*
+ * remember, no chunklists in the
+ * reply
+ */
- ret = gf_rdma_post_send (peer->qp, post, (buf - post->buf));
- if (!ret) {
- ret = send_size;
- } else {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_SEND_FAILED, "posting send (to %s) "
- "failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- gf_rdma_post_unref (post);
- __gf_rdma_disconnect (peer->trans);
- ret = -1;
- }
+ if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
+ ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK);
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD,
+ "msg size (%d) is greater than maximum size "
+ "of msg that can be sent inlined (%d)",
+ send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD);
+ goto out;
+ }
+
+ header = (gf_rdma_header_t *)post->buf;
+
+ __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info,
+ peer->send_count);
+
+ buf = (char *)&header->rm_body.rm_chunks[3];
+
+ if (entry->rpchdr_count != 0) {
+ iov_unload(buf, entry->rpchdr, entry->rpchdr_count);
+ buf += iov_length(entry->rpchdr, entry->rpchdr_count);
+ }
+
+ if (entry->proghdr_count != 0) {
+ iov_unload(buf, entry->proghdr, entry->proghdr_count);
+ buf += iov_length(entry->proghdr, entry->proghdr_count);
+ }
+
+ if (entry->prog_payload_count != 0) {
+ iov_unload(buf, entry->prog_payload, entry->prog_payload_count);
+ buf += iov_length(entry->prog_payload, entry->prog_payload_count);
+ }
+
+ gf_rdma_post_ref(post);
+
+ ret = gf_rdma_post_send(peer->qp, post, (buf - post->buf));
+ if (!ret) {
+ ret = send_size;
+ } else {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED,
+ "posting send (to %s) "
+ "failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ gf_rdma_post_unref(post);
+ __gf_rdma_disconnect(peer->trans);
+ ret = -1;
+ }
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_reply_encode_write_chunks (gf_rdma_peer_t *peer,
- uint32_t payload_size,
- gf_rdma_post_t *post,
- gf_rdma_reply_info_t *reply_info,
- uint32_t **ptr)
+__gf_rdma_reply_encode_write_chunks(gf_rdma_peer_t *peer, uint32_t payload_size,
+ gf_rdma_post_t *post,
+ gf_rdma_reply_info_t *reply_info,
+ uint32_t **ptr)
{
- uint32_t chunk_size = 0;
- int32_t ret = -1;
- gf_rdma_write_array_t *target_array = NULL;
- int i = 0;
-
- target_array = (gf_rdma_write_array_t *)*ptr;
-
- for (i = 0; i < reply_info->wc_array->wc_nchunks; i++) {
- chunk_size +=
- reply_info->wc_array->wc_array[i].wc_target.rs_length;
- }
-
- if (chunk_size < payload_size) {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0, "length of payload (%d) is "
- "exceeding the total write chunk length (%d)",
- payload_size, chunk_size);
- goto out;
- }
-
- target_array->wc_discrim = hton32 (1);
- for (i = 0; (i < reply_info->wc_array->wc_nchunks)
- && (payload_size != 0);
- i++) {
- target_array->wc_array[i].wc_target.rs_offset
- = hton64 (reply_info->wc_array->wc_array[i].wc_target.rs_offset);
-
- target_array->wc_array[i].wc_target.rs_length
- = hton32 (min (payload_size,
- reply_info->wc_array->wc_array[i].wc_target.rs_length));
- }
-
- target_array->wc_nchunks = hton32 (i);
- target_array->wc_array[i].wc_target.rs_handle = 0; /* terminate
- chunklist */
-
- ret = 0;
-
- *ptr = &target_array->wc_array[i].wc_target.rs_length;
+ uint32_t chunk_size = 0;
+ int32_t ret = -1;
+ gf_rdma_write_array_t *target_array = NULL;
+ int i = 0;
+
+ target_array = (gf_rdma_write_array_t *)*ptr;
+
+ for (i = 0; i < reply_info->wc_array->wc_nchunks; i++) {
+ chunk_size += reply_info->wc_array->wc_array[i].wc_target.rs_length;
+ }
+
+ if (chunk_size < payload_size) {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "length of payload (%d) is "
+ "exceeding the total write chunk length (%d)",
+ payload_size, chunk_size);
+ goto out;
+ }
+
+ target_array->wc_discrim = hton32(1);
+ for (i = 0; (i < reply_info->wc_array->wc_nchunks) && (payload_size != 0);
+ i++) {
+ target_array->wc_array[i].wc_target.rs_offset = hton64(
+ reply_info->wc_array->wc_array[i].wc_target.rs_offset);
+
+ target_array->wc_array[i].wc_target.rs_length = hton32(
+ min(payload_size,
+ reply_info->wc_array->wc_array[i].wc_target.rs_length));
+ }
+
+ target_array->wc_nchunks = hton32(i);
+ target_array->wc_array[i].wc_target.rs_handle = 0; /* terminate
+ chunklist */
+
+ ret = 0;
+
+ *ptr = &target_array->wc_array[i].wc_target.rs_length;
out:
- return ret;
+ return ret;
}
-
static int32_t
-__gf_rdma_register_local_mr_for_rdma (gf_rdma_peer_t *peer,
- struct iovec *vector, int count,
- gf_rdma_post_context_t *ctx)
+__gf_rdma_register_local_mr_for_rdma(gf_rdma_peer_t *peer, struct iovec *vector,
+ int count, gf_rdma_post_context_t *ctx)
{
- int i = 0;
- int32_t ret = -1;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, ctx, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, vector, out);
-
- priv = peer->trans->private;
- device = priv->device;
-
- for (i = 0; i < count; i++) {
- /* what if the memory is registered more than once?
- * Assume that a single write buffer is passed to afr, which
- * then passes it to its children. If more than one children
- * happen to use rdma, then the buffer is registered more than
- * once.
- * Ib-verbs specification says that multiple registrations of
- * same memory location is allowed. Refer to 10.6.3.8 of
- * Infiniband Architecture Specification Volume 1
- * (Release 1.2.1)
- */
- ctx->mr[ctx->mr_count] = gf_rdma_get_pre_registred_mr(
- peer->trans, (void *)vector[i].iov_base,
- vector[i].iov_len);
-
- if (!ctx->mr[ctx->mr_count]) {
- ctx->mr[ctx->mr_count] = ibv_reg_mr (device->pd,
- vector[i].iov_base,
- vector[i].iov_len,
- IBV_ACCESS_LOCAL_WRITE);
- }
- if (ctx->mr[ctx->mr_count] == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_MR_ALOC_FAILED,
- "registering memory for IBV_ACCESS_LOCAL_WRITE"
- " failed");
- goto out;
- }
+ int i = 0;
+ int32_t ret = -1;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, ctx, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, vector, out);
+
+ priv = peer->trans->private;
+ device = priv->device;
+
+ for (i = 0; i < count; i++) {
+ /* what if the memory is registered more than once?
+ * Assume that a single write buffer is passed to afr, which
+ * then passes it to its children. If more than one children
+ * happen to use rdma, then the buffer is registered more than
+ * once.
+ * Ib-verbs specification says that multiple registrations of
+ * same memory location is allowed. Refer to 10.6.3.8 of
+ * Infiniband Architecture Specification Volume 1
+ * (Release 1.2.1)
+ */
+ ctx->mr[ctx->mr_count] = gf_rdma_get_pre_registred_mr(
+ peer->trans, (void *)vector[i].iov_base, vector[i].iov_len);
- ctx->mr_count++;
+ if (!ctx->mr[ctx->mr_count]) {
+ ctx->mr[ctx->mr_count] = ibv_reg_mr(device->pd, vector[i].iov_base,
+ vector[i].iov_len,
+ IBV_ACCESS_LOCAL_WRITE);
+ }
+ if (ctx->mr[ctx->mr_count] == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_MR_ALOC_FAILED,
+ "registering memory for IBV_ACCESS_LOCAL_WRITE"
+ " failed");
+ goto out;
}
- ret = 0;
+ ctx->mr_count++;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
/* 1. assumes xfer_len of data is pointed by vector(s) starting from vec[*idx]
* 2. modifies vec
*/
int32_t
-__gf_rdma_write (gf_rdma_peer_t *peer, gf_rdma_post_t *post, struct iovec *vec,
- uint32_t xfer_len, int *idx, gf_rdma_write_chunk_t *writech)
+__gf_rdma_write(gf_rdma_peer_t *peer, gf_rdma_post_t *post, struct iovec *vec,
+ uint32_t xfer_len, int *idx, gf_rdma_write_chunk_t *writech)
{
- int size = 0, num_sge = 0, i = 0;
- int32_t ret = -1;
- struct ibv_sge *sg_list = NULL;
- struct ibv_send_wr wr = {
- .opcode = IBV_WR_RDMA_WRITE,
- .send_flags = IBV_SEND_SIGNALED,
- }, *bad_wr;
-
- if ((peer == NULL) || (writech == NULL) || (idx == NULL)
- || (post == NULL) || (vec == NULL) || (xfer_len == 0)) {
- goto out;
- }
-
- for (i = *idx; size < xfer_len; i++) {
- size += vec[i].iov_len;
- }
-
- num_sge = i - *idx;
-
- sg_list = GF_CALLOC (num_sge, sizeof (struct ibv_sge),
- gf_common_mt_sge);
- if (sg_list == NULL) {
- ret = -1;
- goto out;
- }
-
- for ((i = *idx), (num_sge = 0); (xfer_len != 0); i++, num_sge++) {
- size = min (xfer_len, vec[i].iov_len);
-
- sg_list[num_sge].addr = (unsigned long)vec[i].iov_base;
- sg_list[num_sge].length = size;
- sg_list[num_sge].lkey = post->ctx.mr[i]->lkey;
-
- xfer_len -= size;
- }
-
- *idx = i;
-
- if (size < vec[i - 1].iov_len) {
- vec[i - 1].iov_base += size;
- vec[i - 1].iov_len -= size;
- *idx = i - 1;
- }
-
- wr.sg_list = sg_list;
- wr.num_sge = num_sge;
- wr.wr_id = (unsigned long) gf_rdma_post_ref (post);
- wr.wr.rdma.rkey = writech->wc_target.rs_handle;
- wr.wr.rdma.remote_addr = writech->wc_target.rs_offset;
-
- ret = ibv_post_send(peer->qp, &wr, &bad_wr);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_CLIENT_ERROR, "rdma write to "
- "client (%s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- ret = -1;
- }
-
- GF_FREE (sg_list);
+ int size = 0, num_sge = 0, i = 0;
+ int32_t ret = -1;
+ struct ibv_sge *sg_list = NULL;
+ struct ibv_send_wr wr =
+ {
+ .opcode = IBV_WR_RDMA_WRITE,
+ .send_flags = IBV_SEND_SIGNALED,
+ },
+ *bad_wr;
+
+ if ((peer == NULL) || (writech == NULL) || (idx == NULL) ||
+ (post == NULL) || (vec == NULL) || (xfer_len == 0)) {
+ goto out;
+ }
+
+ for (i = *idx; size < xfer_len; i++) {
+ size += vec[i].iov_len;
+ }
+
+ num_sge = i - *idx;
+
+ sg_list = GF_CALLOC(num_sge, sizeof(struct ibv_sge), gf_common_mt_sge);
+ if (sg_list == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ for ((i = *idx), (num_sge = 0); (xfer_len != 0); i++, num_sge++) {
+ size = min(xfer_len, vec[i].iov_len);
+
+ sg_list[num_sge].addr = (unsigned long)vec[i].iov_base;
+ sg_list[num_sge].length = size;
+ sg_list[num_sge].lkey = post->ctx.mr[i]->lkey;
+
+ xfer_len -= size;
+ }
+
+ *idx = i;
+
+ if (size < vec[i - 1].iov_len) {
+ vec[i - 1].iov_base += size;
+ vec[i - 1].iov_len -= size;
+ *idx = i - 1;
+ }
+
+ wr.sg_list = sg_list;
+ wr.num_sge = num_sge;
+ wr.wr_id = (unsigned long)gf_rdma_post_ref(post);
+ wr.wr.rdma.rkey = writech->wc_target.rs_handle;
+ wr.wr.rdma.remote_addr = writech->wc_target.rs_offset;
+
+ ret = ibv_post_send(peer->qp, &wr, &bad_wr);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_CLIENT_ERROR,
+ "rdma write to "
+ "client (%s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ ret = -1;
+ }
+
+ GF_FREE(sg_list);
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_do_gf_rdma_write (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- struct iovec *vector, int count,
- struct iobref *iobref,
- gf_rdma_reply_info_t *reply_info)
+__gf_rdma_do_gf_rdma_write(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ struct iovec *vector, int count,
+ struct iobref *iobref,
+ gf_rdma_reply_info_t *reply_info)
{
- int i = 0, payload_idx = 0;
- uint32_t payload_size = 0, xfer_len = 0;
- int32_t ret = -1;
+ int i = 0, payload_idx = 0;
+ uint32_t payload_size = 0, xfer_len = 0;
+ int32_t ret = -1;
- if (count != 0) {
- payload_size = iov_length (vector, count);
- }
+ if (count != 0) {
+ payload_size = iov_length(vector, count);
+ }
- if (payload_size == 0) {
- ret = 0;
- goto out;
- }
+ if (payload_size == 0) {
+ ret = 0;
+ goto out;
+ }
- ret = __gf_rdma_register_local_mr_for_rdma (peer, vector, count,
- &post->ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_MR_ALOC_FAILED,
- "registering memory region for rdma failed");
- goto out;
- }
+ ret = __gf_rdma_register_local_mr_for_rdma(peer, vector, count, &post->ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_MR_ALOC_FAILED,
+ "registering memory region for rdma failed");
+ goto out;
+ }
- post->ctx.iobref = iobref_ref (iobref);
+ post->ctx.iobref = iobref_ref(iobref);
- for (i = 0; (i < reply_info->wc_array->wc_nchunks)
- && (payload_size != 0);
- i++) {
- xfer_len = min (payload_size,
- reply_info->wc_array->wc_array[i].wc_target.rs_length);
+ for (i = 0; (i < reply_info->wc_array->wc_nchunks) && (payload_size != 0);
+ i++) {
+ xfer_len = min(payload_size,
+ reply_info->wc_array->wc_array[i].wc_target.rs_length);
- ret = __gf_rdma_write (peer, post, vector, xfer_len,
- &payload_idx,
- &reply_info->wc_array->wc_array[i]);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_CLIENT_ERROR, "rdma write to "
- "client (%s) failed",
- peer->trans->peerinfo.identifier);
- goto out;
- }
-
- payload_size -= xfer_len;
+ ret = __gf_rdma_write(peer, post, vector, xfer_len, &payload_idx,
+ &reply_info->wc_array->wc_array[i]);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_WRITE_CLIENT_ERROR,
+ "rdma write to "
+ "client (%s) failed",
+ peer->trans->peerinfo.identifier);
+ goto out;
}
- ret = 0;
+ payload_size -= xfer_len;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_send_reply_type_nomsg (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post,
- gf_rdma_reply_info_t *reply_info)
+__gf_rdma_send_reply_type_nomsg(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post,
+ gf_rdma_reply_info_t *reply_info)
{
- gf_rdma_header_t *header = NULL;
- char *buf = NULL;
- uint32_t payload_size = 0;
- int count = 0, i = 0;
- int32_t ret = 0;
- struct iovec vector[MAX_IOVEC];
-
- header = (gf_rdma_header_t *)post->buf;
-
- __gf_rdma_fill_reply_header (header, entry->rpchdr, reply_info,
- peer->send_count);
-
- header->rm_type = hton32 (GF_RDMA_NOMSG);
-
- payload_size = iov_length (entry->rpchdr, entry->rpchdr_count) +
- iov_length (entry->proghdr, entry->proghdr_count);
-
- /* encode reply chunklist */
- buf = (char *)&header->rm_body.rm_chunks[2];
- ret = __gf_rdma_reply_encode_write_chunks (peer, payload_size, post,
- reply_info,
- (uint32_t **)&buf);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_ENCODE_ERROR, "encoding write chunks failed");
- ret = __gf_rdma_send_error (peer, entry, post, reply_info,
- ERR_CHUNK);
- goto out;
- }
-
- gf_rdma_post_ref (post);
-
- for (i = 0; i < entry->rpchdr_count; i++) {
- vector[count++] = entry->rpchdr[i];
- }
-
- for (i = 0; i < entry->proghdr_count; i++) {
- vector[count++] = entry->proghdr[i];
- }
-
- ret = __gf_rdma_do_gf_rdma_write (peer, post, vector, count,
- entry->iobref, reply_info);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_PEER_FAILED, "rdma write to peer "
- "(%s) failed", peer->trans->peerinfo.identifier);
- gf_rdma_post_unref (post);
- goto out;
- }
-
- ret = gf_rdma_post_send (peer->qp, post, (buf - post->buf));
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_SEND_FAILED, "posting a send request "
- "to client (%s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- ret = -1;
- gf_rdma_post_unref (post);
- } else {
- ret = payload_size;
- }
+ gf_rdma_header_t *header = NULL;
+ char *buf = NULL;
+ uint32_t payload_size = 0;
+ int count = 0, i = 0;
+ int32_t ret = 0;
+ struct iovec vector[MAX_IOVEC];
+
+ header = (gf_rdma_header_t *)post->buf;
+
+ __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info,
+ peer->send_count);
+
+ header->rm_type = hton32(GF_RDMA_NOMSG);
+
+ payload_size = iov_length(entry->rpchdr, entry->rpchdr_count) +
+ iov_length(entry->proghdr, entry->proghdr_count);
+
+ /* encode reply chunklist */
+ buf = (char *)&header->rm_body.rm_chunks[2];
+ ret = __gf_rdma_reply_encode_write_chunks(peer, payload_size, post,
+ reply_info, (uint32_t **)&buf);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_ENCODE_ERROR,
+ "encoding write chunks failed");
+ ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK);
+ goto out;
+ }
+
+ gf_rdma_post_ref(post);
+
+ for (i = 0; i < entry->rpchdr_count; i++) {
+ vector[count++] = entry->rpchdr[i];
+ }
+
+ for (i = 0; i < entry->proghdr_count; i++) {
+ vector[count++] = entry->proghdr[i];
+ }
+
+ ret = __gf_rdma_do_gf_rdma_write(peer, post, vector, count, entry->iobref,
+ reply_info);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED,
+ "rdma write to peer "
+ "(%s) failed",
+ peer->trans->peerinfo.identifier);
+ gf_rdma_post_unref(post);
+ goto out;
+ }
+
+ ret = gf_rdma_post_send(peer->qp, post, (buf - post->buf));
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_SEND_FAILED,
+ "posting a send request "
+ "to client (%s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ ret = -1;
+ gf_rdma_post_unref(post);
+ } else {
+ ret = payload_size;
+ }
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_send_reply_type_msg (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post,
- gf_rdma_reply_info_t *reply_info)
+__gf_rdma_send_reply_type_msg(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post,
+ gf_rdma_reply_info_t *reply_info)
{
- gf_rdma_header_t *header = NULL;
- int32_t send_size = 0, ret = 0;
- char *ptr = NULL;
- uint32_t payload_size = 0;
-
- send_size = iov_length (entry->rpchdr, entry->rpchdr_count)
- + iov_length (entry->proghdr, entry->proghdr_count)
- + GLUSTERFS_RDMA_MAX_HEADER_SIZE;
-
- if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD,
- "client has provided only write chunks, but the "
- "combined size of rpc and program header (%d) is "
- "exceeding the size of msg that can be sent using "
- "RDMA send (%d)", send_size,
- GLUSTERFS_RDMA_INLINE_THRESHOLD);
-
- ret = __gf_rdma_send_error (peer, entry, post, reply_info,
- ERR_CHUNK);
- goto out;
- }
-
- header = (gf_rdma_header_t *)post->buf;
-
- __gf_rdma_fill_reply_header (header, entry->rpchdr, reply_info,
- peer->send_count);
-
- payload_size = iov_length (entry->prog_payload,
- entry->prog_payload_count);
- ptr = (char *)&header->rm_body.rm_chunks[1];
-
- ret = __gf_rdma_reply_encode_write_chunks (peer, payload_size, post,
- reply_info,
- (uint32_t **)&ptr);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_ENCODE_ERROR, "encoding write chunks failed");
- ret = __gf_rdma_send_error (peer, entry, post, reply_info,
- ERR_CHUNK);
- goto out;
- }
-
- *(uint32_t *)ptr = 0; /* terminate reply chunklist */
- ptr += sizeof (uint32_t);
-
- gf_rdma_post_ref (post);
-
- ret = __gf_rdma_do_gf_rdma_write (peer, post, entry->prog_payload,
- entry->prog_payload_count,
- entry->iobref, reply_info);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_PEER_FAILED, "rdma write to peer "
- "(%s) failed", peer->trans->peerinfo.identifier);
- gf_rdma_post_unref (post);
- goto out;
- }
-
- iov_unload (ptr, entry->rpchdr, entry->rpchdr_count);
- ptr += iov_length (entry->rpchdr, entry->rpchdr_count);
-
- iov_unload (ptr, entry->proghdr, entry->proghdr_count);
- ptr += iov_length (entry->proghdr, entry->proghdr_count);
-
- ret = gf_rdma_post_send (peer->qp, post, (ptr - post->buf));
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_CLIENT_ERROR,
- "rdma send to client (%s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier, ret,
- (ret > 0) ? strerror (ret) : "");
- gf_rdma_post_unref (post);
- ret = -1;
- } else {
- ret = send_size + payload_size;
- }
+ gf_rdma_header_t *header = NULL;
+ int32_t send_size = 0, ret = 0;
+ char *ptr = NULL;
+ uint32_t payload_size = 0;
+
+ send_size = iov_length(entry->rpchdr, entry->rpchdr_count) +
+ iov_length(entry->proghdr, entry->proghdr_count) +
+ GLUSTERFS_RDMA_MAX_HEADER_SIZE;
+
+ if (send_size > GLUSTERFS_RDMA_INLINE_THRESHOLD) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_SEND_SIZE_GREAT_INLINE_THRESHOLD,
+ "client has provided only write chunks, but the "
+ "combined size of rpc and program header (%d) is "
+ "exceeding the size of msg that can be sent using "
+ "RDMA send (%d)",
+ send_size, GLUSTERFS_RDMA_INLINE_THRESHOLD);
+
+ ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK);
+ goto out;
+ }
+
+ header = (gf_rdma_header_t *)post->buf;
+
+ __gf_rdma_fill_reply_header(header, entry->rpchdr, reply_info,
+ peer->send_count);
+
+ payload_size = iov_length(entry->prog_payload, entry->prog_payload_count);
+ ptr = (char *)&header->rm_body.rm_chunks[1];
+
+ ret = __gf_rdma_reply_encode_write_chunks(peer, payload_size, post,
+ reply_info, (uint32_t **)&ptr);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_ENCODE_ERROR,
+ "encoding write chunks failed");
+ ret = __gf_rdma_send_error(peer, entry, post, reply_info, ERR_CHUNK);
+ goto out;
+ }
+
+ *(uint32_t *)ptr = 0; /* terminate reply chunklist */
+ ptr += sizeof(uint32_t);
+
+ gf_rdma_post_ref(post);
+
+ ret = __gf_rdma_do_gf_rdma_write(peer, post, entry->prog_payload,
+ entry->prog_payload_count, entry->iobref,
+ reply_info);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED,
+ "rdma write to peer "
+ "(%s) failed",
+ peer->trans->peerinfo.identifier);
+ gf_rdma_post_unref(post);
+ goto out;
+ }
+
+ iov_unload(ptr, entry->rpchdr, entry->rpchdr_count);
+ ptr += iov_length(entry->rpchdr, entry->rpchdr_count);
+
+ iov_unload(ptr, entry->proghdr, entry->proghdr_count);
+ ptr += iov_length(entry->proghdr, entry->proghdr_count);
+
+ ret = gf_rdma_post_send(peer->qp, post, (ptr - post->buf));
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_SEND_CLIENT_ERROR,
+ "rdma send to client (%s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+ gf_rdma_post_unref(post);
+ ret = -1;
+ } else {
+ ret = send_size + payload_size;
+ }
out:
- return ret;
+ return ret;
}
-
void
-gf_rdma_reply_info_destroy (gf_rdma_reply_info_t *reply_info)
+gf_rdma_reply_info_destroy(gf_rdma_reply_info_t *reply_info)
{
- if (reply_info == NULL) {
- goto out;
- }
+ if (reply_info == NULL) {
+ goto out;
+ }
- if (reply_info->wc_array != NULL) {
- GF_FREE (reply_info->wc_array);
- reply_info->wc_array = NULL;
- }
+ if (reply_info->wc_array != NULL) {
+ GF_FREE(reply_info->wc_array);
+ reply_info->wc_array = NULL;
+ }
- mem_put (reply_info);
+ mem_put(reply_info);
out:
- return;
+ return;
}
-
gf_rdma_reply_info_t *
-gf_rdma_reply_info_alloc (gf_rdma_peer_t *peer)
+gf_rdma_reply_info_alloc(gf_rdma_peer_t *peer)
{
- gf_rdma_reply_info_t *reply_info = NULL;
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_reply_info_t *reply_info = NULL;
+ gf_rdma_private_t *priv = NULL;
- priv = peer->trans->private;
+ priv = peer->trans->private;
- reply_info = mem_get (priv->device->reply_info_pool);
- if (reply_info == NULL) {
- goto out;
- }
+ reply_info = mem_get(priv->device->reply_info_pool);
+ if (reply_info == NULL) {
+ goto out;
+ }
- memset (reply_info, 0, sizeof (*reply_info));
- reply_info->pool = priv->device->reply_info_pool;
+ memset(reply_info, 0, sizeof(*reply_info));
+ reply_info->pool = priv->device->reply_info_pool;
out:
- return reply_info;
+ return reply_info;
}
-
int32_t
-__gf_rdma_ioq_churn_reply (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
- gf_rdma_post_t *post)
+__gf_rdma_ioq_churn_reply(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry,
+ gf_rdma_post_t *post)
{
- gf_rdma_reply_info_t *reply_info = NULL;
- int32_t ret = -1;
- gf_rdma_chunktype_t type = gf_rdma_noch;
+ gf_rdma_reply_info_t *reply_info = NULL;
+ int32_t ret = -1;
+ gf_rdma_chunktype_t type = gf_rdma_noch;
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, peer, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, entry, out);
- GF_VALIDATE_OR_GOTO (GF_RDMA_LOG_NAME, post, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, peer, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, entry, out);
+ GF_VALIDATE_OR_GOTO(GF_RDMA_LOG_NAME, post, out);
- reply_info = entry->msg.reply_info;
- if (reply_info != NULL) {
- type = reply_info->type;
- }
+ reply_info = entry->msg.reply_info;
+ if (reply_info != NULL) {
+ type = reply_info->type;
+ }
- switch (type) {
+ switch (type) {
case gf_rdma_noch:
- ret = __gf_rdma_send_reply_inline (peer, entry, post,
- reply_info);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_REPLY_FAILED,
- "failed to send reply to peer (%s) as an "
- "inlined rdma msg",
- peer->trans->peerinfo.identifier);
- }
- break;
+ ret = __gf_rdma_send_reply_inline(peer, entry, post, reply_info);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_SEND_REPLY_FAILED,
+ "failed to send reply to peer (%s) as an "
+ "inlined rdma msg",
+ peer->trans->peerinfo.identifier);
+ }
+ break;
case gf_rdma_replych:
- ret = __gf_rdma_send_reply_type_nomsg (peer, entry, post,
- reply_info);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_REPLY_FAILED,
- "failed to send reply to peer (%s) as "
- "RDMA_NOMSG", peer->trans->peerinfo.identifier);
- }
- break;
+ ret = __gf_rdma_send_reply_type_nomsg(peer, entry, post,
+ reply_info);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_SEND_REPLY_FAILED,
+ "failed to send reply to peer (%s) as "
+ "RDMA_NOMSG",
+ peer->trans->peerinfo.identifier);
+ }
+ break;
case gf_rdma_writech:
- ret = __gf_rdma_send_reply_type_msg (peer, entry, post,
- reply_info);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_SEND_REPLY_FAILED,
- "failed to send reply with write chunks "
- "to peer (%s)",
- peer->trans->peerinfo.identifier);
- }
- break;
+ ret = __gf_rdma_send_reply_type_msg(peer, entry, post, reply_info);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_SEND_REPLY_FAILED,
+ "failed to send reply with write chunks "
+ "to peer (%s)",
+ peer->trans->peerinfo.identifier);
+ }
+ break;
default:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_CHUNK_TYPE,
- "invalid chunktype (%d) specified for sending reply "
- " (peer:%s)", type, peer->trans->peerinfo.identifier);
- break;
- }
-
- if (reply_info != NULL) {
- gf_rdma_reply_info_destroy (reply_info);
- }
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_INVALID_CHUNK_TYPE,
+ "invalid chunktype (%d) specified for sending reply "
+ " (peer:%s)",
+ type, peer->trans->peerinfo.identifier);
+ break;
+ }
+
+ if (reply_info != NULL) {
+ gf_rdma_reply_info_destroy(reply_info);
+ }
out:
- return ret;
+ return ret;
}
-
int32_t
-__gf_rdma_ioq_churn_entry (gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry)
+__gf_rdma_ioq_churn_entry(gf_rdma_peer_t *peer, gf_rdma_ioq_t *entry)
{
- int32_t ret = 0, quota = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- gf_rdma_options_t *options = NULL;
- gf_rdma_post_t *post = NULL;
-
- priv = peer->trans->private;
- options = &priv->options;
- device = priv->device;
-
- quota = __gf_rdma_quota_get (peer);
- if (quota > 0) {
- post = gf_rdma_get_post (&device->sendq);
- if (post == NULL) {
- post = gf_rdma_new_post (peer->trans, device,
- (options->send_size + 2048),
- GF_RDMA_SEND_POST);
- }
-
- if (post == NULL) {
- ret = -1;
- gf_msg_callingfn (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_SEND_FAILED,
- "not able to get a post to send msg");
- goto out;
- }
-
- if (entry->is_request) {
- ret = __gf_rdma_ioq_churn_request (peer, entry, post);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
- "failed to process request ioq entry "
- "to peer(%s)",
- peer->trans->peerinfo.identifier);
- }
- } else {
- ret = __gf_rdma_ioq_churn_reply (peer, entry, post);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
- "failed to process reply ioq entry "
- "to peer (%s)",
- peer->trans->peerinfo.identifier);
- }
- }
+ int32_t ret = 0, quota = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ gf_rdma_options_t *options = NULL;
+ gf_rdma_post_t *post = NULL;
+
+ priv = peer->trans->private;
+ options = &priv->options;
+ device = priv->device;
+
+ quota = __gf_rdma_quota_get(peer);
+ if (quota > 0) {
+ post = gf_rdma_get_post(&device->sendq);
+ if (post == NULL) {
+ post = gf_rdma_new_post(peer->trans, device,
+ (options->send_size + 2048),
+ GF_RDMA_SEND_POST);
+ }
- if (ret != 0) {
- __gf_rdma_ioq_entry_free (entry);
- }
+ if (post == NULL) {
+ ret = -1;
+ gf_msg_callingfn(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_POST_SEND_FAILED,
+ "not able to get a post to send msg");
+ goto out;
+ }
+
+ if (entry->is_request) {
+ ret = __gf_rdma_ioq_churn_request(peer, entry, post);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
+ "failed to process request ioq entry "
+ "to peer(%s)",
+ peer->trans->peerinfo.identifier);
+ }
} else {
- ret = 0;
+ ret = __gf_rdma_ioq_churn_reply(peer, entry, post);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
+ "failed to process reply ioq entry "
+ "to peer (%s)",
+ peer->trans->peerinfo.identifier);
+ }
+ }
+
+ if (ret != 0) {
+ __gf_rdma_ioq_entry_free(entry);
}
+ } else {
+ ret = 0;
+ }
out:
- return ret;
+ return ret;
}
-
static int32_t
-__gf_rdma_ioq_churn (gf_rdma_peer_t *peer)
+__gf_rdma_ioq_churn(gf_rdma_peer_t *peer)
{
- gf_rdma_ioq_t *entry = NULL;
- int32_t ret = 0;
+ gf_rdma_ioq_t *entry = NULL;
+ int32_t ret = 0;
- while (!list_empty (&peer->ioq)) {
- /* pick next entry */
- entry = peer->ioq_next;
+ while (!list_empty(&peer->ioq)) {
+ /* pick next entry */
+ entry = peer->ioq_next;
- ret = __gf_rdma_ioq_churn_entry (peer, entry);
+ ret = __gf_rdma_ioq_churn_entry(peer, entry);
- if (ret <= 0)
- break;
- }
+ if (ret <= 0)
+ break;
+ }
- /*
- list_for_each_entry_safe (entry, dummy, &peer->ioq, list) {
- ret = __gf_rdma_ioq_churn_entry (peer, entry);
- if (ret <= 0) {
- break;
- }
- }
- */
+ /*
+ list_for_each_entry_safe (entry, dummy, &peer->ioq, list) {
+ ret = __gf_rdma_ioq_churn_entry (peer, entry);
+ if (ret <= 0) {
+ break;
+ }
+ }
+ */
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_writev (rpc_transport_t *this, gf_rdma_ioq_t *entry)
+gf_rdma_writev(rpc_transport_t *this, gf_rdma_ioq_t *entry)
{
- int32_t ret = 0, need_append = 1;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_peer_t *peer = NULL;
+ int32_t ret = 0, need_append = 1;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_peer_t *peer = NULL;
- priv = this->private;
- pthread_mutex_lock (&priv->write_mutex);
- {
- if (!priv->connected) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_PEER_DISCONNECTED,
- "rdma is not connected to peer (%s)",
- this->peerinfo.identifier);
- ret = -1;
- goto unlock;
- }
+ priv = this->private;
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ if (!priv->connected) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_PEER_DISCONNECTED,
+ "rdma is not connected to peer (%s)",
+ this->peerinfo.identifier);
+ ret = -1;
+ goto unlock;
+ }
- peer = &priv->peer;
- if (list_empty (&peer->ioq)) {
- ret = __gf_rdma_ioq_churn_entry (peer, entry);
- if (ret != 0) {
- need_append = 0;
-
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
- "processing ioq entry destined"
- " to (%s) failed",
- this->peerinfo.identifier);
- }
- }
- }
+ peer = &priv->peer;
+ if (list_empty(&peer->ioq)) {
+ ret = __gf_rdma_ioq_churn_entry(peer, entry);
+ if (ret != 0) {
+ need_append = 0;
- if (need_append) {
- list_add_tail (&entry->list, &peer->ioq);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ RDMA_MSG_PROC_IOQ_ENTRY_FAILED,
+ "processing ioq entry destined"
+ " to (%s) failed",
+ this->peerinfo.identifier);
}
+ }
}
+
+ if (need_append) {
+ list_add_tail(&entry->list, &peer->ioq);
+ }
+ }
unlock:
- pthread_mutex_unlock (&priv->write_mutex);
- return ret;
+ pthread_mutex_unlock(&priv->write_mutex);
+ return ret;
}
-
gf_rdma_ioq_t *
-gf_rdma_ioq_new (rpc_transport_t *this, rpc_transport_data_t *data)
+gf_rdma_ioq_new(rpc_transport_t *this, rpc_transport_data_t *data)
{
- gf_rdma_ioq_t *entry = NULL;
- int count = 0, i = 0;
- rpc_transport_msg_t *msg = NULL;
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_ioq_t *entry = NULL;
+ int count = 0, i = 0;
+ rpc_transport_msg_t *msg = NULL;
+ gf_rdma_private_t *priv = NULL;
- if ((data == NULL) || (this == NULL)) {
- goto out;
- }
+ if ((data == NULL) || (this == NULL)) {
+ goto out;
+ }
- priv = this->private;
+ priv = this->private;
- entry = mem_get (priv->device->ioq_pool);
- if (entry == NULL) {
- goto out;
- }
- memset (entry, 0, sizeof (*entry));
- entry->pool = priv->device->ioq_pool;
-
- if (data->is_request) {
- msg = &data->data.req.msg;
- if (data->data.req.rsp.rsphdr_count != 0) {
- for (i = 0; i < data->data.req.rsp.rsphdr_count; i++) {
- entry->msg.request.rsphdr_vec[i]
- = data->data.req.rsp.rsphdr[i];
- }
+ entry = mem_get(priv->device->ioq_pool);
+ if (entry == NULL) {
+ goto out;
+ }
+ memset(entry, 0, sizeof(*entry));
+ entry->pool = priv->device->ioq_pool;
- entry->msg.request.rsphdr_count =
- data->data.req.rsp.rsphdr_count;
- }
+ if (data->is_request) {
+ msg = &data->data.req.msg;
+ if (data->data.req.rsp.rsphdr_count != 0) {
+ for (i = 0; i < data->data.req.rsp.rsphdr_count; i++) {
+ entry->msg.request.rsphdr_vec[i] = data->data.req.rsp.rsphdr[i];
+ }
- if (data->data.req.rsp.rsp_payload_count != 0) {
- for (i = 0; i < data->data.req.rsp.rsp_payload_count;
- i++) {
- entry->msg.request.rsp_payload[i]
- = data->data.req.rsp.rsp_payload[i];
- }
+ entry->msg.request.rsphdr_count = data->data.req.rsp.rsphdr_count;
+ }
- entry->msg.request.rsp_payload_count =
- data->data.req.rsp.rsp_payload_count;
- }
+ if (data->data.req.rsp.rsp_payload_count != 0) {
+ for (i = 0; i < data->data.req.rsp.rsp_payload_count; i++) {
+ entry->msg.request.rsp_payload[i] = data->data.req.rsp
+ .rsp_payload[i];
+ }
- entry->msg.request.rpc_req = data->data.req.rpc_req;
+ entry->msg.request.rsp_payload_count = data->data.req.rsp
+ .rsp_payload_count;
+ }
- if (data->data.req.rsp.rsp_iobref != NULL) {
- entry->msg.request.rsp_iobref
- = iobref_ref (data->data.req.rsp.rsp_iobref);
- }
- } else {
- msg = &data->data.reply.msg;
- entry->msg.reply_info = data->data.reply.private;
+ entry->msg.request.rpc_req = data->data.req.rpc_req;
+
+ if (data->data.req.rsp.rsp_iobref != NULL) {
+ entry->msg.request.rsp_iobref = iobref_ref(
+ data->data.req.rsp.rsp_iobref);
}
+ } else {
+ msg = &data->data.reply.msg;
+ entry->msg.reply_info = data->data.reply.private;
+ }
- entry->is_request = data->is_request;
+ entry->is_request = data->is_request;
- count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount;
+ count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount;
- GF_ASSERT (count <= MAX_IOVEC);
+ GF_ASSERT(count <= MAX_IOVEC);
- if (msg->rpchdr != NULL) {
- memcpy (&entry->rpchdr[0], msg->rpchdr,
- sizeof (struct iovec) * msg->rpchdrcount);
- entry->rpchdr_count = msg->rpchdrcount;
- }
+ if (msg->rpchdr != NULL) {
+ memcpy(&entry->rpchdr[0], msg->rpchdr,
+ sizeof(struct iovec) * msg->rpchdrcount);
+ entry->rpchdr_count = msg->rpchdrcount;
+ }
- if (msg->proghdr != NULL) {
- memcpy (&entry->proghdr[0], msg->proghdr,
- sizeof (struct iovec) * msg->proghdrcount);
- entry->proghdr_count = msg->proghdrcount;
- }
+ if (msg->proghdr != NULL) {
+ memcpy(&entry->proghdr[0], msg->proghdr,
+ sizeof(struct iovec) * msg->proghdrcount);
+ entry->proghdr_count = msg->proghdrcount;
+ }
- if (msg->progpayload != NULL) {
- memcpy (&entry->prog_payload[0], msg->progpayload,
- sizeof (struct iovec) * msg->progpayloadcount);
- entry->prog_payload_count = msg->progpayloadcount;
- }
+ if (msg->progpayload != NULL) {
+ memcpy(&entry->prog_payload[0], msg->progpayload,
+ sizeof(struct iovec) * msg->progpayloadcount);
+ entry->prog_payload_count = msg->progpayloadcount;
+ }
- if (msg->iobref != NULL) {
- entry->iobref = iobref_ref (msg->iobref);
- }
+ if (msg->iobref != NULL) {
+ entry->iobref = iobref_ref(msg->iobref);
+ }
- INIT_LIST_HEAD (&entry->list);
+ INIT_LIST_HEAD(&entry->list);
out:
- return entry;
+ return entry;
}
-
int32_t
-gf_rdma_submit_request (rpc_transport_t *this, rpc_transport_req_t *req)
+gf_rdma_submit_request(rpc_transport_t *this, rpc_transport_req_t *req)
{
- int32_t ret = 0;
- gf_rdma_ioq_t *entry = NULL;
- rpc_transport_data_t data = {0, };
- gf_rdma_private_t *priv = NULL;
- gf_rdma_peer_t *peer = NULL;
-
- if (req == NULL) {
- goto out;
- }
-
- priv = this->private;
- if (priv == NULL) {
- ret = -1;
- goto out;
- }
-
- peer = &priv->peer;
- data.is_request = 1;
- data.data.req = *req;
-/*
- * when fist message is received on a transport, quota variable will
- * initiaize and quota_set will set to one. In gluster code client
- * process with respect to transport is the one who sends the first
- * message. Before settng quota_set variable if a submit request is
- * came on server, then the message should not send.
- */
-
- if (priv->entity == GF_RDMA_SERVER && peer->quota_set == 0) {
- ret = 0;
- goto out;
- }
+ int32_t ret = 0;
+ gf_rdma_ioq_t *entry = NULL;
+ rpc_transport_data_t data = {
+ 0,
+ };
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_peer_t *peer = NULL;
+
+ if (req == NULL) {
+ goto out;
+ }
+
+ priv = this->private;
+ if (priv == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ peer = &priv->peer;
+ data.is_request = 1;
+ data.data.req = *req;
+ /*
+ * when fist message is received on a transport, quota variable will
+ * initiaize and quota_set will set to one. In gluster code client
+ * process with respect to transport is the one who sends the first
+ * message. Before settng quota_set variable if a submit request is
+ * came on server, then the message should not send.
+ */
+
+ if (priv->entity == GF_RDMA_SERVER && peer->quota_set == 0) {
+ ret = 0;
+ goto out;
+ }
- entry = gf_rdma_ioq_new (this, &data);
- if (entry == NULL) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_NEW_IOQ_ENTRY_FAILED,
- "getting a new ioq entry failed (peer:%s)",
- this->peerinfo.identifier);
- goto out;
- }
+ entry = gf_rdma_ioq_new(this, &data);
+ if (entry == NULL) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NEW_IOQ_ENTRY_FAILED,
+ "getting a new ioq entry failed (peer:%s)",
+ this->peerinfo.identifier);
+ goto out;
+ }
- ret = gf_rdma_writev (this, entry);
+ ret = gf_rdma_writev(this, entry);
- if (ret > 0) {
- ret = 0;
- } else if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_PEER_FAILED,
- "sending request to peer (%s) failed",
- this->peerinfo.identifier);
- rpc_transport_disconnect (this, _gf_false);
- }
+ if (ret > 0) {
+ ret = 0;
+ } else if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED,
+ "sending request to peer (%s) failed",
+ this->peerinfo.identifier);
+ rpc_transport_disconnect(this, _gf_false);
+ }
out:
- return ret;
+ return ret;
}
int32_t
-gf_rdma_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply)
+gf_rdma_submit_reply(rpc_transport_t *this, rpc_transport_reply_t *reply)
{
- int32_t ret = 0;
- gf_rdma_ioq_t *entry = NULL;
- rpc_transport_data_t data = {0, };
-
- if (reply == NULL) {
- goto out;
- }
-
- data.data.reply = *reply;
-
- entry = gf_rdma_ioq_new (this, &data);
- if (entry == NULL) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_NEW_IOQ_ENTRY_FAILED,
- "getting a new ioq entry failed (peer:%s)",
- this->peerinfo.identifier);
- goto out;
- }
-
- ret = gf_rdma_writev (this, entry);
- if (ret > 0) {
- ret = 0;
- } else if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_WRITE_PEER_FAILED,
- "sending request to peer (%s) failed",
- this->peerinfo.identifier);
- rpc_transport_disconnect (this, _gf_false);
- }
+ int32_t ret = 0;
+ gf_rdma_ioq_t *entry = NULL;
+ rpc_transport_data_t data = {
+ 0,
+ };
+
+ if (reply == NULL) {
+ goto out;
+ }
+
+ data.data.reply = *reply;
+
+ entry = gf_rdma_ioq_new(this, &data);
+ if (entry == NULL) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NEW_IOQ_ENTRY_FAILED,
+ "getting a new ioq entry failed (peer:%s)",
+ this->peerinfo.identifier);
+ goto out;
+ }
+
+ ret = gf_rdma_writev(this, entry);
+ if (ret > 0) {
+ ret = 0;
+ } else if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_WRITE_PEER_FAILED,
+ "sending request to peer (%s) failed",
+ this->peerinfo.identifier);
+ rpc_transport_disconnect(this, _gf_false);
+ }
out:
- return ret;
+ return ret;
}
-
static int
-gf_rdma_register_peer (gf_rdma_device_t *device, int32_t qp_num,
- gf_rdma_peer_t *peer)
+gf_rdma_register_peer(gf_rdma_device_t *device, int32_t qp_num,
+ gf_rdma_peer_t *peer)
{
- struct _qpent *ent = NULL;
- gf_rdma_qpreg_t *qpreg = NULL;
- int32_t hash = 0;
- int ret = -1;
+ struct _qpent *ent = NULL;
+ gf_rdma_qpreg_t *qpreg = NULL;
+ int32_t hash = 0;
+ int ret = -1;
- qpreg = &device->qpreg;
- hash = qp_num % 42;
+ qpreg = &device->qpreg;
+ hash = qp_num % 42;
- pthread_mutex_lock (&qpreg->lock);
- {
- ent = qpreg->ents[hash].next;
- while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) {
- ent = ent->next;
- }
-
- if (ent->qp_num == qp_num) {
- ret = 0;
- goto unlock;
- }
+ pthread_mutex_lock(&qpreg->lock);
+ {
+ ent = qpreg->ents[hash].next;
+ while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) {
+ ent = ent->next;
+ }
- ent = (struct _qpent *) GF_CALLOC (1, sizeof (*ent),
- gf_common_mt_qpent);
- if (ent == NULL) {
- goto unlock;
- }
+ if (ent->qp_num == qp_num) {
+ ret = 0;
+ goto unlock;
+ }
- /* TODO: ref reg->peer */
- ent->peer = peer;
- ent->next = &qpreg->ents[hash];
- ent->prev = ent->next->prev;
- ent->next->prev = ent;
- ent->prev->next = ent;
- ent->qp_num = qp_num;
- qpreg->count++;
- ret = 0;
+ ent = (struct _qpent *)GF_CALLOC(1, sizeof(*ent), gf_common_mt_qpent);
+ if (ent == NULL) {
+ goto unlock;
}
+
+ /* TODO: ref reg->peer */
+ ent->peer = peer;
+ ent->next = &qpreg->ents[hash];
+ ent->prev = ent->next->prev;
+ ent->next->prev = ent;
+ ent->prev->next = ent;
+ ent->qp_num = qp_num;
+ qpreg->count++;
+ ret = 0;
+ }
unlock:
- pthread_mutex_unlock (&qpreg->lock);
+ pthread_mutex_unlock(&qpreg->lock);
- return ret;
+ return ret;
}
-
static void
-gf_rdma_unregister_peer (gf_rdma_device_t *device, int32_t qp_num)
+gf_rdma_unregister_peer(gf_rdma_device_t *device, int32_t qp_num)
{
- struct _qpent *ent = NULL;
- gf_rdma_qpreg_t *qpreg = NULL;
- int32_t hash = 0;
+ struct _qpent *ent = NULL;
+ gf_rdma_qpreg_t *qpreg = NULL;
+ int32_t hash = 0;
- qpreg = &device->qpreg;
- hash = qp_num % 42;
+ qpreg = &device->qpreg;
+ hash = qp_num % 42;
- pthread_mutex_lock (&qpreg->lock);
- {
- ent = qpreg->ents[hash].next;
- while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num))
- ent = ent->next;
- if (ent->qp_num != qp_num) {
- pthread_mutex_unlock (&qpreg->lock);
- return;
- }
- ent->prev->next = ent->next;
- ent->next->prev = ent->prev;
- /* TODO: unref reg->peer */
- GF_FREE (ent);
- qpreg->count--;
- }
- pthread_mutex_unlock (&qpreg->lock);
+ pthread_mutex_lock(&qpreg->lock);
+ {
+ ent = qpreg->ents[hash].next;
+ while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num))
+ ent = ent->next;
+ if (ent->qp_num != qp_num) {
+ pthread_mutex_unlock(&qpreg->lock);
+ return;
+ }
+ ent->prev->next = ent->next;
+ ent->next->prev = ent->prev;
+ /* TODO: unref reg->peer */
+ GF_FREE(ent);
+ qpreg->count--;
+ }
+ pthread_mutex_unlock(&qpreg->lock);
}
-
static gf_rdma_peer_t *
-__gf_rdma_lookup_peer (gf_rdma_device_t *device, int32_t qp_num)
+__gf_rdma_lookup_peer(gf_rdma_device_t *device, int32_t qp_num)
{
- struct _qpent *ent = NULL;
- gf_rdma_peer_t *peer = NULL;
- gf_rdma_qpreg_t *qpreg = NULL;
- int32_t hash = 0;
-
- qpreg = &device->qpreg;
- hash = qp_num % 42;
- ent = qpreg->ents[hash].next;
- while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num))
- ent = ent->next;
-
- if (ent != &qpreg->ents[hash]) {
- peer = ent->peer;
- }
-
- return peer;
+ struct _qpent *ent = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ gf_rdma_qpreg_t *qpreg = NULL;
+ int32_t hash = 0;
+
+ qpreg = &device->qpreg;
+ hash = qp_num % 42;
+ ent = qpreg->ents[hash].next;
+ while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num))
+ ent = ent->next;
+
+ if (ent != &qpreg->ents[hash]) {
+ peer = ent->peer;
+ }
+
+ return peer;
}
-
static void
-__gf_rdma_destroy_qp (rpc_transport_t *this)
+__gf_rdma_destroy_qp(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
+ gf_rdma_private_t *priv = NULL;
- priv = this->private;
- if (priv->peer.qp) {
- gf_rdma_unregister_peer (priv->device, priv->peer.qp->qp_num);
- rdma_destroy_qp (priv->peer.cm_id);
- }
- priv->peer.qp = NULL;
+ priv = this->private;
+ if (priv->peer.qp) {
+ gf_rdma_unregister_peer(priv->device, priv->peer.qp->qp_num);
+ rdma_destroy_qp(priv->peer.cm_id);
+ }
+ priv->peer.qp = NULL;
- return;
+ return;
}
-
static int32_t
-gf_rdma_create_qp (rpc_transport_t *this)
+gf_rdma_create_qp(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_device_t *device = NULL;
- int32_t ret = 0;
- gf_rdma_peer_t *peer = NULL;
- char *device_name = NULL;
-
- priv = this->private;
-
- peer = &priv->peer;
-
- device_name = (char *)ibv_get_device_name (peer->cm_id->verbs->device);
- if (device_name == NULL) {
- ret = -1;
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_DEVICE_NAME_FAILED, "cannot get "
- "device_name");
- goto out;
- }
-
- device = gf_rdma_get_device (this, peer->cm_id->verbs,
- device_name);
- if (device == NULL) {
- ret = -1;
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_DEVICE_FAILED, "cannot get device for "
- "device %s", device_name);
- goto out;
- }
-
- if (priv->device == NULL) {
- priv->device = device;
- }
-
- struct ibv_qp_init_attr init_attr = {
- .send_cq = device->send_cq,
- .recv_cq = device->recv_cq,
- .srq = device->srq,
- .cap = {
- .max_send_wr = peer->send_count,
- .max_recv_wr = peer->recv_count,
- .max_send_sge = 2,
- .max_recv_sge = 1
- },
- .qp_type = IBV_QPT_RC
- };
-
- ret = rdma_create_qp(peer->cm_id, device->pd, &init_attr);
- if (ret != 0) {
- gf_msg (peer->trans->name, GF_LOG_CRITICAL, errno,
- RDMA_MSG_CREAT_QP_FAILED, "%s: could not create QP",
- this->name);
- ret = -1;
- goto out;
- }
-
- peer->qp = peer->cm_id->qp;
-
- ret = gf_rdma_register_peer (device, peer->qp->qp_num, peer);
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_device_t *device = NULL;
+ int32_t ret = 0;
+ gf_rdma_peer_t *peer = NULL;
+ char *device_name = NULL;
+
+ priv = this->private;
+
+ peer = &priv->peer;
+
+ device_name = (char *)ibv_get_device_name(peer->cm_id->verbs->device);
+ if (device_name == NULL) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_DEVICE_NAME_FAILED,
+ "cannot get "
+ "device_name");
+ goto out;
+ }
+
+ device = gf_rdma_get_device(this, peer->cm_id->verbs, device_name);
+ if (device == NULL) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_GET_DEVICE_FAILED,
+ "cannot get device for "
+ "device %s",
+ device_name);
+ goto out;
+ }
+
+ if (priv->device == NULL) {
+ priv->device = device;
+ }
+
+ struct ibv_qp_init_attr init_attr = {
+ .send_cq = device->send_cq,
+ .recv_cq = device->recv_cq,
+ .srq = device->srq,
+ .cap = {.max_send_wr = peer->send_count,
+ .max_recv_wr = peer->recv_count,
+ .max_send_sge = 2,
+ .max_recv_sge = 1},
+ .qp_type = IBV_QPT_RC};
+
+ ret = rdma_create_qp(peer->cm_id, device->pd, &init_attr);
+ if (ret != 0) {
+ gf_msg(peer->trans->name, GF_LOG_CRITICAL, errno,
+ RDMA_MSG_CREAT_QP_FAILED, "%s: could not create QP", this->name);
+ ret = -1;
+ goto out;
+ }
+
+ peer->qp = peer->cm_id->qp;
+
+ ret = gf_rdma_register_peer(device, peer->qp->qp_num, peer);
out:
- if (ret == -1)
- __gf_rdma_destroy_qp (this);
+ if (ret == -1)
+ __gf_rdma_destroy_qp(this);
- return ret;
+ return ret;
}
-
static int32_t
-__gf_rdma_teardown (rpc_transport_t *this)
+__gf_rdma_teardown(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_peer_t *peer = NULL;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_peer_t *peer = NULL;
- priv = this->private;
- peer = &priv->peer;
+ priv = this->private;
+ peer = &priv->peer;
- if (peer->cm_id && peer->cm_id->qp != NULL) {
- __gf_rdma_destroy_qp (this);
- }
+ if (peer->cm_id && peer->cm_id->qp != NULL) {
+ __gf_rdma_destroy_qp(this);
+ }
- if (!list_empty (&priv->peer.ioq)) {
- __gf_rdma_ioq_flush (peer);
- }
+ if (!list_empty(&priv->peer.ioq)) {
+ __gf_rdma_ioq_flush(peer);
+ }
- if (peer->cm_id != NULL) {
- rdma_destroy_id (peer->cm_id);
- peer->cm_id = NULL;
- }
+ if (peer->cm_id != NULL) {
+ rdma_destroy_id(peer->cm_id);
+ peer->cm_id = NULL;
+ }
- /* TODO: decrement cq size */
- return 0;
+ /* TODO: decrement cq size */
+ return 0;
}
-
static int32_t
-gf_rdma_teardown (rpc_transport_t *this)
+gf_rdma_teardown(rpc_transport_t *this)
{
- int32_t ret = 0;
- gf_rdma_private_t *priv = NULL;
+ int32_t ret = 0;
+ gf_rdma_private_t *priv = NULL;
- if (this == NULL) {
- goto out;
- }
+ if (this == NULL) {
+ goto out;
+ }
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->write_mutex);
- {
- ret = __gf_rdma_teardown (this);
- }
- pthread_mutex_unlock (&priv->write_mutex);
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ ret = __gf_rdma_teardown(this);
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
out:
- return ret;
+ return ret;
}
-
/*
* allocates new memory to hold write-chunklist. New memory is needed since
* write-chunklist will be used while sending reply and the post holding initial
@@ -3334,1756 +3201,1704 @@ out:
* event is sent to upper layers.
*/
int32_t
-gf_rdma_get_write_chunklist (char **ptr, gf_rdma_write_array_t **write_ary)
+gf_rdma_get_write_chunklist(char **ptr, gf_rdma_write_array_t **write_ary)
{
- gf_rdma_write_array_t *from = NULL, *to = NULL;
- int32_t ret = -1, size = 0, i = 0;
-
- from = (gf_rdma_write_array_t *) *ptr;
- if (from->wc_discrim == 0) {
- ret = 0;
- goto out;
- }
-
- from->wc_nchunks = ntoh32 (from->wc_nchunks);
-
- size = sizeof (*from)
- + (sizeof (gf_rdma_write_chunk_t) * from->wc_nchunks);
-
- to = GF_CALLOC (1, size, gf_common_mt_char);
- if (to == NULL) {
- ret = -1;
- goto out;
- }
-
- to->wc_discrim = ntoh32 (from->wc_discrim);
- to->wc_nchunks = from->wc_nchunks;
+ gf_rdma_write_array_t *from = NULL, *to = NULL;
+ int32_t ret = -1, size = 0, i = 0;
- for (i = 0; i < to->wc_nchunks; i++) {
- to->wc_array[i].wc_target.rs_handle
- = ntoh32 (from->wc_array[i].wc_target.rs_handle);
- to->wc_array[i].wc_target.rs_length
- = ntoh32 (from->wc_array[i].wc_target.rs_length);
- to->wc_array[i].wc_target.rs_offset
- = ntoh64 (from->wc_array[i].wc_target.rs_offset);
- }
-
- *write_ary = to;
+ from = (gf_rdma_write_array_t *)*ptr;
+ if (from->wc_discrim == 0) {
ret = 0;
- *ptr = (char *)&from->wc_array[i].wc_target.rs_handle;
+ goto out;
+ }
+
+ from->wc_nchunks = ntoh32(from->wc_nchunks);
+
+ size = sizeof(*from) + (sizeof(gf_rdma_write_chunk_t) * from->wc_nchunks);
+
+ to = GF_CALLOC(1, size, gf_common_mt_char);
+ if (to == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ to->wc_discrim = ntoh32(from->wc_discrim);
+ to->wc_nchunks = from->wc_nchunks;
+
+ for (i = 0; i < to->wc_nchunks; i++) {
+ to->wc_array[i].wc_target.rs_handle = ntoh32(
+ from->wc_array[i].wc_target.rs_handle);
+ to->wc_array[i].wc_target.rs_length = ntoh32(
+ from->wc_array[i].wc_target.rs_length);
+ to->wc_array[i].wc_target.rs_offset = ntoh64(
+ from->wc_array[i].wc_target.rs_offset);
+ }
+
+ *write_ary = to;
+ ret = 0;
+ *ptr = (char *)&from->wc_array[i].wc_target.rs_handle;
out:
- return ret;
+ return ret;
}
-
/*
* does not allocate new memory to hold read-chunklist. New memory is not
* needed, since post is not put back to srq till we've completed all the
* rdma-reads and hence readchunk-list can point to memory held by post.
*/
int32_t
-gf_rdma_get_read_chunklist (char **ptr, gf_rdma_read_chunk_t **readch)
+gf_rdma_get_read_chunklist(char **ptr, gf_rdma_read_chunk_t **readch)
{
- int32_t ret = -1;
- gf_rdma_read_chunk_t *chunk = NULL;
- int i = 0;
-
- chunk = (gf_rdma_read_chunk_t *)*ptr;
- if (chunk[0].rc_discrim == 0) {
- ret = 0;
- goto out;
- }
+ int32_t ret = -1;
+ gf_rdma_read_chunk_t *chunk = NULL;
+ int i = 0;
- for (i = 0; chunk[i].rc_discrim != 0; i++) {
- chunk[i].rc_discrim = ntoh32 (chunk[i].rc_discrim);
- chunk[i].rc_position = ntoh32 (chunk[i].rc_position);
- chunk[i].rc_target.rs_handle
- = ntoh32 (chunk[i].rc_target.rs_handle);
- chunk[i].rc_target.rs_length
- = ntoh32 (chunk[i].rc_target.rs_length);
- chunk[i].rc_target.rs_offset
- = ntoh64 (chunk[i].rc_target.rs_offset);
- }
-
- *readch = &chunk[0];
+ chunk = (gf_rdma_read_chunk_t *)*ptr;
+ if (chunk[0].rc_discrim == 0) {
ret = 0;
- *ptr = (char *)&chunk[i].rc_discrim;
+ goto out;
+ }
+
+ for (i = 0; chunk[i].rc_discrim != 0; i++) {
+ chunk[i].rc_discrim = ntoh32(chunk[i].rc_discrim);
+ chunk[i].rc_position = ntoh32(chunk[i].rc_position);
+ chunk[i].rc_target.rs_handle = ntoh32(chunk[i].rc_target.rs_handle);
+ chunk[i].rc_target.rs_length = ntoh32(chunk[i].rc_target.rs_length);
+ chunk[i].rc_target.rs_offset = ntoh64(chunk[i].rc_target.rs_offset);
+ }
+
+ *readch = &chunk[0];
+ ret = 0;
+ *ptr = (char *)&chunk[i].rc_discrim;
out:
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_decode_error_msg (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- size_t bytes_in_post)
+gf_rdma_decode_error_msg(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ size_t bytes_in_post)
{
- gf_rdma_header_t *header = NULL;
- struct iobuf *iobuf = NULL;
- struct iobref *iobref = NULL;
- int32_t ret = -1;
- struct rpc_msg rpc_msg = {0, };
-
- header = (gf_rdma_header_t *)post->buf;
- header->rm_body.rm_error.rm_type
- = ntoh32 (header->rm_body.rm_error.rm_type);
- if (header->rm_body.rm_error.rm_type == ERR_VERS) {
- header->rm_body.rm_error.rm_version.gf_rdma_vers_low =
- ntoh32 (header->rm_body.rm_error.rm_version.gf_rdma_vers_low);
- header->rm_body.rm_error.rm_version.gf_rdma_vers_high =
- ntoh32 (header->rm_body.rm_error.rm_version.gf_rdma_vers_high);
- }
-
- rpc_msg.rm_xid = header->rm_xid;
- rpc_msg.rm_direction = REPLY;
- rpc_msg.rm_reply.rp_stat = MSG_DENIED;
-
- iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool, bytes_in_post);
- if (iobuf == NULL) {
- ret = -1;
- goto out;
- }
-
- post->ctx.iobref = iobref = iobref_new ();
- if (iobref == NULL) {
- ret = -1;
- goto out;
- }
-
- iobref_add (iobref, iobuf);
- iobuf_unref (iobuf);
-
- ret = rpc_reply_to_xdr (&rpc_msg, iobuf_ptr (iobuf),
- iobuf_pagesize (iobuf), &post->ctx.vector[0]);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_RPC_REPLY_CREATE_FAILED, "Failed to create "
- "RPC reply");
- goto out;
- }
-
- post->ctx.count = 1;
-
- iobuf = NULL;
- iobref = NULL;
+ gf_rdma_header_t *header = NULL;
+ struct iobuf *iobuf = NULL;
+ struct iobref *iobref = NULL;
+ int32_t ret = -1;
+ struct rpc_msg rpc_msg = {
+ 0,
+ };
+
+ header = (gf_rdma_header_t *)post->buf;
+ header->rm_body.rm_error.rm_type = ntoh32(header->rm_body.rm_error.rm_type);
+ if (header->rm_body.rm_error.rm_type == ERR_VERS) {
+ header->rm_body.rm_error.rm_version.gf_rdma_vers_low = ntoh32(
+ header->rm_body.rm_error.rm_version.gf_rdma_vers_low);
+ header->rm_body.rm_error.rm_version.gf_rdma_vers_high = ntoh32(
+ header->rm_body.rm_error.rm_version.gf_rdma_vers_high);
+ }
+
+ rpc_msg.rm_xid = header->rm_xid;
+ rpc_msg.rm_direction = REPLY;
+ rpc_msg.rm_reply.rp_stat = MSG_DENIED;
+
+ iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool, bytes_in_post);
+ if (iobuf == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ post->ctx.iobref = iobref = iobref_new();
+ if (iobref == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ iobref_add(iobref, iobuf);
+ iobuf_unref(iobuf);
+
+ ret = rpc_reply_to_xdr(&rpc_msg, iobuf_ptr(iobuf), iobuf_pagesize(iobuf),
+ &post->ctx.vector[0]);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_RPC_REPLY_CREATE_FAILED,
+ "Failed to create "
+ "RPC reply");
+ goto out;
+ }
+
+ post->ctx.count = 1;
+
+ iobuf = NULL;
+ iobref = NULL;
out:
- if (ret == -1) {
- if (iobuf != NULL) {
- iobuf_unref (iobuf);
- }
+ if (ret == -1) {
+ if (iobuf != NULL) {
+ iobuf_unref(iobuf);
+ }
- if (iobref != NULL) {
- iobref_unref (iobref);
- }
+ if (iobref != NULL) {
+ iobref_unref(iobref);
}
+ }
- return 0;
+ return 0;
}
-
int32_t
-gf_rdma_decode_msg (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- gf_rdma_read_chunk_t **readch, size_t bytes_in_post)
+gf_rdma_decode_msg(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ gf_rdma_read_chunk_t **readch, size_t bytes_in_post)
{
- int32_t ret = -1;
- gf_rdma_header_t *header = NULL;
- gf_rdma_reply_info_t *reply_info = NULL;
- char *ptr = NULL;
- gf_rdma_write_array_t *write_ary = NULL;
- size_t header_len = 0;
-
- header = (gf_rdma_header_t *)post->buf;
-
- ptr = (char *)&header->rm_body.rm_chunks[0];
-
- ret = gf_rdma_get_read_chunklist (&ptr, readch);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_READ_CHUNK_FAILED, "cannot get read "
- "chunklist from msg");
- goto out;
+ int32_t ret = -1;
+ gf_rdma_header_t *header = NULL;
+ gf_rdma_reply_info_t *reply_info = NULL;
+ char *ptr = NULL;
+ gf_rdma_write_array_t *write_ary = NULL;
+ size_t header_len = 0;
+
+ header = (gf_rdma_header_t *)post->buf;
+
+ ptr = (char *)&header->rm_body.rm_chunks[0];
+
+ ret = gf_rdma_get_read_chunklist(&ptr, readch);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_GET_READ_CHUNK_FAILED,
+ "cannot get read "
+ "chunklist from msg");
+ goto out;
+ }
+
+ /* skip terminator of read-chunklist */
+ ptr = ptr + sizeof(uint32_t);
+
+ ret = gf_rdma_get_write_chunklist(&ptr, &write_ary);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_GET_WRITE_CHUNK_FAILED,
+ "cannot get write "
+ "chunklist from msg");
+ goto out;
+ }
+
+ /* skip terminator of write-chunklist */
+ ptr = ptr + sizeof(uint32_t);
+
+ if (write_ary != NULL) {
+ reply_info = gf_rdma_reply_info_alloc(peer);
+ if (reply_info == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_REPLY_INFO_ALLOC_FAILED, "reply_info_alloc failed");
+ ret = -1;
+ goto out;
}
- /* skip terminator of read-chunklist */
- ptr = ptr + sizeof (uint32_t);
-
- ret = gf_rdma_get_write_chunklist (&ptr, &write_ary);
+ reply_info->type = gf_rdma_writech;
+ reply_info->wc_array = write_ary;
+ reply_info->rm_xid = header->rm_xid;
+ } else {
+ ret = gf_rdma_get_write_chunklist(&ptr, &write_ary);
if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_GET_WRITE_CHUNK_FAILED, "cannot get write "
- "chunklist from msg");
- goto out;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_CHUNKLIST_ERROR,
+ "cannot get reply "
+ "chunklist from msg");
+ goto out;
}
- /* skip terminator of write-chunklist */
- ptr = ptr + sizeof (uint32_t);
-
if (write_ary != NULL) {
- reply_info = gf_rdma_reply_info_alloc (peer);
- if (reply_info == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_REPLY_INFO_ALLOC_FAILED,
- "reply_info_alloc failed");
- ret = -1;
- goto out;
- }
-
- reply_info->type = gf_rdma_writech;
- reply_info->wc_array = write_ary;
- reply_info->rm_xid = header->rm_xid;
- } else {
- ret = gf_rdma_get_write_chunklist (&ptr, &write_ary);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_CHUNKLIST_ERROR, "cannot get reply "
- "chunklist from msg");
- goto out;
- }
-
- if (write_ary != NULL) {
- reply_info = gf_rdma_reply_info_alloc (peer);
- if (reply_info == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_REPLY_INFO_ALLOC_FAILED,
- "reply_info_alloc_failed");
- ret = -1;
- goto out;
- }
+ reply_info = gf_rdma_reply_info_alloc(peer);
+ if (reply_info == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_REPLY_INFO_ALLOC_FAILED,
+ "reply_info_alloc_failed");
+ ret = -1;
+ goto out;
+ }
- reply_info->type = gf_rdma_replych;
- reply_info->wc_array = write_ary;
- reply_info->rm_xid = header->rm_xid;
- }
+ reply_info->type = gf_rdma_replych;
+ reply_info->wc_array = write_ary;
+ reply_info->rm_xid = header->rm_xid;
}
+ }
- /* skip terminator of reply chunk */
- ptr = ptr + sizeof (uint32_t);
- if (header->rm_type != GF_RDMA_NOMSG) {
- header_len = (long)ptr - (long)post->buf;
- post->ctx.vector[0].iov_len = (bytes_in_post - header_len);
-
- post->ctx.hdr_iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool,
- (bytes_in_post - header_len));
- if (post->ctx.hdr_iobuf == NULL) {
- ret = -1;
- goto out;
- }
+ /* skip terminator of reply chunk */
+ ptr = ptr + sizeof(uint32_t);
+ if (header->rm_type != GF_RDMA_NOMSG) {
+ header_len = (long)ptr - (long)post->buf;
+ post->ctx.vector[0].iov_len = (bytes_in_post - header_len);
- post->ctx.vector[0].iov_base = iobuf_ptr (post->ctx.hdr_iobuf);
- memcpy (post->ctx.vector[0].iov_base, ptr,
- post->ctx.vector[0].iov_len);
- post->ctx.count = 1;
+ post->ctx.hdr_iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool,
+ (bytes_in_post - header_len));
+ if (post->ctx.hdr_iobuf == NULL) {
+ ret = -1;
+ goto out;
}
- post->ctx.reply_info = reply_info;
-out:
- if (ret == -1) {
- if (*readch != NULL) {
- GF_FREE (*readch);
- *readch = NULL;
- }
+ post->ctx.vector[0].iov_base = iobuf_ptr(post->ctx.hdr_iobuf);
+ memcpy(post->ctx.vector[0].iov_base, ptr, post->ctx.vector[0].iov_len);
+ post->ctx.count = 1;
+ }
- GF_FREE (write_ary);
+ post->ctx.reply_info = reply_info;
+out:
+ if (ret == -1) {
+ if (*readch != NULL) {
+ GF_FREE(*readch);
+ *readch = NULL;
}
- return ret;
-}
+ GF_FREE(write_ary);
+ }
+ return ret;
+}
/* Assumes only one of either write-chunklist or a reply chunk is present */
int32_t
-gf_rdma_decode_header (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- gf_rdma_read_chunk_t **readch, size_t bytes_in_post)
+gf_rdma_decode_header(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ gf_rdma_read_chunk_t **readch, size_t bytes_in_post)
{
- int32_t ret = -1;
- gf_rdma_header_t *header = NULL;
+ int32_t ret = -1;
+ gf_rdma_header_t *header = NULL;
- header = (gf_rdma_header_t *)post->buf;
+ header = (gf_rdma_header_t *)post->buf;
- header->rm_xid = ntoh32 (header->rm_xid);
- header->rm_vers = ntoh32 (header->rm_vers);
- header->rm_credit = ntoh32 (header->rm_credit);
- header->rm_type = ntoh32 (header->rm_type);
+ header->rm_xid = ntoh32(header->rm_xid);
+ header->rm_vers = ntoh32(header->rm_vers);
+ header->rm_credit = ntoh32(header->rm_credit);
+ header->rm_type = ntoh32(header->rm_type);
- switch (header->rm_type) {
+ switch (header->rm_type) {
case GF_RDMA_MSG:
case GF_RDMA_NOMSG:
- ret = gf_rdma_decode_msg (peer, post, readch, bytes_in_post);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_ENCODE_ERROR, "cannot decode msg of "
- "type (%d)", header->rm_type);
- }
+ ret = gf_rdma_decode_msg(peer, post, readch, bytes_in_post);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_ENCODE_ERROR,
+ "cannot decode msg of "
+ "type (%d)",
+ header->rm_type);
+ }
- break;
+ break;
case GF_RDMA_MSGP:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_ENTRY, "rdma msg of msg-type "
- "GF_RDMA_MSGP should not have been received");
- ret = -1;
- break;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY,
+ "rdma msg of msg-type "
+ "GF_RDMA_MSGP should not have been received");
+ ret = -1;
+ break;
case GF_RDMA_DONE:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_ENTRY, "rdma msg of msg-type "
- "GF_RDMA_DONE should not have been received");
- ret = -1;
- break;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY,
+ "rdma msg of msg-type "
+ "GF_RDMA_DONE should not have been received");
+ ret = -1;
+ break;
case GF_RDMA_ERROR:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_RDMA_ERROR_RECEIVED, "received a msg of type"
- " RDMA_ERROR");
- ret = gf_rdma_decode_error_msg (peer, post, bytes_in_post);
- break;
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_RDMA_ERROR_RECEIVED,
+ "received a msg of type"
+ " RDMA_ERROR");
+ ret = gf_rdma_decode_error_msg(peer, post, bytes_in_post);
+ break;
default:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_ENTRY, "unknown rdma msg-type (%d)",
- header->rm_type);
- }
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY,
+ "unknown rdma msg-type (%d)", header->rm_type);
+ }
- return ret;
+ return ret;
}
-
int32_t
-gf_rdma_do_reads (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- gf_rdma_read_chunk_t *readch)
+gf_rdma_do_reads(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ gf_rdma_read_chunk_t *readch)
{
- int32_t ret = -1, i = 0, count = 0;
- size_t size = 0;
- char *ptr = NULL;
- struct iobuf *iobuf = NULL;
- gf_rdma_private_t *priv = NULL;
- struct ibv_sge *list = NULL;
- struct ibv_send_wr *wr = NULL, *bad_wr = NULL;
- int total_ref = 0;
- priv = peer->trans->private;
-
- for (i = 0; readch[i].rc_discrim != 0; i++) {
- size += readch[i].rc_target.rs_length;
- }
-
- if (i == 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_CHUNK_TYPE, "message type specified "
- "as rdma-read but there are no rdma read-chunks "
- "present");
- goto out;
- }
-
- post->ctx.gf_rdma_reads = i;
- i = 0;
- iobuf = iobuf_get2 (peer->trans->ctx->iobuf_pool, size);
- if (iobuf == NULL) {
- goto out;
- }
-
+ int32_t ret = -1, i = 0, count = 0;
+ size_t size = 0;
+ char *ptr = NULL;
+ struct iobuf *iobuf = NULL;
+ gf_rdma_private_t *priv = NULL;
+ struct ibv_sge *list = NULL;
+ struct ibv_send_wr *wr = NULL, *bad_wr = NULL;
+ int total_ref = 0;
+ priv = peer->trans->private;
+
+ for (i = 0; readch[i].rc_discrim != 0; i++) {
+ size += readch[i].rc_target.rs_length;
+ }
+
+ if (i == 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_CHUNK_TYPE,
+ "message type specified "
+ "as rdma-read but there are no rdma read-chunks "
+ "present");
+ goto out;
+ }
+
+ post->ctx.gf_rdma_reads = i;
+ i = 0;
+ iobuf = iobuf_get2(peer->trans->ctx->iobuf_pool, size);
+ if (iobuf == NULL) {
+ goto out;
+ }
+
+ if (post->ctx.iobref == NULL) {
+ post->ctx.iobref = iobref_new();
if (post->ctx.iobref == NULL) {
- post->ctx.iobref = iobref_new ();
- if (post->ctx.iobref == NULL) {
- iobuf_unref (iobuf);
- iobuf = NULL;
- goto out;
- }
+ iobuf_unref(iobuf);
+ iobuf = NULL;
+ goto out;
}
+ }
- iobref_add (post->ctx.iobref, iobuf);
- iobuf_unref (iobuf);
+ iobref_add(post->ctx.iobref, iobuf);
+ iobuf_unref(iobuf);
- ptr = iobuf_ptr (iobuf);
- iobuf = NULL;
+ ptr = iobuf_ptr(iobuf);
+ iobuf = NULL;
- pthread_mutex_lock (&priv->write_mutex);
- {
- if (!priv->connected) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PEER_DISCONNECTED, "transport not "
- "connected to peer (%s), not doing rdma reads",
- peer->trans->peerinfo.identifier);
- goto unlock;
- }
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ if (!priv->connected) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PEER_DISCONNECTED,
+ "transport not "
+ "connected to peer (%s), not doing rdma reads",
+ peer->trans->peerinfo.identifier);
+ goto unlock;
+ }
- list = GF_CALLOC (post->ctx.gf_rdma_reads,
- sizeof (struct ibv_sge), gf_common_mt_sge);
+ list = GF_CALLOC(post->ctx.gf_rdma_reads, sizeof(struct ibv_sge),
+ gf_common_mt_sge);
- if (list == NULL) {
- errno = ENOMEM;
- ret = -1;
- goto unlock;
- }
- wr = GF_CALLOC (post->ctx.gf_rdma_reads,
- sizeof (struct ibv_send_wr), gf_common_mt_wr);
- if (wr == NULL) {
- errno = ENOMEM;
- ret = -1;
- goto unlock;
- }
- for (i = 0; readch[i].rc_discrim != 0; i++) {
- count = post->ctx.count++;
- post->ctx.vector[count].iov_base = ptr;
- post->ctx.vector[count].iov_len
- = readch[i].rc_target.rs_length;
-
- ret = __gf_rdma_register_local_mr_for_rdma (peer,
- &post->ctx.vector[count], 1, &post->ctx);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_MR_ALOC_FAILED,
- "registering local memory"
- " for rdma read failed");
- goto unlock;
- }
-
- list[i].addr = (unsigned long)
- post->ctx.vector[count].iov_base;
- list[i].length = post->ctx.vector[count].iov_len;
- list[i].lkey =
- post->ctx.mr[post->ctx.mr_count - 1]->lkey;
-
- wr[i].wr_id =
- (unsigned long) gf_rdma_post_ref (post);
- wr[i].sg_list = &list[i];
- wr[i].next = &wr[i+1];
- wr[i].num_sge = 1;
- wr[i].opcode = IBV_WR_RDMA_READ;
- wr[i].send_flags = IBV_SEND_SIGNALED;
- wr[i].wr.rdma.remote_addr =
- readch[i].rc_target.rs_offset;
- wr[i].wr.rdma.rkey = readch[i].rc_target.rs_handle;
-
- ptr += readch[i].rc_target.rs_length;
- total_ref++;
- }
- wr[i-1].next = NULL;
- ret = ibv_post_send (peer->qp, wr, &bad_wr);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_READ_CLIENT_ERROR, "rdma read from "
- "client (%s) failed with ret = %d (%s)",
- peer->trans->peerinfo.identifier,
- ret, (ret > 0) ? strerror (ret) : "");
-
- if (!bad_wr) {
- ret = -1;
- goto unlock;
- }
-
- for (i = 0; i < post->ctx.gf_rdma_reads; i++) {
- if (&wr[i] != bad_wr)
- total_ref--;
- else
- break;
- }
+ if (list == NULL) {
+ errno = ENOMEM;
+ ret = -1;
+ goto unlock;
+ }
+ wr = GF_CALLOC(post->ctx.gf_rdma_reads, sizeof(struct ibv_send_wr),
+ gf_common_mt_wr);
+ if (wr == NULL) {
+ errno = ENOMEM;
+ ret = -1;
+ goto unlock;
+ }
+ for (i = 0; readch[i].rc_discrim != 0; i++) {
+ count = post->ctx.count++;
+ post->ctx.vector[count].iov_base = ptr;
+ post->ctx.vector[count].iov_len = readch[i].rc_target.rs_length;
+
+ ret = __gf_rdma_register_local_mr_for_rdma(
+ peer, &post->ctx.vector[count], 1, &post->ctx);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_MR_ALOC_FAILED,
+ "registering local memory"
+ " for rdma read failed");
+ goto unlock;
+ }
+
+ list[i].addr = (unsigned long)post->ctx.vector[count].iov_base;
+ list[i].length = post->ctx.vector[count].iov_len;
+ list[i].lkey = post->ctx.mr[post->ctx.mr_count - 1]->lkey;
+
+ wr[i].wr_id = (unsigned long)gf_rdma_post_ref(post);
+ wr[i].sg_list = &list[i];
+ wr[i].next = &wr[i + 1];
+ wr[i].num_sge = 1;
+ wr[i].opcode = IBV_WR_RDMA_READ;
+ wr[i].send_flags = IBV_SEND_SIGNALED;
+ wr[i].wr.rdma.remote_addr = readch[i].rc_target.rs_offset;
+ wr[i].wr.rdma.rkey = readch[i].rc_target.rs_handle;
+
+ ptr += readch[i].rc_target.rs_length;
+ total_ref++;
+ }
+ wr[i - 1].next = NULL;
+ ret = ibv_post_send(peer->qp, wr, &bad_wr);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_READ_CLIENT_ERROR,
+ "rdma read from "
+ "client (%s) failed with ret = %d (%s)",
+ peer->trans->peerinfo.identifier, ret,
+ (ret > 0) ? strerror(ret) : "");
+
+ if (!bad_wr) {
+ ret = -1;
+ goto unlock;
+ }
- ret = -1;
- }
+ for (i = 0; i < post->ctx.gf_rdma_reads; i++) {
+ if (&wr[i] != bad_wr)
+ total_ref--;
+ else
+ break;
+ }
+ ret = -1;
}
+ }
unlock:
- pthread_mutex_unlock (&priv->write_mutex);
+ pthread_mutex_unlock(&priv->write_mutex);
out:
- if (list)
- GF_FREE (list);
- if (wr)
- GF_FREE (wr);
+ if (list)
+ GF_FREE(list);
+ if (wr)
+ GF_FREE(wr);
- if (ret == -1) {
- while (total_ref-- > 0)
- gf_rdma_post_unref (post);
+ if (ret == -1) {
+ while (total_ref-- > 0)
+ gf_rdma_post_unref(post);
+ }
- }
-
- return ret;
+ return ret;
}
-
int32_t
-gf_rdma_pollin_notify (gf_rdma_peer_t *peer, gf_rdma_post_t *post)
+gf_rdma_pollin_notify(gf_rdma_peer_t *peer, gf_rdma_post_t *post)
{
- int32_t ret = -1;
- enum msg_type msg_type = 0;
- struct rpc_req *rpc_req = NULL;
- gf_rdma_request_context_t *request_context = NULL;
- rpc_request_info_t request_info = {0, };
- gf_rdma_private_t *priv = NULL;
- uint32_t *ptr = NULL;
- rpc_transport_pollin_t *pollin = NULL;
-
- if ((peer == NULL) || (post == NULL)) {
- goto out;
- }
-
+ int32_t ret = -1;
+ enum msg_type msg_type = 0;
+ struct rpc_req *rpc_req = NULL;
+ gf_rdma_request_context_t *request_context = NULL;
+ rpc_request_info_t request_info = {
+ 0,
+ };
+ gf_rdma_private_t *priv = NULL;
+ uint32_t *ptr = NULL;
+ rpc_transport_pollin_t *pollin = NULL;
+
+ if ((peer == NULL) || (post == NULL)) {
+ goto out;
+ }
+
+ if (post->ctx.iobref == NULL) {
+ post->ctx.iobref = iobref_new();
if (post->ctx.iobref == NULL) {
- post->ctx.iobref = iobref_new ();
- if (post->ctx.iobref == NULL) {
- goto out;
- }
-
- /* handling the case where both hdr and payload of
- * GF_FOP_READ_CBK were received in a single iobuf
- * because of server sending entire msg as inline without
- * doing rdma writes.
- */
- if (post->ctx.hdr_iobuf)
- iobref_add (post->ctx.iobref, post->ctx.hdr_iobuf);
+ goto out;
}
- pollin = rpc_transport_pollin_alloc (peer->trans,
- post->ctx.vector,
- post->ctx.count,
- post->ctx.hdr_iobuf,
- post->ctx.iobref,
- post->ctx.reply_info);
- if (pollin == NULL) {
- goto out;
- }
+ /* handling the case where both hdr and payload of
+ * GF_FOP_READ_CBK were received in a single iobuf
+ * because of server sending entire msg as inline without
+ * doing rdma writes.
+ */
+ if (post->ctx.hdr_iobuf)
+ iobref_add(post->ctx.iobref, post->ctx.hdr_iobuf);
+ }
- ptr = (uint32_t *)pollin->vector[0].iov_base;
+ pollin = rpc_transport_pollin_alloc(peer->trans, post->ctx.vector,
+ post->ctx.count, post->ctx.hdr_iobuf,
+ post->ctx.iobref, post->ctx.reply_info);
+ if (pollin == NULL) {
+ goto out;
+ }
- request_info.xid = ntoh32 (*ptr);
- msg_type = ntoh32 (*(ptr + 1));
+ ptr = (uint32_t *)pollin->vector[0].iov_base;
- if (msg_type == REPLY) {
- ret = rpc_transport_notify (peer->trans,
- RPC_TRANSPORT_MAP_XID_REQUEST,
- &request_info);
- if (ret == -1) {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0, "cannot get request"
- "information from rpc layer");
- goto out;
- }
+ request_info.xid = ntoh32(*ptr);
+ msg_type = ntoh32(*(ptr + 1));
- rpc_req = request_info.rpc_req;
- if (rpc_req == NULL) {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0, "rpc request "
- "structure not found");
- ret = -1;
- goto out;
- }
+ if (msg_type == REPLY) {
+ ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MAP_XID_REQUEST,
+ &request_info);
+ if (ret == -1) {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "cannot get request"
+ "information from rpc layer");
+ goto out;
+ }
- request_context = rpc_req->conn_private;
- rpc_req->conn_private = NULL;
+ rpc_req = request_info.rpc_req;
+ if (rpc_req == NULL) {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "rpc request "
+ "structure not found");
+ ret = -1;
+ goto out;
+ }
- priv = peer->trans->private;
- if (request_context != NULL) {
- pthread_mutex_lock (&priv->write_mutex);
- {
- __gf_rdma_request_context_destroy (request_context);
- }
- pthread_mutex_unlock (&priv->write_mutex);
- } else {
- gf_rdma_quota_put (peer);
- }
+ request_context = rpc_req->conn_private;
+ rpc_req->conn_private = NULL;
- pollin->is_reply = 1;
+ priv = peer->trans->private;
+ if (request_context != NULL) {
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ __gf_rdma_request_context_destroy(request_context);
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
+ } else {
+ gf_rdma_quota_put(peer);
}
- ret = rpc_transport_notify (peer->trans, RPC_TRANSPORT_MSG_RECEIVED,
- pollin);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- TRANS_MSG_TRANSPORT_ERROR, "transport_notify failed");
- }
+ pollin->is_reply = 1;
+ }
+
+ ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MSG_RECEIVED, pollin);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, TRANS_MSG_TRANSPORT_ERROR,
+ "transport_notify failed");
+ }
out:
- if (pollin != NULL) {
- pollin->private = NULL;
- rpc_transport_pollin_destroy (pollin);
- }
+ if (pollin != NULL) {
+ pollin->private = NULL;
+ rpc_transport_pollin_destroy(pollin);
+ }
- return ret;
+ return ret;
}
-
int32_t
-gf_rdma_recv_reply (gf_rdma_peer_t *peer, gf_rdma_post_t *post)
+gf_rdma_recv_reply(gf_rdma_peer_t *peer, gf_rdma_post_t *post)
{
- int32_t ret = -1;
- gf_rdma_header_t *header = NULL;
- gf_rdma_reply_info_t *reply_info = NULL;
- gf_rdma_write_array_t *wc_array = NULL;
- int i = 0;
- uint32_t *ptr = NULL;
- gf_rdma_request_context_t *ctx = NULL;
- rpc_request_info_t request_info = {0, };
- struct rpc_req *rpc_req = NULL;
-
- header = (gf_rdma_header_t *)post->buf;
- reply_info = post->ctx.reply_info;
-
- /* no write chunklist, just notify upper layers */
- if (reply_info == NULL) {
- ret = 0;
- goto out;
- }
-
- wc_array = reply_info->wc_array;
-
- if (header->rm_type == GF_RDMA_NOMSG) {
- post->ctx.vector[0].iov_base
- = (void *)(long)wc_array->wc_array[0].wc_target.rs_offset;
- post->ctx.vector[0].iov_len
- = wc_array->wc_array[0].wc_target.rs_length;
-
- post->ctx.count = 1;
- } else {
- for (i = 0; i < wc_array->wc_nchunks; i++) {
- post->ctx.vector[i + 1].iov_base
- = (void *)(long)wc_array->wc_array[i].wc_target.rs_offset;
- post->ctx.vector[i + 1].iov_len
- = wc_array->wc_array[i].wc_target.rs_length;
- }
-
- post->ctx.count += wc_array->wc_nchunks;
- }
-
- ptr = (uint32_t *)post->ctx.vector[0].iov_base;
- request_info.xid = ntoh32 (*ptr);
-
- ret = rpc_transport_notify (peer->trans,
- RPC_TRANSPORT_MAP_XID_REQUEST,
- &request_info);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- TRANS_MSG_TRANSPORT_ERROR, "cannot get request "
- "information (peer:%s) from rpc layer",
- peer->trans->peerinfo.identifier);
- goto out;
- }
+ int32_t ret = -1;
+ gf_rdma_header_t *header = NULL;
+ gf_rdma_reply_info_t *reply_info = NULL;
+ gf_rdma_write_array_t *wc_array = NULL;
+ int i = 0;
+ uint32_t *ptr = NULL;
+ gf_rdma_request_context_t *ctx = NULL;
+ rpc_request_info_t request_info = {
+ 0,
+ };
+ struct rpc_req *rpc_req = NULL;
+
+ header = (gf_rdma_header_t *)post->buf;
+ reply_info = post->ctx.reply_info;
+
+ /* no write chunklist, just notify upper layers */
+ if (reply_info == NULL) {
+ ret = 0;
+ goto out;
+ }
- rpc_req = request_info.rpc_req;
- if (rpc_req == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_RPC_ST_ERROR, "rpc request structure not "
- "found");
- ret = -1;
- goto out;
- }
+ wc_array = reply_info->wc_array;
- ctx = rpc_req->conn_private;
- if ((post->ctx.iobref == NULL) && ctx->rsp_iobref) {
- post->ctx.iobref = iobref_ref (ctx->rsp_iobref);
- }
+ if (header->rm_type == GF_RDMA_NOMSG) {
+ post->ctx.vector[0].iov_base = (void *)(long)wc_array->wc_array[0]
+ .wc_target.rs_offset;
+ post->ctx.vector[0].iov_len = wc_array->wc_array[0].wc_target.rs_length;
- ret = 0;
-
- gf_rdma_reply_info_destroy (reply_info);
+ post->ctx.count = 1;
+ } else {
+ for (i = 0; i < wc_array->wc_nchunks; i++) {
+ post->ctx.vector[i + 1].iov_base =
+ (void *)(long)wc_array->wc_array[i].wc_target.rs_offset;
+ post->ctx.vector[i + 1].iov_len = wc_array->wc_array[i]
+ .wc_target.rs_length;
+ }
+
+ post->ctx.count += wc_array->wc_nchunks;
+ }
+
+ ptr = (uint32_t *)post->ctx.vector[0].iov_base;
+ request_info.xid = ntoh32(*ptr);
+
+ ret = rpc_transport_notify(peer->trans, RPC_TRANSPORT_MAP_XID_REQUEST,
+ &request_info);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, TRANS_MSG_TRANSPORT_ERROR,
+ "cannot get request "
+ "information (peer:%s) from rpc layer",
+ peer->trans->peerinfo.identifier);
+ goto out;
+ }
+
+ rpc_req = request_info.rpc_req;
+ if (rpc_req == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_RPC_ST_ERROR,
+ "rpc request structure not "
+ "found");
+ ret = -1;
+ goto out;
+ }
+
+ ctx = rpc_req->conn_private;
+ if ((post->ctx.iobref == NULL) && ctx->rsp_iobref) {
+ post->ctx.iobref = iobref_ref(ctx->rsp_iobref);
+ }
+
+ ret = 0;
+
+ gf_rdma_reply_info_destroy(reply_info);
out:
- if (ret == 0) {
- ret = gf_rdma_pollin_notify (peer, post);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POLL_IN_NOTIFY_FAILED,
- "pollin notify failed");
- }
+ if (ret == 0) {
+ ret = gf_rdma_pollin_notify(peer, post);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_POLL_IN_NOTIFY_FAILED, "pollin notify failed");
}
+ }
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_recv_request (gf_rdma_peer_t *peer, gf_rdma_post_t *post,
- gf_rdma_read_chunk_t *readch)
+gf_rdma_recv_request(gf_rdma_peer_t *peer, gf_rdma_post_t *post,
+ gf_rdma_read_chunk_t *readch)
{
- int32_t ret = -1;
+ int32_t ret = -1;
- if (readch != NULL) {
- ret = gf_rdma_do_reads (peer, post, readch);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PEER_READ_FAILED,
- "rdma read from peer (%s) failed",
- peer->trans->peerinfo.identifier);
- }
- } else {
- ret = gf_rdma_pollin_notify (peer, post);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POLL_IN_NOTIFY_FAILED,
- "pollin notification failed");
- }
+ if (readch != NULL) {
+ ret = gf_rdma_do_reads(peer, post, readch);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PEER_READ_FAILED, "rdma read from peer (%s) failed",
+ peer->trans->peerinfo.identifier);
}
+ } else {
+ ret = gf_rdma_pollin_notify(peer, post);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_POLL_IN_NOTIFY_FAILED,
+ "pollin notification failed");
+ }
+ }
- return ret;
+ return ret;
}
void
-gf_rdma_process_recv (gf_rdma_peer_t *peer, struct ibv_wc *wc)
+gf_rdma_process_recv(gf_rdma_peer_t *peer, struct ibv_wc *wc)
{
- gf_rdma_post_t *post = NULL;
- gf_rdma_read_chunk_t *readch = NULL;
- int ret = -1;
- uint32_t *ptr = NULL;
- enum msg_type msg_type = 0;
- gf_rdma_header_t *header = NULL;
- gf_rdma_private_t *priv = NULL;
-
- post = (gf_rdma_post_t *) (long) wc->wr_id;
- if (post == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_POST_MISSING, "no post found in successful "
- "work completion element");
- goto out;
- }
-
- ret = gf_rdma_decode_header (peer, post, &readch, wc->byte_len);
- if (ret == -1) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_HEADER_DECODE_FAILED, "decoding of header "
- "failed");
- goto out;
- }
-
- header = (gf_rdma_header_t *)post->buf;
-
- priv = peer->trans->private;
-
- pthread_mutex_lock (&priv->write_mutex);
- {
- if (!priv->peer.quota_set) {
- priv->peer.quota_set = 1;
-
- /* Initially peer.quota is set to 1 as per RFC 5666. We
- * have to account for the quota used while sending
- * first msg (which may or may not be returned to pool
- * at this point) while deriving peer.quota from
- * header->rm_credit. Hence the arithmetic below,
- * instead of directly setting it to header->rm_credit.
- */
- priv->peer.quota = header->rm_credit
- - (1 - priv->peer.quota);
- }
- }
- pthread_mutex_unlock (&priv->write_mutex);
-
- switch (header->rm_type) {
+ gf_rdma_post_t *post = NULL;
+ gf_rdma_read_chunk_t *readch = NULL;
+ int ret = -1;
+ uint32_t *ptr = NULL;
+ enum msg_type msg_type = 0;
+ gf_rdma_header_t *header = NULL;
+ gf_rdma_private_t *priv = NULL;
+
+ post = (gf_rdma_post_t *)(long)wc->wr_id;
+ if (post == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_POST_MISSING,
+ "no post found in successful "
+ "work completion element");
+ goto out;
+ }
+
+ ret = gf_rdma_decode_header(peer, post, &readch, wc->byte_len);
+ if (ret == -1) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_HEADER_DECODE_FAILED,
+ "decoding of header "
+ "failed");
+ goto out;
+ }
+
+ header = (gf_rdma_header_t *)post->buf;
+
+ priv = peer->trans->private;
+
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ if (!priv->peer.quota_set) {
+ priv->peer.quota_set = 1;
+
+ /* Initially peer.quota is set to 1 as per RFC 5666. We
+ * have to account for the quota used while sending
+ * first msg (which may or may not be returned to pool
+ * at this point) while deriving peer.quota from
+ * header->rm_credit. Hence the arithmetic below,
+ * instead of directly setting it to header->rm_credit.
+ */
+ priv->peer.quota = header->rm_credit - (1 - priv->peer.quota);
+ }
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
+
+ switch (header->rm_type) {
case GF_RDMA_MSG:
- ptr = (uint32_t *)post->ctx.vector[0].iov_base;
- msg_type = ntoh32 (*(ptr + 1));
- break;
+ ptr = (uint32_t *)post->ctx.vector[0].iov_base;
+ msg_type = ntoh32(*(ptr + 1));
+ break;
case GF_RDMA_NOMSG:
- if (readch != NULL) {
- msg_type = CALL;
- } else {
- msg_type = REPLY;
- }
- break;
+ if (readch != NULL) {
+ msg_type = CALL;
+ } else {
+ msg_type = REPLY;
+ }
+ break;
case GF_RDMA_ERROR:
- if (header->rm_body.rm_error.rm_type == ERR_CHUNK) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_RDMA_ERROR_RECEIVED,
- "peer (%s), couldn't encode or decode the msg "
- "properly or write chunks were not provided "
- "for replies that were bigger than "
- "RDMA_INLINE_THRESHOLD (%d)",
- peer->trans->peerinfo.identifier,
- GLUSTERFS_RDMA_INLINE_THRESHOLD);
- ret = gf_rdma_pollin_notify (peer, post);
- if (ret == -1) {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0, "pollin "
- "notification failed");
- }
- goto out;
- } else {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0,
- TRANS_MSG_TRANSPORT_ERROR, "an error has "
- "happened while transmission of msg, "
- "disconnecting the transport");
- ret = -1;
- goto out;
+ if (header->rm_body.rm_error.rm_type == ERR_CHUNK) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_RDMA_ERROR_RECEIVED,
+ "peer (%s), couldn't encode or decode the msg "
+ "properly or write chunks were not provided "
+ "for replies that were bigger than "
+ "RDMA_INLINE_THRESHOLD (%d)",
+ peer->trans->peerinfo.identifier,
+ GLUSTERFS_RDMA_INLINE_THRESHOLD);
+ ret = gf_rdma_pollin_notify(peer, post);
+ if (ret == -1) {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "pollin "
+ "notification failed");
}
+ goto out;
+ } else {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0,
+ TRANS_MSG_TRANSPORT_ERROR,
+ "an error has "
+ "happened while transmission of msg, "
+ "disconnecting the transport");
+ ret = -1;
+ goto out;
+ }
default:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_INVALID_ENTRY, "invalid rdma msg-type (%d)",
- header->rm_type);
- goto out;
- }
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_INVALID_ENTRY,
+ "invalid rdma msg-type (%d)", header->rm_type);
+ goto out;
+ }
- if (msg_type == CALL) {
- ret = gf_rdma_recv_request (peer, post, readch);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PEER_REQ_FAILED, "receiving a request"
- " from peer (%s) failed",
- peer->trans->peerinfo.identifier);
- }
- } else {
- ret = gf_rdma_recv_reply (peer, post);
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_PEER_REP_FAILED, "receiving a reply "
- "from peer (%s) failed",
- peer->trans->peerinfo.identifier);
- }
+ if (msg_type == CALL) {
+ ret = gf_rdma_recv_request(peer, post, readch);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PEER_REQ_FAILED,
+ "receiving a request"
+ " from peer (%s) failed",
+ peer->trans->peerinfo.identifier);
+ }
+ } else {
+ ret = gf_rdma_recv_reply(peer, post);
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_PEER_REP_FAILED,
+ "receiving a reply "
+ "from peer (%s) failed",
+ peer->trans->peerinfo.identifier);
}
+ }
out:
- if (ret == -1) {
- rpc_transport_disconnect (peer->trans, _gf_false);
- }
+ if (ret == -1) {
+ rpc_transport_disconnect(peer->trans, _gf_false);
+ }
- return;
+ return;
}
void *
-gf_rdma_async_event_thread (void *context)
+gf_rdma_async_event_thread(void *context)
{
- struct ibv_async_event event;
- int ret;
-
- while (1) {
- do {
- ret = ibv_get_async_event((struct ibv_context *)context,
- &event);
-
- if (ret && errno != EINTR) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_EVENT_ERROR, "Error getting "
- "event");
- }
- } while (ret && errno == EINTR);
+ struct ibv_async_event event;
+ int ret;
- switch (event.event_type) {
- case IBV_EVENT_SRQ_LIMIT_REACHED:
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_EVENT_SRQ_LIMIT_REACHED, "received "
- "srq_limit reached");
- break;
-
- default:
- gf_msg_debug (GF_RDMA_LOG_NAME, 0, "event (%d) "
- "received", event.event_type);
- break;
- }
+ while (1) {
+ do {
+ ret = ibv_get_async_event((struct ibv_context *)context, &event);
+
+ if (ret && errno != EINTR) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_EVENT_ERROR,
+ "Error getting "
+ "event");
+ }
+ } while (ret && errno == EINTR);
+
+ switch (event.event_type) {
+ case IBV_EVENT_SRQ_LIMIT_REACHED:
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_EVENT_SRQ_LIMIT_REACHED,
+ "received "
+ "srq_limit reached");
+ break;
- ibv_ack_async_event(&event);
+ default:
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "event (%d) "
+ "received",
+ event.event_type);
+ break;
}
- return 0;
-}
+ ibv_ack_async_event(&event);
+ }
+ return 0;
+}
static void *
-gf_rdma_recv_completion_proc (void *data)
+gf_rdma_recv_completion_proc(void *data)
{
- struct ibv_comp_channel *chan = NULL;
- gf_rdma_device_t *device = NULL;;
- gf_rdma_post_t *post = NULL;
- gf_rdma_peer_t *peer = NULL;
- struct ibv_cq *event_cq = NULL;
- struct ibv_wc wc[10] = {{0},};
- void *event_ctx = NULL;
- int32_t ret = 0;
- int32_t num_wr = 0, index = 0;
- uint8_t failed = 0;
-
- chan = data;
-
- while (1) {
- failed = 0;
- ret = ibv_get_cq_event (chan, &event_cq, &event_ctx);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_GET_CQ_FAILED,
- "ibv_get_cq_event failed, terminating recv "
- "thread %d (%d)", ret, errno);
- continue;
- }
+ struct ibv_comp_channel *chan = NULL;
+ gf_rdma_device_t *device = NULL;
+ ;
+ gf_rdma_post_t *post = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ struct ibv_cq *event_cq = NULL;
+ struct ibv_wc wc[10] = {
+ {0},
+ };
+ void *event_ctx = NULL;
+ int32_t ret = 0;
+ int32_t num_wr = 0, index = 0;
+ uint8_t failed = 0;
+
+ chan = data;
+
+ while (1) {
+ failed = 0;
+ ret = ibv_get_cq_event(chan, &event_cq, &event_ctx);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_GET_CQ_FAILED,
+ "ibv_get_cq_event failed, terminating recv "
+ "thread %d (%d)",
+ ret, errno);
+ continue;
+ }
- device = event_ctx;
+ device = event_ctx;
- ret = ibv_req_notify_cq (event_cq, 0);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED,
- "ibv_req_notify_cq on %s failed, terminating "
- "recv thread: %d (%d)",
- device->device_name, ret, errno);
- continue;
- }
+ ret = ibv_req_notify_cq(event_cq, 0);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED,
+ "ibv_req_notify_cq on %s failed, terminating "
+ "recv thread: %d (%d)",
+ device->device_name, ret, errno);
+ continue;
+ }
- device = (gf_rdma_device_t *) event_ctx;
-
- while (!failed &&
- (num_wr = ibv_poll_cq (event_cq, 10, wc)) > 0) {
-
- for (index = 0; index < num_wr && !failed; index++) {
- post = (gf_rdma_post_t *) (long)
- wc[index].wr_id;
-
- pthread_mutex_lock (&device->qpreg.lock);
- {
- peer = __gf_rdma_lookup_peer (device,
- wc[index].qp_num);
-
- /*
- * keep a refcount on transport so that it
- * does not get freed because of some error
- * indicated by wc.status till we are done
- * with usage of peer and thereby that of
- * trans.
- */
- if (peer != NULL) {
- rpc_transport_ref (peer->trans);
- }
- }
- pthread_mutex_unlock (&device->qpreg.lock);
-
- if (wc[index].status != IBV_WC_SUCCESS) {
- gf_msg (GF_RDMA_LOG_NAME,
- GF_LOG_ERROR, 0,
- RDMA_MSG_RECV_ERROR, "recv work "
- "request on `%s' returned error (%d)",
- device->device_name,
- wc[index].status);
- failed = 1;
- if (peer) {
- ibv_ack_cq_events (event_cq, num_wr);
- rpc_transport_disconnect (peer->trans,
- _gf_false);
- rpc_transport_unref (peer->trans);
- }
-
- if (post) {
- gf_rdma_post_unref (post);
- }
-
- continue;
- }
-
- if (peer) {
- gf_rdma_process_recv (peer,
- &wc[index]);
- rpc_transport_unref (peer->trans);
- } else {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0,
- "could not lookup peer "
- "for qp_num: %d",
- wc[index].qp_num);
- }
-
- gf_rdma_post_unref (post);
- }
+ device = (gf_rdma_device_t *)event_ctx;
+
+ while (!failed && (num_wr = ibv_poll_cq(event_cq, 10, wc)) > 0) {
+ for (index = 0; index < num_wr && !failed; index++) {
+ post = (gf_rdma_post_t *)(long)wc[index].wr_id;
+
+ pthread_mutex_lock(&device->qpreg.lock);
+ {
+ peer = __gf_rdma_lookup_peer(device, wc[index].qp_num);
+
+ /*
+ * keep a refcount on transport so that it
+ * does not get freed because of some error
+ * indicated by wc.status till we are done
+ * with usage of peer and thereby that of
+ * trans.
+ */
+ if (peer != NULL) {
+ rpc_transport_ref(peer->trans);
+ }
+ }
+ pthread_mutex_unlock(&device->qpreg.lock);
+
+ if (wc[index].status != IBV_WC_SUCCESS) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, 0,
+ RDMA_MSG_RECV_ERROR,
+ "recv work "
+ "request on `%s' returned error (%d)",
+ device->device_name, wc[index].status);
+ failed = 1;
+ if (peer) {
+ ibv_ack_cq_events(event_cq, num_wr);
+ rpc_transport_disconnect(peer->trans, _gf_false);
+ rpc_transport_unref(peer->trans);
+ }
+
+ if (post) {
+ gf_rdma_post_unref(post);
+ }
+
+ continue;
}
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_POLL_CQ_ERROR,
- "ibv_poll_cq on `%s' returned error "
- "(ret = %d, errno = %d)",
- device->device_name, ret, errno);
- continue;
+ if (peer) {
+ gf_rdma_process_recv(peer, &wc[index]);
+ rpc_transport_unref(peer->trans);
+ } else {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "could not lookup peer "
+ "for qp_num: %d",
+ wc[index].qp_num);
}
- if (!failed)
- ibv_ack_cq_events (event_cq, num_wr);
+
+ gf_rdma_post_unref(post);
+ }
}
- return NULL;
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_POLL_CQ_ERROR,
+ "ibv_poll_cq on `%s' returned error "
+ "(ret = %d, errno = %d)",
+ device->device_name, ret, errno);
+ continue;
+ }
+ if (!failed)
+ ibv_ack_cq_events(event_cq, num_wr);
+ }
+
+ return NULL;
}
-
void
-gf_rdma_handle_failed_send_completion (gf_rdma_peer_t *peer, struct ibv_wc *wc)
+gf_rdma_handle_failed_send_completion(gf_rdma_peer_t *peer, struct ibv_wc *wc)
{
- gf_rdma_post_t *post = NULL;
- gf_rdma_device_t *device = NULL;
- gf_rdma_private_t *priv = NULL;
-
- if (peer != NULL) {
- priv = peer->trans->private;
- if (priv != NULL) {
- device = priv->device;
- }
- }
-
+ gf_rdma_post_t *post = NULL;
+ gf_rdma_device_t *device = NULL;
+ gf_rdma_private_t *priv = NULL;
- post = (gf_rdma_post_t *) (long) wc->wr_id;
-
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_RDMA_HANDLE_FAILED,
- "send work request on `%s' returned error "
- "wc.status = %d, wc.vendor_err = %d, post->buf = %p, "
- "wc.byte_len = %d, post->reused = %d",
- (device != NULL) ? device->device_name : NULL, wc->status,
- wc->vendor_err, post->buf, wc->byte_len, post->reused);
-
- if (wc->status == IBV_WC_RETRY_EXC_ERR) {
- gf_msg ("rdma", GF_LOG_ERROR, 0, TRANS_MSG_TIMEOUT_EXCEEDED,
- "connection between client and server not working. "
- "check by running 'ibv_srq_pingpong'. also make sure "
- "subnet manager is running (eg: 'opensm'), or check "
- "if rdma port is valid (or active) by running "
- "'ibv_devinfo'. contact Gluster Support Team if the "
- "problem persists.");
- }
-
- if (peer) {
- rpc_transport_disconnect (peer->trans, _gf_false);
- }
-
- return;
+ if (peer != NULL) {
+ priv = peer->trans->private;
+ if (priv != NULL) {
+ device = priv->device;
+ }
+ }
+
+ post = (gf_rdma_post_t *)(long)wc->wr_id;
+
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0, RDMA_MSG_RDMA_HANDLE_FAILED,
+ "send work request on `%s' returned error "
+ "wc.status = %d, wc.vendor_err = %d, post->buf = %p, "
+ "wc.byte_len = %d, post->reused = %d",
+ (device != NULL) ? device->device_name : NULL, wc->status,
+ wc->vendor_err, post->buf, wc->byte_len, post->reused);
+
+ if (wc->status == IBV_WC_RETRY_EXC_ERR) {
+ gf_msg("rdma", GF_LOG_ERROR, 0, TRANS_MSG_TIMEOUT_EXCEEDED,
+ "connection between client and server not working. "
+ "check by running 'ibv_srq_pingpong'. also make sure "
+ "subnet manager is running (eg: 'opensm'), or check "
+ "if rdma port is valid (or active) by running "
+ "'ibv_devinfo'. contact Gluster Support Team if the "
+ "problem persists.");
+ }
+
+ if (peer) {
+ rpc_transport_disconnect(peer->trans, _gf_false);
+ }
+
+ return;
}
-
void
-gf_rdma_handle_successful_send_completion (gf_rdma_peer_t *peer,
- struct ibv_wc *wc)
+gf_rdma_handle_successful_send_completion(gf_rdma_peer_t *peer,
+ struct ibv_wc *wc)
{
- gf_rdma_post_t *post = NULL;
- int reads = 0, ret = 0;
- gf_rdma_header_t *header = NULL;
-
- if (wc->opcode != IBV_WC_RDMA_READ) {
- goto out;
- }
+ gf_rdma_post_t *post = NULL;
+ int reads = 0, ret = 0;
+ gf_rdma_header_t *header = NULL;
- post = (gf_rdma_post_t *)(long) wc->wr_id;
+ if (wc->opcode != IBV_WC_RDMA_READ) {
+ goto out;
+ }
- pthread_mutex_lock (&post->lock);
- {
- reads = --post->ctx.gf_rdma_reads;
- }
- pthread_mutex_unlock (&post->lock);
+ post = (gf_rdma_post_t *)(long)wc->wr_id;
- if (reads != 0) {
- /* if it is not the last rdma read, we've got nothing to do */
- goto out;
- }
+ pthread_mutex_lock(&post->lock);
+ {
+ reads = --post->ctx.gf_rdma_reads;
+ }
+ pthread_mutex_unlock(&post->lock);
- header = (gf_rdma_header_t *)post->buf;
+ if (reads != 0) {
+ /* if it is not the last rdma read, we've got nothing to do */
+ goto out;
+ }
- if (header->rm_type == GF_RDMA_NOMSG) {
- post->ctx.count = 1;
- post->ctx.vector[0].iov_len += post->ctx.vector[1].iov_len;
- }
- /*
- * if reads performed as vectored, then all the buffers are actually
- * contiguous memory, so that we can use it as single vector, instead
- * of multiple.
- */
- while (post->ctx.count > 2) {
- post->ctx.vector[1].iov_len +=
- post->ctx.vector[post->ctx.count-1].iov_len;
- post->ctx.count--;
- }
+ header = (gf_rdma_header_t *)post->buf;
- ret = gf_rdma_pollin_notify (peer, post);
- if ((ret == -1) && (peer != NULL)) {
- rpc_transport_disconnect (peer->trans, _gf_false);
- }
+ if (header->rm_type == GF_RDMA_NOMSG) {
+ post->ctx.count = 1;
+ post->ctx.vector[0].iov_len += post->ctx.vector[1].iov_len;
+ }
+ /*
+ * if reads performed as vectored, then all the buffers are actually
+ * contiguous memory, so that we can use it as single vector, instead
+ * of multiple.
+ */
+ while (post->ctx.count > 2) {
+ post->ctx.vector[1].iov_len += post->ctx.vector[post->ctx.count - 1]
+ .iov_len;
+ post->ctx.count--;
+ }
+
+ ret = gf_rdma_pollin_notify(peer, post);
+ if ((ret == -1) && (peer != NULL)) {
+ rpc_transport_disconnect(peer->trans, _gf_false);
+ }
out:
- return;
+ return;
}
-
static void *
-gf_rdma_send_completion_proc (void *data)
+gf_rdma_send_completion_proc(void *data)
{
- struct ibv_comp_channel *chan = NULL;
- gf_rdma_post_t *post = NULL;
- gf_rdma_peer_t *peer = NULL;
- struct ibv_cq *event_cq = NULL;
- void *event_ctx = NULL;
- gf_rdma_device_t *device = NULL;
- struct ibv_wc wc[10] = {{0},};
- char is_request = 0;
- int32_t ret = 0, quota_ret = 0, num_wr = 0;
- int32_t index = 0, failed = 0;
- chan = data;
- while (1) {
- failed = 0;
- ret = ibv_get_cq_event (chan, &event_cq, &event_ctx);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_GET_CQ_FAILED,
- "ibv_get_cq_event on failed, terminating "
- "send thread: %d (%d)", ret, errno);
- continue;
- }
+ struct ibv_comp_channel *chan = NULL;
+ gf_rdma_post_t *post = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ struct ibv_cq *event_cq = NULL;
+ void *event_ctx = NULL;
+ gf_rdma_device_t *device = NULL;
+ struct ibv_wc wc[10] = {
+ {0},
+ };
+ char is_request = 0;
+ int32_t ret = 0, quota_ret = 0, num_wr = 0;
+ int32_t index = 0, failed = 0;
+ chan = data;
+ while (1) {
+ failed = 0;
+ ret = ibv_get_cq_event(chan, &event_cq, &event_ctx);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_GET_CQ_FAILED,
+ "ibv_get_cq_event on failed, terminating "
+ "send thread: %d (%d)",
+ ret, errno);
+ continue;
+ }
+
+ device = event_ctx;
+
+ ret = ibv_req_notify_cq(event_cq, 0);
+ if (ret) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED,
+ "ibv_req_notify_cq on %s failed, terminating "
+ "send thread: %d (%d)",
+ device->device_name, ret, errno);
+ continue;
+ }
- device = event_ctx;
+ while (!failed && (num_wr = ibv_poll_cq(event_cq, 10, wc)) > 0) {
+ for (index = 0; index < num_wr && !failed; index++) {
+ post = (gf_rdma_post_t *)(long)wc[index].wr_id;
- ret = ibv_req_notify_cq (event_cq, 0);
- if (ret) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_REQ_NOTIFY_CQ_FAILED,
- "ibv_req_notify_cq on %s failed, terminating "
- "send thread: %d (%d)",
- device->device_name, ret, errno);
- continue;
+ pthread_mutex_lock(&device->qpreg.lock);
+ {
+ peer = __gf_rdma_lookup_peer(device, wc[index].qp_num);
+
+ /*
+ * keep a refcount on transport so that it
+ * does not get freed because of some error
+ * indicated by wc.status, till we are done
+ * with usage of peer and thereby that of trans.
+ */
+ if (peer != NULL) {
+ rpc_transport_ref(peer->trans);
+ }
}
+ pthread_mutex_unlock(&device->qpreg.lock);
- while (!failed &&
- (num_wr = ibv_poll_cq (event_cq, 10, wc)) > 0) {
- for (index = 0; index < num_wr && !failed; index++) {
- post = (gf_rdma_post_t *) (long)
- wc[index].wr_id;
-
- pthread_mutex_lock (&device->qpreg.lock);
- {
- peer = __gf_rdma_lookup_peer (device,
- wc[index].qp_num);
-
- /*
- * keep a refcount on transport so that it
- * does not get freed because of some error
- * indicated by wc.status, till we are done
- * with usage of peer and thereby that of trans.
- */
- if (peer != NULL) {
- rpc_transport_ref (peer->trans);
- }
- }
- pthread_mutex_unlock (&device->qpreg.lock);
-
- if (wc[index].status != IBV_WC_SUCCESS) {
- ibv_ack_cq_events (event_cq, num_wr);
- failed = 1;
- gf_rdma_handle_failed_send_completion
- (peer, &wc[index]);
- } else {
- gf_rdma_handle_successful_send_completion
- (peer, &wc[index]);
- }
-
- if (post) {
- is_request = post->ctx.is_request;
-
- ret = gf_rdma_post_unref (post);
- if ((ret == 0)
- && (wc[index].status == IBV_WC_SUCCESS)
- && !is_request
- && (post->type == GF_RDMA_SEND_POST)
- && (peer != NULL)) {
- /* An GF_RDMA_RECV_POST can end up in
- * gf_rdma_send_completion_proc for
- * rdma-reads, and we do not take
- * quota for getting an GF_RDMA_RECV_POST.
- */
-
- /*
- * if it is request, quota is returned
- * after reply has come.
- */
- quota_ret = gf_rdma_quota_put
- (peer);
- if (quota_ret < 0) {
- gf_msg_debug ("rdma",
- 0, "failed to send "
- "message");
- }
- }
- }
-
- if (peer) {
- rpc_transport_unref (peer->trans);
- } else {
- gf_msg_debug (GF_RDMA_LOG_NAME, 0,
- "could not lookup peer for qp_num: %d",
- wc[index].qp_num);
-
- }
+ if (wc[index].status != IBV_WC_SUCCESS) {
+ ibv_ack_cq_events(event_cq, num_wr);
+ failed = 1;
+ gf_rdma_handle_failed_send_completion(peer, &wc[index]);
+ } else {
+ gf_rdma_handle_successful_send_completion(peer, &wc[index]);
+ }
+
+ if (post) {
+ is_request = post->ctx.is_request;
+
+ ret = gf_rdma_post_unref(post);
+ if ((ret == 0) && (wc[index].status == IBV_WC_SUCCESS) &&
+ !is_request && (post->type == GF_RDMA_SEND_POST) &&
+ (peer != NULL)) {
+ /* An GF_RDMA_RECV_POST can end up in
+ * gf_rdma_send_completion_proc for
+ * rdma-reads, and we do not take
+ * quota for getting an GF_RDMA_RECV_POST.
+ */
+
+ /*
+ * if it is request, quota is returned
+ * after reply has come.
+ */
+ quota_ret = gf_rdma_quota_put(peer);
+ if (quota_ret < 0) {
+ gf_msg_debug("rdma", 0,
+ "failed to send "
+ "message");
}
+ }
}
- if (ret < 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
- RDMA_MSG_IBV_POLL_CQ_ERROR,
- "ibv_poll_cq on `%s' returned error (ret = %d,"
- " errno = %d)",
- device->device_name, ret, errno);
- continue;
- }
- if (!failed)
- ibv_ack_cq_events (event_cq, num_wr);
+ if (peer) {
+ rpc_transport_unref(peer->trans);
+ } else {
+ gf_msg_debug(GF_RDMA_LOG_NAME, 0,
+ "could not lookup peer for qp_num: %d",
+ wc[index].qp_num);
+ }
+ }
}
- return NULL;
+ if (ret < 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_ERROR, errno,
+ RDMA_MSG_IBV_POLL_CQ_ERROR,
+ "ibv_poll_cq on `%s' returned error (ret = %d,"
+ " errno = %d)",
+ device->device_name, ret, errno);
+ continue;
+ }
+ if (!failed)
+ ibv_ack_cq_events(event_cq, num_wr);
+ }
+
+ return NULL;
}
-
static void
-gf_rdma_options_init (rpc_transport_t *this)
+gf_rdma_options_init(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_options_t *options = NULL;
- int32_t mtu = 0;
- data_t *temp = NULL;
-
- /* TODO: validate arguments from options below */
-
- priv = this->private;
- options = &priv->options;
- options->send_size = GLUSTERFS_RDMA_INLINE_THRESHOLD;/*this->ctx->page_size * 4; 512 KB*/
- options->recv_size = GLUSTERFS_RDMA_INLINE_THRESHOLD;/*this->ctx->page_size * 4; 512 KB*/
- options->send_count = 4096;
- options->recv_count = 4096;
- options->attr_timeout = GF_RDMA_TIMEOUT;
- options->attr_retry_cnt = GF_RDMA_RETRY_CNT;
- options->attr_rnr_retry = GF_RDMA_RNR_RETRY;
-
- temp = dict_get (this->options, "transport.listen-backlog");
- if (temp)
- options->backlog = data_to_uint32 (temp);
- else
- options->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
-
- temp = dict_get (this->options,
- "transport.rdma.work-request-send-count");
- if (temp)
- options->send_count = data_to_int32 (temp);
-
- temp = dict_get (this->options,
- "transport.rdma.work-request-recv-count");
- if (temp)
- options->recv_count = data_to_int32 (temp);
-
- temp = dict_get (this->options, "transport.rdma.attr-timeout");
-
- if (temp)
- options->attr_timeout = data_to_uint8 (temp);
-
- temp = dict_get (this->options, "transport.rdma.attr-retry-cnt");
-
- if (temp)
- options->attr_retry_cnt = data_to_uint8 (temp);
-
- temp = dict_get (this->options, "transport.rdma.attr-rnr-retry");
-
- if (temp)
- options->attr_rnr_retry = data_to_uint8 (temp);
-
- options->port = 1;
- temp = dict_get (this->options,
- "transport.rdma.port");
- if (temp)
- options->port = data_to_uint64 (temp);
-
- options->mtu = mtu = IBV_MTU_2048;
- temp = dict_get (this->options,
- "transport.rdma.mtu");
- if (temp)
- mtu = data_to_int32 (temp);
- switch (mtu) {
-
- case 256: options->mtu = IBV_MTU_256;
- break;
-
- case 512: options->mtu = IBV_MTU_512;
- break;
-
- case 1024: options->mtu = IBV_MTU_1024;
- break;
-
- case 2048: options->mtu = IBV_MTU_2048;
- break;
-
- case 4096: options->mtu = IBV_MTU_4096;
- break;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_options_t *options = NULL;
+ int32_t mtu = 0;
+ data_t *temp = NULL;
+
+ /* TODO: validate arguments from options below */
+
+ priv = this->private;
+ options = &priv->options;
+ options->send_size =
+ GLUSTERFS_RDMA_INLINE_THRESHOLD; /*this->ctx->page_size * 4; 512 KB*/
+ options->recv_size =
+ GLUSTERFS_RDMA_INLINE_THRESHOLD; /*this->ctx->page_size * 4; 512 KB*/
+ options->send_count = 4096;
+ options->recv_count = 4096;
+ options->attr_timeout = GF_RDMA_TIMEOUT;
+ options->attr_retry_cnt = GF_RDMA_RETRY_CNT;
+ options->attr_rnr_retry = GF_RDMA_RNR_RETRY;
+
+ temp = dict_get(this->options, "transport.listen-backlog");
+ if (temp)
+ options->backlog = data_to_uint32(temp);
+ else
+ options->backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
+
+ temp = dict_get(this->options, "transport.rdma.work-request-send-count");
+ if (temp)
+ options->send_count = data_to_int32(temp);
+
+ temp = dict_get(this->options, "transport.rdma.work-request-recv-count");
+ if (temp)
+ options->recv_count = data_to_int32(temp);
+
+ temp = dict_get(this->options, "transport.rdma.attr-timeout");
+
+ if (temp)
+ options->attr_timeout = data_to_uint8(temp);
+
+ temp = dict_get(this->options, "transport.rdma.attr-retry-cnt");
+
+ if (temp)
+ options->attr_retry_cnt = data_to_uint8(temp);
+
+ temp = dict_get(this->options, "transport.rdma.attr-rnr-retry");
+
+ if (temp)
+ options->attr_rnr_retry = data_to_uint8(temp);
+
+ options->port = 1;
+ temp = dict_get(this->options, "transport.rdma.port");
+ if (temp)
+ options->port = data_to_uint64(temp);
+
+ options->mtu = mtu = IBV_MTU_2048;
+ temp = dict_get(this->options, "transport.rdma.mtu");
+ if (temp)
+ mtu = data_to_int32(temp);
+ switch (mtu) {
+ case 256:
+ options->mtu = IBV_MTU_256;
+ break;
+
+ case 512:
+ options->mtu = IBV_MTU_512;
+ break;
+
+ case 1024:
+ options->mtu = IBV_MTU_1024;
+ break;
+
+ case 2048:
+ options->mtu = IBV_MTU_2048;
+ break;
+
+ case 4096:
+ options->mtu = IBV_MTU_4096;
+ break;
default:
- if (temp)
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
- RDMA_MSG_UNRECG_MTU_VALUE, "%s: unrecognized "
- "MTU value '%s', defaulting to '2048'",
- this->name, data_to_str (temp));
- else
- gf_msg_trace (GF_RDMA_LOG_NAME, 0, "%s: defaulting "
- "MTU to '2048'", this->name);
- options->mtu = IBV_MTU_2048;
- break;
- }
-
- temp = dict_get (this->options,
- "transport.rdma.device-name");
- if (temp)
- options->device_name = gf_strdup (temp->data);
-
- return;
+ if (temp)
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, 0,
+ RDMA_MSG_UNRECG_MTU_VALUE,
+ "%s: unrecognized "
+ "MTU value '%s', defaulting to '2048'",
+ this->name, data_to_str(temp));
+ else
+ gf_msg_trace(GF_RDMA_LOG_NAME, 0,
+ "%s: defaulting "
+ "MTU to '2048'",
+ this->name);
+ options->mtu = IBV_MTU_2048;
+ break;
+ }
+
+ temp = dict_get(this->options, "transport.rdma.device-name");
+ if (temp)
+ options->device_name = gf_strdup(temp->data);
+
+ return;
}
-
gf_rdma_ctx_t *
-__gf_rdma_ctx_create (void)
+__gf_rdma_ctx_create(void)
{
- gf_rdma_ctx_t *rdma_ctx = NULL;
- int ret = -1;
-
- rdma_ctx = GF_CALLOC (1, sizeof (*rdma_ctx), gf_common_mt_char);
- if (rdma_ctx == NULL) {
- goto out;
- }
- pthread_mutex_init (&rdma_ctx->lock, NULL);
- rdma_ctx->rdma_cm_event_channel = rdma_create_event_channel ();
- if (rdma_ctx->rdma_cm_event_channel == NULL) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
- RDMA_MSG_CM_EVENT_FAILED, "rdma_cm event channel "
- "creation failed");
- goto out;
- }
-
- ret = gf_thread_create (&rdma_ctx->rdma_cm_thread, NULL,
- gf_rdma_cm_event_handler,
- rdma_ctx->rdma_cm_event_channel, "rdmaehan");
- if (ret != 0) {
- gf_msg (GF_RDMA_LOG_NAME, GF_LOG_WARNING, ret,
- RDMA_MSG_CM_EVENT_FAILED, "creation of thread to "
- "handle rdma-cm events failed");
- goto out;
- }
+ gf_rdma_ctx_t *rdma_ctx = NULL;
+ int ret = -1;
+
+ rdma_ctx = GF_CALLOC(1, sizeof(*rdma_ctx), gf_common_mt_char);
+ if (rdma_ctx == NULL) {
+ goto out;
+ }
+ pthread_mutex_init(&rdma_ctx->lock, NULL);
+ rdma_ctx->rdma_cm_event_channel = rdma_create_event_channel();
+ if (rdma_ctx->rdma_cm_event_channel == NULL) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, errno,
+ RDMA_MSG_CM_EVENT_FAILED,
+ "rdma_cm event channel "
+ "creation failed");
+ goto out;
+ }
+
+ ret = gf_thread_create(&rdma_ctx->rdma_cm_thread, NULL,
+ gf_rdma_cm_event_handler,
+ rdma_ctx->rdma_cm_event_channel, "rdmaehan");
+ if (ret != 0) {
+ gf_msg(GF_RDMA_LOG_NAME, GF_LOG_WARNING, ret, RDMA_MSG_CM_EVENT_FAILED,
+ "creation of thread to "
+ "handle rdma-cm events failed");
+ goto out;
+ }
out:
- if (ret < 0 && rdma_ctx) {
- if (rdma_ctx->rdma_cm_event_channel != NULL) {
- rdma_destroy_event_channel (rdma_ctx->rdma_cm_event_channel);
- }
-
- GF_FREE (rdma_ctx);
- rdma_ctx = NULL;
+ if (ret < 0 && rdma_ctx) {
+ if (rdma_ctx->rdma_cm_event_channel != NULL) {
+ rdma_destroy_event_channel(rdma_ctx->rdma_cm_event_channel);
}
- return rdma_ctx;
+ GF_FREE(rdma_ctx);
+ rdma_ctx = NULL;
+ }
+
+ return rdma_ctx;
}
static int32_t
-gf_rdma_init (rpc_transport_t *this)
+gf_rdma_init(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- int32_t ret = 0;
- glusterfs_ctx_t *ctx = NULL;
- gf_rdma_options_t *options = NULL;
+ gf_rdma_private_t *priv = NULL;
+ int32_t ret = 0;
+ glusterfs_ctx_t *ctx = NULL;
+ gf_rdma_options_t *options = NULL;
- ctx = this->ctx;
+ ctx = this->ctx;
- priv = this->private;
+ priv = this->private;
- ibv_fork_init ();
- gf_rdma_options_init (this);
+ ibv_fork_init();
+ gf_rdma_options_init(this);
- options = &priv->options;
- priv->peer.send_count = options->send_count;
- priv->peer.recv_count = options->recv_count;
- priv->peer.send_size = options->send_size;
- priv->peer.recv_size = options->recv_size;
- priv->backlog = options->backlog;
+ options = &priv->options;
+ priv->peer.send_count = options->send_count;
+ priv->peer.recv_count = options->recv_count;
+ priv->peer.send_size = options->send_size;
+ priv->peer.recv_size = options->recv_size;
+ priv->backlog = options->backlog;
- priv->peer.trans = this;
- INIT_LIST_HEAD (&priv->peer.ioq);
+ priv->peer.trans = this;
+ INIT_LIST_HEAD(&priv->peer.ioq);
- pthread_mutex_init (&priv->write_mutex, NULL);
- pthread_mutex_init (&priv->recv_mutex, NULL);
- pthread_cond_init (&priv->recv_cond, NULL);
+ pthread_mutex_init(&priv->write_mutex, NULL);
+ pthread_mutex_init(&priv->recv_mutex, NULL);
+ pthread_cond_init(&priv->recv_cond, NULL);
- LOCK (&ctx->lock);
- {
- if (ctx->ib == NULL) {
- ctx->ib = __gf_rdma_ctx_create ();
- if (ctx->ib == NULL) {
- ret = -1;
- }
- }
+ LOCK(&ctx->lock);
+ {
+ if (ctx->ib == NULL) {
+ ctx->ib = __gf_rdma_ctx_create();
+ if (ctx->ib == NULL) {
+ ret = -1;
+ }
}
- UNLOCK (&ctx->lock);
+ }
+ UNLOCK(&ctx->lock);
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_disconnect (rpc_transport_t *this, gf_boolean_t wait)
+gf_rdma_disconnect(rpc_transport_t *this, gf_boolean_t wait)
{
- gf_rdma_private_t *priv = NULL;
- int32_t ret = 0;
+ gf_rdma_private_t *priv = NULL;
+ int32_t ret = 0;
- priv = this->private;
- gf_msg_callingfn (this->name, GF_LOG_DEBUG, 0,
- RDMA_MSG_PEER_DISCONNECTED,
- "disconnect called (peer:%s)",
- this->peerinfo.identifier);
+ priv = this->private;
+ gf_msg_callingfn(this->name, GF_LOG_DEBUG, 0, RDMA_MSG_PEER_DISCONNECTED,
+ "disconnect called (peer:%s)", this->peerinfo.identifier);
- pthread_mutex_lock (&priv->write_mutex);
- {
- ret = __gf_rdma_disconnect (this);
- }
- pthread_mutex_unlock (&priv->write_mutex);
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ ret = __gf_rdma_disconnect(this);
+ }
+ pthread_mutex_unlock(&priv->write_mutex);
- return ret;
+ return ret;
}
-
static int32_t
-gf_rdma_connect (struct rpc_transport *this, int port)
+gf_rdma_connect(struct rpc_transport *this, int port)
{
- gf_rdma_private_t *priv = NULL;
- int32_t ret = 0;
- union gf_sock_union sock_union = {{0, }, };
- socklen_t sockaddr_len = 0;
- gf_rdma_peer_t *peer = NULL;
- gf_rdma_ctx_t *rdma_ctx = NULL;
- gf_boolean_t connected = _gf_false;
-
- priv = this->private;
-
- peer = &priv->peer;
-
- rpc_transport_ref (this);
-
- ret = gf_rdma_client_get_remote_sockaddr (this,
- &sock_union.sa,
- &sockaddr_len, port);
- if (ret != 0) {
- gf_msg_debug (this->name, 0, "cannot get remote address to "
- "connect");
- goto out;
- }
-
- rdma_ctx = this->ctx->ib;
-
- pthread_mutex_lock (&priv->write_mutex);
+ gf_rdma_private_t *priv = NULL;
+ int32_t ret = 0;
+ union gf_sock_union sock_union = {
{
- if (peer->cm_id != NULL) {
- ret = -1;
- errno = EINPROGRESS;
- connected = _gf_true;
- goto unlock;
- }
+ 0,
+ },
+ };
+ socklen_t sockaddr_len = 0;
+ gf_rdma_peer_t *peer = NULL;
+ gf_rdma_ctx_t *rdma_ctx = NULL;
+ gf_boolean_t connected = _gf_false;
- priv->entity = GF_RDMA_CLIENT;
+ priv = this->private;
- ret = rdma_create_id (rdma_ctx->rdma_cm_event_channel,
- &peer->cm_id, this, RDMA_PS_TCP);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- RDMA_MSG_CM_EVENT_FAILED, "creation of "
- "rdma_cm_id failed");
- ret = -errno;
- goto unlock;
- }
+ peer = &priv->peer;
- memcpy (&this->peerinfo.sockaddr, &sock_union.storage,
- sockaddr_len);
- this->peerinfo.sockaddr_len = sockaddr_len;
-
- if (port > 0)
- sock_union.sin.sin_port = htons (port);
-
- ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family =
- ((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family;
-
- ret = gf_rdma_client_bind (this,
- (struct sockaddr *)&this->myinfo.sockaddr,
- &this->myinfo.sockaddr_len,
- peer->cm_id);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_CLIENT_BIND_FAILED,
- "client bind failed");
- goto unlock;
- }
-
- ret = rdma_resolve_addr (peer->cm_id, NULL, &sock_union.sa,
- 2000);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_RDMA_RESOLVE_ADDR_FAILED,
- "rdma_resolve_addr failed");
- goto unlock;
- }
+ rpc_transport_ref(this);
- priv->connected = 0;
- }
-unlock:
- pthread_mutex_unlock (&priv->write_mutex);
+ ret = gf_rdma_client_get_remote_sockaddr(this, &sock_union.sa,
+ &sockaddr_len, port);
+ if (ret != 0) {
+ gf_msg_debug(this->name, 0,
+ "cannot get remote address to "
+ "connect");
+ goto out;
+ }
-out:
- if (ret != 0) {
- if (!connected) {
- gf_rdma_teardown (this);
- }
+ rdma_ctx = this->ctx->ib;
- rpc_transport_unref (this);
+ pthread_mutex_lock(&priv->write_mutex);
+ {
+ if (peer->cm_id != NULL) {
+ ret = -1;
+ errno = EINPROGRESS;
+ connected = _gf_true;
+ goto unlock;
}
- return ret;
-}
-
+ priv->entity = GF_RDMA_CLIENT;
-static int32_t
-gf_rdma_listen (rpc_transport_t *this)
-{
- union gf_sock_union sock_union = {{0, }, };
- socklen_t sockaddr_len = 0;
- gf_rdma_private_t *priv = NULL;
- gf_rdma_peer_t *peer = NULL;
- int ret = 0;
- gf_rdma_ctx_t *rdma_ctx = NULL;
- char service[NI_MAXSERV], host[NI_MAXHOST];
- int optval = 2;
-
- priv = this->private;
- peer = &priv->peer;
-
- priv->entity = GF_RDMA_SERVER_LISTENER;
-
- rdma_ctx = this->ctx->ib;
-
- ret = gf_rdma_server_get_local_sockaddr (this, &sock_union.sa,
- &sockaddr_len);
+ ret = rdma_create_id(rdma_ctx->rdma_cm_event_channel, &peer->cm_id,
+ this, RDMA_PS_TCP);
if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_NW_ADDR_UNKNOWN,
- "cannot find network address of server to bind to");
- goto err;
+ gf_msg(this->name, GF_LOG_ERROR, errno, RDMA_MSG_CM_EVENT_FAILED,
+ "creation of "
+ "rdma_cm_id failed");
+ ret = -errno;
+ goto unlock;
}
- ret = rdma_create_id (rdma_ctx->rdma_cm_event_channel,
- &peer->cm_id, this, RDMA_PS_TCP);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_CM_EVENT_FAILED, "creation of rdma_cm_id "
- "failed");
- goto err;
- }
+ memcpy(&this->peerinfo.sockaddr, &sock_union.storage, sockaddr_len);
+ this->peerinfo.sockaddr_len = sockaddr_len;
- memcpy (&this->myinfo.sockaddr, &sock_union.storage,
- sockaddr_len);
- this->myinfo.sockaddr_len = sockaddr_len;
+ if (port > 0)
+ sock_union.sin.sin_port = htons(port);
- ret = getnameinfo ((struct sockaddr *)&this->myinfo.sockaddr,
- this->myinfo.sockaddr_len, host, sizeof (host),
- service, sizeof (service),
- NI_NUMERICHOST);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- TRANS_MSG_GET_NAME_INFO_FAILED,
- "getnameinfo failed");
- goto err;
- }
+ ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family =
+ ((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family;
- sprintf (this->myinfo.identifier, "%s:%s", host, service);
-
- ret = rdma_set_option(peer->cm_id, RDMA_OPTION_ID,
- RDMA_OPTION_ID_REUSEADDR,
- (void *)&optval, sizeof(optval));
+ ret = gf_rdma_client_bind(this,
+ (struct sockaddr *)&this->myinfo.sockaddr,
+ &this->myinfo.sockaddr_len, peer->cm_id);
if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_OPTION_SET_FAILED, "rdma option set failed");
- goto err;
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ RDMA_MSG_CLIENT_BIND_FAILED, "client bind failed");
+ goto unlock;
}
- ret = rdma_bind_addr (peer->cm_id, &sock_union.sa);
+ ret = rdma_resolve_addr(peer->cm_id, NULL, &sock_union.sa, 2000);
if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_RDMA_BIND_ADDR_FAILED,
- "rdma_bind_addr failed");
- goto err;
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ RDMA_MSG_RDMA_RESOLVE_ADDR_FAILED,
+ "rdma_resolve_addr failed");
+ goto unlock;
}
- ret = rdma_listen (peer->cm_id, priv->backlog);
+ priv->connected = 0;
+ }
+unlock:
+ pthread_mutex_unlock(&priv->write_mutex);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- RDMA_MSG_LISTEN_FAILED,
- "rdma_listen failed");
- goto err;
+out:
+ if (ret != 0) {
+ if (!connected) {
+ gf_rdma_teardown(this);
}
- rpc_transport_ref (this);
+ rpc_transport_unref(this);
+ }
- ret = 0;
+ return ret;
+}
+
+static int32_t
+gf_rdma_listen(rpc_transport_t *this)
+{
+ union gf_sock_union sock_union = {
+ {
+ 0,
+ },
+ };
+ socklen_t sockaddr_len = 0;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_peer_t *peer = NULL;
+ int ret = 0;
+ gf_rdma_ctx_t *rdma_ctx = NULL;
+ char service[NI_MAXSERV], host[NI_MAXHOST];
+ int optval = 2;
+
+ priv = this->private;
+ peer = &priv->peer;
+
+ priv->entity = GF_RDMA_SERVER_LISTENER;
+
+ rdma_ctx = this->ctx->ib;
+
+ ret = gf_rdma_server_get_local_sockaddr(this, &sock_union.sa,
+ &sockaddr_len);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_NW_ADDR_UNKNOWN,
+ "cannot find network address of server to bind to");
+ goto err;
+ }
+
+ ret = rdma_create_id(rdma_ctx->rdma_cm_event_channel, &peer->cm_id, this,
+ RDMA_PS_TCP);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_CM_EVENT_FAILED,
+ "creation of rdma_cm_id "
+ "failed");
+ goto err;
+ }
+
+ memcpy(&this->myinfo.sockaddr, &sock_union.storage, sockaddr_len);
+ this->myinfo.sockaddr_len = sockaddr_len;
+
+ ret = getnameinfo((struct sockaddr *)&this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len, host, sizeof(host), service,
+ sizeof(service), NI_NUMERICHOST);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, TRANS_MSG_GET_NAME_INFO_FAILED,
+ "getnameinfo failed");
+ goto err;
+ }
+
+ sprintf(this->myinfo.identifier, "%s:%s", host, service);
+
+ ret = rdma_set_option(peer->cm_id, RDMA_OPTION_ID, RDMA_OPTION_ID_REUSEADDR,
+ (void *)&optval, sizeof(optval));
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, RDMA_MSG_OPTION_SET_FAILED,
+ "rdma option set failed");
+ goto err;
+ }
+
+ ret = rdma_bind_addr(peer->cm_id, &sock_union.sa);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ 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;
+ }
+
+ rpc_transport_ref(this);
+
+ ret = 0;
err:
- if (ret < 0) {
- if (peer->cm_id != NULL) {
- rdma_destroy_id (peer->cm_id);
- peer->cm_id = NULL;
- }
+ if (ret < 0) {
+ if (peer->cm_id != NULL) {
+ rdma_destroy_id(peer->cm_id);
+ peer->cm_id = NULL;
}
+ }
- return ret;
+ return ret;
}
-
struct rpc_transport_ops tops = {
- .submit_request = gf_rdma_submit_request,
- .submit_reply = gf_rdma_submit_reply,
- .connect = gf_rdma_connect,
- .disconnect = gf_rdma_disconnect,
- .listen = gf_rdma_listen,
+ .submit_request = gf_rdma_submit_request,
+ .submit_reply = gf_rdma_submit_reply,
+ .connect = gf_rdma_connect,
+ .disconnect = gf_rdma_disconnect,
+ .listen = gf_rdma_listen,
};
int32_t
-init (rpc_transport_t *this)
+init(rpc_transport_t *this)
{
- gf_rdma_private_t *priv = NULL;
- gf_rdma_ctx_t *rdma_ctx = NULL;
- struct iobuf_pool *iobuf_pool = NULL;
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_common_mt_rdma_private_t);
- if (!priv)
- return -1;
-
- this->private = priv;
-
- if (gf_rdma_init (this)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- RDMA_MSG_INIT_IB_DEVICE_FAILED,
- "Failed to initialize IB Device");
- this->private = NULL;
- GF_FREE (priv);
- return -1;
- }
- rdma_ctx = this->ctx->ib;
- if (!rdma_ctx)
- return -1;
+ gf_rdma_private_t *priv = NULL;
+ gf_rdma_ctx_t *rdma_ctx = NULL;
+ struct iobuf_pool *iobuf_pool = NULL;
- pthread_mutex_lock (&rdma_ctx->lock);
- {
- if (this->dl_handle && (++(rdma_ctx->dlcount)) == 1) {
- iobuf_pool = this->ctx->iobuf_pool;
- iobuf_pool->rdma_registration = gf_rdma_register_arena;
- iobuf_pool->rdma_deregistration =
- gf_rdma_deregister_arena;
- gf_rdma_register_iobuf_pool_with_device
- (rdma_ctx->device, iobuf_pool);
- }
- }
- pthread_mutex_unlock (&rdma_ctx->lock);
+ priv = GF_CALLOC(1, sizeof(*priv), gf_common_mt_rdma_private_t);
+ if (!priv)
+ return -1;
- return 0;
+ this->private = priv;
+
+ if (gf_rdma_init(this)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, RDMA_MSG_INIT_IB_DEVICE_FAILED,
+ "Failed to initialize IB Device");
+ this->private = NULL;
+ GF_FREE(priv);
+ return -1;
+ }
+ rdma_ctx = this->ctx->ib;
+ if (!rdma_ctx)
+ return -1;
+
+ pthread_mutex_lock(&rdma_ctx->lock);
+ {
+ if (this->dl_handle && (++(rdma_ctx->dlcount)) == 1) {
+ iobuf_pool = this->ctx->iobuf_pool;
+ iobuf_pool->rdma_registration = gf_rdma_register_arena;
+ iobuf_pool->rdma_deregistration = gf_rdma_deregister_arena;
+ gf_rdma_register_iobuf_pool_with_device(rdma_ctx->device,
+ iobuf_pool);
+ }
+ }
+ pthread_mutex_unlock(&rdma_ctx->lock);
+
+ return 0;
}
int
-reconfigure (rpc_transport_t *this, dict_t *options)
+reconfigure(rpc_transport_t *this, dict_t *options)
{
- gf_rdma_private_t *priv = NULL;
- uint32_t backlog = 0;
- int ret = -1;
-
- GF_VALIDATE_OR_GOTO ("rdma", this, out);
- GF_VALIDATE_OR_GOTO ("rdma", this->private, out);
-
- priv = this->private;
-
- if (dict_get_uint32 (options, "transport.listen-backlog",
- &backlog) == 0) {
- priv->backlog = backlog;
- gf_log (this->name, GF_LOG_DEBUG, "Reconfigued "
- "transport.listen-backlog=%d", priv->backlog);
- }
- ret = 0;
+ gf_rdma_private_t *priv = NULL;
+ uint32_t backlog = 0;
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rdma", this, out);
+ GF_VALIDATE_OR_GOTO("rdma", this->private, out);
+
+ priv = this->private;
+
+ if (dict_get_uint32(options, "transport.listen-backlog", &backlog) == 0) {
+ priv->backlog = backlog;
+ gf_log(this->name, GF_LOG_DEBUG,
+ "Reconfigued "
+ "transport.listen-backlog=%d",
+ priv->backlog);
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
void
-fini (struct rpc_transport *this)
+fini(struct rpc_transport *this)
{
- /* TODO: verify this function does graceful finish */
- gf_rdma_private_t *priv = NULL;
- struct iobuf_pool *iobuf_pool = NULL;
- gf_rdma_ctx_t *rdma_ctx = NULL;
+ /* TODO: verify this function does graceful finish */
+ gf_rdma_private_t *priv = NULL;
+ struct iobuf_pool *iobuf_pool = NULL;
+ gf_rdma_ctx_t *rdma_ctx = NULL;
- priv = this->private;
+ priv = this->private;
- this->private = NULL;
+ this->private = NULL;
- if (priv) {
- pthread_mutex_destroy (&priv->recv_mutex);
- pthread_mutex_destroy (&priv->write_mutex);
+ if (priv) {
+ pthread_mutex_destroy(&priv->recv_mutex);
+ pthread_mutex_destroy(&priv->write_mutex);
- gf_msg_trace (this->name, 0,
- "called fini on transport: %p", this);
- GF_FREE (priv);
- }
+ gf_msg_trace(this->name, 0, "called fini on transport: %p", this);
+ GF_FREE(priv);
+ }
- rdma_ctx = this->ctx->ib;
- if (!rdma_ctx)
- return;
+ rdma_ctx = this->ctx->ib;
+ if (!rdma_ctx)
+ return;
- pthread_mutex_lock (&rdma_ctx->lock);
- {
- if (this->dl_handle && (--(rdma_ctx->dlcount)) == 0) {
- iobuf_pool = this->ctx->iobuf_pool;
- gf_rdma_deregister_iobuf_pool (rdma_ctx->device);
- iobuf_pool->rdma_registration = NULL;
- iobuf_pool->rdma_deregistration = NULL;
- }
+ pthread_mutex_lock(&rdma_ctx->lock);
+ {
+ if (this->dl_handle && (--(rdma_ctx->dlcount)) == 0) {
+ iobuf_pool = this->ctx->iobuf_pool;
+ gf_rdma_deregister_iobuf_pool(rdma_ctx->device);
+ iobuf_pool->rdma_registration = NULL;
+ iobuf_pool->rdma_deregistration = NULL;
}
- pthread_mutex_unlock (&rdma_ctx->lock);
+ }
+ pthread_mutex_unlock(&rdma_ctx->lock);
- return;
+ return;
}
/* TODO: expand each option */
struct volume_options options[] = {
- { .key = {"transport.rdma.port",
- "rdma-port"},
- .type = GF_OPTION_TYPE_INT,
- .min = 1,
- .max = 4,
- .description = "check the option by 'ibv_devinfo'"
- },
- { .key = {"transport.rdma.mtu",
- "rdma-mtu"},
- .type = GF_OPTION_TYPE_INT,
- },
- { .key = {"transport.rdma.device-name",
- "rdma-device-name"},
- .type = GF_OPTION_TYPE_ANY,
- .description = "check by 'ibv_devinfo'"
- },
- { .key = {"transport.rdma.work-request-send-count",
- "rdma-work-request-send-count"},
- .type = GF_OPTION_TYPE_INT,
- },
- { .key = {"transport.rdma.work-request-recv-count",
- "rdma-work-request-recv-count"},
- .type = GF_OPTION_TYPE_INT,
- },
- { .key = {"remote-port",
- "transport.remote-port",
- "transport.rdma.remote-port"},
- .type = GF_OPTION_TYPE_INT
- },
- { .key = {"transport.rdma.attr-timeout",
- "rdma-attr-timeout"},
- .type = GF_OPTION_TYPE_INT
- },
- { .key = {"transport.rdma.attr-retry-cnt",
- "rdma-attr-retry-cnt"},
- .type = GF_OPTION_TYPE_INT
- },
- { .key = {"transport.rdma.attr-rnr-retry",
- "rdma-attr-rnr-retry"},
- .type = GF_OPTION_TYPE_INT
- },
- { .key = {"transport.rdma.listen-port", "listen-port"},
- .type = GF_OPTION_TYPE_INT
- },
- { .key = {"transport.rdma.connect-path", "connect-path"},
- .type = GF_OPTION_TYPE_ANY
- },
- { .key = {"transport.rdma.bind-path", "bind-path"},
- .type = GF_OPTION_TYPE_ANY
- },
- { .key = {"transport.rdma.listen-path", "listen-path"},
- .type = GF_OPTION_TYPE_ANY
- },
- { .key = {"transport.address-family",
- "address-family"},
- .value = {"inet", "inet6", "inet/inet6", "inet6/inet",
- "unix", "inet-sdp" },
- .type = GF_OPTION_TYPE_STR
- },
- { .key = {"transport.socket.lowlat"},
- .type = GF_OPTION_TYPE_BOOL
- },
- { .key = {NULL} }
-};
+ {.key = {"transport.rdma.port", "rdma-port"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 1,
+ .max = 4,
+ .description = "check the option by 'ibv_devinfo'"},
+ {
+ .key = {"transport.rdma.mtu", "rdma-mtu"},
+ .type = GF_OPTION_TYPE_INT,
+ },
+ {.key = {"transport.rdma.device-name", "rdma-device-name"},
+ .type = GF_OPTION_TYPE_ANY,
+ .description = "check by 'ibv_devinfo'"},
+ {
+ .key = {"transport.rdma.work-request-send-count",
+ "rdma-work-request-send-count"},
+ .type = GF_OPTION_TYPE_INT,
+ },
+ {
+ .key = {"transport.rdma.work-request-recv-count",
+ "rdma-work-request-recv-count"},
+ .type = GF_OPTION_TYPE_INT,
+ },
+ {.key = {"remote-port", "transport.remote-port",
+ "transport.rdma.remote-port"},
+ .type = GF_OPTION_TYPE_INT},
+ {.key = {"transport.rdma.attr-timeout", "rdma-attr-timeout"},
+ .type = GF_OPTION_TYPE_INT},
+ {.key = {"transport.rdma.attr-retry-cnt", "rdma-attr-retry-cnt"},
+ .type = GF_OPTION_TYPE_INT},
+ {.key = {"transport.rdma.attr-rnr-retry", "rdma-attr-rnr-retry"},
+ .type = GF_OPTION_TYPE_INT},
+ {.key = {"transport.rdma.listen-port", "listen-port"},
+ .type = GF_OPTION_TYPE_INT},
+ {.key = {"transport.rdma.connect-path", "connect-path"},
+ .type = GF_OPTION_TYPE_ANY},
+ {.key = {"transport.rdma.bind-path", "bind-path"},
+ .type = GF_OPTION_TYPE_ANY},
+ {.key = {"transport.rdma.listen-path", "listen-path"},
+ .type = GF_OPTION_TYPE_ANY},
+ {.key = {"transport.address-family", "address-family"},
+ .value = {"inet", "inet6", "inet/inet6", "inet6/inet", "unix", "inet-sdp"},
+ .type = GF_OPTION_TYPE_STR},
+ {.key = {"transport.socket.lowlat"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {NULL}}};
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index 34e6372a8f3..3194a7cf369 100644
--- a/rpc/rpc-transport/socket/src/name.c
+++ b/rpc/rpc-transport/socket/src/name.c
@@ -24,760 +24,729 @@
#include "common-utils.h"
static void
-_assign_port (struct sockaddr *sockaddr, uint16_t port)
+_assign_port(struct sockaddr *sockaddr, uint16_t port)
{
- switch (sockaddr->sa_family) {
+ switch (sockaddr->sa_family) {
case AF_INET6:
- ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port);
- break;
+ ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons(port);
+ break;
case AF_INET_SDP:
case AF_INET:
- ((struct sockaddr_in *)sockaddr)->sin_port = htons (port);
- break;
- }
+ ((struct sockaddr_in *)sockaddr)->sin_port = htons(port);
+ break;
+ }
}
static int32_t
-af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr,
- socklen_t sockaddr_len, uint32_t ceiling)
+af_inet_bind_to_port_lt_ceiling(int fd, struct sockaddr *sockaddr,
+ socklen_t sockaddr_len, uint32_t ceiling)
{
#if GF_DISABLE_PRIVPORT_TRACKING
- _assign_port (sockaddr, 0);
- return bind (fd, sockaddr, sockaddr_len);
+ _assign_port(sockaddr, 0);
+ return bind(fd, sockaddr, sockaddr_len);
#else
- int32_t ret = -1;
- uint16_t port = ceiling - 1;
- unsigned char ports[GF_PORT_ARRAY_SIZE] = {0,};
- int i = 0;
+ int32_t ret = -1;
+ uint16_t port = ceiling - 1;
+ unsigned char ports[GF_PORT_ARRAY_SIZE] = {
+ 0,
+ };
+ int i = 0;
loop:
- ret = gf_process_reserved_ports (ports, ceiling);
+ ret = gf_process_reserved_ports(ports, ceiling);
- while (port) {
- if (port == GF_CLIENT_PORT_CEILING) {
- ret = -1;
- break;
- }
+ while (port) {
+ if (port == GF_CLIENT_PORT_CEILING) {
+ ret = -1;
+ break;
+ }
- /* ignore the reserved ports */
- if (BIT_VALUE (ports, port)) {
- port--;
- continue;
- }
+ /* ignore the reserved ports */
+ if (BIT_VALUE(ports, port)) {
+ port--;
+ continue;
+ }
- _assign_port (sockaddr, port);
+ _assign_port(sockaddr, port);
- ret = bind (fd, sockaddr, sockaddr_len);
+ ret = bind(fd, sockaddr, sockaddr_len);
- if (ret == 0)
- break;
+ if (ret == 0)
+ break;
- if (ret == -1 && errno == EACCES)
- break;
+ if (ret == -1 && errno == EACCES)
+ break;
- port--;
- }
+ port--;
+ }
- /* In case if all the secure ports are exhausted, we are no more
- * binding to secure ports, hence instead of getting a random
- * port, lets define the range to restrict it from getting from
- * ports reserved for bricks i.e from range of 49152 - 65535
- * which further may lead to port clash */
- if (!port) {
- ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
- for (i = 0; i <= ceiling; i++)
- BIT_CLEAR (ports, i);
- goto loop;
- }
+ /* In case if all the secure ports are exhausted, we are no more
+ * binding to secure ports, hence instead of getting a random
+ * port, lets define the range to restrict it from getting from
+ * ports reserved for bricks i.e from range of 49152 - 65535
+ * which further may lead to port clash */
+ if (!port) {
+ ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
+ for (i = 0; i <= ceiling; i++)
+ BIT_CLEAR(ports, i);
+ goto loop;
+ }
- return ret;
+ return ret;
#endif /* GF_DISABLE_PRIVPORT_TRACKING */
}
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, int sock)
{
- data_t *path_data = NULL;
- struct sockaddr_un *addr = NULL;
- int32_t ret = 0;
-
- path_data = dict_get (this->options, "transport.socket.bind-path");
- if (path_data) {
- char *path = data_to_str (path_data);
- if (!path || strlen (path) > UNIX_PATH_MAX) {
- gf_log (this->name, GF_LOG_TRACE,
- "bind-path not specified for unix socket, "
- "letting connect to assign default value");
- goto err;
- }
-
- addr = (struct sockaddr_un *) sockaddr;
- strcpy (addr->sun_path, path);
- ret = bind (sock, (struct sockaddr *)addr, sockaddr_len);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "cannot bind to unix-domain socket %d (%s)",
- sock, strerror (errno));
- goto err;
- }
- } else {
- gf_log (this->name, GF_LOG_TRACE,
- "bind-path not specified for unix socket, "
- "letting connect to assign default value");
+ data_t *path_data = NULL;
+ struct sockaddr_un *addr = NULL;
+ int32_t ret = 0;
+
+ path_data = dict_get(this->options, "transport.socket.bind-path");
+ if (path_data) {
+ char *path = data_to_str(path_data);
+ if (!path || strlen(path) > UNIX_PATH_MAX) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "bind-path not specified for unix socket, "
+ "letting connect to assign default value");
+ goto err;
+ }
+
+ addr = (struct sockaddr_un *)sockaddr;
+ strcpy(addr->sun_path, path);
+ ret = bind(sock, (struct sockaddr *)addr, sockaddr_len);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "cannot bind to unix-domain socket %d (%s)", sock,
+ strerror(errno));
+ goto err;
}
+ } else {
+ gf_log(this->name, GF_LOG_TRACE,
+ "bind-path not specified for unix socket, "
+ "letting connect to assign default value");
+ }
err:
- return ret;
+ return ret;
}
int32_t
-client_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family)
+client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
{
- data_t *address_family_data = NULL;
- int32_t ret = -1;
-
- if (sa_family == NULL) {
- gf_log_callingfn ("", GF_LOG_WARNING,
- "sa_family argument is NULL");
- goto out;
- }
-
- address_family_data = dict_get (this->options,
- "transport.address-family");
- if (!address_family_data) {
- data_t *remote_host_data = NULL, *connect_path_data = NULL;
- remote_host_data = dict_get (this->options, "remote-host");
- connect_path_data = dict_get (this->options,
- "transport.socket.connect-path");
-
- if (!(remote_host_data || connect_path_data) ||
- (remote_host_data && connect_path_data)) {
- gf_log (this->name, GF_LOG_ERROR,
- "transport.address-family not specified. "
- "Could not guess default value from (remote-host:%s or "
- "transport.unix.connect-path:%s) options",
- data_to_str (remote_host_data),
- data_to_str (connect_path_data));
- *sa_family = AF_UNSPEC;
- goto out;
- }
-
- if (remote_host_data) {
- gf_log (this->name, GF_LOG_DEBUG,
- "address-family not specified, marking it as unspec "
- "for getaddrinfo to resolve from (remote-host: %s)",
- data_to_str(remote_host_data));
- *sa_family = AF_UNSPEC;
- } else {
- gf_log (this->name, GF_LOG_DEBUG,
- "address-family not specified, guessing it "
- "to be unix from (transport.unix.connect-path: %s)", data_to_str (connect_path_data));
- *sa_family = AF_UNIX;
- }
-
+ data_t *address_family_data = NULL;
+ int32_t ret = -1;
+
+ if (sa_family == NULL) {
+ gf_log_callingfn("", GF_LOG_WARNING, "sa_family argument is NULL");
+ goto out;
+ }
+
+ address_family_data = dict_get(this->options, "transport.address-family");
+ if (!address_family_data) {
+ data_t *remote_host_data = NULL, *connect_path_data = NULL;
+ remote_host_data = dict_get(this->options, "remote-host");
+ connect_path_data = dict_get(this->options,
+ "transport.socket.connect-path");
+
+ if (!(remote_host_data || connect_path_data) ||
+ (remote_host_data && connect_path_data)) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "transport.address-family not specified. "
+ "Could not guess default value from (remote-host:%s or "
+ "transport.unix.connect-path:%s) options",
+ data_to_str(remote_host_data),
+ data_to_str(connect_path_data));
+ *sa_family = AF_UNSPEC;
+ goto out;
+ }
+
+ if (remote_host_data) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "address-family not specified, marking it as unspec "
+ "for getaddrinfo to resolve from (remote-host: %s)",
+ data_to_str(remote_host_data));
+ *sa_family = AF_UNSPEC;
} else {
- char *address_family = data_to_str (address_family_data);
- if (!strcasecmp (address_family, "unix")) {
- *sa_family = AF_UNIX;
- } else if (!strcasecmp (address_family, "inet")) {
- *sa_family = AF_INET;
- } else if (!strcasecmp (address_family, "inet6")) {
- *sa_family = AF_INET6;
- } else if (!strcasecmp (address_family, "inet-sdp")) {
- *sa_family = AF_INET_SDP;
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "unknown address-family (%s) specified",
- address_family);
- *sa_family = AF_UNSPEC;
- goto out;
- }
+ gf_log(this->name, GF_LOG_DEBUG,
+ "address-family not specified, guessing it "
+ "to be unix from (transport.unix.connect-path: %s)",
+ data_to_str(connect_path_data));
+ *sa_family = AF_UNIX;
+ }
+
+ } else {
+ char *address_family = data_to_str(address_family_data);
+ if (!strcasecmp(address_family, "unix")) {
+ *sa_family = AF_UNIX;
+ } else if (!strcasecmp(address_family, "inet")) {
+ *sa_family = AF_INET;
+ } else if (!strcasecmp(address_family, "inet6")) {
+ *sa_family = AF_INET6;
+ } else if (!strcasecmp(address_family, "inet-sdp")) {
+ *sa_family = AF_INET_SDP;
+ } else {
+ gf_log(this->name, GF_LOG_ERROR,
+ "unknown address-family (%s) specified", address_family);
+ *sa_family = AF_UNSPEC;
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int32_t
-af_inet_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len)
+af_inet_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len)
{
- dict_t *options = this->options;
- data_t *remote_host_data = NULL;
- data_t *remote_port_data = NULL;
- char *remote_host = NULL;
- uint16_t remote_port = 0;
- struct addrinfo *addr_info = NULL;
- int32_t ret = 0;
-
- remote_host_data = dict_get (options, "remote-host");
- if (remote_host_data == NULL)
- {
- gf_log (this->name, GF_LOG_ERROR,
- "option remote-host missing in volume %s", this->name);
- ret = -1;
- goto err;
- }
-
- remote_host = data_to_str (remote_host_data);
- if (remote_host == NULL)
- {
- gf_log (this->name, GF_LOG_ERROR,
- "option remote-host has data NULL in volume %s", this->name);
- ret = -1;
- goto err;
- }
-
- remote_port_data = dict_get (options, "remote-port");
- if (remote_port_data == NULL)
- {
- gf_log (this->name, GF_LOG_TRACE,
- "option remote-port missing in volume %s. Defaulting to %d",
- this->name, GF_DEFAULT_SOCKET_LISTEN_PORT);
-
- remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
- }
- else
- {
- remote_port = data_to_uint16 (remote_port_data);
- }
-
- if (remote_port == (uint16_t)-1)
- {
- gf_log (this->name, GF_LOG_ERROR,
- "option remote-port has invalid port in volume %s",
- this->name);
- ret = -1;
- goto err;
- }
-
- /* TODO: gf_resolve is a blocking call. kick in some
- non blocking dns techniques */
- ret = gf_resolve_ip6 (remote_host, remote_port,
- sockaddr->sa_family, &this->dnscache, &addr_info);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "DNS resolution failed on host %s", remote_host);
- goto err;
- }
-
- memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen);
- *sockaddr_len = addr_info->ai_addrlen;
+ dict_t *options = this->options;
+ data_t *remote_host_data = NULL;
+ data_t *remote_port_data = NULL;
+ char *remote_host = NULL;
+ uint16_t remote_port = 0;
+ struct addrinfo *addr_info = NULL;
+ int32_t ret = 0;
+
+ remote_host_data = dict_get(options, "remote-host");
+ if (remote_host_data == NULL) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option remote-host missing in volume %s", this->name);
+ ret = -1;
+ goto err;
+ }
+
+ remote_host = data_to_str(remote_host_data);
+ if (remote_host == NULL) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option remote-host has data NULL in volume %s", this->name);
+ ret = -1;
+ goto err;
+ }
+
+ remote_port_data = dict_get(options, "remote-port");
+ if (remote_port_data == NULL) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "option remote-port missing in volume %s. Defaulting to %d",
+ this->name, GF_DEFAULT_SOCKET_LISTEN_PORT);
+
+ remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
+ } else {
+ remote_port = data_to_uint16(remote_port_data);
+ }
+
+ if (remote_port == (uint16_t)-1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option remote-port has invalid port in volume %s", this->name);
+ ret = -1;
+ goto err;
+ }
+
+ /* TODO: gf_resolve is a blocking call. kick in some
+ non blocking dns techniques */
+ ret = gf_resolve_ip6(remote_host, remote_port, sockaddr->sa_family,
+ &this->dnscache, &addr_info);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR, "DNS resolution failed on host %s",
+ remote_host);
+ goto err;
+ }
+
+ memcpy(sockaddr, addr_info->ai_addr, addr_info->ai_addrlen);
+ *sockaddr_len = addr_info->ai_addrlen;
err:
- return ret;
+ return ret;
}
static int32_t
-af_unix_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len)
+af_unix_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len)
{
- struct sockaddr_un *sockaddr_un = NULL;
- char *connect_path = NULL;
- data_t *connect_path_data = NULL;
- int32_t ret = 0;
-
- connect_path_data = dict_get (this->options,
- "transport.socket.connect-path");
- if (!connect_path_data) {
- gf_log (this->name, GF_LOG_ERROR,
- "option transport.unix.connect-path not specified for "
- "address-family unix");
- ret = -1;
- goto err;
- }
-
- connect_path = data_to_str (connect_path_data);
- if (!connect_path) {
- gf_log (this->name, GF_LOG_ERROR,
- "transport.unix.connect-path is null-string");
- ret = -1;
- goto err;
- }
-
- if ((strlen (connect_path) + 1) > UNIX_PATH_MAX) {
- gf_log (this->name, GF_LOG_ERROR,
- "connect-path value length %"GF_PRI_SIZET" > %d octets",
- strlen (connect_path), UNIX_PATH_MAX);
- ret = -1;
- goto err;
- }
-
- gf_log (this->name, GF_LOG_TRACE,
- "using connect-path %s", connect_path);
- sockaddr_un = (struct sockaddr_un *)sockaddr;
- strcpy (sockaddr_un->sun_path, connect_path);
- *sockaddr_len = sizeof (struct sockaddr_un);
+ struct sockaddr_un *sockaddr_un = NULL;
+ char *connect_path = NULL;
+ data_t *connect_path_data = NULL;
+ int32_t ret = 0;
+
+ connect_path_data = dict_get(this->options,
+ "transport.socket.connect-path");
+ if (!connect_path_data) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option transport.unix.connect-path not specified for "
+ "address-family unix");
+ ret = -1;
+ goto err;
+ }
+
+ connect_path = data_to_str(connect_path_data);
+ if (!connect_path) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "transport.unix.connect-path is null-string");
+ ret = -1;
+ goto err;
+ }
+
+ if ((strlen(connect_path) + 1) > UNIX_PATH_MAX) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "connect-path value length %" GF_PRI_SIZET " > %d octets",
+ strlen(connect_path), UNIX_PATH_MAX);
+ ret = -1;
+ goto err;
+ }
+
+ gf_log(this->name, GF_LOG_TRACE, "using connect-path %s", connect_path);
+ sockaddr_un = (struct sockaddr_un *)sockaddr;
+ strcpy(sockaddr_un->sun_path, connect_path);
+ *sockaddr_len = sizeof(struct sockaddr_un);
err:
- return ret;
+ return ret;
}
static int32_t
-af_unix_server_get_local_sockaddr (rpc_transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len)
{
- data_t *listen_path_data = NULL;
- char *listen_path = NULL;
- int32_t ret = 0;
- struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
-
-
- listen_path_data = dict_get (this->options,
- "transport.socket.listen-path");
- if (!listen_path_data) {
- gf_log (this->name, GF_LOG_ERROR,
- "missing option transport.socket.listen-path");
- ret = -1;
- goto err;
- }
+ data_t *listen_path_data = NULL;
+ char *listen_path = NULL;
+ int32_t ret = 0;
+ struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
+
+ listen_path_data = dict_get(this->options, "transport.socket.listen-path");
+ if (!listen_path_data) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "missing option transport.socket.listen-path");
+ ret = -1;
+ goto err;
+ }
- listen_path = data_to_str (listen_path_data);
+ listen_path = data_to_str(listen_path_data);
#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif
- if ((strlen (listen_path) + 1) > UNIX_PATH_MAX) {
- gf_log (this->name, GF_LOG_ERROR,
- "option transport.unix.listen-path has value length "
- "%"GF_PRI_SIZET" > %d",
- strlen (listen_path), UNIX_PATH_MAX);
- ret = -1;
- goto err;
- }
+ if ((strlen(listen_path) + 1) > UNIX_PATH_MAX) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option transport.unix.listen-path has value length "
+ "%" GF_PRI_SIZET " > %d",
+ strlen(listen_path), UNIX_PATH_MAX);
+ ret = -1;
+ goto err;
+ }
- sunaddr->sun_family = AF_UNIX;
- strcpy (sunaddr->sun_path, listen_path);
- *addr_len = sizeof (struct sockaddr_un);
+ sunaddr->sun_family = AF_UNIX;
+ strcpy(sunaddr->sun_path, listen_path);
+ *addr_len = sizeof(struct sockaddr_un);
err:
- return ret;
+ return ret;
}
static int32_t
-af_inet_server_get_local_sockaddr (rpc_transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len)
{
- struct addrinfo hints, *res = 0, *rp = NULL;
- data_t *listen_port_data = NULL, *listen_host_data = NULL;
- uint16_t listen_port = -1;
- char service[NI_MAXSERV], *listen_host = NULL;
- dict_t *options = NULL;
- int32_t ret = 0;
-
- 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;
-
-
- 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;
- in->sin6_port = htons(listen_port);
- *addr_len = sizeof(struct sockaddr_in6);
- goto out;
- } else if (addr->sa_family == AF_INET) {
- struct sockaddr_in *in = (struct sockaddr_in *) addr;
- in->sin_addr.s_addr = htonl(INADDR_ANY);
- in->sin_port = htons(listen_port);
- *addr_len = sizeof(struct sockaddr_in);
- goto out;
- }
- }
-
- sprintf (service, "%d", listen_port);
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = addr->sa_family;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
-
- ret = getaddrinfo(listen_host, service, &hints, &res);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "getaddrinfo failed for host %s, service %s (%s)",
- listen_host, service, gai_strerror (ret));
- ret = -1;
- goto out;
- }
- /* IPV6 server can handle both ipv4 and ipv6 clients */
- for (rp = res; rp != NULL; rp = rp->ai_next) {
- if (rp->ai_addr == NULL)
- continue;
- if (rp->ai_family == AF_INET6) {
- memcpy (addr, rp->ai_addr, rp->ai_addrlen);
- *addr_len = rp->ai_addrlen;
- }
- }
-
- if (!(*addr_len)) {
- memcpy (addr, res->ai_addr, res->ai_addrlen);
- *addr_len = res->ai_addrlen;
- }
-
- freeaddrinfo (res);
+ struct addrinfo hints, *res = 0, *rp = NULL;
+ data_t *listen_port_data = NULL, *listen_host_data = NULL;
+ uint16_t listen_port = -1;
+ char service[NI_MAXSERV], *listen_host = NULL;
+ dict_t *options = NULL;
+ int32_t ret = 0;
+
+ 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;
+
+ 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;
+ in->sin6_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in6);
+ goto out;
+ } else if (addr->sa_family == AF_INET) {
+ struct sockaddr_in *in = (struct sockaddr_in *)addr;
+ in->sin_addr.s_addr = htonl(INADDR_ANY);
+ in->sin_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in);
+ goto out;
+ }
+ }
+
+ sprintf(service, "%d", listen_port);
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = addr->sa_family;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+
+ ret = getaddrinfo(listen_host, service, &hints, &res);
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "getaddrinfo failed for host %s, service %s (%s)", listen_host,
+ service, gai_strerror(ret));
+ ret = -1;
+ goto out;
+ }
+ /* IPV6 server can handle both ipv4 and ipv6 clients */
+ for (rp = res; rp != NULL; rp = rp->ai_next) {
+ if (rp->ai_addr == NULL)
+ continue;
+ if (rp->ai_family == AF_INET6) {
+ memcpy(addr, rp->ai_addr, rp->ai_addrlen);
+ *addr_len = rp->ai_addrlen;
+ }
+ }
+
+ if (!(*addr_len)) {
+ memcpy(addr, res->ai_addr, res->ai_addrlen);
+ *addr_len = res->ai_addrlen;
+ }
+
+ freeaddrinfo(res);
out:
- return ret;
+ return ret;
}
int32_t
-client_bind (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len,
- int sock)
+client_bind(rpc_transport_t *this, struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len, int sock)
{
- int ret = 0;
+ int ret = 0;
- *sockaddr_len = sizeof (struct sockaddr_in6);
- switch (sockaddr->sa_family)
- {
+ *sockaddr_len = sizeof(struct sockaddr_in6);
+ switch (sockaddr->sa_family) {
case AF_INET_SDP:
case AF_INET:
- *sockaddr_len = sizeof (struct sockaddr_in);
+ *sockaddr_len = sizeof(struct sockaddr_in);
/* Fall through */
case AF_INET6:
- if (!this->bind_insecure) {
- ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr,
- *sockaddr_len,
- GF_CLIENT_PORT_CEILING);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_DEBUG,
- "cannot bind inet socket (%d) "
- "to port less than %d (%s)",
- sock, GF_CLIENT_PORT_CEILING,
- strerror (errno));
- ret = 0;
- }
- } else {
- ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr,
- *sockaddr_len,
- GF_IANA_PRIV_PORTS_START);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_DEBUG,
- "failed while binding to less than "
- "%d (%s)", GF_IANA_PRIV_PORTS_START,
- strerror (errno));
- ret = 0;
- }
+ if (!this->bind_insecure) {
+ ret = af_inet_bind_to_port_lt_ceiling(
+ sock, sockaddr, *sockaddr_len, GF_CLIENT_PORT_CEILING);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "cannot bind inet socket (%d) "
+ "to port less than %d (%s)",
+ sock, GF_CLIENT_PORT_CEILING, strerror(errno));
+ ret = 0;
+ }
+ } else {
+ ret = af_inet_bind_to_port_lt_ceiling(
+ sock, sockaddr, *sockaddr_len, GF_IANA_PRIV_PORTS_START);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "failed while binding to less than "
+ "%d (%s)",
+ GF_IANA_PRIV_PORTS_START, strerror(errno));
+ ret = 0;
}
- break;
+ }
+ break;
case AF_UNIX:
- *sockaddr_len = sizeof (struct sockaddr_un);
- ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr,
- *sockaddr_len, sock);
- break;
+ *sockaddr_len = sizeof(struct sockaddr_un);
+ ret = af_unix_client_bind(this, (struct sockaddr *)sockaddr,
+ *sockaddr_len, sock);
+ break;
default:
- gf_log (this->name, GF_LOG_ERROR,
- "unknown address family %d", sockaddr->sa_family);
- ret = -1;
- break;
- }
+ gf_log(this->name, GF_LOG_ERROR, "unknown address family %d",
+ sockaddr->sa_family);
+ ret = -1;
+ break;
+ }
- return ret;
+ return ret;
}
int32_t
-socket_client_get_remote_sockaddr (rpc_transport_t *this,
- struct sockaddr *sockaddr,
- socklen_t *sockaddr_len,
- sa_family_t *sa_family)
+socket_client_get_remote_sockaddr(rpc_transport_t *this,
+ struct sockaddr *sockaddr,
+ socklen_t *sockaddr_len,
+ sa_family_t *sa_family)
{
- int32_t ret = 0;
+ int32_t ret = 0;
- GF_VALIDATE_OR_GOTO ("socket", sockaddr, err);
- GF_VALIDATE_OR_GOTO ("socket", sockaddr_len, err);
- GF_VALIDATE_OR_GOTO ("socket", sa_family, err);
+ GF_VALIDATE_OR_GOTO("socket", sockaddr, err);
+ GF_VALIDATE_OR_GOTO("socket", sockaddr_len, err);
+ GF_VALIDATE_OR_GOTO("socket", sa_family, err);
- ret = client_fill_address_family (this, &sockaddr->sa_family);
- if (ret) {
- ret = -1;
- goto err;
- }
+ ret = client_fill_address_family(this, &sockaddr->sa_family);
+ if (ret) {
+ ret = -1;
+ goto err;
+ }
- *sa_family = sockaddr->sa_family;
+ *sa_family = sockaddr->sa_family;
- switch (sockaddr->sa_family)
- {
+ switch (sockaddr->sa_family) {
case AF_INET_SDP:
- sockaddr->sa_family = AF_INET;
+ sockaddr->sa_family = AF_INET;
/* Fall through */
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
- ret = af_inet_client_get_remote_sockaddr (this, sockaddr,
- sockaddr_len);
- break;
+ ret = af_inet_client_get_remote_sockaddr(this, sockaddr,
+ sockaddr_len);
+ break;
case AF_UNIX:
- ret = af_unix_client_get_remote_sockaddr (this, sockaddr,
- sockaddr_len);
- break;
+ ret = af_unix_client_get_remote_sockaddr(this, sockaddr,
+ sockaddr_len);
+ break;
default:
- gf_log (this->name, GF_LOG_ERROR,
- "unknown address-family %d", sockaddr->sa_family);
- ret = -1;
- }
+ gf_log(this->name, GF_LOG_ERROR, "unknown address-family %d",
+ sockaddr->sa_family);
+ ret = -1;
+ }
- if (*sa_family == AF_UNSPEC) {
- *sa_family = sockaddr->sa_family;
- }
+ if (*sa_family == AF_UNSPEC) {
+ *sa_family = sockaddr->sa_family;
+ }
err:
- return ret;
+ return ret;
}
-
int32_t
-server_fill_address_family (rpc_transport_t *this, sa_family_t *sa_family)
+server_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
{
- data_t *address_family_data = NULL;
- int32_t ret = -1;
+ data_t *address_family_data = NULL;
+ int32_t ret = -1;
#ifdef IPV6_DEFAULT
- char *addr_family = "inet6";
- sa_family_t default_family = AF_INET6;
+ char *addr_family = "inet6";
+ sa_family_t default_family = AF_INET6;
#else
- char *addr_family = "inet";
- sa_family_t default_family = AF_INET;
+ char *addr_family = "inet";
+ sa_family_t default_family = AF_INET;
#endif
- GF_VALIDATE_OR_GOTO ("socket", sa_family, out);
-
- address_family_data = dict_get (this->options,
- "transport.address-family");
- if (address_family_data) {
- char *address_family = NULL;
- address_family = data_to_str (address_family_data);
-
- if (!strcasecmp (address_family, "inet")) {
- *sa_family = AF_INET;
- } else if (!strcasecmp (address_family, "inet6")) {
- *sa_family = AF_INET6;
- } else if (!strcasecmp (address_family, "inet-sdp")) {
- *sa_family = AF_INET_SDP;
- } else if (!strcasecmp (address_family, "unix")) {
- *sa_family = AF_UNIX;
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "unknown address family (%s) specified", address_family);
- *sa_family = AF_UNSPEC;
- goto out;
- }
+ GF_VALIDATE_OR_GOTO("socket", sa_family, out);
+
+ address_family_data = dict_get(this->options, "transport.address-family");
+ if (address_family_data) {
+ char *address_family = NULL;
+ address_family = data_to_str(address_family_data);
+
+ if (!strcasecmp(address_family, "inet")) {
+ *sa_family = AF_INET;
+ } else if (!strcasecmp(address_family, "inet6")) {
+ *sa_family = AF_INET6;
+ } else if (!strcasecmp(address_family, "inet-sdp")) {
+ *sa_family = AF_INET_SDP;
+ } else if (!strcasecmp(address_family, "unix")) {
+ *sa_family = AF_UNIX;
} else {
- gf_log (this->name, GF_LOG_DEBUG,
- "option address-family not specified, "
- "defaulting to %s", addr_family);
- *sa_family = default_family;
- }
-
- ret = 0;
+ gf_log(this->name, GF_LOG_ERROR,
+ "unknown address family (%s) specified", address_family);
+ *sa_family = AF_UNSPEC;
+ goto out;
+ }
+ } else {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "option address-family not specified, "
+ "defaulting to %s",
+ addr_family);
+ *sa_family = default_family;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int32_t
-socket_server_get_local_sockaddr (rpc_transport_t *this, struct sockaddr *addr,
- socklen_t *addr_len, sa_family_t *sa_family)
+socket_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
+ socklen_t *addr_len, sa_family_t *sa_family)
{
- int32_t ret = -1;
+ int32_t ret = -1;
- GF_VALIDATE_OR_GOTO ("socket", sa_family, err);
- GF_VALIDATE_OR_GOTO ("socket", addr, err);
- GF_VALIDATE_OR_GOTO ("socket", addr_len, err);
+ GF_VALIDATE_OR_GOTO("socket", sa_family, err);
+ GF_VALIDATE_OR_GOTO("socket", addr, err);
+ GF_VALIDATE_OR_GOTO("socket", addr_len, err);
- ret = server_fill_address_family (this, &addr->sa_family);
- if (ret == -1) {
- goto err;
- }
+ ret = server_fill_address_family(this, &addr->sa_family);
+ if (ret == -1) {
+ goto err;
+ }
- *sa_family = addr->sa_family;
+ *sa_family = addr->sa_family;
- switch (addr->sa_family)
- {
+ switch (addr->sa_family) {
case AF_INET_SDP:
- addr->sa_family = AF_INET;
- /* Fall through */
+ addr->sa_family = AF_INET;
+ /* Fall through */
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
- ret = af_inet_server_get_local_sockaddr (this, addr, addr_len);
- break;
+ ret = af_inet_server_get_local_sockaddr(this, addr, addr_len);
+ break;
case AF_UNIX:
- ret = af_unix_server_get_local_sockaddr (this, addr, addr_len);
- break;
- }
+ ret = af_unix_server_get_local_sockaddr(this, addr, addr_len);
+ break;
+ }
- if (*sa_family == AF_UNSPEC) {
- *sa_family = addr->sa_family;
- }
+ if (*sa_family == AF_UNSPEC) {
+ *sa_family = addr->sa_family;
+ }
err:
- return ret;
+ return ret;
}
int32_t
-fill_inet6_inet_identifiers (rpc_transport_t *this, struct sockaddr_storage *addr,
- int32_t addr_len, char *identifier)
+fill_inet6_inet_identifiers(rpc_transport_t *this,
+ struct sockaddr_storage *addr, int32_t addr_len,
+ char *identifier)
{
- union gf_sock_union sock_union;
-
- char service[NI_MAXSERV] = {0,};
- char host[NI_MAXHOST] = {0,};
- int32_t ret = 0;
- int32_t tmpaddr_len = 0;
- int32_t one_to_four = 0;
- int32_t four_to_eight = 0;
- int32_t twelve_to_sixteen = 0;
- int16_t eight_to_ten = 0;
- int16_t ten_to_twelve = 0;
-
- memset (&sock_union, 0, sizeof (sock_union));
- sock_union.storage = *addr;
- tmpaddr_len = addr_len;
-
- if (sock_union.sa.sa_family == AF_INET6) {
- one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0];
- four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1];
+ union gf_sock_union sock_union;
+
+ char service[NI_MAXSERV] = {
+ 0,
+ };
+ char host[NI_MAXHOST] = {
+ 0,
+ };
+ int32_t ret = 0;
+ int32_t tmpaddr_len = 0;
+ int32_t one_to_four = 0;
+ int32_t four_to_eight = 0;
+ int32_t twelve_to_sixteen = 0;
+ int16_t eight_to_ten = 0;
+ int16_t ten_to_twelve = 0;
+
+ memset(&sock_union, 0, sizeof(sock_union));
+ sock_union.storage = *addr;
+ tmpaddr_len = addr_len;
+
+ if (sock_union.sa.sa_family == AF_INET6) {
+ one_to_four = sock_union.sin6.sin6_addr.s6_addr32[0];
+ four_to_eight = sock_union.sin6.sin6_addr.s6_addr32[1];
#ifdef GF_SOLARIS_HOST_OS
- eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4];
+ eight_to_ten = S6_ADDR16(sock_union.sin6.sin6_addr)[4];
#else
- eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4];
+ eight_to_ten = sock_union.sin6.sin6_addr.s6_addr16[4];
#endif
#ifdef GF_SOLARIS_HOST_OS
- ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5];
+ ten_to_twelve = S6_ADDR16(sock_union.sin6.sin6_addr)[5];
#else
- ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5];
+ ten_to_twelve = sock_union.sin6.sin6_addr.s6_addr16[5];
#endif
- twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3];
-
- /* ipv4 mapped ipv6 address has
- bits 0-80: 0
- bits 80-96: 0xffff
- bits 96-128: ipv4 address
- */
-
- if (one_to_four == 0 &&
- four_to_eight == 0 &&
- eight_to_ten == 0 &&
- ten_to_twelve == -1) {
- struct sockaddr_in *in_ptr = &sock_union.sin;
- memset (&sock_union, 0, sizeof (sock_union));
-
- in_ptr->sin_family = AF_INET;
- in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port;
- in_ptr->sin_addr.s_addr = twelve_to_sixteen;
- tmpaddr_len = sizeof (*in_ptr);
- }
- }
+ twelve_to_sixteen = sock_union.sin6.sin6_addr.s6_addr32[3];
+
+ /* ipv4 mapped ipv6 address has
+ bits 0-80: 0
+ bits 80-96: 0xffff
+ bits 96-128: ipv4 address
+ */
+
+ if (one_to_four == 0 && four_to_eight == 0 && eight_to_ten == 0 &&
+ ten_to_twelve == -1) {
+ struct sockaddr_in *in_ptr = &sock_union.sin;
+ memset(&sock_union, 0, sizeof(sock_union));
- ret = getnameinfo (&sock_union.sa,
- tmpaddr_len,
- host, sizeof (host),
- service, sizeof (service),
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "getnameinfo failed (%s)", gai_strerror (ret));
+ in_ptr->sin_family = AF_INET;
+ in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port;
+ in_ptr->sin_addr.s_addr = twelve_to_sixteen;
+ tmpaddr_len = sizeof(*in_ptr);
}
+ }
- sprintf (identifier, "%s:%s", host, service);
+ ret = getnameinfo(&sock_union.sa, tmpaddr_len, host, sizeof(host), service,
+ sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV);
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "getnameinfo failed (%s)",
+ gai_strerror(ret));
+ }
- return ret;
+ sprintf(identifier, "%s:%s", host, service);
+
+ return ret;
}
int32_t
-get_transport_identifiers (rpc_transport_t *this)
+get_transport_identifiers(rpc_transport_t *this)
{
- int32_t ret = 0;
- char is_inet_sdp = 0;
+ int32_t ret = 0;
+ char is_inet_sdp = 0;
- switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family)
- {
+ switch (((struct sockaddr *)&this->myinfo.sockaddr)->sa_family) {
case AF_INET_SDP:
- is_inet_sdp = 1;
- ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET;
+ is_inet_sdp = 1;
+ ((struct sockaddr *)&this->peerinfo.sockaddr)
+ ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr)
+ ->sa_family = AF_INET;
/* Fall through */
case AF_INET:
- case AF_INET6:
- {
- ret = fill_inet6_inet_identifiers (this,
- &this->myinfo.sockaddr,
- this->myinfo.sockaddr_len,
- this->myinfo.identifier);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "cannot fill inet/inet6 identifier for server");
- goto err;
- }
-
- ret = fill_inet6_inet_identifiers (this,
- &this->peerinfo.sockaddr,
- this->peerinfo.sockaddr_len,
- this->peerinfo.identifier);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "cannot fill inet/inet6 identifier for client");
- goto err;
- }
+ case AF_INET6: {
+ ret = fill_inet6_inet_identifiers(this, &this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len,
+ this->myinfo.identifier);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "cannot fill inet/inet6 identifier for server");
+ goto err;
+ }
+
+ ret = fill_inet6_inet_identifiers(this, &this->peerinfo.sockaddr,
+ this->peerinfo.sockaddr_len,
+ this->peerinfo.identifier);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "cannot fill inet/inet6 identifier for client");
+ goto err;
+ }
- if (is_inet_sdp) {
- ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP;
- }
- }
- break;
+ if (is_inet_sdp) {
+ ((struct sockaddr *)&this->peerinfo.sockaddr)
+ ->sa_family = ((struct sockaddr *)&this->myinfo.sockaddr)
+ ->sa_family = AF_INET_SDP;
+ }
+ } break;
- case AF_UNIX:
- {
- struct sockaddr_un *sunaddr = NULL;
+ case AF_UNIX: {
+ struct sockaddr_un *sunaddr = NULL;
- sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr;
- strcpy (this->myinfo.identifier, sunaddr->sun_path);
+ sunaddr = (struct sockaddr_un *)&this->myinfo.sockaddr;
+ strcpy(this->myinfo.identifier, sunaddr->sun_path);
- sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr;
- strcpy (this->peerinfo.identifier, sunaddr->sun_path);
- }
- break;
+ sunaddr = (struct sockaddr_un *)&this->peerinfo.sockaddr;
+ strcpy(this->peerinfo.identifier, sunaddr->sun_path);
+ } break;
default:
- gf_log (this->name, GF_LOG_ERROR,
- "unknown address family (%d)",
- ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family);
- ret = -1;
- break;
- }
+ gf_log(this->name, GF_LOG_ERROR, "unknown address family (%d)",
+ ((struct sockaddr *)&this->myinfo.sockaddr)->sa_family);
+ ret = -1;
+ break;
+ }
err:
- return ret;
+ return ret;
}
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 2c222ce8321..b3f8b7fc580 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -42,591 +42,583 @@
#define GF_LOG_ERRNO(errno) ((errno == ENOTCONN) ? GF_LOG_DEBUG : GF_LOG_ERROR)
#define SA(ptr) ((struct sockaddr *)ptr)
-#define SSL_ENABLED_OPT "transport.socket.ssl-enabled"
-#define SSL_OWN_CERT_OPT "transport.socket.ssl-own-cert"
+#define SSL_ENABLED_OPT "transport.socket.ssl-enabled"
+#define SSL_OWN_CERT_OPT "transport.socket.ssl-own-cert"
#define SSL_PRIVATE_KEY_OPT "transport.socket.ssl-private-key"
-#define SSL_CA_LIST_OPT "transport.socket.ssl-ca-list"
-#define SSL_CERT_DEPTH_OPT "transport.socket.ssl-cert-depth"
+#define SSL_CA_LIST_OPT "transport.socket.ssl-ca-list"
+#define SSL_CERT_DEPTH_OPT "transport.socket.ssl-cert-depth"
#define SSL_CIPHER_LIST_OPT "transport.socket.ssl-cipher-list"
-#define SSL_DH_PARAM_OPT "transport.socket.ssl-dh-param"
-#define SSL_EC_CURVE_OPT "transport.socket.ssl-ec-curve"
-#define SSL_CRL_PATH_OPT "transport.socket.ssl-crl-path"
-#define OWN_THREAD_OPT "transport.socket.own-thread"
+#define SSL_DH_PARAM_OPT "transport.socket.ssl-dh-param"
+#define SSL_EC_CURVE_OPT "transport.socket.ssl-ec-curve"
+#define SSL_CRL_PATH_OPT "transport.socket.ssl-crl-path"
+#define OWN_THREAD_OPT "transport.socket.own-thread"
/* TBD: do automake substitutions etc. (ick) to set these. */
#if !defined(DEFAULT_ETC_SSL)
-# ifdef GF_LINUX_HOST_OS
-# define DEFAULT_ETC_SSL "/etc/ssl"
-# endif
-# ifdef GF_BSD_HOST_OS
-# define DEFAULT_ETC_SSL "/etc/openssl"
-# endif
-# ifdef GF_DARWIN_HOST_OS
-# define DEFAULT_ETC_SSL "/usr/local/etc/openssl"
-# endif
-# if !defined(DEFAULT_ETC_SSL)
-# define DEFAULT_ETC_SSL "/etc/ssl"
-# endif
+#ifdef GF_LINUX_HOST_OS
+#define DEFAULT_ETC_SSL "/etc/ssl"
+#endif
+#ifdef GF_BSD_HOST_OS
+#define DEFAULT_ETC_SSL "/etc/openssl"
+#endif
+#ifdef GF_DARWIN_HOST_OS
+#define DEFAULT_ETC_SSL "/usr/local/etc/openssl"
+#endif
+#if !defined(DEFAULT_ETC_SSL)
+#define DEFAULT_ETC_SSL "/etc/ssl"
+#endif
#endif
#if !defined(DEFAULT_CERT_PATH)
-#define DEFAULT_CERT_PATH DEFAULT_ETC_SSL "/glusterfs.pem"
+#define DEFAULT_CERT_PATH DEFAULT_ETC_SSL "/glusterfs.pem"
#endif
#if !defined(DEFAULT_KEY_PATH)
-#define DEFAULT_KEY_PATH DEFAULT_ETC_SSL "/glusterfs.key"
+#define DEFAULT_KEY_PATH DEFAULT_ETC_SSL "/glusterfs.key"
#endif
#if !defined(DEFAULT_CA_PATH)
-#define DEFAULT_CA_PATH DEFAULT_ETC_SSL "/glusterfs.ca"
+#define DEFAULT_CA_PATH DEFAULT_ETC_SSL "/glusterfs.ca"
#endif
#if !defined(DEFAULT_VERIFY_DEPTH)
#define DEFAULT_VERIFY_DEPTH 1
#endif
#define DEFAULT_CIPHER_LIST "EECDH:EDH:HIGH:!3DES:!RC4:!DES:!MD5:!aNULL:!eNULL"
-#define DEFAULT_DH_PARAM DEFAULT_ETC_SSL "/dhparam.pem"
-#define DEFAULT_EC_CURVE "prime256v1"
+#define DEFAULT_DH_PARAM DEFAULT_ETC_SSL "/dhparam.pem"
+#define DEFAULT_EC_CURVE "prime256v1"
-#define POLL_MASK_INPUT (POLLIN | POLLPRI)
+#define POLL_MASK_INPUT (POLLIN | POLLPRI)
#define POLL_MASK_OUTPUT (POLLOUT)
-#define POLL_MASK_ERROR (POLLERR | POLLHUP | POLLNVAL)
-
-typedef int SSL_unary_func (SSL *);
-typedef int SSL_trinary_func (SSL *, void *, int);
-static int ssl_setup_connection_params(rpc_transport_t *this);
-
-#define __socket_proto_reset_pending(priv) do { \
- struct gf_sock_incoming_frag *frag; \
- frag = &priv->incoming.frag; \
- \
- memset (&frag->vector, 0, sizeof (frag->vector)); \
- frag->pending_vector = &frag->vector; \
- frag->pending_vector->iov_base = frag->fragcurrent; \
- priv->incoming.pending_vector = frag->pending_vector; \
- } while (0)
-
-
-#define __socket_proto_update_pending(priv) \
- do { \
- uint32_t remaining; \
- struct gf_sock_incoming_frag *frag; \
- frag = &priv->incoming.frag; \
- if (frag->pending_vector->iov_len == 0) { \
- remaining = (RPC_FRAGSIZE (priv->incoming.fraghdr) \
- - frag->bytes_read); \
- \
- frag->pending_vector->iov_len = \
- (remaining > frag->remaining_size) \
- ? frag->remaining_size : remaining; \
- \
- frag->remaining_size -= \
- frag->pending_vector->iov_len; \
- } \
- } while (0)
-
-#define __socket_proto_update_priv_after_read(priv, ret, bytes_read) \
- { \
- struct gf_sock_incoming_frag *frag; \
- frag = &priv->incoming.frag; \
- \
- frag->fragcurrent += bytes_read; \
- frag->bytes_read += bytes_read; \
- \
- if ((ret > 0) || (frag->remaining_size != 0)) { \
- if (frag->remaining_size != 0 && ret == 0) { \
- __socket_proto_reset_pending (priv); \
- } \
- \
- gf_log (this->name, GF_LOG_TRACE, \
- "partial read on non-blocking socket"); \
- \
- break; \
- } \
- }
-
-#define __socket_proto_init_pending(priv,size) \
- do { \
- uint32_t remaining = 0; \
- struct gf_sock_incoming_frag *frag; \
- frag = &priv->incoming.frag; \
- \
- remaining = (RPC_FRAGSIZE (priv->incoming.fraghdr) \
- - frag->bytes_read); \
- \
- __socket_proto_reset_pending (priv); \
- \
- frag->pending_vector->iov_len = \
- (remaining > size) ? size : remaining; \
- \
- frag->remaining_size = (size - frag->pending_vector->iov_len); \
- \
- } while(0)
+#define POLL_MASK_ERROR (POLLERR | POLLHUP | POLLNVAL)
+typedef int
+SSL_unary_func(SSL *);
+typedef int
+SSL_trinary_func(SSL *, void *, int);
+static int
+ssl_setup_connection_params(rpc_transport_t *this);
+
+#define __socket_proto_reset_pending(priv) \
+ do { \
+ struct gf_sock_incoming_frag *frag; \
+ frag = &priv->incoming.frag; \
+ \
+ memset(&frag->vector, 0, sizeof(frag->vector)); \
+ frag->pending_vector = &frag->vector; \
+ frag->pending_vector->iov_base = frag->fragcurrent; \
+ priv->incoming.pending_vector = frag->pending_vector; \
+ } while (0)
+
+#define __socket_proto_update_pending(priv) \
+ do { \
+ uint32_t remaining; \
+ struct gf_sock_incoming_frag *frag; \
+ frag = &priv->incoming.frag; \
+ if (frag->pending_vector->iov_len == 0) { \
+ remaining = (RPC_FRAGSIZE(priv->incoming.fraghdr) - \
+ frag->bytes_read); \
+ \
+ frag->pending_vector->iov_len = (remaining > frag->remaining_size) \
+ ? frag->remaining_size \
+ : remaining; \
+ \
+ frag->remaining_size -= frag->pending_vector->iov_len; \
+ } \
+ } while (0)
+
+#define __socket_proto_update_priv_after_read(priv, ret, bytes_read) \
+ { \
+ struct gf_sock_incoming_frag *frag; \
+ frag = &priv->incoming.frag; \
+ \
+ frag->fragcurrent += bytes_read; \
+ frag->bytes_read += bytes_read; \
+ \
+ if ((ret > 0) || (frag->remaining_size != 0)) { \
+ if (frag->remaining_size != 0 && ret == 0) { \
+ __socket_proto_reset_pending(priv); \
+ } \
+ \
+ gf_log(this->name, GF_LOG_TRACE, \
+ "partial read on non-blocking socket"); \
+ \
+ break; \
+ } \
+ }
+
+#define __socket_proto_init_pending(priv, size) \
+ do { \
+ uint32_t remaining = 0; \
+ struct gf_sock_incoming_frag *frag; \
+ frag = &priv->incoming.frag; \
+ \
+ remaining = (RPC_FRAGSIZE(priv->incoming.fraghdr) - frag->bytes_read); \
+ \
+ __socket_proto_reset_pending(priv); \
+ \
+ frag->pending_vector->iov_len = (remaining > size) ? size : remaining; \
+ \
+ frag->remaining_size = (size - frag->pending_vector->iov_len); \
+ \
+ } while (0)
/* This will be used in a switch case and breaks from the switch case if all
* the pending data is not read.
*/
-#define __socket_proto_read(priv, ret) \
- { \
- size_t bytes_read = 0; \
- struct gf_sock_incoming *in; \
- in = &priv->incoming; \
- \
- __socket_proto_update_pending (priv); \
- \
- ret = __socket_readv (this, \
- in->pending_vector, 1, \
- &in->pending_vector, \
- &in->pending_count, \
- &bytes_read); \
- if (ret == -1) \
- break; \
- __socket_proto_update_priv_after_read (priv, ret, bytes_read); \
- }
+#define __socket_proto_read(priv, ret) \
+ { \
+ size_t bytes_read = 0; \
+ struct gf_sock_incoming *in; \
+ in = &priv->incoming; \
+ \
+ __socket_proto_update_pending(priv); \
+ \
+ ret = __socket_readv(this, in->pending_vector, 1, &in->pending_vector, \
+ &in->pending_count, &bytes_read); \
+ if (ret == -1) \
+ break; \
+ __socket_proto_update_priv_after_read(priv, ret, bytes_read); \
+ }
struct socket_connect_error_state_ {
- xlator_t *this;
- rpc_transport_t *trans;
- gf_boolean_t refd;
+ xlator_t *this;
+ rpc_transport_t *trans;
+ gf_boolean_t refd;
};
typedef struct socket_connect_error_state_ socket_connect_error_state_t;
-static int socket_init (rpc_transport_t *this);
-static int __socket_nonblock (int fd);
+static int
+socket_init(rpc_transport_t *this);
+static int
+__socket_nonblock(int fd);
static void
-socket_dump_info (struct sockaddr *sa, int is_server, int is_ssl, int sock,
- char *log_domain, char *log_label)
+socket_dump_info(struct sockaddr *sa, int is_server, int is_ssl, int sock,
+ char *log_domain, char *log_label)
{
- char addr_buf[INET6_ADDRSTRLEN+1] = {0, };
- char *addr = NULL;
- char *peer_type = NULL;
- int af = sa->sa_family;
- int so_error = -1;
- socklen_t slen = sizeof(so_error);
-
- if (af == AF_UNIX) {
- addr = ((struct sockaddr_un *)(sa))->sun_path;
+ char addr_buf[INET6_ADDRSTRLEN + 1] = {
+ 0,
+ };
+ char *addr = NULL;
+ char *peer_type = NULL;
+ int af = sa->sa_family;
+ int so_error = -1;
+ socklen_t slen = sizeof(so_error);
+
+ if (af == AF_UNIX) {
+ addr = ((struct sockaddr_un *)(sa))->sun_path;
+ } else {
+ if (af == AF_INET6) {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)(sa);
+
+ inet_ntop(af, &sin6->sin6_addr, addr_buf, sizeof(addr_buf));
+ addr = addr_buf;
} else {
- if (af == AF_INET6) {
- struct sockaddr_in6 *sin6 =
- (struct sockaddr_in6 *)(sa);
+ struct sockaddr_in *sin = (struct sockaddr_in *)(sa);
- inet_ntop (af, &sin6->sin6_addr, addr_buf,
- sizeof (addr_buf));
- addr = addr_buf;
- } else {
- struct sockaddr_in *sin =
- (struct sockaddr_in *)(sa);
-
- inet_ntop (af, &sin->sin_addr, addr_buf,
- sizeof (addr_buf));
- addr = addr_buf;
- }
+ inet_ntop(af, &sin->sin_addr, addr_buf, sizeof(addr_buf));
+ addr = addr_buf;
}
- if (is_server)
- peer_type = "server";
- else
- peer_type = "client";
+ }
+ if (is_server)
+ peer_type = "server";
+ else
+ peer_type = "client";
- getsockopt (sock, SOL_SOCKET, SO_ERROR, &so_error, &slen);
+ getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &slen);
- gf_log (log_domain, GF_LOG_TRACE,
- "$$$ %s: %s (af:%d,sock:%d) %s %s (errno:%d:%s)",
- peer_type, log_label, af, sock, addr,
- (is_ssl ? "SSL" : "non-SSL"),
- so_error, strerror (so_error));
+ gf_log(log_domain, GF_LOG_TRACE,
+ "$$$ %s: %s (af:%d,sock:%d) %s %s (errno:%d:%s)", peer_type,
+ log_label, af, sock, addr, (is_ssl ? "SSL" : "non-SSL"), so_error,
+ strerror(so_error));
}
static void
-ssl_dump_error_stack (const char *caller)
+ssl_dump_error_stack(const char *caller)
{
- unsigned long errnum = 0;
- char errbuf[120] = {0, };
+ unsigned long errnum = 0;
+ char errbuf[120] = {
+ 0,
+ };
- /* OpenSSL docs explicitly give 120 as the error-string length. */
+ /* OpenSSL docs explicitly give 120 as the error-string length. */
- while ((errnum = ERR_get_error())) {
- ERR_error_string(errnum, errbuf);
- gf_log(caller, GF_LOG_ERROR, " %s", errbuf);
- }
+ while ((errnum = ERR_get_error())) {
+ ERR_error_string(errnum, errbuf);
+ gf_log(caller, GF_LOG_ERROR, " %s", errbuf);
+ }
}
static int
-ssl_do (rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func)
+ssl_do(rpc_transport_t *this, void *buf, size_t len, SSL_trinary_func *func)
{
- int r = (-1);
- socket_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO(this->name, this->private, out);
- priv = this->private;
-
- if (buf) {
- if (priv->connected == -1) {
- /*
- * Fields in the SSL structure (especially
- * the BIO pointers) are not valid at this
- * point, so we'll segfault if we pass them
- * to SSL_read/SSL_write.
- */
- gf_log (this->name, GF_LOG_INFO,
- "lost connection in %s", __func__);
- return -1;
- }
- r = func (priv->ssl_ssl, buf, len);
- } else {
- /*
- * We actually need these functions to get to
- * priv->connected == 1.
- */
- r = ((SSL_unary_func *)func)(priv->ssl_ssl);
- }
- switch (SSL_get_error (priv->ssl_ssl, r)) {
+ int r = (-1);
+ socket_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ priv = this->private;
+
+ if (buf) {
+ if (priv->connected == -1) {
+ /*
+ * Fields in the SSL structure (especially
+ * the BIO pointers) are not valid at this
+ * point, so we'll segfault if we pass them
+ * to SSL_read/SSL_write.
+ */
+ gf_log(this->name, GF_LOG_INFO, "lost connection in %s", __func__);
+ return -1;
+ }
+ r = func(priv->ssl_ssl, buf, len);
+ } else {
+ /*
+ * We actually need these functions to get to
+ * priv->connected == 1.
+ */
+ r = ((SSL_unary_func *)func)(priv->ssl_ssl);
+ }
+ switch (SSL_get_error(priv->ssl_ssl, r)) {
case SSL_ERROR_NONE:
/* fall through */
case SSL_ERROR_WANT_READ:
/* fall through */
case SSL_ERROR_WANT_WRITE:
- errno = EAGAIN;
- return r;
+ errno = EAGAIN;
+ return r;
case SSL_ERROR_SYSCALL:
- /* Sometimes SSL_ERROR_SYSCALL returns errno as
- * EAGAIN. In such a case we should reattempt operation
- * So, for now, just return the return value and the
- * errno as is.
- */
- gf_log (this->name, GF_LOG_DEBUG,
- "syscall error (probably remote disconnect) "
- "errno:%d:%s", errno, strerror(errno));
- return r;
+ /* Sometimes SSL_ERROR_SYSCALL returns errno as
+ * EAGAIN. In such a case we should reattempt operation
+ * So, for now, just return the return value and the
+ * errno as is.
+ */
+ gf_log(this->name, GF_LOG_DEBUG,
+ "syscall error (probably remote disconnect) "
+ "errno:%d:%s",
+ errno, strerror(errno));
+ return r;
default:
- errno = EIO;
- goto out; /* "break" would just loop again */
- }
+ errno = EIO;
+ goto out; /* "break" would just loop again */
+ }
out:
- return -1;
+ return -1;
}
-#define ssl_read_one(t, b, l) ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_read)
-#define ssl_write_one(t, b, l) ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_write)
-
+#define ssl_read_one(t, b, l) \
+ ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_read)
+#define ssl_write_one(t, b, l) \
+ ssl_do((t), (b), (l), (SSL_trinary_func *)SSL_write)
int
-ssl_setup_connection_prefix (rpc_transport_t *this)
+ssl_setup_connection_prefix(rpc_transport_t *this)
{
- int ret = -1;
- socket_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO(this->name, this->private, done);
+ int ret = -1;
+ socket_private_t *priv = NULL;
- priv = this->private;
-
- if (ssl_setup_connection_params (this) < 0) {
- gf_log (this->name, GF_LOG_TRACE,
- "+ ssl_setup_connection_params() failed!");
- goto done;
- } else {
- gf_log (this->name, GF_LOG_TRACE,
- "+ ssl_setup_connection_params() done!");
- }
+ GF_VALIDATE_OR_GOTO(this->name, this->private, done);
- priv->ssl_error_required = SSL_ERROR_NONE;
- priv->ssl_connected = _gf_false;
- priv->ssl_accepted = _gf_false;
- priv->ssl_context_created = _gf_false;
+ priv = this->private;
- priv->ssl_ssl = SSL_new(priv->ssl_ctx);
- if (!priv->ssl_ssl) {
- gf_log(this->name, GF_LOG_ERROR, "SSL_new failed");
- ssl_dump_error_stack(this->name);
- goto done;
- }
+ if (ssl_setup_connection_params(this) < 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "+ ssl_setup_connection_params() failed!");
+ goto done;
+ } else {
+ gf_log(this->name, GF_LOG_TRACE,
+ "+ ssl_setup_connection_params() done!");
+ }
+
+ priv->ssl_error_required = SSL_ERROR_NONE;
+ priv->ssl_connected = _gf_false;
+ priv->ssl_accepted = _gf_false;
+ priv->ssl_context_created = _gf_false;
+
+ priv->ssl_ssl = SSL_new(priv->ssl_ctx);
+ if (!priv->ssl_ssl) {
+ gf_log(this->name, GF_LOG_ERROR, "SSL_new failed");
+ ssl_dump_error_stack(this->name);
+ goto done;
+ }
- priv->ssl_sbio = BIO_new_socket(priv->sock, BIO_NOCLOSE);
- if (!priv->ssl_sbio) {
- gf_log(this->name, GF_LOG_ERROR, "BIO_new_socket failed");
- ssl_dump_error_stack(this->name);
- goto free_ssl;
- }
+ priv->ssl_sbio = BIO_new_socket(priv->sock, BIO_NOCLOSE);
+ if (!priv->ssl_sbio) {
+ gf_log(this->name, GF_LOG_ERROR, "BIO_new_socket failed");
+ ssl_dump_error_stack(this->name);
+ goto free_ssl;
+ }
- SSL_set_bio (priv->ssl_ssl, priv->ssl_sbio, priv->ssl_sbio);
- ret = 0;
- goto done;
+ SSL_set_bio(priv->ssl_ssl, priv->ssl_sbio, priv->ssl_sbio);
+ ret = 0;
+ goto done;
free_ssl:
- SSL_free(priv->ssl_ssl);
- priv->ssl_ssl = NULL;
+ SSL_free(priv->ssl_ssl);
+ priv->ssl_ssl = NULL;
done:
- return ret;
+ return ret;
}
static char *
-ssl_setup_connection_postfix (rpc_transport_t *this)
+ssl_setup_connection_postfix(rpc_transport_t *this)
{
- X509 *peer = NULL;
- char peer_CN[256] = "";
- socket_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO(this->name, this->private, done);
- priv = this->private;
-
- /* Make sure _SSL verification_ succeeded, yielding an identity. */
- if (SSL_get_verify_result(priv->ssl_ssl) != X509_V_OK) {
- goto ssl_error;
- }
- peer = SSL_get_peer_certificate(priv->ssl_ssl);
- if (!peer) {
- goto ssl_error;
- }
-
- SSL_set_mode(priv->ssl_ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
-
- /* Finally, everything seems OK. */
- X509_NAME_get_text_by_NID(X509_get_subject_name(peer),
- NID_commonName, peer_CN, sizeof(peer_CN)-1);
- peer_CN[sizeof(peer_CN)-1] = '\0';
- gf_log(this->name, GF_LOG_DEBUG, "peer CN = %s", peer_CN);
- gf_log (this->name, GF_LOG_DEBUG,
- "SSL verification succeeded (client: %s) (server: %s)",
- this->peerinfo.identifier, this->myinfo.identifier);
- return gf_strdup(peer_CN);
-
- /* Error paths. */
+ X509 *peer = NULL;
+ char peer_CN[256] = "";
+ socket_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO(this->name, this->private, done);
+ priv = this->private;
+
+ /* Make sure _SSL verification_ succeeded, yielding an identity. */
+ if (SSL_get_verify_result(priv->ssl_ssl) != X509_V_OK) {
+ goto ssl_error;
+ }
+ peer = SSL_get_peer_certificate(priv->ssl_ssl);
+ if (!peer) {
+ goto ssl_error;
+ }
+
+ SSL_set_mode(priv->ssl_ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
+
+ /* Finally, everything seems OK. */
+ X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName,
+ peer_CN, sizeof(peer_CN) - 1);
+ peer_CN[sizeof(peer_CN) - 1] = '\0';
+ gf_log(this->name, GF_LOG_DEBUG, "peer CN = %s", peer_CN);
+ gf_log(this->name, GF_LOG_DEBUG,
+ "SSL verification succeeded (client: %s) (server: %s)",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ return gf_strdup(peer_CN);
+
+ /* Error paths. */
ssl_error:
- gf_log (this->name, GF_LOG_ERROR,
- "SSL connect error (client: %s) (server: %s)",
- this->peerinfo.identifier, this->myinfo.identifier);
- ssl_dump_error_stack(this->name);
+ gf_log(this->name, GF_LOG_ERROR,
+ "SSL connect error (client: %s) (server: %s)",
+ this->peerinfo.identifier, this->myinfo.identifier);
+ ssl_dump_error_stack(this->name);
- SSL_free(priv->ssl_ssl);
- priv->ssl_ssl = NULL;
+ SSL_free(priv->ssl_ssl);
+ priv->ssl_ssl = NULL;
done:
- return NULL;
+ return NULL;
}
-
int
-ssl_complete_connection (rpc_transport_t *this)
+ssl_complete_connection(rpc_transport_t *this)
{
- int ret = -1; /* 1 : implies go back to epoll_wait()
- * 0 : implies successful ssl connection
- * -1: implies continue processing current event
- * as if EPOLLERR has been encountered
- */
- char *cname = NULL;
- int r = -1;
- int ssl_error = -1;
- socket_private_t *priv = NULL;
-
+ int ret = -1; /* 1 : implies go back to epoll_wait()
+ * 0 : implies successful ssl connection
+ * -1: implies continue processing current event
+ * as if EPOLLERR has been encountered
+ */
+ char *cname = NULL;
+ int r = -1;
+ int ssl_error = -1;
+ socket_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (priv->is_server) {
- r = SSL_accept (priv->ssl_ssl);
- } else {
- r = SSL_connect (priv->ssl_ssl);
- }
+ if (priv->is_server) {
+ r = SSL_accept(priv->ssl_ssl);
+ } else {
+ r = SSL_connect(priv->ssl_ssl);
+ }
- ssl_error = SSL_get_error (priv->ssl_ssl, r);
- priv->ssl_error_required = ssl_error;
+ ssl_error = SSL_get_error(priv->ssl_ssl, r);
+ priv->ssl_error_required = ssl_error;
- switch (ssl_error) {
+ switch (ssl_error) {
case SSL_ERROR_NONE:
- cname = ssl_setup_connection_postfix (this);
- if (!cname) {
- /* we've failed to get the cname so
- * we must close the connection
- *
- * treat this as EPOLLERR
- */
- gf_log (this->name, GF_LOG_TRACE,
- "error getting cname");
- errno = ECONNRESET;
- ret = -1;
+ cname = ssl_setup_connection_postfix(this);
+ if (!cname) {
+ /* we've failed to get the cname so
+ * we must close the connection
+ *
+ * treat this as EPOLLERR
+ */
+ gf_log(this->name, GF_LOG_TRACE, "error getting cname");
+ errno = ECONNRESET;
+ ret = -1;
+ } else {
+ this->ssl_name = cname;
+ if (priv->is_server) {
+ priv->ssl_accepted = _gf_true;
+ gf_log(this->name, GF_LOG_TRACE, "ssl_accepted!");
} else {
- this->ssl_name = cname;
- if (priv->is_server) {
- priv->ssl_accepted = _gf_true;
- gf_log (this->name, GF_LOG_TRACE,
- "ssl_accepted!");
- } else {
- priv->ssl_connected = _gf_true;
- gf_log (this->name, GF_LOG_TRACE,
- "ssl_connected!");
- }
- ret = 0;
+ priv->ssl_connected = _gf_true;
+ gf_log(this->name, GF_LOG_TRACE, "ssl_connected!");
}
- break;
+ ret = 0;
+ }
+ break;
case SSL_ERROR_WANT_READ:
/* fall through */
case SSL_ERROR_WANT_WRITE:
- errno = EAGAIN;
- break;
+ errno = EAGAIN;
+ break;
case SSL_ERROR_SYSCALL:
- /* Sometimes SSL_ERROR_SYSCALL returns with errno as EAGAIN
- * So, we should retry the operation.
- * So, for now, we just return the return value and errno as is.
- */
- break;
+ /* Sometimes SSL_ERROR_SYSCALL returns with errno as EAGAIN
+ * So, we should retry the operation.
+ * So, for now, we just return the return value and errno as is.
+ */
+ break;
case SSL_ERROR_SSL:
- /* treat this as EPOLLERR */
- ret = -1;
- break;
+ /* treat this as EPOLLERR */
+ ret = -1;
+ break;
default:
- /* treat this as EPOLLERR */
- errno = EIO;
- ret = -1;
- break;
- }
- return ret;
+ /* treat this as EPOLLERR */
+ errno = EIO;
+ ret = -1;
+ break;
+ }
+ return ret;
}
static void
-ssl_teardown_connection (socket_private_t *priv)
+ssl_teardown_connection(socket_private_t *priv)
{
- if (priv->ssl_ssl) {
- SSL_shutdown(priv->ssl_ssl);
- SSL_clear(priv->ssl_ssl);
- SSL_free(priv->ssl_ssl);
- SSL_CTX_free(priv->ssl_ctx);
- priv->ssl_ssl = NULL;
- priv->ssl_ctx = NULL;
- if (priv->ssl_private_key) {
- GF_FREE (priv->ssl_private_key);
- priv->ssl_private_key = NULL;
- }
- if (priv->ssl_own_cert) {
- GF_FREE (priv->ssl_own_cert);
- priv->ssl_own_cert = NULL;
- }
- if (priv->ssl_ca_list) {
- GF_FREE (priv->ssl_ca_list);
- priv->ssl_ca_list = NULL;
- }
+ if (priv->ssl_ssl) {
+ SSL_shutdown(priv->ssl_ssl);
+ SSL_clear(priv->ssl_ssl);
+ SSL_free(priv->ssl_ssl);
+ SSL_CTX_free(priv->ssl_ctx);
+ priv->ssl_ssl = NULL;
+ priv->ssl_ctx = NULL;
+ if (priv->ssl_private_key) {
+ GF_FREE(priv->ssl_private_key);
+ priv->ssl_private_key = NULL;
}
- priv->use_ssl = _gf_false;
+ if (priv->ssl_own_cert) {
+ GF_FREE(priv->ssl_own_cert);
+ priv->ssl_own_cert = NULL;
+ }
+ if (priv->ssl_ca_list) {
+ GF_FREE(priv->ssl_ca_list);
+ priv->ssl_ca_list = NULL;
+ }
+ }
+ priv->use_ssl = _gf_false;
}
-
static ssize_t
-__socket_ssl_readv (rpc_transport_t *this, struct iovec *opvector, int opcount)
+__socket_ssl_readv(rpc_transport_t *this, struct iovec *opvector, int opcount)
{
- socket_private_t *priv = NULL;
- int sock = -1;
- int ret = -1;
-
- priv = this->private;
- sock = priv->sock;
-
- if (priv->use_ssl) {
- gf_log (this->name, GF_LOG_TRACE, "***** reading over SSL");
- ret = ssl_read_one (this, opvector->iov_base, opvector->iov_len);
- } else {
- gf_log (this->name, GF_LOG_TRACE, "***** reading over non-SSL");
- ret = sys_readv (sock, opvector, IOV_MIN(opcount));
- }
-
- return ret;
+ socket_private_t *priv = NULL;
+ int sock = -1;
+ int ret = -1;
+
+ priv = this->private;
+ sock = priv->sock;
+
+ if (priv->use_ssl) {
+ gf_log(this->name, GF_LOG_TRACE, "***** reading over SSL");
+ ret = ssl_read_one(this, opvector->iov_base, opvector->iov_len);
+ } else {
+ gf_log(this->name, GF_LOG_TRACE, "***** reading over non-SSL");
+ ret = sys_readv(sock, opvector, IOV_MIN(opcount));
+ }
+
+ return ret;
}
-
static ssize_t
-__socket_ssl_read (rpc_transport_t *this, void *buf, size_t count)
+__socket_ssl_read(rpc_transport_t *this, void *buf, size_t count)
{
- struct iovec iov = {0, };
- int ret = -1;
+ struct iovec iov = {
+ 0,
+ };
+ int ret = -1;
- iov.iov_base = buf;
- iov.iov_len = count;
+ iov.iov_base = buf;
+ iov.iov_len = count;
- ret = __socket_ssl_readv (this, &iov, 1);
+ ret = __socket_ssl_readv(this, &iov, 1);
- return ret;
+ return ret;
}
-
static int
-__socket_cached_read (rpc_transport_t *this, struct iovec *opvector, int opcount)
+__socket_cached_read(rpc_transport_t *this, struct iovec *opvector, int opcount)
{
- socket_private_t *priv = NULL;
- struct gf_sock_incoming *in = NULL;
- int req_len = -1;
- int ret = -1;
-
- priv = this->private;
- in = &priv->incoming;
- req_len = iov_length (opvector, opcount);
-
- if (in->record_state == SP_STATE_READING_FRAGHDR) {
- in->ra_read = 0;
- in->ra_served = 0;
- in->ra_max = 0;
- in->ra_buf = NULL;
- goto uncached;
- }
-
- if (!in->ra_max) {
- /* first call after passing SP_STATE_READING_FRAGHDR */
- in->ra_max = min (RPC_FRAGSIZE (in->fraghdr), GF_SOCKET_RA_MAX);
- /* Note that the in->iobuf is the primary iobuf into which
- headers are read into, and in->frag.fragcurrent points to
- some position in the buffer. By using this itself as our
- read-ahead cache, we can avoid memory copies in iov_load
- */
- in->ra_buf = in->frag.fragcurrent;
- }
-
- /* fill read-ahead */
- if (in->ra_read < in->ra_max) {
- ret = __socket_ssl_read (this, &in->ra_buf[in->ra_read],
- (in->ra_max - in->ra_read));
- if (ret > 0)
- in->ra_read += ret;
-
- /* we proceed to test if there is still cached data to
- be served even if readahead could not progress */
- }
-
- /* serve cached */
- if (in->ra_served < in->ra_read) {
- ret = iov_load (opvector, opcount, &in->ra_buf[in->ra_served],
- min (req_len, (in->ra_read - in->ra_served)));
-
- in->ra_served += ret;
- /* Do not read uncached and cached in the same call */
- goto out;
- }
-
- if (in->ra_read < in->ra_max)
- /* If there was no cached data to be served, (and we are
- guaranteed to have already performed an attempt to progress
- readahead above), and we have not yet read out the full
- readahead capacity, then bail out for now without doing
- the uncached read below (as that will overtake future cached
- read)
- */
- goto out;
+ socket_private_t *priv = NULL;
+ struct gf_sock_incoming *in = NULL;
+ int req_len = -1;
+ int ret = -1;
+
+ priv = this->private;
+ in = &priv->incoming;
+ req_len = iov_length(opvector, opcount);
+
+ if (in->record_state == SP_STATE_READING_FRAGHDR) {
+ in->ra_read = 0;
+ in->ra_served = 0;
+ in->ra_max = 0;
+ in->ra_buf = NULL;
+ goto uncached;
+ }
+
+ if (!in->ra_max) {
+ /* first call after passing SP_STATE_READING_FRAGHDR */
+ in->ra_max = min(RPC_FRAGSIZE(in->fraghdr), GF_SOCKET_RA_MAX);
+ /* Note that the in->iobuf is the primary iobuf into which
+ headers are read into, and in->frag.fragcurrent points to
+ some position in the buffer. By using this itself as our
+ read-ahead cache, we can avoid memory copies in iov_load
+ */
+ in->ra_buf = in->frag.fragcurrent;
+ }
+
+ /* fill read-ahead */
+ if (in->ra_read < in->ra_max) {
+ ret = __socket_ssl_read(this, &in->ra_buf[in->ra_read],
+ (in->ra_max - in->ra_read));
+ if (ret > 0)
+ in->ra_read += ret;
+
+ /* we proceed to test if there is still cached data to
+ be served even if readahead could not progress */
+ }
+
+ /* serve cached */
+ if (in->ra_served < in->ra_read) {
+ ret = iov_load(opvector, opcount, &in->ra_buf[in->ra_served],
+ min(req_len, (in->ra_read - in->ra_served)));
+
+ in->ra_served += ret;
+ /* Do not read uncached and cached in the same call */
+ goto out;
+ }
+
+ if (in->ra_read < in->ra_max)
+ /* If there was no cached data to be served, (and we are
+ guaranteed to have already performed an attempt to progress
+ readahead above), and we have not yet read out the full
+ readahead capacity, then bail out for now without doing
+ the uncached read below (as that will overtake future cached
+ read)
+ */
+ goto out;
uncached:
- ret = __socket_ssl_readv (this, opvector, opcount);
+ ret = __socket_ssl_readv(this, opvector, opcount);
out:
- return ret;
+ return ret;
}
static gf_boolean_t
-__does_socket_rwv_error_need_logging (socket_private_t *priv, int write)
+__does_socket_rwv_error_need_logging(socket_private_t *priv, int write)
{
- int read = !write;
+ int read = !write;
- if (priv->connected == -1) /* Didn't even connect, of course it fails */
- return _gf_false;
+ if (priv->connected == -1) /* Didn't even connect, of course it fails */
+ return _gf_false;
- if (read && (priv->read_fail_log == _gf_false))
- return _gf_false;
+ if (read && (priv->read_fail_log == _gf_false))
+ return _gf_false;
- return _gf_true;
+ return _gf_true;
}
/*
@@ -637,822 +629,786 @@ __does_socket_rwv_error_need_logging (socket_private_t *priv, int write)
*/
static int
-__socket_rwv (rpc_transport_t *this, struct iovec *vector, int count,
- struct iovec **pending_vector, int *pending_count, size_t *bytes,
- int write)
+__socket_rwv(rpc_transport_t *this, struct iovec *vector, int count,
+ struct iovec **pending_vector, int *pending_count, size_t *bytes,
+ int write)
{
- socket_private_t *priv = NULL;
- int sock = -1;
- int ret = -1;
- struct iovec *opvector = NULL;
- int opcount = 0;
- int moved = 0;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
- sock = priv->sock;
-
- opvector = vector;
- opcount = count;
-
- if (bytes != NULL) {
- *bytes = 0;
+ socket_private_t *priv = NULL;
+ int sock = -1;
+ int ret = -1;
+ struct iovec *opvector = NULL;
+ int opcount = 0;
+ int moved = 0;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+ sock = priv->sock;
+
+ opvector = vector;
+ opcount = count;
+
+ if (bytes != NULL) {
+ *bytes = 0;
+ }
+
+ while (opcount > 0) {
+ if (opvector->iov_len == 0) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "would have passed zero length to read/write");
+ ++opvector;
+ --opcount;
+ continue;
+ }
+ if (priv->use_ssl && !priv->ssl_ssl) {
+ /*
+ * We could end up here with priv->ssl_ssl still NULL
+ * if (a) the connection failed and (b) some fool
+ * called other socket functions anyway. Demoting to
+ * non-SSL might be insecure, so just fail it outright.
+ */
+ ret = -1;
+ gf_log(this->name, GF_LOG_TRACE,
+ "### no priv->ssl_ssl yet; ret = -1;");
+ } else if (write) {
+ if (priv->use_ssl) {
+ ret = ssl_write_one(this, opvector->iov_base,
+ opvector->iov_len);
+ } else {
+ ret = sys_writev(sock, opvector, IOV_MIN(opcount));
+ }
+
+ if (ret == 0 || (ret == -1 && errno == EAGAIN)) {
+ /* done for now */
+ break;
+ }
+ this->total_bytes_write += ret;
+ } else {
+ ret = __socket_cached_read(this, opvector, opcount);
+ if (ret == 0) {
+ gf_log(this->name, GF_LOG_DEBUG, "EOF on socket (errno:%d:%s)",
+ errno, strerror(errno));
+ errno = ENODATA;
+ ret = -1;
+ }
+ if (ret == -1 && errno == EAGAIN) {
+ /* done for now */
+ break;
+ }
+ this->total_bytes_read += ret;
}
- while (opcount > 0) {
- if (opvector->iov_len == 0) {
- gf_log(this->name, GF_LOG_DEBUG,
- "would have passed zero length to read/write");
- ++opvector;
- --opcount;
- continue;
- }
- if (priv->use_ssl && !priv->ssl_ssl) {
- /*
- * We could end up here with priv->ssl_ssl still NULL
- * if (a) the connection failed and (b) some fool
- * called other socket functions anyway. Demoting to
- * non-SSL might be insecure, so just fail it outright.
- */
- ret = -1;
- gf_log (this->name, GF_LOG_TRACE,
- "### no priv->ssl_ssl yet; ret = -1;");
- } else if (write) {
- if (priv->use_ssl) {
- ret = ssl_write_one (this, opvector->iov_base,
- opvector->iov_len);
- } else {
- ret = sys_writev (sock, opvector, IOV_MIN(opcount));
- }
-
- if (ret == 0 || (ret == -1 && errno == EAGAIN)) {
- /* done for now */
- break;
- }
- this->total_bytes_write += ret;
- } else {
- ret = __socket_cached_read (this, opvector, opcount);
- if (ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "EOF on socket (errno:%d:%s)",
- errno, strerror (errno));
- errno = ENODATA;
- ret = -1;
- }
- if (ret == -1 && errno == EAGAIN) {
- /* done for now */
- break;
- }
- this->total_bytes_read += ret;
- }
-
- if (ret == 0) {
- /* Mostly due to 'umount' in client */
-
- gf_log (this->name, GF_LOG_DEBUG,
- "EOF from peer %s", this->peerinfo.identifier);
- opcount = -1;
- errno = ENOTCONN;
- break;
- }
- if (ret == -1) {
- if (errno == EINTR)
- continue;
-
- if (__does_socket_rwv_error_need_logging (priv,
- write)) {
- GF_LOG_OCCASIONALLY(priv->log_ctr, this->name,
- GF_LOG_WARNING,
- "%s on %s failed (%s)",
- write ? "writev":"readv",
- this->peerinfo.identifier,
- strerror (errno));
- }
-
- if (priv->use_ssl && priv->ssl_ssl) {
- ssl_dump_error_stack(this->name);
- }
- opcount = -1;
- break;
- }
+ if (ret == 0) {
+ /* Mostly due to 'umount' in client */
- if (bytes != NULL) {
- *bytes += ret;
- }
+ gf_log(this->name, GF_LOG_DEBUG, "EOF from peer %s",
+ this->peerinfo.identifier);
+ opcount = -1;
+ errno = ENOTCONN;
+ break;
+ }
+ if (ret == -1) {
+ if (errno == EINTR)
+ continue;
- moved = 0;
+ if (__does_socket_rwv_error_need_logging(priv, write)) {
+ GF_LOG_OCCASIONALLY(priv->log_ctr, this->name, GF_LOG_WARNING,
+ "%s on %s failed (%s)",
+ write ? "writev" : "readv",
+ this->peerinfo.identifier, strerror(errno));
+ }
- while (moved < ret) {
- if (!opcount) {
- gf_log(this->name, GF_LOG_DEBUG,
- "ran out of iov, moved %d/%d",
- moved, ret);
- goto ran_out;
- }
- if (!opvector[0].iov_len) {
- opvector++;
- opcount--;
- continue;
- }
- if ((ret - moved) >= opvector[0].iov_len) {
- moved += opvector[0].iov_len;
- opvector++;
- opcount--;
- } else {
- opvector[0].iov_len -= (ret - moved);
- opvector[0].iov_base += (ret - moved);
- moved += (ret - moved);
- }
- }
+ if (priv->use_ssl && priv->ssl_ssl) {
+ ssl_dump_error_stack(this->name);
+ }
+ opcount = -1;
+ break;
}
+ if (bytes != NULL) {
+ *bytes += ret;
+ }
+
+ moved = 0;
+
+ while (moved < ret) {
+ if (!opcount) {
+ gf_log(this->name, GF_LOG_DEBUG, "ran out of iov, moved %d/%d",
+ moved, ret);
+ goto ran_out;
+ }
+ if (!opvector[0].iov_len) {
+ opvector++;
+ opcount--;
+ continue;
+ }
+ if ((ret - moved) >= opvector[0].iov_len) {
+ moved += opvector[0].iov_len;
+ opvector++;
+ opcount--;
+ } else {
+ opvector[0].iov_len -= (ret - moved);
+ opvector[0].iov_base += (ret - moved);
+ moved += (ret - moved);
+ }
+ }
+ }
+
ran_out:
- if (pending_vector)
- *pending_vector = opvector;
+ if (pending_vector)
+ *pending_vector = opvector;
- if (pending_count)
- *pending_count = opcount;
+ if (pending_count)
+ *pending_count = opcount;
out:
- return opcount;
+ return opcount;
}
-
static int
-__socket_readv (rpc_transport_t *this, struct iovec *vector, int count,
- struct iovec **pending_vector, int *pending_count,
- size_t *bytes)
+__socket_readv(rpc_transport_t *this, struct iovec *vector, int count,
+ struct iovec **pending_vector, int *pending_count, size_t *bytes)
{
- int ret = -1;
+ int ret = -1;
- ret = __socket_rwv (this, vector, count,
- pending_vector, pending_count, bytes, 0);
+ ret = __socket_rwv(this, vector, count, pending_vector, pending_count,
+ bytes, 0);
- return ret;
+ return ret;
}
-
static int
-__socket_writev (rpc_transport_t *this, struct iovec *vector, int count,
- struct iovec **pending_vector, int *pending_count)
+__socket_writev(rpc_transport_t *this, struct iovec *vector, int count,
+ struct iovec **pending_vector, int *pending_count)
{
- int ret = -1;
+ int ret = -1;
- ret = __socket_rwv (this, vector, count,
- pending_vector, pending_count, NULL, 1);
+ ret = __socket_rwv(this, vector, count, pending_vector, pending_count, NULL,
+ 1);
- return ret;
+ return ret;
}
-
static int
-__socket_shutdown (rpc_transport_t *this)
+__socket_shutdown(rpc_transport_t *this)
{
- int ret = -1;
- socket_private_t *priv = this->private;
-
- priv->connected = -1;
- ret = shutdown (priv->sock, SHUT_RDWR);
- if (ret) {
- /* its already disconnected.. no need to understand
- why it failed to shutdown in normal cases */
- gf_log (this->name, GF_LOG_DEBUG,
- "shutdown() returned %d. %s",
- ret, strerror (errno));
- }
-
- return ret;
+ int ret = -1;
+ socket_private_t *priv = this->private;
+
+ priv->connected = -1;
+ ret = shutdown(priv->sock, SHUT_RDWR);
+ if (ret) {
+ /* its already disconnected.. no need to understand
+ why it failed to shutdown in normal cases */
+ gf_log(this->name, GF_LOG_DEBUG, "shutdown() returned %d. %s", ret,
+ strerror(errno));
+ }
+
+ return ret;
}
static int
-__socket_teardown_connection (rpc_transport_t *this)
+__socket_teardown_connection(rpc_transport_t *this)
{
- int ret = -1;
- socket_private_t *priv = NULL;
+ int ret = -1;
+ socket_private_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- if (priv->use_ssl)
- ssl_teardown_connection(priv);
+ if (priv->use_ssl)
+ ssl_teardown_connection(priv);
- ret = __socket_shutdown(this);
+ ret = __socket_shutdown(this);
out:
- return ret;
+ return ret;
}
static int
-__socket_disconnect (rpc_transport_t *this)
+__socket_disconnect(rpc_transport_t *this)
{
- int ret = -1;
- socket_private_t *priv = NULL;
+ int ret = -1;
+ socket_private_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- gf_log (this->name, GF_LOG_TRACE, "disconnecting %p, sock=%d",
- this, priv->sock);
+ gf_log(this->name, GF_LOG_TRACE, "disconnecting %p, sock=%d", this,
+ priv->sock);
- if (priv->sock != -1) {
- gf_log_callingfn (this->name, GF_LOG_TRACE,
- "tearing down socket connection");
- ret = __socket_teardown_connection (this);
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG,
- "__socket_teardown_connection () failed: %s",
- strerror (errno));
- }
+ if (priv->sock != -1) {
+ gf_log_callingfn(this->name, GF_LOG_TRACE,
+ "tearing down socket connection");
+ ret = __socket_teardown_connection(this);
+ if (ret) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "__socket_teardown_connection () failed: %s",
+ strerror(errno));
}
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_server_bind (rpc_transport_t *this)
+__socket_server_bind(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = -1;
- int opt = 1;
- int reuse_check_sock = -1;
- struct sockaddr_storage unix_addr = {0};
+ socket_private_t *priv = NULL;
+ 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);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- ret = setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR,
- &opt, sizeof (opt));
+ ret = setsockopt(priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "setsockopt() for SO_REUSEADDR failed (%s)",
- strerror (errno));
- }
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "setsockopt() for SO_REUSEADDR failed (%s)", strerror(errno));
+ }
- /* reuse-address doesn't work for unix type sockets */
- if (AF_UNIX == SA (&this->myinfo.sockaddr)->sa_family) {
- memcpy (&unix_addr, SA (&this->myinfo.sockaddr),
- this->myinfo.sockaddr_len);
- reuse_check_sock = socket (AF_UNIX, SOCK_STREAM, 0);
- if (reuse_check_sock >= 0) {
- ret = connect (reuse_check_sock, SA (&unix_addr),
- this->myinfo.sockaddr_len);
- if ((ret == -1) && (ECONNREFUSED == errno)) {
- sys_unlink (((struct sockaddr_un *)&unix_addr)->sun_path);
- }
- sys_close (reuse_check_sock);
- }
+ /* reuse-address doesn't work for unix type sockets */
+ if (AF_UNIX == SA(&this->myinfo.sockaddr)->sa_family) {
+ memcpy(&unix_addr, SA(&this->myinfo.sockaddr),
+ this->myinfo.sockaddr_len);
+ reuse_check_sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (reuse_check_sock >= 0) {
+ ret = connect(reuse_check_sock, SA(&unix_addr),
+ this->myinfo.sockaddr_len);
+ if ((ret == -1) && (ECONNREFUSED == errno)) {
+ sys_unlink(((struct sockaddr_un *)&unix_addr)->sun_path);
+ }
+ sys_close(reuse_check_sock);
}
+ }
- ret = bind (priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
- this->myinfo.sockaddr_len);
+ ret = bind(priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
+ this->myinfo.sockaddr_len);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "binding to %s failed: %s",
- this->myinfo.identifier, strerror (errno));
- if (errno == EADDRINUSE) {
- gf_log (this->name, GF_LOG_ERROR,
- "Port is already in use");
-
- ret = -EADDRINUSE;
- }
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR, "binding to %s failed: %s",
+ this->myinfo.identifier, strerror(errno));
+ if (errno == EADDRINUSE) {
+ gf_log(this->name, GF_LOG_ERROR, "Port is already in use");
+
+ ret = -EADDRINUSE;
}
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_nonblock (int fd)
+__socket_nonblock(int fd)
{
- int flags = 0;
- int ret = -1;
+ int flags = 0;
+ int ret = -1;
- flags = fcntl (fd, F_GETFL);
+ flags = fcntl(fd, F_GETFL);
- if (flags != -1)
- ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+ if (flags != -1)
+ ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- return ret;
+ return ret;
}
static int
-__socket_nodelay (int fd)
+__socket_nodelay(int fd)
{
- int on = 1;
- int ret = -1;
+ int on = 1;
+ int ret = -1;
- ret = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
- &on, sizeof (on));
- if (!ret)
- gf_log (THIS->name, GF_LOG_TRACE,
- "NODELAY enabled for socket %d", fd);
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+ if (!ret)
+ gf_log(THIS->name, GF_LOG_TRACE, "NODELAY enabled for socket %d", fd);
- return ret;
+ return ret;
}
-
static int
-__socket_keepalive (int fd, int family, int keepaliveintvl,
- int keepaliveidle, int keepalivecnt, int timeout)
+__socket_keepalive(int fd, int family, int keepaliveintvl, int keepaliveidle,
+ int keepalivecnt, int timeout)
{
- int on = 1;
- int ret = -1;
+ int on = 1;
+ int ret = -1;
#if defined(TCP_USER_TIMEOUT)
- int timeout_ms = timeout * 1000;
+ int timeout_ms = timeout * 1000;
#endif
- ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on));
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING,
- "failed to set keep alive option on socket %d", fd);
- goto err;
- }
+ ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set keep alive option on socket %d", fd);
+ goto err;
+ }
- if (keepaliveintvl == GF_USE_DEFAULT_KEEPALIVE)
- goto done;
+ if (keepaliveintvl == GF_USE_DEFAULT_KEEPALIVE)
+ goto done;
#if !defined(GF_LINUX_HOST_OS) && !defined(__NetBSD__)
#if defined(GF_SOLARIS_HOST_OS) || defined(__FreeBSD__)
- ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &keepaliveintvl,
- sizeof (keepaliveintvl));
+ ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepaliveintvl,
+ sizeof(keepaliveintvl));
#else
- ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepaliveintvl,
- sizeof (keepaliveintvl));
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepaliveintvl,
+ sizeof(keepaliveintvl));
#endif
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING,
- "failed to set keep alive interval on socket %d", fd);
- goto err;
- }
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set keep alive interval on socket %d", fd);
+ goto err;
+ }
#else
- if (family != AF_INET && family != AF_INET6)
- goto done;
+ if (family != AF_INET && family != AF_INET6)
+ goto done;
- ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepaliveidle,
- sizeof (keepaliveidle));
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING,
- "failed to set keep idle %d on socket %d, %s",
- keepaliveidle, fd, strerror(errno));
- goto err;
- }
- ret = setsockopt (fd, IPPROTO_TCP , TCP_KEEPINTVL, &keepaliveintvl,
- sizeof (keepaliveintvl));
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING,
- "failed to set keep interval %d on socket %d, %s",
- keepaliveintvl, fd, strerror(errno));
- goto err;
- }
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepaliveidle,
+ sizeof(keepaliveidle));
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set keep idle %d on socket %d, %s", keepaliveidle, fd,
+ strerror(errno));
+ goto err;
+ }
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepaliveintvl,
+ sizeof(keepaliveintvl));
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set keep interval %d on socket %d, %s",
+ keepaliveintvl, fd, strerror(errno));
+ goto err;
+ }
#if defined(TCP_USER_TIMEOUT)
- if (timeout_ms < 0)
- goto done;
- ret = setsockopt (fd, IPPROTO_TCP , TCP_USER_TIMEOUT, &timeout_ms,
- sizeof (timeout_ms));
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING, "failed to set "
- "TCP_USER_TIMEOUT %d on socket %d, %s", timeout_ms, fd,
- strerror(errno));
- goto err;
- }
+ if (timeout_ms < 0)
+ goto done;
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout_ms,
+ sizeof(timeout_ms));
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set "
+ "TCP_USER_TIMEOUT %d on socket %d, %s",
+ timeout_ms, fd, strerror(errno));
+ goto err;
+ }
#endif
#if defined(TCP_KEEPCNT)
- ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPCNT, &keepalivecnt,
- sizeof (keepalivecnt));
- if (ret == -1) {
- gf_log ("socket", GF_LOG_WARNING, "failed to set "
- "TCP_KEEPCNT %d on socket %d, %s", keepalivecnt, fd,
- strerror(errno));
- goto err;
- }
+ ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepalivecnt,
+ sizeof(keepalivecnt));
+ if (ret == -1) {
+ gf_log("socket", GF_LOG_WARNING,
+ "failed to set "
+ "TCP_KEEPCNT %d on socket %d, %s",
+ keepalivecnt, fd, strerror(errno));
+ goto err;
+ }
#endif
#endif
done:
- gf_log (THIS->name, GF_LOG_TRACE, "Keep-alive enabled for socket: %d, "
- "(idle: %d, interval: %d, max-probes: %d, timeout: %d)",
- fd, keepaliveidle, keepaliveintvl, keepalivecnt,
- timeout);
+ gf_log(THIS->name, GF_LOG_TRACE,
+ "Keep-alive enabled for socket: %d, "
+ "(idle: %d, interval: %d, max-probes: %d, timeout: %d)",
+ fd, keepaliveidle, keepaliveintvl, keepalivecnt, timeout);
err:
- return ret;
+ return ret;
}
-
static int
-__socket_connect_finish (int fd)
+__socket_connect_finish(int fd)
{
- int ret = -1;
- int optval = 0;
- socklen_t optlen = sizeof (int);
+ int ret = -1;
+ int optval = 0;
+ socklen_t optlen = sizeof(int);
- ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen);
+ ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen);
- if (ret == 0 && optval) {
- errno = optval;
- ret = -1;
- }
+ if (ret == 0 && optval) {
+ errno = optval;
+ ret = -1;
+ }
- return ret;
+ return ret;
}
-
static void
-__socket_reset (rpc_transport_t *this)
+__socket_reset(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
-
- /* TODO: use mem-pool on incoming data */
-
- if (priv->incoming.iobref) {
- iobref_unref (priv->incoming.iobref);
- priv->incoming.iobref = NULL;
- }
-
- if (priv->incoming.iobuf) {
- iobuf_unref (priv->incoming.iobuf);
- priv->incoming.iobuf = NULL;
- }
-
- GF_FREE (priv->incoming.request_info);
-
- memset (&priv->incoming, 0, sizeof (priv->incoming));
-
- event_unregister_close (this->ctx->event_pool, priv->sock, priv->idx);
-
- priv->sock = -1;
- priv->idx = -1;
- priv->connected = -1;
- priv->ssl_connected = _gf_false;
- priv->ssl_accepted = _gf_false;
- priv->ssl_context_created = _gf_false;
-
- if (priv->ssl_private_key) {
- GF_FREE (priv->ssl_private_key);
- priv->ssl_private_key = NULL;
- }
- if (priv->ssl_own_cert) {
- GF_FREE (priv->ssl_own_cert);
- priv->ssl_own_cert = NULL;
- }
- if (priv->ssl_ca_list) {
- GF_FREE (priv->ssl_ca_list);
- priv->ssl_ca_list = NULL;
- }
+ socket_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+
+ /* TODO: use mem-pool on incoming data */
+
+ if (priv->incoming.iobref) {
+ iobref_unref(priv->incoming.iobref);
+ priv->incoming.iobref = NULL;
+ }
+
+ if (priv->incoming.iobuf) {
+ iobuf_unref(priv->incoming.iobuf);
+ priv->incoming.iobuf = NULL;
+ }
+
+ GF_FREE(priv->incoming.request_info);
+
+ memset(&priv->incoming, 0, sizeof(priv->incoming));
+
+ event_unregister_close(this->ctx->event_pool, priv->sock, priv->idx);
+
+ priv->sock = -1;
+ priv->idx = -1;
+ priv->connected = -1;
+ priv->ssl_connected = _gf_false;
+ priv->ssl_accepted = _gf_false;
+ priv->ssl_context_created = _gf_false;
+
+ if (priv->ssl_private_key) {
+ GF_FREE(priv->ssl_private_key);
+ priv->ssl_private_key = NULL;
+ }
+ if (priv->ssl_own_cert) {
+ GF_FREE(priv->ssl_own_cert);
+ priv->ssl_own_cert = NULL;
+ }
+ if (priv->ssl_ca_list) {
+ GF_FREE(priv->ssl_ca_list);
+ priv->ssl_ca_list = NULL;
+ }
out:
- return;
+ return;
}
-
static void
-socket_set_lastfrag (uint32_t *fragsize) {
- (*fragsize) |= 0x80000000U;
+socket_set_lastfrag(uint32_t *fragsize)
+{
+ (*fragsize) |= 0x80000000U;
}
-
static void
-socket_set_frag_header_size (uint32_t size, char *haddr)
+socket_set_frag_header_size(uint32_t size, char *haddr)
{
- size = htonl (size);
- memcpy (haddr, &size, sizeof (size));
+ size = htonl(size);
+ memcpy(haddr, &size, sizeof(size));
}
-
static void
-socket_set_last_frag_header_size (uint32_t size, char *haddr)
+socket_set_last_frag_header_size(uint32_t size, char *haddr)
{
- socket_set_lastfrag (&size);
- socket_set_frag_header_size (size, haddr);
+ socket_set_lastfrag(&size);
+ socket_set_frag_header_size(size, haddr);
}
static struct ioq *
-__socket_ioq_new (rpc_transport_t *this, rpc_transport_msg_t *msg)
+__socket_ioq_new(rpc_transport_t *this, rpc_transport_msg_t *msg)
{
- struct ioq *entry = NULL;
- int count = 0;
- uint32_t size = 0;
+ struct ioq *entry = NULL;
+ int count = 0;
+ uint32_t size = 0;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
- /* TODO: use mem-pool */
- entry = GF_CALLOC (1, sizeof (*entry), gf_common_mt_ioq);
- if (!entry)
- return NULL;
+ /* TODO: use mem-pool */
+ entry = GF_CALLOC(1, sizeof(*entry), gf_common_mt_ioq);
+ if (!entry)
+ return NULL;
- count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount;
+ count = msg->rpchdrcount + msg->proghdrcount + msg->progpayloadcount;
- GF_ASSERT (count <= (MAX_IOVEC - 1));
+ GF_ASSERT(count <= (MAX_IOVEC - 1));
- size = iov_length (msg->rpchdr, msg->rpchdrcount)
- + iov_length (msg->proghdr, msg->proghdrcount)
- + iov_length (msg->progpayload, msg->progpayloadcount);
+ size = iov_length(msg->rpchdr, msg->rpchdrcount) +
+ iov_length(msg->proghdr, msg->proghdrcount) +
+ iov_length(msg->progpayload, msg->progpayloadcount);
- if (size > RPC_MAX_FRAGMENT_SIZE) {
- gf_log (this->name, GF_LOG_ERROR,
- "msg size (%u) bigger than the maximum allowed size on "
- "sockets (%u)", size, RPC_MAX_FRAGMENT_SIZE);
- GF_FREE (entry);
- return NULL;
- }
+ if (size > RPC_MAX_FRAGMENT_SIZE) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "msg size (%u) bigger than the maximum allowed size on "
+ "sockets (%u)",
+ size, RPC_MAX_FRAGMENT_SIZE);
+ GF_FREE(entry);
+ return NULL;
+ }
- socket_set_last_frag_header_size (size, (char *)&entry->fraghdr);
+ socket_set_last_frag_header_size(size, (char *)&entry->fraghdr);
- entry->vector[0].iov_base = (char *)&entry->fraghdr;
- entry->vector[0].iov_len = sizeof (entry->fraghdr);
- entry->count = 1;
+ entry->vector[0].iov_base = (char *)&entry->fraghdr;
+ entry->vector[0].iov_len = sizeof(entry->fraghdr);
+ entry->count = 1;
- if (msg->rpchdr != NULL) {
- memcpy (&entry->vector[1], msg->rpchdr,
- sizeof (struct iovec) * msg->rpchdrcount);
- entry->count += msg->rpchdrcount;
- }
+ if (msg->rpchdr != NULL) {
+ memcpy(&entry->vector[1], msg->rpchdr,
+ sizeof(struct iovec) * msg->rpchdrcount);
+ entry->count += msg->rpchdrcount;
+ }
- if (msg->proghdr != NULL) {
- memcpy (&entry->vector[entry->count], msg->proghdr,
- sizeof (struct iovec) * msg->proghdrcount);
- entry->count += msg->proghdrcount;
- }
+ if (msg->proghdr != NULL) {
+ memcpy(&entry->vector[entry->count], msg->proghdr,
+ sizeof(struct iovec) * msg->proghdrcount);
+ entry->count += msg->proghdrcount;
+ }
- if (msg->progpayload != NULL) {
- memcpy (&entry->vector[entry->count], msg->progpayload,
- sizeof (struct iovec) * msg->progpayloadcount);
- entry->count += msg->progpayloadcount;
- }
+ if (msg->progpayload != NULL) {
+ memcpy(&entry->vector[entry->count], msg->progpayload,
+ sizeof(struct iovec) * msg->progpayloadcount);
+ entry->count += msg->progpayloadcount;
+ }
- entry->pending_vector = entry->vector;
- entry->pending_count = entry->count;
+ entry->pending_vector = entry->vector;
+ entry->pending_count = entry->count;
- if (msg->iobref != NULL)
- entry->iobref = iobref_ref (msg->iobref);
+ if (msg->iobref != NULL)
+ entry->iobref = iobref_ref(msg->iobref);
- INIT_LIST_HEAD (&entry->list);
+ INIT_LIST_HEAD(&entry->list);
out:
- return entry;
+ return entry;
}
-
static void
-__socket_ioq_entry_free (struct ioq *entry)
+__socket_ioq_entry_free(struct ioq *entry)
{
- GF_VALIDATE_OR_GOTO ("socket", entry, out);
+ GF_VALIDATE_OR_GOTO("socket", entry, out);
- list_del_init (&entry->list);
- if (entry->iobref)
- iobref_unref (entry->iobref);
+ list_del_init(&entry->list);
+ if (entry->iobref)
+ iobref_unref(entry->iobref);
- /* TODO: use mem-pool */
- GF_FREE (entry);
+ /* TODO: use mem-pool */
+ GF_FREE(entry);
out:
- return;
+ return;
}
-
static void
-__socket_ioq_flush (rpc_transport_t *this)
+__socket_ioq_flush(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- struct ioq *entry = NULL;
+ socket_private_t *priv = NULL;
+ struct ioq *entry = NULL;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- while (!list_empty (&priv->ioq)) {
- entry = priv->ioq_next;
- __socket_ioq_entry_free (entry);
- }
+ while (!list_empty(&priv->ioq)) {
+ entry = priv->ioq_next;
+ __socket_ioq_entry_free(entry);
+ }
out:
- return;
+ return;
}
-
static int
-__socket_ioq_churn_entry (rpc_transport_t *this, struct ioq *entry, int direct)
+__socket_ioq_churn_entry(rpc_transport_t *this, struct ioq *entry, int direct)
{
- int ret = -1;
+ int ret = -1;
- ret = __socket_writev (this, entry->pending_vector,
- entry->pending_count,
- &entry->pending_vector,
- &entry->pending_count);
+ ret = __socket_writev(this, entry->pending_vector, entry->pending_count,
+ &entry->pending_vector, &entry->pending_count);
- if (ret == 0) {
- /* current entry was completely written */
- GF_ASSERT (entry->pending_count == 0);
- __socket_ioq_entry_free (entry);
- }
+ if (ret == 0) {
+ /* current entry was completely written */
+ GF_ASSERT(entry->pending_count == 0);
+ __socket_ioq_entry_free(entry);
+ }
- return ret;
+ return ret;
}
-
static int
-__socket_ioq_churn (rpc_transport_t *this)
+__socket_ioq_churn(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = 0;
- struct ioq *entry = NULL;
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ struct ioq *entry = NULL;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- while (!list_empty (&priv->ioq)) {
- /* pick next entry */
- entry = priv->ioq_next;
+ while (!list_empty(&priv->ioq)) {
+ /* pick next entry */
+ entry = priv->ioq_next;
- ret = __socket_ioq_churn_entry (this, entry, 0);
+ ret = __socket_ioq_churn_entry(this, entry, 0);
- if (ret != 0)
- break;
- }
+ if (ret != 0)
+ break;
+ }
- if (list_empty (&priv->ioq)) {
- /* all pending writes done, not interested in POLLOUT */
- priv->idx = event_select_on (this->ctx->event_pool,
- priv->sock, priv->idx, -1, 0);
- }
+ if (list_empty(&priv->ioq)) {
+ /* all pending writes done, not interested in POLLOUT */
+ priv->idx = event_select_on(this->ctx->event_pool, priv->sock,
+ priv->idx, -1, 0);
+ }
out:
- return ret;
+ return ret;
}
-
static gf_boolean_t
-socket_event_poll_err (rpc_transport_t *this, int gen, int idx)
+socket_event_poll_err(rpc_transport_t *this, int gen, int idx)
{
- socket_private_t *priv = NULL;
- gf_boolean_t socket_closed = _gf_false;
+ socket_private_t *priv = NULL;
+ gf_boolean_t socket_closed = _gf_false;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->in_lock);
- pthread_mutex_lock (&priv->out_lock);
- {
- if ((priv->gen == gen) && (priv->idx == idx)
- && (priv->sock != -1)) {
- __socket_ioq_flush (this);
- __socket_reset (this);
- socket_closed = _gf_true;
- }
+ pthread_mutex_lock(&priv->in_lock);
+ pthread_mutex_lock(&priv->out_lock);
+ {
+ if ((priv->gen == gen) && (priv->idx == idx) && (priv->sock != -1)) {
+ __socket_ioq_flush(this);
+ __socket_reset(this);
+ socket_closed = _gf_true;
}
- pthread_mutex_unlock (&priv->out_lock);
- pthread_mutex_unlock (&priv->in_lock);
-
- if (socket_closed) {
- pthread_mutex_lock (&priv->notify.lock);
- {
- while (priv->notify.in_progress)
- pthread_cond_wait (&priv->notify.cond,
- &priv->notify.lock);
- }
- pthread_mutex_unlock (&priv->notify.lock);
+ }
+ pthread_mutex_unlock(&priv->out_lock);
+ pthread_mutex_unlock(&priv->in_lock);
- rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, this);
+ if (socket_closed) {
+ pthread_mutex_lock(&priv->notify.lock);
+ {
+ while (priv->notify.in_progress)
+ pthread_cond_wait(&priv->notify.cond, &priv->notify.lock);
}
+ pthread_mutex_unlock(&priv->notify.lock);
+
+ rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT, this);
+ }
out:
- return socket_closed;
+ return socket_closed;
}
-
static int
-socket_event_poll_out (rpc_transport_t *this)
+socket_event_poll_out(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = -1;
+ socket_private_t *priv = NULL;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->out_lock);
- {
- if (priv->connected == 1) {
- ret = __socket_ioq_churn (this);
-
- if (ret == -1) {
- gf_log (this->name, GF_LOG_TRACE,
- "__socket_ioq_churn returned -1; "
- "disconnecting socket");
- __socket_disconnect (this);
- }
- }
+ pthread_mutex_lock(&priv->out_lock);
+ {
+ if (priv->connected == 1) {
+ ret = __socket_ioq_churn(this);
+
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "__socket_ioq_churn returned -1; "
+ "disconnecting socket");
+ __socket_disconnect(this);
+ }
}
- pthread_mutex_unlock (&priv->out_lock);
+ }
+ pthread_mutex_unlock(&priv->out_lock);
- if (ret == 0)
- ret = rpc_transport_notify (this, RPC_TRANSPORT_MSG_SENT, NULL);
+ if (ret == 0)
+ ret = rpc_transport_notify(this, RPC_TRANSPORT_MSG_SENT, NULL);
out:
- return ret;
+ return ret;
}
-
static int
-__socket_read_simple_msg (rpc_transport_t *this)
+__socket_read_simple_msg(rpc_transport_t *this)
{
- int ret = 0;
- uint32_t remaining_size = 0;
- size_t bytes_read = 0;
- socket_private_t *priv = NULL;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ int ret = 0;
+ uint32_t remaining_size = 0;
+ size_t bytes_read = 0;
+ socket_private_t *priv = NULL;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
- priv = this->private;
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- in = &priv->incoming;
- frag = &in->frag;
+ priv = this->private;
- switch (frag->simple_state) {
+ in = &priv->incoming;
+ frag = &in->frag;
+ switch (frag->simple_state) {
case SP_STATE_SIMPLE_MSG_INIT:
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- __socket_proto_init_pending (priv, remaining_size);
+ __socket_proto_init_pending(priv, remaining_size);
- frag->simple_state = SP_STATE_READING_SIMPLE_MSG;
+ frag->simple_state = SP_STATE_READING_SIMPLE_MSG;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_SIMPLE_MSG:
- ret = 0;
+ ret = 0;
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- if (remaining_size > 0) {
- ret = __socket_readv (this,
- in->pending_vector, 1,
- &in->pending_vector,
- &in->pending_count,
- &bytes_read);
- }
+ if (remaining_size > 0) {
+ ret = __socket_readv(this, in->pending_vector, 1,
+ &in->pending_vector, &in->pending_count,
+ &bytes_read);
+ }
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "reading from socket failed. Error (%s), "
- "peer (%s)", strerror (errno),
- this->peerinfo.identifier);
- break;
- }
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "reading from socket failed. Error (%s), "
+ "peer (%s)",
+ strerror(errno), this->peerinfo.identifier);
+ break;
+ }
- frag->bytes_read += bytes_read;
- frag->fragcurrent += bytes_read;
+ frag->bytes_read += bytes_read;
+ frag->fragcurrent += bytes_read;
- if (ret > 0) {
- gf_log (this->name, GF_LOG_TRACE,
- "partial read on non-blocking socket.");
- break;
- }
+ if (ret > 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "partial read on non-blocking socket.");
+ break;
+ }
- if (ret == 0) {
- frag->simple_state = SP_STATE_SIMPLE_MSG_INIT;
- }
- }
+ if (ret == 0) {
+ frag->simple_state = SP_STATE_SIMPLE_MSG_INIT;
+ }
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_read_simple_request (rpc_transport_t *this)
+__socket_read_simple_request(rpc_transport_t *this)
{
- return __socket_read_simple_msg (this);
+ return __socket_read_simple_msg(this);
}
-
#define rpc_cred_addr(buf) (buf + RPC_MSGTYPE_SIZE + RPC_CALL_BODY_SIZE - 4)
#define rpc_verf_addr(fragcurrent) (fragcurrent - 4)
@@ -1464,1875 +1420,1810 @@ __socket_read_simple_request (rpc_transport_t *this)
#define rpc_procnum_addr(buf) (buf + RPC_MSGTYPE_SIZE + 12)
static int
-__socket_read_vectored_request (rpc_transport_t *this, rpcsvc_vector_sizer vector_sizer)
+__socket_read_vectored_request(rpc_transport_t *this,
+ rpcsvc_vector_sizer vector_sizer)
{
- socket_private_t *priv = NULL;
- int ret = 0;
- uint32_t credlen = 0, verflen = 0;
- char *addr = NULL;
- struct iobuf *iobuf = NULL;
- uint32_t remaining_size = 0;
- ssize_t readsize = 0;
- size_t size = 0;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
- sp_rpcfrag_request_state_t *request = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
-
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
- request = &frag->call_body.request;
-
- switch (request->vector_state) {
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ uint32_t credlen = 0, verflen = 0;
+ char *addr = NULL;
+ struct iobuf *iobuf = NULL;
+ uint32_t remaining_size = 0;
+ ssize_t readsize = 0;
+ size_t size = 0;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+ sp_rpcfrag_request_state_t *request = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+ request = &frag->call_body.request;
+
+ switch (request->vector_state) {
case SP_STATE_VECTORED_REQUEST_INIT:
- request->vector_sizer_state = 0;
+ request->vector_sizer_state = 0;
- addr = rpc_cred_addr (iobuf_ptr (in->iobuf));
+ addr = rpc_cred_addr(iobuf_ptr(in->iobuf));
- /* also read verf flavour and verflen */
- credlen = ntoh32 (*((uint32_t *)addr))
- + RPC_AUTH_FLAVOUR_N_LENGTH_SIZE;
+ /* also read verf flavour and verflen */
+ credlen = ntoh32(*((uint32_t *)addr)) +
+ RPC_AUTH_FLAVOUR_N_LENGTH_SIZE;
- __socket_proto_init_pending (priv, credlen);
+ __socket_proto_init_pending(priv, credlen);
- request->vector_state = SP_STATE_READING_CREDBYTES;
+ request->vector_state = SP_STATE_READING_CREDBYTES;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_CREDBYTES:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- request->vector_state = SP_STATE_READ_CREDBYTES;
+ request->vector_state = SP_STATE_READ_CREDBYTES;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_CREDBYTES:
- addr = rpc_verf_addr (frag->fragcurrent);
- verflen = ntoh32 (*((uint32_t *)addr));
+ addr = rpc_verf_addr(frag->fragcurrent);
+ verflen = ntoh32(*((uint32_t *)addr));
- if (verflen == 0) {
- request->vector_state = SP_STATE_READ_VERFBYTES;
- goto sp_state_read_verfbytes;
- }
- __socket_proto_init_pending (priv, verflen);
+ if (verflen == 0) {
+ request->vector_state = SP_STATE_READ_VERFBYTES;
+ goto sp_state_read_verfbytes;
+ }
+ __socket_proto_init_pending(priv, verflen);
- request->vector_state = SP_STATE_READING_VERFBYTES;
+ request->vector_state = SP_STATE_READING_VERFBYTES;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_VERFBYTES:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- request->vector_state = SP_STATE_READ_VERFBYTES;
+ request->vector_state = SP_STATE_READ_VERFBYTES;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_VERFBYTES:
-sp_state_read_verfbytes:
- /* set the base_addr 'persistently' across multiple calls
- into the state machine */
- in->proghdr_base_addr = frag->fragcurrent;
+ sp_state_read_verfbytes:
+ /* set the base_addr 'persistently' across multiple calls
+ into the state machine */
+ in->proghdr_base_addr = frag->fragcurrent;
- request->vector_sizer_state =
- vector_sizer (request->vector_sizer_state,
- &readsize, in->proghdr_base_addr,
- frag->fragcurrent);
- __socket_proto_init_pending (priv, readsize);
+ request->vector_sizer_state = vector_sizer(
+ request->vector_sizer_state, &readsize, in->proghdr_base_addr,
+ frag->fragcurrent);
+ __socket_proto_init_pending(priv, readsize);
- request->vector_state = SP_STATE_READING_PROGHDR;
+ request->vector_state = SP_STATE_READING_PROGHDR;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_PROGHDR:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- request->vector_state = SP_STATE_READ_PROGHDR;
+ request->vector_state = SP_STATE_READ_PROGHDR;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_PROGHDR:
-sp_state_read_proghdr:
- request->vector_sizer_state =
- vector_sizer (request->vector_sizer_state,
- &readsize, in->proghdr_base_addr,
- frag->fragcurrent);
- if (readsize == 0) {
- request->vector_state = SP_STATE_READ_PROGHDR_XDATA;
- goto sp_state_read_proghdr_xdata;
- }
+ sp_state_read_proghdr:
+ request->vector_sizer_state = vector_sizer(
+ request->vector_sizer_state, &readsize, in->proghdr_base_addr,
+ frag->fragcurrent);
+ if (readsize == 0) {
+ request->vector_state = SP_STATE_READ_PROGHDR_XDATA;
+ goto sp_state_read_proghdr_xdata;
+ }
- __socket_proto_init_pending (priv, readsize);
+ __socket_proto_init_pending(priv, readsize);
- request->vector_state = SP_STATE_READING_PROGHDR_XDATA;
+ request->vector_state = SP_STATE_READING_PROGHDR_XDATA;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_PROGHDR_XDATA:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- request->vector_state = SP_STATE_READ_PROGHDR;
- /* check if the vector_sizer() has more to say */
- goto sp_state_read_proghdr;
+ request->vector_state = SP_STATE_READ_PROGHDR;
+ /* check if the vector_sizer() has more to say */
+ goto sp_state_read_proghdr;
case SP_STATE_READ_PROGHDR_XDATA:
-sp_state_read_proghdr_xdata:
- if (in->payload_vector.iov_base == NULL) {
-
- size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (!iobuf) {
- ret = -1;
- break;
- }
-
- if (in->iobref == NULL) {
- in->iobref = iobref_new ();
- if (in->iobref == NULL) {
- ret = -1;
- iobuf_unref (iobuf);
- break;
- }
- }
+ sp_state_read_proghdr_xdata:
+ if (in->payload_vector.iov_base == NULL) {
+ size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (!iobuf) {
+ ret = -1;
+ break;
+ }
+
+ if (in->iobref == NULL) {
+ in->iobref = iobref_new();
+ if (in->iobref == NULL) {
+ ret = -1;
+ iobuf_unref(iobuf);
+ break;
+ }
+ }
- iobref_add (in->iobref, iobuf);
+ iobref_add(in->iobref, iobuf);
- in->payload_vector.iov_base = iobuf_ptr (iobuf);
- frag->fragcurrent = iobuf_ptr (iobuf);
+ in->payload_vector.iov_base = iobuf_ptr(iobuf);
+ frag->fragcurrent = iobuf_ptr(iobuf);
- iobuf_unref (iobuf);
- }
+ iobuf_unref(iobuf);
+ }
- request->vector_state = SP_STATE_READING_PROG;
+ request->vector_state = SP_STATE_READING_PROG;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_PROG:
- /* now read the remaining rpc msg into buffer pointed by
- * fragcurrent
- */
+ /* now read the remaining rpc msg into buffer pointed by
+ * fragcurrent
+ */
- ret = __socket_read_simple_msg (this);
+ ret = __socket_read_simple_msg(this);
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- if ((ret == -1) ||
- ((ret == 0) && (remaining_size == 0)
- && RPC_LASTFRAG (in->fraghdr))) {
- request->vector_state = SP_STATE_VECTORED_REQUEST_INIT;
- in->payload_vector.iov_len
- = ((unsigned long)frag->fragcurrent
- - (unsigned long)in->payload_vector.iov_base);
- }
- break;
- }
+ if ((ret == -1) || ((ret == 0) && (remaining_size == 0) &&
+ RPC_LASTFRAG(in->fraghdr))) {
+ request->vector_state = SP_STATE_VECTORED_REQUEST_INIT;
+ in->payload_vector.iov_len = ((unsigned long)frag->fragcurrent -
+ (unsigned long)
+ in->payload_vector.iov_base);
+ }
+ break;
+ }
out:
- return ret;
+ return ret;
}
static int
-__socket_read_request (rpc_transport_t *this)
+__socket_read_request(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- uint32_t prognum = 0, procnum = 0, progver = 0;
- uint32_t remaining_size = 0;
- int ret = -1;
- char *buf = NULL;
- rpcsvc_vector_sizer vector_sizer = NULL;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
- sp_rpcfrag_request_state_t *request = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
-
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
- request = &frag->call_body.request;
-
- switch (request->header_state) {
-
+ socket_private_t *priv = NULL;
+ uint32_t prognum = 0, procnum = 0, progver = 0;
+ uint32_t remaining_size = 0;
+ int ret = -1;
+ char *buf = NULL;
+ rpcsvc_vector_sizer vector_sizer = NULL;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+ sp_rpcfrag_request_state_t *request = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+ request = &frag->call_body.request;
+
+ switch (request->header_state) {
case SP_STATE_REQUEST_HEADER_INIT:
- __socket_proto_init_pending (priv, RPC_CALL_BODY_SIZE);
+ __socket_proto_init_pending(priv, RPC_CALL_BODY_SIZE);
- request->header_state = SP_STATE_READING_RPCHDR1;
+ request->header_state = SP_STATE_READING_RPCHDR1;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_RPCHDR1:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- request->header_state = SP_STATE_READ_RPCHDR1;
+ request->header_state = SP_STATE_READ_RPCHDR1;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_RPCHDR1:
- buf = rpc_prognum_addr (iobuf_ptr (in->iobuf));
- prognum = ntoh32 (*((uint32_t *)buf));
+ buf = rpc_prognum_addr(iobuf_ptr(in->iobuf));
+ prognum = ntoh32(*((uint32_t *)buf));
- buf = rpc_progver_addr (iobuf_ptr (in->iobuf));
- progver = ntoh32 (*((uint32_t *)buf));
+ buf = rpc_progver_addr(iobuf_ptr(in->iobuf));
+ progver = ntoh32(*((uint32_t *)buf));
- buf = rpc_procnum_addr (iobuf_ptr (in->iobuf));
- procnum = ntoh32 (*((uint32_t *)buf));
+ buf = rpc_procnum_addr(iobuf_ptr(in->iobuf));
+ procnum = ntoh32(*((uint32_t *)buf));
- if (priv->is_server) {
- /* this check is needed as rpcsvc and rpc-clnt
- * actor structures are not same */
- vector_sizer =
- rpcsvc_get_program_vector_sizer ((rpcsvc_t *)this->mydata,
- prognum, progver, procnum);
- }
+ if (priv->is_server) {
+ /* this check is needed as rpcsvc and rpc-clnt
+ * actor structures are not same */
+ vector_sizer = rpcsvc_get_program_vector_sizer(
+ (rpcsvc_t *)this->mydata, prognum, progver, procnum);
+ }
- if (vector_sizer) {
- ret = __socket_read_vectored_request (this, vector_sizer);
- } else {
- ret = __socket_read_simple_request (this);
- }
+ if (vector_sizer) {
+ ret = __socket_read_vectored_request(this, vector_sizer);
+ } else {
+ ret = __socket_read_simple_request(this);
+ }
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- if ((ret == -1)
- || ((ret == 0)
- && (remaining_size == 0)
- && (RPC_LASTFRAG (in->fraghdr)))) {
- request->header_state = SP_STATE_REQUEST_HEADER_INIT;
- }
+ if ((ret == -1) || ((ret == 0) && (remaining_size == 0) &&
+ (RPC_LASTFRAG(in->fraghdr)))) {
+ request->header_state = SP_STATE_REQUEST_HEADER_INIT;
+ }
- break;
- }
+ break;
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_read_accepted_successful_reply (rpc_transport_t *this)
+__socket_read_accepted_successful_reply(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = 0;
- struct iobuf *iobuf = NULL;
- gfs3_read_rsp read_rsp = {0, };
- ssize_t size = 0;
- ssize_t default_read_size = 0;
- XDR xdr;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
-
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
-
- switch (frag->call_body.reply.accepted_success_state) {
-
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ struct iobuf *iobuf = NULL;
+ gfs3_read_rsp read_rsp = {
+ 0,
+ };
+ ssize_t size = 0;
+ ssize_t default_read_size = 0;
+ XDR xdr;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+
+ switch (frag->call_body.reply.accepted_success_state) {
case SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT:
- default_read_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_read_rsp,
- &read_rsp);
+ default_read_size = xdr_sizeof((xdrproc_t)xdr_gfs3_read_rsp,
+ &read_rsp);
- /* We need to store the current base address because we will
- * need it after a partial read. */
- in->proghdr_base_addr = frag->fragcurrent;
+ /* We need to store the current base address because we will
+ * need it after a partial read. */
+ in->proghdr_base_addr = frag->fragcurrent;
- __socket_proto_init_pending (priv, default_read_size);
+ __socket_proto_init_pending(priv, default_read_size);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READING_PROC_HEADER;
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READING_PROC_HEADER;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_PROC_HEADER:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- /* there can be 'xdata' in read response, figure it out */
- default_read_size = frag->fragcurrent - in->proghdr_base_addr;
- xdrmem_create (&xdr, in->proghdr_base_addr, default_read_size,
- XDR_DECODE);
+ /* there can be 'xdata' in read response, figure it out */
+ default_read_size = frag->fragcurrent - in->proghdr_base_addr;
+ xdrmem_create(&xdr, in->proghdr_base_addr, default_read_size,
+ XDR_DECODE);
- /* This will fail if there is xdata sent from server, if not,
- well and good, we don't need to worry about */
- xdr_gfs3_read_rsp (&xdr, &read_rsp);
+ /* This will fail if there is xdata sent from server, if not,
+ well and good, we don't need to worry about */
+ xdr_gfs3_read_rsp(&xdr, &read_rsp);
- free (read_rsp.xdata.xdata_val);
+ free(read_rsp.xdata.xdata_val);
- /* need to round off to proper roof (%4), as XDR packing pads
- the end of opaque object with '0' */
- size = roof (read_rsp.xdata.xdata_len, 4);
+ /* need to round off to proper roof (%4), as XDR packing pads
+ the end of opaque object with '0' */
+ size = roof(read_rsp.xdata.xdata_len, 4);
- if (!size) {
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_OPAQUE;
- goto read_proc_opaque;
- }
+ if (!size) {
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_OPAQUE;
+ goto read_proc_opaque;
+ }
- __socket_proto_init_pending (priv, size);
+ __socket_proto_init_pending(priv, size);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READING_PROC_OPAQUE;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READING_PROC_OPAQUE;
+ /* fall through */
case SP_STATE_READING_PROC_OPAQUE:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_OPAQUE;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_OPAQUE;
+ /* fall through */
case SP_STATE_READ_PROC_OPAQUE:
read_proc_opaque:
- if (in->payload_vector.iov_base == NULL) {
-
- size = (RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read);
-
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (iobuf == NULL) {
- ret = -1;
- goto out;
- }
+ if (in->payload_vector.iov_base == NULL) {
+ size = (RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read);
- if (in->iobref == NULL) {
- in->iobref = iobref_new ();
- if (in->iobref == NULL) {
- ret = -1;
- iobuf_unref (iobuf);
- goto out;
- }
- }
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (iobuf == NULL) {
+ ret = -1;
+ goto out;
+ }
- ret = iobref_add (in->iobref, iobuf);
- iobuf_unref (iobuf);
- if (ret < 0) {
- goto out;
- }
+ if (in->iobref == NULL) {
+ in->iobref = iobref_new();
+ if (in->iobref == NULL) {
+ ret = -1;
+ iobuf_unref(iobuf);
+ goto out;
+ }
+ }
- in->payload_vector.iov_base = iobuf_ptr (iobuf);
- in->payload_vector.iov_len = size;
+ ret = iobref_add(in->iobref, iobuf);
+ iobuf_unref(iobuf);
+ if (ret < 0) {
+ goto out;
}
- frag->fragcurrent = in->payload_vector.iov_base;
+ in->payload_vector.iov_base = iobuf_ptr(iobuf);
+ in->payload_vector.iov_len = size;
+ }
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_HEADER;
+ frag->fragcurrent = in->payload_vector.iov_base;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_HEADER;
+
+ /* fall through */
case SP_STATE_READ_PROC_HEADER:
- /* now read the entire remaining msg into new iobuf */
- ret = __socket_read_simple_msg (this);
- if ((ret == -1)
- || ((ret == 0) && RPC_LASTFRAG (in->fraghdr))) {
- frag->call_body.reply.accepted_success_state
- = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT;
- }
+ /* now read the entire remaining msg into new iobuf */
+ ret = __socket_read_simple_msg(this);
+ if ((ret == -1) || ((ret == 0) && RPC_LASTFRAG(in->fraghdr))) {
+ frag->call_body.reply.accepted_success_state =
+ SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT;
+ }
- break;
- }
+ break;
+ }
out:
- return ret;
+ return ret;
}
static int
-__socket_read_accepted_successful_reply_v2 (rpc_transport_t *this)
+__socket_read_accepted_successful_reply_v2(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = 0;
- struct iobuf *iobuf = NULL;
- gfx_read_rsp read_rsp = {0, };
- ssize_t size = 0;
- ssize_t default_read_size = 0;
- XDR xdr;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
-
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
-
- switch (frag->call_body.reply.accepted_success_state) {
-
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ struct iobuf *iobuf = NULL;
+ gfx_read_rsp read_rsp = {
+ 0,
+ };
+ ssize_t size = 0;
+ ssize_t default_read_size = 0;
+ XDR xdr;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+
+ switch (frag->call_body.reply.accepted_success_state) {
case SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT:
- default_read_size = xdr_sizeof ((xdrproc_t) xdr_gfx_read_rsp,
- &read_rsp);
+ default_read_size = xdr_sizeof((xdrproc_t)xdr_gfx_read_rsp,
+ &read_rsp);
- /* We need to store the current base address because we will
- * need it after a partial read. */
- in->proghdr_base_addr = frag->fragcurrent;
+ /* We need to store the current base address because we will
+ * need it after a partial read. */
+ in->proghdr_base_addr = frag->fragcurrent;
- __socket_proto_init_pending (priv, default_read_size);
+ __socket_proto_init_pending(priv, default_read_size);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READING_PROC_HEADER;
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READING_PROC_HEADER;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_PROC_HEADER:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- /* there can be 'xdata' in read response, figure it out */
- default_read_size = frag->fragcurrent - in->proghdr_base_addr;
+ /* there can be 'xdata' in read response, figure it out */
+ default_read_size = frag->fragcurrent - in->proghdr_base_addr;
- xdrmem_create (&xdr, in->proghdr_base_addr, default_read_size,
- XDR_DECODE);
+ xdrmem_create(&xdr, in->proghdr_base_addr, default_read_size,
+ XDR_DECODE);
- /* This will fail if there is xdata sent from server, if not,
- well and good, we don't need to worry about */
- xdr_gfx_read_rsp (&xdr, &read_rsp);
+ /* This will fail if there is xdata sent from server, if not,
+ well and good, we don't need to worry about */
+ xdr_gfx_read_rsp(&xdr, &read_rsp);
- free (read_rsp.xdata.pairs.pairs_val);
+ free(read_rsp.xdata.pairs.pairs_val);
- /* need to round off to proper roof (%4), as XDR packing pads
- the end of opaque object with '0' */
- size = roof (read_rsp.xdata.xdr_size, 4);
+ /* need to round off to proper roof (%4), as XDR packing pads
+ the end of opaque object with '0' */
+ size = roof(read_rsp.xdata.xdr_size, 4);
- if (!size) {
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_OPAQUE;
- goto read_proc_opaque;
- }
+ if (!size) {
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_OPAQUE;
+ goto read_proc_opaque;
+ }
- __socket_proto_init_pending (priv, size);
+ __socket_proto_init_pending(priv, size);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READING_PROC_OPAQUE;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READING_PROC_OPAQUE;
+ /* fall through */
case SP_STATE_READING_PROC_OPAQUE:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_OPAQUE;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_OPAQUE;
+ /* fall through */
case SP_STATE_READ_PROC_OPAQUE:
read_proc_opaque:
- if (in->payload_vector.iov_base == NULL) {
-
- size = (RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read);
+ if (in->payload_vector.iov_base == NULL) {
+ size = (RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read);
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (iobuf == NULL) {
- ret = -1;
- goto out;
- }
-
- if (in->iobref == NULL) {
- in->iobref = iobref_new ();
- if (in->iobref == NULL) {
- ret = -1;
- iobuf_unref (iobuf);
- goto out;
- }
- }
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (iobuf == NULL) {
+ ret = -1;
+ goto out;
+ }
- ret = iobref_add (in->iobref, iobuf);
- iobuf_unref (iobuf);
- if (ret < 0) {
- goto out;
- }
+ if (in->iobref == NULL) {
+ in->iobref = iobref_new();
+ if (in->iobref == NULL) {
+ ret = -1;
+ iobuf_unref(iobuf);
+ goto out;
+ }
+ }
- in->payload_vector.iov_base = iobuf_ptr (iobuf);
- in->payload_vector.iov_len = size;
+ ret = iobref_add(in->iobref, iobuf);
+ iobuf_unref(iobuf);
+ if (ret < 0) {
+ goto out;
}
- frag->fragcurrent = in->payload_vector.iov_base;
+ in->payload_vector.iov_base = iobuf_ptr(iobuf);
+ in->payload_vector.iov_len = size;
+ }
- frag->call_body.reply.accepted_success_state
- = SP_STATE_READ_PROC_HEADER;
+ frag->fragcurrent = in->payload_vector.iov_base;
- /* fall through */
+ frag->call_body.reply
+ .accepted_success_state = SP_STATE_READ_PROC_HEADER;
+
+ /* fall through */
case SP_STATE_READ_PROC_HEADER:
- /* now read the entire remaining msg into new iobuf */
- ret = __socket_read_simple_msg (this);
- if ((ret == -1)
- || ((ret == 0) && RPC_LASTFRAG (in->fraghdr))) {
- frag->call_body.reply.accepted_success_state
- = SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT;
- }
+ /* now read the entire remaining msg into new iobuf */
+ ret = __socket_read_simple_msg(this);
+ if ((ret == -1) || ((ret == 0) && RPC_LASTFRAG(in->fraghdr))) {
+ frag->call_body.reply.accepted_success_state =
+ SP_STATE_ACCEPTED_SUCCESS_REPLY_INIT;
+ }
- break;
- }
+ break;
+ }
out:
- return ret;
+ return ret;
}
#define rpc_reply_verflen_addr(fragcurrent) ((char *)fragcurrent - 4)
#define rpc_reply_accept_status_addr(fragcurrent) ((char *)fragcurrent - 4)
static int
-__socket_read_accepted_reply (rpc_transport_t *this)
+__socket_read_accepted_reply(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = -1;
- char *buf = NULL;
- uint32_t verflen = 0, len = 0;
- uint32_t remaining_size = 0;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
-
- switch (frag->call_body.reply.accepted_state) {
-
+ socket_private_t *priv = NULL;
+ int ret = -1;
+ char *buf = NULL;
+ uint32_t verflen = 0, len = 0;
+ uint32_t remaining_size = 0;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+
+ switch (frag->call_body.reply.accepted_state) {
case SP_STATE_ACCEPTED_REPLY_INIT:
- __socket_proto_init_pending (priv,
- RPC_AUTH_FLAVOUR_N_LENGTH_SIZE);
+ __socket_proto_init_pending(priv, RPC_AUTH_FLAVOUR_N_LENGTH_SIZE);
- frag->call_body.reply.accepted_state
- = SP_STATE_READING_REPLY_VERFLEN;
+ frag->call_body.reply
+ .accepted_state = SP_STATE_READING_REPLY_VERFLEN;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_REPLY_VERFLEN:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- frag->call_body.reply.accepted_state
- = SP_STATE_READ_REPLY_VERFLEN;
+ frag->call_body.reply.accepted_state = SP_STATE_READ_REPLY_VERFLEN;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_REPLY_VERFLEN:
- buf = rpc_reply_verflen_addr (frag->fragcurrent);
+ buf = rpc_reply_verflen_addr(frag->fragcurrent);
- verflen = ntoh32 (*((uint32_t *) buf));
+ verflen = ntoh32(*((uint32_t *)buf));
- /* also read accept status along with verf data */
- len = verflen + RPC_ACCEPT_STATUS_LEN;
+ /* also read accept status along with verf data */
+ len = verflen + RPC_ACCEPT_STATUS_LEN;
- __socket_proto_init_pending (priv, len);
+ __socket_proto_init_pending(priv, len);
- frag->call_body.reply.accepted_state
- = SP_STATE_READING_REPLY_VERFBYTES;
+ frag->call_body.reply
+ .accepted_state = SP_STATE_READING_REPLY_VERFBYTES;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_REPLY_VERFBYTES:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- frag->call_body.reply.accepted_state
- = SP_STATE_READ_REPLY_VERFBYTES;
+ frag->call_body.reply
+ .accepted_state = SP_STATE_READ_REPLY_VERFBYTES;
- buf = rpc_reply_accept_status_addr (frag->fragcurrent);
+ buf = rpc_reply_accept_status_addr(frag->fragcurrent);
- frag->call_body.reply.accept_status
- = ntoh32 (*(uint32_t *) buf);
+ frag->call_body.reply.accept_status = ntoh32(*(uint32_t *)buf);
- /* fall through */
+ /* fall through */
case SP_STATE_READ_REPLY_VERFBYTES:
- if (frag->call_body.reply.accept_status
- == SUCCESS) {
- /* Need two different methods here for different protocols
- Mainly because the exact XDR is used to calculate the
- size of response */
- if ((in->request_info->procnum == GFS3_OP_READ) &&
- (in->request_info->prognum == GLUSTER_FOP_PROGRAM) &&
- (in->request_info->progver == GLUSTER_FOP_VERSION_v2)) {
- ret = __socket_read_accepted_successful_reply_v2 (this);
- } else {
- ret = __socket_read_accepted_successful_reply (this);
- }
+ if (frag->call_body.reply.accept_status == SUCCESS) {
+ /* Need two different methods here for different protocols
+ Mainly because the exact XDR is used to calculate the
+ size of response */
+ if ((in->request_info->procnum == GFS3_OP_READ) &&
+ (in->request_info->prognum == GLUSTER_FOP_PROGRAM) &&
+ (in->request_info->progver == GLUSTER_FOP_VERSION_v2)) {
+ ret = __socket_read_accepted_successful_reply_v2(this);
} else {
- /* read entire remaining msg into buffer pointed to by
- * fragcurrent
- */
- ret = __socket_read_simple_msg (this);
+ ret = __socket_read_accepted_successful_reply(this);
}
+ } else {
+ /* read entire remaining msg into buffer pointed to by
+ * fragcurrent
+ */
+ ret = __socket_read_simple_msg(this);
+ }
- remaining_size = RPC_FRAGSIZE (in->fraghdr)
- - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- if ((ret == -1)
- || ((ret == 0) && (remaining_size == 0)
- && (RPC_LASTFRAG (in->fraghdr)))) {
- frag->call_body.reply.accepted_state
- = SP_STATE_ACCEPTED_REPLY_INIT;
- }
+ if ((ret == -1) || ((ret == 0) && (remaining_size == 0) &&
+ (RPC_LASTFRAG(in->fraghdr)))) {
+ frag->call_body.reply
+ .accepted_state = SP_STATE_ACCEPTED_REPLY_INIT;
+ }
- break;
- }
+ break;
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_read_denied_reply (rpc_transport_t *this)
+__socket_read_denied_reply(rpc_transport_t *this)
{
- return __socket_read_simple_msg (this);
+ return __socket_read_simple_msg(this);
}
-
#define rpc_reply_status_addr(fragcurrent) ((char *)fragcurrent - 4)
-
static int
-__socket_read_vectored_reply (rpc_transport_t *this)
+__socket_read_vectored_reply(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int ret = 0;
- char *buf = NULL;
- uint32_t remaining_size = 0;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ char *buf = NULL;
+ uint32_t remaining_size = 0;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
- in = &priv->incoming;
- frag = &in->frag;
-
- switch (frag->call_body.reply.status_state) {
+ priv = this->private;
+ in = &priv->incoming;
+ frag = &in->frag;
+ switch (frag->call_body.reply.status_state) {
case SP_STATE_ACCEPTED_REPLY_INIT:
- __socket_proto_init_pending (priv, RPC_REPLY_STATUS_SIZE);
+ __socket_proto_init_pending(priv, RPC_REPLY_STATUS_SIZE);
- frag->call_body.reply.status_state
- = SP_STATE_READING_REPLY_STATUS;
+ frag->call_body.reply.status_state = SP_STATE_READING_REPLY_STATUS;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_REPLY_STATUS:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- buf = rpc_reply_status_addr (frag->fragcurrent);
+ buf = rpc_reply_status_addr(frag->fragcurrent);
- frag->call_body.reply.accept_status
- = ntoh32 (*((uint32_t *) buf));
+ frag->call_body.reply.accept_status = ntoh32(*((uint32_t *)buf));
- frag->call_body.reply.status_state
- = SP_STATE_READ_REPLY_STATUS;
+ frag->call_body.reply.status_state = SP_STATE_READ_REPLY_STATUS;
- /* fall through */
+ /* fall through */
case SP_STATE_READ_REPLY_STATUS:
- if (frag->call_body.reply.accept_status == MSG_ACCEPTED) {
- ret = __socket_read_accepted_reply (this);
- } else {
- ret = __socket_read_denied_reply (this);
- }
-
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
-
- if ((ret == -1)
- || ((ret == 0) && (remaining_size == 0)
- && (RPC_LASTFRAG (in->fraghdr)))) {
- frag->call_body.reply.status_state
- = SP_STATE_VECTORED_REPLY_STATUS_INIT;
- in->payload_vector.iov_len
- = (unsigned long)frag->fragcurrent
- - (unsigned long)in->payload_vector.iov_base;
- }
- break;
- }
+ if (frag->call_body.reply.accept_status == MSG_ACCEPTED) {
+ ret = __socket_read_accepted_reply(this);
+ } else {
+ ret = __socket_read_denied_reply(this);
+ }
+
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
+
+ if ((ret == -1) || ((ret == 0) && (remaining_size == 0) &&
+ (RPC_LASTFRAG(in->fraghdr)))) {
+ frag->call_body.reply
+ .status_state = SP_STATE_VECTORED_REPLY_STATUS_INIT;
+ in->payload_vector.iov_len = (unsigned long)frag->fragcurrent -
+ (unsigned long)
+ in->payload_vector.iov_base;
+ }
+ break;
+ }
out:
- return ret;
+ return ret;
}
-
static int
-__socket_read_simple_reply (rpc_transport_t *this)
+__socket_read_simple_reply(rpc_transport_t *this)
{
- return __socket_read_simple_msg (this);
+ return __socket_read_simple_msg(this);
}
#define rpc_xid_addr(buf) (buf)
static int
-__socket_read_reply (rpc_transport_t *this)
+__socket_read_reply(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- char *buf = NULL;
- int32_t ret = -1;
- rpc_request_info_t *request_info = NULL;
- char map_xid = 0;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
- in = &priv->incoming;
- frag = &in->frag;
-
- buf = rpc_xid_addr (iobuf_ptr (in->iobuf));
-
+ socket_private_t *priv = NULL;
+ char *buf = NULL;
+ int32_t ret = -1;
+ rpc_request_info_t *request_info = NULL;
+ char map_xid = 0;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+ in = &priv->incoming;
+ frag = &in->frag;
+
+ buf = rpc_xid_addr(iobuf_ptr(in->iobuf));
+
+ if (in->request_info == NULL) {
+ in->request_info = GF_CALLOC(1, sizeof(*request_info),
+ gf_common_mt_rpc_trans_reqinfo_t);
if (in->request_info == NULL) {
- in->request_info = GF_CALLOC (1, sizeof (*request_info),
- gf_common_mt_rpc_trans_reqinfo_t);
- if (in->request_info == NULL) {
- goto out;
- }
-
- map_xid = 1;
+ goto out;
}
- request_info = in->request_info;
-
- if (map_xid) {
- request_info->xid = ntoh32 (*((uint32_t *) buf));
+ map_xid = 1;
+ }
- /* release priv->lock, so as to avoid deadlock b/w conn->lock
- * and priv->lock, since we are doing an upcall here.
- */
- frag->state = SP_STATE_NOTIFYING_XID;
- pthread_mutex_unlock (&priv->in_lock);
- {
- ret = rpc_transport_notify (this,
- RPC_TRANSPORT_MAP_XID_REQUEST,
- in->request_info);
- }
- pthread_mutex_lock (&priv->in_lock);
+ request_info = in->request_info;
- /* Transition back to externally visible state. */
- frag->state = SP_STATE_READ_MSGTYPE;
+ if (map_xid) {
+ request_info->xid = ntoh32(*((uint32_t *)buf));
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "notify for event MAP_XID failed for %s",
- this->peerinfo.identifier);
- goto out;
- }
+ /* release priv->lock, so as to avoid deadlock b/w conn->lock
+ * and priv->lock, since we are doing an upcall here.
+ */
+ frag->state = SP_STATE_NOTIFYING_XID;
+ pthread_mutex_unlock(&priv->in_lock);
+ {
+ ret = rpc_transport_notify(this, RPC_TRANSPORT_MAP_XID_REQUEST,
+ in->request_info);
}
+ pthread_mutex_lock(&priv->in_lock);
- if ((request_info->prognum == GLUSTER_FOP_PROGRAM)
- && (request_info->procnum == GF_FOP_READ)) {
- if (map_xid && request_info->rsp.rsp_payload_count != 0) {
- in->iobref = iobref_ref (request_info->rsp.rsp_iobref);
- in->payload_vector = *request_info->rsp.rsp_payload;
- }
+ /* Transition back to externally visible state. */
+ frag->state = SP_STATE_READ_MSGTYPE;
- ret = __socket_read_vectored_reply (this);
- } else {
- ret = __socket_read_simple_reply (this);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "notify for event MAP_XID failed for %s",
+ this->peerinfo.identifier);
+ goto out;
}
+ }
+
+ if ((request_info->prognum == GLUSTER_FOP_PROGRAM) &&
+ (request_info->procnum == GF_FOP_READ)) {
+ if (map_xid && request_info->rsp.rsp_payload_count != 0) {
+ in->iobref = iobref_ref(request_info->rsp.rsp_iobref);
+ in->payload_vector = *request_info->rsp.rsp_payload;
+ }
+
+ ret = __socket_read_vectored_reply(this);
+ } else {
+ ret = __socket_read_simple_reply(this);
+ }
out:
- return ret;
+ return ret;
}
-
/* returns the number of bytes yet to be read in a fragment */
static int
-__socket_read_frag (rpc_transport_t *this)
+__socket_read_frag(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- int32_t ret = 0;
- char *buf = NULL;
- uint32_t remaining_size = 0;
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
-
- switch (frag->state) {
+ socket_private_t *priv = NULL;
+ int32_t ret = 0;
+ char *buf = NULL;
+ uint32_t remaining_size = 0;
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
+
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+
+ priv = this->private;
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
+
+ switch (frag->state) {
case SP_STATE_NADA:
- __socket_proto_init_pending (priv, RPC_MSGTYPE_SIZE);
+ __socket_proto_init_pending(priv, RPC_MSGTYPE_SIZE);
- frag->state = SP_STATE_READING_MSGTYPE;
+ frag->state = SP_STATE_READING_MSGTYPE;
- /* fall through */
+ /* fall through */
case SP_STATE_READING_MSGTYPE:
- __socket_proto_read (priv, ret);
+ __socket_proto_read(priv, ret);
- frag->state = SP_STATE_READ_MSGTYPE;
- /* fall through */
+ frag->state = SP_STATE_READ_MSGTYPE;
+ /* fall through */
case SP_STATE_READ_MSGTYPE:
- buf = rpc_msgtype_addr (iobuf_ptr (in->iobuf));
- in->msg_type = ntoh32 (*((uint32_t *)buf));
-
- if (in->msg_type == CALL) {
- ret = __socket_read_request (this);
- } else if (in->msg_type == REPLY) {
- ret = __socket_read_reply (this);
- } else if (in->msg_type == (msg_type_t) GF_UNIVERSAL_ANSWER) {
- gf_log ("rpc", GF_LOG_ERROR,
- "older version of protocol/process trying to "
- "connect from %s. use newer version on that node",
- this->peerinfo.identifier);
- } else {
- gf_log ("rpc", GF_LOG_ERROR,
- "wrong MSG-TYPE (%d) received from %s",
- in->msg_type,
- this->peerinfo.identifier);
- ret = -1;
- }
+ buf = rpc_msgtype_addr(iobuf_ptr(in->iobuf));
+ in->msg_type = ntoh32(*((uint32_t *)buf));
+
+ if (in->msg_type == CALL) {
+ ret = __socket_read_request(this);
+ } else if (in->msg_type == REPLY) {
+ ret = __socket_read_reply(this);
+ } else if (in->msg_type == (msg_type_t)GF_UNIVERSAL_ANSWER) {
+ gf_log("rpc", GF_LOG_ERROR,
+ "older version of protocol/process trying to "
+ "connect from %s. use newer version on that node",
+ this->peerinfo.identifier);
+ } else {
+ gf_log("rpc", GF_LOG_ERROR,
+ "wrong MSG-TYPE (%d) received from %s", in->msg_type,
+ this->peerinfo.identifier);
+ ret = -1;
+ }
- remaining_size = RPC_FRAGSIZE (in->fraghdr) - frag->bytes_read;
+ remaining_size = RPC_FRAGSIZE(in->fraghdr) - frag->bytes_read;
- if ((ret == -1)
- || ((ret == 0) && (remaining_size == 0)
- && (RPC_LASTFRAG (in->fraghdr)))) {
- /* frag->state = SP_STATE_NADA; */
- frag->state = SP_STATE_RPCFRAG_INIT;
- }
+ if ((ret == -1) || ((ret == 0) && (remaining_size == 0) &&
+ (RPC_LASTFRAG(in->fraghdr)))) {
+ /* frag->state = SP_STATE_NADA; */
+ frag->state = SP_STATE_RPCFRAG_INIT;
+ }
- break;
+ break;
case SP_STATE_NOTIFYING_XID:
- /* Another epoll thread is notifying higher layers
- *of reply's xid. */
- errno = EAGAIN;
- return -1;
- break;
-
- }
+ /* Another epoll thread is notifying higher layers
+ *of reply's xid. */
+ errno = EAGAIN;
+ return -1;
+ break;
+ }
out:
- return ret;
+ return ret;
}
-
static void
-__socket_reset_priv (socket_private_t *priv)
+__socket_reset_priv(socket_private_t *priv)
{
- struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming *in = NULL;
- /* used to reduce the indirection */
- in = &priv->incoming;
+ /* used to reduce the indirection */
+ in = &priv->incoming;
- if (in->iobref) {
- iobref_unref (in->iobref);
- in->iobref = NULL;
- }
+ if (in->iobref) {
+ iobref_unref(in->iobref);
+ in->iobref = NULL;
+ }
- if (in->iobuf) {
- iobuf_unref (in->iobuf);
- in->iobuf = NULL;
- }
-
- if (in->request_info != NULL) {
- GF_FREE (in->request_info);
- in->request_info = NULL;
- }
+ if (in->iobuf) {
+ iobuf_unref(in->iobuf);
+ in->iobuf = NULL;
+ }
- memset (&in->payload_vector, 0,
- sizeof (in->payload_vector));
+ if (in->request_info != NULL) {
+ GF_FREE(in->request_info);
+ in->request_info = NULL;
+ }
+ memset(&in->payload_vector, 0, sizeof(in->payload_vector));
}
-
static int
-__socket_proto_state_machine (rpc_transport_t *this,
- rpc_transport_pollin_t **pollin)
+__socket_proto_state_machine(rpc_transport_t *this,
+ rpc_transport_pollin_t **pollin)
{
- int ret = -1;
- socket_private_t *priv = NULL;
- struct iobuf *iobuf = NULL;
- struct iobref *iobref = NULL;
- struct iovec vector[2];
- struct gf_sock_incoming *in = NULL;
- struct gf_sock_incoming_frag *frag = NULL;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
-
- priv = this->private;
- /* used to reduce the indirection */
- in = &priv->incoming;
- frag = &in->frag;
-
- while (in->record_state != SP_STATE_COMPLETE) {
- switch (in->record_state) {
-
- case SP_STATE_NADA:
- in->total_bytes_read = 0;
- in->payload_vector.iov_len = 0;
-
- in->pending_vector = in->vector;
- in->pending_vector->iov_base = &in->fraghdr;
-
- in->pending_vector->iov_len = sizeof (in->fraghdr);
-
- in->record_state = SP_STATE_READING_FRAGHDR;
-
- /* fall through */
-
- case SP_STATE_READING_FRAGHDR:
- ret = __socket_readv (this, in->pending_vector, 1,
- &in->pending_vector,
- &in->pending_count,
- NULL);
- if (ret == -1)
- goto out;
-
- if (ret > 0) {
- gf_log (this->name, GF_LOG_TRACE, "partial "
- "fragment header read");
- goto out;
- }
+ int ret = -1;
+ socket_private_t *priv = NULL;
+ struct iobuf *iobuf = NULL;
+ struct iobref *iobref = NULL;
+ struct iovec vector[2];
+ struct gf_sock_incoming *in = NULL;
+ struct gf_sock_incoming_frag *frag = NULL;
- if (ret == 0) {
- in->record_state = SP_STATE_READ_FRAGHDR;
- }
- /* fall through */
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- case SP_STATE_READ_FRAGHDR:
+ priv = this->private;
+ /* used to reduce the indirection */
+ in = &priv->incoming;
+ frag = &in->frag;
- in->fraghdr = ntoh32 (in->fraghdr);
- in->total_bytes_read += RPC_FRAGSIZE(in->fraghdr);
+ while (in->record_state != SP_STATE_COMPLETE) {
+ switch (in->record_state) {
+ case SP_STATE_NADA:
+ in->total_bytes_read = 0;
+ in->payload_vector.iov_len = 0;
- if (in->total_bytes_read >= GF_UNIT_GB) {
- ret = -ENOMEM;
- goto out;
- }
+ in->pending_vector = in->vector;
+ in->pending_vector->iov_base = &in->fraghdr;
- iobuf = iobuf_get2 (this->ctx->iobuf_pool,
- (in->total_bytes_read +
- sizeof (in->fraghdr)));
- if (!iobuf) {
- ret = -ENOMEM;
- goto out;
- }
+ in->pending_vector->iov_len = sizeof(in->fraghdr);
- if (in->iobuf == NULL) {
- /* first fragment */
- frag->fragcurrent = iobuf_ptr (iobuf);
- } else {
- /* second or further fragment */
- memcpy(iobuf_ptr (iobuf), iobuf_ptr (in->iobuf),
- in->total_bytes_read - RPC_FRAGSIZE(in->fraghdr));
- iobuf_unref (in->iobuf);
- frag->fragcurrent = (char *) iobuf_ptr (iobuf) +
- in->total_bytes_read - RPC_FRAGSIZE(in->fraghdr);
- frag->pending_vector->iov_base = frag->fragcurrent;
- in->pending_vector = frag->pending_vector;
- }
+ in->record_state = SP_STATE_READING_FRAGHDR;
- in->iobuf = iobuf;
- in->iobuf_size = 0;
- in->record_state = SP_STATE_READING_FRAG;
- /* fall through */
+ /* fall through */
- case SP_STATE_READING_FRAG:
- ret = __socket_read_frag (this);
+ case SP_STATE_READING_FRAGHDR:
+ ret = __socket_readv(this, in->pending_vector, 1,
+ &in->pending_vector, &in->pending_count,
+ NULL);
+ if (ret == -1)
+ goto out;
- if ((ret == -1) ||
- (frag->bytes_read != RPC_FRAGSIZE (in->fraghdr))) {
- goto out;
- }
+ if (ret > 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "partial "
+ "fragment header read");
+ goto out;
+ }
- frag->bytes_read = 0;
+ if (ret == 0) {
+ in->record_state = SP_STATE_READ_FRAGHDR;
+ }
+ /* fall through */
- if (!RPC_LASTFRAG (in->fraghdr)) {
- in->pending_vector = in->vector;
- in->pending_vector->iov_base = &in->fraghdr;
- in->pending_vector->iov_len = sizeof(in->fraghdr);
- in->record_state = SP_STATE_READING_FRAGHDR;
- break;
- }
+ case SP_STATE_READ_FRAGHDR:
+
+ in->fraghdr = ntoh32(in->fraghdr);
+ in->total_bytes_read += RPC_FRAGSIZE(in->fraghdr);
+
+ if (in->total_bytes_read >= GF_UNIT_GB) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ iobuf = iobuf_get2(
+ this->ctx->iobuf_pool,
+ (in->total_bytes_read + sizeof(in->fraghdr)));
+ if (!iobuf) {
+ ret = -ENOMEM;
+ goto out;
+ }
- /* we've read the entire rpc record, notify the
- * upper layers.
- */
- if (pollin != NULL) {
- int count = 0;
- in->iobuf_size = (in->total_bytes_read -
- in->payload_vector.iov_len);
-
- memset (vector, 0, sizeof (vector));
-
- if (in->iobref == NULL) {
- in->iobref = iobref_new ();
- if (in->iobref == NULL) {
- ret = -1;
- goto out;
- }
- }
-
- vector[count].iov_base = iobuf_ptr (in->iobuf);
- vector[count].iov_len = in->iobuf_size;
-
- iobref = in->iobref;
-
- count++;
-
- if (in->payload_vector.iov_base != NULL) {
- vector[count] = in->payload_vector;
- count++;
- }
-
- *pollin = rpc_transport_pollin_alloc (this,
- vector,
- count,
- in->iobuf,
- iobref,
- in->request_info);
- iobuf_unref (in->iobuf);
- in->iobuf = NULL;
-
- if (*pollin == NULL) {
- gf_log (this->name, GF_LOG_WARNING,
- "transport pollin allocation failed");
- ret = -1;
- goto out;
- }
- if (in->msg_type == REPLY)
- (*pollin)->is_reply = 1;
-
- in->request_info = NULL;
+ if (in->iobuf == NULL) {
+ /* first fragment */
+ frag->fragcurrent = iobuf_ptr(iobuf);
+ } else {
+ /* second or further fragment */
+ memcpy(iobuf_ptr(iobuf), iobuf_ptr(in->iobuf),
+ in->total_bytes_read - RPC_FRAGSIZE(in->fraghdr));
+ iobuf_unref(in->iobuf);
+ frag->fragcurrent = (char *)iobuf_ptr(iobuf) +
+ in->total_bytes_read -
+ RPC_FRAGSIZE(in->fraghdr);
+ frag->pending_vector->iov_base = frag->fragcurrent;
+ in->pending_vector = frag->pending_vector;
+ }
+
+ in->iobuf = iobuf;
+ in->iobuf_size = 0;
+ in->record_state = SP_STATE_READING_FRAG;
+ /* fall through */
+
+ case SP_STATE_READING_FRAG:
+ ret = __socket_read_frag(this);
+
+ if ((ret == -1) ||
+ (frag->bytes_read != RPC_FRAGSIZE(in->fraghdr))) {
+ goto out;
+ }
+
+ frag->bytes_read = 0;
+
+ if (!RPC_LASTFRAG(in->fraghdr)) {
+ in->pending_vector = in->vector;
+ in->pending_vector->iov_base = &in->fraghdr;
+ in->pending_vector->iov_len = sizeof(in->fraghdr);
+ in->record_state = SP_STATE_READING_FRAGHDR;
+ break;
+ }
+
+ /* we've read the entire rpc record, notify the
+ * upper layers.
+ */
+ if (pollin != NULL) {
+ int count = 0;
+ in->iobuf_size = (in->total_bytes_read -
+ in->payload_vector.iov_len);
+
+ memset(vector, 0, sizeof(vector));
+
+ if (in->iobref == NULL) {
+ in->iobref = iobref_new();
+ if (in->iobref == NULL) {
+ ret = -1;
+ goto out;
}
- in->record_state = SP_STATE_COMPLETE;
- break;
+ }
- case SP_STATE_COMPLETE:
- /* control should not reach here */
- gf_log (this->name, GF_LOG_WARNING, "control reached to "
- "SP_STATE_COMPLETE, which should not have "
- "happened");
- break;
+ vector[count].iov_base = iobuf_ptr(in->iobuf);
+ vector[count].iov_len = in->iobuf_size;
+
+ iobref = in->iobref;
+
+ count++;
+
+ if (in->payload_vector.iov_base != NULL) {
+ vector[count] = in->payload_vector;
+ count++;
+ }
+
+ *pollin = rpc_transport_pollin_alloc(this, vector, count,
+ in->iobuf, iobref,
+ in->request_info);
+ iobuf_unref(in->iobuf);
+ in->iobuf = NULL;
+
+ if (*pollin == NULL) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "transport pollin allocation failed");
+ ret = -1;
+ goto out;
+ }
+ if (in->msg_type == REPLY)
+ (*pollin)->is_reply = 1;
+
+ in->request_info = NULL;
}
- }
+ in->record_state = SP_STATE_COMPLETE;
+ break;
- if (in->record_state == SP_STATE_COMPLETE) {
- in->record_state = SP_STATE_NADA;
- __socket_reset_priv (priv);
+ case SP_STATE_COMPLETE:
+ /* control should not reach here */
+ gf_log(this->name, GF_LOG_WARNING,
+ "control reached to "
+ "SP_STATE_COMPLETE, which should not have "
+ "happened");
+ break;
}
+ }
+
+ if (in->record_state == SP_STATE_COMPLETE) {
+ in->record_state = SP_STATE_NADA;
+ __socket_reset_priv(priv);
+ }
out:
- if ((ret == -1) && (errno == EAGAIN)) {
- ret = 0;
- }
+ if ((ret == -1) && (errno == EAGAIN)) {
+ ret = 0;
+ }
- return ret;
+ return ret;
}
-
static int
-socket_proto_state_machine (rpc_transport_t *this,
- rpc_transport_pollin_t **pollin)
+socket_proto_state_machine(rpc_transport_t *this,
+ rpc_transport_pollin_t **pollin)
{
- socket_private_t *priv = NULL;
- int ret = 0;
+ socket_private_t *priv = NULL;
+ int ret = 0;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->in_lock);
- {
- ret = __socket_proto_state_machine (this, pollin);
- }
- pthread_mutex_unlock (&priv->in_lock);
+ pthread_mutex_lock(&priv->in_lock);
+ {
+ ret = __socket_proto_state_machine(this, pollin);
+ }
+ pthread_mutex_unlock(&priv->in_lock);
out:
- return ret;
+ return ret;
}
-
static int
-socket_event_poll_in (rpc_transport_t *this, gf_boolean_t notify_handled)
+socket_event_poll_in(rpc_transport_t *this, gf_boolean_t notify_handled)
{
- int ret = -1;
- rpc_transport_pollin_t *pollin = NULL;
- socket_private_t *priv = this->private;
- glusterfs_ctx_t *ctx = NULL;
+ int ret = -1;
+ rpc_transport_pollin_t *pollin = NULL;
+ socket_private_t *priv = this->private;
+ glusterfs_ctx_t *ctx = NULL;
- ctx = this->ctx;
+ ctx = this->ctx;
- ret = socket_proto_state_machine (this, &pollin);
+ ret = socket_proto_state_machine(this, &pollin);
- if (pollin) {
- pthread_mutex_lock (&priv->notify.lock);
- {
- priv->notify.in_progress++;
- }
- pthread_mutex_unlock (&priv->notify.lock);
+ if (pollin) {
+ pthread_mutex_lock(&priv->notify.lock);
+ {
+ priv->notify.in_progress++;
}
+ pthread_mutex_unlock(&priv->notify.lock);
+ }
+ if (notify_handled && (ret != -1))
+ event_handled(ctx->event_pool, priv->sock, priv->idx, priv->gen);
- if (notify_handled && (ret != -1))
- event_handled (ctx->event_pool, priv->sock, priv->idx,
- priv->gen);
-
- if (pollin) {
- ret = rpc_transport_notify (this, RPC_TRANSPORT_MSG_RECEIVED,
- pollin);
+ if (pollin) {
+ ret = rpc_transport_notify(this, RPC_TRANSPORT_MSG_RECEIVED, pollin);
- rpc_transport_pollin_destroy (pollin);
+ rpc_transport_pollin_destroy(pollin);
- pthread_mutex_lock (&priv->notify.lock);
- {
- --priv->notify.in_progress;
+ pthread_mutex_lock(&priv->notify.lock);
+ {
+ --priv->notify.in_progress;
- if (!priv->notify.in_progress)
- pthread_cond_signal (&priv->notify.cond);
- }
- pthread_mutex_unlock (&priv->notify.lock);
+ if (!priv->notify.in_progress)
+ pthread_cond_signal(&priv->notify.cond);
}
+ pthread_mutex_unlock(&priv->notify.lock);
+ }
- return ret;
+ return ret;
}
-
static int
-socket_connect_finish (rpc_transport_t *this)
+socket_connect_finish(rpc_transport_t *this)
{
- int ret = -1;
- socket_private_t *priv = NULL;
- rpc_transport_event_t event = 0;
- char notify_rpc = 0;
-
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ int ret = -1;
+ socket_private_t *priv = NULL;
+ rpc_transport_event_t event = 0;
+ char notify_rpc = 0;
- priv = this->private;
-
- pthread_mutex_lock (&priv->in_lock);
- pthread_mutex_lock (&priv->out_lock);
- {
- if (priv->connected != 0)
- goto unlock;
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- get_transport_identifiers (this);
+ priv = this->private;
- ret = __socket_connect_finish (priv->sock);
+ pthread_mutex_lock(&priv->in_lock);
+ pthread_mutex_lock(&priv->out_lock);
+ {
+ if (priv->connected != 0)
+ goto unlock;
- if (ret == -1 && errno == EINPROGRESS)
- ret = 1;
+ get_transport_identifiers(this);
- if (ret == -1 && errno != EINPROGRESS) {
- if (!priv->connect_finish_log) {
- gf_log (this->name, GF_LOG_ERROR,
- "connection to %s failed (%s); "
- "disconnecting socket",
- this->peerinfo.identifier,
- strerror (errno));
- priv->connect_finish_log = 1;
- }
- __socket_disconnect (this);
- goto unlock;
- }
+ ret = __socket_connect_finish(priv->sock);
- if (ret == 0) {
- notify_rpc = 1;
-
- this->myinfo.sockaddr_len =
- sizeof (this->myinfo.sockaddr);
-
- ret = getsockname (priv->sock,
- SA (&this->myinfo.sockaddr),
- &this->myinfo.sockaddr_len);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "getsockname on (%d) failed (%s) - "
- "disconnecting socket",
- priv->sock, strerror (errno));
- __socket_disconnect (this);
- event = RPC_TRANSPORT_DISCONNECT;
- goto unlock;
- }
+ if (ret == -1 && errno == EINPROGRESS)
+ ret = 1;
- priv->connected = 1;
- priv->connect_finish_log = 0;
- event = RPC_TRANSPORT_CONNECT;
- }
+ if (ret == -1 && errno != EINPROGRESS) {
+ if (!priv->connect_finish_log) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "connection to %s failed (%s); "
+ "disconnecting socket",
+ this->peerinfo.identifier, strerror(errno));
+ priv->connect_finish_log = 1;
+ }
+ __socket_disconnect(this);
+ goto unlock;
}
+
+ if (ret == 0) {
+ notify_rpc = 1;
+
+ this->myinfo.sockaddr_len = sizeof(this->myinfo.sockaddr);
+
+ ret = getsockname(priv->sock, SA(&this->myinfo.sockaddr),
+ &this->myinfo.sockaddr_len);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "getsockname on (%d) failed (%s) - "
+ "disconnecting socket",
+ priv->sock, strerror(errno));
+ __socket_disconnect(this);
+ event = RPC_TRANSPORT_DISCONNECT;
+ goto unlock;
+ }
+
+ priv->connected = 1;
+ priv->connect_finish_log = 0;
+ event = RPC_TRANSPORT_CONNECT;
+ }
+ }
unlock:
- pthread_mutex_unlock (&priv->out_lock);
- pthread_mutex_unlock (&priv->in_lock);
+ pthread_mutex_unlock(&priv->out_lock);
+ pthread_mutex_unlock(&priv->in_lock);
- if (notify_rpc) {
- rpc_transport_notify (this, event, this);
- }
+ if (notify_rpc) {
+ rpc_transport_notify(this, event, this);
+ }
out:
- return ret;
+ return ret;
}
-static int socket_disconnect (rpc_transport_t *this, gf_boolean_t wait);
+static int
+socket_disconnect(rpc_transport_t *this, gf_boolean_t wait);
/* socket_is_connected() is for use only in socket_event_handler() */
static inline gf_boolean_t
-socket_is_connected (rpc_transport_t *this)
+socket_is_connected(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
+ socket_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (priv->use_ssl) {
- return priv->is_server ? priv->ssl_accepted :
- priv->ssl_connected;
- } else {
- return priv->is_server ? priv->accepted :
- priv->connected;
- }
+ if (priv->use_ssl) {
+ return priv->is_server ? priv->ssl_accepted : priv->ssl_connected;
+ } else {
+ return priv->is_server ? priv->accepted : priv->connected;
+ }
}
static void
-ssl_rearm_event_fd (rpc_transport_t *this)
+ssl_rearm_event_fd(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
- int idx = -1;
- int gen = -1;
- int fd = -1;
-
- priv = this->private;
- ctx = this->ctx;
-
- idx = priv->idx;
- gen = priv->gen;
- fd = priv->sock;
-
- if (priv->ssl_error_required == SSL_ERROR_WANT_READ)
- event_select_on (ctx->event_pool, fd, idx, 1, -1);
- if (priv->ssl_error_required == SSL_ERROR_WANT_WRITE)
- event_select_on (ctx->event_pool, fd, idx, -1, 1);
- event_handled (ctx->event_pool, fd, idx, gen);
+ socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ int idx = -1;
+ int gen = -1;
+ int fd = -1;
+
+ priv = this->private;
+ ctx = this->ctx;
+
+ idx = priv->idx;
+ gen = priv->gen;
+ fd = priv->sock;
+
+ if (priv->ssl_error_required == SSL_ERROR_WANT_READ)
+ event_select_on(ctx->event_pool, fd, idx, 1, -1);
+ if (priv->ssl_error_required == SSL_ERROR_WANT_WRITE)
+ event_select_on(ctx->event_pool, fd, idx, -1, 1);
+ event_handled(ctx->event_pool, fd, idx, gen);
}
static int
-ssl_handle_server_connection_attempt (rpc_transport_t *this)
+ssl_handle_server_connection_attempt(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
- int idx = -1;
- int gen = -1;
- int ret = -1;
- int fd = -1;
-
- priv = this->private;
- ctx = this->ctx;
-
- idx = priv->idx;
- gen = priv->gen;
- fd = priv->sock;
-
- if (!priv->ssl_context_created) {
- ret = ssl_setup_connection_prefix (this);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_TRACE,
- "> ssl_setup_connection_prefix() failed!");
- ret = -1;
- goto out;
- } else {
- priv->ssl_context_created = _gf_true;
- }
- }
- ret = ssl_complete_connection (this);
- if (ret == 0) {
- /* nothing to do */
- event_select_on (ctx->event_pool, fd, idx, 1, 0);
- event_handled (ctx->event_pool, fd, idx, gen);
- ret = 1;
+ socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ int idx = -1;
+ int gen = -1;
+ int ret = -1;
+ int fd = -1;
+
+ priv = this->private;
+ ctx = this->ctx;
+
+ idx = priv->idx;
+ gen = priv->gen;
+ fd = priv->sock;
+
+ if (!priv->ssl_context_created) {
+ ret = ssl_setup_connection_prefix(this);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "> ssl_setup_connection_prefix() failed!");
+ ret = -1;
+ goto out;
} else {
- if (errno == EAGAIN) {
- ssl_rearm_event_fd (this);
- ret = 1;
- } else {
- ret = -1;
- gf_log (this->name, GF_LOG_TRACE,
- "ssl_complete_connection returned error");
- }
+ priv->ssl_context_created = _gf_true;
+ }
+ }
+ ret = ssl_complete_connection(this);
+ if (ret == 0) {
+ /* nothing to do */
+ event_select_on(ctx->event_pool, fd, idx, 1, 0);
+ event_handled(ctx->event_pool, fd, idx, gen);
+ ret = 1;
+ } else {
+ if (errno == EAGAIN) {
+ ssl_rearm_event_fd(this);
+ ret = 1;
+ } else {
+ ret = -1;
+ gf_log(this->name, GF_LOG_TRACE,
+ "ssl_complete_connection returned error");
}
+ }
out:
- return ret;
+ return ret;
}
static int
-ssl_handle_client_connection_attempt (rpc_transport_t *this)
+ssl_handle_client_connection_attempt(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
- int idx = -1;
- int ret = -1;
- int fd = -1;
-
- priv = this->private;
- ctx = this->ctx;
-
- idx = priv->idx;
- fd = priv->sock;
-
- /* SSL client */
- if (priv->connect_failed) {
- gf_log (this->name, GF_LOG_TRACE,
- ">>> disconnecting SSL socket");
- ret = socket_disconnect (this, _gf_false);
- /* Force ret to be -1, as we are officially done with
- this socket */
+ socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ int idx = -1;
+ int ret = -1;
+ int fd = -1;
+
+ priv = this->private;
+ ctx = this->ctx;
+
+ idx = priv->idx;
+ fd = priv->sock;
+
+ /* SSL client */
+ if (priv->connect_failed) {
+ gf_log(this->name, GF_LOG_TRACE, ">>> disconnecting SSL socket");
+ ret = socket_disconnect(this, _gf_false);
+ /* Force ret to be -1, as we are officially done with
+ this socket */
+ ret = -1;
+ } else {
+ if (!priv->ssl_context_created) {
+ ret = ssl_setup_connection_prefix(this);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "> ssl_setup_connection_prefix() "
+ "failed!");
ret = -1;
+ goto out;
+ } else {
+ priv->ssl_context_created = _gf_true;
+ }
+ }
+ ret = ssl_complete_connection(this);
+ if (ret == 0) {
+ ret = socket_connect_finish(this);
+ event_select_on(ctx->event_pool, fd, idx, 1, 0);
+ gf_log(this->name, GF_LOG_TRACE, ">>> completed client connect");
} else {
- if (!priv->ssl_context_created) {
- ret = ssl_setup_connection_prefix (this);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_TRACE,
- "> ssl_setup_connection_prefix() "
- "failed!");
- ret = -1;
- goto out;
- } else {
- priv->ssl_context_created = _gf_true;
- }
- }
- ret = ssl_complete_connection (this);
- if (ret == 0) {
- ret = socket_connect_finish (this);
- event_select_on (ctx->event_pool, fd, idx, 1, 0);
- gf_log (this->name, GF_LOG_TRACE,
- ">>> completed client connect");
- } else {
- if (errno == EAGAIN) {
- gf_log (this->name, GF_LOG_TRACE,
- ">>> retrying client connect 2");
- ssl_rearm_event_fd (this);
- ret = 1;
- } else {
- /* this is a connection failure */
- ret = socket_connect_finish (this);
- gf_log (this->name, GF_LOG_TRACE,
- "ssl_complete_connection "
- "returned error");
- ret = -1;
- }
- }
+ if (errno == EAGAIN) {
+ gf_log(this->name, GF_LOG_TRACE,
+ ">>> retrying client connect 2");
+ ssl_rearm_event_fd(this);
+ ret = 1;
+ } else {
+ /* this is a connection failure */
+ ret = socket_connect_finish(this);
+ gf_log(this->name, GF_LOG_TRACE,
+ "ssl_complete_connection "
+ "returned error");
+ ret = -1;
+ }
}
+ }
out:
- return ret;
+ return ret;
}
static int
-socket_handle_client_connection_attempt (rpc_transport_t *this)
+socket_handle_client_connection_attempt(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
- int idx = -1;
- int gen = -1;
- int ret = -1;
- int fd = -1;
-
- priv = this->private;
- ctx = this->ctx;
-
- idx = priv->idx;
- gen = priv->gen;
- fd = priv->sock;
-
- /* non-SSL client */
- if (priv->connect_failed) {
- /* connect failed with some other error than
- EINPROGRESS or ENOENT, so nothing more to
- do, fail reading/writing anything even if
- poll_in or poll_out
- is set
- */
- gf_log ("transport", GF_LOG_DEBUG,
- "connect failed with some other error "
- "than EINPROGRESS or ENOENT, so "
- "nothing more to do; disconnecting "
- "socket");
- (void)socket_disconnect (this, _gf_false);
-
- /* Force ret to be -1, as we are officially
- * done with this socket
- */
- ret = -1;
- } else {
- ret = socket_connect_finish (this);
- gf_log (this->name, GF_LOG_TRACE,
- "socket_connect_finish() returned %d",
- ret);
- if (ret == 0 || ret == 1) {
- /* we don't want to do any reads or
- * writes on the connection yet in
- * socket_event_handler, so just
- * return 1
- */
- ret = 1;
- event_handled (ctx->event_pool, fd, idx, gen);
- }
- }
- return ret;
+ socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ int idx = -1;
+ int gen = -1;
+ int ret = -1;
+ int fd = -1;
+
+ priv = this->private;
+ ctx = this->ctx;
+
+ idx = priv->idx;
+ gen = priv->gen;
+ fd = priv->sock;
+
+ /* non-SSL client */
+ if (priv->connect_failed) {
+ /* connect failed with some other error than
+ EINPROGRESS or ENOENT, so nothing more to
+ do, fail reading/writing anything even if
+ poll_in or poll_out
+ is set
+ */
+ gf_log("transport", GF_LOG_DEBUG,
+ "connect failed with some other error "
+ "than EINPROGRESS or ENOENT, so "
+ "nothing more to do; disconnecting "
+ "socket");
+ (void)socket_disconnect(this, _gf_false);
+
+ /* Force ret to be -1, as we are officially
+ * done with this socket
+ */
+ ret = -1;
+ } else {
+ ret = socket_connect_finish(this);
+ gf_log(this->name, GF_LOG_TRACE, "socket_connect_finish() returned %d",
+ ret);
+ if (ret == 0 || ret == 1) {
+ /* we don't want to do any reads or
+ * writes on the connection yet in
+ * socket_event_handler, so just
+ * return 1
+ */
+ ret = 1;
+ event_handled(ctx->event_pool, fd, idx, gen);
+ }
+ }
+ return ret;
}
static int
-socket_complete_connection (rpc_transport_t *this)
+socket_complete_connection(rpc_transport_t *this)
{
- socket_private_t *priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
- int idx = -1;
- int gen = -1;
- int ret = -1;
- int fd = -1;
+ socket_private_t *priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ int idx = -1;
+ int gen = -1;
+ int ret = -1;
+ int fd = -1;
- priv = this->private;
- ctx = this->ctx;
+ priv = this->private;
+ ctx = this->ctx;
- idx = priv->idx;
- gen = priv->gen;
- fd = priv->sock;
+ idx = priv->idx;
+ gen = priv->gen;
+ fd = priv->sock;
- if (priv->use_ssl) {
- if (priv->is_server) {
- ret = ssl_handle_server_connection_attempt (this);
- } else {
- ret = ssl_handle_client_connection_attempt (this);
- }
+ if (priv->use_ssl) {
+ if (priv->is_server) {
+ ret = ssl_handle_server_connection_attempt(this);
} else {
- if (priv->is_server) {
- /* non-SSL server: nothing much to do
- * connection has already been accepted in
- * socket_server_event_handler()
- */
- priv->accepted = _gf_true;
- event_handled (ctx->event_pool, fd, idx, gen);
- ret = 1;
- } else {
- ret = socket_handle_client_connection_attempt (this);
- }
+ ret = ssl_handle_client_connection_attempt(this);
}
- return ret;
+ } else {
+ if (priv->is_server) {
+ /* non-SSL server: nothing much to do
+ * connection has already been accepted in
+ * socket_server_event_handler()
+ */
+ priv->accepted = _gf_true;
+ event_handled(ctx->event_pool, fd, idx, gen);
+ ret = 1;
+ } else {
+ ret = socket_handle_client_connection_attempt(this);
+ }
+ }
+ return ret;
}
/* reads rpc_requests during pollin */
static int
-socket_event_handler (int fd, int idx, int gen, void *data,
- int poll_in, int poll_out, int poll_err)
+socket_event_handler(int fd, int idx, int gen, void *data, int poll_in,
+ int poll_out, int poll_err)
{
- rpc_transport_t *this = NULL;
- socket_private_t *priv = NULL;
- int ret = -1;
- glusterfs_ctx_t *ctx = NULL;
- gf_boolean_t socket_closed = _gf_false, notify_handled = _gf_false;
+ rpc_transport_t *this = NULL;
+ socket_private_t *priv = NULL;
+ int ret = -1;
+ glusterfs_ctx_t *ctx = NULL;
+ gf_boolean_t socket_closed = _gf_false, notify_handled = _gf_false;
+ this = data;
- this = data;
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this->xl, out);
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
- GF_VALIDATE_OR_GOTO ("socket", this->xl, out);
+ THIS = this->xl;
+ priv = this->private;
+ ctx = this->ctx;
- THIS = this->xl;
- priv = this->private;
- ctx = this->ctx;
+ pthread_mutex_lock(&priv->in_lock);
+ pthread_mutex_lock(&priv->out_lock);
+ {
+ priv->idx = idx;
+ priv->gen = gen;
+ }
+ pthread_mutex_unlock(&priv->out_lock);
+ pthread_mutex_unlock(&priv->in_lock);
+
+ gf_log(this->name, GF_LOG_TRACE, "%s (sock:%d) in:%d, out:%d, err:%d",
+ (priv->is_server ? "server" : "client"), priv->sock, poll_in,
+ poll_out, poll_err);
+
+ if (!poll_err) {
+ if (!socket_is_connected(this)) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "%s (sock:%d) socket is not connected, "
+ "completing connection",
+ (priv->is_server ? "server" : "client"), priv->sock);
+
+ ret = socket_complete_connection(this);
+
+ gf_log(this->name, GF_LOG_TRACE,
+ "(sock:%d) "
+ "socket_complete_connection() returned %d",
+ priv->sock, ret);
+
+ if (ret > 0) {
+ gf_log(this->name, GF_LOG_TRACE,
+ "(sock:%d) returning to wait on socket", priv->sock);
+ return 0;
+ }
+ } else {
+ char *sock_type = (priv->is_server ? "Server" : "Client");
- pthread_mutex_lock (&priv->in_lock);
- pthread_mutex_lock (&priv->out_lock);
- {
- priv->idx = idx;
- priv->gen = gen;
+ gf_log(this->name, GF_LOG_TRACE,
+ "%s socket (%d) is already connected", sock_type,
+ priv->sock);
+ ret = 0;
}
- pthread_mutex_unlock (&priv->out_lock);
- pthread_mutex_unlock (&priv->in_lock);
-
- gf_log (this->name, GF_LOG_TRACE, "%s (sock:%d) in:%d, out:%d, err:%d",
- (priv->is_server ? "server" : "client"),
- priv->sock, poll_in, poll_out, poll_err);
-
- if (!poll_err) {
- if (!socket_is_connected (this)) {
- gf_log (this->name, GF_LOG_TRACE,
- "%s (sock:%d) socket is not connected, "
- "completing connection",
- (priv->is_server ? "server" : "client"),
- priv->sock);
-
- ret = socket_complete_connection (this);
-
- gf_log (this->name, GF_LOG_TRACE, "(sock:%d) "
- "socket_complete_connection() returned %d",
- priv->sock, ret);
-
- if (ret > 0) {
- gf_log (this->name, GF_LOG_TRACE,
- "(sock:%d) returning to wait on socket",
- priv->sock);
- return 0;
- }
- } else {
- char *sock_type = (priv->is_server ? "Server" :
- "Client");
+ }
- gf_log (this->name, GF_LOG_TRACE,
- "%s socket (%d) is already connected",
- sock_type, priv->sock);
- ret = 0;
- }
- }
+ if (!ret && poll_out) {
+ ret = socket_event_poll_out(this);
+ gf_log(this->name, GF_LOG_TRACE,
+ "(sock:%d) "
+ "socket_event_poll_out returned %d",
+ priv->sock, ret);
+ }
- if (!ret && poll_out) {
- ret = socket_event_poll_out (this);
- gf_log (this->name, GF_LOG_TRACE, "(sock:%d) "
- "socket_event_poll_out returned %d", priv->sock, ret);
- }
+ if (!ret && poll_in) {
+ ret = socket_event_poll_in(this, !poll_err);
+ gf_log(this->name, GF_LOG_TRACE,
+ "(sock:%d) "
+ "socket_event_poll_in returned %d",
+ priv->sock, ret);
+ notify_handled = _gf_true;
+ }
- if (!ret && poll_in) {
- ret = socket_event_poll_in (this, !poll_err);
- gf_log (this->name, GF_LOG_TRACE, "(sock:%d) "
- "socket_event_poll_in returned %d", priv->sock, ret);
- notify_handled = _gf_true;
- }
+ if ((ret < 0) || poll_err) {
+ struct sockaddr *sa = SA(&this->peerinfo.sockaddr);
- if ((ret < 0) || poll_err) {
- struct sockaddr *sa = SA(&this->peerinfo.sockaddr);
+ if (priv->is_server &&
+ SA(&this->myinfo.sockaddr)->sa_family == AF_UNIX) {
+ sa = SA(&this->myinfo.sockaddr);
+ }
- if (priv->is_server &&
- SA(&this->myinfo.sockaddr)->sa_family == AF_UNIX) {
- sa = SA(&this->myinfo.sockaddr);
- }
+ socket_dump_info(sa, priv->is_server, priv->use_ssl, priv->sock,
+ this->name, "disconnecting from");
- socket_dump_info (sa, priv->is_server, priv->use_ssl,
- priv->sock, this->name,
- "disconnecting from");
+ /* Logging has happened already in earlier cases */
+ gf_log("transport", ((ret >= 0) ? GF_LOG_INFO : GF_LOG_DEBUG),
+ "EPOLLERR - disconnecting (sock:%d) (%s)", priv->sock,
+ (priv->use_ssl ? "SSL" : "non-SSL"));
- /* Logging has happened already in earlier cases */
- gf_log ("transport", ((ret >= 0) ? GF_LOG_INFO : GF_LOG_DEBUG),
- "EPOLLERR - disconnecting (sock:%d) (%s)",
- priv->sock, (priv->use_ssl ? "SSL" : "non-SSL"));
+ socket_closed = socket_event_poll_err(this, gen, idx);
- socket_closed = socket_event_poll_err (this, gen, idx);
+ if (socket_closed)
+ rpc_transport_unref(this);
- if (socket_closed)
- rpc_transport_unref (this);
-
- } else if (!notify_handled) {
- event_handled (ctx->event_pool, fd, idx, gen);
- }
+ } else if (!notify_handled) {
+ event_handled(ctx->event_pool, fd, idx, gen);
+ }
out:
- return ret;
+ return ret;
}
static int
-socket_server_event_handler (int fd, int idx, int gen, void *data,
- int poll_in, int poll_out, int poll_err)
+socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in,
+ int poll_out, int poll_err)
{
- rpc_transport_t *this = NULL;
- socket_private_t *priv = NULL;
- int ret = 0;
- int new_sock = -1;
- rpc_transport_t *new_trans = NULL;
- struct sockaddr_storage new_sockaddr = {0, };
- socklen_t addrlen = sizeof (new_sockaddr);
- socket_private_t *new_priv = NULL;
- glusterfs_ctx_t *ctx = NULL;
-
- this = data;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
- GF_VALIDATE_OR_GOTO ("socket", this->xl, out);
-
- THIS = this->xl;
- priv = this->private;
- ctx = this->ctx;
-
- /* NOTE:
- * We have done away with the critical section in this function. since
- * there's little that it helps with. There's no other code that
- * attempts to unref the listener socket/transport from any other
- * thread context while we are using it here.
- */
- priv->idx = idx;
-
- if (poll_in) {
- new_sock = accept (priv->sock, SA (&new_sockaddr), &addrlen);
-
- if (ctx)
- event_handled (ctx->event_pool, fd, idx, gen);
-
- if (new_sock == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "accept on %d failed (%s)",
- priv->sock, strerror (errno));
- goto out;
- }
-
- if (priv->nodelay && (new_sockaddr.ss_family != AF_UNIX)) {
- ret = __socket_nodelay (new_sock);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "setsockopt() failed for "
- "NODELAY (%s)",
- strerror (errno));
- }
- }
-
- if (priv->keepalive &&
- new_sockaddr.ss_family != AF_UNIX) {
- ret = __socket_keepalive (new_sock,
- new_sockaddr.ss_family,
- priv->keepaliveintvl,
- priv->keepaliveidle,
- priv->keepalivecnt,
- priv->timeout);
- if (ret == -1)
- gf_log (this->name, GF_LOG_WARNING,
- "Failed to set keep-alive: %s",
- strerror (errno));
- }
-
- new_trans = GF_CALLOC (1, sizeof (*new_trans),
- gf_common_mt_rpc_trans_t);
- if (!new_trans) {
- sys_close (new_sock);
- goto out;
- }
-
- ret = pthread_mutex_init(&new_trans->lock, NULL);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "pthread_mutex_init() failed: %s",
- strerror (errno));
- sys_close (new_sock);
- GF_FREE (new_trans);
- goto out;
- }
- INIT_LIST_HEAD (&new_trans->list);
-
- new_trans->name = gf_strdup (this->name);
-
- memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr, addrlen);
- new_trans->peerinfo.sockaddr_len = addrlen;
-
- new_trans->myinfo.sockaddr_len = sizeof (new_trans->myinfo.sockaddr);
-
- ret = getsockname (new_sock, SA (&new_trans->myinfo.sockaddr),
- &new_trans->myinfo.sockaddr_len);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "getsockname on %d failed (%s)",
- new_sock, strerror (errno));
- sys_close (new_sock);
- GF_FREE (new_trans->name);
- GF_FREE (new_trans);
- goto out;
- }
+ rpc_transport_t *this = NULL;
+ socket_private_t *priv = NULL;
+ int ret = 0;
+ int new_sock = -1;
+ rpc_transport_t *new_trans = NULL;
+ struct sockaddr_storage new_sockaddr = {
+ 0,
+ };
+ socklen_t addrlen = sizeof(new_sockaddr);
+ socket_private_t *new_priv = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+
+ this = data;
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this->xl, out);
+
+ THIS = this->xl;
+ priv = this->private;
+ ctx = this->ctx;
+
+ /* NOTE:
+ * We have done away with the critical section in this function. since
+ * there's little that it helps with. There's no other code that
+ * attempts to unref the listener socket/transport from any other
+ * thread context while we are using it here.
+ */
+ priv->idx = idx;
+
+ if (poll_in) {
+ new_sock = accept(priv->sock, SA(&new_sockaddr), &addrlen);
+
+ if (ctx)
+ event_handled(ctx->event_pool, fd, idx, gen);
+
+ if (new_sock == -1) {
+ gf_log(this->name, GF_LOG_WARNING, "accept on %d failed (%s)",
+ priv->sock, strerror(errno));
+ goto out;
+ }
+
+ if (priv->nodelay && (new_sockaddr.ss_family != AF_UNIX)) {
+ ret = __socket_nodelay(new_sock);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "setsockopt() failed for "
+ "NODELAY (%s)",
+ strerror(errno));
+ }
+ }
+
+ if (priv->keepalive && new_sockaddr.ss_family != AF_UNIX) {
+ ret = __socket_keepalive(new_sock, new_sockaddr.ss_family,
+ priv->keepaliveintvl, priv->keepaliveidle,
+ priv->keepalivecnt, priv->timeout);
+ if (ret == -1)
+ gf_log(this->name, GF_LOG_WARNING,
+ "Failed to set keep-alive: %s", strerror(errno));
+ }
+
+ new_trans = GF_CALLOC(1, sizeof(*new_trans), gf_common_mt_rpc_trans_t);
+ if (!new_trans) {
+ sys_close(new_sock);
+ goto out;
+ }
+
+ ret = pthread_mutex_init(&new_trans->lock, NULL);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "pthread_mutex_init() failed: %s", strerror(errno));
+ sys_close(new_sock);
+ GF_FREE(new_trans);
+ goto out;
+ }
+ INIT_LIST_HEAD(&new_trans->list);
- get_transport_identifiers (new_trans);
- gf_log (this->name, GF_LOG_TRACE, "XXX server:%s, client:%s",
- new_trans->myinfo.identifier,
- new_trans->peerinfo.identifier);
+ new_trans->name = gf_strdup(this->name);
- ret = socket_init(new_trans);
- if (ret != 0) {
- sys_close (new_sock);
- GF_FREE (new_trans->name);
- GF_FREE (new_trans);
- goto out;
- }
- new_trans->ops = this->ops;
- new_trans->init = this->init;
- new_trans->fini = this->fini;
- new_trans->ctx = ctx;
- new_trans->xl = this->xl;
- new_trans->mydata = this->mydata;
- new_trans->notify = this->notify;
- new_trans->listener = this;
- new_priv = new_trans->private;
-
- if (new_sockaddr.ss_family == AF_UNIX) {
- new_priv->use_ssl = _gf_false;
- } else {
- switch (priv->srvr_ssl) {
- case MGMT_SSL_ALWAYS:
- /* Glusterd with secure_mgmt. */
- new_priv->use_ssl = _gf_true;
- break;
- case MGMT_SSL_COPY_IO:
- /* Glusterfsd. */
- new_priv->use_ssl = priv->ssl_enabled;
- break;
- default:
- new_priv->use_ssl = _gf_false;
- }
- }
+ memcpy(&new_trans->peerinfo.sockaddr, &new_sockaddr, addrlen);
+ new_trans->peerinfo.sockaddr_len = addrlen;
- new_priv->sock = new_sock;
+ new_trans->myinfo.sockaddr_len = sizeof(new_trans->myinfo.sockaddr);
- new_priv->ssl_enabled = priv->ssl_enabled;
- new_priv->ssl_ctx = priv->ssl_ctx;
- new_priv->connected = 1;
- new_priv->is_server = _gf_true;
-
- /* set O_NONBLOCK for plain text as well as ssl connections */
- if (!priv->bio) {
- gf_log (this->name, GF_LOG_TRACE,
- "### use non-blocking IO");
- ret = __socket_nonblock (new_sock);
+ ret = getsockname(new_sock, SA(&new_trans->myinfo.sockaddr),
+ &new_trans->myinfo.sockaddr_len);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING, "getsockname on %d failed (%s)",
+ new_sock, strerror(errno));
+ sys_close(new_sock);
+ GF_FREE(new_trans->name);
+ GF_FREE(new_trans);
+ goto out;
+ }
+
+ get_transport_identifiers(new_trans);
+ gf_log(this->name, GF_LOG_TRACE, "XXX server:%s, client:%s",
+ new_trans->myinfo.identifier, new_trans->peerinfo.identifier);
+
+ ret = socket_init(new_trans);
+ if (ret != 0) {
+ sys_close(new_sock);
+ GF_FREE(new_trans->name);
+ GF_FREE(new_trans);
+ goto out;
+ }
+ new_trans->ops = this->ops;
+ new_trans->init = this->init;
+ new_trans->fini = this->fini;
+ new_trans->ctx = ctx;
+ new_trans->xl = this->xl;
+ new_trans->mydata = this->mydata;
+ new_trans->notify = this->notify;
+ new_trans->listener = this;
+ new_priv = new_trans->private;
+
+ if (new_sockaddr.ss_family == AF_UNIX) {
+ new_priv->use_ssl = _gf_false;
+ } else {
+ switch (priv->srvr_ssl) {
+ case MGMT_SSL_ALWAYS:
+ /* Glusterd with secure_mgmt. */
+ new_priv->use_ssl = _gf_true;
+ break;
+ case MGMT_SSL_COPY_IO:
+ /* Glusterfsd. */
+ new_priv->use_ssl = priv->ssl_enabled;
+ break;
+ default:
+ new_priv->use_ssl = _gf_false;
+ }
+ }
+
+ new_priv->sock = new_sock;
+
+ new_priv->ssl_enabled = priv->ssl_enabled;
+ new_priv->ssl_ctx = priv->ssl_ctx;
+ new_priv->connected = 1;
+ new_priv->is_server = _gf_true;
+
+ /* set O_NONBLOCK for plain text as well as ssl connections */
+ if (!priv->bio) {
+ gf_log(this->name, GF_LOG_TRACE, "### use non-blocking IO");
+ ret = __socket_nonblock(new_sock);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_WARNING,
- "NBIO on %d failed (%s)",
- new_sock, strerror (errno));
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_WARNING, "NBIO on %d failed (%s)",
+ new_sock, strerror(errno));
- sys_close (new_sock);
- GF_FREE (new_trans->name);
- GF_FREE (new_trans);
- goto out;
- }
- }
- /*
- * This is the first ref on the newly accepted
- * transport.
- */
- rpc_transport_ref (new_trans);
-
- {
- /* Take a ref on the new_trans to avoid
- * getting deleted when event_register()
- * causes socket_event_handler() to race
- * ahead of this path to eventually find
- * a disconnect and unref the transport
- */
- rpc_transport_ref (new_trans);
-
- /* Send a notification to RPCSVC layer
- * to save the new_trans in its service
- * list before we register the new_sock
- * with epoll to begin receiving notifications
- * for data handling.
- */
- ret = rpc_transport_notify (this, RPC_TRANSPORT_ACCEPT, new_trans);
-
- if (ret != -1) {
- new_priv->idx =
- event_register (ctx->event_pool,
- new_sock,
- socket_event_handler,
- new_trans,
- 1, 0);
- if (new_priv->idx == -1) {
- ret = -1;
- gf_log(this->name, GF_LOG_ERROR,
- "failed to register the socket "
- "with event");
-
- /* event_register() could have failed for some
- * reason, implying that the new_sock cannot be
- * added to the epoll set. If we won't get any
- * more notifications for new_sock from epoll,
- * then we better remove the corresponding
- * new_trans object from the RPCSVC service list.
- * Since we've notified RPC service of new_trans
- * before we attempted event_register(), we better
- * unlink the new_trans from the RPCSVC service list
- * to cleanup the stateby sending out a DISCONNECT
- * notification.
- */
- rpc_transport_notify (this, RPC_TRANSPORT_DISCONNECT, new_trans);
- }
- }
+ sys_close(new_sock);
+ GF_FREE(new_trans->name);
+ GF_FREE(new_trans);
+ goto out;
+ }
+ }
+ /*
+ * This is the first ref on the newly accepted
+ * transport.
+ */
+ rpc_transport_ref(new_trans);
- /* this rpc_transport_unref() is for managing race between
- * 1. socket_server_event_handler and
- * 2. socket_event_handler
- * trying to add and remove new_trans from the rpcsvc
- * service list
- * now that we are done with the notifications, lets
- * reduce the reference
- */
- rpc_transport_unref (new_trans);
- }
+ {
+ /* Take a ref on the new_trans to avoid
+ * getting deleted when event_register()
+ * causes socket_event_handler() to race
+ * ahead of this path to eventually find
+ * a disconnect and unref the transport
+ */
+ rpc_transport_ref(new_trans);
+
+ /* Send a notification to RPCSVC layer
+ * to save the new_trans in its service
+ * list before we register the new_sock
+ * with epoll to begin receiving notifications
+ * for data handling.
+ */
+ ret = rpc_transport_notify(this, RPC_TRANSPORT_ACCEPT, new_trans);
+
+ if (ret != -1) {
+ new_priv->idx = event_register(ctx->event_pool, new_sock,
+ socket_event_handler, new_trans,
+ 1, 0);
+ if (new_priv->idx == -1) {
+ ret = -1;
+ gf_log(this->name, GF_LOG_ERROR,
+ "failed to register the socket "
+ "with event");
+
+ /* event_register() could have failed for some
+ * reason, implying that the new_sock cannot be
+ * added to the epoll set. If we won't get any
+ * more notifications for new_sock from epoll,
+ * then we better remove the corresponding
+ * new_trans object from the RPCSVC service list.
+ * Since we've notified RPC service of new_trans
+ * before we attempted event_register(), we better
+ * unlink the new_trans from the RPCSVC service list
+ * to cleanup the stateby sending out a DISCONNECT
+ * notification.
+ */
+ rpc_transport_notify(this, RPC_TRANSPORT_DISCONNECT,
+ new_trans);
+ }
+ }
+
+ /* this rpc_transport_unref() is for managing race between
+ * 1. socket_server_event_handler and
+ * 2. socket_event_handler
+ * trying to add and remove new_trans from the rpcsvc
+ * service list
+ * now that we are done with the notifications, lets
+ * reduce the reference
+ */
+ rpc_transport_unref(new_trans);
+ }
- if (ret == -1) {
- sys_close (new_sock);
- /* this unref is to actually cause the destruction of
- * the new_trans since we've failed at everything so far
- */
- rpc_transport_unref (new_trans);
- }
+ if (ret == -1) {
+ sys_close(new_sock);
+ /* this unref is to actually cause the destruction of
+ * the new_trans since we've failed at everything so far
+ */
+ rpc_transport_unref(new_trans);
}
+ }
out:
- return ret;
+ return ret;
}
-
static int
-socket_disconnect (rpc_transport_t *this, gf_boolean_t wait)
+socket_disconnect(rpc_transport_t *this, gf_boolean_t wait)
{
- socket_private_t *priv = NULL;
- int ret = -1;
+ socket_private_t *priv = NULL;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("socket", this, out);
- GF_VALIDATE_OR_GOTO ("socket", this->private, out);
+ GF_VALIDATE_OR_GOTO("socket", this, out);
+ GF_VALIDATE_OR_GOTO("socket", this->private, out);
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->in_lock);
- pthread_mutex_lock (&priv->out_lock);
- {
- ret = __socket_disconnect (this);
- }
- pthread_mutex_unlock (&priv->out_lock);
- pthread_mutex_unlock (&priv->in_lock);
+ pthread_mutex_lock(&priv->in_lock);
+ pthread_mutex_lock(&priv->out_lock);
+ {
+ ret = __socket_disconnect(this);
+ }
+ pthread_mutex_unlock(&priv->out_lock);
+ pthread_mutex_unlock(&priv->in_lock);
out:
- return ret;
+ return ret;
}
-void*
-socket_connect_error_cbk (void *opaque)
+void *
+socket_connect_error_cbk(void *opaque)
{
- socket_connect_error_state_t *arg;
+ socket_connect_error_state_t *arg;
- GF_ASSERT (opaque);
+ GF_ASSERT(opaque);
- arg = opaque;
- THIS = arg->this;
+ arg = opaque;
+ THIS = arg->this;
- rpc_transport_notify (arg->trans, RPC_TRANSPORT_DISCONNECT, arg->trans);
+ rpc_transport_notify(arg->trans, RPC_TRANSPORT_DISCONNECT, arg->trans);
- if (arg->refd)
- rpc_transport_unref (arg->trans);
+ if (arg->refd)
+ rpc_transport_unref(arg->trans);
- GF_FREE (opaque);
- return NULL;
+ GF_FREE(opaque);
+ return NULL;
}
static void
-socket_fix_ssl_opts (rpc_transport_t *this, socket_private_t *priv,
- uint16_t port)
+socket_fix_ssl_opts(rpc_transport_t *this, socket_private_t *priv,
+ uint16_t port)
{
- if (port == GF_DEFAULT_SOCKET_LISTEN_PORT) {
- gf_log (this->name, GF_LOG_DEBUG,
- "%s SSL for portmapper connection",
- priv->mgmt_ssl ? "enabling" : "disabling");
- priv->use_ssl = priv->mgmt_ssl;
- } else if (priv->ssl_enabled && !priv->use_ssl) {
- gf_log(this->name, GF_LOG_DEBUG,
- "re-enabling SSL for I/O connection");
- priv->use_ssl = _gf_true;
- }
+ if (port == GF_DEFAULT_SOCKET_LISTEN_PORT) {
+ gf_log(this->name, GF_LOG_DEBUG, "%s SSL for portmapper connection",
+ priv->mgmt_ssl ? "enabling" : "disabling");
+ priv->use_ssl = priv->mgmt_ssl;
+ } else if (priv->ssl_enabled && !priv->use_ssl) {
+ gf_log(this->name, GF_LOG_DEBUG, "re-enabling SSL for I/O connection");
+ priv->use_ssl = _gf_true;
+ }
}
/*
@@ -3343,1009 +3234,968 @@ socket_fix_ssl_opts (rpc_transport_t *this, socket_private_t *priv,
* as well.
*/
static int
-connect_loop (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+connect_loop(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
- int ret;
- int connect_fails = 0;
+ int ret;
+ int connect_fails = 0;
- for (;;) {
- ret = connect (sockfd, addr, addrlen);
- if (ret >= 0) {
- break;
- }
- if ((errno != ENOENT) || (++connect_fails >= 5)) {
- break;
- }
- sleep (1);
+ for (;;) {
+ ret = connect(sockfd, addr, addrlen);
+ if (ret >= 0) {
+ break;
+ }
+ if ((errno != ENOENT) || (++connect_fails >= 5)) {
+ break;
}
+ sleep(1);
+ }
- return ret;
+ return ret;
}
static int
-socket_connect (rpc_transport_t *this, int port)
+socket_connect(rpc_transport_t *this, int port)
{
- int ret = -1;
- int th_ret = -1;
- int sock = -1;
- socket_private_t *priv = NULL;
- socklen_t sockaddr_len = 0;
- glusterfs_ctx_t *ctx = NULL;
- sa_family_t sa_family = {0, };
- char *local_addr = NULL;
- union gf_sock_union sock_union;
- struct sockaddr_in *addr = NULL;
- gf_boolean_t refd = _gf_false;
- socket_connect_error_state_t *arg = NULL;
- pthread_t th_id = {0, };
- gf_boolean_t ign_enoent = _gf_false;
- gf_boolean_t connect_attempted = _gf_false;
-
- GF_VALIDATE_OR_GOTO ("socket", this, err);
- GF_VALIDATE_OR_GOTO ("socket", this->private, err);
-
- priv = this->private;
- ctx = this->ctx;
-
- if (!priv) {
- gf_log_callingfn (this->name, GF_LOG_WARNING,
- "connect() called on uninitialized transport");
- goto err;
+ int ret = -1;
+ int th_ret = -1;
+ int sock = -1;
+ socket_private_t *priv = NULL;
+ socklen_t sockaddr_len = 0;
+ glusterfs_ctx_t *ctx