diff options
Diffstat (limited to 'rpc/rpc-lib/src/rpc-transport.c')
| -rw-r--r-- | rpc/rpc-lib/src/rpc-transport.c | 162 |
1 files changed, 67 insertions, 95 deletions
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c index 54636dcbf00..a6e201a9b36 100644 --- a/rpc/rpc-lib/src/rpc-transport.c +++ b/rpc/rpc-lib/src/rpc-transport.c @@ -12,17 +12,9 @@ #include <stdlib.h> #include <stdio.h> #include <sys/poll.h> -#include <fnmatch.h> #include <stdint.h> -#include "logging.h" #include "rpc-transport.h" -#include "glusterfs.h" -/* FIXME: xlator.h is needed for volume_option_t, need to define the datatype - * in some other header - */ -#include "xlator.h" -#include "list.h" #ifndef GF_OPTION_LIST_EMPTY #define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) @@ -68,17 +60,6 @@ out: } int32_t -rpc_transport_get_myname(rpc_transport_t *this, char *hostname, int hostlen) -{ - int32_t ret = -1; - GF_VALIDATE_OR_GOTO("rpc", this, out); - - ret = this->ops->get_myname(this, hostname, hostlen); -out: - return ret; -} - -int32_t rpc_transport_get_peername(rpc_transport_t *this, char *hostname, int hostlen) { int32_t ret = -1; @@ -92,14 +73,10 @@ out: int rpc_transport_throttle(rpc_transport_t *this, gf_boolean_t onoff) { - int ret = 0; - if (!this->ops->throttle) return -ENOSYS; - ret = this->ops->throttle(this, onoff); - - return ret; + return this->ops->throttle(this, onoff); } int32_t @@ -144,6 +121,8 @@ rpc_transport_pollin_alloc(rpc_transport_t *this, struct iovec *vector, goto out; } + msg->trans = this; + if (count > 1) { msg->vectored = 1; } @@ -159,6 +138,31 @@ out: return msg; } +void +rpc_transport_cleanup(rpc_transport_t *trans) +{ + if (!trans) + return; + + if (trans->fini) + trans->fini(trans); + + if (trans->options) { + dict_unref(trans->options); + trans->options = NULL; + } + + GF_FREE(trans->name); + + if (trans->xl) + pthread_mutex_destroy(&trans->lock); + + if (trans->dl_handle) + dlclose(trans->dl_handle); + + GF_FREE(trans); +} + rpc_transport_t * rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) { @@ -166,7 +170,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) char *name = NULL; void *handle = NULL; char *type = NULL; - char str[] = "ERROR"; + static char str[] = "ERROR"; int32_t ret = -1; int is_tcp = 0, is_unix = 0, is_ibsdp = 0; volume_opt_list_t *vol_opt = NULL; @@ -191,9 +195,9 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) type = str; /* Backward compatibility */ - ret = dict_get_str(options, "transport-type", &type); + ret = dict_get_str_sizen(options, "transport-type", &type); if (ret < 0) { - ret = dict_set_str(options, "transport-type", "socket"); + ret = dict_set_str_sizen(options, "transport-type", "socket"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); else @@ -215,15 +219,16 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) is_ibsdp = strcmp(type, "ib-sdp"); if ((is_tcp == 0) || (is_unix == 0) || (is_ibsdp == 0)) { if (is_unix == 0) - ret = dict_set_str(options, "transport.address-family", "unix"); + ret = dict_set_str_sizen(options, "transport.address-family", + "unix"); if (is_ibsdp == 0) - ret = dict_set_str(options, "transport.address-family", - "inet-sdp"); + ret = dict_set_str_sizen(options, "transport.address-family", + "inet-sdp"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting address-family failed"); - ret = dict_set_str(options, "transport-type", "socket"); + ret = dict_set_str_sizen(options, "transport-type", "socket"); if (ret < 0) gf_log("dict", GF_LOG_DEBUG, "setting transport-type failed"); } @@ -232,9 +237,9 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) /* client-bind-insecure is for clients protocol, and * bind-insecure for glusterd. Both mutually exclusive */ - ret = dict_get_str(options, "client-bind-insecure", &type); + ret = dict_get_str_sizen(options, "client-bind-insecure", &type); if (ret) - ret = dict_get_str(options, "bind-insecure", &type); + ret = dict_get_str_sizen(options, "bind-insecure", &type); if (ret == 0) { ret = gf_string2boolean(type, &bind_insecure); if (ret < 0) { @@ -253,7 +258,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) trans->bind_insecure = 1; } - ret = dict_get_str(options, "transport-type", &type); + ret = dict_get_str_sizen(options, "transport-type", &type); if (ret < 0) { gf_log("rpc-transport", GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'", @@ -266,7 +271,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) goto fail; } - if (dict_get(options, "notify-poller-death")) { + if (dict_get_sizen(options, "notify-poller-death")) { trans->notify_poller_death = 1; } @@ -332,7 +337,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) } } - trans->options = options; + trans->options = dict_ref(options); pthread_mutex_init(&trans->lock, NULL); trans->xl = this; @@ -345,6 +350,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) } INIT_LIST_HEAD(&trans->list); + GF_ATOMIC_INIT(trans->disconnect_progress, 0); return_trans = trans; @@ -354,15 +360,7 @@ rpc_transport_load(glusterfs_ctx_t *ctx, dict_t *options, char *trans_name) fail: if (!success) { - if (trans) { - GF_FREE(trans->name); - - if (trans->dl_handle) - dlclose(trans->dl_handle); - - GF_FREE(trans); - } - + rpc_transport_cleanup(trans); GF_FREE(name); return_trans = NULL; @@ -441,13 +439,10 @@ fail: return ret; } -int32_t +static void rpc_transport_destroy(rpc_transport_t *this) { struct dnscache6 *cache = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO("rpc_transport", this, fail); if (this->clnt_options) dict_unref(this->clnt_options); @@ -475,10 +470,6 @@ rpc_transport_destroy(rpc_transport_t *this) } GF_FREE(this); - - ret = 0; -fail: - return ret; } rpc_transport_t * @@ -561,16 +552,17 @@ rpc_transport_keepalive_options_set(dict_t *options, int32_t interval, GF_ASSERT(options); GF_ASSERT((interval > 0) || (time > 0)); - ret = dict_set_int32(options, "transport.socket.keepalive-interval", - interval); + ret = dict_set_int32_sizen(options, "transport.socket.keepalive-interval", + interval); if (ret) goto out; - ret = dict_set_int32(options, "transport.socket.keepalive-time", time); + ret = dict_set_int32_sizen(options, "transport.socket.keepalive-time", + time); if (ret) goto out; - ret = dict_set_int32(options, "transport.tcp-user-timeout", timeout); + ret = dict_set_int32_sizen(options, "transport.tcp-user-timeout", timeout); if (ret) goto out; out: @@ -578,19 +570,14 @@ out: } int -rpc_transport_unix_options_build(dict_t **options, char *filepath, +rpc_transport_unix_options_build(dict_t *dict, char *filepath, int frame_timeout) { - dict_t *dict = NULL; char *fpath = NULL; int ret = -1; GF_ASSERT(filepath); - GF_ASSERT(options); - - dict = dict_new(); - if (!dict) - goto out; + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); fpath = gf_strdup(filepath); if (!fpath) { @@ -598,62 +585,52 @@ rpc_transport_unix_options_build(dict_t **options, char *filepath, goto out; } - ret = dict_set_dynstr(dict, "transport.socket.connect-path", fpath); + ret = dict_set_dynstr_sizen(dict, "transport.socket.connect-path", fpath); if (ret) { GF_FREE(fpath); goto out; } - ret = dict_set_str(dict, "transport.address-family", "unix"); + ret = dict_set_str_sizen(dict, "transport.address-family", "unix"); if (ret) goto out; - ret = dict_set_str(dict, "transport.socket.nodelay", "off"); + ret = dict_set_str_sizen(dict, "transport.socket.nodelay", "off"); if (ret) goto out; - ret = dict_set_str(dict, "transport-type", "socket"); + ret = dict_set_str_sizen(dict, "transport-type", "socket"); if (ret) goto out; - ret = dict_set_str(dict, "transport.socket.keepalive", "off"); + ret = dict_set_str_sizen(dict, "transport.socket.keepalive", "off"); if (ret) goto out; if (frame_timeout > 0) { - ret = dict_set_int32(dict, "frame-timeout", frame_timeout); + ret = dict_set_int32_sizen(dict, "frame-timeout", frame_timeout); if (ret) goto out; } - - *options = dict; out: - if (ret && dict) { - dict_unref(dict); - } return ret; } int -rpc_transport_inet_options_build(dict_t **options, const char *hostname, - int port) +rpc_transport_inet_options_build(dict_t *dict, const char *hostname, int port, + char *af) { - dict_t *dict = NULL; char *host = NULL; int ret = -1; #ifdef IPV6_DEFAULT - char *addr_family = "inet6"; + static char *addr_family = "inet6"; #else - char *addr_family = "inet"; + static char *addr_family = "inet"; #endif - GF_ASSERT(options); GF_ASSERT(hostname); GF_ASSERT(port >= 1024); - - dict = dict_new(); - if (!dict) - goto out; + GF_VALIDATE_OR_GOTO("rpc-transport", dict, out); host = gf_strdup((char *)hostname); if (!host) { @@ -661,7 +638,7 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname, goto out; } - ret = dict_set_dynstr(dict, "remote-host", host); + ret = dict_set_dynstr_sizen(dict, "remote-host", host); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set remote-host with %s", host); @@ -669,32 +646,27 @@ rpc_transport_inet_options_build(dict_t **options, const char *hostname, goto out; } - ret = dict_set_int32(dict, "remote-port", port); + ret = dict_set_int32_sizen(dict, "remote-port", port); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set remote-port with %d", port); goto out; } - ret = dict_set_str(dict, "address-family", addr_family); + ret = dict_set_str_sizen(dict, "address-family", + (af != NULL ? af : addr_family)); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set address-family to %s", addr_family); goto out; } - ret = dict_set_str(dict, "transport-type", "socket"); + ret = dict_set_str_sizen(dict, "transport-type", "socket"); if (ret) { gf_log(THIS->name, GF_LOG_WARNING, "failed to set trans-type with socket"); goto out; } - - *options = dict; out: - if (ret && dict) { - dict_unref(dict); - } - return ret; } |
