diff options
author | Vijay Bellur <vijay@gluster.com> | 2010-04-22 13:33:09 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-04-23 06:32:52 -0700 |
commit | 582de0677da4be19fc6f873625c58c45d069ab1c (patch) | |
tree | f10cb3e26e1f92f6ea91034e6f7bb925790dd9bc /xlators/cluster/afr/src | |
parent | 72baa17282f5cf749fa743fd601c7b728ece4fa2 (diff) |
Memory accounting changes
Memory accounting Changes. Thanks to Vinayak Hegde and Csaba Henk for their
contributions.
Signed-off-by: Vijay Bellur <vijay@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 329 (Replacing memory allocation functions with mem-type functions)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=329
Diffstat (limited to 'xlators/cluster/afr/src')
-rw-r--r-- | xlators/cluster/afr/src/afr-dir-read.c | 19 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-dir-write.c | 8 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-read.c | 6 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-write.c | 2 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-mem-types.h | 46 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-algorithm.c | 35 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-common.c | 67 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-data.c | 16 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-entry.c | 22 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-metadata.c | 5 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.c | 137 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.h | 52 |
12 files changed, 268 insertions, 147 deletions
diff --git a/xlators/cluster/afr/src/afr-dir-read.c b/xlators/cluster/afr/src/afr-dir-read.c index 501cc3e8c58..0f9bdf59eae 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 9d7e74e7871..439e8d8c765 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 9ce1036755d..b1bbac10bc2 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 e28fe5f89ac..37909181e21 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 00000000000..27117c1848c --- /dev/null +++ b/xlators/cluster/afr/src/afr-mem-types.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com> + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + <http://www.gnu.org/licenses/>. +*/ + + +#ifndef __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 f840c1bbe25..ef9d4026e0d 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 5115a7306ee..30e1708cc1f 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 2d74ed1e98d..e29c1deff4b 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 4336c7a61f8..dcb8d0d71df 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 57408cfa68c..4501595b7a4 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 4e266113119..5072869448e 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 a6ca1c2be9d..0f7d8bbae13 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; } |