summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/map
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/cluster/map
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/cluster/map')
-rw-r--r--xlators/cluster/map/src/map-helper.c5
-rw-r--r--xlators/cluster/map/src/map-mem-types.h35
-rw-r--r--xlators/cluster/map/src/map.c48
-rw-r--r--xlators/cluster/map/src/map.h1
4 files changed, 76 insertions, 13 deletions
diff --git a/xlators/cluster/map/src/map-helper.c b/xlators/cluster/map/src/map-helper.c
index b4c8ad525..ad01b2102 100644
--- a/xlators/cluster/map/src/map-helper.c
+++ b/xlators/cluster/map/src/map-helper.c
@@ -256,14 +256,15 @@ verify_dir_and_assign_subvol (xlator_t *this,
goto out;
}
- tmp_map = CALLOC (1, sizeof (struct map_pattern));
+ tmp_map = GF_CALLOC (1, sizeof (struct map_pattern),
+ gf_map_mt_map_pattern);
tmp_map->xl = trav->xlator;
tmp_map->dir_len = strlen (directory);
/* make sure that the top level directory starts
* with '/' and ends without '/'
*/
- tmp_map->directory = strdup (directory);
+ tmp_map->directory = gf_strdup (directory);
if (directory[tmp_map->dir_len - 1] == '/') {
tmp_map->dir_len--;
}
diff --git a/xlators/cluster/map/src/map-mem-types.h b/xlators/cluster/map/src/map-mem-types.h
new file mode 100644
index 000000000..f41ab420a
--- /dev/null
+++ b/xlators/cluster/map/src/map-mem-types.h
@@ -0,0 +1,35 @@
+
+/*
+ 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 __MAP_MEM_TYPES_H__
+#define __MAP_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_map_mem_types_ {
+ gf_map_mt_map_private_t = gf_common_mt_end + 1,
+ gf_map_mt_map_local_t,
+ gf_map_mt_map_xlator_array,
+ gf_map_mt_map_pattern,
+ gf_map_mt_end
+};
+#endif
+
diff --git a/xlators/cluster/map/src/map.c b/xlators/cluster/map/src/map.c
index 09d22b5d6..1383d83c1 100644
--- a/xlators/cluster/map/src/map.c
+++ b/xlators/cluster/map/src/map.c
@@ -2147,7 +2147,8 @@ map_lookup (call_frame_t *frame,
return 0;
root_inode:
- local = CALLOC (1, sizeof (map_local_t));
+ local = GF_CALLOC (1, sizeof (map_local_t),
+ gf_map_mt_map_local_t);
frame->local = local;
local->call_count = priv->child_count;
@@ -2199,7 +2200,8 @@ map_statfs (call_frame_t *frame,
return 0;
root_inode:
- local = CALLOC (1, sizeof (map_local_t));
+ local = GF_CALLOC (1, sizeof (map_local_t),
+ gf_map_mt_map_local_t);
priv = this->private;
frame->local = local;
@@ -2251,7 +2253,8 @@ map_opendir (call_frame_t *frame,
return 0;
root_inode:
- local = CALLOC (1, sizeof (map_local_t));
+ local = GF_CALLOC (1, sizeof (map_local_t),
+ gf_map_mt_map_local_t);
priv = this->private;
frame->local = local;
@@ -2310,7 +2313,8 @@ map_do_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
root_inode:
/* readdir on '/' */
- local = CALLOC (1, sizeof (map_local_t));
+ local = GF_CALLOC (1, sizeof (map_local_t),
+ gf_map_mt_map_local_t);
if (!local) {
gf_log (this->name, GF_LOG_ERROR,
"memory allocation failed :(");
@@ -2372,21 +2376,40 @@ fini (xlator_t *this)
if (priv) {
if (priv->xlarray)
- FREE (priv->xlarray);
+ GF_FREE (priv->xlarray);
trav_map = priv->map;
while (trav_map) {
tmp_map = trav_map;
trav_map = trav_map->next;
- FREE (tmp_map);
+ GF_FREE (tmp_map);
}
- FREE(priv);
+ GF_FREE(priv);
}
return;
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_map_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
int
init (xlator_t *this)
{
@@ -2403,6 +2426,7 @@ init (xlator_t *this)
char *subvol_str = NULL;
char *map_xl = NULL;
+
if (!this->children) {
gf_log (this->name,GF_LOG_ERROR,
"FATAL: map should have one or more child defined");
@@ -2414,7 +2438,8 @@ init (xlator_t *this)
"dangling volume. check volfile ");
}
- priv = CALLOC (1, sizeof (map_private_t));
+ priv = GF_CALLOC (1, sizeof (map_private_t),
+ gf_map_mt_map_private_t);
this->private = priv;
/* allocate xlator array */
@@ -2423,7 +2448,8 @@ init (xlator_t *this)
count++;
trav = trav->next;
}
- priv->xlarray = CALLOC (1, sizeof (struct map_xlator_array) * count);
+ priv->xlarray = GF_CALLOC (1, sizeof (struct map_xlator_array) * count,
+ gf_map_mt_map_xlator_array);
priv->child_count = count;
/* build xlator array */
@@ -2443,7 +2469,7 @@ init (xlator_t *this)
}
map_pair_str = strtok_r (pattern_string, ";", &tmp_str);
while (map_pair_str) {
- dup_map_pair = strdup (map_pair_str);
+ dup_map_pair = gf_strdup (map_pair_str);
dir_str = strtok_r (dup_map_pair, ":", &tmp_str1);
if (!dir_str) {
gf_log (this->name, GF_LOG_ERROR,
@@ -2465,7 +2491,7 @@ init (xlator_t *this)
goto err;
}
- FREE (dup_map_pair);
+ GF_FREE (dup_map_pair);
map_pair_str = strtok_r (NULL, ";", &tmp_str);
}
diff --git a/xlators/cluster/map/src/map.h b/xlators/cluster/map/src/map.h
index b423642cc..eb549eb06 100644
--- a/xlators/cluster/map/src/map.h
+++ b/xlators/cluster/map/src/map.h
@@ -21,6 +21,7 @@
#define __MAP_H__
#include "xlator.h"
+#include "map-mem-types.h"
struct map_pattern {
struct map_pattern *next;