summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/options.c
diff options
context:
space:
mode:
authorGauravKumarGarg <ggarg@redhat.com>2014-11-12 17:41:33 +0530
committerVijay Bellur <vbellur@redhat.com>2015-02-04 22:02:42 -0800
commite44d4e135747b04a5e2b7cfac21f9a3343e071db (patch)
treee514e5f6f0bd2752c2d0c0c564a0ae12dbb175f6 /libglusterfs/src/options.c
parent0b198a113e254f6a2702a87a45e823cea964ab11 (diff)
DHT: cluster.min-free-disk option should validate correctly
PROBLEM: Previously gluster accepting input value as a percentage which is out of range [0-100] and accepting input value as a size (unit is byte) which is fractional for option cluster.min-free-disk. FIX: Now with this change it will refer to correct validation function and it will accept value that is in range [0-100] for input value as a percentage and unsigned integer value for input as a size (unit in byte) for option cluster.min-free-disk. Change-Id: Iee1962a100542e146276cfc8a4068abddee2bf2d BUG: 1163108 Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com> Reviewed-on: http://review.gluster.org/9104 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-by: Raghavendra G <rgowdapp@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src/options.c')
-rw-r--r--libglusterfs/src/options.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index 9edb7c03df2..44f74a498c5 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -367,20 +367,58 @@ out:
}
static int
+xlator_option_validate_fractional_value (const char *value)
+{
+ const char *s = NULL;
+ int ret = 0;
+
+ s = strchr (value, '.');
+ if (s) {
+ for (s = s+1; *s != '\0'; s++) {
+ if (*s != '0') {
+ return -1;
+ }
+ }
+ }
+
+ return ret;
+}
+
+static int
xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,
const char *value,
volume_option_t *opt, char **op_errstr)
{
- int ret = -1;
- char errstr[256];
- uint64_t size = 0;
+ int ret = -1;
+ char errstr[256];
+ double size = 0;
gf_boolean_t is_percent = _gf_false;
if (gf_string2percent_or_bytesize (value, &size, &is_percent) == 0) {
if (is_percent) {
+ if ((size < 0.0) || (size > 100.0)) {
+ snprintf (errstr, sizeof (errstr),
+ "'%lf' in 'option %s %s' is out"
+ " of range [0 - 100]", size, key,
+ value);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ goto out;
+ }
ret = 0;
goto out;
}
+
+ /*Input value of size(in byte) should not be fractional*/
+ ret = xlator_option_validate_fractional_value (value);
+ if (ret) {
+ snprintf (errstr, sizeof (errstr), "'%lf' in 'option %s"
+ " %s' should not be fractional value. Use "
+ "valid unsigned integer value.", size, key,
+ value);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ goto out;
+ }
+
/* Check the range */
if ((opt->min == 0) && (opt->max == 0)) {
gf_log (xl->name, GF_LOG_TRACE,
@@ -392,7 +430,7 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,
}
if ((size < opt->min) || (size > opt->max)) {
snprintf (errstr, 256,
- "'%"PRId64"' in 'option %s %s'"
+ "'%lf' in 'option %s %s'"
" is out of range [%.0f - %.0f]",
size, key, value, opt->min, opt->max);
gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);