summaryrefslogtreecommitdiffstats
path: root/xlators/meta
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/meta
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/meta')
-rw-r--r--xlators/meta/src/meta-mem-types.h35
-rw-r--r--xlators/meta/src/meta.c61
-rw-r--r--xlators/meta/src/tree.c23
3 files changed, 91 insertions, 28 deletions
diff --git a/xlators/meta/src/meta-mem-types.h b/xlators/meta/src/meta-mem-types.h
new file mode 100644
index 0000000..a9ec943
--- /dev/null
+++ b/xlators/meta/src/meta-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 __META_MEM_TYPES_H__
+#define __META_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_meta_mem_types_ {
+ gf_meta_mt__open_local = gf_common_mt_end + 1,
+ gf_meta_mt_dir_entry_t,
+ gf_meta_mt_meta_dirent_t,
+ gf_meta_mt_meta_private_t,
+ gf_meta_mt_stat,
+ gf_meta_mt_end
+};
+#endif
+
diff --git a/xlators/meta/src/meta.c b/xlators/meta/src/meta.c
index 7843e81..2babe32 100644
--- a/xlators/meta/src/meta.c
+++ b/xlators/meta/src/meta.c
@@ -32,6 +32,7 @@
#include "meta.h"
#include "view.h"
+#include "meta-mem-types.h"
int32_t
meta_getattr_cbk (call_frame_t *frame,
@@ -516,9 +517,9 @@ meta_open (call_frame_t *frame, xlator_t *this,
if (file) {
if (file->fops && file->fops->open) {
- struct _open_local *local = CALLOC (1, sizeof (struct _open_local));
+ struct _open_local *local = GF_CALLOC (1, sizeof (struct _open_local), gf_meta_mt__open_local);
ERR_ABORT (local);
- local->path = strdup (path);
+ local->path = gf_strdup (path);
frame->local = local;
STACK_WIND (frame, meta_open_cbk,
this, file->fops->open,
@@ -528,7 +529,7 @@ meta_open (call_frame_t *frame, xlator_t *this,
else {
dict_t *ctx = get_new_dict ();
dict_ref (ctx);
- dict_set (ctx, this->name, str_to_data (strdup (path)));
+ dict_set (ctx, this->name, str_to_data (gf_strdup (path)));
STACK_UNWIND (frame, 0, 0, ctx, file->stbuf);
return 0;
}
@@ -551,9 +552,9 @@ meta_create (call_frame_t *frame, xlator_t *this,
if (file) {
if (file->fops && file->fops->create) {
- struct _open_local *local = CALLOC (1, sizeof (struct _open_local));
+ struct _open_local *local = GF_CALLOC (1, sizeof (struct _open_local), gf_meta_mt__open_local);
ERR_ABORT (local);
- local->path = strdup (path);
+ local->path = gf_strdup (path);
frame->local = local;
STACK_WIND (frame, meta_open_cbk,
this, file->fops->create,
@@ -826,7 +827,7 @@ meta_opendir (call_frame_t *frame,
if (dir) {
dict_t *ctx = get_new_dict ();
- dict_set (ctx, this->name, str_to_data (strdup (path)));
+ dict_set (ctx, this->name, str_to_data (gf_strdup (path)));
STACK_UNWIND (frame, 0, 0, ctx);
return 0;
}
@@ -850,10 +851,11 @@ meta_readdir_cbk (call_frame_t *frame,
meta_private_t *priv = (meta_private_t *)this->private;
if ((int) cookie == 1) {
- dir_entry_t *dir = CALLOC (1, sizeof (dir_entry_t));
+ dir_entry_t *dir = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_meta_mt_dir_entry_t);
ERR_ABORT (dir);
- dir->name = strdup (".meta");
+ dir->name = gf_strdup (".meta");
memcpy (&dir->buf, priv->tree->stbuf, sizeof (struct stat));
dir->next = entries->next;
entries->next = dir;
@@ -887,7 +889,8 @@ meta_readdir (call_frame_t *frame,
dir_entry_t *entries = NULL;
while (dir) {
- dir_entry_t *d = CALLOC (1, sizeof (dir_entry_t));
+ dir_entry_t *d = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_meta_mt_dir_entry_t);
ERR_ABORT (d);
d->name = dir->name;
d->buf = *dir->stbuf;
@@ -897,7 +900,8 @@ meta_readdir (call_frame_t *frame,
dir = dir->next;
}
- dir_entry_t *header = CALLOC (1, sizeof (dir_entry_t));
+ dir_entry_t *header = GF_CALLOC (1, sizeof (dir_entry_t),
+ gf_meta_mt_dir_entry_t);
ERR_ABORT (header);
header->next = entries;
STACK_UNWIND (frame, 0, 0, header, count);
@@ -1163,16 +1167,16 @@ add_xlator_to_tree (meta_dirent_t *tree, xlator_t *this,
const char *prefix)
{
char *dir;
- asprintf (&dir, "%s/%s", prefix, this->name);
+ gf_asprintf (&dir, "%s/%s", prefix, this->name);
char *children;
- asprintf (&children, "%s/%s", dir, "subvolumes");
+ gf_asprintf (&children, "%s/%s", dir, "subvolumes");
char *type;
- asprintf (&type, "%s/%s", dir, "type");
+ gf_asprintf (&type, "%s/%s", dir, "type");
char *view;
- asprintf (&view, "%s/%s", dir, "view");
+ gf_asprintf (&view, "%s/%s", dir, "view");
insert_meta_entry (tree, dir, S_IFDIR, NULL, NULL);
insert_meta_entry (tree, children, S_IFDIR, NULL, NULL);
@@ -1194,9 +1198,10 @@ static void
build_meta_tree (xlator_t *this)
{
meta_private_t *priv = (meta_private_t *) this->private;
- priv->tree = CALLOC (1, sizeof (meta_dirent_t));
+ priv->tree = GF_CALLOC (1, sizeof (meta_dirent_t),
+ gf_meta_mt_meta_dirent_t);
ERR_ABORT (priv->tree);
- priv->tree->name = strdup (".meta");
+ priv->tree->name = gf_strdup (".meta");
priv->tree->stbuf = new_stbuf ();
priv->tree->stbuf->st_mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH |
S_IXUSR | S_IXGRP | S_IXOTH;
@@ -1215,6 +1220,25 @@ build_meta_tree (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_meta_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
+int32_t
init (xlator_t *this)
{
if (this->parent != NULL) {
@@ -1222,12 +1246,13 @@ init (xlator_t *this)
return -1;
}
- meta_private_t *priv = CALLOC (1, sizeof (meta_private_t));
+ meta_private_t *priv = GF_CALLOC (1, sizeof (meta_private_t),
+ gf_meta_mt_meta_private_t);
ERR_ABORT (priv);
data_t *directory = dict_get (this->options, "directory");
if (directory) {
- priv->directory = strdup (data_to_str (directory));
+ priv->directory = gf_strdup (data_to_str (directory));
}
else {
priv->directory = ".meta";
diff --git a/xlators/meta/src/tree.c b/xlators/meta/src/tree.c
index a5ba08a..787f27d 100644
--- a/xlators/meta/src/tree.c
+++ b/xlators/meta/src/tree.c
@@ -31,6 +31,7 @@
#include "xlator.h"
#include "meta.h"
+#include "meta-mem-types.h"
static int
is_meta_path (const char *path)
@@ -46,7 +47,7 @@ struct stat *
new_stbuf (void)
{
static int next_inode = 0;
- struct stat *stbuf = CALLOC (1, sizeof (struct stat));
+ struct stat *stbuf = GF_CALLOC (1, sizeof (struct stat), gf_meta_mt_stat);
ERR_ABORT (stbuf);
@@ -99,7 +100,7 @@ meta_dirent_t *
lookup_meta_entry (meta_dirent_t *root, const char *path,
char **remain)
{
- char *_path = strdup (path);
+ char *_path = gf_strdup (path);
if (!is_meta_path (path))
return NULL;
@@ -119,10 +120,10 @@ lookup_meta_entry (meta_dirent_t *root, const char *path,
while (piece) {
char *tmp = *remain;
if (*remain)
- asprintf (remain, "/%s/%s", *remain, piece);
+ gf_asprintf (remain, "/%s/%s", *remain, piece);
else
- asprintf (remain, "/%s", piece);
- if (tmp) free (tmp);
+ gf_asprintf (remain, "/%s", piece);
+ if (tmp) GF_FREE (tmp);
piece = strtok (NULL, "/");
}
}
@@ -132,7 +133,7 @@ lookup_meta_entry (meta_dirent_t *root, const char *path,
trav = ntrav;
}
- free (_path);
+ GF_FREE (_path);
return trav;
}
@@ -148,9 +149,10 @@ insert_meta_entry (meta_dirent_t *root, const char *path,
if (!dir)
return NULL;
- meta_dirent_t *new = CALLOC (1, sizeof (meta_dirent_t));
+ meta_dirent_t *new = GF_CALLOC (1, sizeof (meta_dirent_t),
+ gf_meta_mt_meta_dirent_t);
ERR_ABORT (new);
- new->name = strdup (slashpos+1);
+ new->name = gf_strdup (slashpos+1);
new->type = type;
new->parent = parent;
new->next = parent->children;
@@ -167,9 +169,10 @@ insert_meta_entry (meta_dirent_t *root, const char *path,
int main (void)
{
- meta_dirent_t *root = CALLOC (1, sizeof (meta_dirent_t));
+ meta_dirent_t *root = GF_CALLOC (1, sizeof (meta_dirent_t),
+ gf_meta_mt_meta_dirent_t);
ERR_ABORT (root);
- root->name = strdup (".meta");
+ root->name = gf_strdup (".meta");
insert_meta_entry (root, "/.meta/version", S_IFREG, NULL, NULL);
return 0;