summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/options.c24
-rw-r--r--libglusterfs/src/options.h24
-rw-r--r--xlators/cluster/afr/src/afr.c1
3 files changed, 39 insertions, 10 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;
diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h
index 8c0ff2499c9..1775ad9ea71 100644
--- a/libglusterfs/src/options.h
+++ b/libglusterfs/src/options.h
@@ -41,22 +41,32 @@ typedef enum {
GF_OPTION_TYPE_MAX,
} volume_option_type_t;
+typedef enum {
+ GF_OPT_VALIDATE_BOTH = 0,
+ GF_OPT_VALIDATE_MIN,
+ GF_OPT_VALIDATE_MAX,
+} opt_validate_type_t;
#define ZR_VOLUME_MAX_NUM_KEY 4
#define ZR_OPTION_MAX_ARRAY_SIZE 64
/* Each translator should define this structure */
typedef struct volume_options {
- char *key[ZR_VOLUME_MAX_NUM_KEY];
+ char *key[ZR_VOLUME_MAX_NUM_KEY];
/* different key, same meaning */
- volume_option_type_t type;
- int64_t min; /* 0 means no range */
- int64_t max; /* 0 means no range */
- char *value[ZR_OPTION_MAX_ARRAY_SIZE];
+ volume_option_type_t type;
+ int64_t min; /* 0 means no range */
+ int64_t max; /* 0 means no range */
+ char *value[ZR_OPTION_MAX_ARRAY_SIZE];
/* If specified, will check for one of
the value from this array */
- char *default_value;
- char *description; /* about the key */
+ char *default_value;
+ char *description; /* about the key */
+ /* Required for int options where only the min value
+ * is given and is 0. This will cause validation not to
+ * happen
+ */
+ opt_validate_type_t validate;
} volume_option_t;
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index 4f7bf2de004..ebb9f1ee904 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -524,6 +524,7 @@ struct volume_options options[] = {
.type = GF_OPTION_TYPE_INT,
.min = 0,
.default_value = "16",
+ .validate = GF_OPT_VALIDATE_MIN,
},
{ .key = {"data-self-heal"},
.type = GF_OPTION_TYPE_STR,