summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/options.c
diff options
context:
space:
mode:
authorKaushal M <kaushal@redhat.com>2012-04-04 12:00:30 +0530
committerAnand Avati <avati@redhat.com>2012-06-07 11:42:10 -0700
commit81e7464a54165b5d8b40847355d3bb6fe7b6e9df (patch)
tree990c4864efad87fefa6f24fb7a876c28f26c4238 /libglusterfs/src/options.c
parent86ff555eaaefb616b3dde5924a40271d99314861 (diff)
libglusterfs : Fix validation for integer volume options.
Integer volume options which specified only the min value as 0, would not be validated during "volume set". The range check for an option happened only if both min and max were not 0. In the above case, even though a minium was specified, the range check did not happen as both min and max were 0. To allow forced validation in such cases, a new member, "validate", has been added to volume_options_t. This member takes the values GF_OPT_VALIDATE_BOTH, GF_OPT_VALIDATE_MIN and GF_OPT_VALIDATE_MAX (GF_OPT_VALIDATE_BOTH is the default). Change-Id: I351de0eedb6028120e5c0b073ee5d9c141dee717 BUG: 809847 Signed-off-by: Kaushal M <kaushal@redhat.com> Reviewed-on: http://review.gluster.com/3084 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src/options.c')
-rw-r--r--libglusterfs/src/options.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index 6ec1478cee3..e5025e45ef3 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -71,7 +71,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,
goto out;
}
- if ((opt->min == 0) && (opt->max == 0)) {
+ if ((opt->min == 0) && (opt->max == 0) &&
+ (opt->validate == GF_OPT_VALIDATE_BOTH)) {
gf_log (xl->name, GF_LOG_TRACE,
"no range check required for 'option %s %s'",
key, value);
@@ -79,7 +80,25 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,
goto out;
}
- if ((inputll < opt->min) || (inputll > opt->max)) {
+ if ((opt->validate == GF_OPT_VALIDATE_MIN)) {
+ if (inputll < opt->min) {
+ snprintf (errstr, 256,
+ "'%lld' in 'option %s %s' is smaller than "
+ "minimum value '%"PRId64"'", inputll, key,
+ value, opt->min);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ goto out;
+ }
+ } else if ((opt->validate == GF_OPT_VALIDATE_MAX)) {
+ if ((inputll > opt->max)) {
+ snprintf (errstr, 256,
+ "'%lld' in 'option %s %s' is greater than "
+ "maximum value '%"PRId64"'", inputll, key,
+ value, opt->max);
+ gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
+ goto out;
+ }
+ } else if ((inputll < opt->min) || (inputll > opt->max)) {
snprintf (errstr, 256,
"'%lld' in 'option %s %s' is out of range "
"[%"PRId64" - %"PRId64"]",
@@ -126,7 +145,6 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,
snprintf (errstr, 256, "Cache size %"PRId64" is out of "
"range [%"PRId64" - %"PRId64"]",
size, opt->min, opt->max);
- //*op_errstr = gf_strdup (errstr);
gf_log (xl->name, GF_LOG_WARNING, "%s", errstr);
ret = 0;
goto out;