From 582de0677da4be19fc6f873625c58c45d069ab1c Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Thu, 22 Apr 2010 13:33:09 +0000 Subject: Memory accounting changes Memory accounting Changes. Thanks to Vinayak Hegde and Csaba Henk for their contributions. Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 329 (Replacing memory allocation functions with mem-type functions) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=329 --- xlators/cluster/afr/src/afr-dir-read.c | 19 +-- xlators/cluster/afr/src/afr-dir-write.c | 8 +- xlators/cluster/afr/src/afr-inode-read.c | 6 +- xlators/cluster/afr/src/afr-inode-write.c | 2 +- xlators/cluster/afr/src/afr-mem-types.h | 46 ++++++ xlators/cluster/afr/src/afr-self-heal-algorithm.c | 35 ++-- xlators/cluster/afr/src/afr-self-heal-common.c | 67 +++++--- xlators/cluster/afr/src/afr-self-heal-data.c | 16 +- xlators/cluster/afr/src/afr-self-heal-entry.c | 22 +-- xlators/cluster/afr/src/afr-self-heal-metadata.c | 5 +- xlators/cluster/afr/src/afr.c | 137 ++++++++++------ xlators/cluster/afr/src/afr.h | 52 +++--- xlators/cluster/dht/src/dht-common.c | 9 +- xlators/cluster/dht/src/dht-common.h | 2 + xlators/cluster/dht/src/dht-helper.c | 9 +- xlators/cluster/dht/src/dht-layout.c | 13 +- xlators/cluster/dht/src/dht-mem-types.h | 42 +++++ xlators/cluster/dht/src/dht-selfheal.c | 2 +- xlators/cluster/dht/src/dht.c | 51 ++++-- xlators/cluster/dht/src/nufa.c | 32 ++-- xlators/cluster/dht/src/switch.c | 78 +++++---- xlators/cluster/ha/src/ha-helpers.c | 11 +- xlators/cluster/ha/src/ha-mem-types.h | 37 +++++ xlators/cluster/ha/src/ha.c | 167 +++++++++++-------- xlators/cluster/ha/src/ha.h | 2 + xlators/cluster/map/src/map-helper.c | 5 +- xlators/cluster/map/src/map-mem-types.h | 35 ++++ xlators/cluster/map/src/map.c | 48 ++++-- xlators/cluster/map/src/map.h | 1 + xlators/cluster/stripe/src/stripe-mem-types.h | 40 +++++ xlators/cluster/stripe/src/stripe.c | 178 ++++++++++++++------- xlators/cluster/stripe/src/stripe.h | 1 + xlators/cluster/unify/src/unify-mem-types.h | 41 +++++ xlators/cluster/unify/src/unify-self-heal.c | 90 ++++++----- xlators/cluster/unify/src/unify.c | 94 +++++++---- xlators/cluster/unify/src/unify.h | 3 +- xlators/debug/io-stats/src/io-stats-mem-types.h | 33 ++++ xlators/debug/io-stats/src/io-stats.c | 41 +++-- xlators/debug/trace/src/trace.c | 70 ++++---- xlators/features/filter/src/filter-mem-types.h | 30 ++++ xlators/features/filter/src/filter.c | 48 ++++-- xlators/features/locks/src/common.c | 49 +++--- xlators/features/locks/src/entrylk.c | 29 ++-- xlators/features/locks/src/inodelk.c | 9 +- xlators/features/locks/src/locks-mem-types.h | 39 +++++ xlators/features/locks/src/locks.h | 1 + xlators/features/locks/src/posix.c | 60 ++++--- .../features/path-convertor/src/path-mem-types.h | 32 ++++ xlators/features/path-convertor/src/path.c | 88 ++++++---- xlators/features/quota/src/quota-mem-types.h | 31 ++++ xlators/features/quota/src/quota.c | 40 ++++- xlators/features/trash/src/trash-mem-types.h | 33 ++++ xlators/features/trash/src/trash.c | 83 +++++----- xlators/meta/src/meta-mem-types.h | 35 ++++ xlators/meta/src/meta.c | 61 ++++--- xlators/meta/src/tree.c | 23 +-- xlators/mount/fuse/src/fuse-bridge.c | 81 ++++++---- xlators/mount/fuse/src/fuse-mem-types.h | 35 ++++ xlators/nfs/lib/src/rpcsvc-auth.c | 12 +- xlators/nfs/lib/src/rpcsvc.c | 32 ++-- xlators/nfs/lib/src/xdr-nfs3.c | 18 +-- xlators/nfs/server/src/mount3.c | 31 ++-- xlators/nfs/server/src/nfs-common.c | 11 +- xlators/nfs/server/src/nfs-mem-types.h | 46 ++++++ xlators/nfs/server/src/nfs.c | 26 ++- xlators/nfs/server/src/nfs3-helpers.c | 35 ++-- xlators/nfs/server/src/nfs3.c | 21 +-- xlators/performance/io-cache/src/io-cache.c | 77 ++++++--- xlators/performance/io-cache/src/ioc-inode.c | 10 +- xlators/performance/io-cache/src/ioc-mem-types.h | 40 +++++ xlators/performance/io-cache/src/page.c | 39 +++-- xlators/performance/io-threads/src/io-threads.c | 25 ++- xlators/performance/io-threads/src/io-threads.h | 1 + xlators/performance/io-threads/src/iot-mem-types.h | 31 ++++ .../quick-read/src/quick-read-mem-types.h | 35 ++++ xlators/performance/quick-read/src/quick-read.c | 72 ++++++--- xlators/performance/quick-read/src/quick-read.h | 1 + xlators/performance/read-ahead/src/page.c | 40 +++-- .../read-ahead/src/read-ahead-mem-types.h | 37 +++++ xlators/performance/read-ahead/src/read-ahead.c | 33 +++- xlators/performance/read-ahead/src/read-ahead.h | 1 + .../stat-prefetch/src/stat-prefetch-mem-types.h | 36 +++++ .../performance/stat-prefetch/src/stat-prefetch.c | 84 ++++++---- .../performance/stat-prefetch/src/stat-prefetch.h | 1 + .../write-behind/src/write-behind-mem-types.h | 35 ++++ .../performance/write-behind/src/write-behind.c | 81 +++++++--- xlators/protocol/client/src/client-mem-types.h | 43 +++++ xlators/protocol/client/src/client-protocol.c | 178 ++++++++++++--------- xlators/protocol/client/src/saved-frames.c | 13 +- xlators/protocol/server/src/server-helpers.c | 97 +++++------ xlators/protocol/server/src/server-mem-types.h | 39 +++++ xlators/protocol/server/src/server-protocol.c | 164 +++++++++++-------- xlators/protocol/server/src/server-protocol.h | 1 + xlators/protocol/server/src/server-resolve.c | 11 +- xlators/storage/bdb/src/bctx.c | 14 +- xlators/storage/bdb/src/bdb-ll.c | 48 +++--- xlators/storage/bdb/src/bdb-mem-types.h | 42 +++++ xlators/storage/bdb/src/bdb.c | 95 ++++++----- xlators/storage/posix/src/posix-mem-types.h | 36 +++++ xlators/storage/posix/src/posix.c | 140 +++++++++------- xlators/storage/posix/src/posix.h | 2 + 101 files changed, 2952 insertions(+), 1239 deletions(-) create mode 100644 xlators/cluster/afr/src/afr-mem-types.h create mode 100644 xlators/cluster/dht/src/dht-mem-types.h create mode 100644 xlators/cluster/ha/src/ha-mem-types.h create mode 100644 xlators/cluster/map/src/map-mem-types.h create mode 100644 xlators/cluster/stripe/src/stripe-mem-types.h create mode 100644 xlators/cluster/unify/src/unify-mem-types.h create mode 100644 xlators/debug/io-stats/src/io-stats-mem-types.h create mode 100644 xlators/features/filter/src/filter-mem-types.h create mode 100644 xlators/features/locks/src/locks-mem-types.h create mode 100644 xlators/features/path-convertor/src/path-mem-types.h create mode 100644 xlators/features/quota/src/quota-mem-types.h create mode 100644 xlators/features/trash/src/trash-mem-types.h create mode 100644 xlators/meta/src/meta-mem-types.h create mode 100644 xlators/mount/fuse/src/fuse-mem-types.h create mode 100644 xlators/nfs/server/src/nfs-mem-types.h create mode 100644 xlators/performance/io-cache/src/ioc-mem-types.h create mode 100644 xlators/performance/io-threads/src/iot-mem-types.h create mode 100644 xlators/performance/quick-read/src/quick-read-mem-types.h create mode 100644 xlators/performance/read-ahead/src/read-ahead-mem-types.h create mode 100644 xlators/performance/stat-prefetch/src/stat-prefetch-mem-types.h create mode 100644 xlators/performance/write-behind/src/write-behind-mem-types.h create mode 100644 xlators/protocol/client/src/client-mem-types.h create mode 100644 xlators/protocol/server/src/server-mem-types.h create mode 100644 xlators/storage/bdb/src/bdb-mem-types.h create mode 100644 xlators/storage/posix/src/posix-mem-types.h (limited to 'xlators') diff --git a/xlators/cluster/afr/src/afr-dir-read.c b/xlators/cluster/afr/src/afr-dir-read.c index 501cc3e8..0f9bdf59 100644 --- a/xlators/cluster/afr/src/afr-dir-read.c +++ b/xlators/cluster/afr/src/afr-dir-read.c @@ -188,8 +188,9 @@ afr_examine_dir (call_frame_t *frame, xlator_t *this) local = frame->local; priv = this->private; - local->cont.opendir.checksum = CALLOC (priv->child_count, - sizeof (*local->cont.opendir.checksum)); + local->cont.opendir.checksum = GF_CALLOC (priv->child_count, + sizeof (*local->cont.opendir.checksum), + gf_afr_mt_int32_t); call_count = afr_up_children_count (priv->child_count, local->child_up); @@ -387,8 +388,8 @@ afr_remember_entries (gf_dirent_t *entries, fd_t *fd) fd_ctx = (afr_fd_ctx_t *)(long) ctx; list_for_each_entry (entry, &entries->list, list) { - n = CALLOC (1, sizeof (*n)); - n->name = strdup (entry->d_name); + n = GF_CALLOC (1, sizeof (*n), gf_afr_mt_entry_name); + n->name = gf_strdup (entry->d_name); INIT_LIST_HEAD (&n->list); list_add (&n->list, &fd_ctx->entries); @@ -421,7 +422,7 @@ afr_filter_entries (gf_dirent_t *entries, fd_t *fd) if (remembered_name (entry->d_name, &fd_ctx->entries)) { list_del (&entry->list); - FREE (entry); + GF_FREE (entry); } } @@ -448,9 +449,9 @@ afr_forget_entries (fd_t *fd) fd_ctx = (afr_fd_ctx_t *)(long) ctx; list_for_each_entry_safe (entry, tmp, &fd_ctx->entries, list) { - FREE (entry->name); + GF_FREE (entry->name); list_del (&entry->list); - FREE (entry); + GF_FREE (entry); } } @@ -485,7 +486,7 @@ afr_readdir_cbk (call_frame_t *frame, void *cookie, if ((local->fd->inode == local->fd->inode->table->root) && !strcmp (entry->d_name, GF_REPLICATE_TRASH_DIR)) { list_del_init (&entry->list); - FREE (entry); + GF_FREE (entry); } } } @@ -571,7 +572,7 @@ afr_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if ((local->fd->inode == local->fd->inode->table->root) && !strcmp (entry->d_name, GF_REPLICATE_TRASH_DIR)) { list_del_init (&entry->list); - FREE (entry); + GF_FREE (entry); } } } diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c index 9d7e74e7..439e8d8c 100644 --- a/xlators/cluster/afr/src/afr-dir-write.c +++ b/xlators/cluster/afr/src/afr-dir-write.c @@ -58,9 +58,9 @@ afr_build_parent_loc (loc_t *parent, loc_t *child) return; } - tmp = strdup (child->path); - parent->path = strdup (dirname (tmp)); - FREE (tmp); + tmp = gf_strdup (child->path); + parent->path = gf_strdup (dirname (tmp)); + GF_FREE (tmp); parent->name = strrchr (parent->path, '/'); if (parent->name) @@ -1315,7 +1315,7 @@ afr_symlink (call_frame_t *frame, xlator_t *this, } UNLOCK (&priv->read_child_lock); - local->cont.symlink.linkpath = strdup (linkpath); + local->cont.symlink.linkpath = gf_strdup (linkpath); if (loc->parent) local->cont.symlink.parent_ino = loc->parent->ino; diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c index 9ce10367..b1bbac10 100644 --- a/xlators/cluster/afr/src/afr-inode-read.c +++ b/xlators/cluster/afr/src/afr-inode-read.c @@ -566,7 +566,7 @@ __gather_xattr_keys (dict_t *dict, char *key, data_t *value, if (!strncmp (key, AFR_XATTR_PREFIX, strlen (AFR_XATTR_PREFIX))) { - xkey = CALLOC (1, sizeof (*xkey)); + xkey = GF_CALLOC (1, sizeof (*xkey), gf_afr_mt_xattr_key); if (!xkey) return; @@ -596,7 +596,7 @@ __filter_xattrs (dict_t *dict) list_del_init (&key->list); - FREE (key); + GF_FREE (key); } } @@ -713,7 +713,7 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, loc_copy (&local->loc, loc); if (name) - local->cont.getxattr.name = strdup (name); + local->cont.getxattr.name = gf_strdup (name); STACK_WIND_COOKIE (frame, afr_getxattr_cbk, (void *) (long) call_child, diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index e28fe5f8..37909181 100644 --- a/xlators/cluster/afr/src/afr-inode-write.c +++ b/xlators/cluster/afr/src/afr-inode-write.c @@ -1600,7 +1600,7 @@ afr_removexattr (call_frame_t *frame, xlator_t *this, local->op_ret = -1; - local->cont.removexattr.name = strdup (name); + local->cont.removexattr.name = gf_strdup (name); local->transaction.fop = afr_removexattr_wind; local->transaction.done = afr_removexattr_done; diff --git a/xlators/cluster/afr/src/afr-mem-types.h b/xlators/cluster/afr/src/afr-mem-types.h new file mode 100644 index 00000000..27117c18 --- /dev/null +++ b/xlators/cluster/afr/src/afr-mem-types.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __AFR_MEM_TYPES_H__ +#define __AFR_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_afr_mem_types_ { + gf_afr_mt_iovec = gf_common_mt_end + 1, + gf_afr_mt_afr_fd_ctx_t, + gf_afr_mt_afr_local_t, + gf_afr_mt_afr_private_t, + gf_afr_mt_int32_t, + gf_afr_mt_char, + gf_afr_mt_xattr_key, + gf_afr_mt_dict_t, + gf_afr_mt_xlator_t, + gf_afr_mt_stat, + gf_afr_mt_int, + gf_afr_mt_afr_node_character, + gf_afr_mt_sh_diff_loop_state, + gf_afr_mt_uint8_t, + gf_afr_mt_loc_t, + gf_afr_mt_entry_name, + gf_afr_mt_end +}; +#endif + diff --git a/xlators/cluster/afr/src/afr-self-heal-algorithm.c b/xlators/cluster/afr/src/afr-self-heal-algorithm.c index f840c1bb..ef9d4026 100644 --- a/xlators/cluster/afr/src/afr-self-heal-algorithm.c +++ b/xlators/cluster/afr/src/afr-self-heal-algorithm.c @@ -66,7 +66,7 @@ sh_full_private_cleanup (call_frame_t *frame, xlator_t *this) sh_priv = sh->private; if (sh_priv) - FREE (sh_priv); + GF_FREE (sh_priv); } @@ -384,7 +384,8 @@ afr_sh_algo_full (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - sh_priv = CALLOC (1, sizeof (*sh_priv)); + sh_priv = GF_CALLOC (1, sizeof (*sh_priv), + gf_afr_mt_afr_private_t); LOCK_INIT (&sh_priv->lock); @@ -422,18 +423,18 @@ sh_diff_private_cleanup (call_frame_t *frame, xlator_t *this) for (i = 0; i < priv->data_self_heal_window_size; i++) { if (sh_priv->loops[i]) { if (sh_priv->loops[i]->write_needed) - FREE (sh_priv->loops[i]->write_needed); + GF_FREE (sh_priv->loops[i]->write_needed); if (sh_priv->loops[i]->checksum) - FREE (sh_priv->loops[i]->checksum); + GF_FREE (sh_priv->loops[i]->checksum); } } if (sh_priv) { if (sh_priv->loops) - FREE (sh_priv->loops); + GF_FREE (sh_priv->loops); - FREE (sh_priv); + GF_FREE (sh_priv); } @@ -1034,7 +1035,8 @@ afr_sh_algo_diff (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - sh_priv = CALLOC (1, sizeof (*sh_priv)); + sh_priv = GF_CALLOC (1, sizeof (*sh_priv), + gf_afr_mt_afr_private_t); sh_priv->block_size = this->ctx->page_size; @@ -1044,16 +1046,19 @@ afr_sh_algo_diff (call_frame_t *frame, xlator_t *this) local->call_count = 0; - sh_priv->loops = CALLOC (priv->data_self_heal_window_size, - sizeof (*sh_priv->loops)); + sh_priv->loops = GF_CALLOC (priv->data_self_heal_window_size, + sizeof (*sh_priv->loops), + gf_afr_mt_sh_diff_loop_state); for (i = 0; i < priv->data_self_heal_window_size; i++) { - sh_priv->loops[i] = CALLOC (1, sizeof (*sh_priv->loops[i])); - - sh_priv->loops[i]->checksum = CALLOC (priv->child_count, - MD5_DIGEST_LEN); - sh_priv->loops[i]->write_needed = CALLOC (priv->child_count, - sizeof (*sh_priv->loops[i]->write_needed)); + sh_priv->loops[i] = GF_CALLOC (1, sizeof (*sh_priv->loops[i]), + gf_afr_mt_sh_diff_loop_state); + + sh_priv->loops[i]->checksum = GF_CALLOC (priv->child_count, + MD5_DIGEST_LEN, gf_afr_mt_uint8_t); + sh_priv->loops[i]->write_needed = GF_CALLOC (priv->child_count, + sizeof (*sh_priv->loops[i]->write_needed), + gf_afr_mt_char); } sh_diff_loop_driver (frame, this); diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index 5115a730..30e1708c 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -98,7 +98,7 @@ afr_sh_print_pending_matrix (int32_t *pending_matrix[], xlator_t *this) int i, j; /* 10 digits per entry + 1 space + '[' and ']' */ - buf = MALLOC (priv->child_count * 11 + 8); + buf = GF_MALLOC (priv->child_count * 11 + 8, gf_afr_mt_char); for (i = 0; i < priv->child_count; i++) { ptr = buf; @@ -111,7 +111,7 @@ afr_sh_print_pending_matrix (int32_t *pending_matrix[], xlator_t *this) "pending_matrix: %s", buf); } - FREE (buf); + GF_FREE (buf); } @@ -129,7 +129,8 @@ afr_sh_build_pending_matrix (afr_private_t *priv, unsigned char *ignorant_subvols = NULL; - ignorant_subvols = CALLOC (sizeof (*ignorant_subvols), child_count); + ignorant_subvols = GF_CALLOC (sizeof (*ignorant_subvols), child_count, + gf_afr_mt_char); /* start clean */ for (i = 0; i < child_count; i++) { @@ -177,7 +178,7 @@ afr_sh_build_pending_matrix (afr_private_t *priv, } } - FREE (ignorant_subvols); + GF_FREE (ignorant_subvols); } @@ -479,8 +480,9 @@ afr_sh_mark_sources (afr_self_heal_t *sh, int child_count, /* stores the 'characters' (innocent, fool, wise) of the nodes */ afr_node_character * - characters = CALLOC (sizeof (afr_node_character), - child_count); + characters = GF_CALLOC (sizeof (afr_node_character), + child_count, + gf_afr_mt_afr_node_character) ; /* start clean */ for (i = 0; i < child_count; i++) { @@ -543,7 +545,7 @@ afr_sh_mark_sources (afr_self_heal_t *sh, int child_count, } out: - FREE (characters); + GF_FREE (characters); return nsources; } @@ -612,7 +614,8 @@ afr_sh_delta_to_xattr (afr_private_t *priv, continue; for (j = 0; j < child_count; j++) { - pending = CALLOC (sizeof (int32_t), 3); + pending = GF_CALLOC (sizeof (int32_t), 3, + gf_afr_mt_int32_t); /* 3 = data+metadata+entry */ k = afr_index_for_transaction_type (type); @@ -882,7 +885,7 @@ sh_destroy_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (parent_loc) { loc_wipe (parent_loc); - FREE (parent_loc); + GF_FREE (parent_loc); } call_count = afr_frame_return (frame); @@ -935,7 +938,8 @@ sh_missing_entries_newentry_cbk (call_frame_t *frame, void *cookie, if (op_ret == 0) { setattr_frame = copy_frame (frame); - setattr_frame->local = CALLOC (1, sizeof (afr_local_t)); + setattr_frame->local = GF_CALLOC (1, sizeof (afr_local_t), + gf_afr_mt_afr_local_t); ((afr_local_t *)setattr_frame->local)->call_count = 2; @@ -950,7 +954,8 @@ sh_missing_entries_newentry_cbk (call_frame_t *frame, void *cookie, &local->loc, &stbuf, valid); valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - parent_loc = CALLOC (1, sizeof (*parent_loc)); + parent_loc = GF_CALLOC (1, sizeof (*parent_loc), + gf_afr_mt_loc_t); afr_build_parent_loc (parent_loc, &local->loc); STACK_WIND_COOKIE (setattr_frame, sh_destroy_cbk, @@ -1452,7 +1457,9 @@ afr_local_t *afr_local_copy (afr_local_t *l, xlator_t *this) sh = &l->self_heal; - lc = CALLOC (1, sizeof (afr_local_t)); + lc = GF_CALLOC (1, sizeof (afr_local_t), + gf_afr_mt_afr_local_t); + shc = &lc->self_heal; shc->unwind = sh->unwind; @@ -1567,23 +1574,35 @@ afr_self_heal (call_frame_t *frame, xlator_t *this) sh->completion_cbk = afr_self_heal_completion_cbk; - sh->buf = CALLOC (priv->child_count, sizeof (struct stat)); - sh->child_errno = CALLOC (priv->child_count, sizeof (int)); - sh->success = CALLOC (priv->child_count, sizeof (int)); - sh->xattr = CALLOC (priv->child_count, sizeof (dict_t *)); - sh->sources = CALLOC (priv->child_count, sizeof (*sh->sources)); - sh->locked_nodes = CALLOC (priv->child_count, sizeof (*sh->locked_nodes)); + sh->buf = GF_CALLOC (priv->child_count, sizeof (struct stat), + gf_afr_mt_stat); + sh->child_errno = GF_CALLOC (priv->child_count, sizeof (int), + gf_afr_mt_int); + sh->success = GF_CALLOC (priv->child_count, sizeof (int), + gf_afr_mt_int); + sh->xattr = GF_CALLOC (priv->child_count, sizeof (dict_t *), + gf_afr_mt_dict_t); + sh->sources = GF_CALLOC (sizeof (*sh->sources), priv->child_count, + gf_afr_mt_int); + sh->locked_nodes = GF_CALLOC (sizeof (*sh->locked_nodes), + priv->child_count, + gf_afr_mt_int); + + sh->pending_matrix = GF_CALLOC (sizeof (int32_t *), priv->child_count, + gf_afr_mt_int32_t); - sh->pending_matrix = CALLOC (sizeof (int32_t *), priv->child_count); for (i = 0; i < priv->child_count; i++) { - sh->pending_matrix[i] = CALLOC (sizeof (int32_t), - priv->child_count); + sh->pending_matrix[i] = GF_CALLOC (sizeof (int32_t), + priv->child_count, + gf_afr_mt_int32_t); } - sh->delta_matrix = CALLOC (sizeof (int32_t *), priv->child_count); + sh->delta_matrix = GF_CALLOC (sizeof (int32_t *), priv->child_count, + gf_afr_mt_int32_t); for (i = 0; i < priv->child_count; i++) { - sh->delta_matrix[i] = CALLOC (sizeof (int32_t), - priv->child_count); + sh->delta_matrix[i] = GF_CALLOC (sizeof (int32_t), + priv->child_count, + gf_afr_mt_int32_t); } if (local->success_count && local->enoent_count) { diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c index 2d74ed1e..e29c1def 100644 --- a/xlators/cluster/afr/src/afr-self-heal-data.c +++ b/xlators/cluster/afr/src/afr-self-heal-data.c @@ -387,7 +387,8 @@ afr_sh_data_erase_pending (call_frame_t *frame, xlator_t *this) afr_sh_pending_to_delta (priv, sh->xattr, sh->delta_matrix, sh->success, priv->child_count, AFR_DATA_TRANSACTION); - erase_xattr = CALLOC (sizeof (*erase_xattr), priv->child_count); + erase_xattr = GF_CALLOC (sizeof (*erase_xattr), priv->child_count, + gf_afr_mt_dict_t); for (i = 0; i < priv->child_count; i++) { if (sh->xattr[i]) { @@ -425,7 +426,7 @@ afr_sh_data_erase_pending (call_frame_t *frame, xlator_t *this) dict_unref (erase_xattr[i]); } } - FREE (erase_xattr); + GF_FREE (erase_xattr); return 0; } @@ -766,13 +767,16 @@ afr_self_heal_get_source (xlator_t *this, afr_local_t *local, dict_t **xattr) sh = &local->self_heal; priv = this->private; - sh->pending_matrix = CALLOC (sizeof (int32_t *), priv->child_count); + sh->pending_matrix = GF_CALLOC (sizeof (int32_t *), priv->child_count, + gf_afr_mt_int32_t); for (i = 0; i < priv->child_count; i++) { - sh->pending_matrix[i] = CALLOC (sizeof (int32_t), - priv->child_count); + sh->pending_matrix[i] = GF_CALLOC (sizeof (int32_t), + priv->child_count, + gf_afr_mt_int32_t); } - sh->sources = CALLOC (priv->child_count, sizeof (*sh->sources)); + sh->sources = GF_CALLOC (priv->child_count, sizeof (*sh->sources), + gf_afr_mt_int32_t); afr_sh_build_pending_matrix (priv, sh->pending_matrix, xattr, priv->child_count, AFR_DATA_TRANSACTION); diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c index 4336c7a6..dcb8d0d7 100644 --- a/xlators/cluster/afr/src/afr-self-heal-entry.c +++ b/xlators/cluster/afr/src/afr-self-heal-entry.c @@ -236,7 +236,8 @@ afr_sh_entry_erase_pending (call_frame_t *frame, xlator_t *this) afr_sh_pending_to_delta (priv, sh->xattr, sh->delta_matrix, sh->success, priv->child_count, AFR_ENTRY_TRANSACTION); - erase_xattr = CALLOC (sizeof (*erase_xattr), priv->child_count); + erase_xattr = GF_CALLOC (sizeof (*erase_xattr), priv->child_count, + gf_afr_mt_dict_t); for (i = 0; i < priv->child_count; i++) { if (sh->xattr[i]) { @@ -277,7 +278,7 @@ afr_sh_entry_erase_pending (call_frame_t *frame, xlator_t *this) dict_unref (erase_xattr[i]); } } - FREE (erase_xattr); + GF_FREE (erase_xattr); if (need_unwind) afr_sh_entry_finish (frame, this); @@ -373,10 +374,10 @@ build_child_loc (xlator_t *this, loc_t *child, loc_t *parent, char *name) } if (strcmp (parent->path, "/") == 0) - ret = asprintf ((char **)&child->path, "/%s", name); + ret = gf_asprintf ((char **)&child->path, "/%s", name); else - ret = asprintf ((char **)&child->path, "%s/%s", parent->path, - name); + ret = gf_asprintf ((char **)&child->path, "%s/%s", + parent->path, name); if (-1 == ret) { gf_log (this->name, GF_LOG_ERROR, @@ -532,7 +533,7 @@ afr_sh_entry_expunge_rename_cbk (call_frame_t *expunge_frame, void *cookie, static void init_trash_loc (loc_t *trash_loc, inode_table_t *table) { - trash_loc->path = strdup ("/" GF_REPLICATE_TRASH_DIR); + trash_loc->path = gf_strdup ("/" GF_REPLICATE_TRASH_DIR); trash_loc->name = GF_REPLICATE_TRASH_DIR; trash_loc->parent = table->root; trash_loc->inode = inode_new (table); @@ -545,7 +546,8 @@ make_trash_path (const char *path) char *c = NULL; char *tp = NULL; - tp = CALLOC (strlen ("/" GF_REPLICATE_TRASH_DIR) + strlen (path) + 1, sizeof (char)); + tp = GF_CALLOC (strlen ("/" GF_REPLICATE_TRASH_DIR) + strlen (path) + 1, + sizeof (char), gf_afr_mt_char); strcpy (tp, GF_REPLICATE_TRASH_DIR); strcat (tp, path); @@ -1263,7 +1265,7 @@ afr_sh_entry_impunge_parent_setattr_cbk (call_frame_t *setattr_frame, loc_wipe (parent_loc); - FREE (parent_loc); + GF_FREE (parent_loc); AFR_STACK_DESTROY (setattr_frame); return 0; @@ -1336,7 +1338,7 @@ afr_sh_entry_impunge_newfile_cbk (call_frame_t *impunge_frame, void *cookie, parentbuf = impunge_sh->parentbuf; setattr_frame = copy_frame (impunge_frame); - parent_loc = CALLOC (1, sizeof (*parent_loc)); + parent_loc = GF_CALLOC (1, sizeof (*parent_loc), gf_afr_mt_loc_t); afr_build_parent_loc (parent_loc, &impunge_local->loc); STACK_WIND_COOKIE (impunge_frame, afr_sh_entry_impunge_xattrop_cbk, @@ -1668,7 +1670,7 @@ afr_sh_entry_impunge_readlink_cbk (call_frame_t *impunge_frame, void *cookie, goto out; } - impunge_sh->linkname = strdup (linkname); + impunge_sh->linkname = gf_strdup (linkname); afr_sh_entry_impunge_readlink_sink (impunge_frame, this, child_index); diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c index 57408cfa..4501595b 100644 --- a/xlators/cluster/afr/src/afr-self-heal-metadata.c +++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c @@ -225,7 +225,8 @@ afr_sh_metadata_erase_pending (call_frame_t *frame, xlator_t *this) sh->success, priv->child_count, AFR_METADATA_TRANSACTION); - erase_xattr = CALLOC (sizeof (*erase_xattr), priv->child_count); + erase_xattr = GF_CALLOC (sizeof (*erase_xattr), priv->child_count, + gf_afr_mt_dict_t); for (i = 0; i < priv->child_count; i++) { if (sh->xattr[i]) { @@ -272,7 +273,7 @@ afr_sh_metadata_erase_pending (call_frame_t *frame, xlator_t *this) dict_unref (erase_xattr[i]); } } - FREE (erase_xattr); + GF_FREE (erase_xattr); return 0; } diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index 4e266113..50728694 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -239,7 +239,7 @@ afr_local_sh_cleanup (afr_local_t *local, xlator_t *this) priv = this->private; if (sh->buf) - FREE (sh->buf); + GF_FREE (sh->buf); if (sh->xattr) { for (i = 0; i < priv->child_count; i++) { @@ -248,34 +248,34 @@ afr_local_sh_cleanup (afr_local_t *local, xlator_t *this) sh->xattr[i] = NULL; } } - FREE (sh->xattr); + GF_FREE (sh->xattr); } if (sh->child_errno) - FREE (sh->child_errno); + GF_FREE (sh->child_errno); if (sh->pending_matrix) { for (i = 0; i < priv->child_count; i++) { - FREE (sh->pending_matrix[i]); + GF_FREE (sh->pending_matrix[i]); } - FREE (sh->pending_matrix); + GF_FREE (sh->pending_matrix); } if (sh->delta_matrix) { for (i = 0; i < priv->child_count; i++) { - FREE (sh->delta_matrix[i]); + GF_FREE (sh->delta_matrix[i]); } - FREE (sh->delta_matrix); + GF_FREE (sh->delta_matrix); } if (sh->sources) - FREE (sh->sources); + GF_FREE (sh->sources); if (sh->success) - FREE (sh->success); + GF_FREE (sh->success); if (sh->locked_nodes) - FREE (sh->locked_nodes); + GF_FREE (sh->locked_nodes); if (sh->healing_fd && !sh->healing_fd_opened) { fd_unref (sh->healing_fd); @@ -283,7 +283,7 @@ afr_local_sh_cleanup (afr_local_t *local, xlator_t *this) } if (sh->linkname) - FREE (sh->linkname); + GF_FREE ((char *)sh->linkname); loc_wipe (&sh->parent_loc); } @@ -299,17 +299,17 @@ afr_local_transaction_cleanup (afr_local_t *local, xlator_t *this) for (i = 0; i < priv->child_count; i++) { if (local->pending && local->pending[i]) - FREE (local->pending[i]); + GF_FREE (local->pending[i]); } - FREE (local->pending); + GF_FREE (local->pending); - FREE (local->transaction.locked_nodes); - FREE (local->transaction.child_errno); - FREE (local->child_errno); + GF_FREE (local->transaction.locked_nodes); + GF_FREE (local->transaction.child_errno); + GF_FREE (local->child_errno); - FREE (local->transaction.basename); - FREE (local->transaction.new_basename); + GF_FREE (local->transaction.basename); + GF_FREE (local->transaction.new_basename); loc_wipe (&local->transaction.parent_loc); loc_wipe (&local->transaction.new_parent_loc); @@ -340,7 +340,7 @@ afr_local_cleanup (afr_local_t *local, xlator_t *this) if (local->xattr_req) dict_unref (local->xattr_req); - FREE (local->child_up); + GF_FREE (local->child_up); { /* lookup */ if (local->cont.lookup.xattrs) { @@ -350,7 +350,7 @@ afr_local_cleanup (afr_local_t *local, xlator_t *this) local->cont.lookup.xattrs[i] = NULL; } } - FREE (local->cont.lookup.xattrs); + GF_FREE (local->cont.lookup.xattrs); local->cont.lookup.xattrs = NULL; } @@ -365,19 +365,19 @@ afr_local_cleanup (afr_local_t *local, xlator_t *this) { /* getxattr */ if (local->cont.getxattr.name) - FREE (local->cont.getxattr.name); + GF_FREE (local->cont.getxattr.name); } { /* lk */ if (local->cont.lk.locked_nodes) - FREE (local->cont.lk.locked_nodes); + GF_FREE (local->cont.lk.locked_nodes); } { /* checksum */ if (local->cont.checksum.file_checksum) - FREE (local->cont.checksum.file_checksum); + GF_FREE (local->cont.checksum.file_checksum); if (local->cont.checksum.dir_checksum) - FREE (local->cont.checksum.dir_checksum); + GF_FREE (local->cont.checksum.dir_checksum); } { /* create */ @@ -386,7 +386,7 @@ afr_local_cleanup (afr_local_t *local, xlator_t *this) } { /* writev */ - FREE (local->cont.writev.vector); + GF_FREE (local->cont.writev.vector); } { /* setxattr */ @@ -395,16 +395,16 @@ afr_local_cleanup (afr_local_t *local, xlator_t *this) } { /* removexattr */ - FREE (local->cont.removexattr.name); + GF_FREE (local->cont.removexattr.name); } { /* symlink */ - FREE (local->cont.symlink.linkpath); + GF_FREE (local->cont.symlink.linkpath); } { /* opendir */ if (local->cont.opendir.checksum) - FREE (local->cont.opendir.checksum); + GF_FREE (local->cont.opendir.checksum); } } @@ -1005,8 +1005,9 @@ afr_lookup (call_frame_t *frame, xlator_t *this, local->child_up = memdup (priv->child_up, priv->child_count); - local->cont.lookup.xattrs = CALLOC (priv->child_count, - sizeof (*local->cont.lookup.xattr)); + local->cont.lookup.xattrs = GF_CALLOC (priv->child_count, + sizeof (*local->cont.lookup.xattr), + gf_afr_mt_dict_t); local->call_count = afr_up_children_count (priv->child_count, local->child_up); @@ -1083,7 +1084,8 @@ afr_fd_ctx_set (xlator_t *this, fd_t *fd) if (ret == 0) goto unlock; - fd_ctx = CALLOC (1, sizeof (afr_fd_ctx_t)); + fd_ctx = GF_CALLOC (1, sizeof (afr_fd_ctx_t), + gf_afr_mt_afr_fd_ctx_t); if (!fd_ctx) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -1092,8 +1094,9 @@ afr_fd_ctx_set (xlator_t *this, fd_t *fd) goto unlock; } - fd_ctx->pre_op_done = CALLOC (sizeof (*fd_ctx->pre_op_done), - priv->child_count); + fd_ctx->pre_op_done = GF_CALLOC (sizeof (*fd_ctx->pre_op_done), + priv->child_count, + gf_afr_mt_char); if (!fd_ctx->pre_op_done) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -1101,8 +1104,9 @@ afr_fd_ctx_set (xlator_t *this, fd_t *fd) goto unlock; } - fd_ctx->opened_on = CALLOC (sizeof (*fd_ctx->opened_on), - priv->child_count); + fd_ctx->opened_on = GF_CALLOC (sizeof (*fd_ctx->opened_on), + priv->child_count, + gf_afr_mt_char); if (!fd_ctx->opened_on) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -1110,8 +1114,10 @@ afr_fd_ctx_set (xlator_t *this, fd_t *fd) goto unlock; } - fd_ctx->child_failed = CALLOC (sizeof (*fd_ctx->child_failed), - priv->child_count); + fd_ctx->child_failed = GF_CALLOC ( + sizeof (*fd_ctx->child_failed), + priv->child_count, + gf_afr_mt_char); if (!fd_ctx->child_failed) { gf_log (this->name, GF_LOG_ERROR, @@ -1436,15 +1442,15 @@ afr_cleanup_fd_ctx (xlator_t *this, fd_t *fd) if (fd_ctx) { if (fd_ctx->child_failed) - FREE (fd_ctx->child_failed); + GF_FREE (fd_ctx->child_failed); if (fd_ctx->pre_op_done) - FREE (fd_ctx->pre_op_done); + GF_FREE (fd_ctx->pre_op_done); if (fd_ctx->opened_on) - FREE (fd_ctx->opened_on); + GF_FREE (fd_ctx->opened_on); - FREE (fd_ctx); + GF_FREE (fd_ctx); } out: @@ -2176,11 +2182,13 @@ afr_checksum_cbk (call_frame_t *frame, void *cookie, if (op_ret == 0 && (local->op_ret != 0)) { local->op_ret = 0; - local->cont.checksum.file_checksum = MALLOC (NAME_MAX); + local->cont.checksum.file_checksum = + GF_MALLOC (NAME_MAX, gf_afr_mt_char); memcpy (local->cont.checksum.file_checksum, file_checksum, NAME_MAX); - local->cont.checksum.dir_checksum = MALLOC (NAME_MAX); + local->cont.checksum.dir_checksum = + GF_MALLOC (NAME_MAX, gf_afr_mt_char); memcpy (local->cont.checksum.dir_checksum, dir_checksum, NAME_MAX); @@ -2486,8 +2494,9 @@ afr_lk (call_frame_t *frame, xlator_t *this, frame->local = local; - local->cont.lk.locked_nodes = CALLOC (priv->child_count, - sizeof (*local->cont.lk.locked_nodes)); + local->cont.lk.locked_nodes = GF_CALLOC (priv->child_count, + sizeof (*local->cont.lk.locked_nodes), + gf_afr_mt_char); if (!local->cont.lk.locked_nodes) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -2676,6 +2685,25 @@ notify (xlator_t *this, int32_t event, return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_afr_mt_end + 1); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + static const char *favorite_child_warning_str = "You have specified subvolume '%s' " "as the 'favorite child'. This means that if a discrepancy in the content " @@ -2718,6 +2746,7 @@ init (xlator_t *this) int read_ret = -1; int dict_ret = -1; + if (!this->children) { gf_log (this->name, GF_LOG_ERROR, "replicate translator needs more than one " @@ -2730,6 +2759,7 @@ init (xlator_t *this) "Volume is dangling."); } + ALLOC_OR_GOTO (this->private, afr_private_t, out); priv = this->private; @@ -2775,7 +2805,7 @@ init (xlator_t *this) dict_ret = dict_get_str (this->options, "data-self-heal-algorithm", &algo); if (dict_ret == 0) { - priv->data_self_heal_algorithm = strdup (algo); + priv->data_self_heal_algorithm = gf_strdup (algo); } @@ -2946,7 +2976,8 @@ init (xlator_t *this) LOCK_INIT (&priv->lock); LOCK_INIT (&priv->read_child_lock); - priv->child_up = CALLOC (sizeof (unsigned char), child_count); + priv->child_up = GF_CALLOC (sizeof (unsigned char), child_count, + gf_afr_mt_char); if (!priv->child_up) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -2954,7 +2985,8 @@ init (xlator_t *this) goto out; } - priv->children = CALLOC (sizeof (xlator_t *), child_count); + priv->children = GF_CALLOC (sizeof (xlator_t *), child_count, + gf_afr_mt_xlator_t); if (!priv->children) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -2962,7 +2994,9 @@ init (xlator_t *this) goto out; } - priv->pending_key = CALLOC (sizeof (*priv->pending_key), child_count); + priv->pending_key = GF_CALLOC (sizeof (*priv->pending_key), + child_count, + gf_afr_mt_char); if (!priv->pending_key) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -2975,8 +3009,9 @@ init (xlator_t *this) while (i < child_count) { priv->children[i] = trav->xlator; - ret = asprintf (&priv->pending_key[i], "%s.%s", AFR_XATTR_PREFIX, - trav->xlator->name); + ret = gf_asprintf (&priv->pending_key[i], "%s.%s", + AFR_XATTR_PREFIX, + trav->xlator->name); if (-1 == ret) { gf_log (this->name, GF_LOG_ERROR, "asprintf failed to set pending key"); diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index a6ca1c2b..0f7d8bba 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -29,6 +29,7 @@ #include "scheduler.h" #include "call-stub.h" #include "compat-errno.h" +#include "afr-mem-types.h" #define AFR_XATTR_PREFIX "trusted.afr" @@ -302,7 +303,7 @@ typedef struct _afr_local { } readlink; struct { - const char *name; + char *name; int last_tried; } getxattr; @@ -401,7 +402,7 @@ typedef struct _afr_local { } setxattr; struct { - const char *name; + char *name; } removexattr; /* dir write */ @@ -509,8 +510,8 @@ typedef struct _afr_local { unsigned char *locked_nodes; int lock_count; - const char *basename; - const char *new_basename; + char *basename; + char *new_basename; loc_t parent_loc; loc_t new_parent_loc; @@ -559,7 +560,8 @@ typedef struct { /* try alloc and if it fails, goto label */ #define ALLOC_OR_GOTO(var, type, label) do { \ - var = CALLOC (sizeof (type), 1); \ + var = GF_CALLOC (sizeof (type), 1, \ + gf_afr_mt_##type); \ if (!var) { \ gf_log (this->name, GF_LOG_ERROR, \ "out of memory :("); \ @@ -643,7 +645,7 @@ afr_cleanup_fd_ctx (xlator_t *this, fd_t *fd); frame->local = NULL; \ STACK_UNWIND_STRICT (fop, frame, params); \ afr_local_cleanup (__local, __this); \ - free (__local); \ + GF_FREE (__local); \ } while (0); #define AFR_STACK_DESTROY(frame) \ @@ -655,7 +657,7 @@ afr_cleanup_fd_ctx (xlator_t *this, fd_t *fd); frame->local = NULL; \ STACK_DESTROY (frame->root); \ afr_local_cleanup (__local, __this); \ - free (__local); \ + GF_FREE (__local); \ } while (0); /* allocate and return a string that is the basename of argument */ @@ -664,9 +666,9 @@ AFR_BASENAME (const char *str) { char *__tmp_str = NULL; char *__basename_str = NULL; - __tmp_str = strdup (str); - __basename_str = strdup (basename (__tmp_str)); - FREE (__tmp_str); + __tmp_str = gf_strdup (str); + __basename_str = gf_strdup (basename (__tmp_str)); + GF_FREE (__tmp_str); return __basename_str; } @@ -674,8 +676,9 @@ AFR_BASENAME (const char *str) static inline int AFR_LOCAL_INIT (afr_local_t *local, afr_private_t *priv) { - local->child_up = CALLOC (sizeof (*local->child_up), - priv->child_count); + local->child_up = GF_CALLOC (sizeof (*local->child_up), + priv->child_count, + gf_afr_mt_char); if (!local->child_up) { return -ENOMEM; } @@ -731,31 +734,36 @@ afr_transaction_local_init (afr_local_t *local, afr_private_t *priv) local->first_up_child = afr_first_up_child (priv); - local->child_errno = CALLOC (sizeof (*local->child_errno), - priv->child_count); + local->child_errno = GF_CALLOC (sizeof (*local->child_errno), + priv->child_count, + gf_afr_mt_int32_t); if (!local->child_errno) { return -ENOMEM; } - local->pending = CALLOC (sizeof (*local->pending), - priv->child_count); + local->pending = GF_CALLOC (sizeof (*local->pending), + priv->child_count, + gf_afr_mt_int32_t); if (!local->pending) { return -ENOMEM; } for (i = 0; i < priv->child_count; i++) { - local->pending[i] = CALLOC (sizeof (*local->pending[i]), - 3); /* data + metadata + entry */ + local->pending[i] = GF_CALLOC (sizeof (*local->pending[i]), + 3, /* data + metadata + entry */ + gf_afr_mt_int32_t); if (!local->pending[i]) return -ENOMEM; } - local->transaction.locked_nodes = CALLOC (sizeof (*local->transaction.locked_nodes), - priv->child_count); + local->transaction.locked_nodes = GF_CALLOC (sizeof (*local->transaction.locked_nodes), + priv->child_count, + gf_afr_mt_char); - local->transaction.child_errno = CALLOC (sizeof (*local->transaction.child_errno), - priv->child_count); + local->transaction.child_errno = GF_CALLOC (sizeof (*local->transaction.child_errno), + priv->child_count, + gf_afr_mt_int32_t); return 0; } diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index 1ee723d9..a8a15920 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -3557,7 +3557,8 @@ dht_rmdir_is_subvol_empty (call_frame_t *frame, xlator_t *this, goto err; } - lookup_local = CALLOC (sizeof (*local), 1); + lookup_local = GF_CALLOC (sizeof (*local), 1, + gf_dht_mt_dht_local_t); if (!lookup_local) { gf_log (this->name, GF_LOG_ERROR, "Out of Memory"); @@ -4235,7 +4236,8 @@ dht_init_subvolumes (xlator_t *this, dht_conf_t *conf) for (subvols = this->children; subvols; subvols = subvols->next) cnt++; - conf->subvolumes = CALLOC (cnt, sizeof (xlator_t *)); + conf->subvolumes = GF_CALLOC (cnt, sizeof (xlator_t *), + gf_dht_mt_xlator_t); if (!conf->subvolumes) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -4247,7 +4249,8 @@ dht_init_subvolumes (xlator_t *this, dht_conf_t *conf) for (subvols = this->children; subvols; subvols = subvols->next) conf->subvolumes[cnt++] = subvols->xlator; - conf->subvolume_status = CALLOC (cnt, sizeof (char)); + conf->subvolume_status = GF_CALLOC (cnt, sizeof (char), + gf_dht_mt_char); if (!conf->subvolume_status) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h index e6e1e818..b51f308e 100644 --- a/xlators/cluster/dht/src/dht-common.h +++ b/xlators/cluster/dht/src/dht-common.h @@ -22,6 +22,8 @@ #include "config.h" #endif +#include "dht-mem-types.h" + #ifndef _DHT_H #define _DHT_H diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c index f2e1a182..767be38b 100644 --- a/xlators/cluster/dht/src/dht-helper.c +++ b/xlators/cluster/dht/src/dht-helper.c @@ -148,7 +148,7 @@ dht_local_wipe (xlator_t *this, dht_local_t *local) local->selfheal.layout = NULL; } - FREE (local); + GF_FREE (local); } @@ -158,7 +158,8 @@ dht_local_init (call_frame_t *frame) dht_local_t *local = NULL; /* TODO: use mem-pool */ - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_dht_mt_dht_local_t); if (!local) return NULL; @@ -408,9 +409,9 @@ dht_build_child_loc (xlator_t *this, loc_t *child, loc_t *parent, char *name) } if (strcmp (parent->path, "/") == 0) - asprintf ((char **)&child->path, "/%s", name); + gf_asprintf ((char **)&child->path, "/%s", name); else - asprintf ((char **)&child->path, "%s/%s", parent->path, name); + gf_asprintf ((char **)&child->path, "%s/%s", parent->path, name); if (!child->path) { gf_log (this->name, GF_LOG_ERROR, diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index 86d3c441..41b68967 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -44,7 +44,8 @@ dht_layout_new (xlator_t *this, int cnt) conf = this->private; - layout = CALLOC (1, layout_size (cnt)); + layout = GF_CALLOC (1, layout_size (cnt), + gf_dht_mt_dht_layout_t); if (!layout) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -131,7 +132,7 @@ dht_layout_unref (xlator_t *this, dht_layout_t *layout) UNLOCK (&conf->layout_lock); if (!ref) - FREE (layout); + GF_FREE (layout); } @@ -218,8 +219,9 @@ dht_layouts_init (xlator_t *this, dht_conf_t *conf) int ret = -1; - conf->file_layouts = CALLOC (conf->subvolume_cnt, - sizeof (dht_layout_t *)); + conf->file_layouts = GF_CALLOC (conf->subvolume_cnt, + sizeof (dht_layout_t *), + gf_dht_mt_dht_layout_t); if (!conf->file_layouts) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -253,7 +255,8 @@ dht_disk_layout_extract (xlator_t *this, dht_layout_t *layout, int ret = -1; int32_t *disk_layout = NULL; - disk_layout = CALLOC (5, sizeof (int)); + disk_layout = GF_CALLOC (5, sizeof (int), + gf_dht_mt_int32_t); if (!disk_layout) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); diff --git a/xlators/cluster/dht/src/dht-mem-types.h b/xlators/cluster/dht/src/dht-mem-types.h new file mode 100644 index 00000000..4a7a8bd8 --- /dev/null +++ b/xlators/cluster/dht/src/dht-mem-types.h @@ -0,0 +1,42 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __DHT_MEM_TYPES_H__ +#define __DHT_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_dht_mem_types_ { + gf_dht_mt_dht_du_t = gf_common_mt_end + 1, + gf_dht_mt_dht_conf_t, + gf_dht_mt_char, + gf_dht_mt_int32_t, + gf_dht_mt_dht_local_t, + gf_dht_mt_xlator_t, + gf_dht_mt_dht_layout_t, + gf_switch_mt_dht_conf_t, + gf_switch_mt_dht_du_t, + gf_switch_mt_switch_sched_array, + gf_switch_mt_switch_struct, + gf_dht_mt_end +}; +#endif + diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c index 8a4d3a6f..8380535f 100644 --- a/xlators/cluster/dht/src/dht-selfheal.c +++ b/xlators/cluster/dht/src/dht-selfheal.c @@ -138,7 +138,7 @@ err: dict_destroy (xattr); if (disk_layout) - FREE (disk_layout); + GF_FREE (disk_layout); dht_selfheal_dir_xattr_cbk (frame, subvol, frame->this, -1, ENOMEM); diff --git a/xlators/cluster/dht/src/dht.c b/xlators/cluster/dht/src/dht.c index d7f18745..ca560151 100644 --- a/xlators/cluster/dht/src/dht.c +++ b/xlators/cluster/dht/src/dht.c @@ -212,26 +212,45 @@ fini (xlator_t *this) if (conf) { if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); - FREE (conf); + GF_FREE (conf); } return; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_dht_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) { @@ -241,6 +260,7 @@ init (xlator_t *this) int i = 0; uint32_t temp_free_disk = 0; + if (!this->children) { gf_log (this->name, GF_LOG_CRITICAL, "Distribute needs more than one subvolume"); @@ -252,7 +272,7 @@ init (xlator_t *this) "dangling volume. check volfile"); } - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), gf_dht_mt_dht_conf_t); if (!conf) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -302,7 +322,8 @@ init (xlator_t *this) goto err; } - conf->du_stats = CALLOC (conf->subvolume_cnt, sizeof (dht_du_t)); + conf->du_stats = GF_CALLOC (conf->subvolume_cnt, sizeof (dht_du_t), + gf_dht_mt_dht_du_t); if (!conf->du_stats) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -322,24 +343,24 @@ err: if (conf) { if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); if (conf->du_stats) - FREE (conf->du_stats); + GF_FREE (conf->du_stats); - FREE (conf); + GF_FREE (conf); } return -1; diff --git a/xlators/cluster/dht/src/nufa.c b/xlators/cluster/dht/src/nufa.c index edb900f7..0d8241f4 100644 --- a/xlators/cluster/dht/src/nufa.c +++ b/xlators/cluster/dht/src/nufa.c @@ -513,21 +513,21 @@ fini (xlator_t *this) if (conf) { if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); - FREE (conf); + GF_FREE (conf); } return; @@ -557,7 +557,8 @@ init (xlator_t *this) "dangling volume. check volfile"); } - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), + gf_dht_mt_dht_conf_t); if (!conf) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -642,7 +643,8 @@ init (xlator_t *this) } } - conf->du_stats = CALLOC (conf->subvolume_cnt, sizeof (dht_du_t)); + conf->du_stats = GF_CALLOC (conf->subvolume_cnt, sizeof (dht_du_t), + gf_dht_mt_dht_du_t); if (!conf->du_stats) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -657,24 +659,24 @@ err: if (conf) { if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); if (conf->du_stats) - FREE (conf->du_stats); + GF_FREE (conf->du_stats); - FREE (conf); + GF_FREE (conf); } return -1; diff --git a/xlators/cluster/dht/src/switch.c b/xlators/cluster/dht/src/switch.c index 680ce8d6..f6fb6b65 100644 --- a/xlators/cluster/dht/src/switch.c +++ b/xlators/cluster/dht/src/switch.c @@ -24,6 +24,7 @@ #endif #include "dht-common.c" +#include "dht-mem-types.h" #include #include @@ -82,7 +83,7 @@ get_switch_matching_subvol (const char *path, dht_conf_t *conf, return hashed_subvol; trav = cond; - pathname = strdup (path); + pathname = gf_strdup (path); while (trav) { if (fnmatch (trav->path_pattern, pathname, FNM_NOESCAPE) == 0) { @@ -96,7 +97,7 @@ get_switch_matching_subvol (const char *path, dht_conf_t *conf, } trav = trav->next; } - free (pathname); + GF_FREE (pathname); return hashed_subvol; } @@ -620,29 +621,29 @@ fini (xlator_t *this) conf->private = NULL; while (trav) { if (trav->array) - FREE (trav->array); + GF_FREE (trav->array); prev = trav; trav = trav->next; - FREE (prev); + GF_FREE (prev); } if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); - FREE (conf); + GF_FREE (conf); } return; @@ -679,8 +680,9 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, trav_xl = trav_xl->next; } child_count = index; - switch_buf_array = CALLOC ((index + 1), - sizeof (struct switch_sched_array)); + switch_buf_array = GF_CALLOC ((index + 1), + sizeof (struct switch_sched_array), + gf_switch_mt_switch_sched_array); if (!switch_buf_array) goto err; @@ -698,11 +700,12 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, /* Get the pattern for considering switch case. "option block-size *avi:10MB" etc */ - option_string = strdup (pattern_str); + option_string = gf_strdup (pattern_str); switch_str = strtok_r (option_string, ";", &tmp_str); while (switch_str) { - dup_str = strdup (switch_str); - switch_opt = CALLOC (1, sizeof (struct switch_struct)); + dup_str = gf_strdup (switch_str); + switch_opt = GF_CALLOC (1, sizeof (struct switch_struct), + gf_switch_mt_switch_struct); if (!switch_opt) goto err; @@ -714,12 +717,12 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, "for all the unconfigured child nodes," " hence neglecting current option"); switch_str = strtok_r (NULL, ";", &tmp_str); - free (dup_str); + GF_FREE (dup_str); continue; } memcpy (switch_opt->path_pattern, pattern, strlen (pattern)); if (childs) { - dup_childs = strdup (childs); + dup_childs = gf_strdup (childs); child = strtok_r (dup_childs, ",", &tmp); while (child) { if (gf_switch_valid_child (this, child)) { @@ -734,11 +737,12 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, goto err; } } - free (dup_childs); + GF_FREE (dup_childs); child = strtok_r (childs, ",", &tmp1); switch_opt->num_child = idx; - switch_opt->array = CALLOC (1, (idx * - sizeof (struct switch_sched_array))); + switch_opt->array = GF_CALLOC (1, (idx * + sizeof (struct switch_sched_array)), + gf_switch_mt_switch_sched_array); if (!switch_opt->array) goto err; idx = 0; @@ -772,7 +776,7 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, "option in unify volume. Exiting"); goto err; } - free (dup_str); + GF_FREE (dup_str); /* Link it to the main structure */ if (switch_buf) { @@ -803,7 +807,8 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, "No nodes left for pattern '*'. Exiting"); goto err; } - switch_opt = CALLOC (1, sizeof (struct switch_struct)); + switch_opt = GF_CALLOC (1, sizeof (struct switch_struct), + gf_switch_mt_switch_struct); if (!switch_opt) goto err; @@ -811,7 +816,9 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, memcpy (switch_opt->path_pattern, "*", 2); switch_opt->num_child = flag; switch_opt->array = - CALLOC (1, flag * sizeof (struct switch_sched_array)); + GF_CALLOC (1, + flag * sizeof (struct switch_sched_array), + gf_switch_mt_switch_sched_array); if (!switch_opt->array) goto err; flag = 0; @@ -846,14 +853,14 @@ set_switch_pattern (xlator_t *this, dht_conf_t *conf, err: if (switch_buf) { if (switch_buf_array) - FREE (switch_buf_array); + GF_FREE (switch_buf_array); trav = switch_buf; while (trav) { if (trav->array) - FREE (trav->array); + GF_FREE (trav->array); switch_opt = trav; trav = trav->next; - FREE (switch_opt); + GF_FREE (switch_opt); } } return -1; @@ -881,7 +888,7 @@ init (xlator_t *this) "dangling volume. check volfile"); } - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), gf_switch_mt_dht_conf_t); if (!conf) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -947,7 +954,8 @@ init (xlator_t *this) conf->gen = 1; - conf->du_stats = CALLOC (conf->subvolume_cnt, sizeof (dht_du_t)); + conf->du_stats = GF_CALLOC (conf->subvolume_cnt, sizeof (dht_du_t), + gf_switch_mt_dht_du_t); if (!conf->du_stats) { gf_log (this->name, GF_LOG_ERROR, "Out of memory"); @@ -962,24 +970,24 @@ err: if (conf) { if (conf->file_layouts) { for (i = 0; i < conf->subvolume_cnt; i++) { - FREE (conf->file_layouts[i]); + GF_FREE (conf->file_layouts[i]); } - FREE (conf->file_layouts); + GF_FREE (conf->file_layouts); } if (conf->default_dir_layout) - FREE (conf->default_dir_layout); + GF_FREE (conf->default_dir_layout); if (conf->subvolumes) - FREE (conf->subvolumes); + GF_FREE (conf->subvolumes); if (conf->subvolume_status) - FREE (conf->subvolume_status); + GF_FREE (conf->subvolume_status); if (conf->du_stats) - FREE (conf->du_stats); + GF_FREE (conf->du_stats); - FREE (conf); + GF_FREE (conf); } return -1; diff --git a/xlators/cluster/ha/src/ha-helpers.c b/xlators/cluster/ha/src/ha-helpers.c index c23c5676..fb659310 100644 --- a/xlators/cluster/ha/src/ha-helpers.c +++ b/xlators/cluster/ha/src/ha-helpers.c @@ -49,12 +49,14 @@ int ha_alloc_init_fd (call_frame_t *frame, fd_t *fd) goto out; } hafdp = (hafd_t *)(long)tmp_hafdp; - local = frame->local = CALLOC (1, sizeof (*local)); + local = frame->local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (local == NULL) { ret = -ENOMEM; goto out; } - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, + gf_ha_mt_child_count); if (local->state == NULL) { ret = -ENOMEM; goto out; @@ -147,7 +149,7 @@ int ha_handle_cbk (call_frame_t *frame, void *cookie, int op_ret, int op_errno) } if (local->fd) { - FREE (local->state); + GF_FREE (local->state); local->state = NULL; fd_unref (local->fd); @@ -170,7 +172,8 @@ int ha_alloc_init_inode (call_frame_t *frame, inode_t *inode) local = frame->local; if (local == NULL) { - local = frame->local = CALLOC (1, sizeof (*local)); + local = frame->local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (local == NULL) { ret = -ENOMEM; goto out; diff --git a/xlators/cluster/ha/src/ha-mem-types.h b/xlators/cluster/ha/src/ha-mem-types.h new file mode 100644 index 00000000..bdbfcb52 --- /dev/null +++ b/xlators/cluster/ha/src/ha-mem-types.h @@ -0,0 +1,37 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __HA_MEM_TYPES_H__ +#define __HA_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_ha_mem_types_ { + gf_ha_mt_ha_local_t = gf_common_mt_end + 1, + gf_ha_mt_hafd_t, + gf_ha_mt_char, + gf_ha_mt_child_count, + gf_ha_mt_xlator_t, + gf_ha_mt_ha_private_t, + gf_ha_mt_end +}; +#endif + diff --git a/xlators/cluster/ha/src/ha.c b/xlators/cluster/ha/src/ha.c index 3317ae78..10e64e56 100644 --- a/xlators/cluster/ha/src/ha.c +++ b/xlators/cluster/ha/src/ha.c @@ -50,7 +50,7 @@ ha_local_wipe (ha_local_t *local) } if (local->state) { - FREE (local->state); + GF_FREE (local->state); local->state = NULL; } @@ -71,7 +71,7 @@ ha_local_wipe (ha_local_t *local) local->inode = NULL; } - FREE (local); + GF_FREE (local); return; } @@ -84,7 +84,7 @@ ha_forget (xlator_t *this, char *state = NULL; if (!inode_ctx_del (inode, this, &stateino)) { state = ((char *)(long)stateino); - FREE (state); + GF_FREE (state); } return 0; @@ -193,7 +193,8 @@ ha_lookup (call_frame_t *frame, child_count = pvt->child_count; children = pvt->children; - frame->local = local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -205,7 +206,7 @@ ha_lookup (call_frame_t *frame, ret = inode_ctx_get (loc->inode, this, NULL); if (ret) { - state = CALLOC (1, child_count); + state = GF_CALLOC (1, child_count, gf_ha_mt_child_count); if (state == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -645,7 +646,7 @@ ha_mknod_lookup_cbk (call_frame_t *frame, if (cnt == 0) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); STACK_UNWIND (frame, local->op_ret, local->op_errno, @@ -715,7 +716,7 @@ ha_mknod_cbk (call_frame_t *frame, if (cnt == 0 || i == child_count) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); stub = local->stub; STACK_UNWIND (frame, local->op_ret, local->op_errno, local->stub->args.mknod.loc.inode, &local->buf, @@ -770,7 +771,8 @@ ha_mknod (call_frame_t *frame, pvt = this->private; child_count = pvt->child_count; - frame->local = local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -786,7 +788,7 @@ ha_mknod (call_frame_t *frame, local->op_ret = -1; local->op_errno = ENOTCONN; - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -796,7 +798,7 @@ ha_mknod (call_frame_t *frame, memcpy (local->state, pvt->state, child_count); local->active = -1; - stateino = CALLOC (1, child_count); + stateino = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!stateino) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -875,7 +877,7 @@ ha_mkdir_lookup_cbk (call_frame_t *frame, if (cnt == 0) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); STACK_UNWIND (frame, local->op_ret, local->op_errno, @@ -940,7 +942,7 @@ ha_mkdir_cbk (call_frame_t *frame, if (cnt == 0 || i == child_count) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); stub = local->stub; STACK_UNWIND (frame, local->op_ret, local->op_errno, local->stub->args.mkdir.loc.inode, &local->buf, @@ -993,7 +995,8 @@ ha_mkdir (call_frame_t *frame, pvt = this->private; child_count = pvt->child_count; - frame->local = local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!frame->local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1009,7 +1012,7 @@ ha_mkdir (call_frame_t *frame, local->op_ret = -1; local->op_errno = ENOTCONN; - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1019,7 +1022,7 @@ ha_mkdir (call_frame_t *frame, memcpy (local->state, pvt->state, child_count); local->active = -1; - stateino = CALLOC (1, child_count); + stateino = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!stateino) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1204,7 +1207,7 @@ ha_symlink_lookup_cbk (call_frame_t *frame, if (cnt == 0) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); STACK_UNWIND (frame, local->op_ret, local->op_errno, @@ -1268,7 +1271,7 @@ ha_symlink_cbk (call_frame_t *frame, if (cnt == 0 || i == child_count) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); stub = local->stub; STACK_UNWIND (frame, local->op_ret, local->op_errno, local->stub->args.symlink.loc.inode, &local->buf, @@ -1321,7 +1324,8 @@ ha_symlink (call_frame_t *frame, pvt = this->private; child_count = pvt->child_count; - frame->local = local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1337,7 +1341,7 @@ ha_symlink (call_frame_t *frame, local->op_ret = -1; local->op_errno = ENOTCONN; - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1347,7 +1351,7 @@ ha_symlink (call_frame_t *frame, memcpy (local->state, pvt->state, child_count); local->active = -1; - stateino = CALLOC (1, child_count); + stateino = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!stateino) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1481,7 +1485,7 @@ ha_link_lookup_cbk (call_frame_t *frame, if (cnt == 0) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); STACK_UNWIND (frame, local->op_ret, local->op_errno, @@ -1545,7 +1549,7 @@ ha_link_cbk (call_frame_t *frame, if (cnt == 0 || i == child_count) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); stub = local->stub; STACK_UNWIND (frame, local->op_ret, local->op_errno, local->stub->args.link.oldloc.inode, &local->buf, @@ -1613,7 +1617,8 @@ ha_link (call_frame_t *frame, pvt = this->private; child_count = pvt->child_count; - frame->local = local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!frame->local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1629,7 +1634,7 @@ ha_link (call_frame_t *frame, local->op_ret = -1; local->op_errno = ENOTCONN; - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1741,7 +1746,7 @@ ha_create_cbk (call_frame_t *frame, stub->args.create.fd, stub->args.create.loc.inode, &local->buf, &local->preparent, &local->postparent); - FREE (state); + GF_FREE (state); call_stub_destroy (stub); return 0; } @@ -1785,7 +1790,8 @@ ha_create (call_frame_t *frame, children = pvt->children; if (local == NULL) { - local = frame->local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1799,7 +1805,7 @@ ha_create (call_frame_t *frame, goto err; } - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1819,28 +1825,28 @@ ha_create (call_frame_t *frame, } } /* FIXME handle active -1 */ - stateino = CALLOC (1, child_count); + stateino = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!stateino) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp = CALLOC (1, sizeof (*hafdp)); + hafdp = GF_CALLOC (1, sizeof (*hafdp), gf_ha_mt_hafd_t); if (!hafdp) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->fdstate = CALLOC (1, child_count); + hafdp->fdstate = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!hafdp->fdstate) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->path = strdup(loc->path); + hafdp->path = gf_strdup(loc->path); if (!hafdp->path) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1865,20 +1871,20 @@ err: ha_local_wipe (local); if (stateino) { - FREE (stateino); + GF_FREE (stateino); stateino = NULL; } if (hafdp) { if (hafdp->fdstate) { - FREE (hafdp->fdstate); + GF_FREE (hafdp->fdstate); } if (hafdp->path) { - FREE (hafdp->path); + GF_FREE (hafdp->path); } - FREE (hafdp); + GF_FREE (hafdp); } return 0; @@ -1955,7 +1961,8 @@ ha_open (call_frame_t *frame, child_count = pvt->child_count; - local = frame->local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1966,21 +1973,21 @@ ha_open (call_frame_t *frame, local->op_errno = ENOTCONN; local->fd = fd; - hafdp = CALLOC (1, sizeof (*hafdp)); + hafdp = GF_CALLOC (1, sizeof (*hafdp), gf_ha_mt_hafd_t); if (!hafdp) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->fdstate = CALLOC (1, child_count); + hafdp->fdstate = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!hafdp->fdstate) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->path = strdup (loc->path); + hafdp->path = gf_strdup (loc->path); if (!hafdp->path) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -2020,16 +2027,16 @@ err: STACK_UNWIND (frame, -1, op_errno, fd); if (hafdp) { if (hafdp->fdstate) { - FREE (hafdp->fdstate); + GF_FREE (hafdp->fdstate); hafdp->fdstate = NULL; } if (hafdp->path) { - FREE (hafdp->path); + GF_FREE (hafdp->path); hafdp->path = NULL; } - FREE (hafdp); + GF_FREE (hafdp); } ha_local_wipe (local); @@ -2420,7 +2427,8 @@ ha_opendir (call_frame_t *frame, children = pvt->children; child_count = pvt->child_count; - local = frame->local = CALLOC (1, sizeof (*local)); + frame->local = local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -2431,21 +2439,21 @@ ha_opendir (call_frame_t *frame, local->op_errno = ENOTCONN; local->fd = fd; - hafdp = CALLOC (1, sizeof (*hafdp)); + hafdp = GF_CALLOC (1, sizeof (*hafdp), gf_ha_mt_hafd_t); if (!hafdp) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->fdstate = CALLOC (1, child_count); + hafdp->fdstate = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!hafdp->fdstate) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto err; } - hafdp->path = strdup (loc->path); + hafdp->path = gf_strdup (loc->path); if (!hafdp->path) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -2484,16 +2492,16 @@ err: ha_local_wipe (local); if (hafdp) { if (hafdp->fdstate) { - FREE (hafdp->fdstate); + GF_FREE (hafdp->fdstate); hafdp->fdstate = NULL; } if (hafdp->path) { - FREE (hafdp->path); + GF_FREE (hafdp->path); hafdp->path = NULL; } - FREE (hafdp); + GF_FREE (hafdp); } return 0; } @@ -2733,7 +2741,8 @@ ha_statfs (call_frame_t *frame, /* The normal way of handling failover doesn't work here * as loc->inode may be null in this case. */ - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -3073,7 +3082,7 @@ ha_lk_setlk_unlck_cbk (call_frame_t *frame, if (cnt == 0) { stub = local->stub; - FREE (local->state); + GF_FREE (local->state); if (stub->args.lk.lock.l_type == F_UNLCK) { STACK_UNWIND (frame, local->op_ret, local->op_errno, &stub->args.lk.lock); } else { @@ -3122,7 +3131,7 @@ ha_lk_setlk_cbk (call_frame_t *frame, } if (i == child_count) { call_stub_t *stub = local->stub; - FREE (local->state); + GF_FREE (local->state); STACK_UNWIND (frame, 0, op_errno, &stub->args.lk.lock); call_stub_destroy (stub); return 0; @@ -3163,7 +3172,7 @@ ha_lk_setlk_cbk (call_frame_t *frame, } return 0; } else { - FREE (local->state); + GF_FREE (local->state); call_stub_destroy (local->stub); STACK_UNWIND (frame, op_ret, @@ -3197,7 +3206,7 @@ ha_lk_getlk_cbk (call_frame_t *frame, prev_frame = cookie; if (op_ret == 0) { - FREE (local->state); + GF_FREE (local->state); call_stub_destroy (local->stub); STACK_UNWIND (frame, 0, 0, lock); return 0; @@ -3214,7 +3223,7 @@ ha_lk_getlk_cbk (call_frame_t *frame, } if (i == child_count) { - FREE (local->state); + GF_FREE (local->state); call_stub_destroy (local->stub); STACK_UNWIND (frame, op_ret, op_errno, lock); return 0; @@ -3255,7 +3264,8 @@ ha_lk (call_frame_t *frame, gf_log (this->name, GF_LOG_ERROR, "fd_ctx_get failed"); if (local == NULL) { - local = frame->local = CALLOC (1, sizeof (*local)); + local = frame->local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -3280,7 +3290,7 @@ ha_lk (call_frame_t *frame, goto err; } - local->state = CALLOC (1, child_count); + local->state = GF_CALLOC (1, child_count, gf_ha_mt_char); if (!local->state) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -3636,7 +3646,8 @@ ha_stats (call_frame_t *frame, int i = 0; int32_t op_errno = EINVAL; - local = frame->local = CALLOC (1, sizeof (*local)); + local = frame->local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -3737,7 +3748,8 @@ ha_getspec (call_frame_t *frame, int i = 0; int32_t op_errno = EINVAL; - local = frame->local = CALLOC (1, sizeof (*local)); + local = frame->local = GF_CALLOC (1, sizeof (*local), + gf_ha_mt_ha_local_t); if (!local) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -3791,8 +3803,8 @@ ha_closedir (xlator_t *this, } hafdp = (hafd_t *)(long)tmp_hafdp; - FREE (hafdp->fdstate); - FREE (hafdp->path); + GF_FREE (hafdp->fdstate); + GF_FREE (hafdp->path); LOCK_DESTROY (&hafdp->lock); return 0; } @@ -3812,8 +3824,8 @@ ha_close (xlator_t *this, } hafdp = (hafd_t *)(long)tmp_hafdp; - FREE (hafdp->fdstate); - FREE (hafdp->path); + GF_FREE (hafdp->fdstate); + GF_FREE (hafdp->path); LOCK_DESTROY (&hafdp->lock); return 0; } @@ -3884,6 +3896,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_ha_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) { @@ -3891,6 +3922,7 @@ init (xlator_t *this) xlator_list_t *trav = NULL; int count = 0, ret = 0; + if (!this->children) { gf_log (this->name,GF_LOG_ERROR, "FATAL: ha should have one or more child defined"); @@ -3903,7 +3935,7 @@ init (xlator_t *this) } trav = this->children; - pvt = CALLOC (1, sizeof (ha_private_t)); + pvt = GF_CALLOC (1, sizeof (ha_private_t), gf_ha_mt_ha_private_t); ret = dict_get_int32 (this->options, "preferred-subvolume", &pvt->pref_subvol); @@ -3918,7 +3950,8 @@ init (xlator_t *this) } pvt->child_count = count; - pvt->children = CALLOC (count, sizeof (xlator_t*)); + pvt->children = GF_CALLOC (count, sizeof (xlator_t*), + gf_ha_mt_xlator_t); trav = this->children; count = 0; @@ -3928,7 +3961,7 @@ init (xlator_t *this) trav = trav->next; } - pvt->state = CALLOC (1, count); + pvt->state = GF_CALLOC (1, count, gf_ha_mt_char); this->private = pvt; return 0; } @@ -3938,7 +3971,7 @@ fini (xlator_t *this) { ha_private_t *priv = NULL; priv = this->private; - FREE (priv); + GF_FREE (priv); return; } diff --git a/xlators/cluster/ha/src/ha.h b/xlators/cluster/ha/src/ha.h index e5c9541d..5e06b7e0 100644 --- a/xlators/cluster/ha/src/ha.h +++ b/xlators/cluster/ha/src/ha.h @@ -20,6 +20,8 @@ #ifndef __HA_H_ #define __HA_H_ +#include "ha-mem-types.h" + typedef struct { call_stub_t *stub; int32_t op_ret, op_errno; diff --git a/xlators/cluster/map/src/map-helper.c b/xlators/cluster/map/src/map-helper.c index b4c8ad52..ad01b210 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 00000000..f41ab420 --- /dev/null +++ b/xlators/cluster/map/src/map-mem-types.h @@ -0,0 +1,35 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#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 09d22b5d..1383d83c 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 b423642c..eb549eb0 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; diff --git a/xlators/cluster/stripe/src/stripe-mem-types.h b/xlators/cluster/stripe/src/stripe-mem-types.h new file mode 100644 index 00000000..06667107 --- /dev/null +++ b/xlators/cluster/stripe/src/stripe-mem-types.h @@ -0,0 +1,40 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __STRIPE_MEM_TYPES_H__ +#define __STRIPE_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_stripe_mem_types_ { + gf_stripe_mt_stripe_local_t = gf_common_mt_end + 1, + gf_stripe_mt_iovec, + gf_stripe_mt_readv_replies, + gf_stripe_mt_stripe_fd_ctx_t, + gf_stripe_mt_char, + gf_stripe_mt_int8_t, + gf_stripe_mt_xlator_t, + gf_stripe_mt_stripe_private_t, + gf_stripe_mt_stripe_options, + gf_stripe_mt_end +}; +#endif + diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index eb5a154d..52473c03 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -53,7 +53,7 @@ stripe_get_matching_bs (const char *path, struct stripe_options *opts, uint64_t block_size = 0; block_size = default_bs; - pathname = strdup (path); + pathname = gf_strdup (path); trav = opts; while (trav) { @@ -63,7 +63,8 @@ stripe_get_matching_bs (const char *path, struct stripe_options *opts, } trav = trav->next; } - free (pathname); + + GF_FREE (pathname); return block_size; } @@ -572,7 +573,8 @@ stripe_entry_self_heal (call_frame_t *frame, xlator_t *this, if (!rframe) { goto out; } - rlocal = CALLOC (1, sizeof (stripe_local_t)); + rlocal = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!rlocal) { goto out; } @@ -709,7 +711,8 @@ stripe_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -760,7 +763,8 @@ stripe_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -844,7 +848,8 @@ stripe_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) priv = this->private; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -893,7 +898,8 @@ stripe_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1008,7 +1014,8 @@ stripe_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1049,7 +1056,8 @@ stripe_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1215,7 +1223,8 @@ stripe_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1270,7 +1279,8 @@ stripe_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1356,7 +1366,8 @@ stripe_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1617,7 +1628,8 @@ stripe_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1684,7 +1696,8 @@ stripe_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1735,7 +1748,8 @@ stripe_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -1936,7 +1950,8 @@ stripe_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, /* */ if (local->op_ret >= 0) { - fctx = CALLOC (1, sizeof (stripe_fd_ctx_t)); + fctx = GF_CALLOC (1, sizeof (stripe_fd_ctx_t), + gf_stripe_mt_stripe_fd_ctx_t); if (fctx) { fctx->stripe_size = local->stripe_size; fctx->stripe_count = priv->child_count; @@ -2035,7 +2050,8 @@ stripe_create (call_frame_t *frame, xlator_t *this, loc_t *loc, } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2107,8 +2123,8 @@ stripe_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (local->op_ret == -1) { if (local->fctx) { if (!local->fctx->static_array) - FREE (local->fctx->xl_array); - FREE (local->fctx); + GF_FREE (local->fctx->xl_array); + GF_FREE (local->fctx); } } else { fd_ctx_set (local->fd, this, @@ -2167,7 +2183,8 @@ stripe_open_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } if (!local->fctx) { - local->fctx = CALLOC (1, sizeof (stripe_fd_ctx_t)); + local->fctx = GF_CALLOC (1, sizeof (stripe_fd_ctx_t), + gf_stripe_mt_stripe_fd_ctx_t); if (!local->fctx) { local->op_errno = ENOMEM; local->op_ret = -1; @@ -2209,9 +2226,11 @@ stripe_open_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local->op_errno = EIO; goto unlock; } - local->fctx->xl_array = - CALLOC (local->fctx->stripe_count, - sizeof (xlator_t *)); + + local->fctx->xl_array = + GF_CALLOC (local->fctx->stripe_count, + sizeof (xlator_t *), + gf_stripe_mt_xlator_t); } if (local->fctx->stripe_count != data_to_int32 (data)) { gf_log (this->name, GF_LOG_ERROR, @@ -2326,7 +2345,8 @@ stripe_open (call_frame_t *frame, xlator_t *this, loc_t *loc, } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2354,7 +2374,8 @@ stripe_open (call_frame_t *frame, xlator_t *this, loc_t *loc, trav = trav->next; } } else { - local->fctx = CALLOC (1, sizeof (stripe_fd_ctx_t)); + local->fctx = GF_CALLOC (1, sizeof (stripe_fd_ctx_t), + gf_stripe_mt_stripe_fd_ctx_t); if (!local->fctx) { op_errno = ENOMEM; goto err; @@ -2448,7 +2469,8 @@ stripe_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2537,7 +2559,8 @@ stripe_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, priv = this->private; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2582,7 +2605,8 @@ stripe_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) goto err; } /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2624,7 +2648,8 @@ stripe_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2668,7 +2693,8 @@ stripe_fstat (call_frame_t *frame, trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2710,7 +2736,8 @@ stripe_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2752,7 +2779,8 @@ stripe_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) trav = this->children; /* Initialization */ - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -2802,7 +2830,8 @@ stripe_readv_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, op_ret = 0; /* Keep extra space for filling in '\0's */ - vec = CALLOC ((local->count * 2), sizeof (struct iovec)); + vec = GF_CALLOC ((local->count * 2), sizeof (struct iovec), + gf_stripe_mt_iovec); if (!vec) { op_ret = -1; goto done; @@ -2932,7 +2961,8 @@ stripe_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (need_to_check_proper_size) goto check_size; - final_vec = CALLOC (mlocal->count, sizeof (struct iovec)); + final_vec = GF_CALLOC (mlocal->count, sizeof (struct iovec), + gf_stripe_mt_iovec); if (!final_vec) { op_ret = -1; @@ -2964,7 +2994,8 @@ stripe_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, iobref_unref (tmp_iobref); if (final_vec) - FREE (final_vec); + GF_FREE (final_vec); + } goto out; @@ -2977,7 +3008,7 @@ stripe_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, (fctx->xl_array[index])->fops->fstat, mlocal->fd); } - } + out: STACK_DESTROY (frame->root); return 0; @@ -3027,8 +3058,9 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, rounded_start = floor (offset, stripe_size); rounded_end = roof (offset+size, stripe_size); num_stripe = rounded_end/stripe_size - rounded_start/stripe_size; - - local = CALLOC (1, sizeof (stripe_local_t)); + + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -3036,7 +3068,8 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, frame->local = local; /* This is where all the vectors should be copied. */ - local->replies = CALLOC (num_stripe, sizeof (struct readv_replies)); + local->replies = GF_CALLOC (num_stripe, sizeof (struct readv_replies), + gf_stripe_mt_readv_replies); if (!local->replies) { op_errno = ENOMEM; goto err; @@ -3051,7 +3084,8 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, for (index = off_index; index < (num_stripe + off_index); index++) { rframe = copy_frame (frame); - rlocal = CALLOC (1, sizeof (stripe_local_t)); + rlocal = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!rlocal) { op_errno = ENOMEM; goto err; @@ -3173,7 +3207,8 @@ stripe_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, } remaining_size = total_size; - local = CALLOC (1, sizeof (stripe_local_t)); + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); if (!local) { op_errno = ENOMEM; goto err; @@ -3198,7 +3233,8 @@ stripe_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, tmp_count = iov_subset (vector, count, offset_offset, offset_offset + fill_size, NULL); - tmp_vec = CALLOC (tmp_count, sizeof (struct iovec)); + tmp_vec = GF_CALLOC (tmp_count, sizeof (struct iovec), + gf_stripe_mt_iovec); if (!tmp_vec) { op_errno = ENOMEM; goto err; @@ -3213,7 +3249,7 @@ stripe_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, STACK_WIND(frame, stripe_writev_cbk, fctx->xl_array[idx], fctx->xl_array[idx]->fops->writev, fd, tmp_vec, tmp_count, offset + offset_offset, iobref); - FREE (tmp_vec); + GF_FREE (tmp_vec); offset_offset += fill_size; if (remaining_size == 0) break; @@ -3243,10 +3279,10 @@ stripe_release (xlator_t *this, fd_t *fd) fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; if (!fctx->static_array) - FREE (fctx->xl_array); - - FREE (fctx); - + GF_FREE (fctx->xl_array); + + GF_FREE (fctx); + out: return 0; } @@ -3345,10 +3381,11 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) "option block-size *avi:10MB" etc */ stripe_str = strtok_r (data, ",", &tmp_str); while (stripe_str) { - dup_str = strdup (stripe_str); - stripe_opt = CALLOC (1, sizeof (struct stripe_options)); + dup_str = gf_strdup (stripe_str); + stripe_opt = GF_CALLOC (1, sizeof (struct stripe_options), + gf_stripe_mt_stripe_options); if (!stripe_opt) { - FREE (dup_str); + GF_FREE (dup_str); goto out; } @@ -3378,6 +3415,7 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) temp_stripeopt->next = stripe_opt; } stripe_str = strtok_r (NULL, ",", &tmp_str); + GF_FREE (dup_str); } ret = 0; @@ -3385,6 +3423,25 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) return ret; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_stripe_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 when xlator-graph gets initialized. * The option given in volfiles are parsed here. @@ -3423,14 +3480,19 @@ init (xlator_t *this) " please check the volume. exiting"); goto out; } - priv = CALLOC (1, sizeof (stripe_private_t)); + + priv = GF_CALLOC (1, sizeof (stripe_private_t), + gf_stripe_mt_stripe_private_t); + if (!priv) goto out; - priv->xl_array = CALLOC (count, sizeof (xlator_t *)); + priv->xl_array = GF_CALLOC (count, sizeof (xlator_t *), + gf_stripe_mt_xlator_t); if (!priv->xl_array) goto out; - priv->state = CALLOC (count, sizeof (int8_t)); + priv->state = GF_CALLOC (count, sizeof (int8_t), + gf_stripe_mt_int8_t); if (!priv->state) goto out; @@ -3485,8 +3547,8 @@ init (xlator_t *this) if (ret) { if (priv) { if (priv->xl_array) - FREE (priv->xl_array); - FREE (priv); + GF_FREE (priv->xl_array); + GF_FREE (priv); } } return ret; @@ -3506,16 +3568,16 @@ fini (xlator_t *this) priv = this->private; if (priv) { if (priv->xl_array) - FREE (priv->xl_array); + GF_FREE (priv->xl_array); trav = priv->pattern; while (trav) { prev = trav; trav = trav->next; - FREE (prev); + GF_FREE (prev); } LOCK_DESTROY (&priv->lock); - FREE (priv); + GF_FREE (priv); } return; diff --git a/xlators/cluster/stripe/src/stripe.h b/xlators/cluster/stripe/src/stripe.h index 23ee4546..8afc6aa9 100644 --- a/xlators/cluster/stripe/src/stripe.h +++ b/xlators/cluster/stripe/src/stripe.h @@ -32,6 +32,7 @@ #include "common-utils.h" #include "compat.h" #include "compat-errno.h" +#include "stripe-mem-types.h" #include #include 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 00000000..3b4abc8e --- /dev/null +++ b/xlators/cluster/unify/src/unify-mem-types.h @@ -0,0 +1,41 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#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 86f9e88f..88145af9 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 2eadfe31..3f0910df 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 cf3560d5..8dcf1659 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); \ diff --git a/xlators/debug/io-stats/src/io-stats-mem-types.h b/xlators/debug/io-stats/src/io-stats-mem-types.h new file mode 100644 index 00000000..d9b434d5 --- /dev/null +++ b/xlators/debug/io-stats/src/io-stats-mem-types.h @@ -0,0 +1,33 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __IO_STATS_MEM_TYPES_H__ +#define __IO_STATS_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_io_stats_mem_types_ { + gf_io_stats_mt_ios_conf = gf_common_mt_end + 1, + gf_io_stats_mt_ios_fd, + gf_io_stats_mt_end +}; +#endif + diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index e5ccf10b..09ee8675 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -41,6 +41,7 @@ #include #include "glusterfs.h" #include "xlator.h" +#include "io-stats-mem-types.h" struct ios_global_stats { @@ -360,13 +361,13 @@ io_stats_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto unwind; if (op_ret < 0) { - FREE (path); + GF_FREE (path); goto unwind; } - iosfd = CALLOC (1, sizeof (*iosfd)); + iosfd = GF_CALLOC (1, sizeof (*iosfd), gf_io_stats_mt_ios_fd); if (!iosfd) { - FREE (path); + GF_FREE (path); goto unwind; } @@ -396,13 +397,13 @@ io_stats_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto unwind; if (op_ret < 0) { - FREE (path); + GF_FREE (path); goto unwind; } - iosfd = CALLOC (1, sizeof (*iosfd)); + iosfd = GF_CALLOC (1, sizeof (*iosfd), gf_io_stats_mt_ios_fd); if (!iosfd) { - FREE (path); + GF_FREE (path); goto unwind; } @@ -1024,7 +1025,7 @@ io_stats_open (call_frame_t *frame, xlator_t *this, { BUMP_FOP (OPEN); - frame->local = strdup (loc->path); + frame->local = gf_strdup (loc->path); STACK_WIND (frame, io_stats_open_cbk, FIRST_CHILD(this), @@ -1040,7 +1041,7 @@ io_stats_create (call_frame_t *frame, xlator_t *this, { BUMP_FOP (CREATE); - frame->local = strdup (loc->path); + frame->local = gf_strdup (loc->path); STACK_WIND (frame, io_stats_create_cbk, FIRST_CHILD(this), @@ -1382,8 +1383,8 @@ io_stats_release (xlator_t *this, fd_t *fd) io_stats_dump_fd (this, iosfd); if (iosfd->filename) - FREE (iosfd->filename); - FREE (iosfd); + GF_FREE (iosfd->filename); + GF_FREE (iosfd); } return 0; @@ -1407,6 +1408,24 @@ io_stats_forget (xlator_t *this, fd_t *fd) return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_io_stats_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) @@ -1432,7 +1451,7 @@ init (xlator_t *this) options = this->options; - conf = CALLOC (1, sizeof(*conf)); + conf = GF_CALLOC (1, sizeof(*conf), gf_io_stats_mt_ios_conf); LOCK_INIT (&conf->lock); diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index 5d1d342d..7d619aad 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -75,7 +75,7 @@ trace_stat_to_str (struct iatt *stbuf) strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", localtime ((time_t *)&stbuf->ia_ctime)); - asprint_ret_value = asprintf (&statstr, + asprint_ret_value = gf_asprintf (&statstr, "ia_ino=%"PRIu64", ia_gen=%"PRIu64 ", st_mode=%o, ia_nlink=%"GF_PRI_NLINK", " "ia_uid=%d, ia_gid=%d, ia_size=%"PRId64", ia_blocks=%"PRId64 @@ -118,11 +118,11 @@ trace_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, preparentstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -255,10 +255,10 @@ trace_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, preopstr, postopstr); if (preopstr) - FREE (preopstr); + GF_FREE (preopstr); if (postopstr) - FREE (postopstr); + GF_FREE (postopstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -324,10 +324,10 @@ trace_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, preopstr, postopstr); if (preopstr) - FREE (preopstr); + GF_FREE (preopstr); if (postopstr) - FREE (postopstr); + GF_FREE (postopstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -472,10 +472,10 @@ trace_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, postparentstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -519,16 +519,16 @@ trace_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, prenewparentstr, postnewparentstr); if (preoldparentstr) - FREE (preoldparentstr); + GF_FREE (preoldparentstr); if (postoldparentstr) - FREE (postoldparentstr); + GF_FREE (postoldparentstr); if (prenewparentstr) - FREE (prenewparentstr); + GF_FREE (prenewparentstr); if (postnewparentstr) - FREE (postnewparentstr); + GF_FREE (postnewparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -569,7 +569,7 @@ trace_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, frame->root->unique, op_ret, op_errno); if (statstr) - FREE (statstr); + GF_FREE (statstr); } STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, buf, stbuf); @@ -598,9 +598,9 @@ trace_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -638,13 +638,13 @@ trace_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, preparentstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, @@ -683,13 +683,13 @@ trace_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, preparentstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -727,13 +727,13 @@ trace_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, preparentstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -771,13 +771,13 @@ trace_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, statstr, preparentstr, postparentstr); if (statstr) - FREE (statstr); + GF_FREE (statstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -841,10 +841,10 @@ trace_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, postparentstr); if (preparentstr) - FREE (preparentstr); + GF_FREE (preparentstr); if (postparentstr) - FREE (postparentstr); + GF_FREE (postparentstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -878,10 +878,10 @@ trace_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, postopstr); if (preopstr) - FREE (preopstr); + GF_FREE (preopstr); if (postopstr) - FREE (postopstr); + GF_FREE (postopstr); } else { gf_log (this->name, GF_LOG_NORMAL, "%"PRId64": (op_ret=%d, op_errno=%d)", @@ -1017,10 +1017,10 @@ trace_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, prebufstr, postbufstr); if (prebufstr) - FREE (prebufstr); + GF_FREE (prebufstr); if (postbufstr) - FREE (postbufstr); + GF_FREE (postbufstr); } else { gf_log (this->name, GF_LOG_NORMAL, diff --git a/xlators/features/filter/src/filter-mem-types.h b/xlators/features/filter/src/filter-mem-types.h new file mode 100644 index 00000000..cca35443 --- /dev/null +++ b/xlators/features/filter/src/filter-mem-types.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __FILTER_MEM_TYPES_H__ +#define __FILTER_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_filter_mem_types_ { + gf_filter_mt_gf_filter = gf_common_mt_end + 1, + gf_filter_mt_end +}; +#endif + diff --git a/xlators/features/filter/src/filter.c b/xlators/features/filter/src/filter.c index 0f5e67fb..a0469bf6 100644 --- a/xlators/features/filter/src/filter.c +++ b/xlators/features/filter/src/filter.c @@ -30,6 +30,7 @@ #include "logging.h" #include "dict.h" #include "xlator.h" +#include "filter-mem-types.h" #define GF_FILTER_NOBODY_UID 65534 #define GF_FILTER_NOBODY_GID 65534 @@ -1355,6 +1356,25 @@ filter_removexattr (call_frame_t *frame, return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_filter_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) { @@ -1384,7 +1404,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - filter = CALLOC (sizeof (*filter), 1); + filter = GF_CALLOC (sizeof (*filter), 1, gf_filter_mt_gf_filter); ERR_ABORT (filter); if (dict_get (this->options, "read-only")) { @@ -1419,11 +1439,11 @@ init (xlator_t *this) option_data = dict_get (this->options, "translate-uid"); value = strtok_r (option_data->data, ",", &tmp_str); while (value) { - dup_str = strdup (value); + dup_str = gf_strdup (value); input_value_str1 = strtok_r (dup_str, "=", &tmp_str1); if (input_value_str1) { /* Check for n-m */ - char *temp_string = strdup (input_value_str1); + char *temp_string = gf_strdup (input_value_str1); input_value_str2 = strtok_r (temp_string, "-", &tmp_str2); if (gf_string2int (input_value_str2, &input_value) != 0) { gf_log (this->name, GF_LOG_ERROR, @@ -1442,7 +1462,7 @@ init (xlator_t *this) } } filter->translate_input_uid[filter->translate_num_uid_entries][1] = input_value; - FREE (temp_string); + GF_FREE (temp_string); output_value_str = strtok_r (NULL, "=", &tmp_str1); if (output_value_str) { if (gf_string2int (output_value_str, &output_value) != 0) { @@ -1471,7 +1491,7 @@ init (xlator_t *this) if (filter->translate_num_uid_entries == GF_MAXIMUM_FILTERING_ALLOWED) break; value = strtok_r (NULL, ",", &tmp_str); - FREE (dup_str); + GF_FREE (dup_str); } } @@ -1483,11 +1503,11 @@ init (xlator_t *this) option_data = dict_get (this->options, "translate-gid"); value = strtok_r (option_data->data, ",", &tmp_str); while (value) { - dup_str = strdup (value); + dup_str = gf_strdup (value); input_value_str1 = strtok_r (dup_str, "=", &tmp_str1); if (input_value_str1) { /* Check for n-m */ - char *temp_string = strdup (input_value_str1); + char *temp_string = gf_strdup (input_value_str1); input_value_str2 = strtok_r (temp_string, "-", &tmp_str2); if (gf_string2int (input_value_str2, &input_value) != 0) { gf_log (this->name, GF_LOG_ERROR, @@ -1506,7 +1526,7 @@ init (xlator_t *this) } } filter->translate_input_gid[filter->translate_num_gid_entries][1] = input_value; - FREE (temp_string); + GF_FREE (temp_string); output_value_str = strtok_r (NULL, "=", &tmp_str1); if (output_value_str) { if (gf_string2int (output_value_str, &output_value) != 0) { @@ -1536,7 +1556,7 @@ init (xlator_t *this) if (filter->translate_num_gid_entries == GF_MAXIMUM_FILTERING_ALLOWED) break; value = strtok_r (NULL, ",", &tmp_str); - FREE (dup_str); + GF_FREE (dup_str); } } @@ -1547,7 +1567,7 @@ init (xlator_t *this) option_data = dict_get (this->options, "filter-uid"); value = strtok_r (option_data->data, ",", &tmp_str); while (value) { - dup_str = strdup (value); + dup_str = gf_strdup (value); /* Check for n-m */ input_value_str1 = strtok_r (dup_str, "-", &tmp_str1); if (gf_string2int (input_value_str1, &input_value) != 0) { @@ -1577,7 +1597,7 @@ init (xlator_t *this) if (filter->filter_num_uid_entries == GF_MAXIMUM_FILTERING_ALLOWED) break; value = strtok_r (NULL, ",", &tmp_str); - FREE (dup_str); + GF_FREE (dup_str); } filter->partial_filter = 1; } @@ -1589,7 +1609,7 @@ init (xlator_t *this) option_data = dict_get (this->options, "filter-gid"); value = strtok_r (option_data->data, ",", &tmp_str); while (value) { - dup_str = strdup (value); + dup_str = gf_strdup (value); /* Check for n-m */ input_value_str1 = strtok_r (dup_str, "-", &tmp_str1); if (gf_string2int (input_value_str1, &input_value) != 0) { @@ -1619,7 +1639,7 @@ init (xlator_t *this) if (filter->filter_num_gid_entries == GF_MAXIMUM_FILTERING_ALLOWED) break; value = strtok_r (NULL, ",", &tmp_str); - FREE (dup_str); + GF_FREE (dup_str); } gf_log (this->name, GF_LOG_ERROR, "this option is not supported currently.. exiting"); return -1; @@ -1660,7 +1680,7 @@ fini (xlator_t *this) { struct gf_filter *filter = this->private; - FREE (filter); + GF_FREE (filter); return; } diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 83800ff5..9568c2a5 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -48,12 +48,13 @@ allocate_domain (const char *volume) { pl_dom_list_t *dom = NULL; - dom = CALLOC (1, sizeof (*dom)); + dom = GF_CALLOC (1, sizeof (*dom), + gf_locks_mt_pl_dom_list_t); if (!dom) return NULL; - dom->domain = strdup(volume); + dom->domain = gf_strdup(volume); if (!dom->domain) { gf_log ("posix-locks", GF_LOG_TRACE, "Out of Memory"); @@ -151,7 +152,7 @@ pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc) } if (loc && loc->path) { - ipath = strdup (loc->path); + ipath = gf_strdup (loc->path); } else { ret = inode_path (inode, NULL, &ipath); if (ret <= 0) @@ -163,7 +164,7 @@ pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc) ipath ? ipath : ""); if (ipath) - FREE (ipath); + GF_FREE (ipath); } @@ -418,7 +419,8 @@ pl_inode_get (xlator_t *this, inode_t *inode) pl_inode = (pl_inode_t *)(long)tmp_pl_inode; goto out; } - pl_inode = CALLOC (1, sizeof (*pl_inode)); + pl_inode = GF_CALLOC (1, sizeof (*pl_inode), + gf_locks_mt_pl_inode_t); if (!pl_inode) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -454,7 +456,8 @@ new_posix_lock (struct flock *flock, transport_t *transport, pid_t client_pid, { posix_lock_t *lock = NULL; - lock = CALLOC (1, sizeof (posix_lock_t)); + lock = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); if (!lock) { return NULL; } @@ -490,7 +493,7 @@ __delete_lock (pl_inode_t *pl_inode, posix_lock_t *lock) void __destroy_lock (posix_lock_t *lock) { - free (lock); + GF_FREE (lock); } @@ -567,7 +570,8 @@ add_locks (posix_lock_t *l1, posix_lock_t *l2) { posix_lock_t *sum = NULL; - sum = CALLOC (1, sizeof (posix_lock_t)); + sum = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); if (!sum) return NULL; @@ -591,7 +595,8 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small) if ((big->fl_start == small->fl_start) && (big->fl_end == small->fl_end)) { /* both edges coincide with big */ - v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[0]); memcpy (v.locks[0], big, sizeof (posix_lock_t)); v.locks[0]->fl_type = small->fl_type; @@ -599,11 +604,14 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small) else if ((small->fl_start > big->fl_start) && (small->fl_end < big->fl_end)) { /* both edges lie inside big */ - v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[0]); - v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[1]); - v.locks[2] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[2]); memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -615,9 +623,11 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small) } /* one edge coincides with big */ else if (small->fl_start == big->fl_start) { - v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[0]); - v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[1]); memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -626,9 +636,11 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small) memcpy (v.locks[1], small, sizeof (posix_lock_t)); } else if (small->fl_end == big->fl_end) { - v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[0]); - v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); + v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), + gf_locks_mt_posix_lock_t); ERR_ABORT (v.locks[1]); memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -800,7 +812,8 @@ __grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, struct list_head *g list_del_init (&l->list); if (__is_lock_grantable (pl_inode, l)) { - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), + gf_locks_mt_posix_lock_t); if (!conf) { l->blocked = 1; @@ -855,7 +868,7 @@ grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode) STACK_UNWIND (lock->frame, 0, 0, &lock->user_flock); - FREE (lock); + GF_FREE (lock); } return; diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c index b83044b7..e4b9bb56 100644 --- a/xlators/features/locks/src/entrylk.c +++ b/xlators/features/locks/src/entrylk.c @@ -40,12 +40,13 @@ new_entrylk_lock (pl_inode_t *pinode, const char *basename, entrylk_type type, { pl_entry_lock_t *newlock = NULL; - newlock = CALLOC (1, sizeof (pl_entry_lock_t)); + newlock = GF_CALLOC (1, sizeof (pl_entry_lock_t), + gf_locks_mt_pl_entry_lock_t); if (!newlock) { goto out; } - newlock->basename = basename ? strdup (basename) : NULL; + newlock->basename = basename ? gf_strdup (basename) : NULL; newlock->type = type; newlock->trans = trans; newlock->volume = volume; @@ -457,8 +458,8 @@ __grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode, list_add (&bl->blocked_locks, granted); } else { if (bl->basename) - FREE (bl->basename); - FREE (bl); + GF_FREE ((char *)bl->basename); + GF_FREE (bl); } } return; @@ -490,12 +491,12 @@ grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode, STACK_UNWIND_STRICT (entrylk, lock->frame, 0, 0); - FREE (lock->basename); - FREE (lock); + GF_FREE ((char *)lock->basename); + GF_FREE (lock); } - FREE (unlocked->basename); - FREE (unlocked); + GF_FREE ((char *)unlocked->basename); + GF_FREE (unlocked); return; } @@ -545,8 +546,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode, "releasing lock on held by " "{transport=%p}",trans); - FREE (lock->basename); - FREE (lock); + GF_FREE ((char *)lock->basename); + GF_FREE (lock); } __grant_blocked_entry_locks (this, pinode, dom, &granted); @@ -561,8 +562,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode, STACK_UNWIND_STRICT (entrylk, lock->frame, -1, EAGAIN); if (lock->basename) - FREE (lock->basename); - FREE (lock); + GF_FREE ((char *)lock->basename); + GF_FREE (lock); } @@ -572,8 +573,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode, STACK_UNWIND_STRICT (entrylk, lock->frame, 0, 0); if (lock->basename) - FREE (lock->basename); - FREE (lock); + GF_FREE ((char *)lock->basename); + GF_FREE (lock); } return 0; diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c index 50a5996d..64028d07 100644 --- a/xlators/features/locks/src/inodelk.c +++ b/xlators/features/locks/src/inodelk.c @@ -42,7 +42,7 @@ __delete_inode_lock (pl_inode_lock_t *lock) void __destroy_inode_lock (pl_inode_lock_t *lock) { - FREE (lock); + GF_FREE (lock); } /* Check if 2 inodelks are conflicting on type. Only 2 shared locks don't conflict */ @@ -439,7 +439,7 @@ release_inode_locks_of_transport (xlator_t *this, pl_dom_list_t *dom, } unlock: if (path) - FREE (path); + GF_FREE (path); pthread_mutex_unlock (&pinode->mutex); @@ -447,7 +447,7 @@ unlock: list_del_init (&l->blocked_locks); STACK_UNWIND_STRICT (inodelk, l->frame, -1, EAGAIN); - FREE (l); + GF_FREE (l); } grant_blocked_inode_locks (this, pinode, dom); @@ -515,7 +515,8 @@ new_inode_lock (struct flock *flock, transport_t *transport, pid_t client_pid, { pl_inode_lock_t *lock = NULL; - lock = CALLOC (1, sizeof (*lock)); + lock = GF_CALLOC (1, sizeof (*lock), + gf_locks_mt_pl_inode_lock_t); if (!lock) { return NULL; } diff --git a/xlators/features/locks/src/locks-mem-types.h b/xlators/features/locks/src/locks-mem-types.h new file mode 100644 index 00000000..cf502408 --- /dev/null +++ b/xlators/features/locks/src/locks-mem-types.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __LOCKS_MEM_TYPES_H__ +#define __LOCKS_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_locks_mem_types_ { + gf_locks_mt_pl_dom_list_t = gf_common_mt_end + 1, + gf_locks_mt_pl_inode_t, + gf_locks_mt_posix_lock_t, + gf_locks_mt_pl_entry_lock_t, + gf_locks_mt_pl_inode_lock_t, + gf_locks_mt_truncate_ops, + gf_locks_mt_pl_rw_req_t, + gf_locks_mt_posix_locks_private_t, + gf_locks_mt_pl_local_t, + gf_locks_mt_end +}; +#endif + diff --git a/xlators/features/locks/src/locks.h b/xlators/features/locks/src/locks.h index e8909281..01764484 100644 --- a/xlators/features/locks/src/locks.h +++ b/xlators/features/locks/src/locks.h @@ -29,6 +29,7 @@ #include "transport.h" #include "stack.h" #include "call-stub.h" +#include "locks-mem-types.h" struct __pl_fd; diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index 2e6afd9f..83b3eb34 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -180,7 +180,8 @@ pl_truncate (call_frame_t *frame, xlator_t *this, { struct _truncate_ops *local = NULL; - local = CALLOC (1, sizeof (struct _truncate_ops)); + local = GF_CALLOC (1, sizeof (struct _truncate_ops), + gf_locks_mt_truncate_ops); if (!local) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -211,7 +212,8 @@ pl_ftruncate (call_frame_t *frame, xlator_t *this, { struct _truncate_ops *local = NULL; - local = CALLOC (1, sizeof (struct _truncate_ops)); + local = GF_CALLOC (1, sizeof (struct _truncate_ops), + gf_locks_mt_truncate_ops); if (!local) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -522,7 +524,7 @@ do_blocked_rw (pl_inode_t *pl_inode) list_for_each_entry_safe (rw, tmp, &wind_list, list) { list_del_init (&rw->list); call_resume (rw->stub); - free (rw); + GF_FREE (rw); } return; @@ -601,7 +603,8 @@ pl_readv (call_frame_t *frame, xlator_t *this, goto unlock; } - rw = CALLOC (1, sizeof (*rw)); + rw = GF_CALLOC (1, sizeof (*rw), + gf_locks_mt_pl_rw_req_t); if (!rw) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -617,7 +620,7 @@ pl_readv (call_frame_t *frame, xlator_t *this, "Out of memory."); op_errno = ENOMEM; op_ret = -1; - free (rw); + GF_FREE (rw); goto unlock; } @@ -698,7 +701,8 @@ pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, goto unlock; } - rw = CALLOC (1, sizeof (*rw)); + rw = GF_CALLOC (1, sizeof (*rw), + gf_locks_mt_pl_rw_req_t); if (!rw) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -715,7 +719,7 @@ pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, "Out of memory."); op_errno = ENOMEM; op_ret = -1; - free (rw); + GF_FREE (rw); goto unlock; } @@ -876,7 +880,7 @@ pl_forget (xlator_t *this, list) { list_del (&rw_req->list); - FREE (rw_req); + GF_FREE (rw_req); } } @@ -920,8 +924,8 @@ pl_forget (xlator_t *this, list_del_init (&entry_l->domain_list); if (entry_l->basename) - FREE (entry_l->basename); - FREE (entry_l); + GF_FREE ((char *)entry_l->basename); + GF_FREE (entry_l); } list_splice_init (&dom->blocked_entrylks, &entrylks_released); @@ -930,8 +934,8 @@ pl_forget (xlator_t *this, list_del (&dom->inode_list); gf_log ("posix-locks", GF_LOG_TRACE, " Cleaning up domain: %s", dom->domain); - FREE (dom->domain); - FREE (dom); + GF_FREE ((char *)(dom->domain)); + GF_FREE (dom); } } @@ -953,12 +957,12 @@ pl_forget (xlator_t *this, STACK_UNWIND_STRICT (entrylk, entry_l->frame, -1, 0); if (entry_l->basename) - FREE (entry_l->basename); - FREE (entry_l); + GF_FREE ((char *)entry_l->basename); + GF_FREE (entry_l); } - FREE (pl_inode); + GF_FREE (pl_inode); return 0; } @@ -1117,7 +1121,7 @@ pl_lookup_cbk (call_frame_t *frame, frame->local = NULL; if (local != NULL) - FREE (local); + GF_FREE (local); out: STACK_UNWIND (frame, @@ -1143,7 +1147,7 @@ pl_lookup (call_frame_t *frame, VALIDATE_OR_GOTO (this, out); VALIDATE_OR_GOTO (loc, out); - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_locks_mt_pl_local_t); if (!local) { ret = -1; gf_log (this->name, GF_LOG_ERROR, @@ -1437,7 +1441,24 @@ pl_dump_inode (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_locks_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) @@ -1469,7 +1490,8 @@ init (xlator_t *this) return -1; } - priv = CALLOC (1, sizeof (*priv)); + priv = GF_CALLOC (1, sizeof (*priv), + gf_locks_mt_posix_locks_private_t); mandatory = dict_get (this->options, "mandatory-locks"); if (mandatory) @@ -1497,7 +1519,7 @@ fini (xlator_t *this) posix_locks_private_t *priv = NULL; priv = this->private; - free (priv); + GF_FREE (priv); return 0; } diff --git a/xlators/features/path-convertor/src/path-mem-types.h b/xlators/features/path-convertor/src/path-mem-types.h new file mode 100644 index 00000000..99f79467 --- /dev/null +++ b/xlators/features/path-convertor/src/path-mem-types.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __PATH_MEM_TYPES_H__ +#define __PATH_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_path_mem_types_ { + gf_path_mt_path_private_t = gf_common_mt_end + 1, + gf_path_mt_char, + gf_path_mt_regex_t, + gf_path_mt_end +}; +#endif + diff --git a/xlators/features/path-convertor/src/path.c b/xlators/features/path-convertor/src/path.c index 3589e148..eda16338 100644 --- a/xlators/features/path-convertor/src/path.c +++ b/xlators/features/path-convertor/src/path.c @@ -35,6 +35,7 @@ #include #include "glusterfs.h" #include "xlator.h" +#include "path-mem-types.h" typedef struct path_private { @@ -63,7 +64,9 @@ name_this_to_that (xlator_t *xl, const char *path, const char *name) if (priv->end_off && (total_len > priv->end_off)) { j = priv->start_off; - tmp_name = CALLOC (1, (total_len + ZR_FILE_CONTENT_STRLEN)); + tmp_name = GF_CALLOC (1, (total_len + + ZR_FILE_CONTENT_STRLEN), + gf_path_mt_char); ERR_ABORT (tmp_name); /* Get the complete path for the file first */ @@ -104,7 +107,7 @@ path_this_to_that (xlator_t *xl, const char *path) int32_t i = 0, j = 0; if (priv->end_off && (path_len > priv->start_off)) { - priv_path = CALLOC (1, path_len); + priv_path = GF_CALLOC (1, path_len, gf_path_mt_char); ERR_ABORT (priv_path); if (priv->start_off && (path_len > priv->start_off)) @@ -378,7 +381,7 @@ path_lookup (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -405,7 +408,7 @@ path_stat (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -434,7 +437,7 @@ path_readlink (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -465,7 +468,7 @@ path_mknod (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -494,7 +497,7 @@ path_mkdir (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -521,7 +524,7 @@ path_unlink (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -548,7 +551,7 @@ path_rmdir (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -577,7 +580,7 @@ path_symlink (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -615,11 +618,11 @@ path_rename (call_frame_t *frame, oldloc->path = oldloc_path; if (tmp_oldloc_path != oldloc_path) - FREE (tmp_oldloc_path); + GF_FREE (tmp_oldloc_path); newloc->path = newloc_path; if (tmp_newloc_path != newloc_path) - FREE (tmp_newloc_path); + GF_FREE (tmp_newloc_path); return 0; } @@ -657,11 +660,11 @@ path_link (call_frame_t *frame, oldloc->path = oldloc_path; if (tmp_oldloc_path != oldloc_path) - FREE (tmp_oldloc_path); + GF_FREE (tmp_oldloc_path); newloc->path = newloc_path; if (tmp_newloc_path != newloc_path) - FREE (tmp_newloc_path); + GF_FREE (tmp_newloc_path); return 0; } @@ -704,7 +707,7 @@ path_setattr (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -734,7 +737,7 @@ path_truncate (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -768,7 +771,7 @@ path_open (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -801,7 +804,7 @@ path_create (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -843,10 +846,10 @@ path_setxattr (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); if (tmp_name) - FREE (tmp_name); + GF_FREE (tmp_name); return 0; } @@ -880,10 +883,10 @@ path_getxattr (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); if (tmp_name != name) - FREE (tmp_name); + GF_FREE (tmp_name); return 0; } @@ -917,10 +920,10 @@ path_removexattr (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); if (tmp_name != name) - FREE (tmp_name); + GF_FREE (tmp_name); return 0; } @@ -949,7 +952,7 @@ path_opendir (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -978,7 +981,7 @@ path_access (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -1020,7 +1023,7 @@ path_checksum (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -1047,7 +1050,7 @@ path_entrylk (call_frame_t *frame, xlator_t *this, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -1073,7 +1076,7 @@ path_inodelk (call_frame_t *frame, xlator_t *this, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } @@ -1105,11 +1108,29 @@ path_xattrop (call_frame_t *frame, loc->path = loc_path; if (tmp_path != loc_path) - FREE (tmp_path); + GF_FREE (tmp_path); return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_path_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) @@ -1128,7 +1149,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - priv = CALLOC (1, sizeof (*priv)); + priv = GF_CALLOC (1, sizeof (*priv), gf_path_mt_path_private_t); ERR_ABORT (priv); if (dict_get (options, "start-offset")) { priv->start_off = data_to_int32 (dict_get (options, @@ -1141,7 +1162,8 @@ init (xlator_t *this) if (dict_get (options, "regex")) { int32_t ret = 0; - priv->preg = CALLOC (1, sizeof (regex_t)); + priv->preg = GF_CALLOC (1, sizeof (regex_t), + gf_path_mt_regex_t); ERR_ABORT (priv->preg); ret = regcomp (priv->preg, data_to_str (dict_get (options, "regex")), @@ -1149,7 +1171,7 @@ init (xlator_t *this) if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to compile the 'option regex'"); - FREE (priv); + GF_FREE (priv); return -1; } if (dict_get (options, "replace-with")) { diff --git a/xlators/features/quota/src/quota-mem-types.h b/xlators/features/quota/src/quota-mem-types.h new file mode 100644 index 00000000..b71314ed --- /dev/null +++ b/xlators/features/quota/src/quota-mem-types.h @@ -0,0 +1,31 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __QUOTA_MEM_TYPES_H__ +#define __QUOTA_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_quota_mem_types_ { + gf_quota_mt_quota_local = gf_common_mt_end + 1, + gf_quota_mt_quota_priv, + gf_quota_mt_end +}; +#endif + diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 822c29bd..3b4690bf 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -27,6 +27,7 @@ #include "xlator.h" #include "defaults.h" #include "common-utils.h" +#include "quota-mem-types.h" #ifndef MAX_IOVEC #define MAX_IOVEC 16 @@ -204,7 +205,8 @@ quota_truncate (call_frame_t *frame, xlator_t *this, priv = this->private; if (priv->disk_usage_limit) { - local = CALLOC (1, sizeof (struct quota_local)); + local = GF_CALLOC (1, sizeof (struct quota_local), + gf_quota_mt_quota_local); frame->local = local; loc_copy (&local->loc, loc); @@ -279,7 +281,8 @@ quota_ftruncate (call_frame_t *frame, xlator_t *this, priv = this->private; if (priv->disk_usage_limit) { - local = CALLOC (1, sizeof (struct quota_local)); + local = GF_CALLOC (1, sizeof (struct quota_local), + gf_quota_mt_quota_local); frame->local = local; local->fd = fd_ref (fd); @@ -462,7 +465,8 @@ quota_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) priv = this->private; if (priv->disk_usage_limit) { - local = CALLOC (1, sizeof (struct quota_local)); + local = GF_CALLOC (1, sizeof (struct quota_local), + gf_quota_mt_quota_local); frame->local = local; loc_copy (&local->loc, loc); @@ -534,7 +538,8 @@ quota_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) priv = this->private; if (priv->disk_usage_limit) { - local = CALLOC (1, sizeof (struct quota_local)); + local = GF_CALLOC (1, sizeof (struct quota_local), + gf_quota_mt_quota_local); frame->local = local; loc_copy (&local->loc, loc); @@ -772,7 +777,8 @@ quota_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, } if (priv->disk_usage_limit) { - local = CALLOC (1, sizeof (struct quota_local)); + local = GF_CALLOC (1, sizeof (struct quota_local), + gf_quota_mt_quota_local); local->fd = fd_ref (fd); local->iobref = iobref_ref (iobref); for (i = 0; i < count; i++) { @@ -1018,7 +1024,26 @@ quota_lookup (call_frame_t *frame, loc, xattr_req); return 0; - } +} + +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_quota_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) @@ -1038,7 +1063,8 @@ init (xlator_t *this) "dangling volume. check volfile "); } - _private = CALLOC (1, sizeof (struct quota_priv)); + _private = GF_CALLOC (1, sizeof (struct quota_priv), + gf_quota_mt_quota_priv); _private->disk_usage_limit = 0; data = dict_get (this->options, "disk-usage-limit"); if (data) { diff --git a/xlators/features/trash/src/trash-mem-types.h b/xlators/features/trash/src/trash-mem-types.h new file mode 100644 index 00000000..48613d1e --- /dev/null +++ b/xlators/features/trash/src/trash-mem-types.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __TRASH_MEM_TYPES_H__ +#define __TRASH_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_trash_mem_types_ { + gf_trash_mt_trash_local_t = gf_common_mt_end + 1, + gf_trash_mt_trash_private_t, + gf_trash_mt_char, + gf_trash_mt_trash_elim_pattern_t, + gf_trash_mt_end +}; +#endif + diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index 5ee3da2c..ff060cc5 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -23,7 +23,7 @@ #endif #include "trash.h" - +#include "trash-mem-types.h" int32_t trash_ftruncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -63,7 +63,7 @@ trash_local_wipe (trash_local_t *local) if (local->newfd) fd_unref (local->newfd); - FREE (local); + GF_FREE (local); out: return; } @@ -94,7 +94,7 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loc_t tmp_loc = {0,}; local = frame->local; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -166,8 +166,8 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, &tmp_loc, 0755); out: - free (cookie); - free (tmp_str); + GF_FREE (cookie); + GF_FREE (tmp_str); return 0; } @@ -195,7 +195,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -203,7 +203,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, tmp_loc.path = dir_name; - tmp_cookie = strdup (dir_name); + tmp_cookie = gf_strdup (dir_name); if (!tmp_cookie) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -213,7 +213,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, FIRST_CHILD(this)->fops->mkdir, &tmp_loc, 0755); - free (tmp_str); + GF_FREE (tmp_str); return 0; } @@ -337,7 +337,7 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -346,7 +346,7 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, /* check for the errno, if its ENOENT create directory and call * rename later */ - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -358,7 +358,7 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, this->children->xlator->fops->mkdir, &tmp_loc, 0755); - free (tmp_str); + GF_FREE (tmp_str); return 0; } @@ -396,7 +396,7 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loc_t tmp_loc = {0,}; local = frame->local; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -438,8 +438,8 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -529,7 +529,8 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = GF_CALLOC (1, sizeof (trash_local_t), + gf_trash_mt_trash_local_t); if (!local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); TRASH_STACK_UNWIND (frame, -1, ENOMEM, @@ -605,7 +606,8 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = GF_CALLOC (1, sizeof (trash_local_t), + gf_trash_mt_trash_local_t); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL, NULL); @@ -781,13 +783,13 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if ((op_ret == -1) && (op_errno == ENOENT)) { //Creating the directory structure here. - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } dir_name = dirname (tmp_str); - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -798,7 +800,7 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, tmp_path, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, &tmp_loc, 0755); - free (tmp_str); + GF_FREE (tmp_str); goto out; } @@ -850,7 +852,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loop_count = local->loop_count; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -923,8 +925,8 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, &tmp_loc, 0755); out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -979,8 +981,8 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, strcpy (loc_newname,local->loc.name); strcat (loc_newname,timestr); - local->newloc.name = strdup (loc_newname); - local->newloc.path = strdup (local->newpath); + local->newloc.name = gf_strdup (loc_newname); + local->newloc.path = gf_strdup (local->newpath); local->newloc.inode = inode_new (local->loc.inode->table); local->newloc.ino = local->newloc.inode->ino; local->newfd = fd_create (local->newloc.inode, frame->root->pid); @@ -1036,7 +1038,8 @@ trash_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, LOCK_INIT (&frame->lock); - local = CALLOC (1, sizeof (trash_local_t)); + local = GF_CALLOC (1, sizeof (trash_local_t), + gf_trash_mt_trash_local_t); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL); @@ -1154,13 +1157,13 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } dir_name = dirname (tmp_str); - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1171,7 +1174,7 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, tmp_path, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, &tmp_loc, 0755); - free (tmp_str); + GF_FREE (tmp_str); return 0; } @@ -1214,7 +1217,7 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loop_count = local->loop_count; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1288,8 +1291,8 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, &tmp_loc, 0755); out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -1374,7 +1377,8 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = GF_CALLOC (1, sizeof (trash_local_t), + gf_trash_mt_trash_local_t); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL, NULL); @@ -1438,7 +1442,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - _priv = CALLOC (1, sizeof (*_priv)); + _priv = GF_CALLOC (1, sizeof (*_priv), gf_trash_mt_trash_private_t); if (!_priv) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); return -1; @@ -1449,17 +1453,17 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_NORMAL, "no option specified for 'trash-dir', " "using \"/.trashcan/\""); - _priv->trash_dir = strdup ("/.trashcan"); + _priv->trash_dir = gf_strdup ("/.trashcan"); } else { /* Need a path with '/' as the first char, if not given, append it */ if (data->data[0] == '/') { - _priv->trash_dir = strdup (data->data); + _priv->trash_dir = gf_strdup (data->data); } else { /* TODO: Make sure there is no ".." in the path */ strcpy (trash_dir, "/"); strcat (trash_dir, data->data); - _priv->trash_dir = strdup (trash_dir); + _priv->trash_dir = gf_strdup (trash_dir); } } @@ -1468,7 +1472,7 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_TRACE, "no option specified for 'eliminate', using NULL"); } else { - tmp_str = strdup (data->data); + tmp_str = gf_strdup (data->data); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1476,7 +1480,8 @@ init (xlator_t *this) /* Match Filename to option specified in eliminate. */ component = strtok_r (tmp_str, "|", &strtokptr); while (component) { - trav = CALLOC (1, sizeof (*trav)); + trav = GF_CALLOC (1, sizeof (*trav), + gf_trash_mt_trash_elim_pattern_t); if (!trav) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1521,7 +1526,7 @@ fini (xlator_t *this) priv = this->private; if (priv) - FREE (priv); + GF_FREE (priv); return; } diff --git a/xlators/meta/src/meta-mem-types.h b/xlators/meta/src/meta-mem-types.h new file mode 100644 index 00000000..a9ec9435 --- /dev/null +++ b/xlators/meta/src/meta-mem-types.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#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 7843e816..2babe32f 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; @@ -1214,6 +1219,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) { @@ -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 a5ba08a3..787f27da 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; diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index b57dc0cf..a6ff46a2 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 00000000..b0eb816c --- /dev/null +++ b/xlators/mount/fuse/src/fuse-mem-types.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#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 + diff --git a/xlators/nfs/lib/src/rpcsvc-auth.c b/xlators/nfs/lib/src/rpcsvc-auth.c index 38697965..f61fe91d 100644 --- a/xlators/nfs/lib/src/rpcsvc-auth.c +++ b/xlators/nfs/lib/src/rpcsvc-auth.c @@ -36,7 +36,7 @@ rpcsvc_auth_add_initer (struct list_head *list, char *idfier, if ((!list) || (!init) || (!idfier)) return -1; - new = CALLOC (1, sizeof (*new)); + new = GF_CALLOC (1, sizeof (*new), gf_common_mt_rpcsvc_auth_list); if (!new) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "Memory allocation failed"); return -1; @@ -312,7 +312,7 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen) if (count >= arrlen) break; - gen = asprintf (&srchstr, "rpc-auth.%s", auth->name); + gen = gf_asprintf (&srchstr, "rpc-auth.%s", auth->name); if (gen == -1) { count = -1; goto err; @@ -334,9 +334,9 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen) "d to read auth val"); } - FREE (srchstr); - spec = asprintf (&srchstr, "rpc-auth.%s.%s", auth->name, - volname); + GF_FREE (srchstr); + spec = gf_asprintf (&srchstr, "rpc-auth.%s.%s", auth->name, + volname); if (spec == -1) { count = -1; goto err; @@ -360,7 +360,7 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen) "d to read auth val"); } - FREE (srchstr); + GF_FREE (srchstr); final = rpcsvc_combine_gen_spec_volume_checks (gen, spec); if (final == RPCSVC_AUTH_ACCEPT) { autharr[count] = auth->auth->authnum; diff --git a/xlators/nfs/lib/src/rpcsvc.c b/xlators/nfs/lib/src/rpcsvc.c index 47510ad8..bcb8af65 100644 --- a/xlators/nfs/lib/src/rpcsvc.c +++ b/xlators/nfs/lib/src/rpcsvc.c @@ -78,7 +78,7 @@ rpcsvc_stage_init (rpcsvc_t *svc) if (!svc) return NULL; - stg = CALLOC (1, sizeof(*stg)); + stg = GF_CALLOC (1, sizeof(*stg), gf_common_mt_rpcsvc_stage_t); if (!stg) return NULL; @@ -106,7 +106,7 @@ rpcsvc_stage_init (rpcsvc_t *svc) ret = 0; free_stg: if (ret == -1) { - FREE (stg); + GF_FREE (stg); stg = NULL; } @@ -135,7 +135,7 @@ rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options) if ((!ctx) || (!options)) return NULL; - svc = CALLOC (1, sizeof (*svc)); + svc = GF_CALLOC (1, sizeof (*svc), gf_common_mt_rpcsvc_t); if (!svc) return NULL; @@ -169,7 +169,7 @@ rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options) ret = 0; free_svc: if (ret == -1) { - FREE (svc); + GF_FREE (svc); svc = NULL; } @@ -248,7 +248,7 @@ rpcsvc_conn_peer_check_allow (dict_t *options, char *volname, char *clstr) * subvolumes. */ if (volname) { - ret = asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); + ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); if (ret == -1) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); ret = RPCSVC_AUTH_DONTCARE; @@ -259,7 +259,7 @@ rpcsvc_conn_peer_check_allow (dict_t *options, char *volname, char *clstr) ret = rpcsvc_conn_peer_check_search (options, srchstr, clstr); if (volname) - FREE (srchstr); + GF_FREE (srchstr); if (ret == 0) ret = RPCSVC_AUTH_ACCEPT; @@ -280,7 +280,7 @@ rpcsvc_conn_peer_check_reject (dict_t *options, char *volname, char *clstr) return ret; if (volname) { - ret = asprintf (&srchstr, "rpc-auth.addr.%s.reject", volname); + ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.reject", volname); if (ret == -1) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); ret = RPCSVC_AUTH_REJECT; @@ -291,7 +291,7 @@ rpcsvc_conn_peer_check_reject (dict_t *options, char *volname, char *clstr) ret = rpcsvc_conn_peer_check_search (options, srchstr, clstr); if (volname) - FREE (srchstr); + GF_FREE (srchstr); if (ret == 0) ret = RPCSVC_AUTH_REJECT; @@ -591,14 +591,14 @@ rpcsvc_volume_allowed (dict_t *options, char *volname) if ((!options) || (!volname)) return NULL; - ret = asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); + ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname); if (ret == -1) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); goto out; } if (!dict_get (options, srchstr)) { - FREE (srchstr); + GF_FREE (srchstr); srchstr = globalrule; ret = dict_get_str (options, srchstr, &addrstr); } else @@ -617,7 +617,7 @@ rpcsvc_conn_init (rpcsvc_t *svc, rpcsvc_program_t *prog, int sockfd) int ret = -1; unsigned int poolcount = 0; - conn = CALLOC (1, sizeof(*conn)); + conn = GF_CALLOC (1, sizeof(*conn), gf_common_mt_rpcsvc_conn_t); if (!conn) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed"); return NULL; @@ -659,7 +659,7 @@ free_txp: free_conn: if (ret == -1) { - FREE (conn); + GF_FREE (conn); conn = NULL; } @@ -677,7 +677,7 @@ rpcsvc_conn_destroy (rpcsvc_conn_t *conn) conn->program->conn_destroy (conn->program->private, conn); /* Need to destory record state, txlists etc. */ - FREE (conn); + GF_FREE (conn); gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Connection destroyed"); } @@ -917,7 +917,7 @@ rpcsvc_conn_privport_check (rpcsvc_t *svc, char *volname, rpcsvc_conn_t *conn) } /* Disabled by default */ - ret = asprintf (&srchstr, "rpc-auth.ports.%s.insecure", volname); + ret = gf_asprintf (&srchstr, "rpc-auth.ports.%s.insecure", volname); if (ret == -1) { gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed"); ret = RPCSVC_AUTH_REJECT; @@ -2632,7 +2632,7 @@ rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t program) if (!svc) return -1; - newprog = CALLOC (1, sizeof(*newprog)); + newprog = GF_CALLOC (1, sizeof(*newprog), gf_common_mt_rpcsvc_program_t); if (!newprog) return -1; @@ -2666,7 +2666,7 @@ free_prog: gf_log (GF_RPCSVC, GF_LOG_ERROR, "Program registration failed:" " %s, Num: %d, Ver: %d, Port: %d", newprog->progname, newprog->prognum, newprog->progver, newprog->progport); - FREE (newprog); + GF_FREE (newprog); } return ret; diff --git a/xlators/nfs/lib/src/xdr-nfs3.c b/xlators/nfs/lib/src/xdr-nfs3.c index 7d8075a5..d7984be5 100644 --- a/xlators/nfs/lib/src/xdr-nfs3.c +++ b/xlators/nfs/lib/src/xdr-nfs3.c @@ -1841,15 +1841,15 @@ xdr_free_exports_list (struct exportnode *first) while (first) { elist = first->ex_next; if (first->ex_dir) - FREE (first->ex_dir); + GF_FREE (first->ex_dir); if (first->ex_groups) { if (first->ex_groups->gr_name) - FREE (first->ex_groups->gr_name); - FREE (first->ex_groups); + GF_FREE (first->ex_groups->gr_name); + GF_FREE (first->ex_groups); } - FREE (first); + GF_FREE (first); first = elist; } @@ -1865,10 +1865,10 @@ xdr_free_mountlist (mountlist ml) return; while (ml) { - FREE (ml->ml_hostname); - FREE (ml->ml_directory); + GF_FREE (ml->ml_hostname); + GF_FREE (ml->ml_directory); next = ml->ml_next; - FREE (ml); + GF_FREE (ml); ml = next; } @@ -1885,8 +1885,8 @@ xdr_free_write3args_nocopy (write3args *wa) if (!wa) return; - FREE (wa->file.data.data_val); - FREE (wa); + GF_FREE (wa->file.data.data_val); + GF_FREE (wa); } diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index db4a88e3..c3792b31 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 @@ -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 3623f041..69bf4670 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 00000000..118ee2d2 --- /dev/null +++ b/xlators/nfs/server/src/nfs-mem-types.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#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 b598b0c6..fa7edc9f 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 72861dfd..52bb7169 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 @@ -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 57d9f576..a4ef1c6f 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 @@ -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; } diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 9bf20be5..9f402f1d 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -27,6 +27,7 @@ #include "dict.h" #include "xlator.h" #include "io-cache.h" +#include "ioc-mem-types.h" #include #include @@ -259,7 +260,8 @@ ioc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, ioc_local_t *local = NULL; int32_t op_errno = -1, ret = -1; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_ioc_mt_ioc_local_t); if (local == NULL) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -401,7 +403,8 @@ ioc_wait_on_inode (ioc_inode_t *ioc_inode, ioc_page_t *page) } if (!page_found) { - waiter = CALLOC (1, sizeof (ioc_waitq_t)); + waiter = GF_CALLOC (1, sizeof (ioc_waitq_t), + gf_ioc_mt_ioc_waitq_t); if (waiter == NULL) { gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR, "out of memory"); @@ -436,7 +439,8 @@ ioc_cache_validate (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd, int32_t ret = 0; local = frame->local; - validate_local = CALLOC (1, sizeof (ioc_local_t)); + validate_local = GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (validate_local == NULL) { ret = -1; local->op_ret = -1; @@ -451,7 +455,7 @@ ioc_cache_validate (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd, ret = -1; local->op_ret = -1; local->op_errno = ENOMEM; - FREE (validate_local); + GF_FREE (validate_local); gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR, "out of memory"); goto out; @@ -563,7 +567,7 @@ ioc_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, } } - FREE (local); + GF_FREE (local); frame->local = NULL; STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); @@ -641,7 +645,7 @@ ioc_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } frame->local = NULL; - FREE (local); + GF_FREE (local); STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, preparent, postparent); @@ -664,7 +668,7 @@ ioc_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, ioc_local_t *local = NULL; - local = CALLOC (1, sizeof (ioc_local_t)); + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); STACK_UNWIND_STRICT (open, frame, -1, ENOMEM, NULL); @@ -698,8 +702,8 @@ ioc_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, mode_t mode, fd_t *fd) { ioc_local_t *local = NULL; - - local = CALLOC (1, sizeof (ioc_local_t)); + + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); STACK_UNWIND_STRICT (create, frame, -1, ENOMEM, NULL, NULL, @@ -1021,7 +1025,8 @@ ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, return 0; } - local = (ioc_local_t *) CALLOC (1, sizeof (ioc_local_t)); + local = (ioc_local_t *) GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1105,7 +1110,7 @@ ioc_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, ioc_local_t *local = NULL; uint64_t ioc_inode = 0; - local = CALLOC (1, sizeof (ioc_local_t)); + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1270,7 +1275,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) char *string = NULL; struct ioc_priority *curr = NULL, *tmp = NULL; - string = strdup (opt_str); + string = gf_strdup (opt_str); if (string == NULL) { max_pri = -1; goto out; @@ -1284,7 +1289,8 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) */ stripe_str = strtok_r (string, ",", &tmp_str); while (stripe_str) { - curr = CALLOC (1, sizeof (struct ioc_priority)); + curr = GF_CALLOC (1, sizeof (struct ioc_priority), + gf_ioc_mt_ioc_priority); if (curr == NULL) { max_pri = -1; goto out; @@ -1292,7 +1298,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) list_add_tail (&curr->list, first); - dup_str = strdup (stripe_str); + dup_str = gf_strdup (stripe_str); if (dup_str == NULL) { max_pri = -1; goto out; @@ -1315,7 +1321,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) pattern, priority); - curr->pattern = strdup (pattern); + curr->pattern = gf_strdup (pattern); if (curr->pattern == NULL) { max_pri = -1; goto out; @@ -1329,31 +1335,50 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) max_pri = max (max_pri, curr->priority); } - free (dup_str); + GF_FREE (dup_str); dup_str = NULL; stripe_str = strtok_r (NULL, ",", &tmp_str); } out: if (string != NULL) { - free (string); + GF_FREE (string); } if (dup_str != NULL) { - free (dup_str); + GF_FREE (dup_str); } if (max_pri == -1) { list_for_each_entry_safe (curr, tmp, first, list) { list_del_init (&curr->list); - free (curr->pattern); - free (curr); + GF_FREE (curr->pattern); + GF_FREE (curr); } } return max_pri; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_ioc_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + /* * init - * @this: @@ -1381,7 +1406,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - table = (void *) CALLOC (1, sizeof (*table)); + table = (void *) GF_CALLOC (1, sizeof (*table), gf_ioc_mt_ioc_table_t); if (table == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto out; @@ -1477,7 +1502,9 @@ init (xlator_t *this) goto out; } - table->inode_lru = CALLOC (table->max_pri, sizeof (struct list_head)); + table->inode_lru = GF_CALLOC (table->max_pri, + sizeof (struct list_head), + gf_ioc_mt_list_head); if (table->inode_lru == NULL) { goto out; } @@ -1495,8 +1522,8 @@ init (xlator_t *this) out: if (ret == -1) { if (table != NULL) { - free (table->inode_lru); - free (table); + GF_FREE (table->inode_lru); + GF_FREE (table); } } @@ -1518,7 +1545,7 @@ fini (xlator_t *this) return; pthread_mutex_destroy (&table->table_lock); - FREE (table); + GF_FREE (table); this->private = NULL; return; diff --git a/xlators/performance/io-cache/src/ioc-inode.c b/xlators/performance/io-cache/src/ioc-inode.c index 763f329d..56191348 100644 --- a/xlators/performance/io-cache/src/ioc-inode.c +++ b/xlators/performance/io-cache/src/ioc-inode.c @@ -23,6 +23,7 @@ #endif #include "io-cache.h" +#include "ioc-mem-types.h" extern int ioc_log2_page_size; @@ -51,7 +52,7 @@ ptr_to_str (void *ptr) { int ret = 0; char *str = NULL; - ret = asprintf (&str, "%p", ptr); + ret = gf_asprintf (&str, "%p", ptr); if (-1 == ret) { gf_log ("ioc", GF_LOG_ERROR, "asprintf failed while converting ptr to str"); @@ -137,7 +138,7 @@ ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, waiter = waiter->next; waited->data = NULL; - free (waited); + GF_FREE (waited); } } @@ -157,7 +158,8 @@ ioc_inode_update (ioc_table_t *table, inode_t *inode, uint32_t weight) ioc_inode_t *ioc_inode = NULL; unsigned long no_of_pages = 0; - ioc_inode = CALLOC (1, sizeof (ioc_inode_t)); + ioc_inode = GF_CALLOC (1, sizeof (ioc_inode_t), + gf_ioc_mt_ioc_inode_t); if (ioc_inode == NULL) { goto out; } @@ -213,5 +215,5 @@ ioc_inode_destroy (ioc_inode_t *ioc_inode) rbthash_table_destroy (ioc_inode->cache.page_table); pthread_mutex_destroy (&ioc_inode->inode_lock); - free (ioc_inode); + GF_FREE (ioc_inode); } diff --git a/xlators/performance/io-cache/src/ioc-mem-types.h b/xlators/performance/io-cache/src/ioc-mem-types.h new file mode 100644 index 00000000..d1da65ca --- /dev/null +++ b/xlators/performance/io-cache/src/ioc-mem-types.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2007-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __IOC_MT_H__ +#define __IOC_MT_H__ + +#include "mem-types.h" + +enum gf_ioc_mem_types_ { + gf_ioc_mt_iovec = gf_common_mt_end + 1, + gf_ioc_mt_ioc_table_t, + gf_ioc_mt_char, + gf_ioc_mt_ioc_local_t, + gf_ioc_mt_ioc_waitq_t, + gf_ioc_mt_ioc_priority, + gf_ioc_mt_list_head, + gf_ioc_mt_call_pool_t, + gf_ioc_mt_ioc_inode_t, + gf_ioc_mt_ioc_fill_t, + gf_ioc_mt_ioc_newpage_t, + gf_ioc_mt_end +}; +#endif + diff --git a/xlators/performance/io-cache/src/page.c b/xlators/performance/io-cache/src/page.c index 28be2b35..7209abb0 100644 --- a/xlators/performance/io-cache/src/page.c +++ b/xlators/performance/io-cache/src/page.c @@ -27,6 +27,7 @@ #include "dict.h" #include "xlator.h" #include "io-cache.h" +#include "ioc-mem-types.h" #include #include @@ -86,7 +87,7 @@ ioc_page_destroy (ioc_page_t *page) if (page->vector){ iobref_unref (page->iobref); - free (page->vector); + GF_FREE (page->vector); page->vector = NULL; } @@ -95,7 +96,7 @@ ioc_page_destroy (ioc_page_t *page) if (page_size != -1) { pthread_mutex_destroy (&page->page_lock); - free (page); + GF_FREE (page); } return page_size; @@ -194,7 +195,8 @@ ioc_page_create (ioc_inode_t *ioc_inode, off_t offset) table = ioc_inode->table; rounded_offset = floor (offset, table->page_size); - newpage = CALLOC (1, sizeof (*newpage)); + newpage = GF_CALLOC (1, sizeof (*newpage), + gf_ioc_mt_ioc_newpage_t); if (newpage == NULL) { goto out; } @@ -202,7 +204,7 @@ ioc_page_create (ioc_inode_t *ioc_inode, off_t offset) if (ioc_inode) { table = ioc_inode->table; } else { - free (newpage); + GF_FREE (newpage); newpage = NULL; goto out; } @@ -241,7 +243,7 @@ ioc_wait_on_page (ioc_page_t *page, call_frame_t *frame, off_t offset, ioc_waitq_t *waitq = NULL; ioc_local_t *local = frame->local; - waitq = CALLOC (1, sizeof (*waitq)); + waitq = GF_CALLOC (1, sizeof (*waitq), gf_ioc_mt_ioc_waitq_t); if (waitq == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -322,7 +324,7 @@ ioc_waitq_return (ioc_waitq_t *waitq) frame = trav->data; ioc_frame_return (frame); - free (trav); + GF_FREE (trav); } } @@ -394,7 +396,7 @@ ioc_fault_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } else { if (page->vector) { iobref_unref (page->iobref); - free (page->vector); + GF_FREE (page->vector); page->vector = NULL; } @@ -507,7 +509,8 @@ ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, goto err; } - fault_local = CALLOC (1, sizeof (ioc_local_t)); + fault_local = GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (fault_local == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -603,7 +606,8 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, copy_size, src_offset, dst_offset); { - new = CALLOC (1, sizeof (*new)); + new = GF_CALLOC (1, sizeof (*new), + gf_ioc_mt_ioc_fill_t); if (new == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -622,14 +626,15 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, src_offset + copy_size, NULL); - new->vector = CALLOC (new->count, - sizeof (struct iovec)); + new->vector = GF_CALLOC (new->count, + sizeof (struct iovec), + gf_ioc_mt_iovec); if (new->vector == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; iobref_unref (new->iobref); - FREE (new); + GF_FREE (new); ret = -1; gf_log (page->inode->table->xl->name, @@ -722,7 +727,7 @@ ioc_frame_unwind (call_frame_t *frame) count += fill->count; } - vector = CALLOC (count, sizeof (*vector)); + vector = GF_CALLOC (count, sizeof (*vector), gf_ioc_mt_iovec); if (vector == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -743,8 +748,8 @@ ioc_frame_unwind (call_frame_t *frame) list_del (&fill->list); iobref_unref (fill->iobref); - free (fill->vector); - free (fill); + GF_FREE (fill->vector); + GF_FREE (fill); } if (op_ret != -1) { @@ -764,12 +769,12 @@ ioc_frame_unwind (call_frame_t *frame) } if (vector != NULL) { - free (vector); + GF_FREE (vector); vector = NULL; } pthread_mutex_destroy (&local->local_lock); - free (local); + GF_FREE (local); return; } diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index 5ef71673..c2cca788 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -2111,6 +2111,24 @@ set_stack_size (iot_conf_t *conf) } } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_iot_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) @@ -2132,7 +2150,8 @@ init (xlator_t *this) "dangling volume. check volfile "); } - conf = (void *) CALLOC (1, sizeof (*conf)); + conf = (void *) GF_CALLOC (1, sizeof (*conf), + gf_iot_mt_iot_conf_t); if (conf == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -2169,7 +2188,7 @@ init (xlator_t *this) if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, "cannot initialize worker threads, exiting init"); - FREE (conf); + GF_FREE (conf); goto out; } @@ -2185,7 +2204,7 @@ fini (xlator_t *this) { iot_conf_t *conf = this->private; - FREE (conf); + GF_FREE (conf); this->private = NULL; return; diff --git a/xlators/performance/io-threads/src/io-threads.h b/xlators/performance/io-threads/src/io-threads.h index 85836ff5..13741803 100644 --- a/xlators/performance/io-threads/src/io-threads.h +++ b/xlators/performance/io-threads/src/io-threads.h @@ -35,6 +35,7 @@ #include "list.h" #include #include "locking.h" +#include "iot-mem-types.h" #include diff --git a/xlators/performance/io-threads/src/iot-mem-types.h b/xlators/performance/io-threads/src/iot-mem-types.h new file mode 100644 index 00000000..c083f83b --- /dev/null +++ b/xlators/performance/io-threads/src/iot-mem-types.h @@ -0,0 +1,31 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __IOT_MEM_TYPES_H__ +#define __IOT_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_iot_mem_types_ { + gf_iot_mt_iot_conf_t = gf_common_mt_end + 1, + gf_iot_mt_end +}; +#endif + diff --git a/xlators/performance/quick-read/src/quick-read-mem-types.h b/xlators/performance/quick-read/src/quick-read-mem-types.h new file mode 100644 index 00000000..1e7a5d56 --- /dev/null +++ b/xlators/performance/quick-read/src/quick-read-mem-types.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __QR_MEM_TYPES_H__ +#define __QR_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_qr_mem_types_ { + gf_qr_mt_qr_file_t = gf_common_mt_end + 1, + gf_qr_mt_qr_fd_ctx_t, + gf_qr_mt_qr_local_t, + gf_qr_mt_iovec, + gf_qr_mt_qr_conf_t, + gf_qr_mt_end +}; +#endif + diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 6cdb735a..15d4b637 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -33,7 +33,7 @@ qr_loc_wipe (loc_t *loc) } if (loc->path) { - FREE (loc->path); + GF_FREE ((char *)loc->path); loc->path = NULL; } @@ -65,10 +65,10 @@ qr_loc_fill (loc_t *loc, inode_t *inode, char *path) } loc->inode = inode_ref (inode); - loc->path = strdup (path); + loc->path = gf_strdup (path); loc->ino = inode->ino; - parent = strdup (path); + parent = gf_strdup (path); if (parent == NULL) { ret = -1; goto out; @@ -92,7 +92,7 @@ out: } if (parent) { - FREE (parent); + GF_FREE (parent); } return ret; @@ -139,8 +139,8 @@ qr_fd_ctx_free (qr_fd_ctx_t *qr_fd_ctx) assert (list_empty (&qr_fd_ctx->waiting_ops)); - FREE (qr_fd_ctx->path); - FREE (qr_fd_ctx); + GF_FREE (qr_fd_ctx->path); + GF_FREE (qr_fd_ctx); out: return; @@ -184,7 +184,8 @@ qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, { ret = __inode_ctx_get (inode, this, &value); if (ret == -1) { - qr_file = CALLOC (1, sizeof (*qr_file)); + qr_file = GF_CALLOC (1, sizeof (*qr_file), + gf_qr_mt_qr_file_t); if (qr_file == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -195,7 +196,7 @@ qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = __inode_ctx_put (inode, this, (uint64_t)(long)qr_file); if (ret == -1) { - FREE (qr_file); + GF_FREE (qr_file); qr_file = NULL; op_ret = -1; op_errno = EINVAL; @@ -430,7 +431,8 @@ qr_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, conf = this->private; - tmp_fd_ctx = qr_fd_ctx = CALLOC (1, sizeof (*qr_fd_ctx)); + tmp_fd_ctx = qr_fd_ctx = GF_CALLOC (1, sizeof (*qr_fd_ctx), + gf_qr_mt_qr_fd_ctx_t); if (qr_fd_ctx == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -441,7 +443,7 @@ qr_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, LOCK_INIT (&qr_fd_ctx->lock); INIT_LIST_HEAD (&qr_fd_ctx->waiting_ops); - qr_fd_ctx->path = strdup (loc->path); + qr_fd_ctx->path = gf_strdup (loc->path); qr_fd_ctx->flags = flags; qr_fd_ctx->wbflags = wbflags; @@ -453,7 +455,8 @@ qr_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, } tmp_fd_ctx = NULL; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_qr_mt_qr_local_t); if (local == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -515,7 +518,7 @@ unwind: } if (local != NULL) { - FREE (local); + GF_FREE (local); } STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); @@ -599,8 +602,8 @@ qr_validate_cache_cbk (call_frame_t *frame, void *cookie, xlator_t *this, frame->local = NULL; call_resume (local->stub); - - FREE (local); + + GF_FREE (local); return 0; unwind: @@ -657,7 +660,8 @@ qr_validate_cache (call_frame_t *frame, xlator_t *this, fd_t *fd, call_stub_t *validate_stub = NULL; char need_open = 0, can_wind = 0; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_qr_mt_qr_local_t); if (local == NULL) { goto out; } @@ -839,8 +843,9 @@ qr_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, goto unlock; } - vector = CALLOC (count, - sizeof (*vector)); + vector = GF_CALLOC (count, + sizeof (*vector), + gf_qr_mt_iovec); if (vector == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -977,7 +982,7 @@ out: } if (vector) { - FREE (vector); + GF_FREE (vector); } if (iobref) { @@ -1942,8 +1947,9 @@ qr_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) if (ret == 0) { qr_fd_ctx = (qr_fd_ctx_t *)(long)value; } - - local = CALLOC (1, sizeof (*local)); + + local = GF_CALLOC (1, sizeof (*local), + gf_qr_mt_qr_local_t); if (local == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -2152,7 +2158,7 @@ qr_forget (xlator_t *this, inode_t *inode) UNLOCK (&qr_file->lock); } - FREE (qr_file); + GF_FREE (qr_file); } return 0; @@ -2189,6 +2195,25 @@ qr_priv_dump (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_qr_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) { @@ -2208,7 +2233,8 @@ init (xlator_t *this) "dangling volume. check volfile "); } - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), + gf_qr_mt_qr_conf_t); if (conf == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -2249,7 +2275,7 @@ init (xlator_t *this) this->private = conf; out: if ((ret == -1) && conf) { - FREE (conf); + GF_FREE (conf); } return ret; diff --git a/xlators/performance/quick-read/src/quick-read.h b/xlators/performance/quick-read/src/quick-read.h index e6aebecc..7b832ff8 100644 --- a/xlators/performance/quick-read/src/quick-read.h +++ b/xlators/performance/quick-read/src/quick-read.h @@ -40,6 +40,7 @@ #include #include #include +#include "quick-read-mem-types.h" #define GLUSTERFS_CONTENT_KEY "glusterfs.content" diff --git a/xlators/performance/read-ahead/src/page.c b/xlators/performance/read-ahead/src/page.c index 063258c8..0e271a9a 100644 --- a/xlators/performance/read-ahead/src/page.c +++ b/xlators/performance/read-ahead/src/page.c @@ -62,7 +62,8 @@ ra_page_create (ra_file_t *file, off_t offset) page = page->next; if (page == &file->pages || page->offset != rounded_offset) { - newpage = CALLOC (1, sizeof (*newpage)); + newpage = GF_CALLOC (1, sizeof (*newpage), + gf_ra_mt_ra_page_t); if (!newpage) return NULL; @@ -87,7 +88,8 @@ ra_wait_on_page (ra_page_t *page, call_frame_t *frame) ra_local_t *local = NULL; local = frame->local; - waitq = CALLOC (1, sizeof (*waitq)); + waitq = GF_CALLOC (1, sizeof (*waitq), + gf_ra_mt_ra_waitq_t); if (!waitq) { gf_log (frame->this->name, GF_LOG_ERROR, "out of memory"); @@ -123,7 +125,7 @@ ra_waitq_return (ra_waitq_t *waitq) frame = trav->data; ra_frame_return (frame); - free (trav); + GF_FREE (trav); } } @@ -176,7 +178,7 @@ ra_fault_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (page->vector) { iobref_unref (page->iobref); - free (page->vector); + GF_FREE (page->vector); } page->vector = iov_dup (vector, count); @@ -200,7 +202,7 @@ unlock: fd_unref (local->fd); - free (frame->local); + GF_FREE (frame->local); frame->local = NULL; STACK_DESTROY (frame->root); @@ -225,7 +227,8 @@ ra_page_fault (ra_file_t *file, call_frame_t *frame, off_t offset) goto err; } - fault_local = CALLOC (1, sizeof (ra_local_t)); + fault_local = GF_CALLOC (1, sizeof (ra_local_t), + gf_ra_mt_ra_local_t); if (fault_local == NULL) { STACK_DESTROY (fault_frame->root); op_ret = -1; @@ -297,7 +300,8 @@ ra_frame_fill (ra_page_t *page, call_frame_t *frame) fill = fill->next; } - new = CALLOC (1, sizeof (*new)); + new = GF_CALLOC (1, sizeof (*new), + gf_ra_mt_ra_fill_t); if (new == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -310,11 +314,12 @@ ra_frame_fill (ra_page_t *page, call_frame_t *frame) new->count = iov_subset (page->vector, page->count, src_offset, src_offset+copy_size, NULL); - new->vector = CALLOC (new->count, sizeof (struct iovec)); + new->vector = GF_CALLOC (new->count, sizeof (struct iovec), + gf_ra_mt_iovec); if (new->vector == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; - FREE (new); + GF_FREE (new); goto out; } @@ -366,7 +371,8 @@ ra_frame_unwind (call_frame_t *frame) fill = fill->next; } - vector = CALLOC (count, sizeof (*vector)); + vector = GF_CALLOC (count, sizeof (*vector), + gf_ra_mt_iovec); if (vector == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -391,8 +397,8 @@ ra_frame_unwind (call_frame_t *frame) fill->prev->next = fill->prev; iobref_unref (fill->iobref); - free (fill->vector); - free (fill); + GF_FREE (fill->vector); + GF_FREE (fill); fill = next; } @@ -406,8 +412,8 @@ ra_frame_unwind (call_frame_t *frame) iobref_unref (iobref); pthread_mutex_destroy (&local->local_lock); - free (local); - free (vector); + GF_FREE (local); + GF_FREE (vector); return; } @@ -475,8 +481,8 @@ ra_page_purge (ra_page_t *page) if (page->iobref) { iobref_unref (page->iobref); } - free (page->vector); - free (page); + GF_FREE (page->vector); + GF_FREE (page); } /* @@ -541,5 +547,5 @@ ra_file_destroy (ra_file_t *file) } pthread_mutex_destroy (&file->file_lock); - free (file); + GF_FREE (file); } diff --git a/xlators/performance/read-ahead/src/read-ahead-mem-types.h b/xlators/performance/read-ahead/src/read-ahead-mem-types.h new file mode 100644 index 00000000..b21d0595 --- /dev/null +++ b/xlators/performance/read-ahead/src/read-ahead-mem-types.h @@ -0,0 +1,37 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __RA_MEM_TYPES_H__ +#define __RA_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_ra_mem_types_ { + gf_ra_mt_ra_file_t = gf_common_mt_end + 1, + gf_ra_mt_ra_local_t, + gf_ra_mt_ra_conf_t, + gf_ra_mt_ra_page_t, + gf_ra_mt_ra_waitq_t, + gf_ra_mt_ra_fill_t, + gf_ra_mt_iovec, + gf_ra_mt_end +}; +#endif + diff --git a/xlators/performance/read-ahead/src/read-ahead.c b/xlators/performance/read-ahead/src/read-ahead.c index c0a43258..9f97c72e 100644 --- a/xlators/performance/read-ahead/src/read-ahead.c +++ b/xlators/performance/read-ahead/src/read-ahead.c @@ -59,7 +59,7 @@ ra_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, wbflags = (long)frame->local; - file = CALLOC (1, sizeof (*file)); + file = GF_CALLOC (1, sizeof (*file), gf_ra_mt_ra_file_t); if (!file) { op_ret = -1; op_errno = ENOMEM; @@ -129,7 +129,7 @@ ra_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto unwind; } - file = CALLOC (1, sizeof (*file)); + file = GF_CALLOC (1, sizeof (*file), gf_ra_mt_ra_file_t); if (!file) { op_ret = -1; op_errno = ENOMEM; @@ -480,7 +480,8 @@ ra_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, return 0; } - local = (void *) CALLOC (1, sizeof (*local)); + local = (void *) GF_CALLOC (1, sizeof (*local), + gf_ra_mt_ra_local_t); if (!local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -823,6 +824,25 @@ ra_priv_dump (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_ra_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) { @@ -843,7 +863,8 @@ init (xlator_t *this) "dangling volume. check volfile "); } - conf = (void *) CALLOC (1, sizeof (*conf)); + conf = (void *) GF_CALLOC (1, sizeof (*conf), + gf_ra_mt_ra_conf_t); if (conf == NULL) { gf_log (this->name, GF_LOG_ERROR, "FATAL: Out of memory"); @@ -897,7 +918,7 @@ init (xlator_t *this) out: if (ret == -1) { if (conf != NULL) { - FREE (conf); + GF_FREE (conf); } } @@ -913,7 +934,7 @@ fini (xlator_t *this) return; pthread_mutex_destroy (&conf->conf_lock); - FREE (conf); + GF_FREE (conf); this->private = NULL; return; diff --git a/xlators/performance/read-ahead/src/read-ahead.h b/xlators/performance/read-ahead/src/read-ahead.h index 0ad47fc7..1f56e85d 100644 --- a/xlators/performance/read-ahead/src/read-ahead.h +++ b/xlators/performance/read-ahead/src/read-ahead.h @@ -31,6 +31,7 @@ #include "dict.h" #include "xlator.h" #include "common-utils.h" +#include "read-ahead-mem-types.h" struct ra_conf; struct ra_local; diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch-mem-types.h b/xlators/performance/stat-prefetch/src/stat-prefetch-mem-types.h new file mode 100644 index 00000000..f3d25a8a --- /dev/null +++ b/xlators/performance/stat-prefetch/src/stat-prefetch-mem-types.h @@ -0,0 +1,36 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __SP_MEM_TYPES_H__ +#define __SP_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_sp_mem_types_ { + gf_sp_mt_sp_cache_t = gf_common_mt_end + 1, + gf_sp_mt_sp_fd_ctx_t, + gf_sp_mt_stat, + gf_sp_mt_sp_local_t, + gf_sp_mt_sp_inode_ctx_t, + gf_sp_mt_sp_private_t, + gf_sp_mt_end +}; +#endif + diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c index c5404213..e7dd8958 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.c +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c @@ -59,7 +59,7 @@ sp_inode_ctx_free (xlator_t *this, sp_inode_ctx_t *ctx) UNLOCK (&ctx->lock); LOCK_DESTROY (&ctx->lock); - FREE (ctx); + GF_FREE (ctx); out: return; @@ -71,7 +71,8 @@ sp_inode_ctx_init () { sp_inode_ctx_t *inode_ctx = NULL; - inode_ctx = CALLOC (1, sizeof (*inode_ctx)); + inode_ctx = GF_CALLOC (1, sizeof (*inode_ctx), + gf_sp_mt_sp_inode_ctx_t); if (inode_ctx == NULL) { goto out; } @@ -224,7 +225,7 @@ sp_cache_unref (sp_cache_t *cache) if (refcount == 0) { rbthash_table_destroy (cache->table); - FREE (cache); + GF_FREE (cache); } out: @@ -272,7 +273,8 @@ sp_process_inode_ctx (call_frame_t *frame, xlator_t *this, loc_t *loc, { if (!(inode_ctx->looked_up || inode_ctx->lookup_in_progress)) { if (frame->local == NULL) { - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unlock, @@ -340,14 +342,14 @@ sp_cache_init (xlator_t *this) if (!priv->mem_pool) goto out; - cache = CALLOC (1, sizeof (*cache)); + cache = GF_CALLOC (1, sizeof (*cache), gf_sp_mt_sp_cache_t); if (cache) { cache->table = rbthash_table_init (GF_SP_CACHE_BUCKETS, sp_hashfn, free, 0, priv->mem_pool); if (cache->table == NULL) { - FREE (cache); + GF_FREE (cache); cache = NULL; goto out; } @@ -366,7 +368,7 @@ sp_local_free (sp_local_t *local) { if (local) { loc_wipe (&local->loc); - FREE (local); + GF_FREE (local); } } @@ -400,7 +402,7 @@ sp_cache_remove_entry (sp_cache_t *cache, char *name, char remove_all) table = cache->table; cache->table = rbthash_table_init (GF_SP_CACHE_BUCKETS, sp_hashfn, - free, + __gf_free, 0, priv->mem_pool); if (cache->table == NULL) { @@ -412,7 +414,7 @@ sp_cache_remove_entry (sp_cache_t *cache, char *name, char remove_all) } else { data = rbthash_remove (cache->table, name, strlen (name)); - FREE (data); + GF_FREE (data); ret = 0; } } @@ -526,7 +528,7 @@ sp_fd_ctx_free (sp_fd_ctx_t *fd_ctx) } if (fd_ctx->name) { - FREE (fd_ctx->name); + GF_FREE (fd_ctx->name); fd_ctx->name = NULL; } @@ -534,7 +536,7 @@ sp_fd_ctx_free (sp_fd_ctx_t *fd_ctx) sp_cache_free (fd_ctx->cache); } - FREE (fd_ctx); + GF_FREE (fd_ctx); out: return; } @@ -545,7 +547,7 @@ sp_fd_ctx_init (void) { sp_fd_ctx_t *fd_ctx = NULL; - fd_ctx = CALLOC (1, sizeof (*fd_ctx)); + fd_ctx = GF_CALLOC (1, sizeof (*fd_ctx), gf_sp_mt_sp_fd_ctx_t); return fd_ctx; } @@ -567,7 +569,7 @@ sp_fd_ctx_new (xlator_t *this, inode_t *parent, char *name, sp_cache_t *cache) } if (name) { - fd_ctx->name = strdup (name); + fd_ctx->name = gf_strdup (name); if (fd_ctx->name == NULL) { sp_fd_ctx_free (fd_ctx); fd_ctx = NULL; @@ -713,7 +715,7 @@ sp_cache_add_entries (sp_cache_t *cache, gf_dirent_t *entries) ret = rbthash_insert (cache->table, new, new->d_name, strlen (new->d_name)); if (ret == -1) { - FREE (new); + GF_FREE (new); continue; } @@ -807,7 +809,7 @@ sp_get_ancestors (char *path, char **parent, char **grand_parent) break; } - cpy = strdup (path); + cpy = gf_strdup (path); if (cpy == NULL) { goto out; } @@ -851,13 +853,13 @@ sp_cache_remove_parent_entry (call_frame_t *frame, xlator_t *this, cache_gp = sp_get_cache_inode (this, inode_gp, frame->root->pid); if (cache_gp) { - cpy = strdup (parent); + cpy = gf_strdup (parent); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, cpy, out, errno, ENOMEM); path = basename (cpy); sp_cache_remove_entry (cache_gp, path, 0); - FREE (cpy); + GF_FREE (cpy); sp_cache_unref (cache_gp); } @@ -868,11 +870,11 @@ sp_cache_remove_parent_entry (call_frame_t *frame, xlator_t *this, ret = 0; out: if (parent) { - FREE (parent); + GF_FREE (parent); } if (grand_parent) { - FREE (grand_parent); + GF_FREE (grand_parent); } return ret; @@ -1015,7 +1017,7 @@ sp_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req) entry_cached = 1; } - FREE (dirent); + GF_FREE (dirent); } } else if (IA_ISDIR (loc->inode->ia_type)) { cache = sp_get_cache_inode (this, loc->inode, frame->root->pid); @@ -1032,7 +1034,7 @@ sp_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req) entry_cached = 1; } - FREE (dirent); + GF_FREE (dirent); } } } @@ -1054,7 +1056,7 @@ wind: GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, stub, unwind, op_errno, ENOMEM); - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unwind, op_errno, ENOMEM); @@ -1204,14 +1206,14 @@ sp_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, ret = sp_cache_remove_parent_entry (frame, this, fd->inode->table, path); - FREE (path); + GF_FREE (path); if (ret < 0) { errno = -ret; goto unwind; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); if (local) { local->fd = fd; frame->local = local; @@ -1341,7 +1343,7 @@ sp_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, loc->inode, out, op_errno, EINVAL); - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -1453,7 +1455,7 @@ sp_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, goto out; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -1541,7 +1543,7 @@ sp_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, loc->inode, out, op_errno, EINVAL); - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -1643,7 +1645,7 @@ sp_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) goto out; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -1706,7 +1708,7 @@ sp_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, goto out; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -1769,7 +1771,7 @@ sp_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, goto out; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_sp_mt_sp_local_t); GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno, ENOMEM); @@ -3687,7 +3689,7 @@ sp_forget (xlator_t *this, inode_t *inode) if (value) { buf = (void *)(long)value; - FREE (buf); + GF_FREE (buf); } return 0; @@ -3717,7 +3719,24 @@ sp_release (xlator_t *this, fd_t *fd) return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_sp_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) @@ -3733,7 +3752,8 @@ init (xlator_t *this) goto out; } - priv = CALLOC (1, sizeof(sp_private_t)); + priv = GF_CALLOC (1, sizeof(sp_private_t), + gf_sp_mt_sp_private_t); LOCK_INIT (&priv->lock); this->private = priv; diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.h b/xlators/performance/stat-prefetch/src/stat-prefetch.h index 9ff2899a..16edf76a 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.h +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.h @@ -33,6 +33,7 @@ #include "rbthash.h" #include "hashfn.h" #include "call-stub.h" +#include "stat-prefetch-mem-types.h" #include struct sp_cache { diff --git a/xlators/performance/write-behind/src/write-behind-mem-types.h b/xlators/performance/write-behind/src/write-behind-mem-types.h new file mode 100644 index 00000000..61846151 --- /dev/null +++ b/xlators/performance/write-behind/src/write-behind-mem-types.h @@ -0,0 +1,35 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __WB_MEM_TYPES_H__ +#define __WB_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_wb_mem_types_ { + gf_wb_mt_wb_file_t = gf_common_mt_end + 1, + gf_wb_mt_wb_local_t, + gf_wb_mt_wb_request_t, + gf_wb_mt_iovec, + gf_wb_mt_wb_conf_t, + gf_wb_mt_end +}; +#endif + diff --git a/xlators/performance/write-behind/src/write-behind.c b/xlators/performance/write-behind/src/write-behind.c index 3cbfc497..bd046500 100644 --- a/xlators/performance/write-behind/src/write-behind.c +++ b/xlators/performance/write-behind/src/write-behind.c @@ -35,6 +35,7 @@ #include "common-utils.h" #include "call-stub.h" #include "statedump.h" +#include "write-behind-mem-types.h" #define MAX_VECTOR_COUNT 8 #define WB_AGGREGATE_SIZE 131072 /* 128 KB */ @@ -141,7 +142,7 @@ __wb_request_unref (wb_request_t *this) call_stub_destroy (this->stub); } - FREE (this); + GF_FREE (this); } } @@ -209,7 +210,7 @@ wb_enqueue (wb_file_t *file, call_stub_t *stub) struct iovec *vector = NULL; int32_t count = 0; - request = CALLOC (1, sizeof (*request)); + request = GF_CALLOC (1, sizeof (*request), gf_wb_mt_wb_request_t); if (request == NULL) { goto out; } @@ -270,7 +271,7 @@ wb_file_create (xlator_t *this, fd_t *fd) wb_file_t *file = NULL; wb_conf_t *conf = this->private; - file = CALLOC (1, sizeof (*file)); + file = GF_CALLOC (1, sizeof (*file), gf_wb_mt_wb_file_t); if (file == NULL) { goto out; } @@ -307,7 +308,7 @@ wb_file_destroy (wb_file_t *file) if (!refcount){ LOCK_DESTROY (&file->lock); - FREE (file); + GF_FREE (file); } return; @@ -407,7 +408,8 @@ wb_sync (call_frame_t *frame, wb_file_t *file, list_head_t *winds) list_for_each_entry_safe (request, dummy, winds, winds) { if (!vector) { - vector = MALLOC (VECTORSIZE (MAX_VECTOR_COUNT)); + vector = GF_MALLOC (VECTORSIZE (MAX_VECTOR_COUNT), + gf_wb_mt_iovec); if (vector == NULL) { bytes = -1; goto out; @@ -419,7 +421,8 @@ wb_sync (call_frame_t *frame, wb_file_t *file, list_head_t *winds) goto out; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { bytes = -1; goto out; @@ -488,7 +491,7 @@ wb_sync (call_frame_t *frame, wb_file_t *file, list_head_t *winds) iobref); iobref_unref (iobref); - FREE (vector); + GF_FREE (vector); first_request = NULL; iobref = NULL; vector = NULL; @@ -505,7 +508,7 @@ out: } if (local != NULL) { - FREE (local); + GF_FREE (local); } if (iobref != NULL) { @@ -513,7 +516,7 @@ out: } if (vector != NULL) { - FREE (vector); + GF_FREE (vector); } return bytes; @@ -612,7 +615,8 @@ wb_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) } } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { op_errno = ENOMEM; goto unwind; @@ -726,7 +730,8 @@ wb_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) } file = (wb_file_t *)(long)tmp_file; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { STACK_UNWIND_STRICT (fstat, frame, -1, ENOMEM, NULL); return 0; @@ -877,7 +882,8 @@ wb_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) } } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { op_errno = ENOMEM; goto unwind; @@ -994,7 +1000,8 @@ wb_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) file = (wb_file_t *)(long)tmp_file; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOMEM, NULL, NULL); @@ -1131,7 +1138,8 @@ wb_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, wb_request_t *request = NULL; int32_t ret = -1, op_errno = EINVAL; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { op_errno = ENOMEM; goto unwind; @@ -1263,7 +1271,8 @@ wb_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, wb_local_t *local = NULL; int32_t op_errno = EINVAL; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { op_errno = ENOMEM; goto unwind; @@ -1894,7 +1903,8 @@ wb_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, goto unwind; } - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { op_errno = ENOMEM; goto unwind; @@ -2010,7 +2020,8 @@ wb_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, file = (wb_file_t *)(long)tmp_file; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { STACK_UNWIND_STRICT (readv, frame, -1, ENOMEM, NULL, 0, NULL, NULL); @@ -2165,7 +2176,8 @@ wb_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) file = (wb_file_t *)(long)tmp_file; if (file != NULL) { - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { STACK_UNWIND (frame, -1, ENOMEM, NULL); return 0; @@ -2196,7 +2208,8 @@ wb_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) if (conf->flush_behind && (!disabled) && (disable_till == 0)) { - tmp_local = CALLOC (1, sizeof (*local)); + tmp_local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (tmp_local == NULL) { STACK_UNWIND_STRICT (flush, frame, -1, ENOMEM); @@ -2337,7 +2350,8 @@ wb_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync) file = (wb_file_t *)(long)tmp_file; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_wb_mt_wb_local_t); if (local == NULL) { STACK_UNWIND_STRICT (fsync, frame, -1, ENOMEM, NULL, NULL); return 0; @@ -2444,6 +2458,25 @@ wb_priv_dump (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_wb_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) { @@ -2468,7 +2501,7 @@ init (xlator_t *this) options = this->options; - conf = CALLOC (1, sizeof (*conf)); + conf = GF_CALLOC (1, sizeof (*conf), gf_wb_mt_wb_conf_t); if (conf == NULL) { gf_log (this->name, GF_LOG_ERROR, "FATAL: Out of memory"); @@ -2521,7 +2554,7 @@ init (xlator_t *this) "invalid number format \"%s\" of \"option " "window-size\"", str); - FREE (conf); + GF_FREE (conf); return -1; } } @@ -2539,7 +2572,7 @@ init (xlator_t *this) "aggregate-size(%"PRIu64") cannot be more than " "window-size" "(%"PRIu64")", conf->aggregate_size, conf->window_size); - FREE (conf); + GF_FREE (conf); return -1; } @@ -2586,7 +2619,7 @@ fini (xlator_t *this) { wb_conf_t *conf = this->private; - FREE (conf); + GF_FREE (conf); return; } diff --git a/xlators/protocol/client/src/client-mem-types.h b/xlators/protocol/client/src/client-mem-types.h new file mode 100644 index 00000000..1eee8d93 --- /dev/null +++ b/xlators/protocol/client/src/client-mem-types.h @@ -0,0 +1,43 @@ + +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __CLIENT_MEM_TYPES_H__ +#define __CLIENT_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_client_mem_types_ { + gf_client_mt_dir_entry_t = gf_common_mt_end + 1, + gf_client_mt_volfile_ctx, + gf_client_mt_client_state_t, + gf_client_mt_client_conf_t, + gf_client_mt_locker, + gf_client_mt_lock_table, + gf_client_mt_char, + gf_client_mt_client_connection_t, + gf_client_mt_client_fd_ctx_t, + gf_client_mt_client_local_t, + gf_client_mt_saved_frames, + gf_client_mt_saved_frame, + gf_client_mt_end +}; +#endif + diff --git a/xlators/protocol/client/src/client-protocol.c b/xlators/protocol/client/src/client-protocol.c index 36a31c5c..df890cc3 100644 --- a/xlators/protocol/client/src/client-protocol.c +++ b/xlators/protocol/client/src/client-protocol.c @@ -37,6 +37,7 @@ #include "compat.h" #include "compat-errno.h" #include "statedump.h" +#include "client-mem-types.h" #include #include @@ -169,7 +170,7 @@ client_local_wipe (client_local_t *local) if (local->fd) fd_unref (local->fd); - free (local); + GF_FREE (local); } return 0; @@ -234,7 +235,7 @@ call_bail (void *data) /* Chaining to get call-always functionality from call-once timer */ if (conn->timer) { - timer_cbk = conn->timer->cbk; + timer_cbk = conn->timer->callbk; timeout.tv_sec = 10; timeout.tv_usec = 0; @@ -320,7 +321,7 @@ call_bail (void *data) gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); list_del_init (&trav->list); - FREE (trav); + GF_FREE (trav); } out: return; @@ -507,7 +508,7 @@ client_start_ping (void *data) return; err: if (hdr) - FREE (hdr); + GF_FREE (hdr); if (dummy_frame) STACK_DESTROY (dummy_frame->root); @@ -661,7 +662,7 @@ protocol_client_xfer (call_frame_t *frame, xlator_t *this, transport_t *trans, gf_cbks[op] (frame, &rsphdr, sizeof (rsphdr), NULL); } - FREE (hdr); + GF_FREE (hdr); } return ret; @@ -695,7 +696,7 @@ client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); local->fd = fd_ref (fd); @@ -735,7 +736,7 @@ client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, fd, NULL, NULL); return 0; @@ -765,7 +766,7 @@ client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, uint64_t gen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); local->fd = fd_ref (fd); @@ -805,7 +806,7 @@ client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, fd); return 0; @@ -860,7 +861,7 @@ client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -916,7 +917,7 @@ client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -947,7 +948,7 @@ client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, uint64_t gen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, loc); @@ -985,7 +986,7 @@ client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); return 0; @@ -1014,7 +1015,7 @@ client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) uint64_t gen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, loc); @@ -1051,7 +1052,7 @@ client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); return 0; @@ -1107,7 +1108,7 @@ client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -1163,7 +1164,7 @@ client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -1195,7 +1196,7 @@ client_symlink (call_frame_t *frame, xlator_t *this, const char *linkname, uint64_t gen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, loc); @@ -1232,7 +1233,7 @@ client_symlink (call_frame_t *frame, xlator_t *this, const char *linkname, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); return 0; @@ -1312,7 +1313,7 @@ client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -1344,7 +1345,7 @@ client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) uint64_t newgen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, oldloc); @@ -1395,7 +1396,7 @@ client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, oldloc->inode, NULL); return 0; } @@ -1450,7 +1451,7 @@ client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -1523,7 +1524,7 @@ client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, return 0; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL, 0, NULL); return 0; @@ -1596,7 +1597,7 @@ client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -1653,7 +1654,7 @@ client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -1721,7 +1722,7 @@ client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) return 0; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -1790,7 +1791,7 @@ client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -1844,7 +1845,7 @@ client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, req->dict_len = hton32 (dict_len); if (dict) { memcpy (req->dict, buf, dict_len); - FREE (buf); + GF_FREE (buf); } req->ino = hton64 (ino); @@ -1858,7 +1859,7 @@ client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -1942,7 +1943,7 @@ client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EBADFD, NULL); return 0; @@ -2019,7 +2020,7 @@ client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -2110,7 +2111,7 @@ client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -2170,7 +2171,7 @@ client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -2249,7 +2250,7 @@ client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -2308,7 +2309,7 @@ client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; } @@ -2335,7 +2336,7 @@ client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t pathlen = 0; client_local_t *local = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, loc); @@ -2371,7 +2372,7 @@ client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, fd); return 0; @@ -2437,7 +2438,7 @@ client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, return 0; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EBADFD, NULL); return 0; @@ -2505,7 +2506,7 @@ client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, return 0; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EBADFD, NULL); return 0; @@ -2624,7 +2625,7 @@ client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -2693,7 +2694,7 @@ client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -2759,7 +2760,7 @@ client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -2857,7 +2858,7 @@ client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -2949,7 +2950,7 @@ client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -3056,7 +3057,7 @@ client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -3118,7 +3119,7 @@ client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -3196,7 +3197,7 @@ client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL); return 0; @@ -3230,7 +3231,7 @@ client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, client_local_t *local = NULL; char *buf = NULL; - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); GF_VALIDATE_OR_GOTO (this->name, local, unwind); loc_copy (&local->loc, loc); @@ -3281,7 +3282,7 @@ client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, if (dictlen > 0) { memcpy (req->dict + pathlen + baselen, buf, dictlen); - FREE (buf); + GF_FREE (buf); } req->dictlen = hton32 (dictlen); @@ -3451,7 +3452,7 @@ client_fdctx_destroy (xlator_t *this, client_fd_ctx_t *fdctx) out: inode_unref (fdctx->inode); - FREE (fdctx); + GF_FREE (fdctx); return ret; } @@ -3598,7 +3599,7 @@ fail: STACK_UNWIND (frame, op_ret, op_errno, dict); if (dictbuf) - free (dictbuf); + GF_FREE (dictbuf); if (dict) dict_unref (dict); @@ -3657,7 +3658,7 @@ fail: STACK_UNWIND (frame, op_ret, op_errno, dict); if (dictbuf) - free (dictbuf); + GF_FREE (dictbuf); if (dict) dict_unref (dict); @@ -3724,7 +3725,8 @@ client_create_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, local->loc.path); } - fdctx = CALLOC (1, sizeof (*fdctx)); + fdctx = GF_CALLOC (1, sizeof (*fdctx), + gf_client_mt_client_fd_ctx_t); if (!fdctx) { op_ret = -1; op_errno = ENOMEM; @@ -3801,7 +3803,8 @@ client_open_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, } if (op_ret >= 0) { - fdctx = CALLOC (1, sizeof (*fdctx)); + fdctx = GF_CALLOC (1, sizeof (*fdctx), + gf_client_mt_client_fd_ctx_t); if (!fdctx) { op_ret = -1; op_errno = ENOMEM; @@ -4521,7 +4524,8 @@ client_opendir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, } if (op_ret >= 0) { - fdctx = CALLOC (1, sizeof (*fdctx)); + fdctx = GF_CALLOC (1, sizeof (*fdctx), + gf_client_mt_client_fd_ctx_t); if (!fdctx) { op_ret = -1; op_errno = ENOMEM; @@ -4719,7 +4723,7 @@ fail: client_local_wipe (local); if (dictbuf) - free (dictbuf); + GF_FREE (dictbuf); if (xattr) dict_unref (xattr); @@ -4790,13 +4794,13 @@ gf_free_direntry (dir_entry_t *head) trav = head->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 (head); + GF_FREE (head); fail: return 0; } @@ -4945,7 +4949,7 @@ fail: client_local_wipe (local); if (dictbuf) - free (dictbuf); + GF_FREE (dictbuf); if (dict) dict_unref (dict); @@ -5133,7 +5137,7 @@ client_getspec (call_frame_t *frame, xlator_t *this, const char *key, return ret; unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; } @@ -5203,7 +5207,7 @@ client_log (call_frame_t *frame, xlator_t *this, const char *msg) unwind: if (hdr) - free (hdr); + GF_FREE (hdr); STACK_UNWIND (frame, -1, EINVAL, NULL); return 0; @@ -5477,7 +5481,7 @@ protocol_client_reopendir (xlator_t *this, client_fd_ctx_t *fdctx) goto out; } - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); if (!local) { goto out; } @@ -5523,7 +5527,7 @@ out: client_local_wipe (local); if (path) - FREE (path); + GF_FREE (path); return 0; } @@ -5600,7 +5604,7 @@ protocol_client_reopen (xlator_t *this, client_fd_ctx_t *fdctx) goto out; } - local = calloc (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); if (!local) { goto out; } @@ -5647,7 +5651,7 @@ out: client_local_wipe (local); if (path) - FREE (path); + GF_FREE (path); return 0; @@ -6120,6 +6124,26 @@ protocol_client_interpret (xlator_t *this, transport_t *trans, return ret; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_client_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + + /* * init - initiliazation function. called during loading of client protocol * @this: @@ -6179,7 +6203,8 @@ init (xlator_t *this) ping_timeout = GF_UNIVERSAL_ANSWER; } - conf = CALLOC (1, sizeof (client_conf_t)); + conf = GF_CALLOC (1, sizeof (client_conf_t), + gf_client_mt_client_conf_t); pthread_mutex_init (&conf->mutex, NULL); INIT_LIST_HEAD (&conf->saved_fds); @@ -6189,7 +6214,7 @@ init (xlator_t *this) for (i = 0; i < CHANNEL_MAX; i++) { if (CHANNEL_LOWLAT == i) { dict_set (this->options, "transport.socket.lowlat", - data_from_dynstr (strdup ("true"))); + data_from_dynstr (gf_strdup ("true"))); } trans = transport_load (this->options, this); if (trans == NULL) { @@ -6199,7 +6224,8 @@ init (xlator_t *this) goto out; } - conn = CALLOC (1, sizeof (*conn)); + conn = GF_CALLOC (1, sizeof (*conn), + gf_client_mt_client_connection_t); conn->saved_frames = saved_frames_new (); @@ -6262,7 +6288,7 @@ fini (xlator_t *this) this->private = NULL; if (conf) { - FREE (conf); + GF_FREE (conf); } return; } @@ -6288,8 +6314,8 @@ protocol_client_handshake (xlator_t *this, transport_t *trans) GF_PROTOCOL_VERSION); } - ret = asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, - this->name); + ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, + this->name); if (-1 == ret) { gf_log (this->name, GF_LOG_ERROR, "asprintf failed while setting process_uuid"); @@ -6345,7 +6371,7 @@ protocol_client_handshake (xlator_t *this, transport_t *trans) return ret; fail: if (hdr) - free (hdr); + GF_FREE (hdr); return ret; } @@ -6393,7 +6419,7 @@ protocol_client_pollin (xlator_t *this, transport_t *trans) } /* TODO: use mem-pool */ - FREE (hdr); + GF_FREE (hdr); return ret; } diff --git a/xlators/protocol/client/src/saved-frames.c b/xlators/protocol/client/src/saved-frames.c index cd5349e2..770de19a 100644 --- a/xlators/protocol/client/src/saved-frames.c +++ b/xlators/protocol/client/src/saved-frames.c @@ -22,6 +22,7 @@ #include "common-utils.h" #include "protocol.h" #include "xlator.h" +#include "client-mem-types.h" @@ -30,7 +31,8 @@ saved_frames_new (void) { struct saved_frames *saved_frames = NULL; - saved_frames = CALLOC (sizeof (*saved_frames), 1); + saved_frames = GF_CALLOC (sizeof (*saved_frames), 1, + gf_client_mt_saved_frames); if (!saved_frames) { return NULL; } @@ -76,7 +78,8 @@ saved_frames_put (struct saved_frames *frames, call_frame_t *frame, head_frame = get_head_frame_for_type (frames, type); - saved_frame = CALLOC (sizeof (*saved_frame), 1); + saved_frame = GF_CALLOC (sizeof (*saved_frame), 1, + gf_client_mt_saved_frame); if (!saved_frame) { return -ENOMEM; } @@ -119,7 +122,7 @@ saved_frames_get (struct saved_frames *frames, int32_t op, if (saved_frame) frame = saved_frame->frame; - FREE (saved_frame); + GF_FREE (saved_frame); return frame; } @@ -174,7 +177,7 @@ saved_frames_unwind (xlator_t *this, struct saved_frames *saved_frames, gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); list_del_init (&trav->list); - FREE (trav); + GF_FREE (trav); } } @@ -187,5 +190,5 @@ saved_frames_destroy (xlator_t *this, struct saved_frames *frames, saved_frames_unwind (this, frames, &frames->mops, gf_mops, gf_mop_list); saved_frames_unwind (this, frames, &frames->cbks, gf_cbks, gf_cbk_list); - FREE (frames); + GF_FREE (frames); } diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index dc2620c9..d07e841f 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -101,7 +101,7 @@ server_loc_fill (loc_t *loc, server_state_t *state, if (loc->name) loc->name++; } else { - loc->path = strdup (path); + loc->path = gf_strdup (path); loc->name = strrchr (loc->path, '/'); if (loc->name) loc->name++; @@ -142,7 +142,7 @@ stat_to_str (struct iatt *stbuf) uint32_t ctime_nsec = stbuf->ia_ctime_nsec; - ret = asprintf (&tmp_buf, + ret = gf_asprintf (&tmp_buf, GF_STAT_PRINT_FMT_STR, dev, ino, @@ -182,8 +182,8 @@ server_loc_wipe (loc_t *loc) loc->inode = NULL; } - if (loc->path) - FREE (loc->path); + if (loc->path) + GF_FREE ((char *)loc->path); } @@ -194,13 +194,13 @@ server_resolve_wipe (server_resolve_t *resolve) int i = 0; if (resolve->path) - FREE (resolve->path); + GF_FREE (resolve->path); if (resolve->bname) - FREE (resolve->bname); + GF_FREE (resolve->bname); if (resolve->resolved) - FREE (resolve->resolved); + GF_FREE (resolve->resolved); loc_wipe (&resolve->deep_loc); @@ -210,7 +210,7 @@ server_resolve_wipe (server_resolve_t *resolve) if (comp[i].inode) inode_unref (comp[i].inode); } - FREE (resolve->components); + GF_FREE (resolve->components); } } @@ -244,10 +244,10 @@ free_state (server_state_t *state) } if (state->volume) - FREE (state->volume); + GF_FREE ((char *)state->volume); if (state->name) - FREE (state->name); + GF_FREE (state->name); server_loc_wipe (&state->loc); server_loc_wipe (&state->loc2); @@ -255,7 +255,7 @@ free_state (server_state_t *state) server_resolve_wipe (&state->resolve); server_resolve_wipe (&state->resolve2); - FREE (state); + GF_FREE (state); } @@ -269,7 +269,8 @@ server_copy_frame (call_frame_t *frame) new_frame = copy_frame (frame); - new_state = CALLOC (1, sizeof (server_state_t)); + new_state = GF_CALLOC (1, sizeof (server_state_t), + gf_server_mt_server_state_t); new_frame->root->op = frame->root->op; new_frame->root->type = frame->root->type; @@ -295,7 +296,8 @@ gf_add_locker (struct _lock_table *table, const char *volume, struct _locker *new = NULL; uint8_t dir = 0; - new = CALLOC (1, sizeof (struct _locker)); + new = GF_CALLOC (1, sizeof (struct _locker), + gf_server_mt_locker); if (new == NULL) { gf_log ("server", GF_LOG_ERROR, "failed to allocate memory for \'struct _locker\'"); @@ -303,7 +305,7 @@ gf_add_locker (struct _lock_table *table, const char *volume, } INIT_LIST_HEAD (&new->lockers); - new->volume = strdup (volume); + new->volume = gf_strdup (volume); if (fd == NULL) { loc_copy (&new->loc, loc); @@ -381,9 +383,9 @@ gf_del_locker (struct _lock_table *table, const char *volume, else loc_wipe (&locker->loc); - free (locker->volume); - free (locker); - } + GF_FREE (locker->volume); + GF_FREE (locker); + } return ret; } @@ -419,7 +421,7 @@ gf_direntry_to_bin (dir_entry_t *head, char *buffer) trav->name, tmp_buf, trav->link); - FREE (tmp_buf); + GF_FREE (tmp_buf); trav = trav->next; ptr += this_len; } @@ -435,7 +437,8 @@ gf_lock_table_new (void) { struct _lock_table *new = NULL; - new = CALLOC (1, sizeof (struct _lock_table)); + new = GF_CALLOC (1, sizeof (struct _lock_table), + gf_server_mt_lock_table); if (new == NULL) { gf_log ("server-protocol", GF_LOG_CRITICAL, "failed to allocate memory for new lock table"); @@ -473,7 +476,7 @@ do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, } UNLOCK (<able->lock); - free (ltable); + GF_FREE (ltable); flock.l_type = F_UNLCK; flock.l_start = 0; @@ -509,10 +512,10 @@ do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, loc_wipe (&locker->loc); } - free (locker->volume); - + GF_FREE (locker->volume); + list_del_init (&locker->lockers); - free (locker); + GF_FREE (locker); } tmp = NULL; @@ -541,10 +544,10 @@ do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, loc_wipe (&locker->loc); } - free (locker->volume); - + GF_FREE (locker->volume); + list_del_init (&locker->lockers); - free (locker); + GF_FREE (locker); } ret = 0; @@ -601,7 +604,7 @@ do_fd_cleanup (xlator_t *this, server_connection_t *conn, call_frame_t *frame, } } - FREE (fdentries); + GF_FREE (fdentries); ret = 0; out: @@ -631,7 +634,7 @@ do_connection_cleanup (xlator_t *this, server_connection_t *conn, state = CALL_STATE (frame); if (state) - free (state); + GF_FREE (state); STACK_DESTROY (frame->root); @@ -733,7 +736,7 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) list_splice_init (<able->dir_lockers, &dir_lockers); } UNLOCK (<able->lock); - free (ltable); + GF_FREE (ltable); flock.l_type = F_UNLCK; flock.l_start = 0; @@ -764,11 +767,11 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) loc_wipe (&locker->loc); } - free (locker->volume); + GF_FREE (locker->volume); - list_del_init (&locker->lockers); - free (locker); - } + list_del_init (&locker->lockers); + GF_FREE (locker); + } tmp = NULL; locker = NULL; @@ -796,11 +799,12 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) loc_wipe (&locker->loc); } - free (locker->volume); + GF_FREE (locker->volume); - list_del_init (&locker->lockers); - free (locker); - } + + list_del_init (&locker->lockers); + GF_FREE (locker); + } pthread_mutex_lock (&(conn->lock)); { @@ -827,22 +831,22 @@ server_connection_destroy (xlator_t *this, server_connection_t *conn) fd); } } - FREE (fdentries); + GF_FREE (fdentries); } } if (frame) { state = CALL_STATE (frame); if (state) - free (state); + GF_FREE (state); STACK_DESTROY (frame->root); } gf_log (this->name, GF_LOG_INFO, "destroyed connection of %s", conn->id); - FREE (conn->id); - FREE (conn); + GF_FREE (conn->id); + GF_FREE (conn); out: return ret; @@ -867,12 +871,13 @@ server_connection_get (xlator_t *this, const char *id) } } - if (!conn) { - conn = (void *) CALLOC (1, sizeof (*conn)); + if (!conn) { + conn = (void *) GF_CALLOC (1, sizeof (*conn), + gf_server_mt_server_connection_t); - conn->id = strdup (id); - conn->fdtable = gf_fd_fdtable_alloc (); - conn->ltable = gf_lock_table_new (); + conn->id = gf_strdup (id); + conn->fdtable = gf_fd_fdtable_alloc (); + conn->ltable = gf_lock_table_new (); pthread_mutex_init (&conn->lock, NULL); diff --git a/xlators/protocol/server/src/server-mem-types.h b/xlators/protocol/server/src/server-mem-types.h new file mode 100644 index 00000000..86877d79 --- /dev/null +++ b/xlators/protocol/server/src/server-mem-types.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __AFR_MEM_TYPES_H__ +#define __AFR_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_server_mem_types_ { + gf_server_mt_dir_entry_t = gf_common_mt_end + 1, + gf_server_mt_volfile_ctx, + gf_server_mt_server_state_t, + gf_server_mt_server_conf_t, + gf_server_mt_locker, + gf_server_mt_lock_table, + gf_server_mt_char, + gf_server_mt_server_connection_t, + gf_server_mt_resolve_comp, + gf_server_mt_end +}; +#endif + diff --git a/xlators/protocol/server/src/server-protocol.c b/xlators/protocol/server/src/server-protocol.c index 71c5a1fc..079b3f2e 100644 --- a/xlators/protocol/server/src/server-protocol.c +++ b/xlators/protocol/server/src/server-protocol.c @@ -2,7 +2,7 @@ Copyright (c) 2006-2009 Gluster, Inc. This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify + GlusterFS is GF_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. @@ -2535,10 +2535,10 @@ server_lookup (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_DONTCARE; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); if (IS_NOT_ROOT (pathlen)) { - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.bname = gf_strdup (req->bname + pathlen); baselen = STRLEN_0 (state->resolve.bname); } @@ -2555,7 +2555,7 @@ server_lookup (call_frame_t *frame, xlator_t *bound_xl, "unserialize req-buffer to dictionary", frame->root->unique, state->resolve.path, state->resolve.ino); - FREE (req_dictbuf); + GF_FREE (req_dictbuf); goto err; } @@ -2625,7 +2625,7 @@ server_stat (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); } resolve_and_resume (frame, server_stat_resume); @@ -2670,7 +2670,7 @@ server_setattr (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); gf_stat_to_iatt (&req->stbuf, &state->stbuf); state->valid = ntoh32 (req->valid); @@ -2762,7 +2762,7 @@ server_readlink (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->size = ntoh32 (req->size); @@ -2817,8 +2817,8 @@ server_create (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_NOT; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); state->mode = ntoh32 (req->mode); state->flags = gf_flags_to_flags (ntoh32 (req->flags)); @@ -2867,7 +2867,7 @@ server_open (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->flags = gf_flags_to_flags (ntoh32 (req->flags)); @@ -3208,7 +3208,7 @@ server_truncate (call_frame_t *frame, xlator_t *bound_xl, state = CALL_STATE (frame); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); state->offset = ntoh64 (req->offset); @@ -3257,8 +3257,8 @@ server_unlink (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); resolve_and_resume (frame, server_unlink_resume); @@ -3306,7 +3306,7 @@ server_setxattr (call_frame_t *frame, xlator_t *bound_xl, dict_len = ntoh32 (req->dict_len); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path + dict_len); + state->resolve.path = gf_strdup (req->path + dict_len); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); state->flags = ntoh32 (req->flags); @@ -3323,7 +3323,7 @@ server_setxattr (call_frame_t *frame, xlator_t *bound_xl, "unserialize request buffer to dictionary", frame->root->unique, state->loc.path, state->resolve.ino); - FREE (req_dictbuf); + GF_FREE (req_dictbuf); goto err; } @@ -3400,7 +3400,7 @@ server_fsetxattr (call_frame_t *frame, xlator_t *bound_xl, "unserialize request buffer to dictionary", frame->root->unique, state->loc.path, state->resolve.ino); - FREE (req_dictbuf); + GF_FREE (req_dictbuf); goto err; } @@ -3478,7 +3478,7 @@ server_fxattrop (call_frame_t *frame, xlator_t *bound_xl, "fd - %"PRId64" (%"PRId64"): failed to unserialize " "request buffer to dictionary", state->resolve.fd_no, state->fd->inode->ino); - free (req_dictbuf); + GF_FREE (req_dictbuf); goto fail; } dict->extra_free = req_dictbuf; @@ -3538,7 +3538,7 @@ server_xattrop (call_frame_t *frame, xlator_t *bound_xl, dict_len = ntoh32 (req->dict_len); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path + dict_len); + state->resolve.path = gf_strdup (req->path + dict_len); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); state->flags = ntoh32 (req->flags); @@ -3555,7 +3555,7 @@ server_xattrop (call_frame_t *frame, xlator_t *bound_xl, "fd - %"PRId64" (%"PRId64"): failed to unserialize " "request buffer to dictionary", state->resolve.fd_no, state->fd->inode->ino); - free (req_dictbuf); + GF_FREE (req_dictbuf); goto fail; } dict->extra_free = req_dictbuf; @@ -3613,13 +3613,13 @@ server_getxattr (call_frame_t *frame, xlator_t *bound_xl, pathlen = STRLEN_0 (req->path); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); namelen = ntoh32 (req->namelen); if (namelen) - state->name = strdup (req->name + pathlen); + state->name = gf_strdup (req->name + pathlen); resolve_and_resume (frame, server_getxattr_resume); @@ -3665,7 +3665,7 @@ server_fgetxattr (call_frame_t *frame, xlator_t *bound_xl, namelen = ntoh32 (req->namelen); if (namelen) - state->name = strdup (req->name); + state->name = gf_strdup (req->name); resolve_and_resume (frame, server_fgetxattr_resume); @@ -3708,10 +3708,10 @@ server_removexattr (call_frame_t *frame, xlator_t *bound_xl, pathlen = STRLEN_0 (req->path); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->name = strdup (req->name + pathlen); + state->name = gf_strdup (req->name + pathlen); resolve_and_resume (frame, server_removexattr_resume); @@ -3758,7 +3758,7 @@ server_statfs (call_frame_t *frame, xlator_t *bound_xl, if (!state->resolve.ino) state->resolve.ino = 1; state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); resolve_and_resume (frame, server_statfs_resume); @@ -3801,7 +3801,7 @@ server_opendir (call_frame_t *frame, xlator_t *bound_xl, state = CALL_STATE (frame); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); @@ -4087,8 +4087,8 @@ server_mknod (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_NOT; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); state->mode = ntoh32 (req->mode); state->dev = ntoh64 (req->dev); @@ -4140,8 +4140,8 @@ server_mkdir (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_NOT; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); state->mode = ntoh32 (req->mode); @@ -4186,8 +4186,8 @@ server_rmdir (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); resolve_and_resume (frame, server_rmdir_resume); @@ -4235,7 +4235,7 @@ server_inodelk (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_EXACT; state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); cmd = ntoh32 (req->cmd); switch (cmd) { @@ -4251,7 +4251,7 @@ server_inodelk (call_frame_t *frame, xlator_t *bound_xl, } state->type = ntoh32 (req->type); - state->volume = strdup (req->volume + pathlen); + state->volume = gf_strdup (req->volume + pathlen); gf_flock_to_flock (&req->flock, &state->flock); @@ -4310,7 +4310,7 @@ server_finodelk (call_frame_t *frame, xlator_t *bound_xl, state = CALL_STATE(frame); state->resolve.type = RESOLVE_EXACT; - state->volume = strdup (req->volume); + state->volume = gf_strdup (req->volume); state->resolve.fd_no = ntoh64 (req->fd); state->cmd = ntoh32 (req->cmd); @@ -4388,13 +4388,13 @@ server_entrylk (call_frame_t *frame, xlator_t *bound_xl, vollen = STRLEN_0(req->volume + pathlen + namelen); state->resolve.type = RESOLVE_EXACT; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.ino = ntoh64 (req->ino); state->resolve.gen = ntoh64 (req->gen); if (namelen) - state->name = strdup (req->name + pathlen); - state->volume = strdup (req->volume + pathlen + namelen); + state->name = gf_strdup (req->name + pathlen); + state->volume = gf_strdup (req->volume + pathlen + namelen); state->cmd = ntoh32 (req->cmd); state->type = ntoh32 (req->type); @@ -4451,7 +4451,7 @@ server_fentrylk (call_frame_t *frame, xlator_t *bound_xl, namelen = ntoh64 (req->namelen); if (namelen) state->name = req->name; - state->volume = strdup (req->volume + namelen); + state->volume = gf_strdup (req->volume + namelen); resolve_and_resume (frame, server_finodelk_resume); @@ -4495,7 +4495,7 @@ server_access (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_MUST; state->resolve.ino = hton64 (req->ino); state->resolve.gen = hton64 (req->gen); - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->mask = ntoh32 (req->mask); @@ -4548,9 +4548,9 @@ server_symlink (call_frame_t *frame, xlator_t *bound_xl, state->resolve.type = RESOLVE_NOT; state->resolve.par = ntoh64 (req->par); state->resolve.gen = ntoh64 (req->gen); - state->resolve.path = strdup (req->path); - state->resolve.bname = strdup (req->bname + pathlen); - state->name = strdup (req->linkname + pathlen + baselen); + state->resolve.path = gf_strdup (req->path); + state->resolve.bname = gf_strdup (req->bname + pathlen); + state->name = gf_strdup (req->linkname + pathlen + baselen); resolve_and_resume (frame, server_symlink_resume); @@ -4610,13 +4610,13 @@ server_link (call_frame_t *frame, xlator_t *this, newbaselen = STRLEN_0 (req->newbname + oldpathlen + newpathlen); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->oldpath); + state->resolve.path = gf_strdup (req->oldpath); state->resolve.ino = ntoh64 (req->oldino); state->resolve.gen = ntoh64 (req->oldgen); state->resolve2.type = RESOLVE_NOT; - state->resolve2.path = strdup (req->newpath + oldpathlen); - state->resolve2.bname = strdup (req->newbname + oldpathlen + newpathlen); + state->resolve2.path = gf_strdup (req->newpath + oldpathlen); + state->resolve2.bname = gf_strdup (req->newbname + oldpathlen + newpathlen); state->resolve2.par = ntoh64 (req->newpar); state->resolve2.gen = ntoh64 (req->newgen); @@ -4680,14 +4680,14 @@ server_rename (call_frame_t *frame, xlator_t *bound_xl, oldbaselen + newpathlen); state->resolve.type = RESOLVE_MUST; - state->resolve.path = strdup (req->oldpath); - state->resolve.bname = strdup (req->oldbname + oldpathlen); + state->resolve.path = gf_strdup (req->oldpath); + state->resolve.bname = gf_strdup (req->oldbname + oldpathlen); state->resolve.par = ntoh64 (req->oldpar); state->resolve.gen = ntoh64 (req->oldgen); state->resolve2.type = RESOLVE_MAY; - state->resolve2.path = strdup (req->newpath + oldpathlen + oldbaselen); - state->resolve2.bname = strdup (req->newbname + oldpathlen + oldbaselen + + state->resolve2.path = gf_strdup (req->newpath + oldpathlen + oldbaselen); + state->resolve2.bname = gf_strdup (req->newbname + oldpathlen + oldbaselen + newpathlen); state->resolve2.par = ntoh64 (req->newpar); state->resolve2.gen = ntoh64 (req->newgen); @@ -4809,10 +4809,11 @@ _volfile_update_checksum (xlator_t *this, char *key, uint32_t checksum) } if (!temp_volfile) { - temp_volfile = CALLOC (1, sizeof (struct _volfile_ctx)); + temp_volfile = GF_CALLOC (1, sizeof (struct _volfile_ctx), + gf_server_mt_volfile_ctx); temp_volfile->next = conf->volfile; - temp_volfile->key = (key)? strdup (key): NULL; + temp_volfile->key = (key)? gf_strdup (key): NULL; temp_volfile->checksum = checksum; conf->volfile = temp_volfile; @@ -4900,12 +4901,12 @@ build_volfile_path (xlator_t *this, const char *key, char *path, goto out; } - conf_dir = strdup (conf_dir_data->data); + conf_dir = gf_strdup (conf_dir_data->data); free_conf_dir = 1; } - ret = asprintf (&filename, "%s/%s.vol", - conf_dir, key); + ret = gf_asprintf (&filename, "%s/%s.vol", + conf_dir, key); if (-1 == ret) goto out; @@ -4933,10 +4934,10 @@ build_volfile_path (xlator_t *this, const char *key, char *path, out: if (free_conf_dir) - free (conf_dir); + GF_FREE (conf_dir); if (free_filename) - free (filename); + GF_FREE (filename); return ret; } @@ -5161,7 +5162,7 @@ server_checksum (call_frame_t *frame, xlator_t *bound_xl, state = CALL_STATE (frame); state->resolve.type = RESOLVE_MAY; - state->resolve.path = strdup (req->path); + state->resolve.path = gf_strdup (req->path); state->resolve.gen = ntoh64 (req->gen); state->resolve.ino = ntoh64 (req->ino); state->flags = ntoh32 (req->flag); @@ -5397,11 +5398,11 @@ mop_setvolume (call_frame_t *frame, xlator_t *bound_xl, ret = strcmp (version, GF_PROTOCOL_VERSION); if (ret != 0) { - ret = asprintf (&msg, "protocol version mismatch: client(%s) " + ret = gf_asprintf (&msg, "protocol version mismatch: client(%s) " "- server(%s)", version, GF_PROTOCOL_VERSION); if (-1 == ret) { gf_log (trans->xl->name, GF_LOG_ERROR, - "asprintf failed while setting up error msg"); + "gf_asprintf failed while setting up error msg"); goto fail; } ret = dict_set_dynstr (reply, "ERROR", msg); @@ -5430,11 +5431,11 @@ mop_setvolume (call_frame_t *frame, xlator_t *bound_xl, xl = get_xlator_by_name (frame->this, name); if (xl == NULL) { - ret = asprintf (&msg, "remote-subvolume \"%s\" is not found", + ret = gf_asprintf (&msg, "remote-subvolume \"%s\" is not found", name); if (-1 == ret) { gf_log (trans->xl->name, GF_LOG_ERROR, - "asprintf failed while setting error msg"); + "gf_asprintf failed while setting error msg"); goto fail; } ret = dict_set_dynstr (reply, "ERROR", msg); @@ -5806,7 +5807,8 @@ get_frame_for_transport (transport_t *trans) frame = create_frame (trans->xl, pool); GF_VALIDATE_OR_GOTO("server", frame, out); - state = CALLOC (1, sizeof (*state)); + state = GF_CALLOC (1, sizeof (*state), + gf_server_mt_server_state_t); GF_VALIDATE_OR_GOTO("server", state, out); conn = trans->xl_private; @@ -6187,7 +6189,7 @@ get_auth_types (dict_t *this, char *key, data_t *value, void *data) int32_t ret = -1; auth_dict = data; - key_cpy = strdup (key); + key_cpy = gf_strdup (key); GF_VALIDATE_OR_GOTO("server", key_cpy, out); tmp = strtok_r (key_cpy, ".", &saveptr); @@ -6208,7 +6210,7 @@ get_auth_types (dict_t *this, char *key, data_t *value, void *data) } } - FREE (key_cpy); + GF_FREE (key_cpy); out: return; } @@ -6229,7 +6231,7 @@ validate_auth_options (xlator_t *this, dict_t *dict) while (trav) { error = -1; for (pair = dict->members_list; pair; pair = pair->next) { - key_cpy = strdup (pair->key); + key_cpy = gf_strdup (pair->key); tmp = strtok_r (key_cpy, ".", &saveptr); ret = strcmp (tmp, "auth"); if (ret == 0) { @@ -6241,10 +6243,10 @@ validate_auth_options (xlator_t *this, dict_t *dict) if (strcmp (tmp, trav->xlator->name) == 0) { error = 0; - free (key_cpy); + GF_FREE (key_cpy); break; } - free (key_cpy); + GF_FREE (key_cpy); } if (-1 == error) { gf_log (this->name, GF_LOG_ERROR, @@ -6259,6 +6261,25 @@ validate_auth_options (xlator_t *this, dict_t *dict) return error; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_server_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + " failed"); + return ret; + } + + return ret; +} + /* * init - called during server protocol initialization @@ -6295,7 +6316,8 @@ init (xlator_t *this) goto out; } - conf = CALLOC (1, sizeof (server_conf_t)); + conf = GF_CALLOC (1, sizeof (server_conf_t), + gf_server_mt_server_conf_t); GF_VALIDATE_OR_GOTO(this->name, conf, out); INIT_LIST_HEAD (&conf->conns); @@ -6409,7 +6431,7 @@ protocol_server_pollin (xlator_t *this, transport_t *trans) hdrlen, iobuf); /* TODO: use mem-pool */ - FREE (hdr); + GF_FREE (hdr); return ret; } @@ -6433,7 +6455,7 @@ fini (xlator_t *this) dict_unref (conf->auth_modules); } - FREE (conf); + GF_FREE (conf); this->private = NULL; out: return; diff --git a/xlators/protocol/server/src/server-protocol.h b/xlators/protocol/server/src/server-protocol.h index 61fcb877..3d432614 100644 --- a/xlators/protocol/server/src/server-protocol.h +++ b/xlators/protocol/server/src/server-protocol.h @@ -34,6 +34,7 @@ #include "authenticate.h" #include "fd.h" #include "byte-order.h" +#include "server-mem-types.h" #define DEFAULT_BLOCK_SIZE 4194304 /* 4MB */ #define DEFAULT_VOLUME_FILE_PATH CONFDIR "/glusterfs.vol" diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c index f4c9ebad..00f1728c 100644 --- a/xlators/protocol/server/src/server-resolve.c +++ b/xlators/protocol/server/src/server-resolve.c @@ -69,11 +69,12 @@ prepare_components (call_frame_t *frame) this = frame->this; resolve = state->resolve_now; - resolved = strdup (resolve->path); + resolved = gf_strdup (resolve->path); resolve->resolved = resolved; count = component_count (resolve->path); - components = CALLOC (sizeof (*components), count); + components = GF_CALLOC (sizeof (*components), count, + gf_server_mt_resolve_comp); resolve->components = components; components[0].basename = ""; @@ -116,7 +117,7 @@ resolve_loc_touchup (call_frame_t *frame) } if (!path) - path = strdup (resolve->path); + path = gf_strdup (resolve->path); loc->path = path; } @@ -205,7 +206,7 @@ resolve_deep_cbk (call_frame_t *frame, void *cookie, xlator_t *this, /* join the current component with the path resolved until now */ *(components[i].basename - 1) = '/'; - resolve->deep_loc.path = strdup (resolve->resolved); + resolve->deep_loc.path = gf_strdup (resolve->resolved); resolve->deep_loc.parent = inode_ref (components[i-1].inode); resolve->deep_loc.inode = inode_new (state->itable); resolve->deep_loc.name = components[i].basename; @@ -241,7 +242,7 @@ resolve_path_deep (call_frame_t *frame) /* start from the root */ resolve->deep_loc.inode = state->itable->root; - resolve->deep_loc.path = strdup ("/"); + resolve->deep_loc.path = gf_strdup ("/"); resolve->deep_loc.name = ""; STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, diff --git a/xlators/storage/bdb/src/bctx.c b/xlators/storage/bdb/src/bctx.c index 361ce75f..150d709a 100644 --- a/xlators/storage/bdb/src/bctx.c +++ b/xlators/storage/bdb/src/bctx.c @@ -25,12 +25,12 @@ static void __destroy_bctx (bctx_t *bctx) { if (bctx->directory) - FREE (bctx->directory); + GF_FREE (bctx->directory); if (bctx->db_path) - FREE (bctx->db_path); + GF_FREE (bctx->db_path); - FREE (bctx); + GF_FREE (bctx); } static void @@ -236,16 +236,16 @@ __create_bctx (bctx_table_t *table, bctx_t *bctx = NULL; char *db_path = NULL; - bctx = CALLOC (1, sizeof (*bctx)); + bctx = GF_CALLOC (1, sizeof (*bctx), gf_bdb_mt_bctx_t); GF_VALIDATE_OR_GOTO ("bctx", bctx, out); bctx->table = table; - bctx->directory = strdup (path); + bctx->directory = gf_strdup (path); GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out); MAKE_REAL_PATH_TO_STORAGE_DB (db_path, BDB_THIS (table), path); - bctx->db_path = strdup (db_path); + bctx->db_path = gf_strdup (db_path); GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out); INIT_LIST_HEAD (&bctx->c_list); @@ -327,7 +327,7 @@ bctx_parent (bctx_table_t *table, GF_VALIDATE_OR_GOTO ("bctx", table, out); GF_VALIDATE_OR_GOTO ("bctx", path, out); - pathname = strdup (path); + pathname = gf_strdup (path); GF_VALIDATE_OR_GOTO ("bctx", pathname, out); directory = dirname (pathname); diff --git a/xlators/storage/bdb/src/bdb-ll.c b/xlators/storage/bdb/src/bdb-ll.c index 290b2971..dcf18c0a 100644 --- a/xlators/storage/bdb/src/bdb-ll.c +++ b/xlators/storage/bdb/src/bdb-ll.c @@ -57,7 +57,7 @@ bdb_generate_secondary_hash (DB *secondary, primary = pkey->data; - hash = calloc (1, sizeof (uint32_t)); + hash = GF_CALLOC (1, sizeof (uint32_t), gf_bdb_mt_uint32_t); *hash = gf_dm_hashfn (primary, pkey->size); @@ -316,9 +316,10 @@ bdb_cache_insert (bctx_t *bctx, list_del_init (&bcache->c_list); } if (bcache->key) { - free (bcache->key); - bcache->key = calloc (key->size + 1, - sizeof (char)); + GF_FREE (bcache->key); + bcache->key = GF_CALLOC (key->size + 1, + sizeof (char), + gf_bdb_mt_char); GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->key, unlock); memcpy (bcache->key, (char *)key->data, @@ -331,7 +332,7 @@ bdb_cache_insert (bctx_t *bctx, bctx->directory, (char *)key->data); } /* if(bcache->key)...else */ if (bcache->data) { - free (bcache->data); + GF_FREE (bcache->data); bcache->data = memdup (data->data, data->size); GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->data, unlock); @@ -347,10 +348,12 @@ bdb_cache_insert (bctx_t *bctx, ret = 0; } else { /* we will be entering here very rarely */ - bcache = CALLOC (1, sizeof (*bcache)); + bcache = GF_CALLOC (1, sizeof (*bcache), + gf_bdb_mt_bdb_cache_t); GF_VALIDATE_OR_GOTO ("bdb-ll", bcache, unlock); - bcache->key = calloc (key->size + 1, sizeof (char)); + bcache->key = GF_CALLOC (key->size + 1, sizeof (char), + gf_bdb_mt_char); GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->key, unlock); memcpy (bcache->key, key->data, key->size); @@ -391,9 +394,9 @@ bdb_cache_delete (bctx_t *bctx, if (bcache) { list_del_init (&bcache->c_list); - free (bcache->key); - free (bcache->data); - free (bcache); + GF_FREE (bcache->key); + GF_FREE (bcache->data); + GF_FREE (bcache); } } UNLOCK (&bctx->lock); @@ -578,7 +581,7 @@ bdb_db_get (bctx_t *bctx, } if (size == 0) - free (value.data); + GF_FREE (value.data); need_break = 1; } else { @@ -615,7 +618,7 @@ bdb_db_iread (struct bdb_ctx *bctx, const char *key, char **bufp) size = ret; if (bufp) { - buf = calloc (size, sizeof (char)); + buf = GF_CALLOC (size, sizeof (char), gf_bdb_mt_char); *bufp = buf; ret = bdb_db_get (bctx, NULL, key, buf, size, 0); } @@ -1309,7 +1312,7 @@ bdb_db_init (xlator_t *this, private->dir_mode = private->dir_mode | S_IFDIR; - table = CALLOC (1, sizeof (*table)); + table = GF_CALLOC (1, sizeof (*table), gf_bdb_mt_bctx_table_t); if (table == NULL) { gf_log ("bdb-ll", GF_LOG_CRITICAL, "memory allocation for 'storage/bdb' internal " @@ -1376,8 +1379,9 @@ bdb_db_init (xlator_t *this, } table->hash_size = BDB_DEFAULT_HASH_SIZE; - table->b_hash = CALLOC (BDB_DEFAULT_HASH_SIZE, - sizeof (struct list_head)); + table->b_hash = GF_CALLOC (BDB_DEFAULT_HASH_SIZE, + sizeof (struct list_head), + gf_bdb_mt_list_head); for (idx = 0; idx < table->hash_size; idx++) INIT_LIST_HEAD(&(table->b_hash[idx])); @@ -1386,7 +1390,7 @@ bdb_db_init (xlator_t *this, ret = dict_get_str (options, "errfile", &errfile); if (ret == 0) { - private->errfile = strdup (errfile); + private->errfile = gf_strdup (errfile); gf_log (this->name, GF_LOG_DEBUG, "using %s as error logging file for libdb (Berkeley DB " "library) internal logging.", private->errfile); @@ -1402,10 +1406,10 @@ bdb_db_init (xlator_t *this, "using the database environment home " "directory (%s) itself as transaction log " "directory", directory); - private->logdir = strdup (directory); + private->logdir = gf_strdup (directory); } else { - private->logdir = strdup (logdir); + private->logdir = gf_strdup (logdir); op_ret = stat (private->logdir, &stbuf); if ((op_ret != 0) @@ -1445,15 +1449,15 @@ bdb_db_init (xlator_t *this, return op_ret; err: if (table) { - FREE (table->b_hash); - FREE (table); + GF_FREE (table->b_hash); + GF_FREE (table); } if (private) { if (private->errfile) - FREE (private->errfile); + GF_FREE (private->errfile); if (private->logdir) - FREE (private->logdir); + GF_FREE (private->logdir); } return -1; diff --git a/xlators/storage/bdb/src/bdb-mem-types.h b/xlators/storage/bdb/src/bdb-mem-types.h new file mode 100644 index 00000000..cfbc4a4e --- /dev/null +++ b/xlators/storage/bdb/src/bdb-mem-types.h @@ -0,0 +1,42 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __POSIX_MEM_TYPES_H__ +#define __POSIX_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_bdb_mem_types_ { + gf_bdb_mt_bctx_t = gf_common_mt_end + 1, + gf_bdb_mt_bdb_fd, + gf_bdb_mt_dir_entry_t, + gf_bdb_mt_char, + gf_bdb_mt_dir_entry_t, + gf_bdb_mt_char, + gf_bdb_mt_bdb_private, + gf_bdb_mt_uint32_t, + gf_bdb_mt_char, + gf_bdb_mt_bdb_cache_t, + gf_bdb_mt_char, + gf_bdb_mt_bctx_table_t, + gf_bdb_mt_list_head, + gf_bdb_mt_end, +}; +#endif diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c index 68e5227a..fba34ee0 100644 --- a/xlators/storage/bdb/src/bdb.c +++ b/xlators/storage/bdb/src/bdb.c @@ -320,7 +320,7 @@ bdb_create (call_frame_t *frame, } /* create successful */ - bfd = CALLOC (1, sizeof (*bfd)); + bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); if (bfd == NULL) { gf_log (this->name, GF_LOG_DEBUG, "CREATE %"PRId64"/%s (%s): ENOMEM" @@ -333,7 +333,7 @@ bdb_create (call_frame_t *frame, /* NOTE: bdb_get_bctx_from () returns bctx with a ref */ bfd->ctx = bctx; - bfd->key = strdup (key_string); + bfd->key = gf_strdup (key_string); if (bfd->key == NULL) { gf_log (this->name, GF_LOG_DEBUG, "CREATE %"PRId64" (%s): ENOMEM" @@ -399,7 +399,7 @@ bdb_open (call_frame_t *frame, goto out; } - bfd = CALLOC (1, sizeof (*bfd)); + bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); if (bfd == NULL) { gf_log (this->name, GF_LOG_DEBUG, "OPEN %"PRId64" (%s): ENOMEM" @@ -414,7 +414,7 @@ bdb_open (call_frame_t *frame, bfd->ctx = bctx; MAKE_KEY_FROM_PATH (key_string, loc->path); - bfd->key = strdup (key_string); + bfd->key = gf_strdup (key_string); if (bfd->key == NULL) { gf_log (this->name, GF_LOG_DEBUG, "OPEN %"PRId64" (%s): ENOMEM" @@ -686,8 +686,8 @@ bdb_release (xlator_t *this, bfd->ctx = NULL; if (bfd->key) - FREE (bfd->key); /* we did strdup() in bdb_open() */ - FREE (bfd); + GF_FREE (bfd->key); /* we did strdup() in bdb_open() */ + GF_FREE (bfd); op_ret = 0; op_errno = 0; @@ -793,7 +793,7 @@ bdb_lookup (call_frame_t *frame, MAKE_REAL_PATH (real_path, this, loc->path); - pathname = strdup (loc->path); + pathname = gf_strdup (loc->path); GF_VALIDATE_OR_GOTO (this->name, pathname, out); directory = dirname (pathname); @@ -932,11 +932,11 @@ bdb_lookup (call_frame_t *frame, file_content, entry_size); if (op_ret < 0) { /* continue without giving file contents */ - FREE (file_content); + GF_FREE (file_content); } } else { if (file_content) - FREE (file_content); + GF_FREE (file_content); } if (loc->ino) { @@ -966,7 +966,7 @@ out: } if (pathname) - free (pathname); + GF_FREE (pathname); if (xattr) dict_ref (xattr); @@ -1102,7 +1102,7 @@ bdb_opendir (call_frame_t *frame, goto out; } - bfd = CALLOC (1, sizeof (*bfd)); + bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); if (bfd == NULL) { gf_log (this->name, GF_LOG_DEBUG, "OPENDIR %"PRId64" (%s): ENOMEM" @@ -1126,7 +1126,7 @@ bdb_opendir (call_frame_t *frame, /* NOTE: bctx_lookup() return bctx with ref */ bfd->ctx = bctx; - bfd->path = strdup (real_path); + bfd->path = gf_strdup (real_path); if (bfd == NULL) { gf_log (this->name, GF_LOG_DEBUG, "OPENDIR %"PRId64" (%s): ENOMEM" @@ -1149,7 +1149,7 @@ err: if (bfd->dir) closedir (bfd->dir); - FREE (bfd); + GF_FREE (bfd); } return 0; @@ -1264,7 +1264,8 @@ bdb_getdents (call_frame_t *frame, continue; }/* if(key.data)...else */ - this_entry = CALLOC (1, sizeof (*this_entry)); + this_entry = GF_CALLOC (1, sizeof (*this_entry), + gf_bdb_mt_dir_entry_t); if (this_entry == NULL) { gf_log (this->name, GF_LOG_DEBUG, "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 @@ -1276,7 +1277,8 @@ bdb_getdents (call_frame_t *frame, goto out; } - this_entry->name = CALLOC (pri.size + 1, sizeof (char)); + this_entry->name = GF_CALLOC (pri.size + 1, sizeof (char), + gf_bdb_mt_char); if (this_entry->name == NULL) { gf_log (this->name, GF_LOG_DEBUG, "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 @@ -1308,10 +1310,10 @@ bdb_getdents (call_frame_t *frame, /* if size is 0, count can never be = size, * so entire dir is read */ if (sec.data) - FREE (sec.data); + GF_FREE (sec.data); if (pri.data) - FREE (pri.data); + GF_FREE (pri.data); if (count == size) break; @@ -1377,7 +1379,8 @@ dir_read: continue; } - this_entry = CALLOC (1, sizeof (*this_entry)); + this_entry = GF_CALLOC (1, sizeof (*this_entry), + gf_bdb_mt_dir_entry_t); if (this_entry == NULL) { gf_log (this->name, GF_LOG_DEBUG, "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 @@ -1389,7 +1392,7 @@ dir_read: goto out; } - this_entry->name = strdup (dirent->d_name); + this_entry->name = gf_strdup (dirent->d_name); if (this_entry->name == NULL) { gf_log (this->name, GF_LOG_DEBUG, "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 @@ -1410,7 +1413,7 @@ dir_read: ret = readlink (entry_path, linkpath, ZR_PATH_MAX); if (ret != -1) { linkpath[ret] = '\0'; - this_entry->link = strdup (linkpath); + this_entry->link = gf_strdup (linkpath); } } else { this_entry->link = ""; @@ -1441,8 +1444,8 @@ out: while (entries.next) { this_entry = entries.next; entries.next = entries.next->next; - FREE (this_entry->name); - FREE (this_entry); + GF_FREE (this_entry->name); + GF_FREE (this_entry); } return 0; @@ -1468,7 +1471,7 @@ bdb_releasedir (xlator_t *this, } if (bfd->path) { - free (bfd->path); + GF_FREE (bfd->path); } else { gf_log (this->name, GF_LOG_DEBUG, "RELEASEDIR %"PRId64": (bfd->path is NULL)", @@ -1491,7 +1494,7 @@ bdb_releasedir (xlator_t *this, fd->inode->ino); } - free (bfd); + GF_FREE (bfd); out: return 0; @@ -2395,7 +2398,7 @@ bdb_getxattr (call_frame_t *frame, if (op_ret == -1) break; - value = CALLOC (op_ret + 1, sizeof(char)); + value = GF_CALLOC (op_ret + 1, sizeof(char), gf_bdb_mt_char); GF_VALIDATE_OR_GOTO (this->name, value, out); op_ret = sys_lgetxattr (real_path, key, value, @@ -2406,7 +2409,7 @@ bdb_getxattr (call_frame_t *frame, op_ret = dict_set_dynptr (dict, key, value, op_ret); if (op_ret < 0) { - FREE (value); + GF_FREE (value); gf_log (this->name, GF_LOG_DEBUG, "GETXATTR %"PRId64" (%s) - %s: " "(skipping key %s)", @@ -2619,7 +2622,7 @@ bdb_setdents (call_frame_t *frame, real_path_len = strlen (bfd->path); entry_path_len = real_path_len + 256; - entry_path = CALLOC (1, entry_path_len); + entry_path = GF_CALLOC (1, entry_path_len, gf_bdb_mt_char); GF_VALIDATE_OR_GOTO (this->name, entry_path, out); strcpy (entry_path, bfd->path); @@ -2710,7 +2713,7 @@ bdb_setdents (call_frame_t *frame, out: STACK_UNWIND (frame, op_ret, op_errno); - FREE (entry_path); + GF_FREE (entry_path); return 0; } @@ -2892,11 +2895,11 @@ bdb_readdir (call_frame_t *frame, this_entry->d_len = pri.size + 1; if (sec.data) { - FREE (sec.data); + GF_FREE (sec.data); } if (pri.data) - FREE (pri.data); + GF_FREE (pri.data); list_add_tail (&this_entry->list, &entries.list); @@ -3189,7 +3192,7 @@ bdb_checksum (call_frame_t *frame, for (idx = 0; idx < length; idx++) file_checksum[idx] ^= data[idx]; - FREE (key.data); + GF_FREE (key.data); } else { gf_log (this->name, GF_LOG_DEBUG, "CHECKSUM %"PRId64" (%s)", @@ -3240,6 +3243,24 @@ notify (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_bdb_mt_end + 1); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} /** * init - @@ -3273,7 +3294,7 @@ init (xlator_t *this) goto err; } - _private = CALLOC (1, sizeof (*_private)); + _private = GF_CALLOC (1, sizeof (*_private), gf_bdb_mt_bdb_private); if (_private == NULL) { gf_log (this->name, GF_LOG_ERROR, "could not allocate memory for 'storage/bdb' " @@ -3317,7 +3338,7 @@ init (xlator_t *this) } - _private->export_path = strdup (directory); + _private->export_path = gf_strdup (directory); if (_private->export_path == NULL) { gf_log (this->name, GF_LOG_ERROR, "could not allocate memory for 'storage/bdb' " @@ -3367,9 +3388,9 @@ init (xlator_t *this) err: if (_private) { if (_private->export_path) - FREE (_private->export_path); + GF_FREE (_private->export_path); - FREE (_private); + GF_FREE (_private); } out: return ret; @@ -3444,9 +3465,9 @@ fini (xlator_t *this) /* impossible to reach here */ } - FREE (B_TABLE(this)); + GF_FREE (B_TABLE(this)); } - FREE (private); + GF_FREE (private); return; } diff --git a/xlators/storage/posix/src/posix-mem-types.h b/xlators/storage/posix/src/posix-mem-types.h new file mode 100644 index 00000000..6687560c --- /dev/null +++ b/xlators/storage/posix/src/posix-mem-types.h @@ -0,0 +1,36 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + +#ifndef __POSIX_MEM_TYPES_H__ +#define __POSIX_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_posix_mem_types_ { + gf_posix_mt_dir_entry_t = gf_common_mt_end + 1, + gf_posix_mt_posix_fd, + gf_posix_mt_char, + gf_posix_mt_posix_private, + gf_posix_mt_int32_t, + gf_posix_mt_posix_dev_t, + gf_posix_mt_trash_path, + gf_posix_mt_end +}; +#endif + diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 832b437b..5ed3e5dc 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -126,7 +126,8 @@ _posix_xattr_get_set (dict_t *xattr_req, goto err; } - databuf = calloc (1, filler->stbuf->ia_size); + databuf = GF_CALLOC (1, filler->stbuf->ia_size, + gf_posix_mt_char); if (!databuf) { gf_log (filler->this->name, GF_LOG_ERROR, @@ -163,7 +164,7 @@ _posix_xattr_get_set (dict_t *xattr_req, if (_fd != -1) close (_fd); if (databuf) - FREE (databuf); + GF_FREE (databuf); } } else if (!strcmp (key, GLUSTERFS_OPEN_FD_COUNT)) { loc = filler->loc; @@ -176,7 +177,8 @@ _posix_xattr_get_set (dict_t *xattr_req, xattr_size = sys_lgetxattr (filler->real_path, key, NULL, 0); if (xattr_size > 0) { - value = calloc (1, xattr_size + 1); + value = GF_CALLOC (1, xattr_size + 1, + gf_posix_mt_char); sys_lgetxattr (filler->real_path, key, value, xattr_size); @@ -422,7 +424,7 @@ setgid_override (xlator_t *this, char *real_path, gid_t *gid) int op_ret = 0; - tmp_path = strdup (real_path); + tmp_path = gf_strdup (real_path); if (!tmp_path) { op_ret = -ENOMEM; gf_log ("[storage/posix]", GF_LOG_ERROR, @@ -453,7 +455,7 @@ setgid_override (xlator_t *this, char *real_path, gid_t *gid) out: if (tmp_path) - FREE (tmp_path); + GF_FREE (tmp_path); return op_ret; } @@ -504,7 +506,7 @@ posix_lookup (call_frame_t *frame, xlator_t *this, parent: if (loc->parent) { - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -522,7 +524,7 @@ parent: op_ret = entry_ret; out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); if (xattr) dict_ref (xattr); @@ -915,7 +917,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this, goto out; } - pfd = CALLOC (1, sizeof (*fd)); + pfd = GF_CALLOC (1, sizeof (*fd), gf_posix_mt_posix_fd); if (!pfd) { op_errno = errno; gf_log (this->name, GF_LOG_ERROR, @@ -925,7 +927,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this, pfd->dir = dir; pfd->fd = dirfd (dir); - pfd->path = strdup (real_path); + pfd->path = gf_strdup (real_path); if (!pfd->path) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -944,8 +946,8 @@ posix_opendir (call_frame_t *frame, xlator_t *this, } if (pfd) { if (pfd->path) - FREE (pfd->path); - FREE (pfd); + GF_FREE (pfd->path); + GF_FREE (pfd); pfd = NULL; } } @@ -1101,7 +1103,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this, goto out; SET_FS_ID (frame->root->uid, gid); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -1168,7 +1170,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); @@ -1289,9 +1291,9 @@ posix_janitor_thread_proc (void *data) } if (pfd->path) - FREE (pfd->path); + GF_FREE (pfd->path); - FREE (pfd); + GF_FREE (pfd); } } @@ -1367,7 +1369,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this, goto out; SET_FS_ID (frame->root->uid, gid); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -1423,7 +1425,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); @@ -1461,7 +1463,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this, SET_FS_ID (frame->root->uid, frame->root->gid); MAKE_REAL_PATH (real_path, this, loc->path); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -1512,7 +1514,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); @@ -1547,7 +1549,7 @@ posix_rmdir (call_frame_t *frame, xlator_t *this, SET_FS_ID (frame->root->uid, frame->root->gid); MAKE_REAL_PATH (real_path, this, loc->path); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -1589,7 +1591,7 @@ posix_rmdir (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); @@ -1639,7 +1641,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this, goto out; SET_FS_ID (frame->root->uid, gid); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -1695,7 +1697,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); @@ -1744,7 +1746,7 @@ posix_rename (call_frame_t *frame, xlator_t *this, MAKE_REAL_PATH (real_oldpath, this, oldloc->path); MAKE_REAL_PATH (real_newpath, this, newloc->path); - oldpathdup = strdup (real_oldpath); + oldpathdup = gf_strdup (real_oldpath); GF_VALIDATE_OR_GOTO (this->name, oldpathdup, out); oldparentpath = dirname (oldpathdup); @@ -1758,7 +1760,7 @@ posix_rename (call_frame_t *frame, xlator_t *this, goto out; } - newpathdup = strdup (real_newpath); + newpathdup = gf_strdup (real_newpath); GF_VALIDATE_OR_GOTO (this->name, newpathdup, out); newparentpath = dirname (newpathdup); @@ -1818,10 +1820,10 @@ posix_rename (call_frame_t *frame, xlator_t *this, out: if (oldpathdup) - FREE (oldpathdup); + GF_FREE (oldpathdup); if (newpathdup) - FREE (newpathdup); + GF_FREE (newpathdup); SET_TO_OLD_FS_ID (); @@ -1873,7 +1875,7 @@ posix_link (call_frame_t *frame, xlator_t *this, was_present = 0; } - newpathdup = strdup (real_newpath); + newpathdup = gf_strdup (real_newpath); if (!newpathdup) { gf_log (this->name, GF_LOG_ERROR, "strdup failed"); op_errno = ENOMEM; @@ -1919,7 +1921,7 @@ posix_link (call_frame_t *frame, xlator_t *this, out: if (newpathdup) - FREE (newpathdup); + GF_FREE (newpathdup); SET_TO_OLD_FS_ID (); STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, @@ -2039,7 +2041,7 @@ posix_create (call_frame_t *frame, xlator_t *this, } SET_FS_ID (frame->root->uid, gid); - pathdup = strdup (real_path); + pathdup = gf_strdup (real_path); GF_VALIDATE_OR_GOTO (this->name, pathdup, out); parentpath = dirname (pathdup); @@ -2106,7 +2108,7 @@ posix_create (call_frame_t *frame, xlator_t *this, } op_ret = -1; - pfd = CALLOC (1, sizeof (*pfd)); + pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd); if (!pfd) { op_errno = errno; @@ -2130,7 +2132,7 @@ posix_create (call_frame_t *frame, xlator_t *this, out: if (pathdup) - FREE (pathdup); + GF_FREE (pathdup); SET_TO_OLD_FS_ID (); if ((-1 == op_ret) && (_fd != -1)) { @@ -2197,7 +2199,7 @@ posix_open (call_frame_t *frame, xlator_t *this, goto out; } - pfd = CALLOC (1, sizeof (*pfd)); + pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd); if (!pfd) { op_errno = errno; @@ -2453,7 +2455,8 @@ posix_writev (call_frame_t *frame, xlator_t *this, max_buf_size = vector[idx].iov_len; } - alloc_buf = MALLOC (1 * (max_buf_size + align)); + alloc_buf = GF_MALLOC (1 * (max_buf_size + align), + gf_posix_mt_char); if (!alloc_buf) { op_errno = errno; gf_log (this->name, GF_LOG_ERROR, @@ -2530,7 +2533,7 @@ posix_writev (call_frame_t *frame, xlator_t *this, out: if (alloc_buf) { - FREE (alloc_buf); + GF_FREE (alloc_buf); } STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, &preop, &postop); @@ -2965,7 +2968,8 @@ get_file_contents (xlator_t *this, char *real_path, goto out; } - *contents = CALLOC (stbuf.ia_size + 1, sizeof(char)); + *contents = GF_CALLOC (stbuf.ia_size + 1, sizeof(char), + gf_posix_mt_char); if (! *contents) { op_ret = -errno; @@ -2995,7 +2999,7 @@ get_file_contents (xlator_t *this, char *real_path, out: if (op_ret < 0) { if (*contents) - FREE (*contents); + GF_FREE (*contents); if (file_fd != -1) close (file_fd); } @@ -3114,7 +3118,8 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, if (op_ret == -1) break; - value = CALLOC (op_ret + 1, sizeof(char)); + value = GF_CALLOC (op_ret + 1, sizeof(char), + gf_posix_mt_char); if (!value) { op_errno = errno; gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -3129,7 +3134,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, if (strcmp (key, gen_key) != 0) dict_set (dict, key, data_from_dynptr (value, op_ret)); else - FREE (value); + GF_FREE (value); remaining_size -= strlen (key) + 1; list_offset += strlen (key) + 1; @@ -3239,7 +3244,8 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, if (op_ret == -1) break; - value = CALLOC (op_ret + 1, sizeof(char)); + value = GF_CALLOC (op_ret + 1, sizeof(char), + gf_posix_mt_char); if (!value) { op_errno = errno; gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -3525,7 +3531,7 @@ do_xattrop (call_frame_t *frame, xlator_t *this, MAKE_REAL_PATH (real_path, this, loc->path); if (loc) { - path = strdup (loc->path); + path = gf_strdup (loc->path); inode = loc->inode; } else { inode = fd->inode; @@ -3533,7 +3539,8 @@ do_xattrop (call_frame_t *frame, xlator_t *this, while (trav) { count = trav->value->len / sizeof (int32_t); - array = CALLOC (count, sizeof (int32_t)); + array = GF_CALLOC (count, sizeof (int32_t), + gf_posix_mt_int32_t); LOCK (&inode->lock); { @@ -3645,10 +3652,10 @@ do_xattrop (call_frame_t *frame, xlator_t *this, out: if (array) - FREE (array); + GF_FREE (array); if (path) - FREE (path); + GF_FREE (path); STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, xattr); return 0; @@ -4222,8 +4229,8 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this, VALIDATE_OR_GOTO (fd, out); memset (strong_checksum, 0, MD5_DIGEST_LEN); + buf = GF_CALLOC (1, len, gf_posix_mt_char); - buf = CALLOC (1, len); if (!buf) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, @@ -4255,7 +4262,7 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this, weak_checksum = gf_rsync_weak_checksum (buf, len); gf_rsync_strong_checksum (buf, len, strong_checksum); - FREE (buf); + GF_FREE (buf); op_ret = 0; out: @@ -4289,6 +4296,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_posix_mt_end + 1); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + /** * init - */ @@ -4375,7 +4401,8 @@ init (xlator_t *this) } } - _private = CALLOC (1, sizeof (*_private)); + _private = GF_CALLOC (1, sizeof (*_private), + gf_posix_mt_posix_private); if (!_private) { gf_log (this->name, GF_LOG_ERROR, "Out of memory."); @@ -4383,13 +4410,14 @@ init (xlator_t *this) goto out; } - _private->base_path = strdup (dir_data->data); + _private->base_path = gf_strdup (dir_data->data); _private->base_path_length = strlen (_private->base_path); - _private->trash_path = CALLOC (1, _private->base_path_length - + strlen ("/") - + strlen (GF_REPLICATE_TRASH_DIR) - + 1); + _private->trash_path = GF_CALLOC (1, _private->base_path_length + + strlen ("/") + + strlen (GF_REPLICATE_TRASH_DIR) + + 1, + gf_posix_mt_trash_path); if (!_private->trash_path) { gf_log (this->name, GF_LOG_ERROR, @@ -4477,9 +4505,11 @@ init (xlator_t *this) if (_private->num_devices_to_span < 1) _private->num_devices_to_span = 1; } - _private->st_device = CALLOC (1, (sizeof (dev_t) * - _private->num_devices_to_span)); + _private->st_device = GF_CALLOC (1, (sizeof (dev_t) * + _private->num_devices_to_span), + gf_posix_mt_posix_dev_t); + /* Start with the base */ _private->st_device[0] = buf.st_dev; @@ -4542,7 +4572,7 @@ fini (xlator_t *this) { struct posix_private *priv = this->private; sys_lremovexattr (priv->base_path, "trusted.glusterfs.test"); - FREE (priv); + GF_FREE (priv); return; } diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index 6146c370..0295a1f4 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -50,6 +50,8 @@ #include "xlator.h" #include "inode.h" #include "compat.h" +#include "timer.h" +#include "posix-mem-types.h" /** * posix_fd - internal structure common to file and directory fd's -- cgit