summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/unify
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/cluster/unify')
-rw-r--r--xlators/cluster/unify/src/unify-mem-types.h41
-rw-r--r--xlators/cluster/unify/src/unify-self-heal.c90
-rw-r--r--xlators/cluster/unify/src/unify.c94
-rw-r--r--xlators/cluster/unify/src/unify.h3
4 files changed, 159 insertions, 69 deletions
diff --git a/xlators/cluster/unify/src/unify-mem-types.h b/xlators/cluster/unify/src/unify-mem-types.h
new file mode 100644
index 00000000000..3b4abc8e9b8
--- /dev/null
+++ b/xlators/cluster/unify/src/unify-mem-types.h
@@ -0,0 +1,41 @@
+
+/*
+ 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 __UNIFY_MEM_TYPES_H__
+#define __UNIFY_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_unify_mem_types_ {
+ gf_unify_mt_char = gf_common_mt_end + 1,
+ gf_unify_mt_int16_t,
+ gf_unify_mt_xlator_t,
+ gf_unify_mt_unify_private_t,
+ gf_unify_mt_xlator_list_t,
+ gf_unify_mt_dir_entry_t,
+ gf_unify_mt_off_t,
+ gf_unify_mt_int,
+ gf_unify_mt_unify_self_heal_struct,
+ gf_unify_mt_unify_local_t,
+ gf_unify_mt_end
+};
+#endif
+
diff --git a/xlators/cluster/unify/src/unify-self-heal.c b/xlators/cluster/unify/src/unify-self-heal.c
index 86f9e88fa5c..88145af9a77 100644
--- a/xlators/cluster/unify/src/unify-self-heal.c
+++ b/xlators/cluster/unify/src/unify-self-heal.c
@@ -93,20 +93,20 @@ unify_local_wipe (unify_local_t *local)
{
/* Free the strdup'd variables in the local structure */
if (local->name) {
- FREE (local->name);
+ GF_FREE (local->name);
}
if (local->sh_struct) {
if (local->sh_struct->offset_list)
- FREE (local->sh_struct->offset_list);
+ GF_FREE (local->sh_struct->offset_list);
if (local->sh_struct->entry_list)
- FREE (local->sh_struct->entry_list);
+ GF_FREE (local->sh_struct->entry_list);
if (local->sh_struct->count_list)
- FREE (local->sh_struct->count_list);
+ GF_FREE (local->sh_struct->count_list);
- FREE (local->sh_struct);
+ GF_FREE (local->sh_struct);
}
loc_wipe (&local->loc1);
@@ -144,13 +144,13 @@ unify_sh_setdents_cbk (call_frame_t *frame,
trav = entry->next;
while (trav) {
prev->next = trav->next;
- FREE (trav->name);
+ GF_FREE (trav->name);
if (IA_ISLNK (trav->buf.ia_type))
- FREE (trav->link);
- FREE (trav);
+ GF_FREE (trav->link);
+ GF_FREE (trav);
trav = prev->next;
}
- FREE (entry);
+ GF_FREE (entry);
}
if (!local->flags) {
@@ -202,7 +202,8 @@ unify_sh_ns_getdents_cbk (call_frame_t *frame,
unify_private_t *priv = this->private;
long index = 0;
unsigned long final = 0;
- dir_entry_t *tmp = CALLOC (1, sizeof (dir_entry_t));
+ dir_entry_t *tmp = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_unify_mt_dir_entry_t);
local->sh_struct->entry_list[0] = tmp;
local->sh_struct->count_list[0] = count;
@@ -259,13 +260,13 @@ unify_sh_ns_setdents_cbk (call_frame_t *frame,
trav = entry->next;
while (trav) {
prev->next = trav->next;
- FREE (trav->name);
+ GF_FREE (trav->name);
if (IA_ISLNK (trav->buf.ia_type))
- FREE (trav->link);
- FREE (trav);
+ GF_FREE (trav->link);
+ GF_FREE (trav);
trav = prev->next;
}
- FREE (entry);
+ GF_FREE (entry);
}
}
UNLOCK (&frame->lock);
@@ -341,7 +342,8 @@ unify_sh_getdents_cbk (call_frame_t *frame,
if (op_ret >= 0 && count > 0) {
/* There is some dentry found, just send the dentry to NS */
- tmp = CALLOC (1, sizeof (dir_entry_t));
+ tmp = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_unify_mt_dir_entry_t);
local->sh_struct->entry_list[index] = tmp;
local->sh_struct->count_list[index] = count;
if (entry) {
@@ -458,18 +460,21 @@ unify_sh_opendir_cbk (call_frame_t *frame,
* STACK_WIND.
*/
local->sh_struct->offset_list =
- calloc (priv->child_count,
- sizeof (off_t));
+ GF_CALLOC (priv->child_count,
+ sizeof (off_t),
+ gf_unify_mt_off_t);
ERR_ABORT (local->sh_struct->offset_list);
local->sh_struct->entry_list =
- calloc (priv->child_count,
- sizeof (dir_entry_t *));
+ GF_CALLOC (priv->child_count,
+ sizeof (dir_entry_t *),
+ gf_unify_mt_dir_entry_t);
ERR_ABORT (local->sh_struct->entry_list);
local->sh_struct->count_list =
- calloc (priv->child_count,
- sizeof (int));
+ GF_CALLOC (priv->child_count,
+ sizeof (int),
+ gf_unify_mt_int);
ERR_ABORT (local->sh_struct->count_list);
/* Send getdents on all the fds */
@@ -668,13 +673,13 @@ unify_bgsh_setdents_cbk (call_frame_t *frame,
trav = entry->next;
while (trav) {
prev->next = trav->next;
- FREE (trav->name);
+ GF_FREE (trav->name);
if (IA_ISLNK (trav->buf.ia_type))
- FREE (trav->link);
- FREE (trav);
+ GF_FREE (trav->link);
+ GF_FREE (trav);
trav = prev->next;
}
- FREE (entry);
+ GF_FREE (entry);
}
if (!local->flags) {
@@ -718,7 +723,8 @@ unify_bgsh_ns_getdents_cbk (call_frame_t *frame,
unify_private_t *priv = this->private;
long index = 0;
unsigned long final = 0;
- dir_entry_t *tmp = CALLOC (1, sizeof (dir_entry_t));
+ dir_entry_t *tmp = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_unify_mt_dir_entry_t);
local->sh_struct->entry_list[0] = tmp;
local->sh_struct->count_list[0] = count;
@@ -775,13 +781,13 @@ unify_bgsh_ns_setdents_cbk (call_frame_t *frame,
trav = entry->next;
while (trav) {
prev->next = trav->next;
- FREE (trav->name);
+ GF_FREE (trav->name);
if (IA_ISLNK (trav->buf.ia_type))
- FREE (trav->link);
- FREE (trav);
+ GF_FREE (trav->link);
+ GF_FREE (trav);
trav = prev->next;
}
- FREE (entry);
+ GF_FREE (entry);
}
if (local->sh_struct->count_list[index] <
@@ -855,7 +861,8 @@ unify_bgsh_getdents_cbk (call_frame_t *frame,
if (op_ret >= 0 && count > 0) {
/* There is some dentry found, just send the dentry to NS */
- tmp = CALLOC (1, sizeof (dir_entry_t));
+ tmp = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_unify_mt_dir_entry_t);
local->sh_struct->entry_list[index] = tmp;
local->sh_struct->count_list[index] = count;
if (entry) {
@@ -969,18 +976,21 @@ unify_bgsh_opendir_cbk (call_frame_t *frame,
track of offset sent to each node during
STACK_WIND. */
local->sh_struct->offset_list =
- calloc (priv->child_count,
- sizeof (off_t));
+ GF_CALLOC (priv->child_count,
+ sizeof (off_t),
+ gf_unify_mt_off_t);
ERR_ABORT (local->sh_struct->offset_list);
local->sh_struct->entry_list =
- calloc (priv->child_count,
- sizeof (dir_entry_t *));
+ GF_CALLOC (priv->child_count,
+ sizeof (dir_entry_t *),
+ gf_unify_mt_dir_entry_t);
ERR_ABORT (local->sh_struct->entry_list);
local->sh_struct->count_list =
- calloc (priv->child_count,
- sizeof (int));
+ GF_CALLOC (priv->child_count,
+ sizeof (int),
+ gf_unify_mt_int);
ERR_ABORT (local->sh_struct->count_list);
/* Send getdents on all the fds */
@@ -1161,7 +1171,8 @@ zr_unify_self_heal (call_frame_t *frame,
local->failed = 0;
local->call_count = priv->child_count + 1;
local->sh_struct =
- calloc (1, sizeof (struct unify_self_heal_struct));
+ GF_CALLOC (1, sizeof (struct unify_self_heal_struct),
+ gf_unify_mt_unify_self_heal_struct);
/* +1 is for NS */
for (index = 0;
@@ -1188,7 +1199,8 @@ zr_unify_self_heal (call_frame_t *frame,
bg_local->failed = 0;
bg_local->call_count = priv->child_count + 1;
bg_local->sh_struct =
- calloc (1, sizeof (struct unify_self_heal_struct));
+ GF_CALLOC (1, sizeof (struct unify_self_heal_struct),
+ gf_unify_mt_unify_self_heal_struct);
/* +1 is for NS */
for (index = 0; index < (priv->child_count + 1); index++) {
diff --git a/xlators/cluster/unify/src/unify.c b/xlators/cluster/unify/src/unify.c
index 2eadfe31cd7..3f0910df4fa 100644
--- a/xlators/cluster/unify/src/unify.c
+++ b/xlators/cluster/unify/src/unify.c
@@ -82,7 +82,7 @@ unify_local_wipe (unify_local_t *local)
{
/* Free the strdup'd variables in the local structure */
if (local->name) {
- FREE (local->name);
+ GF_FREE (local->name);
}
loc_wipe (&local->loc1);
loc_wipe (&local->loc2);
@@ -421,7 +421,8 @@ unify_lookup_cbk (call_frame_t *frame,
if (!local->list) {
/* list is not allocated, allocate
the max possible range */
- local->list = CALLOC (1, 2 * (priv->child_count + 2));
+ local->list = GF_CALLOC (1, 2 * (priv->child_count + 2),
+ gf_unify_mt_int16_t);
if (!local->list) {
gf_log (this->name,
GF_LOG_CRITICAL,
@@ -494,11 +495,12 @@ unify_lookup_cbk (call_frame_t *frame,
/* If its a file, big array is useless,
allocate the smaller one */
int16_t *list = NULL;
- list = CALLOC (1, 2 * (local->index + 1));
+ list = GF_CALLOC (1, 2 * (local->index + 1),
+ gf_unify_mt_int16_t);
ERR_ABORT (list);
memcpy (list, local->list, 2 * local->index);
/* Make the end of the list as -1 */
- FREE (local->list);
+ GF_FREE (local->list);
local->list = list;
local->list [local->index] = -1;
/* Update the inode's ctx with proper array */
@@ -524,7 +526,7 @@ unify_lookup_cbk (call_frame_t *frame,
}
if (local->op_ret == -1) {
if (!local->revalidate && local->list)
- FREE (local->list);
+ GF_FREE (local->list);
}
if ((local->op_ret >= 0) && local->failed &&
@@ -1219,19 +1221,20 @@ unify_open_readlink_cbk (call_frame_t *frame,
}
if (path[0] == '/') {
- local->name = strdup (path);
+ local->name = gf_strdup (path);
ERR_ABORT (local->name);
} else {
- char *tmp_str = strdup (local->loc1.path);
+ char *tmp_str = gf_strdup (local->loc1.path);
char *tmp_base = dirname (tmp_str);
- local->name = CALLOC (1, ZR_PATH_MAX);
+ local->name = GF_CALLOC (1, ZR_PATH_MAX, gf_unify_mt_char);
strcpy (local->name, tmp_base);
strncat (local->name, "/", 1);
strcat (local->name, path);
- FREE (tmp_str);
+ GF_FREE (tmp_str);
}
- local->list = CALLOC (1, sizeof (int16_t) * 3);
+ local->list = GF_CALLOC (1, sizeof (int16_t) * 3,
+ gf_unify_mt_int16_t);
ERR_ABORT (local->list);
local->call_count = priv->child_count + 1;
local->op_ret = -1;
@@ -1663,7 +1666,8 @@ unify_ns_create_cbk (call_frame_t *frame,
local->op_ret = -1;
/* Start the mapping list */
- list = CALLOC (1, sizeof (int16_t) * 3);
+ list = GF_CALLOC (1, sizeof (int16_t) * 3,
+ gf_unify_mt_int16_t);
ERR_ABORT (list);
inode_ctx_put (inode, this, (uint64_t)(long)list);
list[0] = priv->child_count;
@@ -1709,7 +1713,8 @@ unify_ns_create_cbk (call_frame_t *frame,
"File(%s) already exists on namespace, sending "
"open instead", local->loc1.path);
- local->list = CALLOC (1, sizeof (int16_t) * 3);
+ local->list = GF_CALLOC (1, sizeof (int16_t) * 3,
+ gf_unify_mt_int16_t);
ERR_ABORT (local->list);
local->call_count = priv->child_count + 1;
local->op_ret = -1;
@@ -2827,7 +2832,7 @@ unify_setxattr (call_frame_t *frame,
content only if file exists */
local->flags = flags;
local->dict = dict;
- local->name = strdup (trav->key);
+ local->name = gf_strdup (trav->key);
flags |= XATTR_REPLACE;
}
@@ -3207,7 +3212,7 @@ unify_ns_mknod_cbk (call_frame_t *frame,
local->oldpreparent = *preparent;
local->oldpostparent = *postparent;
- list = CALLOC (1, sizeof (int16_t) * 3);
+ list = GF_CALLOC (1, sizeof (int16_t) * 3, gf_unify_mt_int16_t);
ERR_ABORT (list);
list[0] = priv->child_count;
list[2] = -1;
@@ -3383,7 +3388,7 @@ unify_ns_symlink_cbk (call_frame_t *frame,
/* Start the mapping list */
- list = CALLOC (1, sizeof (int16_t) * 3);
+ list = GF_CALLOC (1, sizeof (int16_t) * 3, gf_unify_mt_int16_t);
ERR_ABORT (list);
list[0] = priv->child_count; //namespace's index
list[2] = -1;
@@ -3439,7 +3444,7 @@ unify_symlink (call_frame_t *frame,
/* Initialization */
INIT_LOCAL (frame, local);
loc_copy (&local->loc1, loc);
- local->name = strdup (linkpath);
+ local->name = gf_strdup (linkpath);
if ((local->name == NULL) ||
(local->loc1.path == NULL)) {
@@ -3620,7 +3625,8 @@ unify_rename_cbk (call_frame_t *frame,
if (list) {
for (index = 0; list[index] != -1; index++);
- tmp_list = CALLOC (1, index * 2);
+ tmp_list = GF_CALLOC (1, index * 2,
+ gf_unify_mt_int16_t);
memcpy (tmp_list, list, index * 2);
for (index = 0; list[index] != -1; index++) {
@@ -3668,11 +3674,11 @@ unify_rename_cbk (call_frame_t *frame,
}
}
- FREE (tmp_list);
+ GF_FREE (tmp_list);
return 0;
}
if (tmp_list)
- FREE (tmp_list);
+ GF_FREE (tmp_list);
}
}
@@ -4183,7 +4189,7 @@ unify_forget (xlator_t *this,
inode_ctx_get (inode, this, &tmp_list);
if (tmp_list) {
list = (int16_t *)(long)tmp_list;
- FREE (list);
+ GF_FREE (list);
}
}
@@ -4271,6 +4277,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_unify_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
/**
* init - This function is called first in the xlator, while initializing.
* All the config file options are checked and appropriate flags are set.
@@ -4290,6 +4315,7 @@ init (xlator_t *this)
xlator_list_t *parent = NULL;
unify_private_t *_private = NULL;
+
/* Check for number of child nodes, if there is no child nodes, exit */
if (!this->children) {
gf_log (this->name, GF_LOG_ERROR,
@@ -4347,20 +4373,21 @@ init (xlator_t *this)
gf_log (this->name, GF_LOG_DEBUG,
"namespace node specified as %s", data->data);
- _private = CALLOC (1, sizeof (*_private));
+ _private = GF_CALLOC (1, sizeof (*_private),
+ gf_unify_mt_unify_private_t);
ERR_ABORT (_private);
_private->sched_ops = get_scheduler (this, scheduler->data);
if (!_private->sched_ops) {
gf_log (this->name, GF_LOG_CRITICAL,
"Error while loading scheduler. Exiting");
- FREE (_private);
+ GF_FREE (_private);
return -1;
}
if (ns_xl->parents) {
gf_log (this->name, GF_LOG_CRITICAL,
"Namespace node should not be a child of any other node. Exiting");
- FREE (_private);
+ GF_FREE (_private);
return -1;
}
@@ -4390,8 +4417,9 @@ init (xlator_t *this)
" you may hit some performance penalty");
}
- _private->xl_array = CALLOC (1,
- sizeof (xlator_t) * (count + 1));
+ _private->xl_array = GF_CALLOC (1,
+ sizeof (xlator_t) * (count + 1),
+ gf_unify_mt_xlator_t);
ERR_ABORT (_private->xl_array);
count = 0;
@@ -4435,21 +4463,29 @@ init (xlator_t *this)
/* Now that everything is fine. */
this->private = (void *)_private;
{
+ ret = _private->sched_ops->mem_acct_init (this);
+
+ if (ret == -1) {
+ return -1;
+ }
+
/* Initialize scheduler, if everything else is successful */
ret = _private->sched_ops->init (this);
if (ret == -1) {
gf_log (this->name, GF_LOG_CRITICAL,
"Initializing scheduler failed, Exiting");
- FREE (_private);
+ GF_FREE (_private);
return -1;
}
+
ret = 0;
/* This section is required because some fops may look
* for 'xl->parent' variable
*/
- xlparent = CALLOC (1, sizeof (*xlparent));
+ xlparent = GF_CALLOC (1, sizeof (*xlparent),
+ gf_unify_mt_xlator_list_t);
xlparent->xlator = this;
if (!ns_xl->parents) {
ns_xl->parents = xlparent;
@@ -4477,8 +4513,8 @@ fini (xlator_t *this)
priv->sched_ops->fini (this);
this->private = NULL;
LOCK_DESTROY (&priv->lock);
- FREE (priv->xl_array);
- FREE (priv);
+ GF_FREE (priv->xl_array);
+ GF_FREE (priv);
return;
}
diff --git a/xlators/cluster/unify/src/unify.h b/xlators/cluster/unify/src/unify.h
index cf3560d5b05..8dcf1659821 100644
--- a/xlators/cluster/unify/src/unify.h
+++ b/xlators/cluster/unify/src/unify.h
@@ -27,6 +27,7 @@
#include "scheduler.h"
#include "list.h"
+#include "unify-mem-types.h"
#define MAX_DIR_ENTRY_STRING (32 * 1024)
@@ -42,7 +43,7 @@
/* This is used to allocate memory for local structure */
#define INIT_LOCAL(fr, loc) \
do { \
- loc = CALLOC (1, sizeof (unify_local_t)); \
+ loc = GF_CALLOC (1, sizeof (unify_local_t), gf_unify_mt_unify_local_t); \
ERR_ABORT (loc); \
if (!loc) { \
STACK_UNWIND (fr, -1, ENOMEM); \