summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-04-22 13:33:09 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-04-23 06:32:52 -0700
commit582de0677da4be19fc6f873625c58c45d069ab1c (patch)
treef10cb3e26e1f92f6ea91034e6f7bb925790dd9bc /xlators/storage
parent72baa17282f5cf749fa743fd601c7b728ece4fa2 (diff)
Memory accounting changes
Memory accounting Changes. Thanks to Vinayak Hegde and Csaba Henk for their contributions. Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 329 (Replacing memory allocation functions with mem-type functions) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=329
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/bdb/src/bctx.c14
-rw-r--r--xlators/storage/bdb/src/bdb-ll.c48
-rw-r--r--xlators/storage/bdb/src/bdb-mem-types.h42
-rw-r--r--xlators/storage/bdb/src/bdb.c95
-rw-r--r--xlators/storage/posix/src/posix-mem-types.h36
-rw-r--r--xlators/storage/posix/src/posix.c140
-rw-r--r--xlators/storage/posix/src/posix.h2
7 files changed, 256 insertions, 121 deletions
diff --git a/xlators/storage/bdb/src/bctx.c b/xlators/storage/bdb/src/bctx.c
index 361ce75fe..150d709a2 100644
--- a/xlators/storage/bdb/src/bctx.c
+++ b/xlators/storage/bdb/src/bctx.c
@@ -25,12 +25,12 @@ static void
__destroy_bctx (bctx_t *bctx)
{
if (bctx->directory)
- FREE (bctx->directory);
+ GF_FREE (bctx->directory);
if (bctx->db_path)
- FREE (bctx->db_path);
+ GF_FREE (bctx->db_path);
- FREE (bctx);
+ GF_FREE (bctx);
}
static void
@@ -236,16 +236,16 @@ __create_bctx (bctx_table_t *table,
bctx_t *bctx = NULL;
char *db_path = NULL;
- bctx = CALLOC (1, sizeof (*bctx));
+ bctx = GF_CALLOC (1, sizeof (*bctx), gf_bdb_mt_bctx_t);
GF_VALIDATE_OR_GOTO ("bctx", bctx, out);
bctx->table = table;
- bctx->directory = strdup (path);
+ bctx->directory = gf_strdup (path);
GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out);
MAKE_REAL_PATH_TO_STORAGE_DB (db_path, BDB_THIS (table), path);
- bctx->db_path = strdup (db_path);
+ bctx->db_path = gf_strdup (db_path);
GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out);
INIT_LIST_HEAD (&bctx->c_list);
@@ -327,7 +327,7 @@ bctx_parent (bctx_table_t *table,
GF_VALIDATE_OR_GOTO ("bctx", table, out);
GF_VALIDATE_OR_GOTO ("bctx", path, out);
- pathname = strdup (path);
+ pathname = gf_strdup (path);
GF_VALIDATE_OR_GOTO ("bctx", pathname, out);
directory = dirname (pathname);
diff --git a/xlators/storage/bdb/src/bdb-ll.c b/xlators/storage/bdb/src/bdb-ll.c
index 290b29710..dcf18c0a7 100644
--- a/xlators/storage/bdb/src/bdb-ll.c
+++ b/xlators/storage/bdb/src/bdb-ll.c
@@ -57,7 +57,7 @@ bdb_generate_secondary_hash (DB *secondary,
primary = pkey->data;
- hash = calloc (1, sizeof (uint32_t));
+ hash = GF_CALLOC (1, sizeof (uint32_t), gf_bdb_mt_uint32_t);
*hash = gf_dm_hashfn (primary, pkey->size);
@@ -316,9 +316,10 @@ bdb_cache_insert (bctx_t *bctx,
list_del_init (&bcache->c_list);
}
if (bcache->key) {
- free (bcache->key);
- bcache->key = calloc (key->size + 1,
- sizeof (char));
+ GF_FREE (bcache->key);
+ bcache->key = GF_CALLOC (key->size + 1,
+ sizeof (char),
+ gf_bdb_mt_char);
GF_VALIDATE_OR_GOTO ("bdb-ll",
bcache->key, unlock);
memcpy (bcache->key, (char *)key->data,
@@ -331,7 +332,7 @@ bdb_cache_insert (bctx_t *bctx,
bctx->directory, (char *)key->data);
} /* if(bcache->key)...else */
if (bcache->data) {
- free (bcache->data);
+ GF_FREE (bcache->data);
bcache->data = memdup (data->data, data->size);
GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->data,
unlock);
@@ -347,10 +348,12 @@ bdb_cache_insert (bctx_t *bctx,
ret = 0;
} else {
/* we will be entering here very rarely */
- bcache = CALLOC (1, sizeof (*bcache));
+ bcache = GF_CALLOC (1, sizeof (*bcache),
+ gf_bdb_mt_bdb_cache_t);
GF_VALIDATE_OR_GOTO ("bdb-ll", bcache, unlock);
- bcache->key = calloc (key->size + 1, sizeof (char));
+ bcache->key = GF_CALLOC (key->size + 1, sizeof (char),
+ gf_bdb_mt_char);
GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->key, unlock);
memcpy (bcache->key, key->data, key->size);
@@ -391,9 +394,9 @@ bdb_cache_delete (bctx_t *bctx,
if (bcache) {
list_del_init (&bcache->c_list);
- free (bcache->key);
- free (bcache->data);
- free (bcache);
+ GF_FREE (bcache->key);
+ GF_FREE (bcache->data);
+ GF_FREE (bcache);
}
}
UNLOCK (&bctx->lock);
@@ -578,7 +581,7 @@ bdb_db_get (bctx_t *bctx,
}
if (size == 0)
- free (value.data);
+ GF_FREE (value.data);
need_break = 1;
} else {
@@ -615,7 +618,7 @@ bdb_db_iread (struct bdb_ctx *bctx, const char *key, char **bufp)
size = ret;
if (bufp) {
- buf = calloc (size, sizeof (char));
+ buf = GF_CALLOC (size, sizeof (char), gf_bdb_mt_char);
*bufp = buf;
ret = bdb_db_get (bctx, NULL, key, buf, size, 0);
}
@@ -1309,7 +1312,7 @@ bdb_db_init (xlator_t *this,
private->dir_mode = private->dir_mode | S_IFDIR;
- table = CALLOC (1, sizeof (*table));
+ table = GF_CALLOC (1, sizeof (*table), gf_bdb_mt_bctx_table_t);
if (table == NULL) {
gf_log ("bdb-ll", GF_LOG_CRITICAL,
"memory allocation for 'storage/bdb' internal "
@@ -1376,8 +1379,9 @@ bdb_db_init (xlator_t *this,
}
table->hash_size = BDB_DEFAULT_HASH_SIZE;
- table->b_hash = CALLOC (BDB_DEFAULT_HASH_SIZE,
- sizeof (struct list_head));
+ table->b_hash = GF_CALLOC (BDB_DEFAULT_HASH_SIZE,
+ sizeof (struct list_head),
+ gf_bdb_mt_list_head);
for (idx = 0; idx < table->hash_size; idx++)
INIT_LIST_HEAD(&(table->b_hash[idx]));
@@ -1386,7 +1390,7 @@ bdb_db_init (xlator_t *this,
ret = dict_get_str (options, "errfile", &errfile);
if (ret == 0) {
- private->errfile = strdup (errfile);
+ private->errfile = gf_strdup (errfile);
gf_log (this->name, GF_LOG_DEBUG,
"using %s as error logging file for libdb (Berkeley DB "
"library) internal logging.", private->errfile);
@@ -1402,10 +1406,10 @@ bdb_db_init (xlator_t *this,
"using the database environment home "
"directory (%s) itself as transaction log "
"directory", directory);
- private->logdir = strdup (directory);
+ private->logdir = gf_strdup (directory);
} else {
- private->logdir = strdup (logdir);
+ private->logdir = gf_strdup (logdir);
op_ret = stat (private->logdir, &stbuf);
if ((op_ret != 0)
@@ -1445,15 +1449,15 @@ bdb_db_init (xlator_t *this,
return op_ret;
err:
if (table) {
- FREE (table->b_hash);
- FREE (table);
+ GF_FREE (table->b_hash);
+ GF_FREE (table);
}
if (private) {
if (private->errfile)
- FREE (private->errfile);
+ GF_FREE (private->errfile);
if (private->logdir)
- FREE (private->logdir);
+ GF_FREE (private->logdir);
}
return -1;
diff --git a/xlators/storage/bdb/src/bdb-mem-types.h b/xlators/storage/bdb/src/bdb-mem-types.h
new file mode 100644
index 000000000..cfbc4a4e1
--- /dev/null
+++ b/xlators/storage/bdb/src/bdb-mem-types.h
@@ -0,0 +1,42 @@
+/*
+ Copyright (c) 2008-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 __POSIX_MEM_TYPES_H__
+#define __POSIX_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_bdb_mem_types_ {
+ gf_bdb_mt_bctx_t = gf_common_mt_end + 1,
+ gf_bdb_mt_bdb_fd,
+ gf_bdb_mt_dir_entry_t,
+ gf_bdb_mt_char,
+ gf_bdb_mt_dir_entry_t,
+ gf_bdb_mt_char,
+ gf_bdb_mt_bdb_private,
+ gf_bdb_mt_uint32_t,
+ gf_bdb_mt_char,
+ gf_bdb_mt_bdb_cache_t,
+ gf_bdb_mt_char,
+ gf_bdb_mt_bctx_table_t,
+ gf_bdb_mt_list_head,
+ gf_bdb_mt_end,
+};
+#endif
diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c
index 68e5227a1..fba34ee04 100644
--- a/xlators/storage/bdb/src/bdb.c
+++ b/xlators/storage/bdb/src/bdb.c
@@ -320,7 +320,7 @@ bdb_create (call_frame_t *frame,
}
/* create successful */
- bfd = CALLOC (1, sizeof (*bfd));
+ bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd);
if (bfd == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"CREATE %"PRId64"/%s (%s): ENOMEM"
@@ -333,7 +333,7 @@ bdb_create (call_frame_t *frame,
/* NOTE: bdb_get_bctx_from () returns bctx with a ref */
bfd->ctx = bctx;
- bfd->key = strdup (key_string);
+ bfd->key = gf_strdup (key_string);
if (bfd->key == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"CREATE %"PRId64" (%s): ENOMEM"
@@ -399,7 +399,7 @@ bdb_open (call_frame_t *frame,
goto out;
}
- bfd = CALLOC (1, sizeof (*bfd));
+ bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd);
if (bfd == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"OPEN %"PRId64" (%s): ENOMEM"
@@ -414,7 +414,7 @@ bdb_open (call_frame_t *frame,
bfd->ctx = bctx;
MAKE_KEY_FROM_PATH (key_string, loc->path);
- bfd->key = strdup (key_string);
+ bfd->key = gf_strdup (key_string);
if (bfd->key == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"OPEN %"PRId64" (%s): ENOMEM"
@@ -686,8 +686,8 @@ bdb_release (xlator_t *this,
bfd->ctx = NULL;
if (bfd->key)
- FREE (bfd->key); /* we did strdup() in bdb_open() */
- FREE (bfd);
+ GF_FREE (bfd->key); /* we did strdup() in bdb_open() */
+ GF_FREE (bfd);
op_ret = 0;
op_errno = 0;
@@ -793,7 +793,7 @@ bdb_lookup (call_frame_t *frame,
MAKE_REAL_PATH (real_path, this, loc->path);
- pathname = strdup (loc->path);
+ pathname = gf_strdup (loc->path);
GF_VALIDATE_OR_GOTO (this->name, pathname, out);
directory = dirname (pathname);
@@ -932,11 +932,11 @@ bdb_lookup (call_frame_t *frame,
file_content, entry_size);
if (op_ret < 0) {
/* continue without giving file contents */
- FREE (file_content);
+ GF_FREE (file_content);
}
} else {
if (file_content)
- FREE (file_content);
+ GF_FREE (file_content);
}
if (loc->ino) {
@@ -966,7 +966,7 @@ out:
}
if (pathname)
- free (pathname);
+ GF_FREE (pathname);
if (xattr)
dict_ref (xattr);
@@ -1102,7 +1102,7 @@ bdb_opendir (call_frame_t *frame,
goto out;
}
- bfd = CALLOC (1, sizeof (*bfd));
+ bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd);
if (bfd == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"OPENDIR %"PRId64" (%s): ENOMEM"
@@ -1126,7 +1126,7 @@ bdb_opendir (call_frame_t *frame,
/* NOTE: bctx_lookup() return bctx with ref */
bfd->ctx = bctx;
- bfd->path = strdup (real_path);
+ bfd->path = gf_strdup (real_path);
if (bfd == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"OPENDIR %"PRId64" (%s): ENOMEM"
@@ -1149,7 +1149,7 @@ err:
if (bfd->dir)
closedir (bfd->dir);
- FREE (bfd);
+ GF_FREE (bfd);
}
return 0;
@@ -1264,7 +1264,8 @@ bdb_getdents (call_frame_t *frame,
continue;
}/* if(key.data)...else */
- this_entry = CALLOC (1, sizeof (*this_entry));
+ this_entry = GF_CALLOC (1, sizeof (*this_entry),
+ gf_bdb_mt_dir_entry_t);
if (this_entry == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64
@@ -1276,7 +1277,8 @@ bdb_getdents (call_frame_t *frame,
goto out;
}
- this_entry->name = CALLOC (pri.size + 1, sizeof (char));
+ this_entry->name = GF_CALLOC (pri.size + 1, sizeof (char),
+ gf_bdb_mt_char);
if (this_entry->name == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64
@@ -1308,10 +1310,10 @@ bdb_getdents (call_frame_t *frame,
/* if size is 0, count can never be = size,
* so entire dir is read */
if (sec.data)
- FREE (sec.data);
+ GF_FREE (sec.data);
if (pri.data)
- FREE (pri.data);
+ GF_FREE (pri.data);
if (count == size)
break;
@@ -1377,7 +1379,8 @@ dir_read:
continue;
}
- this_entry = CALLOC (1, sizeof (*this_entry));
+ this_entry = GF_CALLOC (1, sizeof (*this_entry),
+ gf_bdb_mt_dir_entry_t);
if (this_entry == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64
@@ -1389,7 +1392,7 @@ dir_read:
goto out;
}
- this_entry->name = strdup (dirent->d_name);
+ this_entry->name = gf_strdup (dirent->d_name);
if (this_entry->name == NULL) {
gf_log (this->name, GF_LOG_DEBUG,
"GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64
@@ -1410,7 +1413,7 @@ dir_read:
ret = readlink (entry_path, linkpath, ZR_PATH_MAX);
if (ret != -1) {
linkpath[ret] = '\0';
- this_entry->link = strdup (linkpath);
+ this_entry->link = gf_strdup (linkpath);
}
} else {
this_entry->link = "";
@@ -1441,8 +1444,8 @@ out:
while (entries.next) {
this_entry = entries.next;
entries.next = entries.next->next;
- FREE (this_entry->name);
- FREE (this_entry);
+ GF_FREE (this_entry->name);
+ GF_FREE (this_entry);
}
return 0;
@@ -1468,7 +1471,7 @@ bdb_releasedir (xlator_t *this,
}
if (bfd->path) {
- free (bfd->path);
+ GF_FREE (bfd->path);
} else {
gf_log (this->name, GF_LOG_DEBUG,
"RELEASEDIR %"PRId64": (bfd->path is NULL)",
@@ -1491,7 +1494,7 @@ bdb_releasedir (xlator_t *this,
fd->inode->ino);
}
- free (bfd);
+ GF_FREE (bfd);
out:
return 0;
@@ -2395,7 +2398,7 @@ bdb_getxattr (call_frame_t *frame,
if (op_ret == -1)
break;
- value = CALLOC (op_ret + 1, sizeof(char));
+ value = GF_CALLOC (op_ret + 1, sizeof(char), gf_bdb_mt_char);
GF_VALIDATE_OR_GOTO (this->name, value, out);
op_ret = sys_lgetxattr (real_path, key, value,
@@ -2406,7 +2409,7 @@ bdb_getxattr (call_frame_t *frame,
op_ret = dict_set_dynptr (dict, key,
value, op_ret);
if (op_ret < 0) {
- FREE (value);
+ GF_FREE (value);
gf_log (this->name, GF_LOG_DEBUG,
"GETXATTR %"PRId64" (%s) - %s: "
"(skipping key %s)",
@@ -2619,7 +2622,7 @@ bdb_setdents (call_frame_t *frame,
real_path_len = strlen (bfd->path);
entry_path_len = real_path_len + 256;
- entry_path = CALLOC (1, entry_path_len);
+ entry_path = GF_CALLOC (1, entry_path_len, gf_bdb_mt_char);
GF_VALIDATE_OR_GOTO (this->name, entry_path, out);
strcpy (entry_path, bfd->path);
@@ -2710,7 +2713,7 @@ bdb_setdents (call_frame_t *frame,
out:
STACK_UNWIND (frame, op_ret, op_errno);
- FREE (entry_path);
+ GF_FREE (entry_path);
return 0;
}
@@ -2892,11 +2895,11 @@ bdb_readdir (call_frame_t *frame,
this_entry->d_len = pri.size + 1;
if (sec.data) {
- FREE (sec.data);
+ GF_FREE (sec.data);
}
if (pri.data)
- FREE (pri.data);
+ GF_FREE (pri.data);
list_add_tail (&this_entry->list, &entries.list);
@@ -3189,7 +3192,7 @@ bdb_checksum (call_frame_t *frame,
for (idx = 0; idx < length; idx++)
file_checksum[idx] ^= data[idx];
- FREE (key.data);
+ GF_FREE (key.data);
} else {
gf_log (this->name, GF_LOG_DEBUG,
"CHECKSUM %"PRId64" (%s)",
@@ -3240,6 +3243,24 @@ notify (xlator_t *this,
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_bdb_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
/**
* init -
@@ -3273,7 +3294,7 @@ init (xlator_t *this)
goto err;
}
- _private = CALLOC (1, sizeof (*_private));
+ _private = GF_CALLOC (1, sizeof (*_private), gf_bdb_mt_bdb_private);
if (_private == NULL) {
gf_log (this->name, GF_LOG_ERROR,
"could not allocate memory for 'storage/bdb' "
@@ -3317,7 +3338,7 @@ init (xlator_t *this)
}
- _private->export_path = strdup (directory);
+ _private->export_path = gf_strdup (directory);
if (_private->export_path == NULL) {
gf_log (this->name, GF_LOG_ERROR,
"could not allocate memory for 'storage/bdb' "
@@ -3367,9 +3388,9 @@ init (xlator_t *this)
err:
if (_private) {
if (_private->export_path)
- FREE (_private->export_path);
+ GF_FREE (_private->export_path);
- FREE (_private);
+ GF_FREE (_private);
}
out:
return ret;
@@ -3444,9 +3465,9 @@ fini (xlator_t *this)
/* impossible to reach here */
}
- FREE (B_TABLE(this));
+ GF_FREE (B_TABLE(this));
}
- FREE (private);
+ GF_FREE (private);
return;
}
diff --git a/xlators/storage/posix/src/posix-mem-types.h b/xlators/storage/posix/src/posix-mem-types.h
new file mode 100644
index 000000000..6687560cf
--- /dev/null
+++ b/xlators/storage/posix/src/posix-mem-types.h
@@ -0,0 +1,36 @@
+/*
+ Copyright (c) 2008-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 __POSIX_MEM_TYPES_H__
+#define __POSIX_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_posix_mem_types_ {
+ gf_posix_mt_dir_entry_t = gf_common_mt_end + 1,
+ gf_posix_mt_posix_fd,
+ gf_posix_mt_char,
+ gf_posix_mt_posix_private,
+ gf_posix_mt_int32_t,
+ gf_posix_mt_posix_dev_t,
+ gf_posix_mt_trash_path,
+ gf_posix_mt_end
+};
+#endif
+
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 832b437b5..5ed3e5dc6 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -126,7 +126,8 @@ _posix_xattr_get_set (dict_t *xattr_req,
goto err;
}
- databuf = calloc (1, filler->stbuf->ia_size);
+ databuf = GF_CALLOC (1, filler->stbuf->ia_size,
+ gf_posix_mt_char);
if (!databuf) {
gf_log (filler->this->name, GF_LOG_ERROR,
@@ -163,7 +164,7 @@ _posix_xattr_get_set (dict_t *xattr_req,
if (_fd != -1)
close (_fd);
if (databuf)
- FREE (databuf);
+ GF_FREE (databuf);
}
} else if (!strcmp (key, GLUSTERFS_OPEN_FD_COUNT)) {
loc = filler->loc;
@@ -176,7 +177,8 @@ _posix_xattr_get_set (dict_t *xattr_req,
xattr_size = sys_lgetxattr (filler->real_path, key, NULL, 0);
if (xattr_size > 0) {
- value = calloc (1, xattr_size + 1);
+ value = GF_CALLOC (1, xattr_size + 1,
+ gf_posix_mt_char);
sys_lgetxattr (filler->real_path, key, value,
xattr_size);
@@ -422,7 +424,7 @@ setgid_override (xlator_t *this, char *real_path, gid_t *gid)
int op_ret = 0;
- tmp_path = strdup (real_path);
+ tmp_path = gf_strdup (real_path);
if (!tmp_path) {
op_ret = -ENOMEM;
gf_log ("[storage/posix]", GF_LOG_ERROR,
@@ -453,7 +455,7 @@ setgid_override (xlator_t *this, char *real_path, gid_t *gid)
out:
if (tmp_path)
- FREE (tmp_path);
+ GF_FREE (tmp_path);
return op_ret;
}
@@ -504,7 +506,7 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
parent:
if (loc->parent) {
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -522,7 +524,7 @@ parent:
op_ret = entry_ret;
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
if (xattr)
dict_ref (xattr);
@@ -915,7 +917,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
goto out;
}
- pfd = CALLOC (1, sizeof (*fd));
+ pfd = GF_CALLOC (1, sizeof (*fd), gf_posix_mt_posix_fd);
if (!pfd) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -925,7 +927,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
pfd->dir = dir;
pfd->fd = dirfd (dir);
- pfd->path = strdup (real_path);
+ pfd->path = gf_strdup (real_path);
if (!pfd->path) {
gf_log (this->name, GF_LOG_ERROR,
"Out of memory.");
@@ -944,8 +946,8 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
}
if (pfd) {
if (pfd->path)
- FREE (pfd->path);
- FREE (pfd);
+ GF_FREE (pfd->path);
+ GF_FREE (pfd);
pfd = NULL;
}
}
@@ -1101,7 +1103,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
goto out;
SET_FS_ID (frame->root->uid, gid);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -1168,7 +1170,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
@@ -1289,9 +1291,9 @@ posix_janitor_thread_proc (void *data)
}
if (pfd->path)
- FREE (pfd->path);
+ GF_FREE (pfd->path);
- FREE (pfd);
+ GF_FREE (pfd);
}
}
@@ -1367,7 +1369,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
goto out;
SET_FS_ID (frame->root->uid, gid);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -1423,7 +1425,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
@@ -1461,7 +1463,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
MAKE_REAL_PATH (real_path, this, loc->path);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -1512,7 +1514,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
@@ -1547,7 +1549,7 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
MAKE_REAL_PATH (real_path, this, loc->path);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -1589,7 +1591,7 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
@@ -1639,7 +1641,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
goto out;
SET_FS_ID (frame->root->uid, gid);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -1695,7 +1697,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
@@ -1744,7 +1746,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
MAKE_REAL_PATH (real_oldpath, this, oldloc->path);
MAKE_REAL_PATH (real_newpath, this, newloc->path);
- oldpathdup = strdup (real_oldpath);
+ oldpathdup = gf_strdup (real_oldpath);
GF_VALIDATE_OR_GOTO (this->name, oldpathdup, out);
oldparentpath = dirname (oldpathdup);
@@ -1758,7 +1760,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
goto out;
}
- newpathdup = strdup (real_newpath);
+ newpathdup = gf_strdup (real_newpath);
GF_VALIDATE_OR_GOTO (this->name, newpathdup, out);
newparentpath = dirname (newpathdup);
@@ -1818,10 +1820,10 @@ posix_rename (call_frame_t *frame, xlator_t *this,
out:
if (oldpathdup)
- FREE (oldpathdup);
+ GF_FREE (oldpathdup);
if (newpathdup)
- FREE (newpathdup);
+ GF_FREE (newpathdup);
SET_TO_OLD_FS_ID ();
@@ -1873,7 +1875,7 @@ posix_link (call_frame_t *frame, xlator_t *this,
was_present = 0;
}
- newpathdup = strdup (real_newpath);
+ newpathdup = gf_strdup (real_newpath);
if (!newpathdup) {
gf_log (this->name, GF_LOG_ERROR, "strdup failed");
op_errno = ENOMEM;
@@ -1919,7 +1921,7 @@ posix_link (call_frame_t *frame, xlator_t *this,
out:
if (newpathdup)
- FREE (newpathdup);
+ GF_FREE (newpathdup);
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (link, frame, op_ret, op_errno,
@@ -2039,7 +2041,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
}
SET_FS_ID (frame->root->uid, gid);
- pathdup = strdup (real_path);
+ pathdup = gf_strdup (real_path);
GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
parentpath = dirname (pathdup);
@@ -2106,7 +2108,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
}
op_ret = -1;
- pfd = CALLOC (1, sizeof (*pfd));
+ pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
if (!pfd) {
op_errno = errno;
@@ -2130,7 +2132,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
out:
if (pathdup)
- FREE (pathdup);
+ GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
if ((-1 == op_ret) && (_fd != -1)) {
@@ -2197,7 +2199,7 @@ posix_open (call_frame_t *frame, xlator_t *this,
goto out;
}
- pfd = CALLOC (1, sizeof (*pfd));
+ pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
if (!pfd) {
op_errno = errno;
@@ -2453,7 +2455,8 @@ posix_writev (call_frame_t *frame, xlator_t *this,
max_buf_size = vector[idx].iov_len;
}
- alloc_buf = MALLOC (1 * (max_buf_size + align));
+ alloc_buf = GF_MALLOC (1 * (max_buf_size + align),
+ gf_posix_mt_char);
if (!alloc_buf) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -2530,7 +2533,7 @@ posix_writev (call_frame_t *frame, xlator_t *this,
out:
if (alloc_buf) {
- FREE (alloc_buf);
+ GF_FREE (alloc_buf);
}
STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, &preop, &postop);
@@ -2965,7 +2968,8 @@ get_file_contents (xlator_t *this, char *real_path,
goto out;
}
- *contents = CALLOC (stbuf.ia_size + 1, sizeof(char));
+ *contents = GF_CALLOC (stbuf.ia_size + 1, sizeof(char),
+ gf_posix_mt_char);
if (! *contents) {
op_ret = -errno;
@@ -2995,7 +2999,7 @@ get_file_contents (xlator_t *this, char *real_path,
out:
if (op_ret < 0) {
if (*contents)
- FREE (*contents);
+ GF_FREE (*contents);
if (file_fd != -1)
close (file_fd);
}
@@ -3114,7 +3118,8 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
if (op_ret == -1)
break;
- value = CALLOC (op_ret + 1, sizeof(char));
+ value = GF_CALLOC (op_ret + 1, sizeof(char),
+ gf_posix_mt_char);
if (!value) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "Out of memory.");
@@ -3129,7 +3134,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
if (strcmp (key, gen_key) != 0)
dict_set (dict, key, data_from_dynptr (value, op_ret));
else
- FREE (value);
+ GF_FREE (value);
remaining_size -= strlen (key) + 1;
list_offset += strlen (key) + 1;
@@ -3239,7 +3244,8 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
if (op_ret == -1)
break;
- value = CALLOC (op_ret + 1, sizeof(char));
+ value = GF_CALLOC (op_ret + 1, sizeof(char),
+ gf_posix_mt_char);
if (!value) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "Out of memory.");
@@ -3525,7 +3531,7 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
MAKE_REAL_PATH (real_path, this, loc->path);
if (loc) {
- path = strdup (loc->path);
+ path = gf_strdup (loc->path);
inode = loc->inode;
} else {
inode = fd->inode;
@@ -3533,7 +3539,8 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
while (trav) {
count = trav->value->len / sizeof (int32_t);
- array = CALLOC (count, sizeof (int32_t));
+ array = GF_CALLOC (count, sizeof (int32_t),
+ gf_posix_mt_int32_t);
LOCK (&inode->lock);
{
@@ -3645,10 +3652,10 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
out:
if (array)
- FREE (array);
+ GF_FREE (array);
if (path)
- FREE (path);
+ GF_FREE (path);
STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, xattr);
return 0;
@@ -4222,8 +4229,8 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (fd, out);
memset (strong_checksum, 0, MD5_DIGEST_LEN);
+ buf = GF_CALLOC (1, len, gf_posix_mt_char);
- buf = CALLOC (1, len);
if (!buf) {
op_errno = ENOMEM;
gf_log (this->name, GF_LOG_ERROR,
@@ -4255,7 +4262,7 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
weak_checksum = gf_rsync_weak_checksum (buf, len);
gf_rsync_strong_checksum (buf, len, strong_checksum);
- FREE (buf);
+ GF_FREE (buf);
op_ret = 0;
out:
@@ -4289,6 +4296,25 @@ notify (xlator_t *this,
return 0;
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_posix_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
/**
* init -
*/
@@ -4375,7 +4401,8 @@ init (xlator_t *this)
}
}
- _private = CALLOC (1, sizeof (*_private));
+ _private = GF_CALLOC (1, sizeof (*_private),
+ gf_posix_mt_posix_private);
if (!_private) {
gf_log (this->name, GF_LOG_ERROR,
"Out of memory.");
@@ -4383,13 +4410,14 @@ init (xlator_t *this)
goto out;
}
- _private->base_path = strdup (dir_data->data);
+ _private->base_path = gf_strdup (dir_data->data);
_private->base_path_length = strlen (_private->base_path);
- _private->trash_path = CALLOC (1, _private->base_path_length
- + strlen ("/")
- + strlen (GF_REPLICATE_TRASH_DIR)
- + 1);
+ _private->trash_path = GF_CALLOC (1, _private->base_path_length
+ + strlen ("/")
+ + strlen (GF_REPLICATE_TRASH_DIR)
+ + 1,
+ gf_posix_mt_trash_path);
if (!_private->trash_path) {
gf_log (this->name, GF_LOG_ERROR,
@@ -4477,9 +4505,11 @@ init (xlator_t *this)
if (_private->num_devices_to_span < 1)
_private->num_devices_to_span = 1;
}
- _private->st_device = CALLOC (1, (sizeof (dev_t) *
- _private->num_devices_to_span));
+ _private->st_device = GF_CALLOC (1, (sizeof (dev_t) *
+ _private->num_devices_to_span),
+ gf_posix_mt_posix_dev_t);
+
/* Start with the base */
_private->st_device[0] = buf.st_dev;
@@ -4542,7 +4572,7 @@ fini (xlator_t *this)
{
struct posix_private *priv = this->private;
sys_lremovexattr (priv->base_path, "trusted.glusterfs.test");
- FREE (priv);
+ GF_FREE (priv);
return;
}
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 6146c3705..0295a1f48 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -50,6 +50,8 @@
#include "xlator.h"
#include "inode.h"
#include "compat.h"
+#include "timer.h"
+#include "posix-mem-types.h"
/**
* posix_fd - internal structure common to file and directory fd's