summaryrefslogtreecommitdiffstats
path: root/scheduler
diff options
context:
space:
mode:
Diffstat (limited to 'scheduler')
-rw-r--r--scheduler/alu/src/alu-mem-types.h35
-rw-r--r--scheduler/alu/src/alu.c64
-rw-r--r--scheduler/nufa/src/nufa-mem-types.h33
-rw-r--r--scheduler/nufa/src/nufa.c54
-rw-r--r--scheduler/random/src/random-mem-types.h32
-rw-r--r--scheduler/random/src/random.c34
-rw-r--r--scheduler/rr/src/rr-mem-types.h32
-rw-r--r--scheduler/rr/src/rr-options.c4
-rw-r--r--scheduler/rr/src/rr.c20
-rw-r--r--scheduler/switch/src/switch-mem-types.h33
-rw-r--r--scheduler/switch/src/switch.c68
11 files changed, 335 insertions, 74 deletions
diff --git a/scheduler/alu/src/alu-mem-types.h b/scheduler/alu/src/alu-mem-types.h
new file mode 100644
index 00000000000..39da342ec6c
--- /dev/null
+++ b/scheduler/alu/src/alu-mem-types.h
@@ -0,0 +1,35 @@
+/*
+ Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef __ALU_MEM_TYPES_H__
+#define __ALU_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_alu_mem_types_ {
+ gf_alu_mt_alu_threshold = gf_common_mt_end + 1,
+ gf_alu_mt_alu_sched,
+ gf_alu_mt_alu_limits,
+ gf_alu_mt_alu_sched_struct,
+ gf_alu_mt_alu_sched_node,
+ gf_alu_mt_end
+};
+#endif
+
diff --git a/scheduler/alu/src/alu.c b/scheduler/alu/src/alu.c
index 8a328dea0b9..f2a0a08f481 100644
--- a/scheduler/alu/src/alu.c
+++ b/scheduler/alu/src/alu.c
@@ -32,6 +32,7 @@
#include <stdint.h>
#include "stack.h"
#include "alu.h"
+#include "alu-mem-types.h"
#define ALU_DISK_USAGE_ENTRY_THRESHOLD_DEFAULT (1 * GF_UNIT_GB)
#define ALU_DISK_USAGE_EXIT_THRESHOLD_DEFAULT (512 * GF_UNIT_MB)
@@ -146,7 +147,9 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
if (strcmp (order_str, "disk-usage") == 0) {
/* Disk usage */
_threshold_fn =
- CALLOC (1, sizeof (struct alu_threshold));
+ GF_CALLOC (1,
+ sizeof (struct alu_threshold),
+ gf_alu_mt_alu_threshold);
ERR_ABORT (_threshold_fn);
_threshold_fn->diff_value = get_max_diff_disk_usage;
_threshold_fn->sched_value = get_stats_disk_usage;
@@ -199,7 +202,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
} else if (strcmp (order_str, "write-usage") == 0) {
/* Handle "write-usage" */
- _threshold_fn = CALLOC (1, sizeof (struct alu_threshold));
+ _threshold_fn = GF_CALLOC (1, sizeof (struct alu_threshold), gf_alu_mt_alu_threshold);
ERR_ABORT (_threshold_fn);
_threshold_fn->diff_value = get_max_diff_write_usage;
_threshold_fn->sched_value = get_stats_write_usage;
@@ -252,7 +255,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
} else if (strcmp (order_str, "read-usage") == 0) {
/* Read usage */
- _threshold_fn = CALLOC (1, sizeof (struct alu_threshold));
+ _threshold_fn = GF_CALLOC (1, sizeof (struct alu_threshold), gf_alu_mt_alu_threshold);
ERR_ABORT (_threshold_fn);
_threshold_fn->diff_value = get_max_diff_read_usage;
_threshold_fn->sched_value = get_stats_read_usage;
@@ -311,7 +314,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
} else if (strcmp (order_str, "open-files-usage") == 0) {
/* Open files counter */
- _threshold_fn = CALLOC (1, sizeof (struct alu_threshold));
+ _threshold_fn = GF_CALLOC (1, sizeof (struct alu_threshold), gf_alu_mt_alu_threshold);
ERR_ABORT (_threshold_fn);
_threshold_fn->diff_value = get_max_diff_file_usage;
_threshold_fn->sched_value = get_stats_file_usage;
@@ -372,7 +375,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
} else if (strcmp (order_str, "disk-speed-usage") == 0) {
/* Disk speed */
- _threshold_fn = CALLOC (1, sizeof (struct alu_threshold));
+ _threshold_fn = GF_CALLOC (1, sizeof (struct alu_threshold), gf_alu_mt_alu_threshold);
ERR_ABORT (_threshold_fn);
_threshold_fn->diff_value = get_max_diff_disk_speed;
_threshold_fn->sched_value = get_stats_disk_speed;
@@ -423,7 +426,8 @@ alu_init (xlator_t *xl)
uint32_t min_free_disk = 0;
data_t *limits = NULL;
- alu_sched = CALLOC (1, sizeof (struct alu_sched));
+ alu_sched = GF_CALLOC (1, sizeof (struct alu_sched),
+ gf_alu_mt_alu_sched);
ERR_ABORT (alu_sched);
{
@@ -435,7 +439,8 @@ alu_init (xlator_t *xl)
limits = dict_get (xl->options,
"scheduler.limits.min-free-disk");
if (limits) {
- _limit_fn = CALLOC (1, sizeof (struct alu_limits));
+ _limit_fn = GF_CALLOC (1, sizeof (struct alu_limits),
+ gf_alu_mt_alu_limits);
ERR_ABORT (_limit_fn);
_limit_fn->min_value = get_stats_free_disk;
_limit_fn->cur_value = get_stats_free_disk;
@@ -470,7 +475,8 @@ alu_init (xlator_t *xl)
"scheduler.limits.max-open-files");
if (limits) {
// Update alu_sched->priority properly
- _limit_fn = CALLOC (1, sizeof (struct alu_limits));
+ _limit_fn = GF_CALLOC (1, sizeof (struct alu_limits),
+ gf_alu_mt_alu_limits);
ERR_ABORT (_limit_fn);
_limit_fn->max_value = get_stats_file_usage;
_limit_fn->cur_value = get_stats_file_usage;
@@ -539,7 +545,7 @@ alu_init (xlator_t *xl)
trav_xl = trav_xl->next;
}
alu_sched->child_count = index;
- sched_array = CALLOC (index, sizeof (struct alu_sched_struct));
+ sched_array = GF_CALLOC (index, sizeof (struct alu_sched_struct), gf_alu_mt_alu_sched_struct);
ERR_ABORT (sched_array);
trav_xl = xl->children;
index = 0;
@@ -556,7 +562,7 @@ alu_init (xlator_t *xl)
if (data) {
char *child = NULL;
char *tmp = NULL;
- char *childs_data = strdup (data->data);
+ char *childs_data = gf_strdup (data->data);
child = strtok_r (childs_data, ",", &tmp);
while (child) {
@@ -604,18 +610,18 @@ alu_fini (xlator_t *xl)
struct alu_threshold *threshold = alu_sched->threshold_fn;
void *tmp = NULL;
pthread_mutex_destroy (&alu_sched->alu_mutex);
- free (alu_sched->array);
+ GF_FREE (alu_sched->array);
while (limit) {
tmp = limit;
limit = limit->next;
- free (tmp);
+ GF_FREE (tmp);
}
while (threshold) {
tmp = threshold;
threshold = threshold->next;
- free (tmp);
+ GF_FREE (tmp);
}
- free (alu_sched);
+ GF_FREE (alu_sched);
}
static int32_t
@@ -785,7 +791,7 @@ alu_scheduler (xlator_t *xl, const void *path)
continue;
}
}
- tmp_sched_node = CALLOC (1, sizeof (struct alu_sched_node));
+ tmp_sched_node = GF_CALLOC (1, sizeof (struct alu_sched_node), gf_alu_mt_alu_sched_node);
ERR_ABORT (tmp_sched_node);
tmp_sched_node->index = idx;
if (!alu_sched->sched_node) {
@@ -808,7 +814,7 @@ alu_scheduler (xlator_t *xl, const void *path)
if (alu_sched->array[sched_index].eligible)
break;
alu_sched->sched_node = trav_sched_node->next;
- free (trav_sched_node);
+ GF_FREE (trav_sched_node);
alu_sched->sched_nodes_pending--;
}
if (alu_sched->sched_nodes_pending) {
@@ -823,7 +829,7 @@ alu_scheduler (xlator_t *xl, const void *path)
/* Free the allocated info for the node :) */
pthread_mutex_lock (&alu_sched->alu_mutex);
alu_sched->sched_node = trav_sched_node->next;
- free (trav_sched_node);
+ GF_FREE (trav_sched_node);
trav_sched_node = alu_sched->sched_node;
alu_sched->sched_nodes_pending--;
pthread_mutex_unlock (&alu_sched->alu_mutex);
@@ -832,7 +838,7 @@ alu_scheduler (xlator_t *xl, const void *path)
/* if there is no exit value, then exit after scheduling once */
pthread_mutex_lock (&alu_sched->alu_mutex);
alu_sched->sched_node = trav_sched_node->next;
- free (trav_sched_node);
+ GF_FREE (trav_sched_node);
trav_sched_node = alu_sched->sched_node;
alu_sched->sched_nodes_pending--;
pthread_mutex_unlock (&alu_sched->alu_mutex);
@@ -928,12 +934,32 @@ alu_notify (xlator_t *xl, int32_t event, void *data)
}
+int32_t
+alu_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_alu_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
struct sched_ops sched = {
.init = alu_init,
.fini = alu_fini,
.update = alu_update,
.schedule = alu_scheduler,
- .notify = alu_notify
+ .notify = alu_notify,
+ .mem_acct_init = alu_mem_acct_init,
};
struct volume_options options[] = {
diff --git a/scheduler/nufa/src/nufa-mem-types.h b/scheduler/nufa/src/nufa-mem-types.h
new file mode 100644
index 00000000000..d8ce993daf9
--- /dev/null
+++ b/scheduler/nufa/src/nufa-mem-types.h
@@ -0,0 +1,33 @@
+/*
+ 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 __NUFA_MEM_TYPES_H__
+#define __NUFA_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_locks_mem_types_ {
+ gf_nufa_mt_nufa_struct = gf_common_mt_end + 1,
+ gf_nufa_mt_nufa_sched_struct,
+ gf_nufa_mt_int32_t,
+ gf_nufa_mt_end
+};
+#endif
+
diff --git a/scheduler/nufa/src/nufa.c b/scheduler/nufa/src/nufa.c
index 92b70ca7580..f089782cd8c 100644
--- a/scheduler/nufa/src/nufa.c
+++ b/scheduler/nufa/src/nufa.c
@@ -26,6 +26,7 @@
#include "scheduler.h"
#include "common-utils.h"
+#include "nufa-mem-types.h"
struct nufa_sched_struct {
xlator_t *xl;
@@ -63,7 +64,8 @@ nufa_init (xlator_t *xl)
xlator_list_t *trav_xl = xl->children;
struct nufa_struct *nufa_buf = NULL;
- nufa_buf = CALLOC (1, sizeof (struct nufa_struct));
+ nufa_buf = GF_CALLOC (1, sizeof (struct nufa_struct),
+ gf_nufa_mt_nufa_struct);
ERR_ABORT (nufa_buf);
data = dict_get (xl->options, "scheduler.limits.min-free-disk");
@@ -112,9 +114,11 @@ nufa_init (xlator_t *xl)
}
nufa_buf->child_count = index;
nufa_buf->sched_index = 0;
- nufa_buf->array = CALLOC (index, sizeof (struct nufa_sched_struct));
+ nufa_buf->array = GF_CALLOC (index, sizeof (struct nufa_sched_struct),
+ gf_nufa_mt_nufa_sched_struct);
ERR_ABORT (nufa_buf->array);
- nufa_buf->local_array = CALLOC (index, sizeof (int32_t));
+ nufa_buf->local_array = GF_CALLOC (index, sizeof (int32_t),
+ gf_nufa_mt_int32_t);
ERR_ABORT (nufa_buf->array);
trav_xl = xl->children;
@@ -123,9 +127,9 @@ nufa_init (xlator_t *xl)
/* Error */
gf_log ("nufa", GF_LOG_ERROR,
"No 'local-volume-name' option given in volume file");
- FREE (nufa_buf->array);
- FREE (nufa_buf->local_array);
- FREE (nufa_buf);
+ GF_FREE (nufa_buf->array);
+ GF_FREE (nufa_buf->local_array);
+ GF_FREE (nufa_buf);
return -1;
}
@@ -147,7 +151,7 @@ nufa_init (xlator_t *xl)
int32_t array_index = 0;
char *child = NULL;
char *tmp = NULL;
- char *childs_data = strdup (local_name->data);
+ char *childs_data = gf_strdup (local_name->data);
child = strtok_r (childs_data, ",", &tmp);
while (child) {
@@ -168,9 +172,9 @@ nufa_init (xlator_t *xl)
gf_log ("nufa", GF_LOG_ERROR,
"option 'scheduler.local-volume-name' "
"%s is wrong", child);
- FREE (nufa_buf->array);
- FREE (nufa_buf->local_array);
- FREE (nufa_buf);
+ GF_FREE (nufa_buf->array);
+ GF_FREE (nufa_buf->local_array);
+ GF_FREE (nufa_buf);
return -1;
} else {
nufa_buf->local_array[array_index++] = index;
@@ -178,7 +182,7 @@ nufa_init (xlator_t *xl)
}
child = strtok_r (NULL, ",", &tmp);
}
- free (childs_data);
+ GF_FREE (childs_data);
}
LOCK_INIT (&nufa_buf->nufa_lock);
@@ -193,9 +197,9 @@ nufa_fini (xlator_t *xl)
(struct nufa_struct *)*((long *)xl->private);
LOCK_DESTROY (&nufa_buf->nufa_lock);
- FREE (nufa_buf->local_array);
- FREE (nufa_buf->array);
- FREE (nufa_buf);
+ GF_FREE (nufa_buf->local_array);
+ GF_FREE (nufa_buf->array);
+ GF_FREE (nufa_buf);
}
static int32_t
@@ -379,12 +383,32 @@ nufa_notify (xlator_t *xl, int32_t event, void *data)
}
+int32_t
+nufa_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_nufa_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
struct sched_ops sched = {
.init = nufa_init,
.fini = nufa_fini,
.update = nufa_update,
.schedule = nufa_schedule,
- .notify = nufa_notify
+ .notify = nufa_notify,
+ .mem_acct_init = nufa_mem_acct_init,
};
struct volume_options options[] = {
diff --git a/scheduler/random/src/random-mem-types.h b/scheduler/random/src/random-mem-types.h
new file mode 100644
index 00000000000..612e53dbdb6
--- /dev/null
+++ b/scheduler/random/src/random-mem-types.h
@@ -0,0 +1,32 @@
+/*
+ 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 __RANDOM_MEM_TYPES_H__
+#define __RANDOM_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_random_mem_types_ {
+ gf_random_mt_random_struct = gf_common_mt_end + 1,
+ gf_random_mt_random_sched_struct,
+ gf_random_mt_end
+};
+#endif
+
diff --git a/scheduler/random/src/random.c b/scheduler/random/src/random.c
index 07ed45e7318..e6bd34c3d7e 100644
--- a/scheduler/random/src/random.c
+++ b/scheduler/random/src/random.c
@@ -26,6 +26,7 @@
#endif
#include "random.h"
+#include "random-mem-types.h"
#define RANDOM_LIMITS_MIN_FREE_DISK_DEFAULT 15
#define RANDOM_REFRESH_INTERVAL_DEFAULT 10
@@ -39,7 +40,8 @@ random_init (xlator_t *xl)
data_t *limit = NULL;
int32_t index = 0;
- random_buf = CALLOC (1, sizeof (struct random_struct));
+ random_buf = GF_CALLOC (1, sizeof (struct random_struct),
+ gf_random_mt_random_struct);
ERR_ABORT (random_buf);
/* Set the seed for the 'random' function */
@@ -89,8 +91,9 @@ random_init (xlator_t *xl)
trav_xl = trav_xl->next;
}
random_buf->child_count = index;
- random_buf->array = CALLOC (index,
- sizeof (struct random_sched_struct));
+ random_buf->array = GF_CALLOC (index,
+ sizeof (struct random_sched_struct),
+ gf_random_mt_random_sched_struct);
ERR_ABORT (random_buf->array);
trav_xl = xl->children;
index = 0;
@@ -115,8 +118,8 @@ random_fini (xlator_t *xl)
random_buf = (struct random_struct *)*((long *)xl->private);
pthread_mutex_destroy (&random_buf->random_mutex);
- free (random_buf->array);
- free (random_buf);
+ GF_FREE (random_buf->array);
+ GF_FREE (random_buf);
}
@@ -222,6 +225,24 @@ random_schedule (xlator_t *xl, const void *path)
return random_buf->array[rand].xl;
}
+int32_t
+random_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_random_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ " failed");
+ return ret;
+ }
+
+ return ret;
+}
/**
* notify
@@ -267,7 +288,8 @@ struct sched_ops sched = {
.fini = random_fini,
.update = random_update,
.schedule = random_schedule,
- .notify = random_notify
+ .notify = random_notify,
+ .mem_acct_init = random_mem_acct_init,
};
struct volume_options options[] = {
diff --git a/scheduler/rr/src/rr-mem-types.h b/scheduler/rr/src/rr-mem-types.h
new file mode 100644
index 00000000000..4b283ca841d
--- /dev/null
+++ b/scheduler/rr/src/rr-mem-types.h
@@ -0,0 +1,32 @@
+/*
+ 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 __RR_MEM_TYPES_H__
+#define __RR_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_rr_mem_types_ {
+ gf_rr_mt_rr_t = gf_common_mt_end + 1,
+ gf_rr_mt_rr_subvolume_t,
+ gf_rr_mt_end
+};
+#endif
+
diff --git a/scheduler/rr/src/rr-options.c b/scheduler/rr/src/rr-options.c
index b76c9fcccfc..b454ccd7c22 100644
--- a/scheduler/rr/src/rr-options.c
+++ b/scheduler/rr/src/rr-options.c
@@ -143,9 +143,9 @@ _rr_options_read_only_subvolumes_validate (const char *value_string,
free_exit:
for (i = 0; i < vcount; i++)
{
- free (vlist[i]);
+ GF_FREE (vlist[i]);
}
- free (vlist);
+ GF_FREE (vlist);
return -1;
}
diff --git a/scheduler/rr/src/rr.c b/scheduler/rr/src/rr.c
index d47f87278bc..83a0f267fd2 100644
--- a/scheduler/rr/src/rr.c
+++ b/scheduler/rr/src/rr.c
@@ -31,6 +31,7 @@
#include "rr-options.h"
#include "rr.h"
+#include "rr-mem-types.h"
#define RR_MIN_FREE_DISK_NOT_REACHED 0
#define RR_MIN_FREE_DISK_REACHED 1
@@ -58,14 +59,14 @@ _cleanup_rr (rr_t *rr)
{
for (i = 0; i < rr->options.read_only_subvolume_count; i++)
{
- free (rr->options.read_only_subvolume_list[i]);
+ GF_FREE (rr->options.read_only_subvolume_list[i]);
}
- free (rr->options.read_only_subvolume_list);
+ GF_FREE (rr->options.read_only_subvolume_list);
}
- free (rr->subvolume_list);
+ GF_FREE (rr->subvolume_list);
- free (rr);
+ GF_FREE (rr);
return 0;
}
@@ -95,14 +96,14 @@ rr_init (xlator_t *this_xl)
return -1;
}
- if ((rr = CALLOC (1, sizeof (rr_t))) == NULL)
+ if ((rr = GF_CALLOC (1, sizeof (rr_t), gf_rr_mt_rr_t)) == NULL)
{
return -1;
}
if (rr_options_validate (options, &rr->options) != 0)
{
- free (rr);
+ GF_FREE (rr);
return -1;
}
@@ -147,8 +148,9 @@ rr_init (xlator_t *this_xl)
return -1;
}
- if ((rr->subvolume_list = CALLOC (rr->subvolume_count,
- sizeof (rr_subvolume_t))) == NULL)
+ if ((rr->subvolume_list = GF_CALLOC (rr->subvolume_count,
+ sizeof (rr_subvolume_t),
+ gf_rr_mt_rr_subvolume_t)) == NULL)
{
_cleanup_rr (rr);
return -1;
@@ -476,7 +478,7 @@ rr_notify (xlator_t *this_xl, int32_t event, void *data)
if (xattr)
dict_ref (xattr);
- loc.path = strdup ("/");
+ loc.path = gf_strdup ("/");
for (trav = this_xl->parents->xlator; trav; trav = trav->parents->xlator) {
if (trav->itable) {
loc.inode = trav->itable->root;
diff --git a/scheduler/switch/src/switch-mem-types.h b/scheduler/switch/src/switch-mem-types.h
new file mode 100644
index 00000000000..07773da4e2f
--- /dev/null
+++ b/scheduler/switch/src/switch-mem-types.h
@@ -0,0 +1,33 @@
+/*
+ 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 __SWITCH_MEM_TYPES_H__
+#define __SWITCH_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_switch_mem_types_ {
+ gf_switch_mt_switch_struct = gf_common_mt_end + 1,
+ gf_switch_mt_switch_sched_struct,
+ gf_switch_mt_switch_sched_array,
+ gf_switch_mt_end
+};
+#endif
+
diff --git a/scheduler/switch/src/switch.c b/scheduler/switch/src/switch.c
index 8089f9376fa..5a5d20f8d50 100644
--- a/scheduler/switch/src/switch.c
+++ b/scheduler/switch/src/switch.c
@@ -28,6 +28,7 @@
#include "xlator.h"
#include "scheduler.h"
+#include "switch-mem-types.h"
struct switch_sched_array {
xlator_t *xl;
@@ -58,20 +59,20 @@ static xlator_t *
switch_get_matching_xl (const char *path, struct switch_sched_struct *cond)
{
struct switch_sched_struct *trav = cond;
- char *pathname = strdup (path);
+ char *pathname = gf_strdup (path);
int index = 0;
while (trav) {
if (fnmatch (trav->path_pattern,
pathname, FNM_NOESCAPE) == 0) {
- free (pathname);
+ GF_FREE (pathname);
trav->node_index %= trav->num_child;
index = (trav->node_index++) % trav->num_child;
return trav->array[index].xl;
}
trav = trav->next;
}
- free (pathname);
+ GF_FREE (pathname);
return NULL;
}
@@ -107,7 +108,8 @@ switch_init (xlator_t *xl)
xlator_list_t *trav_xl = xl->children;
struct switch_struct *switch_buf = NULL;
- switch_buf = CALLOC (1, sizeof (struct switch_struct));
+ switch_buf = GF_CALLOC (1, sizeof (struct switch_struct),
+ gf_switch_mt_switch_struct);
ERR_ABORT (switch_buf);
while (trav_xl) {
@@ -115,8 +117,9 @@ switch_init (xlator_t *xl)
trav_xl = trav_xl->next;
}
switch_buf->child_count = index;
- switch_buf->array = CALLOC (index + 1,
- sizeof (struct switch_sched_struct));
+ switch_buf->array = GF_CALLOC (index + 1,
+ sizeof (struct switch_sched_struct),
+ gf_switch_mt_switch_sched_struct);
ERR_ABORT (switch_buf->array);
trav_xl = xl->children;
index = 0;
@@ -130,7 +133,7 @@ switch_init (xlator_t *xl)
data = dict_get (xl->options, "scheduler.read-only-subvolumes");
if (data) {
- childs_data = strdup (data->data);
+ childs_data = gf_strdup (data->data);
child = strtok_r (childs_data, ",", &tmp);
while (child) {
for (index = 1;
@@ -148,7 +151,7 @@ switch_init (xlator_t *xl)
}
child = strtok_r (NULL, ",", &tmp);
}
- free (childs_data);
+ GF_FREE (childs_data);
}
data = dict_get (xl->options, "scheduler.local-volume-name");
@@ -176,10 +179,9 @@ switch_init (xlator_t *xl)
"option block-size *avi:10MB" etc */
switch_str = strtok_r (data->data, ";", &tmp_str);
while (switch_str) {
- dup_str = strdup (switch_str);
+ dup_str = gf_strdup (switch_str);
switch_opt =
- CALLOC (1,
- sizeof (struct switch_sched_struct));
+ GF_CALLOC (1, sizeof (struct switch_sched_struct), gf_switch_mt_switch_sched_struct);
ERR_ABORT (switch_opt);
/* Link it to the main structure */
@@ -201,7 +203,7 @@ switch_init (xlator_t *xl)
"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,
@@ -212,7 +214,7 @@ switch_init (xlator_t *xl)
char *dup_childs = NULL;
/* TODO: get the list of child nodes for
the given pattern */
- dup_childs = strdup (childs);
+ dup_childs = gf_strdup (childs);
child = strtok_r (dup_childs, ",", &tmp);
while (child) {
if (gf_unify_valid_child (child, xl)) {
@@ -229,11 +231,11 @@ switch_init (xlator_t *xl)
return -1;
}
}
- 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));
+ GF_CALLOC (1, idx * sizeof (struct switch_sched_array), gf_switch_mt_switch_sched_array);
ERR_ABORT (switch_opt->array);
idx = 0;
child = strtok_r (childs, ",", &tmp);
@@ -267,11 +269,11 @@ switch_init (xlator_t *xl)
gf_log ("switch", GF_LOG_ERROR,
"Check \"scheduler.switch.case\" "
"option in unify volume. Exiting");
- free (switch_buf->array);
- free (switch_buf);
+ GF_FREE (switch_buf->array);
+ GF_FREE (switch_buf);
return -1;
}
- free (dup_str);
+ GF_FREE (dup_str);
switch_str = strtok_r (NULL, ";", &tmp_str);
}
}
@@ -293,7 +295,7 @@ switch_init (xlator_t *xl)
"No nodes left for pattern '*'. Exiting.");
return -1;
}
- switch_opt = CALLOC (1, sizeof (struct switch_sched_struct));
+ switch_opt = GF_CALLOC (1, sizeof (struct switch_sched_struct), gf_switch_mt_switch_sched_struct);
ERR_ABORT (switch_opt);
if (switch_buf->cond) {
/* there are already few entries */
@@ -309,7 +311,7 @@ switch_init (xlator_t *xl)
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);
ERR_ABORT (switch_opt->array);
flag = 0;
for (index=0; index < switch_buf->child_count; index++) {
@@ -343,8 +345,8 @@ switch_fini (xlator_t *xl)
switch_buf = (struct switch_struct *)*((long *)xl->private);
pthread_mutex_destroy (&switch_buf->switch_mutex);
- free (switch_buf->array);
- free (switch_buf);
+ GF_FREE (switch_buf->array);
+ GF_FREE (switch_buf);
}
static xlator_t *
@@ -403,13 +405,33 @@ switch_update (xlator_t *xl)
{
return;
}
+
+int32_t
+switch_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_switch_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ " failed");
+ return ret;
+ }
+
+ return ret;
+}
struct sched_ops sched = {
.init = switch_init,
.fini = switch_fini,
.update = switch_update,
.schedule = switch_schedule,
- .notify = switch_notify
+ .notify = switch_notify,
+ .mem_acct_init = switch_mem_acct_init,
};
struct volume_options options[] = {