summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/common-utils.c28
-rw-r--r--libglusterfs/src/compat.h8
-rw-r--r--libglusterfs/src/dict.c95
-rw-r--r--libglusterfs/src/dict.h9
-rw-r--r--libglusterfs/src/glusterfs.h1
-rw-r--r--libglusterfs/src/iobuf.c4
-rw-r--r--libglusterfs/src/latency.c12
-rw-r--r--libglusterfs/src/mem-pool.c10
-rw-r--r--libglusterfs/src/mem-types.h1
-rw-r--r--libglusterfs/src/timespec.c12
-rw-r--r--libglusterfs/src/timespec.h3
-rw-r--r--libglusterfs/src/xlator.c16
-rw-r--r--libglusterfs/src/xlator.h1
13 files changed, 157 insertions, 43 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 18f445ae265..6a5889207d4 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -181,26 +181,16 @@ gf_rev_dns_lookup (const char *ip)
{
char *fqdn = NULL;
int ret = 0;
- struct sockaddr_in sa = {0};
- char host_addr[256] = {0, };
GF_VALIDATE_OR_GOTO ("resolver", ip, out);
- sa.sin_family = AF_INET;
- inet_pton (AF_INET, ip, &sa.sin_addr);
- ret = getnameinfo ((struct sockaddr *)&sa, sizeof (sa), host_addr,
- sizeof (host_addr), NULL, 0, 0);
-
+ /* Get the FQDN */
+ ret = gf_get_hostname_from_ip ((char *)ip, &fqdn);
if (ret != 0) {
gf_msg ("resolver", GF_LOG_INFO, errno,
LG_MSG_RESOLVE_HOSTNAME_FAILED, "could not resolve "
"hostname for %s", ip);
- goto out;
}
-
- /* Get the FQDN */
- fqdn = gf_strdup (host_addr);
-
out:
return fqdn;
}
@@ -3107,11 +3097,13 @@ gf_get_hostname_from_ip (char *client_ip, char **hostname)
char *client_ip_copy = NULL;
char *tmp = NULL;
char *ip = NULL;
+ size_t addr_sz = 0;
/* if ipv4, reverse lookup the hostname to
* allow FQDN based rpc authentication
*/
- if (valid_ipv4_address (client_ip, strlen (client_ip), 0) == _gf_false) {
+ if (!valid_ipv6_address (client_ip, strlen (client_ip), 0) &&
+ !valid_ipv4_address (client_ip, strlen (client_ip), 0)) {
/* most times, we get a.b.c.d:port form, so check that */
client_ip_copy = gf_strdup (client_ip);
if (!client_ip_copy)
@@ -3124,12 +3116,14 @@ gf_get_hostname_from_ip (char *client_ip, char **hostname)
if (valid_ipv4_address (ip, strlen (ip), 0) == _gf_true) {
client_sockaddr = (struct sockaddr *)&client_sock_in;
+ addr_sz = sizeof (client_sock_in);
client_sock_in.sin_family = AF_INET;
ret = inet_pton (AF_INET, ip,
(void *)&client_sock_in.sin_addr.s_addr);
} else if (valid_ipv6_address (ip, strlen (ip), 0) == _gf_true) {
client_sockaddr = (struct sockaddr *) &client_sock_in6;
+ addr_sz = sizeof (client_sock_in6);
client_sock_in6.sin6_family = AF_INET6;
ret = inet_pton (AF_INET6, ip,
@@ -3143,8 +3137,14 @@ gf_get_hostname_from_ip (char *client_ip, char **hostname)
goto out;
}
+ /* You cannot just use sizeof (*client_sockaddr), as per the man page
+ * the (getnameinfo) size must be the size of the underlying sockaddr
+ * struct e.g. sockaddr_in6 or sockaddr_in. Failure to do so will
+ * break IPv6 hostname resolution (IPv4 will work only because
+ * the sockaddr_in struct happens to be of the correct size).
+ */
ret = getnameinfo (client_sockaddr,
- sizeof (*client_sockaddr),
+ addr_sz,
client_hostname, sizeof (client_hostname),
NULL, 0, 0);
if (ret) {
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index ea722028eb5..56736e52052 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -467,6 +467,12 @@ int gf_mkostemp (char *tmpl, int suffixlen, int flags);
#define ST_CTIM_NSEC_SET(stbuf, val) do { } while (0);
#endif
+#ifdef GF_BSD_HOST_OS
+#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
+#endif
+
+#ifndef IPV6_DEFAULT
+
#ifndef IXDR_GET_LONG
#define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf))
#endif
@@ -483,6 +489,8 @@ int gf_mkostemp (char *tmpl, int suffixlen, int flags);
#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG(buf, (long)(v))
#endif
+#endif /* IPV6_DEFAULT */
+
#if defined(__GNUC__) && !defined(RELAX_POISONING)
/* Use run API, see run.h */
#include <stdlib.h> /* system(), mkostemp() */
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index 25ddff0d8c4..6a61e641e19 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -27,6 +27,45 @@
#include "statedump.h"
#include "libglusterfs-messages.h"
+/* this goes with the bucket_size lookup table below */
+#define NUM_DISTINCT_SIZES_32_BIT 32
+
+/* this bucket_size lookup table is borrowed from GNU libstdc++ */
+static const uint32_t bucket_sizes[NUM_DISTINCT_SIZES_32_BIT] = {
+ /* 0 */ 5ul,
+ /* 1 */ 11ul,
+ /* 2 */ 23ul,
+ /* 3 */ 47ul,
+ /* 4 */ 97ul,
+ /* 5 */ 199ul,
+ /* 6 */ 409ul,
+ /* 7 */ 823ul,
+ /* 8 */ 1741ul,
+ /* 9 */ 3469ul,
+ /* 10 */ 6949ul,
+ /* 11 */ 14033ul,
+ /* 12 */ 28411ul,
+ /* 13 */ 57557ul,
+ /* 14 */ 116731ul,
+ /* 15 */ 236897ul,
+ /* 16 */ 480881ul,
+ /* 17 */ 976369ul,
+ /* 18 */ 1982627ul,
+ /* 19 */ 4026031ul,
+ /* 20 */ 8175383ul,
+ /* 21 */ 16601593ul,
+ /* 22 */ 33712729ul,
+ /* 23 */ 68460391ul,
+ /* 24 */ 139022417ul,
+ /* 25 */ 282312799ul,
+ /* 26 */ 573292817ul,
+ /* 27 */ 1164186217ul,
+ /* 28 */ 2364114217ul,
+ /* 29 */ 4294967291ul,
+ /* 30 */ 4294967291ul,
+ /* 31 */ 4294967291ul,
+};
+
struct dict_cmp {
dict_t *dict;
gf_boolean_t (*value_ignore) (char *k);
@@ -47,7 +86,7 @@ get_new_data ()
}
dict_t *
-get_new_dict_full (int size_hint)
+get_new_dict_full (uint32_t size_hint)
{
dict_t *dict = mem_get0 (THIS->ctx->dict_pool);
@@ -67,17 +106,8 @@ get_new_dict_full (int size_hint)
dict->members = &dict->members_internal;
}
else {
- /*
- * We actually need to allocate space for size_hint *pointers*
- * but we actually allocate space for one *structure*. Since
- * a data_pair_t consists of five pointers, we're wasting four
- * pointers' worth for N=1, and will overrun what we allocated
- * for N>5. If anybody ever starts using size_hint, we'll need
- * to fix this.
- */
- GF_ASSERT (size_hint <=
- (sizeof(data_pair_t) / sizeof(data_pair_t *)));
- dict->members = mem_get0 (THIS->ctx->dict_pair_pool);
+ dict->members = GF_CALLOC (size_hint, sizeof (data_pair_t *),
+ gf_common_mt_data_pair_t);
if (!dict->members) {
mem_put (dict);
return NULL;
@@ -108,6 +138,35 @@ dict_new (void)
return dict;
}
+dict_t *
+dict_new_by_size (uint32_t num)
+{
+ int32_t highest_bit = 0;
+ uint32_t bucket_size = 0;
+ dict_t *dict = NULL;
+
+ if (num == 0)
+ goto out;
+
+#ifdef _GNU_SOURCE
+ highest_bit = 32 - __builtin_clz (num);
+#else
+ while (num != 0) {
+ highest_bit++;
+ num >>= 1;
+ }
+#endif
+
+ bucket_size = bucket_sizes[highest_bit - 1];
+ dict = get_new_dict_full (bucket_size);
+
+ if (dict)
+ dict_ref (dict);
+
+out:
+ return dict;
+}
+
int32_t
is_data_equal (data_t *one,
data_t *two)
@@ -268,7 +327,7 @@ err_out:
static data_pair_t *
dict_lookup_common (dict_t *this, char *key)
{
- int hashval = 0;
+ uint32_t hashval = 0;
if (!this || !key) {
gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL,
LG_MSG_INVALID_ARG,
@@ -279,7 +338,7 @@ dict_lookup_common (dict_t *this, char *key)
/* If the divisor is 1, the modulo is always 0,
* in such case avoid hash calculation.
*/
- if (this->hash_size != 1)
+ if (this->hash_size > 1)
hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
data_pair_t *pair;
@@ -319,7 +378,7 @@ dict_lookup (dict_t *this, char *key, data_t **data)
static int32_t
dict_set_lk (dict_t *this, char *key, data_t *value, gf_boolean_t replace)
{
- int hashval = 0;
+ uint32_t hashval = 0;
data_pair_t *pair;
char key_free = 0;
int tmp = 0;
@@ -336,7 +395,7 @@ dict_set_lk (dict_t *this, char *key, data_t *value, gf_boolean_t replace)
/* If the divisor is 1, the modulo is always 0,
* in such case avoid hash calculation.
*/
- if (this->hash_size != 1) {
+ if (this->hash_size > 1) {
tmp = SuperFastHash (key, strlen (key));
hashval = (tmp % this->hash_size);
}
@@ -478,7 +537,7 @@ dict_get (dict_t *this, char *key)
void
dict_del (dict_t *this, char *key)
{
- int hashval = 0;
+ uint32_t hashval = 0;
if (!this || !key) {
gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL,
@@ -491,7 +550,7 @@ dict_del (dict_t *this, char *key)
/* If the divisor is 1, the modulo is always 0,
* in such case avoid hash calculation.
*/
- if (this->hash_size != 1)
+ if (this->hash_size > 1)
hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
data_pair_t *pair = this->members[hashval];
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index c5b82677e2e..1f6c1a0eae9 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -79,9 +79,9 @@ struct _data_pair {
struct _dict {
unsigned char is_static:1;
- int32_t hash_size;
- int32_t count;
- int32_t refcount;
+ uint32_t hash_size;
+ uint32_t count;
+ uint32_t refcount;
data_pair_t **members;
data_pair_t *members_list;
char *extra_free;
@@ -156,7 +156,7 @@ void *data_to_ptr (data_t *data);
data_t *get_new_data ();
data_t * data_copy (data_t *old);
-dict_t *get_new_dict_full (int size_hint);
+dict_t *get_new_dict_full (uint32_t size_hint);
dict_t *get_new_dict ();
int dict_foreach (dict_t *this,
@@ -196,6 +196,7 @@ int dict_keys_join (void *value, int size, dict_t *dict,
/* CLEANED UP FUNCTIONS DECLARATIONS */
GF_MUST_CHECK dict_t *dict_new (void);
+GF_MUST_CHECK dict_t *dict_new_by_size (uint32_t num);
dict_t *dict_copy_with_ref (dict_t *this, dict_t *new);
GF_MUST_CHECK int dict_reset (dict_t *dict);
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 6e2d370605b..399d695665b 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -330,6 +330,7 @@ struct _cmd_args {
uint32_t log_buf_size;
uint32_t log_flush_timeout;
int32_t max_connect_attempts;
+ unsigned int connect_attempts;
char *print_exports;
char *print_netgroups;
/* advanced options */
diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c
index 17cd68fc206..fa3ac840c43 100644
--- a/libglusterfs/src/iobuf.c
+++ b/libglusterfs/src/iobuf.c
@@ -30,8 +30,8 @@ struct iobuf_init_config gf_iobuf_init_config[] = {
{8 * 1024, 128},
{32 * 1024, 64},
{128 * 1024, 32},
- {256 * 1024, 8},
- {1 * 1024 * 1024, 2},
+ {256 * 1024, 64},
+ {1 * 1024 * 1024, 64},
};
int
diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c
index 611615949fa..3399cc7c297 100644
--- a/libglusterfs/src/latency.c
+++ b/libglusterfs/src/latency.c
@@ -21,6 +21,7 @@
#include "statedump.h"
#include "libglusterfs-messages.h"
+static int gf_set_fop_from_fn_pointer_warning;
void
gf_set_fop_from_fn_pointer (call_frame_t *frame, struct xlator_fops *fops, void *fn)
{
@@ -108,8 +109,15 @@ gf_set_fop_from_fn_pointer (call_frame_t *frame, struct xlator_fops *fops, void
fop = GF_FOP_READDIRP;
else if (fops->getspec == *(fop_getspec_t *)&fn)
fop = GF_FOP_GETSPEC;
- else
- fop = -1;
+ else if (fops->ipc == *(fop_ipc_t *)&fn)
+ fop = GF_FOP_IPC;
+ else {
+ fop = GF_FOP_NULL;
+ GF_LOG_OCCASIONALLY(gf_set_fop_from_fn_pointer_warning,
+ "latency",
+ GF_LOG_WARNING,
+ "Unknown FOP type");
+ }
frame->op = fop;
}
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 88fbdf58319..4d81ade8b60 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -454,6 +454,10 @@ mem_get0 (struct mem_pool *mem_pool)
void *
mem_get (struct mem_pool *mem_pool)
{
+#ifdef DISABLE_MEMPOOL
+ return GF_CALLOC (1, mem_pool->real_sizeof_type,
+ gf_common_mt_mem_pool);
+#else
struct list_head *list = NULL;
void *ptr = NULL;
int *in_use = NULL;
@@ -525,6 +529,7 @@ fwd_addr_out:
UNLOCK (&mem_pool->lock);
return ptr;
+#endif /* DISABLE_MEMPOOL */
}
@@ -551,6 +556,10 @@ __is_member (struct mem_pool *pool, void *ptr)
void
mem_put (void *ptr)
{
+#ifdef DISABLE_MEMPOOL
+ GF_FREE (ptr);
+ return;
+#else
struct list_head *list = NULL;
int *in_use = NULL;
void *head = NULL;
@@ -628,6 +637,7 @@ mem_put (void *ptr)
}
}
UNLOCK (&pool->lock);
+#endif /* DISABLE_MEMPOOL */
}
void
diff --git a/libglusterfs/src/mem-types.h b/libglusterfs/src/mem-types.h
index afa52d8bc45..fc7bf9e5996 100644
--- a/libglusterfs/src/mem-types.h
+++ b/libglusterfs/src/mem-types.h
@@ -168,6 +168,7 @@ enum gf_common_mem_types_ {
/*lock migration*/
gf_common_mt_lock_mig,
gf_common_mt_pthread_t,
+ gf_common_ping_local_t,
gf_common_mt_end
};
#endif
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
index f7b2bea2f30..903303d1380 100644
--- a/libglusterfs/src/timespec.c
+++ b/libglusterfs/src/timespec.c
@@ -60,3 +60,15 @@ void timespec_adjust_delta (struct timespec *ts, struct timespec delta)
ts->tv_sec += ((ts->tv_nsec + delta.tv_nsec) / 1000000000);
ts->tv_sec += delta.tv_sec;
}
+
+void timespec_sub (const struct timespec *begin, const struct timespec *end,
+ struct timespec *res)
+{
+ if (end->tv_nsec < begin->tv_nsec) {
+ res->tv_sec = end->tv_sec - begin->tv_sec - 1;
+ res->tv_nsec = end->tv_nsec + 1000000000 - begin->tv_nsec;
+ } else {
+ res->tv_sec = end->tv_sec - begin->tv_sec;
+ res->tv_nsec = end->tv_nsec - begin->tv_nsec;
+ }
+}
diff --git a/libglusterfs/src/timespec.h b/libglusterfs/src/timespec.h
index f37194b97cf..9c393ee7166 100644
--- a/libglusterfs/src/timespec.h
+++ b/libglusterfs/src/timespec.h
@@ -20,5 +20,8 @@
void timespec_now (struct timespec *ts);
void timespec_adjust_delta (struct timespec *ts, struct timespec delta);
+void timespec_sub (const struct timespec *begin,
+ const struct timespec *end,
+ struct timespec *res);
#endif /* __INCLUDE_TIMESPEC_H__ */
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 3c1cde50fa0..b2529d3c4f7 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -117,6 +117,14 @@ out:
}
+static const char *xlator_lib_path (void)
+{
+ const char *libdir_env = getenv ("GLUSTER_LIBDIR");
+
+ return libdir_env ? libdir_env : XLATORDIR;
+}
+
+
int
xlator_volopt_dynload (char *xlator_type, void **dl_handle,
volume_opt_list_t *opt_list)
@@ -130,9 +138,11 @@ xlator_volopt_dynload (char *xlator_type, void **dl_handle,
/* socket.so doesn't fall under the default xlator directory, hence we
* need this check */
if (!strstr(xlator_type, "rpc-transport"))
- ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type);
+ ret = gf_asprintf (&name, "%s/%s.so", xlator_lib_path (),
+ xlator_type);
else
- ret = gf_asprintf (&name, "%s/%s.so", XLATORPARENTDIR, xlator_type);
+ ret = gf_asprintf (&name, "%s/../%s.so", xlator_lib_path (),
+ xlator_type);
if (-1 == ret) {
goto out;
}
@@ -183,7 +193,7 @@ xlator_dynload (xlator_t *xl)
INIT_LIST_HEAD (&xl->volume_options);
- ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type);
+ ret = gf_asprintf (&name, "%s/%s.so", xlator_lib_path (), xl->type);
if (-1 == ret) {
goto out;
}
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 70e6f0a108d..2e04893c487 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -927,6 +927,7 @@ struct _xlator {
gf_loglevel_t loglevel; /* Log level for translator */
+ fop_latency_t client_latency;
/* for latency measurement */
fop_latency_t latencies[GF_FOP_MAXVALUE];