diff options
author | Amar Tumballi <amar@gluster.com> | 2009-06-17 20:58:20 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-18 13:08:04 -0700 |
commit | d3e1a3d453c358f2b5a6b86805767c8361fde2ee (patch) | |
tree | 34fe22da1fec71a90decc1305799597425294301 /libglusterfs/src | |
parent | bb451c37bc05c8a33130e6b93020378d742f0ca2 (diff) |
adding an extra xlator option type, GF_OPTION_PERCENT_OR_SIZET.
Originally from Paul Rawson <plrca2@gmail.com>
http://patches.gluster.com/patch/391/ : patch re-submitted with patching guidelines.
with this patch, the xlator volume options get another type which can take
arguments either in 'percent' or in 'bytes', which is useful in many cases.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/xlator.c | 98 | ||||
-rw-r--r-- | libglusterfs/src/xlator.h | 1 |
2 files changed, 96 insertions, 3 deletions
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 1bcf2e73834..6f5da84b4c0 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -385,10 +385,12 @@ _volume_option_value_validate (xlator_t *xl, || ((i < ZR_OPTION_MAX_ARRAY_SIZE) && (!opt->value[i]))) { /* enter here only if - * 1. reached end of opt->value array and haven't validated input + * 1. reached end of opt->value array and haven't + * validated input * OR - * 2. valid input list is less than ZR_OPTION_MAX_ARRAY_SIZE and - * input has not matched all possible input values. + * 2. valid input list is less than + * ZR_OPTION_MAX_ARRAY_SIZE and input has not + * matched all possible input values. */ char given_array[4096] = {0,}; for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && @@ -432,6 +434,96 @@ _volume_option_value_validate (xlator_t *xl, ret = 0; } break; + case GF_OPTION_TYPE_PERCENT_OR_SIZET: + { + uint32_t percent = 0; + uint64_t input_size = 0; + + /* Check if the value is valid percentage */ + if (gf_string2percent (pair->value->data, + &percent) == 0) { + if (percent > 100) { + gf_log (xl->name, GF_LOG_DEBUG, + "value given was greater than 100, " + "assuming this is actually a size"); + if (gf_string2bytesize (pair->value->data, + &input_size) == 0) { + /* Check the range */ + 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); + // It is a size + ret = 0; + goto out; + } + 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); + } + // It is a size + 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); + } + + } + // It is a percent + ret = 0; + goto out; + } else { + if (gf_string2bytesize (pair->value->data, + &input_size) == 0) { + /* Check the range */ + 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); + // It is a size + ret = 0; + goto out; + } + 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); + } + } 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); + } + //It is a size + ret = 0; + goto out; + } + + } + break; case GF_OPTION_TYPE_TIME: { uint32_t input_time = 0; diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 8e067617578..e8fc9d2503b 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -818,6 +818,7 @@ typedef enum { GF_OPTION_TYPE_INT, GF_OPTION_TYPE_SIZET, GF_OPTION_TYPE_PERCENT, + GF_OPTION_TYPE_PERCENT_OR_SIZET, GF_OPTION_TYPE_BOOL, GF_OPTION_TYPE_XLATOR, GF_OPTION_TYPE_PATH, |