summaryrefslogtreecommitdiffstats
path: root/xlators/storage/bdb
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage/bdb')
-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
4 files changed, 133 insertions, 66 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;
}