summaryrefslogtreecommitdiffstats
path: root/xlators/nfs/server
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/nfs/server
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/nfs/server')
-rw-r--r--xlators/nfs/server/src/mount3.c31
-rw-r--r--xlators/nfs/server/src/nfs-common.c11
-rw-r--r--xlators/nfs/server/src/nfs-mem-types.h46
-rw-r--r--xlators/nfs/server/src/nfs.c26
-rw-r--r--xlators/nfs/server/src/nfs3-helpers.c35
-rw-r--r--xlators/nfs/server/src/nfs3.c21
6 files changed, 124 insertions, 46 deletions
diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c
index db4a88e3d..c3792b314 100644
--- a/xlators/nfs/server/src/mount3.c
+++ b/xlators/nfs/server/src/mount3.c
@@ -36,6 +36,7 @@
#include "nfs-generics.h"
#include "locking.h"
#include "iatt.h"
+#include "nfs-mem-types.h"
#include <errno.h>
@@ -182,7 +183,7 @@ mnt3svc_update_mountlist (struct mount3_state *ms, rpcsvc_request_t *req,
if ((!ms) || (!req) || (!exportxl))
return -1;
- me = (struct mountentry *)CALLOC (1, sizeof (*me));
+ me = (struct mountentry *)GF_CALLOC (1, sizeof (*me), gf_nfs_mt_mountentry);
if (!me)
return -1;
@@ -203,7 +204,7 @@ mnt3svc_update_mountlist (struct mount3_state *ms, rpcsvc_request_t *req,
free_err:
if (ret == -1)
- FREE (me);
+ GF_FREE (me);
return ret;
}
@@ -387,14 +388,15 @@ __build_mountlist (struct mount3_state *ms, int *count)
gf_log (GF_MNT, GF_LOG_DEBUG, "Building mount list:");
list_for_each_entry (me, &ms->mountlist, mlist) {
namelen = strlen (me->exname);
- mlist = CALLOC (1, sizeof (*mlist));
+ mlist = GF_CALLOC (1, sizeof (*mlist), gf_nfs_mt_mountbody);
if (!mlist) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
goto free_list;
}
- mlist->ml_directory = CALLOC (namelen + 2, sizeof (char));
+ mlist->ml_directory = GF_CALLOC (namelen + 2, sizeof (char),
+ gf_nfs_mt_char);
if (!mlist->ml_directory) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
@@ -405,7 +407,8 @@ __build_mountlist (struct mount3_state *ms, int *count)
strcat (mlist->ml_directory, me->exname);
namelen = strlen (me->hostname);
- mlist->ml_hostname = CALLOC (namelen + 2, sizeof (char));
+ mlist->ml_hostname = GF_CALLOC (namelen + 2, sizeof (char),
+ gf_nfs_mt_char);
if (!mlist->ml_hostname) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
@@ -526,7 +529,7 @@ __mnt3svc_umount (struct mount3_state *ms, char *dirpath, char *hostname)
gf_log (GF_MNT, GF_LOG_DEBUG, "Unmounting: dir %s, host: %s",
me->exname, me->hostname);
list_del (&me->mlist);
- FREE (me);
+ GF_FREE (me);
ret = 0;
ret:
return ret;
@@ -635,7 +638,7 @@ __mnt3svc_umountall (struct mount3_state *ms)
list_for_each_entry (me, &ms->mountlist, mlist) {
list_del (&me->mlist);
- FREE (me);
+ GF_FREE (me);
}
return 0;
@@ -701,14 +704,15 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, xlator_list_t *cl)
while (cl) {
namelen = strlen (cl->xlator->name);
- elist = CALLOC (1, sizeof (*elist));
+ elist = GF_CALLOC (1, sizeof (*elist), gf_nfs_mt_exportnode);
if (!elist) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
goto free_list;
}
- elist->ex_dir = CALLOC (namelen + 2, sizeof (char));
+ elist->ex_dir = GF_CALLOC (namelen + 2, sizeof (char),
+ gf_nfs_mt_char);
if (!elist->ex_dir) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
@@ -720,11 +724,12 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, xlator_list_t *cl)
addrstr = rpcsvc_volume_allowed (svc->options,cl->xlator->name);
if (addrstr)
- addrstr = strdup (addrstr);
+ addrstr = gf_strdup (addrstr);
else
- addrstr = strdup ("No Access");
+ addrstr = gf_strdup ("No Access");
- elist->ex_groups = CALLOC (1, sizeof (struct groupnode));
+ elist->ex_groups = GF_CALLOC (1, sizeof (struct groupnode),
+ gf_nfs_mt_groupnode);
if (!elist->ex_groups) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation"
" failed");
@@ -801,7 +806,7 @@ mnt3_init_state (xlator_t *nfsx)
if (!nfsx)
return NULL;
- ms = CALLOC (1, sizeof (*ms));
+ ms = GF_CALLOC (1, sizeof (*ms), gf_nfs_mt_mount3_state);
if (!ms) {
gf_log (GF_MNT, GF_LOG_ERROR, "Memory allocation failed");
return NULL;
diff --git a/xlators/nfs/server/src/nfs-common.c b/xlators/nfs/server/src/nfs-common.c
index 3623f041c..69bf46702 100644
--- a/xlators/nfs/server/src/nfs-common.c
+++ b/xlators/nfs/server/src/nfs-common.c
@@ -30,6 +30,7 @@
#include "iobuf.h"
#include "nfs-common.h"
#include "nfs-fops.h"
+#include "nfs-mem-types.h"
#include "rpcsvc.h"
#include "iatt.h"
@@ -144,7 +145,7 @@ nfs_loc_wipe (loc_t *loc)
return;
if (loc->path) {
- FREE (loc->path);
+ GF_FREE ((char *)loc->path);
loc->path = NULL;
}
@@ -175,7 +176,7 @@ nfs_loc_copy (loc_t *dst, loc_t *src)
if (src->parent)
dst->parent = inode_ref (src->parent);
- dst->path = strdup (src->path);
+ dst->path = gf_strdup (src->path);
if (!dst->path)
goto out;
@@ -206,7 +207,7 @@ nfs_loc_fill (loc_t *loc, inode_t *inode, inode_t *parent, char *path)
if (parent)
loc->parent = inode_ref (parent);
- loc->path = strdup (path);
+ loc->path = gf_strdup (path);
if (!loc->path) {
gf_log (GF_NFS, GF_LOG_ERROR, "strdup failed");
goto loc_wipe;
@@ -258,7 +259,7 @@ err:
inode_unref (parent);
if (resolvedpath)
- FREE (resolvedpath);
+ GF_FREE (resolvedpath);
return ret;
}
@@ -370,7 +371,7 @@ err:
inode_unref (entryinode);
if (resolvedpath)
- FREE (resolvedpath);
+ GF_FREE (resolvedpath);
return ret;
}
diff --git a/xlators/nfs/server/src/nfs-mem-types.h b/xlators/nfs/server/src/nfs-mem-types.h
new file mode 100644
index 000000000..118ee2d23
--- /dev/null
+++ b/xlators/nfs/server/src/nfs-mem-types.h
@@ -0,0 +1,46 @@
+/*
+ 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 __NFS_MEM_TYPES_H__
+#define __NFS_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_nfs_mem_types_ {
+ gf_nfs_mt_mountentry = gf_common_mt_end + 1,
+ gf_nfs_mt_mountbody,
+ gf_nfs_mt_nfs_state,
+ gf_nfs_mt_char,
+ gf_nfs_mt_exportnode,
+ gf_nfs_mt_groupnode,
+ gf_nfs_mt_mount3_state,
+ gf_nfs_mt_write3args,
+ gf_nfs_mt_nfs3_export,
+ gf_nfs_mt_nfs3_state,
+ gf_nfs_mt_entry3,
+ gf_nfs_mt_entryp3,
+ gf_nfs_mt_nfs3_fd_entry,
+ gf_nfs_mt_nfs_initer_list,
+ gf_nfs_mt_xlator_t,
+ gf_nfs_mt_list_head,
+ gf_nfs_mt_end
+};
+#endif
+
diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c
index b598b0c69..fa7edc9ff 100644
--- a/xlators/nfs/server/src/nfs.c
+++ b/xlators/nfs/server/src/nfs.c
@@ -38,6 +38,7 @@
#include "inode.h"
#include "mount3.h"
#include "nfs3.h"
+#include "nfs-mem-types.h"
/* Every NFS version must call this function with the init function
* for its particular version.
@@ -49,7 +50,7 @@ nfs_add_initer (struct list_head *list, nfs_version_initer_t init)
if ((!list) || (!init))
return -1;
- new = CALLOC (1, sizeof (*new));
+ new = GF_CALLOC (1, sizeof (*new), gf_nfs_mt_nfs_initer_list);
if (!new) {
gf_log (GF_NFS, GF_LOG_ERROR, "Memory allocation failed");
return -1;
@@ -356,7 +357,8 @@ nfs_init_subvolumes (struct nfs_state *nfs, xlator_list_t *cl)
}
LOCK_INIT (&nfs->svinitlock);
- nfs->initedxl = CALLOC (svcount, sizeof (xlator_t *));
+ nfs->initedxl = GF_CALLOC (svcount, sizeof (xlator_t *),
+ gf_nfs_mt_xlator_t );
if (!nfs->initedxl) {
gf_log (GF_NFS, GF_LOG_ERROR, "Failed to allocated inited xls");
ret = -1;
@@ -435,6 +437,24 @@ nfs_request_user_init (nfs_user_t *nfu, rpcsvc_request_t *req)
return;
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_nfs_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) {
@@ -452,7 +472,7 @@ init (xlator_t *this) {
return -1;
}
- nfs = CALLOC (1, sizeof (*nfs));
+ nfs = GF_CALLOC (1, sizeof (*nfs), gf_nfs_mt_nfs_state);
if (!nfs) {
gf_log (GF_NFS, GF_LOG_ERROR, "memory allocation failed");
return -1;
diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c
index 72861dfd0..52bb7169a 100644
--- a/xlators/nfs/server/src/nfs3-helpers.c
+++ b/xlators/nfs/server/src/nfs3-helpers.c
@@ -33,6 +33,7 @@
#include "nfs-inodes.h"
#include "nfs-generics.h"
#include "nfs3-helpers.h"
+#include "nfs-mem-types.h"
#include "iatt.h"
#include <string.h>
@@ -708,16 +709,17 @@ nfs3_fill_entry3 (gf_dirent_t *entry)
if (!entry)
return NULL;
- ent = CALLOC (1, sizeof (*ent));
+ ent = GF_CALLOC (1, sizeof (*ent), gf_nfs_mt_entry3);
if (!ent)
return NULL;
gf_log (GF_NFS3, GF_LOG_TRACE, "Entry: %s", entry->d_name);
ent->fileid = entry->d_ino;
ent->cookie = entry->d_off;
- ent->name = CALLOC ((strlen (entry->d_name) + 1), sizeof (char));
+ ent->name = GF_CALLOC ((strlen (entry->d_name) + 1), sizeof (char),
+ gf_nfs_mt_char);
if (!ent->name) {
- FREE (ent);
+ GF_FREE (ent);
ent = NULL;
goto err;
}
@@ -754,7 +756,7 @@ nfs3_fh_to_post_op_fh3 (struct nfs3_fh *fh)
pfh.handle_follows = 1;
- fhp = CALLOC (1, sizeof (*fh));
+ fhp = GF_CALLOC (1, sizeof (*fh), gf_nfs_mt_char);
if (!fhp)
return pfh;
@@ -775,15 +777,16 @@ nfs3_fill_entryp3 (gf_dirent_t *entry, struct nfs3_fh *dirfh)
gf_log (GF_NFS3, GF_LOG_TRACE, "Entry: %s, ino: %"PRIu64,
entry->d_name, entry->d_ino);
- ent = CALLOC (1, sizeof (*ent));
+ ent = GF_CALLOC (1, sizeof (*ent), gf_nfs_mt_entryp3);
if (!ent)
return NULL;
ent->fileid = entry->d_ino;
ent->cookie = entry->d_off;
- ent->name = CALLOC ((strlen (entry->d_name) + 1), sizeof (char));
+ ent->name = GF_CALLOC ((strlen (entry->d_name) + 1), sizeof (char),
+ gf_nfs_mt_char);
if (!ent->name) {
- FREE (ent);
+ GF_FREE (ent);
ent = NULL;
goto err;
}
@@ -937,9 +940,9 @@ nfs3_free_readdirp3res (readdirp3res *res)
while (ent) {
next = ent->nextentry;
- FREE (ent->name);
- FREE (ent->name_handle.post_op_fh3_u.handle.data.data_val);
- FREE (ent);
+ GF_FREE (ent->name);
+ GF_FREE (ent->name_handle.post_op_fh3_u.handle.data.data_val);
+ GF_FREE (ent);
ent = next;
}
@@ -960,8 +963,8 @@ nfs3_free_readdir3res (readdir3res *res)
while (ent) {
next = ent->nextentry;
- FREE (ent->name);
- FREE (ent);
+ GF_FREE (ent->name);
+ GF_FREE (ent);
ent = next;
}
@@ -1810,7 +1813,7 @@ __nfs3_fdcache_remove_entry (struct nfs3_state *nfs3, struct nfs3_fd_entry *fde)
list_del (&fde->list);
fd_ctx_del (fde->cachedfd, nfs3->nfsx, NULL);
fd_unref (fde->cachedfd);
- FREE (fde);
+ GF_FREE (fde);
--nfs3->fdcount;
return 0;
@@ -1869,7 +1872,7 @@ nfs3_fdcache_add (struct nfs3_state *nfs3, fd_t *fd)
if ((!nfs3) || (!fd))
return -1;
- fde = CALLOC (1, sizeof (*fd));
+ fde = GF_CALLOC (1, sizeof (*fd), gf_nfs_mt_nfs3_fd_entry);
if (!fde) {
gf_log (GF_NFS3, GF_LOG_ERROR, "fd entry allocation failed");
goto out;
@@ -1939,7 +1942,7 @@ __nfs3_queue_call_state (nfs3_call_state_t *cs)
goto attach_cs;
}
- inode_q = CALLOC (1, sizeof (*inode_q));
+ inode_q = GF_CALLOC (1, sizeof (*inode_q), gf_nfs_mt_list_head);
if (!inode_q)
goto err;
@@ -2844,7 +2847,7 @@ nfs3_fh_resolve_and_resume (nfs3_call_state_t *cs, struct nfs3_fh *fh,
if (!entry)
ret = nfs3_fh_resolve_inode (cs);
else {
- cs->resolventry = strdup (entry);
+ cs->resolventry = gf_strdup (entry);
if (!cs->resolventry)
goto err;
diff --git a/xlators/nfs/server/src/nfs3.c b/xlators/nfs/server/src/nfs3.c
index 57d9f576e..a4ef1c6fc 100644
--- a/xlators/nfs/server/src/nfs3.c
+++ b/xlators/nfs/server/src/nfs3.c
@@ -36,6 +36,7 @@
#include "nfs-inodes.h"
#include "nfs-generics.h"
#include "nfs3-helpers.h"
+#include "nfs-mem-types.h"
#include <sys/socket.h>
@@ -203,10 +204,10 @@ nfs3_call_state_wipe (nfs3_call_state_t *cs)
fd_unref (cs->resolve_dir_fd);
if (cs->resolventry)
- FREE (cs->resolventry);
+ GF_FREE (cs->resolventry);
if (cs->pathname)
- FREE (cs->pathname);
+ GF_FREE (cs->pathname);
if (!list_empty (&cs->entries.list))
gf_dirent_free (&cs->entries);
@@ -1810,7 +1811,7 @@ nfs3svc_write_vecsizer (rpcsvc_request_t *req, ssize_t *readsize, int *newbuf)
rpcsvc_request_set_private (req, NFS3_VECWRITE_READREST);
ret = 0;
} else if (state == NFS3_VECWRITE_READREST) {
- args = CALLOC (1, sizeof (*args));
+ args = GF_CALLOC (1, sizeof (*args), gf_nfs_mt_write3args);
if (!args)
goto rpcerr;
@@ -2490,7 +2491,7 @@ nfs3_symlink (rpcsvc_request_t *req, struct nfs3_fh *dirfh, char *name,
nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err);
cs->parent = *dirfh;
- cs->pathname = strdup (target);
+ cs->pathname = gf_strdup (target);
if (!cs->pathname) {
ret = -1;
stat = NFS3ERR_SERVERFAULT;
@@ -3284,7 +3285,7 @@ nfs3_rename (rpcsvc_request_t *req, struct nfs3_fh *olddirfh, char *oldname,
* of the dest (fh,name) pair.
*/
cs->fh = *newdirfh;
- cs->pathname = strdup (newname);
+ cs->pathname = gf_strdup (newname);
if (!cs->pathname) {
stat = NFS3ERR_SERVERFAULT;
ret = -1;
@@ -3470,7 +3471,7 @@ nfs3_link (rpcsvc_request_t *req, struct nfs3_fh *targetfh,
nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err);
cs->fh = *dirfh;
- cs->pathname = strdup (newname);
+ cs->pathname = gf_strdup (newname);
if (!cs->pathname) {
stat = NFS3ERR_SERVERFAULT;
ret = -1;
@@ -4735,7 +4736,8 @@ nfs3_init_subvolumes (struct nfs3_state *nfs3, xlator_t *nfsx)
xl_list = xl_list->next;
}
- nfs3->exports = CALLOC (xl_count, sizeof (struct nfs3_export));
+ nfs3->exports = GF_CALLOC (xl_count, sizeof (struct nfs3_export),
+ gf_nfs_mt_nfs3_export);
if (!nfs3->exports) {
gf_log (GF_NFS3, GF_LOG_ERROR, "Memory allocation failed");
goto err;
@@ -4772,7 +4774,8 @@ nfs3_init_state (xlator_t *nfsx)
if (!nfsx)
return NULL;
- nfs3 = (struct nfs3_state *)CALLOC (1, sizeof (*nfs3));
+ nfs3 = (struct nfs3_state *)GF_CALLOC (1, sizeof (*nfs3),
+ gf_nfs_mt_nfs3_state);
if (!nfs3) {
gf_log (GF_NFS3, GF_LOG_ERROR, "Memory allocation failed");
return NULL;
@@ -4817,7 +4820,7 @@ free_localpool:
ret:
if (ret == -1) {
- FREE (nfs3);
+ GF_FREE (nfs3);
nfs3 = NULL;
}