summaryrefslogtreecommitdiffstats
path: root/xlators/mount/fuse
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/mount/fuse
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/mount/fuse')
-rw-r--r--xlators/mount/fuse/src/fuse-bridge.c81
-rw-r--r--xlators/mount/fuse/src/fuse-mem-types.h35
2 files changed, 87 insertions, 29 deletions
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
index b57dc0cfeb2..a6ff46a2659 100644
--- a/xlators/mount/fuse/src/fuse-bridge.c
+++ b/xlators/mount/fuse/src/fuse-bridge.c
@@ -48,6 +48,7 @@
#include "fuse_kernel.h"
#include "fuse-misc.h"
#include "fuse-mount.h"
+#include "fuse-mem-types.h"
#include "list.h"
#include "dict.h"
@@ -146,7 +147,7 @@ typedef struct fuse_private fuse_private_t;
finh->unique, finh->opcode); \
\
send_fuse_err (this, finh, ENOMEM); \
- FREE (finh); \
+ GF_FREE (finh); \
\
return; \
} \
@@ -186,7 +187,7 @@ free_state (fuse_state_t *state)
state->dict = (void *)0xaaaaeeee;
}
if (state->name) {
- FREE (state->name);
+ GF_FREE (state->name);
state->name = NULL;
}
if (state->fd) {
@@ -194,13 +195,13 @@ free_state (fuse_state_t *state)
state->fd = (void *)0xfdfdfdfd;
}
if (state->finh) {
- FREE (state->finh);
+ GF_FREE (state->finh);
state->finh = NULL;
}
#ifdef DEBUG
memset (state, 0x90, sizeof (*state));
#endif
- FREE (state);
+ GF_FREE (state);
state = NULL;
}
@@ -210,7 +211,8 @@ get_state (xlator_t *this, fuse_in_header_t *finh)
{
fuse_state_t *state = NULL;
- state = (void *)calloc (1, sizeof (*state));
+ state = (void *)GF_CALLOC (1, sizeof (*state),
+ gf_fuse_mt_fuse_state_t);
if (!state)
return NULL;
state->pool = this->ctx->pool;
@@ -619,7 +621,7 @@ fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)
inode_t *fuse_inode;
if (finh->nodeid == 1) {
- FREE (finh);
+ GF_FREE (finh);
return;
}
@@ -628,7 +630,7 @@ fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)
inode_forget (fuse_inode, ffi->nlookup);
inode_unref (fuse_inode);
- FREE (finh);
+ GF_FREE (finh);
}
@@ -1832,13 +1834,14 @@ fuse_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
frame->root->unique,
op_ret, state->size, state->off, stbuf->ia_size);
- iov_out = CALLOC (count + 1, sizeof (*iov_out));
+ iov_out = GF_CALLOC (count + 1, sizeof (*iov_out),
+ gf_fuse_mt_iovec);
if (iov_out) {
fouh.error = 0;
iov_out[0].iov_base = &fouh;
memcpy (iov_out + 1, vector, count * sizeof (*iov_out));
send_fuse_iov (this, finh, iov_out, count + 1);
- FREE (iov_out);
+ GF_FREE (iov_out);
} else
send_fuse_err (this, finh, ENOMEM);
} else {
@@ -2197,7 +2200,7 @@ fuse_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
strlen (entry->d_name));
}
- buf = CALLOC (1, size);
+ buf = GF_CALLOC (1, size, gf_fuse_mt_char);
if (!buf) {
gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
"%"PRIu64": READDIR => -1 (%s)", frame->root->unique,
@@ -2223,7 +2226,7 @@ out:
free_state (state);
STACK_DESTROY (frame->root);
if (buf)
- FREE (buf);
+ GF_FREE (buf);
return 0;
}
@@ -2402,7 +2405,7 @@ fuse_setxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
#ifdef DISABLE_POSIX_ACL
if (!strncmp (name, "system.", 7)) {
send_fuse_err (this, finh, EOPNOTSUPP);
- FREE (finh);
+ GF_FREE (finh);
return;
}
#endif
@@ -2546,7 +2549,8 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
}
priv->volfile_size = st.st_size;
- file = priv->volfile = CALLOC (1, priv->volfile_size);
+ file = priv->volfile = GF_CALLOC (1, priv->volfile_size,
+ gf_fuse_mt_char);
ret = lseek (fd, 0, SEEK_SET);
while ((ret = read (fd, file, GF_UNIT_KB)) > 0) {
file += ret;
@@ -2637,14 +2641,14 @@ fuse_getxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
#ifdef DISABLE_POSIX_ACL
if (!strncmp (name, "system.", 7)) {
send_fuse_err (this, finh, ENODATA);
- FREE (finh);
+ GF_FREE (finh);
return;
}
#endif
GET_STATE (this, finh, state);
state->size = fgxi->size;
- state->name = strdup (name);
+ state->name = gf_strdup (name);
ret = fuse_loc_fill (&state->loc, state, finh->nodeid, 0, NULL);
if ((state->loc.inode == NULL) ||
@@ -2950,7 +2954,7 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)
}
out:
- FREE (finh);
+ GF_FREE (finh);
}
@@ -2959,7 +2963,7 @@ fuse_enosys (xlator_t *this, fuse_in_header_t *finh, void *msg)
{
send_fuse_err (this, finh, ENOSYS);
- FREE (finh);
+ GF_FREE (finh);
}
@@ -2968,7 +2972,7 @@ fuse_destroy (xlator_t *this, fuse_in_header_t *finh, void *msg)
{
send_fuse_err (this, finh, 0);
- FREE (finh);
+ GF_FREE (finh);
}
static fuse_handler_t *fuse_ops[FUSE_713_OP_HIGH];
@@ -3101,14 +3105,15 @@ fuse_thread_proc (void *data)
* but it's good enough in most cases (and we can handle
* rest via realloc).
*/
- iov_in[0].iov_base = CALLOC (1, msg0_size);
+ iov_in[0].iov_base = GF_CALLOC (1, msg0_size,
+ gf_fuse_mt_iov_base);
if (!iobuf || !iov_in[0].iov_base) {
gf_log (this->name, GF_LOG_ERROR,
"Out of memory");
if (iobuf)
iobuf_unref (iobuf);
- FREE (iov_in[0].iov_base);
+ GF_FREE (iov_in[0].iov_base);
sleep (10);
continue;
}
@@ -3160,7 +3165,7 @@ fuse_thread_proc (void *data)
else {
if (res > msg0_size) {
iov_in[0].iov_base =
- realloc (iov_in[0].iov_base, res);
+ GF_REALLOC (iov_in[0].iov_base, res);
if (iov_in[0].iov_base)
finh = (fuse_in_header_t *)
iov_in[0].iov_base;
@@ -3187,11 +3192,11 @@ fuse_thread_proc (void *data)
cont_err:
iobuf_unref (iobuf);
- FREE (iov_in[0].iov_base);
+ GF_FREE (iov_in[0].iov_base);
}
iobuf_unref (iobuf);
- FREE (iov_in[0].iov_base);
+ GF_FREE (iov_in[0].iov_base);
if (dict_get (this->options, ZR_MOUNTPOINT_OPT))
mount_point = data_to_str (dict_get (this->options,
@@ -3328,6 +3333,24 @@ notify (xlator_t *this, int32_t event, void *data, ...)
return 0;
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_fuse_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_xl)
@@ -3350,7 +3373,7 @@ init (xlator_t *this_xl)
options = this_xl->options;
if (this_xl->name == NULL) {
- this_xl->name = strdup ("fuse");
+ this_xl->name = gf_strdup ("fuse");
if (!this_xl->name) {
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
"Out of memory");
@@ -3360,7 +3383,7 @@ init (xlator_t *this_xl)
xl_name_allocated = 1;
}
- priv = CALLOC (1, sizeof (*priv));
+ priv = GF_CALLOC (1, sizeof (*priv), gf_fuse_mt_fuse_private_t);
if (!priv) {
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
"Out of memory");
@@ -3404,7 +3427,7 @@ init (xlator_t *this_xl)
ZR_MOUNTPOINT_OPT, value_string);
goto cleanup_exit;
}
- priv->mount_point = strdup (value_string);
+ priv->mount_point = gf_strdup (value_string);
if (!priv->mount_point) {
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
"Out of memory");
@@ -3503,12 +3526,12 @@ init (xlator_t *this_xl)
cleanup_exit:
if (xl_name_allocated)
- FREE (this_xl->name);
+ GF_FREE (this_xl->name);
if (priv) {
- FREE (priv->mount_point);
+ GF_FREE (priv->mount_point);
close (priv->fd);
}
- FREE (priv);
+ GF_FREE (priv);
return -1;
}
diff --git a/xlators/mount/fuse/src/fuse-mem-types.h b/xlators/mount/fuse/src/fuse-mem-types.h
new file mode 100644
index 00000000000..b0eb816cd14
--- /dev/null
+++ b/xlators/mount/fuse/src/fuse-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 __FUSE_MEM_TYPES_H__
+#define __FUSE_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_fuse_mem_types_ {
+ gf_fuse_mt_iovec = gf_common_mt_end + 1,
+ gf_fuse_mt_fuse_private_t,
+ gf_fuse_mt_char,
+ gf_fuse_mt_iov_base,
+ gf_fuse_mt_fuse_state_t,
+ gf_fuse_mt_end
+};
+#endif
+