summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/authenticate.c12
-rw-r--r--libglusterfs/src/call-stub.c65
-rw-r--r--libglusterfs/src/common-utils.c38
-rw-r--r--libglusterfs/src/common-utils.h6
-rw-r--r--libglusterfs/src/defaults.c10
-rw-r--r--libglusterfs/src/defaults.h2
-rw-r--r--libglusterfs/src/dict.c69
-rw-r--r--libglusterfs/src/event.c62
-rw-r--r--libglusterfs/src/fd.c27
-rw-r--r--libglusterfs/src/gf-dirent.c7
-rw-r--r--libglusterfs/src/globals.c4
-rw-r--r--libglusterfs/src/inode.c55
-rw-r--r--libglusterfs/src/iobuf.c18
-rw-r--r--libglusterfs/src/logging.c44
-rw-r--r--libglusterfs/src/mem-pool.c287
-rw-r--r--libglusterfs/src/mem-pool.h65
-rw-r--r--libglusterfs/src/mem-types.h82
-rw-r--r--libglusterfs/src/protocol.h3
-rw-r--r--libglusterfs/src/rbthash.c20
-rw-r--r--libglusterfs/src/scheduler.c6
-rw-r--r--libglusterfs/src/scheduler.h1
-rw-r--r--libglusterfs/src/stack.h19
-rw-r--r--libglusterfs/src/statedump.c45
-rw-r--r--libglusterfs/src/timer.c19
-rw-r--r--libglusterfs/src/timer.h4
-rw-r--r--libglusterfs/src/transport.c37
-rw-r--r--libglusterfs/src/xlator.c74
-rw-r--r--libglusterfs/src/xlator.h3
28 files changed, 831 insertions, 253 deletions
diff --git a/libglusterfs/src/authenticate.c b/libglusterfs/src/authenticate.c
index 6a6fd03ac..eb0e2464c 100644
--- a/libglusterfs/src/authenticate.c
+++ b/libglusterfs/src/authenticate.c
@@ -58,7 +58,7 @@ init (dict_t *this,
key = "addr";
}
- ret = asprintf (&auth_file, "%s/%s.so", LIBDIR, key);
+ ret = gf_asprintf (&auth_file, "%s/%s.so", LIBDIR, key);
if (-1 == ret) {
gf_log ("authenticate", GF_LOG_ERROR, "asprintf failed");
dict_set (this, key, data_from_dynptr (NULL, 0));
@@ -71,11 +71,11 @@ init (dict_t *this,
gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n",
auth_file, dlerror ());
dict_set (this, key, data_from_dynptr (NULL, 0));
- FREE (auth_file);
+ GF_FREE (auth_file);
*error = -1;
return;
}
- FREE (auth_file);
+ GF_FREE (auth_file);
authenticate = dlsym (handle, "gf_auth");
if (!authenticate) {
@@ -86,14 +86,16 @@ init (dict_t *this,
return;
}
- auth_handle = CALLOC (1, sizeof (*auth_handle));
+ auth_handle = GF_CALLOC (1, sizeof (*auth_handle),
+ gf_common_mt_auth_handle_t);
if (!auth_handle) {
gf_log ("authenticate", GF_LOG_ERROR, "Out of memory");
dict_set (this, key, data_from_dynptr (NULL, 0));
*error = -1;
return;
}
- auth_handle->vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
+ auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
+ gf_common_mt_volume_opt_list_t);
auth_handle->vol_opt->given_opt = dlsym (handle, "options");
if (auth_handle->vol_opt->given_opt == NULL) {
gf_log ("authenticate", GF_LOG_DEBUG,
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
index 5f73d9d6e..f0d04eb95 100644
--- a/libglusterfs/src/call-stub.c
+++ b/libglusterfs/src/call-stub.c
@@ -26,6 +26,7 @@
#include "md5.h"
#include "call-stub.h"
+#include "mem-types.h"
static call_stub_t *
@@ -37,7 +38,7 @@ stub_new (call_frame_t *frame,
GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
- new = CALLOC (1, sizeof (*new));
+ new = GF_CALLOC (1, sizeof (*new), gf_common_mt_call_stub_t);
GF_VALIDATE_OR_GOTO ("call-stub", new, out);
new->frame = frame;
@@ -383,7 +384,7 @@ fop_readlink_cbk_stub (call_frame_t *frame,
stub->args.readlink_cbk.op_ret = op_ret;
stub->args.readlink_cbk.op_errno = op_errno;
if (path)
- stub->args.readlink_cbk.buf = strdup (path);
+ stub->args.readlink_cbk.buf = gf_strdup (path);
if (sbuf)
stub->args.readlink_cbk.sbuf = *sbuf;
out:
@@ -614,7 +615,7 @@ fop_symlink_stub (call_frame_t *frame,
GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
stub->args.symlink.fn = fn;
- stub->args.symlink.linkname = strdup (linkname);
+ stub->args.symlink.linkname = gf_strdup (linkname);
loc_copy (&stub->args.symlink.loc, loc);
out:
return stub;
@@ -1291,7 +1292,7 @@ fop_getxattr_stub (call_frame_t *frame,
loc_copy (&stub->args.getxattr.loc, loc);
if (name)
- stub->args.getxattr.name = strdup (name);
+ stub->args.getxattr.name = gf_strdup (name);
out:
return stub;
}
@@ -1388,7 +1389,7 @@ fop_fgetxattr_stub (call_frame_t *frame,
stub->args.fgetxattr.fd = fd_ref (fd);
if (name)
- stub->args.fgetxattr.name = strdup (name);
+ stub->args.fgetxattr.name = gf_strdup (name);
out:
return stub;
}
@@ -1437,7 +1438,7 @@ fop_removexattr_stub (call_frame_t *frame,
stub->args.removexattr.fn = fn;
loc_copy (&stub->args.removexattr.loc, loc);
- stub->args.removexattr.name = strdup (name);
+ stub->args.removexattr.name = gf_strdup (name);
out:
return stub;
}
@@ -1529,7 +1530,7 @@ fop_inodelk_stub (call_frame_t *frame, fop_inodelk_t fn,
stub->args.inodelk.fn = fn;
if (volume)
- stub->args.inodelk.volume = strdup (volume);
+ stub->args.inodelk.volume = gf_strdup (volume);
loc_copy (&stub->args.inodelk.loc, loc);
stub->args.inodelk.cmd = cmd;
@@ -1578,7 +1579,7 @@ fop_finodelk_stub (call_frame_t *frame, fop_finodelk_t fn,
stub->args.finodelk.fd = fd_ref (fd);
if (volume)
- stub->args.finodelk.volume = strdup (volume);
+ stub->args.finodelk.volume = gf_strdup (volume);
stub->args.finodelk.cmd = cmd;
stub->args.finodelk.lock = *lock;
@@ -1625,14 +1626,14 @@ fop_entrylk_stub (call_frame_t *frame, fop_entrylk_t fn,
stub->args.entrylk.fn = fn;
if (volume)
- stub->args.entrylk.volume = strdup (volume);
+ stub->args.entrylk.volume = gf_strdup (volume);
loc_copy (&stub->args.entrylk.loc, loc);
stub->args.entrylk.cmd = cmd;
stub->args.entrylk.type = type;
if (name)
- stub->args.entrylk.name = strdup (name);
+ stub->args.entrylk.name = gf_strdup (name);
return stub;
}
@@ -1675,14 +1676,14 @@ fop_fentrylk_stub (call_frame_t *frame, fop_fentrylk_t fn,
stub->args.fentrylk.fn = fn;
if (volume)
- stub->args.fentrylk.volume = strdup (volume);
+ stub->args.fentrylk.volume = gf_strdup (volume);
if (fd)
stub->args.fentrylk.fd = fd_ref (fd);
stub->args.fentrylk.cmd = cmd;
stub->args.fentrylk.type = type;
if (name)
- stub->args.fentrylk.name = strdup (name);
+ stub->args.fentrylk.name = gf_strdup (name);
return stub;
}
@@ -3222,8 +3223,8 @@ call_resume_unwind (call_stub_t *stub)
stub->args.checksum_cbk.dir_checksum);
if (stub->args.checksum_cbk.op_ret >= 0)
{
- FREE (stub->args.checksum_cbk.file_checksum);
- FREE (stub->args.checksum_cbk.dir_checksum);
+ GF_FREE (stub->args.checksum_cbk.file_checksum);
+ GF_FREE (stub->args.checksum_cbk.dir_checksum);
}
break;
@@ -3247,7 +3248,7 @@ call_resume_unwind (call_stub_t *stub)
stub->args.rchecksum_cbk.strong_checksum);
if (stub->args.rchecksum_cbk.op_ret >= 0)
{
- FREE (stub->args.rchecksum_cbk.strong_checksum);
+ GF_FREE (stub->args.rchecksum_cbk.strong_checksum);
}
break;
@@ -3438,7 +3439,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_SYMLINK:
{
- FREE (stub->args.symlink.linkname);
+ GF_FREE ((char *)stub->args.symlink.linkname);
loc_wipe (&stub->args.symlink.loc);
}
break;
@@ -3475,7 +3476,7 @@ call_stub_destroy_wind (call_stub_t *stub)
struct iobref *iobref = stub->args.writev.iobref;
if (stub->args.writev.fd)
fd_unref (stub->args.writev.fd);
- FREE (stub->args.writev.vector);
+ GF_FREE (stub->args.writev.vector);
if (iobref)
iobref_unref (iobref);
break;
@@ -3511,7 +3512,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_GETXATTR:
{
if (stub->args.getxattr.name)
- FREE (stub->args.getxattr.name);
+ GF_FREE ((char *)stub->args.getxattr.name);
loc_wipe (&stub->args.getxattr.loc);
break;
}
@@ -3527,7 +3528,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_FGETXATTR:
{
if (stub->args.fgetxattr.name)
- FREE (stub->args.fgetxattr.name);
+ GF_FREE ((char *)stub->args.fgetxattr.name);
fd_unref (stub->args.fgetxattr.fd);
break;
}
@@ -3535,7 +3536,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_REMOVEXATTR:
{
loc_wipe (&stub->args.removexattr.loc);
- FREE (stub->args.removexattr.name);
+ GF_FREE ((char *)stub->args.removexattr.name);
break;
}
@@ -3584,7 +3585,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_INODELK:
{
if (stub->args.inodelk.volume)
- FREE (stub->args.inodelk.volume);
+ GF_FREE ((char *)stub->args.inodelk.volume);
loc_wipe (&stub->args.inodelk.loc);
break;
@@ -3592,7 +3593,7 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_FINODELK:
{
if (stub->args.finodelk.volume)
- FREE (stub->args.finodelk.volume);
+ GF_FREE ((char *)stub->args.finodelk.volume);
if (stub->args.finodelk.fd)
fd_unref (stub->args.finodelk.fd);
@@ -3601,20 +3602,20 @@ call_stub_destroy_wind (call_stub_t *stub)
case GF_FOP_ENTRYLK:
{
if (stub->args.entrylk.volume)
- FREE (stub->args.entrylk.volume);
+ GF_FREE ((char *)stub->args.entrylk.volume);
if (stub->args.entrylk.name)
- FREE (stub->args.entrylk.name);
+ GF_FREE ((char *)stub->args.entrylk.name);
loc_wipe (&stub->args.entrylk.loc);
break;
}
case GF_FOP_FENTRYLK:
{
if (stub->args.fentrylk.volume)
- FREE (stub->args.fentrylk.volume);
+ GF_FREE ((char *)stub->args.fentrylk.volume);
if (stub->args.fentrylk.name)
- FREE (stub->args.fentrylk.name);
+ GF_FREE ((char *)stub->args.fentrylk.name);
if (stub->args.fentrylk.fd)
fd_unref (stub->args.fentrylk.fd);
@@ -3717,7 +3718,7 @@ call_stub_destroy_unwind (call_stub_t *stub)
case GF_FOP_READLINK:
{
if (stub->args.readlink_cbk.buf)
- FREE (stub->args.readlink_cbk.buf);
+ GF_FREE ((char *)stub->args.readlink_cbk.buf);
}
break;
@@ -3765,7 +3766,7 @@ call_stub_destroy_unwind (call_stub_t *stub)
{
if (stub->args.readv_cbk.op_ret >= 0) {
struct iobref *iobref = stub->args.readv_cbk.iobref;
- FREE (stub->args.readv_cbk.vector);
+ GF_FREE (stub->args.readv_cbk.vector);
if (iobref) {
iobref_unref (iobref);
@@ -3856,8 +3857,8 @@ call_stub_destroy_unwind (call_stub_t *stub)
case GF_FOP_CHECKSUM:
{
if (stub->args.checksum_cbk.op_ret >= 0) {
- FREE (stub->args.checksum_cbk.file_checksum);
- FREE (stub->args.checksum_cbk.dir_checksum);
+ GF_FREE (stub->args.checksum_cbk.file_checksum);
+ GF_FREE (stub->args.checksum_cbk.dir_checksum);
}
}
break;
@@ -3865,7 +3866,7 @@ call_stub_destroy_unwind (call_stub_t *stub)
case GF_FOP_RCHECKSUM:
{
if (stub->args.rchecksum_cbk.op_ret >= 0) {
- FREE (stub->args.rchecksum_cbk.strong_checksum);
+ GF_FREE (stub->args.rchecksum_cbk.strong_checksum);
}
}
break;
@@ -3931,7 +3932,7 @@ call_stub_destroy (call_stub_t *stub)
call_stub_destroy_unwind (stub);
}
- FREE (stub);
+ GF_FREE (stub);
out:
return;
}
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 984ad0794..7851ad2f8 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -89,7 +89,8 @@ gf_resolve_ip6 (const char *hostname,
}
if (!*dnscache) {
- *dnscache = CALLOC (1, sizeof (struct dnscache6));
+ *dnscache = GF_CALLOC (1, sizeof (struct dnscache6),
+ gf_common_mt_dnscache6);
}
cache = *dnscache;
@@ -111,7 +112,7 @@ gf_resolve_ip6 (const char *hostname,
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG;
- ret = asprintf (&port_str, "%d", port);
+ ret = gf_asprintf (&port_str, "%d", port);
if (-1 == ret) {
gf_log ("resolver", GF_LOG_ERROR, "asprintf failed");
return -1;
@@ -120,12 +121,12 @@ gf_resolve_ip6 (const char *hostname,
gf_log ("resolver", GF_LOG_ERROR,
"getaddrinfo failed (%s)", gai_strerror (ret));
- free (*dnscache);
+ GF_FREE (*dnscache);
*dnscache = NULL;
- free (port_str);
+ GF_FREE (port_str);
return -1;
}
- free (port_str);
+ GF_FREE (port_str);
cache->next = cache->first;
}
@@ -173,7 +174,7 @@ gf_resolve_ip6 (const char *hostname,
err:
freeaddrinfo (cache->first);
cache->first = cache->next = NULL;
- free (cache);
+ GF_FREE (cache);
*dnscache = NULL;
return -1;
}
@@ -509,7 +510,8 @@ gf_strsplit (const char *str, const char *delim,
return -1;
}
- if ((_running = strdup (str)) == NULL)
+ _running = gf_strdup (str);
+ if (_running == NULL)
{
return -1;
}
@@ -520,17 +522,19 @@ gf_strsplit (const char *str, const char *delim,
if (token[0] != '\0')
count++;
}
- free (_running);
+ GF_FREE (_running);
- if ((_running = strdup (str)) == NULL)
+ _running = gf_strdup (str);
+ if (_running == NULL)
{
return -1;
}
running = _running;
- if ((token_list = CALLOC (count, sizeof (char *))) == NULL)
+ if ((token_list = GF_CALLOC (count, sizeof (char *),
+ gf_common_mt_char)) == NULL)
{
- free (_running);
+ GF_FREE (_running);
return -1;
}
@@ -539,23 +543,25 @@ gf_strsplit (const char *str, const char *delim,
if (token[0] == '\0')
continue;
- if ((token_list[i++] = strdup (token)) == NULL)
+ token_list[i] = gf_strdup (token);
+ if (token_list[i] == NULL)
goto free_exit;
+ i++;
}
- free (_running);
+ GF_FREE (_running);
*tokens = token_list;
*token_count = count;
return 0;
free_exit:
- free (_running);
+ GF_FREE (_running);
for (j = 0; j < i; j++)
{
- free (token_list[j]);
+ GF_FREE (token_list[j]);
}
- free (token_list);
+ GF_FREE (token_list);
return -1;
}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 9c1c93ebf..3bf4ba9b1 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -147,7 +147,7 @@ iov_free (struct iovec *vector, int count)
for (i = 0; i < count; i++)
FREE (vector[i].iov_base);
- FREE (vector);
+ GF_FREE (vector);
}
@@ -172,7 +172,7 @@ iov_dup (struct iovec *vector, int count)
struct iovec *newvec = NULL;
bytecount = (count * sizeof (struct iovec));
- newvec = MALLOC (bytecount);
+ newvec = GF_MALLOC (bytecount, gf_common_mt_iovec);
if (!newvec)
return NULL;
@@ -282,7 +282,7 @@ memdup (const void *ptr, size_t size)
{
void *newptr = NULL;
- newptr = MALLOC (size);
+ newptr = GF_MALLOC (size, gf_common_mt_memdup);
if (!newptr)
return NULL;
diff --git a/libglusterfs/src/defaults.c b/libglusterfs/src/defaults.c
index 7ae60130e..7ec877551 100644
--- a/libglusterfs/src/defaults.c
+++ b/libglusterfs/src/defaults.c
@@ -1383,3 +1383,13 @@ default_fsetattr (call_frame_t *frame,
fd, stbuf, valid);
return 0;
}
+
+int32_t
+default_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ ret = xlator_mem_acct_init (this, gf_common_mt_end);
+
+ return ret;
+}
diff --git a/libglusterfs/src/defaults.h b/libglusterfs/src/defaults.h
index 58ef90d42..30e0f9e37 100644
--- a/libglusterfs/src/defaults.h
+++ b/libglusterfs/src/defaults.h
@@ -432,4 +432,6 @@ default_writev_cbk (call_frame_t *frame,
struct iatt *prebuf,
struct iatt *postbuf);
+int32_t
+default_mem_acct_init (xlator_t *this);
#endif /* _DEFAULTS_H */
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index 9e97bf1d4..7d560bdac 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -41,7 +41,8 @@ get_new_data_pair ()
{
data_pair_t *data_pair_ptr = NULL;
- data_pair_ptr = (data_pair_t *) CALLOC (1, sizeof (data_pair_t));
+ data_pair_ptr = (data_pair_t *) GF_CALLOC (1, sizeof (data_pair_t),
+ gf_common_mt_data_pair_t);
ERR_ABORT (data_pair_ptr);
return data_pair_ptr;
@@ -52,7 +53,7 @@ get_new_data ()
{
data_t *data = NULL;
- data = (data_t *) CALLOC (1, sizeof (data_t));
+ data = (data_t *) GF_CALLOC (1, sizeof (data_t), gf_common_mt_data_t);
if (!data) {
gf_log ("dict", GF_LOG_CRITICAL,
"calloc () returned NULL");
@@ -66,7 +67,7 @@ get_new_data ()
dict_t *
get_new_dict_full (int size_hint)
{
- dict_t *dict = CALLOC (1, sizeof (dict_t));
+ dict_t *dict = GF_CALLOC (1, sizeof (dict_t), gf_common_mt_dict_t);
if (!dict) {
gf_log ("dict", GF_LOG_CRITICAL,
@@ -75,7 +76,8 @@ get_new_dict_full (int size_hint)
}
dict->hash_size = size_hint;
- dict->members = CALLOC (size_hint, sizeof (data_pair_t *));
+ dict->members = GF_CALLOC (size_hint, sizeof (data_pair_t *),
+ gf_common_mt_data_pair_t);
if (!dict->members) {
gf_log ("dict", GF_LOG_CRITICAL,
@@ -138,14 +140,14 @@ data_destroy (data_t *data)
if (!data->is_static) {
if (data->data)
- FREE (data->data);
+ GF_FREE (data->data);
if (data->vec)
- FREE (data->vec);
+ GF_FREE (data->vec);
}
data->len = 0xbabababa;
if (!data->is_const)
- FREE (data);
+ GF_FREE (data);
}
}
@@ -158,7 +160,8 @@ data_copy (data_t *old)
return NULL;
}
- data_t *newdata = (data_t *) CALLOC (1, sizeof (*newdata));
+ data_t *newdata = (data_t *) GF_CALLOC (1, sizeof (*newdata),
+ gf_common_mt_data_t);
if (!newdata) {
gf_log ("dict", GF_LOG_CRITICAL,
@@ -229,7 +232,7 @@ _dict_set (dict_t *this,
int ret = 0;
if (!key) {
- ret = asprintf (&key, "ref:%p", value);
+ ret = gf_asprintf (&key, "ref:%p", value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return -1;
@@ -246,18 +249,20 @@ _dict_set (dict_t *this,
pair->value = data_ref (value);
data_unref (unref_data);
if (key_free)
- FREE (key);
+ GF_FREE (key);
/* Indicates duplicate key */
return 0;
}
- pair = (data_pair_t *) CALLOC (1, sizeof (*pair));
+ pair = (data_pair_t *) GF_CALLOC (1, sizeof (*pair),
+ gf_common_mt_data_pair_t);
if (!pair) {
gf_log ("dict", GF_LOG_CRITICAL,
"@pair - NULL returned by CALLOC");
return -1;
}
- pair->key = (char *) CALLOC (1, strlen (key) + 1);
+ pair->key = (char *) GF_CALLOC (1, strlen (key) + 1,
+ gf_common_mt_char);
if (!pair->key) {
gf_log ("dict", GF_LOG_CRITICAL,
"@pair->key - NULL returned by CALLOC");
@@ -280,7 +285,7 @@ _dict_set (dict_t *this,
this->count++;
if (key_free)
- FREE (key);
+ GF_FREE (key);
return 0;
}
@@ -364,8 +369,8 @@ dict_del (dict_t *this,
if (pair->next)
pair->next->prev = pair->prev;
- FREE (pair->key);
- FREE (pair);
+ GF_FREE (pair->key);
+ GF_FREE (pair);
this->count--;
break;
}
@@ -396,18 +401,18 @@ dict_destroy (dict_t *this)
while (prev) {
pair = pair->next;
data_unref (prev->value);
- FREE (prev->key);
- FREE (prev);
+ GF_FREE (prev->key);
+ GF_FREE (prev);
prev = pair;
}
- FREE (this->members);
+ GF_FREE (this->members);
if (this->extra_free)
- FREE (this->extra_free);
+ GF_FREE (this->extra_free);
if (!this->is_static)
- FREE (this);
+ GF_FREE (this);
return;
}
@@ -630,7 +635,7 @@ dict_unserialize_old (char *buf, int32_t size, dict_t **fill)
goto ret;
err:
- FREE (*fill);
+ GF_FREE (*fill);
*fill = NULL;
ret:
@@ -744,7 +749,7 @@ int_to_data (int64_t value)
return NULL;
}
- ret = asprintf (&data->data, "%"PRId64, value);
+ ret = gf_asprintf (&data->data, "%"PRId64, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -765,7 +770,7 @@ data_from_int64 (int64_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRId64, value);
+ ret = gf_asprintf (&data->data, "%"PRId64, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -786,7 +791,7 @@ data_from_int32 (int32_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRId32, value);
+ ret = gf_asprintf (&data->data, "%"PRId32, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -808,7 +813,7 @@ data_from_int16 (int16_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRId16, value);
+ ret = gf_asprintf (&data->data, "%"PRId16, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -830,7 +835,7 @@ data_from_int8 (int8_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%d", value);
+ ret = gf_asprintf (&data->data, "%d", value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -852,7 +857,7 @@ data_from_uint64 (uint64_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRIu64, value);
+ ret = gf_asprintf (&data->data, "%"PRIu64, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -877,7 +882,7 @@ data_from_double (double value)
return NULL;
}
- ret = asprintf (&data->data, "%f", value);
+ ret = gf_asprintf (&data->data, "%f", value);
if (ret == -1) {
gf_log ("dict", GF_LOG_CRITICAL,
"@data - allocation failed by ASPRINTF");
@@ -900,7 +905,7 @@ data_from_uint32 (uint32_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRIu32, value);
+ ret = gf_asprintf (&data->data, "%"PRIu32, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -923,7 +928,7 @@ data_from_uint16 (uint16_t value)
"@data - NULL returned by CALLOC");
return NULL;
}
- ret = asprintf (&data->data, "%"PRIu16, value);
+ ret = gf_asprintf (&data->data, "%"PRIu16, value);
if (-1 == ret) {
gf_log ("dict", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -2513,7 +2518,7 @@ dict_allocate_and_serialize (dict_t *this, char **buf, size_t *length)
goto unlock;
}
- *buf = CALLOC (1, len);
+ *buf = GF_CALLOC (1, len, gf_common_mt_char);
if (*buf == NULL) {
ret = -ENOMEM;
gf_log ("dict", GF_LOG_ERROR, "out of memory");
@@ -2522,7 +2527,7 @@ dict_allocate_and_serialize (dict_t *this, char **buf, size_t *length)
ret = _dict_serialize (this, *buf);
if (ret < 0) {
- FREE (*buf);
+ GF_FREE (*buf);
*buf = NULL;
goto unlock;
}
diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c
index 7bef3c5bd..819357d43 100644
--- a/libglusterfs/src/event.c
+++ b/libglusterfs/src/event.c
@@ -97,19 +97,21 @@ event_pool_new_poll (int count)
struct event_pool *event_pool = NULL;
int ret = -1;
- event_pool = CALLOC (1, sizeof (*event_pool));
+ event_pool = GF_CALLOC (1, sizeof (*event_pool),
+ gf_common_mt_event_pool);
if (!event_pool)
return NULL;
event_pool->count = count;
- event_pool->reg = CALLOC (event_pool->count,
- sizeof (*event_pool->reg));
+ event_pool->reg = GF_CALLOC (event_pool->count,
+ sizeof (*event_pool->reg),
+ gf_common_mt_reg);
if (!event_pool->reg) {
gf_log ("poll", GF_LOG_CRITICAL,
"failed to allocate event registry");
- free (event_pool);
+ GF_FREE (event_pool);
return NULL;
}
@@ -120,8 +122,8 @@ event_pool_new_poll (int count)
if (ret == -1) {
gf_log ("poll", GF_LOG_ERROR,
"pipe creation failed (%s)", strerror (errno));
- free (event_pool->reg);
- free (event_pool);
+ GF_FREE (event_pool->reg);
+ GF_FREE (event_pool);
return NULL;
}
@@ -134,8 +136,8 @@ event_pool_new_poll (int count)
close (event_pool->breaker[1]);
event_pool->breaker[0] = event_pool->breaker[1] = -1;
- free (event_pool->reg);
- free (event_pool);
+ GF_FREE (event_pool->reg);
+ GF_FREE (event_pool);
return NULL;
}
@@ -149,8 +151,8 @@ event_pool_new_poll (int count)
close (event_pool->breaker[1]);
event_pool->breaker[0] = event_pool->breaker[1] = -1;
- free (event_pool->reg);
- free (event_pool);
+ GF_FREE (event_pool->reg);
+ GF_FREE (event_pool);
return NULL;
}
@@ -163,8 +165,8 @@ event_pool_new_poll (int count)
close (event_pool->breaker[1]);
event_pool->breaker[0] = event_pool->breaker[1] = -1;
- free (event_pool->reg);
- free (event_pool);
+ GF_FREE (event_pool->reg);
+ GF_FREE (event_pool);
return NULL;
}
@@ -190,9 +192,9 @@ event_register_poll (struct event_pool *event_pool, int fd,
{
event_pool->count += 256;
- event_pool->reg = realloc (event_pool->reg,
- event_pool->count *
- sizeof (*event_pool->reg));
+ event_pool->reg = GF_REALLOC (event_pool->reg,
+ event_pool->count *
+ sizeof (*event_pool->reg));
}
idx = event_pool->used++;
@@ -392,14 +394,15 @@ event_dispatch_poll_resize (struct event_pool *event_pool,
if (event_pool->used > event_pool->evcache_size) {
if (event_pool->evcache)
- free (event_pool->evcache);
+ GF_FREE (event_pool->evcache);
event_pool->evcache = ufds = NULL;
event_pool->evcache_size = event_pool->used;
- ufds = CALLOC (sizeof (struct pollfd),
- event_pool->evcache_size);
+ ufds = GF_CALLOC (sizeof (struct pollfd),
+ event_pool->evcache_size,
+ gf_common_mt_pollfd);
event_pool->evcache = ufds;
}
@@ -478,19 +481,21 @@ event_pool_new_epoll (int count)
struct event_pool *event_pool = NULL;
int epfd = -1;
- event_pool = CALLOC (1, sizeof (*event_pool));
+ event_pool = GF_CALLOC (1, sizeof (*event_pool),
+ gf_common_mt_event_pool);
if (!event_pool)
return NULL;
event_pool->count = count;
- event_pool->reg = CALLOC (event_pool->count,
- sizeof (*event_pool->reg));
+ event_pool->reg = GF_CALLOC (event_pool->count,
+ sizeof (*event_pool->reg),
+ gf_common_mt_reg);
if (!event_pool->reg) {
gf_log ("epoll", GF_LOG_CRITICAL,
"event registry allocation failed");
- free (event_pool);
+ GF_FREE (event_pool);
return NULL;
}
@@ -499,8 +504,8 @@ event_pool_new_epoll (int count)
if (epfd == -1) {
gf_log ("epoll", GF_LOG_ERROR, "epoll fd creation failed (%s)",
strerror (errno));
- free (event_pool->reg);
- free (event_pool);
+ GF_FREE (event_pool->reg);
+ GF_FREE (event_pool);
return NULL;
}
@@ -536,7 +541,7 @@ event_register_epoll (struct event_pool *event_pool, int fd,
if (event_pool->count == event_pool->used) {
event_pool->count *= 2;
- event_pool->reg = realloc (event_pool->reg,
+ event_pool->reg = GF_REALLOC (event_pool->reg,
event_pool->count *
sizeof (*event_pool->reg));
@@ -832,15 +837,16 @@ event_dispatch_epoll (struct event_pool *event_pool)
if (event_pool->used > event_pool->evcache_size) {
if (event_pool->evcache)
- free (event_pool->evcache);
+ GF_FREE (event_pool->evcache);
event_pool->evcache = events = NULL;
event_pool->evcache_size =
event_pool->used + 256;
- events = CALLOC (event_pool->evcache_size,
- sizeof (struct epoll_event));
+ events = GF_CALLOC (event_pool->evcache_size,
+ sizeof (struct epoll_event),
+ gf_common_mt_epoll_event);
event_pool->evcache = events;
}
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index ee529f356..b01caf765 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -99,7 +99,8 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
oldfds = fdtable->fdentries;
oldmax_fds = fdtable->max_fds;
- fdtable->fdentries = CALLOC (nr, sizeof (fdentry_t));
+ fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t),
+ gf_common_mt_fdentry_t);
ERR_ABORT (fdtable->fdentries);
fdtable->max_fds = nr;
@@ -116,7 +117,7 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
* using the expanded table.
*/
fdtable->first_free = oldmax_fds;
- FREE (oldfds);
+ GF_FREE (oldfds);
return 0;
}
@@ -125,7 +126,7 @@ gf_fd_fdtable_alloc (void)
{
fdtable_t *fdtable = NULL;
- fdtable = CALLOC (1, sizeof (*fdtable));
+ fdtable = GF_CALLOC (1, sizeof (*fdtable), gf_common_mt_fdtable_t);
if (!fdtable)
return NULL;
@@ -150,7 +151,8 @@ __gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
}
fdentries = fdtable->fdentries;
- fdtable->fdentries = calloc (fdtable->max_fds, sizeof (fdentry_t));
+ fdtable->fdentries = GF_CALLOC (fdtable->max_fds, sizeof (fdentry_t),
+ gf_common_mt_fdentry_t);
gf_fd_chain_fd_entries (fdtable->fdentries, 0, fdtable->max_fds);
*count = fdtable->max_fds;
@@ -190,7 +192,7 @@ gf_fd_fdtable_destroy (fdtable_t *fdtable)
pthread_mutex_lock (&fdtable->lock);
{
fdentries = __gf_fd_fdtable_get_all_fds (fdtable, &fd_count);
- FREE (fdtable->fdentries);
+ GF_FREE (fdtable->fdentries);
}
pthread_mutex_unlock (&fdtable->lock);
@@ -202,9 +204,9 @@ gf_fd_fdtable_destroy (fdtable_t *fdtable)
}
}
- FREE (fdentries);
+ GF_FREE (fdentries);
pthread_mutex_destroy (&fdtable->lock);
- FREE (fdtable);
+ GF_FREE (fdtable);
}
}
@@ -425,10 +427,10 @@ fd_destroy (fd_t *fd)
LOCK_DESTROY (&fd->lock);
- FREE (fd->_ctx);
+ GF_FREE (fd->_ctx);
inode_unref (fd->inode);
fd->inode = (inode_t *)0xaaaaaaaa;
- FREE (fd);
+ GF_FREE (fd);
out:
return;
@@ -488,11 +490,12 @@ fd_create (inode_t *inode, pid_t pid)
return NULL;
}
- fd = CALLOC (1, sizeof (fd_t));
+ fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t);
ERR_ABORT (fd);
- fd->_ctx = CALLOC (1, (sizeof (struct _fd_ctx) *
- inode->table->xl->ctx->xl_count));
+ fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) *
+ inode->table->xl->ctx->xl_count),
+ gf_common_mt_fd_ctx);
fd->inode = inode_ref (inode);
fd->pid = pid;
INIT_LIST_HEAD (&fd->inode_list);
diff --git a/libglusterfs/src/gf-dirent.c b/libglusterfs/src/gf-dirent.c
index 4a7220d96..e3c1f1b90 100644
--- a/libglusterfs/src/gf-dirent.c
+++ b/libglusterfs/src/gf-dirent.c
@@ -75,7 +75,8 @@ gf_dirent_for_name (const char *name)
gf_dirent_t *gf_dirent = NULL;
/* TODO: use mem-pool */
- gf_dirent = CALLOC (gf_dirent_size (name), 1);
+ gf_dirent = GF_CALLOC (gf_dirent_size (name), 1,
+ gf_common_mt_gf_dirent_t);
if (!gf_dirent)
return NULL;
@@ -105,7 +106,7 @@ gf_dirent_free (gf_dirent_t *entries)
list_for_each_entry_safe (entry, tmp, &entries->list, list) {
list_del (&entry->list);
- FREE (entry);
+ GF_FREE (entry);
}
}
@@ -165,7 +166,7 @@ gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size)
}
entry_len = sizeof (gf_dirent_t) + entry_strlen + 1;
- entry = CALLOC (1, entry_len);
+ entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t);
if (!entry) {
break;
}
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c
index cdb561de1..9677a169e 100644
--- a/libglusterfs/src/globals.c
+++ b/libglusterfs/src/globals.c
@@ -27,6 +27,7 @@
#include "globals.h"
#include "glusterfs.h"
#include "xlator.h"
+#include "mem-pool.h"
/* CTX */
@@ -221,6 +222,9 @@ glusterfs_globals_init ()
ret = glusterfs_central_log_flag_init ();
if (ret)
goto out;
+
+ gf_mem_acct_enable_set ();
+
out:
return ret;
}
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index 6e5d82fec..622857c1a 100644
--- a/libglusterfs/src/inode.c
+++ b/libglusterfs/src/inode.c
@@ -138,14 +138,14 @@ __dentry_unset (dentry_t *dentry)
list_del_init (&dentry->inode_list);
if (dentry->name)
- FREE (dentry->name);
+ GF_FREE (dentry->name);
if (dentry->parent) {
__inode_unref (dentry->parent);
dentry->parent = NULL;
}
- FREE (dentry);
+ GF_FREE (dentry);
}
@@ -292,11 +292,11 @@ __inode_destroy (inode_t *inode)
}
}
- FREE (inode->_ctx);
+ GF_FREE (inode->_ctx);
noctx:
LOCK_DESTROY (&inode->lock);
// memset (inode, 0xb, sizeof (*inode));
- FREE (inode);
+ GF_FREE (inode);
}
@@ -424,7 +424,8 @@ __dentry_create (inode_t *inode, inode_t *parent, const char *name)
{
dentry_t *newd = NULL;
- newd = (void *) CALLOC (1, sizeof (*newd));
+ newd = (void *) GF_CALLOC (1, sizeof (*newd),
+ gf_common_mt_dentry_t);
if (newd == NULL) {
gf_log ("inode", GF_LOG_ERROR, "out of memory");
goto out;
@@ -433,10 +434,10 @@ __dentry_create (inode_t *inode, inode_t *parent, const char *name)
INIT_LIST_HEAD (&newd->inode_list);
INIT_LIST_HEAD (&newd->hash);
- newd->name = strdup (name);
+ newd->name = gf_strdup (name);
if (newd->name == NULL) {
gf_log ("inode", GF_LOG_ERROR, "out of memory");
- FREE (newd);
+ GF_FREE (newd);
newd = NULL;
goto out;
}
@@ -457,7 +458,7 @@ __inode_create (inode_table_t *table)
{
inode_t *newi = NULL;
- newi = (void *) CALLOC (1, sizeof (*newi));
+ newi = (void *) GF_CALLOC (1, sizeof (*newi), gf_common_mt_inode_t);
if (!newi) {
gf_log ("inode", GF_LOG_ERROR, "out of memory");
goto out;
@@ -472,12 +473,13 @@ __inode_create (inode_table_t *table)
INIT_LIST_HEAD (&newi->hash);
INIT_LIST_HEAD (&newi->dentry_list);
- newi->_ctx = CALLOC (1, (sizeof (struct _inode_ctx) *
- table->xl->ctx->xl_count));
+ newi->_ctx = GF_CALLOC (1, (sizeof (struct _inode_ctx) *
+ table->xl->ctx->xl_count),
+ gf_common_mt_inode_ctx);
if (newi->_ctx == NULL) {
gf_log ("inode", GF_LOG_ERROR, "out of memory");
LOCK_DESTROY (&newi->lock);
- FREE (newi);
+ GF_FREE (newi);
newi = NULL;
goto out;
}
@@ -486,6 +488,7 @@ __inode_create (inode_table_t *table)
table->lru_size++;
out:
+
return newi;
}
@@ -936,7 +939,7 @@ inode_path (inode_t *inode, const char *name, char **bufp)
ret = i;
size = i + 1;
- buf = CALLOC (size, sizeof (char));
+ buf = GF_CALLOC (size, sizeof (char), gf_common_mt_char);
if (buf) {
buf[size - 1] = 0;
@@ -968,9 +971,9 @@ unlock:
if (inode->ino == 1 && !name) {
ret = 1;
if (buf) {
- FREE (buf);
+ GF_FREE (buf);
}
- buf = CALLOC (ret + 1, sizeof (char));
+ buf = GF_CALLOC (ret + 1, sizeof (char), gf_common_mt_char);
if (buf) {
strcpy (buf, "/");
*bufp = buf;
@@ -1049,7 +1052,7 @@ inode_table_new (size_t lru_limit, xlator_t *xl)
int ret = 0;
int i = 0;
- new = (void *)calloc (1, sizeof (*new));
+ new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t);
if (!new)
return NULL;
@@ -1059,18 +1062,20 @@ inode_table_new (size_t lru_limit, xlator_t *xl)
new->hashsize = 14057; /* TODO: Random Number?? */
- new->inode_hash = (void *)calloc (new->hashsize,
- sizeof (struct list_head));
+ new->inode_hash = (void *)GF_CALLOC (new->hashsize,
+ sizeof (struct list_head),
+ gf_common_mt_list_head);
if (!new->inode_hash) {
- FREE (new);
+ GF_FREE (new);
return NULL;
}
- new->name_hash = (void *)calloc (new->hashsize,
- sizeof (struct list_head));
+ new->name_hash = (void *)GF_CALLOC (new->hashsize,
+ sizeof (struct list_head),
+ gf_common_mt_list_head);
if (!new->name_hash) {
- FREE (new->inode_hash);
- FREE (new);
+ GF_FREE (new->inode_hash);
+ GF_FREE (new);
return NULL;
}
@@ -1088,7 +1093,7 @@ inode_table_new (size_t lru_limit, xlator_t *xl)
INIT_LIST_HEAD (&new->purge);
INIT_LIST_HEAD (&new->attic);
- ret = asprintf (&new->name, "%s/inode", xl->name);
+ ret = gf_asprintf (&new->name, "%s/inode", xl->name);
if (-1 == ret) {
/* TODO: This should be ok to continue, check with avati */
;
@@ -1114,7 +1119,7 @@ inode_from_path (inode_table_t *itable, const char *path)
char *strtokptr = NULL;
/* top-down approach */
- pathname = strdup (path);
+ pathname = gf_strdup (path);
if (pathname == NULL) {
gf_log ("inode", GF_LOG_ERROR, "out of memory");
goto out;
@@ -1153,7 +1158,7 @@ inode_from_path (inode_table_t *itable, const char *path)
inode_unref (parent);
if (pathname)
- free (pathname);
+ GF_FREE (pathname);
out:
return inode;
diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c
index 227b46fe8..e39976945 100644
--- a/libglusterfs/src/iobuf.c
+++ b/libglusterfs/src/iobuf.c
@@ -41,7 +41,8 @@ __iobuf_arena_init_iobufs (struct iobuf_arena *iobuf_arena)
page_size = iobuf_arena->iobuf_pool->page_size;
iobuf_cnt = arena_size / page_size;
- iobuf_arena->iobufs = CALLOC (sizeof (*iobuf), iobuf_cnt);
+ iobuf_arena->iobufs = GF_CALLOC (sizeof (*iobuf), iobuf_cnt,
+ gf_common_mt_iobuf);
if (!iobuf_arena->iobufs)
return;
@@ -87,7 +88,7 @@ __iobuf_arena_destroy_iobufs (struct iobuf_arena *iobuf_arena)
iobuf++;
}
- FREE (iobuf_arena->iobufs);
+ GF_FREE (iobuf_arena->iobufs);
}
@@ -107,7 +108,7 @@ __iobuf_arena_destroy (struct iobuf_arena *iobuf_arena)
&& iobuf_arena->mem_base != MAP_FAILED)
munmap (iobuf_arena->mem_base, iobuf_pool->arena_size);
- FREE (iobuf_arena);
+ GF_FREE (iobuf_arena);
}
@@ -117,7 +118,8 @@ __iobuf_arena_alloc (struct iobuf_pool *iobuf_pool)
struct iobuf_arena *iobuf_arena = NULL;
size_t arena_size = 0;
- iobuf_arena = CALLOC (sizeof (*iobuf_arena), 1);
+ iobuf_arena = GF_CALLOC (sizeof (*iobuf_arena), 1,
+ gf_common_mt_iobuf_arena);
if (!iobuf_arena)
goto err;
@@ -224,7 +226,8 @@ iobuf_pool_new (size_t arena_size, size_t page_size)
if (arena_size < page_size)
return NULL;
- iobuf_pool = CALLOC (sizeof (*iobuf_pool), 1);
+ iobuf_pool = GF_CALLOC (sizeof (*iobuf_pool), 1,
+ gf_common_mt_iobuf_pool);
if (!iobuf_pool)
return NULL;
@@ -463,7 +466,8 @@ iobref_new ()
{
struct iobref *iobref = NULL;
- iobref = CALLOC (sizeof (*iobref), 1);
+ iobref = GF_CALLOC (sizeof (*iobref), 1,
+ gf_common_mt_iobref);
if (!iobref)
return NULL;
@@ -508,7 +512,7 @@ iobref_destroy (struct iobref *iobref)
iobuf_unref (iobuf);
}
- FREE (iobref);
+ GF_FREE (iobref);
}
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index a006184cc..a8a7d4dc9 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -84,7 +84,7 @@ gf_log_init (const char *file)
pthread_mutex_init (&logfile_mutex, NULL);
- filename = strdup (file);
+ filename = gf_strdup (file);
if (!filename) {
fprintf (stderr, "gf_log_init: strdup error\n");
return -1;
@@ -153,11 +153,11 @@ __get_dummy_xlator (glusterfs_ctx_t *ctx, const char *remote_host,
xlator_list_t * parent = NULL;
xlator_list_t * tmp = NULL;
- top = CALLOC (1, sizeof (*top));
+ top = GF_CALLOC (1, sizeof (*top), gf_common_mt_xlator_t);
if (!top)
goto out;
- trans = CALLOC (1, sizeof (*trans));
+ trans = GF_CALLOC (1, sizeof (*trans), gf_common_mt_xlator_t);
if (!trans)
goto out;
@@ -169,7 +169,8 @@ __get_dummy_xlator (glusterfs_ctx_t *ctx, const char *remote_host,
top->next = trans;
top->init = dummy_init;
top->notify = gf_log_notify;
- top->children = (void *) CALLOC (1, sizeof (*top->children));
+ top->children = (void *) GF_CALLOC (1, sizeof (*top->children),
+ gf_common_mt_xlator_list_t);
if (!top->children)
goto out;
@@ -183,7 +184,7 @@ __get_dummy_xlator (glusterfs_ctx_t *ctx, const char *remote_host,
trans->notify = default_notify;
trans->options = get_new_dict ();
- parent = CALLOC (1, sizeof(*parent));
+ parent = GF_CALLOC (1, sizeof(*parent), gf_common_mt_xlator_list_t);
if (!parent)
goto out;
@@ -219,7 +220,8 @@ __get_dummy_xlator (glusterfs_ctx_t *ctx, const char *remote_host,
ret = dict_set_static_ptr (trans->options, "non-blocking-io", "off");
if (transport) {
- char *transport_type = CALLOC (1, strlen (transport) + 10);
+ char *transport_type = GF_CALLOC (1, strlen (transport) + 10,
+ gf_common_mt_char);
ERR_ABORT (transport_type);
strcpy(transport_type, transport);
@@ -293,7 +295,7 @@ gf_log_central_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
msg = (struct _log_msg *) cookie;
- FREE (msg->msg);
+ GF_FREE ((char *)(msg->msg));
STACK_DESTROY (frame->root);
@@ -375,14 +377,14 @@ gf_log_central (const char *msg)
{
struct _log_msg *lm = NULL;
- lm = CALLOC (1, sizeof (*lm));
+ lm = GF_CALLOC (1, sizeof (*lm), gf_common_mt_log_msg);
if (!lm)
goto out;
INIT_LIST_HEAD (&lm->queue);
- lm->msg = strdup (msg);
+ lm->msg = gf_strdup (msg);
pthread_mutex_lock (&msg_queue_mutex);
{
@@ -491,10 +493,10 @@ log:
else
basename = file;
- ret = asprintf (&str1, "[%s] %s [%s:%d:%s] %s: ",
- timestr, level_strings[level],
- basename, line, function,
- domain);
+ ret = gf_asprintf (&str1, "[%s] %s [%s:%d:%s] %s: ",
+ timestr, level_strings[level],
+ basename, line, function,
+ domain);
if (-1 == ret) {
goto unlock;
}
@@ -507,7 +509,7 @@ log:
va_end (ap);
len = strlen (str1);
- msg = malloc (len + strlen (str2) + 1);
+ msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char);
strcpy (msg, str1);
strcpy (msg + len, str2);
@@ -528,11 +530,11 @@ unlock:
}
glusterfs_central_log_flag_unset ();
}
- FREE (msg);
+ GF_FREE (msg);
}
if (str1)
- FREE (str1);
+ GF_FREE (str1);
if (str2)
FREE (str2);
@@ -559,12 +561,12 @@ client_log_init (struct _client_log *cl, char *identifier)
cl->identifier = identifier;
- ret = asprintf (&path, "%s.client-%s", filename, identifier);
+ ret = gf_asprintf (&path, "%s.client-%s", filename, identifier);
if (-1 == ret) {
return;
}
cl->file = fopen (path, "a");
- FREE (path);
+ GF_FREE (path);
INIT_LIST_HEAD (&cl->list);
}
@@ -576,7 +578,8 @@ __logfile_for_client (char *identifier)
struct _client_log *client = NULL;
if (!client_logs) {
- client = CALLOC (1, sizeof (*client));
+ client = GF_CALLOC (1, sizeof (*client),
+ gf_common_mt_client_log);
client_log_init (client, identifier);
client_logs = client;
@@ -588,7 +591,8 @@ __logfile_for_client (char *identifier)
}
if (!client) {
- client = CALLOC (1, sizeof (*client));
+ client = GF_CALLOC (1, sizeof (*client),
+ gf_common_mt_client_log);
client_log_init (client, identifier);
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index b0e8391f0..f1a2c98de 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -19,13 +19,278 @@
#include "mem-pool.h"
#include "logging.h"
+#include "xlator.h"
#include <stdlib.h>
+#include <stdarg.h>
#define GF_MEM_POOL_PAD_BOUNDARY (sizeof(struct list_head))
#define mem_pool_chunkhead2ptr(head) ((head) + GF_MEM_POOL_PAD_BOUNDARY)
#define mem_pool_ptr2chunkhead(ptr) ((ptr) - GF_MEM_POOL_PAD_BOUNDARY)
+#define GF_MEM_HEADER_SIZE (4 + sizeof (size_t) + sizeof (xlator_t *) + 4)
+#define GF_MEM_TRAILER_SIZE 4
+
+#define GF_MEM_HEADER_MAGIC 0xCAFEBABE
+#define GF_MEM_TRAILER_MAGIC 0xBAADF00D
+
+#define GLUSTERFS_ENV_MEM_ACCT_STR "GLUSTERFS_DISABLE_MEM_ACCT"
+
+static int gf_mem_acct_enable = 1;
+
+int
+gf_mem_acct_is_enabled ()
+{
+ return gf_mem_acct_enable;
+}
+
+void
+gf_mem_acct_enable_set ()
+{
+ char *opt = NULL;
+ long val = -1;
+
+ opt = getenv (GLUSTERFS_ENV_MEM_ACCT_STR);
+
+ if (!opt)
+ return;
+
+ val = strtol (opt, NULL, 0);
+
+ if (val)
+ gf_mem_acct_enable = 0;
+ else
+ gf_mem_acct_enable = 1;
+
+}
+
+void
+gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr,
+ size_t size, uint32_t type)
+{
+
+ char *ptr = NULL;
+
+ if (!alloc_ptr)
+ return;
+
+ ptr = (char *) (*alloc_ptr);
+
+ if (!xl) {
+ assert (0);
+ }
+
+ if (!(xl->mem_acct.rec)) {
+ assert (0);
+ }
+
+ if (type > xl->mem_acct.num_types) {
+ assert (0);
+ }
+
+ LOCK(&xl->mem_acct.rec[type].lock);
+ {
+ xl->mem_acct.rec[type].size += size;
+ xl->mem_acct.rec[type].num_allocs++;
+ xl->mem_acct.rec[type].max_size =
+ max (xl->mem_acct.rec[type].max_size,
+ xl->mem_acct.rec[type].size);
+ xl->mem_acct.rec[type].max_num_allocs =
+ max (xl->mem_acct.rec[type].max_num_allocs,
+ xl->mem_acct.rec[type].num_allocs);
+ }
+ UNLOCK(&xl->mem_acct.rec[type].lock);
+
+ *(uint32_t *)(ptr) = type;
+ ptr = ptr + 4;
+ memcpy (ptr, &size, sizeof(size_t));
+ ptr += sizeof (size_t);
+ memcpy (ptr, &xl, sizeof(xlator_t *));
+ ptr += sizeof (xlator_t *);
+ *(uint32_t *)(ptr) = GF_MEM_HEADER_MAGIC;
+ ptr = ptr + 4;
+ *(uint32_t *) (ptr + size) = GF_MEM_TRAILER_MAGIC;
+
+ *alloc_ptr = (void *)ptr;
+ return;
+}
+
+
+void *
+__gf_calloc (size_t nmemb, size_t size, uint32_t type)
+{
+ size_t tot_size = 0;
+ size_t req_size = 0;
+ char *ptr = NULL;
+ xlator_t *xl = NULL;
+
+ if (!gf_mem_acct_enable)
+ return CALLOC (nmemb, size);
+
+ xl = THIS;
+
+ req_size = nmemb * size;
+ tot_size = req_size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
+
+ ptr = calloc (1, tot_size);
+
+ if (!ptr)
+ return NULL;
+
+ gf_mem_set_acct_info (xl, &ptr, req_size, type);
+
+ return (void *)ptr;
+}
+
+void *
+__gf_malloc (size_t size, uint32_t type)
+{
+ size_t tot_size = 0;
+ char *ptr = NULL;
+ xlator_t *xl = NULL;
+
+ if (!gf_mem_acct_enable)
+ return MALLOC (size);
+
+ xl = THIS;
+
+ tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
+
+ ptr = malloc (tot_size);
+ if (!ptr)
+ return NULL;
+
+ gf_mem_set_acct_info (xl, &ptr, size, type);
+
+ return (void *)ptr;
+}
+
+void *
+__gf_realloc (void *ptr, size_t size)
+{
+ size_t tot_size = 0;
+ char *orig_ptr = NULL;
+ xlator_t *xl = NULL;
+ uint32_t type = 0;
+
+
+ tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
+
+ orig_ptr = (char *)ptr - 4;
+
+ assert (*(uint32_t *)orig_ptr == GF_MEM_HEADER_MAGIC);
+
+ orig_ptr = orig_ptr - sizeof(xlator_t *);
+ xl = *((xlator_t **)orig_ptr);
+
+ orig_ptr = (char *)ptr - GF_MEM_HEADER_SIZE;
+ type = *(uint32_t *)orig_ptr;
+
+ ptr = realloc (orig_ptr, tot_size);
+ if (!ptr)
+ return NULL;
+
+ gf_mem_set_acct_info (xl, (char **)&ptr, size, type);
+
+ return (void *)ptr;
+}
+
+int
+gf_asprintf (char **string_ptr, const char *format, ...)
+{
+ va_list arg;
+ char *str = NULL;
+ int size = 0;
+ int rv = 0;
+
+ if (!string_ptr || !format)
+ return -1;
+
+ va_start (arg, format);
+ size = vsnprintf (NULL, 0, format, arg);
+ size++;
+ va_start (arg, format);
+ str = GF_MALLOC (size, gf_common_mt_asprintf);
+ if (str == NULL) {
+ va_end (arg);
+ /*
+ * Strictly speaking, GNU asprintf doesn't do this,
+ * but the caller isn't checking the return value.
+ */
+ gf_log ("libglusterfs", GF_LOG_CRITICAL,
+ "failed to allocate memory");
+ return -1;
+ }
+ rv = vsnprintf( str, size, format, arg);
+ va_end (arg);
+
+ *string_ptr = str;
+ return (rv);
+}
+
+void
+__gf_free (void *free_ptr)
+{
+ size_t req_size = 0;
+ char *ptr = NULL;
+ uint32_t type = 0;
+ xlator_t *xl = NULL;
+
+ if (!gf_mem_acct_enable) {
+ FREE (free_ptr);
+ return;
+ }
+
+ if (!free_ptr)
+ return;
+
+
+ ptr = (char *)free_ptr - 4;
+
+ if (GF_MEM_HEADER_MAGIC != *(uint32_t *)ptr) {
+ //Possible corruption, assert here
+ assert (0);
+ }
+
+ *(uint32_t *)ptr = 0;
+
+ ptr = ptr - sizeof(xlator_t *);
+ memcpy (&xl, ptr, sizeof(xlator_t *));
+
+ if (!xl) {
+ //gf_free expects xl to be available
+ assert (0);
+ }
+
+ if (!xl->mem_acct.rec) {
+ ptr = (char *)free_ptr - GF_MEM_HEADER_SIZE;
+ goto free;
+ }
+
+
+ ptr = ptr - sizeof(size_t);
+ memcpy (&req_size, ptr, sizeof (size_t));
+ ptr = ptr - 4;
+ type = *(uint32_t *)ptr;
+
+ if (GF_MEM_TRAILER_MAGIC != *(uint32_t *)
+ ((char *)free_ptr + req_size)) {
+ // This points to a memory overrun
+ assert (0);
+ }
+ *(uint32_t *) ((char *)free_ptr + req_size) = 0;
+
+ LOCK (&xl->mem_acct.rec[type].lock);
+ {
+ xl->mem_acct.rec[type].size -= req_size;
+ xl->mem_acct.rec[type].num_allocs--;
+ }
+ UNLOCK (&xl->mem_acct.rec[type].lock);
+free:
+ FREE (ptr);
+}
+
+
struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type,
@@ -36,14 +301,14 @@ mem_pool_new_fn (unsigned long sizeof_type,
void *pool = NULL;
int i = 0;
struct list_head *list = NULL;
-
+
if (!sizeof_type || !count) {
gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
return NULL;
}
padded_sizeof_type = sizeof_type + GF_MEM_POOL_PAD_BOUNDARY;
-
- mem_pool = CALLOC (sizeof (*mem_pool), 1);
+
+ mem_pool = GF_CALLOC (sizeof (*mem_pool), 1, gf_common_mt_mem_pool);
if (!mem_pool)
return NULL;
@@ -54,9 +319,9 @@ mem_pool_new_fn (unsigned long sizeof_type,
mem_pool->cold_count = count;
mem_pool->real_sizeof_type = sizeof_type;
- pool = CALLOC (count, padded_sizeof_type);
+ pool = GF_CALLOC (count, padded_sizeof_type, gf_common_mt_long);
if (!pool) {
- FREE (mem_pool);
+ GF_FREE (mem_pool);
return NULL;
}
@@ -78,7 +343,7 @@ mem_get (struct mem_pool *mem_pool)
{
struct list_head *list = NULL;
void *ptr = NULL;
-
+
if (!mem_pool) {
gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
return NULL;
@@ -141,7 +406,7 @@ __is_member (struct mem_pool *pool, void *ptr)
gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
return -1;
}
-
+
if (ptr < pool->pool || ptr >= pool->pool_end)
return 0;
@@ -157,12 +422,12 @@ void
mem_put (struct mem_pool *pool, void *ptr)
{
struct list_head *list = NULL;
-
+
if (!pool || !ptr) {
gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
return;
}
-
+
LOCK (&pool->lock);
{
@@ -210,8 +475,8 @@ mem_pool_destroy (struct mem_pool *pool)
return;
LOCK_DESTROY (&pool->lock);
- FREE (pool->pool);
- FREE (pool);
+ GF_FREE (pool->pool);
+ GF_FREE (pool);
return;
}
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index 9b8efbb95..2a064643c 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -22,7 +22,10 @@
#include "list.h"
#include "locking.h"
+#include "mem-types.h"
#include <stdlib.h>
+#include <inttypes.h>
+#include <string.h>
#define MALLOC(size) malloc(size)
@@ -34,6 +37,65 @@
ptr = (void *)0xeeeeeeee; \
}
+struct mem_acct {
+ uint32_t num_types;
+ struct mem_acct_rec *rec;
+};
+
+struct mem_acct_rec {
+ size_t size;
+ size_t max_size;
+ uint32_t num_allocs;
+ uint32_t max_num_allocs;
+ gf_lock_t lock;
+};
+
+
+void *
+__gf_calloc (size_t cnt, size_t size, uint32_t type);
+
+void *
+__gf_malloc (size_t size, uint32_t type);
+
+void *
+__gf_realloc (void *ptr, size_t size);
+
+int
+gf_asprintf (char **string_ptr, const char *format, ...);
+
+#define GF_CALLOC(nmemb, size, type) __gf_calloc (nmemb, size, type)
+
+#define GF_MALLOC(size, type) __gf_malloc (size, type)
+
+#define GF_REALLOC(ptr, size) __gf_realloc (ptr, size)
+
+void
+__gf_free (void *ptr);
+
+
+#define GF_FREE(free_ptr) __gf_free (free_ptr);
+
+static inline
+char * gf_strdup (const char *src)
+{
+
+ char *dup_str = NULL;
+ size_t len = 0;
+
+ len = strlen (src) + 1;
+
+ dup_str = GF_CALLOC(1, len, gf_common_mt_strdup);
+
+ if (!dup_str)
+ return NULL;
+
+ memcpy (dup_str, src, len);
+
+ return dup_str;
+}
+
+
+
struct mem_pool {
struct list_head list;
int hot_count;
@@ -55,4 +117,7 @@ void *mem_get (struct mem_pool *pool);
void mem_pool_destroy (struct mem_pool *pool);
+int gf_mem_acct_is_enabled ();
+void gf_mem_acct_enable_set ();
+
#endif /* _MEM_POOL_H */
diff --git a/libglusterfs/src/mem-types.h b/libglusterfs/src/mem-types.h
new file mode 100644
index 000000000..daf680eb2
--- /dev/null
+++ b/libglusterfs/src/mem-types.h
@@ -0,0 +1,82 @@
+/*
+ Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __MEM_TYPES_H__
+#define __MEM_TYPES_H__
+
+
+enum gf_common_mem_types_ {
+ gf_common_mt_call_stub_t = 0,
+ gf_common_mt_dnscache6,
+ gf_common_mt_data_pair_t,
+ gf_common_mt_data_t,
+ gf_common_mt_dict_t,
+ gf_common_mt_event_pool,
+ gf_common_mt_reg,
+ gf_common_mt_pollfd,
+ gf_common_mt_epoll_event,
+ gf_common_mt_fdentry_t,
+ gf_common_mt_fdtable_t,
+ gf_common_mt_fd_t,
+ gf_common_mt_fd_ctx,
+ gf_common_mt_gf_dirent_t,
+ gf_common_mt_glusterfs_ctx_t,
+ gf_common_mt_dentry_t,
+ gf_common_mt_inode_t,
+ gf_common_mt_inode_ctx,
+ gf_common_mt_list_head,
+ gf_common_mt_inode_table_t,
+ gf_common_mt_xlator_t,
+ gf_common_mt_xlator_list_t,
+ gf_common_mt_log_msg,
+ gf_common_mt_client_log,
+ gf_common_mt_volume_opt_list_t,
+ gf_common_mt_gf_hdr_common_t,
+ gf_common_mt_call_frame_t,
+ gf_common_mt_call_stack_t,
+ gf_common_mt_gf_timer_t,
+ gf_common_mt_gf_timer_registry_t,
+ gf_common_mt_transport,
+ gf_common_mt_transport_msg,
+ gf_common_mt_auth_handle_t,
+ gf_common_mt_iobuf,
+ gf_common_mt_iobuf_arena,
+ gf_common_mt_iobref,
+ gf_common_mt_iobuf_pool,
+ gf_common_mt_iovec,
+ gf_common_mt_memdup,
+ gf_common_mt_asprintf,
+ gf_common_mt_strdup,
+ gf_common_mt_socket_private_t,
+ gf_common_mt_ioq,
+ gf_common_mt_transport_t,
+ gf_common_mt_socket_local_t,
+ gf_common_mt_char,
+ gf_common_mt_rbthash_table_t,
+ gf_common_mt_rbthash_bucket,
+ gf_common_mt_mem_pool,
+ gf_common_mt_long,
+ gf_common_mt_rpcsvc_auth_list,
+ gf_common_mt_rpcsvc_t,
+ gf_common_mt_rpcsvc_conn_t,
+ gf_common_mt_rpcsvc_program_t,
+ gf_common_mt_rpcsvc_stage_t,
+ gf_common_mt_end
+};
+#endif
diff --git a/libglusterfs/src/protocol.h b/libglusterfs/src/protocol.h
index 592d0a4f4..6e8a13067 100644
--- a/libglusterfs/src/protocol.h
+++ b/libglusterfs/src/protocol.h
@@ -999,7 +999,8 @@ __gf_hdr_new (int size)
gf_hdr_common_t *hdr = NULL;
/* TODO: use mem-pool */
- hdr = CALLOC (sizeof (gf_hdr_common_t) + size, 1);
+ hdr = GF_CALLOC (sizeof (gf_hdr_common_t) + size, 1,
+ gf_common_mt_gf_hdr_common_t);
if (!hdr) {
return NULL;
diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c
index 33e80224a..b5e684def 100644
--- a/libglusterfs/src/rbthash.c
+++ b/libglusterfs/src/rbthash.c
@@ -116,11 +116,13 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc,
}
- newtab = CALLOC (1, sizeof (*newtab));
+ newtab = GF_CALLOC (1, sizeof (*newtab),
+ gf_common_mt_rbthash_table_t);
if (!newtab)
return NULL;
- newtab->buckets = CALLOC (buckets, sizeof (struct rbthash_bucket));
+ newtab->buckets = GF_CALLOC (buckets, sizeof (struct rbthash_bucket),
+ gf_common_mt_rbthash_bucket);
if (!newtab->buckets) {
gf_log (GF_RBTHASH, GF_LOG_ERROR, "Failed to allocate memory");
goto free_newtab;
@@ -157,11 +159,11 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc,
free_buckets:
if (ret == -1)
- FREE (newtab->buckets);
+ GF_FREE (newtab->buckets);
free_newtab:
if (ret == -1) {
- FREE (newtab);
+ GF_FREE (newtab);
newtab = NULL;
}
@@ -185,7 +187,7 @@ rbthash_init_entry (rbthash_table_t *tbl, void *data, void *key, int keylen)
}
entry->data = data;
- entry->key = CALLOC (keylen, sizeof (char));
+ entry->key = GF_CALLOC (keylen, sizeof (char), gf_common_mt_char);
if (!entry->key) {
gf_log (GF_RBTHASH, GF_LOG_ERROR, "Memory allocation failed");
goto free_entry;
@@ -216,7 +218,7 @@ rbthash_deinit_entry (rbthash_table_t *tbl, rbthash_entry_t *entry)
return;
if (entry->key)
- FREE (entry->key);
+ GF_FREE (entry->key);
if (tbl) {
if ((entry->data) && (tbl->dfunc))
@@ -374,7 +376,7 @@ rbthash_remove (rbthash_table_t *tbl, void *key, int keylen)
if (!entry)
return NULL;
- FREE (entry->key);
+ GF_FREE (entry->key);
dataref = entry->data;
mem_put (tbl->entrypool, entry);
@@ -418,7 +420,7 @@ rbthash_table_destroy (rbthash_table_t *tbl)
if (tbl->pool_alloced)
mem_pool_destroy (tbl->entrypool);
- FREE (tbl->buckets);
- FREE (tbl);
+ GF_FREE (tbl->buckets);
+ GF_FREE (tbl);
}
diff --git a/libglusterfs/src/scheduler.c b/libglusterfs/src/scheduler.c
index 459c7d868..94131676e 100644
--- a/libglusterfs/src/scheduler.c
+++ b/libglusterfs/src/scheduler.c
@@ -43,7 +43,7 @@ get_scheduler (xlator_t *xl, const char *name)
return NULL;
}
- ret = asprintf (&sched_file, "%s/%s.so", SCHEDULERDIR, name);
+ ret = gf_asprintf (&sched_file, "%s/%s.so", SCHEDULERDIR, name);
if (-1 == ret) {
gf_log ("scheduler", GF_LOG_ERROR, "asprintf failed");
return NULL;
@@ -66,7 +66,8 @@ get_scheduler (xlator_t *xl, const char *name)
return NULL;
}
- vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
+ vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
+ gf_common_mt_volume_opt_list_t);
vol_opt->given_opt = dlsym (handle, "options");
if (vol_opt->given_opt == NULL) {
gf_log ("scheduler", GF_LOG_DEBUG,
@@ -80,6 +81,7 @@ get_scheduler (xlator_t *xl, const char *name)
return NULL;
}
}
+ GF_FREE(sched_file);
return tmp_sched;
}
diff --git a/libglusterfs/src/scheduler.h b/libglusterfs/src/scheduler.h
index 814df9090..3e4acaadd 100644
--- a/libglusterfs/src/scheduler.h
+++ b/libglusterfs/src/scheduler.h
@@ -33,6 +33,7 @@ struct sched_ops {
void (*update) (xlator_t *this);
xlator_t *(*schedule) (xlator_t *this, const void *path);
void (*notify) (xlator_t *xl, int32_t event, void *data);
+ int32_t (*mem_acct_init) (xlator_t *this);
};
extern struct sched_ops *get_scheduler (xlator_t *xl, const char *name);
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h
index 25925f7a6..645f633f5 100644
--- a/libglusterfs/src/stack.h
+++ b/libglusterfs/src/stack.h
@@ -137,9 +137,9 @@ FRAME_DESTROY (call_frame_t *frame)
if (frame->prev)
frame->prev->next = frame->next;
if (frame->local)
- FREE (frame->local);
+ GF_FREE (frame->local);
LOCK_DESTROY (&frame->lock);
- FREE (frame);
+ GF_FREE (frame);
}
@@ -161,7 +161,7 @@ STACK_DESTROY (call_stack_t *stack)
UNLOCK (&stack->pool->lock);
if (stack->frames.local)
- FREE (stack->frames.local);
+ GF_FREE (stack->frames.local);
LOCK_DESTROY (&stack->frames.lock);
@@ -172,7 +172,7 @@ STACK_DESTROY (call_stack_t *stack)
FRAME_DESTROY (stack->frames.next);
}
- FREE (stack);
+ GF_FREE (stack);
}
@@ -185,7 +185,8 @@ STACK_DESTROY (call_stack_t *stack)
call_frame_t *_new = NULL; \
xlator_t *old_THIS = NULL; \
\
- _new = CALLOC (1, sizeof (call_frame_t)); \
+ _new = GF_CALLOC (1, sizeof (call_frame_t), \
+ gf_common_mt_call_frame_t); \
ERR_ABORT (_new); \
typeof(fn##_cbk) tmp_cbk = rfn; \
_new->root = frame->root; \
@@ -219,7 +220,8 @@ STACK_DESTROY (call_stack_t *stack)
call_frame_t *_new = NULL; \
xlator_t *old_THIS = NULL; \
\
- _new = CALLOC (1, sizeof (call_frame_t)); \
+ _new = GF_CALLOC (1, sizeof (call_frame_t), \
+ gf_common_mt_call_frame_t); \
ERR_ABORT (_new); \
typeof(fn##_cbk) tmp_cbk = rfn; \
_new->root = frame->root; \
@@ -304,7 +306,8 @@ copy_frame (call_frame_t *frame)
return NULL;
}
- newstack = (void *) CALLOC (1, sizeof (*newstack));
+ newstack = (void *) GF_CALLOC (1, sizeof (*newstack),
+ gf_common_mt_call_stack_t);
if (newstack == NULL) {
return NULL;
}
@@ -347,7 +350,7 @@ create_frame (xlator_t *xl, call_pool_t *pool)
return NULL;
}
- stack = CALLOC (1, sizeof (*stack));
+ stack = GF_CALLOC (1, sizeof (*stack),gf_common_mt_call_stack_t);
if (!stack)
return NULL;
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
index 4e4228006..678ed6c8e 100644
--- a/libglusterfs/src/statedump.c
+++ b/libglusterfs/src/statedump.c
@@ -28,6 +28,8 @@
#include <malloc.h>
#endif /* MALLOC_H */
+extern xlator_t global_xlator;
+
static pthread_mutex_t gf_proc_dump_mutex;
static int gf_dump_fd = -1;
@@ -115,6 +117,46 @@ gf_proc_dump_write (char *key, char *value,...)
ret = write(gf_dump_fd, buf, strlen(buf));
}
+static void
+gf_proc_dump_xlator_mem_info (xlator_t *xl)
+{
+ char key[GF_DUMP_MAX_BUF_LEN];
+ char prefix[GF_DUMP_MAX_BUF_LEN];
+ int i = 0;
+ struct mem_acct rec = {0,};
+
+ if (!xl)
+ return;
+
+ if (!xl->mem_acct.rec)
+ return;
+
+ gf_proc_dump_add_section("%s.%s - Memory usage", xl->type,xl->name);
+ gf_proc_dump_write("num_types", "%d", xl->mem_acct.num_types);
+
+ for (i = 0; i < xl->mem_acct.num_types; i++) {
+ if (!(memcmp (&xl->mem_acct.rec[i], &rec,
+ sizeof(struct mem_acct))))
+ continue;
+
+ gf_proc_dump_add_section("%s.%s - usage-type %d", xl->type,
+ xl->name,i);
+ gf_proc_dump_build_key(prefix, "memusage", "%s.%s.type.%d",
+ xl->type, xl->name, i);
+ gf_proc_dump_build_key(key, prefix, "size");
+ gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].size);
+ gf_proc_dump_build_key(key, prefix, "num_allocs");
+ gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].num_allocs);
+ gf_proc_dump_build_key(key, prefix, "max_size");
+ gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].max_size);
+ gf_proc_dump_build_key(key, prefix, "max_num_allocs");
+ gf_proc_dump_write(key, "%u", xl->mem_acct.rec[i].max_num_allocs);
+ }
+
+ return;
+}
+
+
/* Currently this dumps only mallinfo. More can be built on here */
void
@@ -138,6 +180,7 @@ gf_proc_dump_mem_info ()
gf_proc_dump_write("mallinfo_fordblks", "%d", info.fordblks);
gf_proc_dump_write("mallinfo_keepcost", "%d", info.keepcost);
#endif
+ gf_proc_dump_xlator_mem_info(&global_xlator);
}
@@ -151,7 +194,9 @@ gf_proc_dump_xlator_info (xlator_t *this_xl)
return;
while (this_xl) {
+
gf_proc_dump_latency_info (this_xl);
+ gf_proc_dump_xlator_mem_info(this_xl);
if (!this_xl->dumpops) {
this_xl = this_xl->next;
diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c
index 6188ccacb..7ff18f94e 100644
--- a/libglusterfs/src/timer.c
+++ b/libglusterfs/src/timer.c
@@ -25,13 +25,14 @@
#include "timer.h"
#include "logging.h"
#include "common-utils.h"
+#include "globals.h"
#define TS(tv) ((((unsigned long long) tv.tv_sec) * 1000000) + (tv.tv_usec))
gf_timer_t *
gf_timer_call_after (glusterfs_ctx_t *ctx,
struct timeval delta,
- gf_timer_cbk_t cbk,
+ gf_timer_cbk_t callbk,
void *data)
{
gf_timer_registry_t *reg = NULL;
@@ -52,7 +53,7 @@ gf_timer_call_after (glusterfs_ctx_t *ctx,
return NULL;
}
- event = CALLOC (1, sizeof (*event));
+ event = GF_CALLOC (1, sizeof (*event), gf_common_mt_gf_timer_t);
if (!event) {
gf_log ("timer", GF_LOG_CRITICAL, "Not enough memory");
return NULL;
@@ -62,8 +63,9 @@ gf_timer_call_after (glusterfs_ctx_t *ctx,
event->at.tv_sec += ((event->at.tv_usec + delta.tv_usec) / 1000000);
event->at.tv_sec += delta.tv_sec;
at = TS (event->at);
- event->cbk = cbk;
+ event->callbk = callbk;
event->data = data;
+ event->xl = THIS;
pthread_mutex_lock (&reg->lock);
{
trav = reg->active.prev;
@@ -126,7 +128,7 @@ gf_timer_call_cancel (glusterfs_ctx_t *ctx,
}
pthread_mutex_unlock (&reg->lock);
- FREE (event);
+ GF_FREE (event);
return 0;
}
@@ -168,8 +170,10 @@ gf_timer_proc (void *ctx)
}
}
pthread_mutex_unlock (&reg->lock);
+ if (event->xl)
+ THIS = event->xl;
if (need_cbk)
- event->cbk (event->data);
+ event->callbk (event->data);
else
break;
@@ -189,7 +193,7 @@ gf_timer_proc (void *ctx)
}
pthread_mutex_unlock (&reg->lock);
pthread_mutex_destroy (&reg->lock);
- FREE (((glusterfs_ctx_t *)ctx)->timer);
+ GF_FREE (((glusterfs_ctx_t *)ctx)->timer);
return NULL;
}
@@ -206,7 +210,8 @@ gf_timer_registry_init (glusterfs_ctx_t *ctx)
if (!ctx->timer) {
gf_timer_registry_t *reg = NULL;
- ctx->timer = reg = CALLOC (1, sizeof (*reg));
+ ctx->timer = reg = GF_CALLOC (1, sizeof (*reg),
+ gf_common_mt_gf_timer_registry_t);
ERR_ABORT (reg);
pthread_mutex_init (&reg->lock, NULL);
reg->active.next = &reg->active;
diff --git a/libglusterfs/src/timer.h b/libglusterfs/src/timer.h
index 98440dc61..e5fa5e2c6 100644
--- a/libglusterfs/src/timer.h
+++ b/libglusterfs/src/timer.h
@@ -26,6 +26,7 @@
#endif
#include "glusterfs.h"
+#include "xlator.h"
#include <sys/time.h>
#include <pthread.h>
@@ -34,8 +35,9 @@ typedef void (*gf_timer_cbk_t) (void *);
struct _gf_timer {
struct _gf_timer *next, *prev;
struct timeval at;
- gf_timer_cbk_t cbk;
+ gf_timer_cbk_t callbk;
void *data;
+ xlator_t *xl;
};
struct _gf_timer_registry {
diff --git a/libglusterfs/src/transport.c b/libglusterfs/src/transport.c
index aee809117..d460d0209 100644
--- a/libglusterfs/src/transport.c
+++ b/libglusterfs/src/transport.c
@@ -52,7 +52,8 @@ transport_load (dict_t *options,
GF_VALIDATE_OR_GOTO("transport", options, fail);
GF_VALIDATE_OR_GOTO("transport", xl, fail);
- trans = CALLOC (1, sizeof (struct transport));
+ trans = GF_CALLOC (1, sizeof (struct transport),
+ gf_common_mt_transport);
GF_VALIDATE_OR_GOTO("transport", trans, fail);
trans->xl = xl;
@@ -107,14 +108,14 @@ transport_load (dict_t *options,
ret = dict_get_str (options, "transport-type", &type);
if (ret < 0) {
- FREE (trans);
+ GF_FREE (trans);
gf_log ("transport", GF_LOG_ERROR,
"'option transport-type <xx>' missing in volume '%s'",
xl->name);
goto fail;
}
- ret = asprintf (&name, "%s/%s.so", TRANSPORTDIR, type);
+ ret = gf_asprintf (&name, "%s/%s.so", TRANSPORTDIR, type);
if (-1 == ret) {
gf_log ("transport", GF_LOG_ERROR, "asprintf failed");
goto fail;
@@ -129,17 +130,17 @@ transport_load (dict_t *options,
"volume '%s': transport-type '%s' is not valid or "
"not found on this machine",
xl->name, type);
- FREE (name);
- FREE (trans);
+ GF_FREE (name);
+ GF_FREE (trans);
goto fail;
}
- FREE (name);
+ GF_FREE (name);
trans->ops = dlsym (handle, "tops");
if (trans->ops == NULL) {
gf_log ("transport", GF_LOG_ERROR,
"dlsym (transport_ops) on %s", dlerror ());
- FREE (trans);
+ GF_FREE (trans);
goto fail;
}
@@ -147,7 +148,7 @@ transport_load (dict_t *options,
if (trans->init == NULL) {
gf_log ("transport", GF_LOG_ERROR,
"dlsym (gf_transport_init) on %s", dlerror ());
- FREE (trans);
+ GF_FREE (trans);
goto fail;
}
@@ -155,11 +156,12 @@ transport_load (dict_t *options,
if (trans->fini == NULL) {
gf_log ("transport", GF_LOG_ERROR,
"dlsym (gf_transport_fini) on %s", dlerror ());
- FREE (trans);
+ GF_FREE (trans);
goto fail;
}
- vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
+ vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
+ gf_common_mt_volume_opt_list_t);
vol_opt->given_opt = dlsym (handle, "options");
if (vol_opt->given_opt == NULL) {
gf_log ("transport", GF_LOG_DEBUG,
@@ -171,7 +173,7 @@ transport_load (dict_t *options,
vol_opt->given_opt)) {
gf_log ("transport", GF_LOG_ERROR,
"volume option validation failed");
- FREE (trans);
+ GF_FREE (trans);
goto fail;
}
}
@@ -180,7 +182,7 @@ transport_load (dict_t *options,
if (ret != 0) {
gf_log ("transport", GF_LOG_ERROR,
"'%s' initialization failed", type);
- FREE (trans);
+ GF_FREE (trans);
goto fail;
}
@@ -204,7 +206,8 @@ transport_submit (transport_t *this, char *buf, int32_t len,
if (this->peer_trans) {
peer_trans = this->peer_trans;
- msg = CALLOC (1, sizeof (*msg));
+ msg = GF_CALLOC (1, sizeof (*msg),
+ gf_common_mt_transport_msg);
if (!msg) {
return -ENOMEM;
}
@@ -215,8 +218,8 @@ transport_submit (transport_t *this, char *buf, int32_t len,
if (vector) {
iobuf = iobuf_get (this->xl->ctx->iobuf_pool);
if (!iobuf) {
- FREE (msg->hdr);
- FREE (msg);
+ GF_FREE (msg->hdr);
+ GF_FREE (msg);
return -ENOMEM;
}
@@ -293,7 +296,7 @@ transport_destroy (transport_t *this)
this->fini (this);
pthread_mutex_destroy (&this->lock);
- FREE (this);
+ GF_FREE (this);
fail:
return ret;
}
@@ -391,7 +394,7 @@ transport_peerproc (void *trans_data)
xlator_notify (trans->xl, GF_EVENT_POLLIN, trans);
- FREE (msg);
+ GF_FREE (msg);
}
}
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index ffa1d94e4..6d27a0140 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -106,6 +106,9 @@ fill_defaults (xlator_t *xl)
if (!xl->notify)
xl->notify = default_notify;
+ if (!xl->mem_acct_init)
+ xl->mem_acct_init = default_mem_acct_init;
+
return;
}
@@ -146,7 +149,8 @@ valid_ipv4_address (char *address, int length)
char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
char ret = 1;
- prev = tmp = strdup (address);
+ tmp = gf_strdup (address);
+ prev = tmp;
prev = strtok_r (tmp, ".", &ptr);
while (prev != NULL)
@@ -166,7 +170,7 @@ valid_ipv4_address (char *address, int length)
}
out:
- FREE (tmp);
+ GF_FREE (tmp);
return ret;
}
@@ -178,7 +182,7 @@ valid_ipv6_address (char *address, int length)
char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
char ret = 1;
- tmp = strdup (address);
+ tmp = gf_strdup (address);
prev = strtok_r (tmp, ":", &ptr);
while (prev != NULL)
@@ -199,7 +203,7 @@ valid_ipv6_address (char *address, int length)
}
out:
- FREE (tmp);
+ GF_FREE (tmp);
return ret;
}
@@ -650,7 +654,7 @@ validate_xlator_volume_options (xlator_t *xl, volume_option_t *opt)
" with correction",
trav->key[i], trav->key[0]);
/* TODO: some bytes lost */
- pairs->key = strdup (trav->key[0]);
+ pairs->key = gf_strdup (trav->key[0]);
}
break;
}
@@ -684,9 +688,9 @@ xlator_set_type (xlator_t *xl,
return -1;
}
- xl->type = strdup (type);
+ xl->type = gf_strdup (type);
- ret = asprintf (&name, "%s/%s.so", XLATORDIR, type);
+ ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, type);
if (-1 == ret) {
gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
return -1;
@@ -740,9 +744,16 @@ xlator_set_type (xlator_t *xl,
"dlsym(dumpops) on %s -- neglecting", dlerror ());
}
+ if (!(xl->mem_acct_init = dlsym (handle, "mem_acct_init"))) {
+ gf_log (xl->name, GF_LOG_DEBUG,
+ "dlsym(mem_acct_init) on %s -- neglecting",
+ dlerror ());
+ }
+
INIT_LIST_HEAD (&xl->volume_options);
- vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
+ vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
+ gf_common_mt_volume_opt_list_t);
if (!(vol_opt->given_opt = dlsym (handle, "options"))) {
dlerror ();
@@ -753,7 +764,7 @@ xlator_set_type (xlator_t *xl,
fill_defaults (xl);
- FREE (name);
+ GF_FREE (name);
return 0;
}
@@ -825,6 +836,8 @@ xlator_init_rec (xlator_t *xl)
while (trav) {
ret = -1;
+ if (trav->mem_acct_init)
+ trav->mem_acct_init (trav);
if (trav->init && !trav->ready) {
ret = xlator_init (trav);
if (ret) {
@@ -940,6 +953,39 @@ xlator_init (xlator_t *xl)
return ret;
}
+int
+xlator_mem_acct_init (xlator_t *xl, int num_types)
+{
+ int i = 0;
+ int ret = 0;
+
+ if (!gf_mem_acct_is_enabled())
+ return 0;
+
+ if (!xl)
+ return -1;
+
+ xl->mem_acct.num_types = num_types;
+
+ xl->mem_acct.rec = calloc(num_types, sizeof(struct mem_acct_rec));
+
+ if (!xl->mem_acct.rec) {
+ gf_log("xlator", GF_LOG_ERROR, "Out of Memory");
+ return -1;
+ }
+
+ gf_log(xl->name, GF_LOG_DEBUG, "Allocated mem_acct_rec for %d types",
+ num_types);
+
+ for (i = 0; i < num_types; i++) {
+ ret = LOCK_INIT(&(xl->mem_acct.rec[i].lock));
+ if (ret) {
+ fprintf(stderr, "Unable to lock..errno : %d",errno);
+ }
+ }
+
+ return 0;
+}
void
xlator_tree_fini (xlator_t *xl)
@@ -969,9 +1015,9 @@ xlator_tree_free (xlator_t *tree)
while (prev) {
trav = prev->next;
dict_destroy (prev->options);
- FREE (prev->name);
- FREE (prev->type);
- FREE (prev);
+ GF_FREE (prev->name);
+ GF_FREE (prev->type);
+ GF_FREE (prev);
prev = trav;
}
@@ -987,7 +1033,7 @@ loc_wipe (loc_t *loc)
loc->inode = NULL;
}
if (loc->path) {
- FREE (loc->path);
+ GF_FREE ((char *)loc->path);
loc->path = NULL;
}
@@ -1011,7 +1057,7 @@ loc_copy (loc_t *dst, loc_t *src)
if (src->parent)
dst->parent = inode_ref (src->parent);
- dst->path = strdup (src->path);
+ dst->path = gf_strdup (src->path);
if (!dst->path)
goto out;
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 993679b25..3bee959f8 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -846,6 +846,7 @@ struct _xlator {
void (*fini) (xlator_t *this);
int32_t (*init) (xlator_t *this);
+ int32_t (*mem_acct_init) (xlator_t *this);
event_notify_fn_t notify;
/* for latency measurement */
@@ -857,6 +858,7 @@ struct _xlator {
char ready;
char init_succeeded;
void *private;
+ struct mem_acct mem_acct;
};
#define xlator_has_parent(xl) (xl->parents != NULL)
@@ -888,6 +890,7 @@ void inode_destroy_notify (inode_t *inode, const char *xlname);
int loc_copy (loc_t *dst, loc_t *src);
#define loc_dup(src, dst) loc_copy(dst, src)
void loc_wipe (loc_t *loc);
+int xlator_mem_acct_init (xlator_t *xl, int num_types);
#define GF_STAT_PRINT_FMT_STR "%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32"\n"