summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/options.c
diff options
context:
space:
mode:
authorHarshavardhana <fharshav@redhat.com>2012-02-21 10:45:32 -0800
committerVijay Bellur <vijay@gluster.com>2012-02-21 22:23:09 -0800
commit2d470cd910b49976befea664ae5cc7ea6aa10020 (patch)
tree227857d16bd8a235de00bdd3b8afddd9413ab869 /libglusterfs/src/options.c
parent311de6f96c4fabf30f734e62996ec18817447e2f (diff)
libglusterfs/options: Cleanup xlator percent_sizet code.
Change-Id: I1a39252d6c26f7e30b77ef682b8b3cdcde8a4a51 BUG: 769691 Signed-off-by: Harshavardhana <fharshav@redhat.com> Reviewed-on: http://review.gluster.com/2619 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src/options.c')
-rw-r--r--libglusterfs/src/options.c118
1 files changed, 36 insertions, 82 deletions
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index b8d3b6ae5a8..39844461a65 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -319,8 +319,6 @@ out:
return ret;
}
-
-/* TODO: clean this up */
static int
xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,
const char *value,
@@ -328,88 +326,44 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,
{
int ret = -1;
char errstr[256];
- uint32_t percent = 0;
uint64_t size = 0;
+ gf_boolean_t is_percent = _gf_false;
+
+ if (gf_string2percent_or_bytesize (value, &size, &is_percent) == 0) {
+ if (is_percent) {
+ ret = 0;
+ goto out;
+ }
+ /* 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'",
+ key, value);
+ ret = 0;
+ goto out;
+ }
+ if ((size < opt->min) || (size > opt->max)) {
+ snprintf (errstr, 256,
+ "'%"PRId64"' in 'option %s %s'"
+ " is out of range [%"PRId64" -"
+ " %"PRId64"]",
+ size, key, value, opt->min, opt->max);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ goto out;
+ }
+ ret = 0;
+ goto out;
+ }
+
+ /* If control reaches here, invalid argument */
+
+ snprintf (errstr, 256,
+ "invalid number format \"%s\" in \"option %s\"",
+ value, key);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
- /* Check if the value is valid percentage */
- if (gf_string2percent (value, &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 (value, &size) == 0) {
- /* Check the range */
- if ((opt->min == 0) && (opt->max == 0)) {
- gf_log (xl->name, GF_LOG_DEBUG,
- "no range check rquired for "
- "'option %s %s'",
- key, value);
- // It is a size
- ret = 0;
- goto out;
- }
- if ((size < opt->min) || (size > opt->max)) {
- snprintf (errstr, 256,
- "'%"PRId64"' in 'option %s %s' "
- "is out of range [%"PRId64" - "
- "%"PRId64"]",
- size, key, value,
- opt->min, opt->max);
- gf_log (xl->name, GF_LOG_ERROR, "%s",
- errstr);
- goto out;
- }
- // It is a size
- ret = 0;
- goto out;
- } else {
- // It's not a percent or size
- snprintf (errstr, 256,
- "invalid number format \"%s\" "
- "in \"option %s\"",
- value, key);
- gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
- goto out;
- }
- }
- // It is a percent
- ret = 0;
- goto out;
- } else {
- if (gf_string2bytesize (value, &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'",
- key, value);
- // It is a size
- ret = 0;
- goto out;
- }
- if ((size < opt->min) || (size > opt->max)) {
- snprintf (errstr, 256,
- "'%"PRId64"' in 'option %s %s'"
- " is out of range [%"PRId64" -"
- " %"PRId64"]",
- size, key, value, opt->min, opt->max);
- gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
- goto out;
- }
- } else {
- // It's not a percent or size
- snprintf (errstr, 256,
- "invalid number format \"%s\" in \"option %s\"",
- value, key);
- gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
- goto out;
- }
- //It is a size
- ret = 0;
- goto out;
- }
- ret = 0;
out:
if (ret && op_errstr)
*op_errstr = gf_strdup (errstr);
@@ -425,7 +379,7 @@ xlator_option_validate_time (xlator_t *xl, const char *key, const char *value,
char errstr[256];
uint32_t input_time = 0;
- /* Check if the value is valid percentage */
+ /* Check if the value is valid time */
if (gf_string2time (value, &input_time) != 0) {
snprintf (errstr, 256,
"invalid time format \"%s\" in "