gluster-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gluster-devel] [PATCH: glusterfs] allow min-free-disk as option for alu


From: plrca2
Subject: [Gluster-devel] [PATCH: glusterfs] allow min-free-disk as option for alu
Date: Wed, 22 Apr 2009 07:10:51 +0000

>From 2f7f407e8eb4b529e964e1226574caecf4ea5820 Mon Sep 17 00:00:00 2001
From: Paul Rawson <address@hidden>
Date: Fri, 17 Apr 2009 00:29:48 -0700
Subject: [PATCH] Allow alu's min-free-disk to be specified as a percent or bytesize

---
libglusterfs/src/xlator.c | 52 +++++++++++++++
libglusterfs/src/xlator.h | 8 ++-
scheduler/alu/src/alu.c | 151 +++++++++------------------------------------
3 files changed, 86 insertions(+), 125 deletions(-)

diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 6af2c8e..5b5067a 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -431,6 +431,58 @@ _volume_option_value_validate (xlator_t *xl,
ret = 0;
}
break;
+ case GF_OPTION_TYPE_PERCENTORSIZET:
+ {
+ uint32_t percent = 0;
+ uint32_t input_size = 0;
+
+ /* Check if the value is valid percentage */
+ if (gf_string2percent (pair->value->data,
+ &percent) == 0) {
+ if ((percent < 0) || (percent > 100)) {
+ gf_log (xl->name, GF_LOG_ERROR,
+ "'%d' in 'option %s %s' is out of "
+ "range [0 - 100]",
+ percent, pair->key,
+ pair->value->data);
+ }
+ ret = 0;
+ goto out;
+ } else {
+ /* Check the range */
+ if (gf_string2bytesize (pair->value->data,
+ &input_size) == 0) {
+
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (xl->name, GF_LOG_DEBUG,
+ "no range check required for "
+ "'option %s %s'",
+ pair->key, pair->value->data);
+ ret = 0;
+ break;
+ }
+ if ((input_size < opt->min) ||
+ (input_size > opt->max)) {
+ gf_log (xl->name, GF_LOG_ERROR,
+ "'%"PRId64"' in 'option %s %s' is "
+ "out of range [%"PRId64" - %"PRId64"]",
+ input_size, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ ret = 0;
+ goto out;
+ } else {
+ // It's not a percent or size
+ gf_log (xl->name, GF_LOG_ERROR,
+ "invalid number format \"%s\" "
+ "in \"option %s\"",
+ pair->value->data, pair->key);
+
+ }
+ }
+ }
+ break;
case GF_OPTION_TYPE_TIME:
{
uint32_t input_time = 0;
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 654e334..cf8d221 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -72,9 +72,10 @@ struct _loc {

struct xlator_stats {
uint64_t nr_files; /* Number of files open via this xlator */
- uint64_t free_disk; /* Mega bytes */
- uint64_t total_disk_size; /* Mega Bytes */
- uint64_t disk_usage; /* Mega bytes */
+ uint64_t free_disk; /* Bytes or percent */
+ uint64_t total_disk_size; /* Bytes or percent */
+ uint64_t disk_usage; /* Bytes or percent */
+ char disk_unit; /* 'p' or 'b' */
uint64_t disk_speed; /* MHz or Mbps */
uint64_t nr_clients; /* Number of client nodes */
uint64_t write_usage;
@@ -807,6 +808,7 @@ typedef enum {
GF_OPTION_TYPE_INT,
GF_OPTION_TYPE_SIZET,
GF_OPTION_TYPE_PERCENT,
+ GF_OPTION_TYPE_PERCENTORSIZET,
GF_OPTION_TYPE_BOOL,
GF_OPTION_TYPE_XLATOR,
GF_OPTION_TYPE_PATH,
diff --git a/scheduler/alu/src/alu.c b/scheduler/alu/src/alu.c
index 571d06e..8939531 100644
--- a/scheduler/alu/src/alu.c
+++ b/scheduler/alu/src/alu.c
@@ -54,7 +54,11 @@
static int64_t
get_stats_disk_usage (struct xlator_stats *this)
{
- return this->disk_usage;
+ if (this->disk_unit == 'p') {
+ return (this->disk_usage * 100) / this->total_disk_size;
+ } else {
+ return this->disk_usage;
+ }
}

static int64_t
@@ -87,9 +91,13 @@ get_stats_file_usage (struct xlator_stats *this)
static int64_t
get_stats_free_disk (struct xlator_stats *this)
{
- if (this->total_disk_size > 0)
- return (this->free_disk * 100) / this->total_disk_size;
- return 0;
+ if (this->total_disk_size > 0) {
+ if (this->disk_unit == 'p') {
+ return (this->free_disk * 100) / this->total_disk_size;
+ } else {
+ return this->free_disk;
+ }
+ }
}

static int64_t
@@ -154,15 +162,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
dict_get (xl->options,
"scheduler.alu.disk-usage.entry-threshold");
if (entry_fn) {
- if (gf_string2bytesize (entry_fn->data,
- &alu_sched->entry_limit.disk_usage) != 0) {
- gf_log (xl->name, GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "disk-usage.entry-threshold\"",
- entry_fn->data);
- return -1;
- }
+ gf_string2bytesize (entry_fn->data, &alu_sched->entry_limit.disk_usage);
} else {
alu_sched->entry_limit.disk_usage = ALU_DISK_USAGE_ENTRY_THRESHOLD_DEFAULT;
}
@@ -170,14 +170,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
exit_fn = dict_get (xl->options,
"scheduler.alu.disk-usage.exit-threshold");
if (exit_fn) {
- if (gf_string2bytesize (exit_fn->data, &alu_sched->exit_limit.disk_usage) != 0) {
- gf_log (xl->name, GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "disk-usage.exit-threshold\"",
- exit_fn->data);
- return -1;
- }
+ gf_string2bytesize (exit_fn->data, &alu_sched->exit_limit.disk_usage);
} else {
alu_sched->exit_limit.disk_usage = ALU_DISK_USAGE_EXIT_THRESHOLD_DEFAULT;
}
@@ -206,15 +199,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
entry_fn = dict_get (xl->options,
"scheduler.alu.write-usage.entry-threshold");
if (entry_fn) {
- if (gf_string2bytesize (entry_fn->data,
- &alu_sched->entry_limit.write_usage) != 0) {
- gf_log (xl->name, GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of option scheduler.alu."
- "write-usage.entry-threshold",
- entry_fn->data);
- return -1;
- }
+ gf_string2bytesize (entry_fn->data, &alu_sched->entry_limit.write_usage);
} else {
alu_sched->entry_limit.write_usage = ALU_WRITE_USAGE_ENTRY_THRESHOLD_DEFAULT;
}
@@ -222,15 +207,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
exit_fn = dict_get (xl->options,
"scheduler.alu.write-usage.exit-threshold");
if (exit_fn) {
- if (gf_string2bytesize (exit_fn->data,
- &alu_sched->exit_limit.write_usage) != 0) {
- gf_log (xl->name, GF_LOG_ERROR,
- "invalid number format \"%s\""
- " of \"option scheduler.alu."
- "write-usage.exit-threshold\"",
- exit_fn->data);
- return -1;
- }
+ gf_string2bytesize (exit_fn->data, &alu_sched->exit_limit.write_usage);
} else {
alu_sched->exit_limit.write_usage = ALU_WRITE_USAGE_EXIT_THRESHOLD_DEFAULT;
}
@@ -259,16 +236,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
entry_fn = dict_get (xl->options,
"scheduler.alu.read-usage.entry-threshold");
if (entry_fn) {
- if (gf_string2bytesize (entry_fn->data,
- &alu_sched->entry_limit.read_usage) != 0) {
- gf_log (xl->name,
- GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "read-usage.entry-threshold\"",
- entry_fn->data);
- return -1;
- }
+ gf_string2bytesize (entry_fn->data, &alu_sched->entry_limit.read_usage);
} else {
alu_sched->entry_limit.read_usage = ALU_READ_USAGE_ENTRY_THRESHOLD_DEFAULT;
}
@@ -277,16 +245,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
"scheduler.alu.read-usage.exit-threshold");
if (exit_fn)
{
- if (gf_string2bytesize (exit_fn->data,
- &alu_sched->exit_limit.read_usage) != 0)
- {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "read-usage.exit-threshold\"",
- exit_fn->data);
- return -1;
- }
+ gf_string2bytesize (exit_fn->data, &alu_sched->exit_limit.read_usage);
}
else
{
@@ -318,16 +277,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
entry_fn = dict_get (xl->options,
"scheduler.alu.open-files-usage.entry-threshold");
if (entry_fn) {
- if (gf_string2uint64 (entry_fn->data,
- &alu_sched->entry_limit.nr_files) != 0)
- {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "open-files-usage.entry-"
- "threshold\"", entry_fn->data);
- return -1;
- }
+ gf_string2uint64 (entry_fn->data, &alu_sched->entry_limit.nr_files);
}
else
{
@@ -338,16 +288,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)
"scheduler.alu.open-files-usage.exit-threshold");
if (exit_fn)
{
- if (gf_string2uint64 (exit_fn->data,
- &alu_sched->exit_limit.nr_files) != 0)
- {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.alu."
- "open-files-usage.exit-"
- "threshold\"", exit_fn->data);
- return -1;
- }
+ gf_string2uint64 (exit_fn->data, &alu_sched->exit_limit.nr_files);
}
else
{
@@ -443,24 +384,14 @@ alu_init (xlator_t *xl)
_limit_fn->next = tmp_limits;
alu_sched->limits_fn = _limit_fn;

- if (gf_string2percent (limits->data,
- &min_free_disk) != 0) {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" "
- "of \"option scheduler.limits."
- "min-free-disk\"", limits->data);
- return -1;
+ if (gf_string2percent (limits->data, &min_free_disk) == 0) {
+ alu_sched->spec_limit.disk_unit = 'p';
+ } else {
+ alu_sched->spec_limit.disk_unit = 'b';
}
+
alu_sched->spec_limit.free_disk = min_free_disk;

- if (alu_sched->spec_limit.free_disk >= 100) {
- gf_log ("alu", GF_LOG_ERROR,
- "check the \"option scheduler."
- "limits.min-free-disk\", it should "
- "be percentage value");
- return -1;
- }
- alu_sched->spec_limit.total_disk_size = ALU_LIMITS_TOTAL_DISK_SIZE_DEFAULT; /* Its in % */
gf_log ("alu", GF_LOG_DEBUG,
"alu.limit.min-disk-free = %"PRId64"",
_limit_fn->cur_value (&(alu_sched->spec_limit)));
@@ -477,16 +408,7 @@ alu_init (xlator_t *xl)
tmp_limits = alu_sched->limits_fn ;
_limit_fn->next = tmp_limits;
alu_sched->limits_fn = _limit_fn;
- if (gf_string2uint64_base10 (limits->data,
- &alu_sched->spec_limit.nr_files) != 0)
- {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format '%s' of option "
- "scheduler.limits.max-open-files",
- limits->data);
- return -1;
- }
-
+ gf_string2uint64_base10 (limits->data, &alu_sched->spec_limit.nr_files);
gf_log ("alu", GF_LOG_DEBUG,
"alu_init: limit.max-open-files = %"PRId64"",
_limit_fn->cur_value (&(alu_sched->spec_limit)));
@@ -497,14 +419,7 @@ alu_init (xlator_t *xl)
limits = dict_get (xl->options,
"scheduler.refresh-interval");
if (limits) {
- if (gf_string2time (limits->data,
- &alu_sched->refresh_interval) != 0) {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "option scheduler.refresh-interval",
- limits->data);
- return -1;
- }
+ gf_string2time (limits->data, &alu_sched->refresh_interval);
} else {
alu_sched->refresh_interval = ALU_REFRESH_INTERVAL_DEFAULT;
}
@@ -514,15 +429,7 @@ alu_init (xlator_t *xl)
limits = dict_get (xl->options,
"scheduler.alu.stat-refresh.num-file-create");
if (limits) {
- if (gf_string2uint32 (limits->data,
- &alu_sched->refresh_create_count) != 0)
- {
- gf_log ("alu", GF_LOG_ERROR,
- "invalid number format \"%s\" of \"option "
- "alu.stat-refresh.num-file-create\"",
- limits->data);
- return -1;
- }
+ gf_string2uint32 (limits->data, &alu_sched->refresh_create_count);
} else {
alu_sched->refresh_create_count = ALU_REFRESH_CREATE_COUNT_DEFAULT;
}
@@ -983,7 +890,7 @@ struct volume_options options[] = {
},
{ .key = { "scheduler.limits.min-free-disk",
"alu.limits.min-free-disk" },
- .type = GF_OPTION_TYPE_PERCENT
+ .type = GF_OPTION_TYPE_PERCENTORSIZET
},
{ .key = { "scheduler.alu.stat-refresh.num-file-create"
"alu.stat-refresh.num-file-create"},
--
1.6.0.6
reply via email to

[Prev in Thread] Current Thread [Next in Thread]