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/features/filter/src/filter-mem-types.h | 30 ++++++++++++++++ xlators/features/filter/src/filter.c | 48 ++++++++++++++++++-------- 2 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 xlators/features/filter/src/filter-mem-types.h (limited to 'xlators/features/filter') 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 000000000..cca354438 --- /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 0f5e67fb0..a0469bf6e 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; } -- cgit