From 9bd4f25b6b0ea8103324b685fcc21525a29849a8 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 23 Mar 2011 00:50:17 +0000 Subject: CLI : Validate options farmework. Signed-off-by: Gaurav Signed-off-by: Vijay Bellur BUG: 2064 (NFS options are removed upon glusterd restart) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2064 --- xlators/performance/io-cache/src/io-cache.c | 156 +++------------------ xlators/performance/io-threads/src/io-threads.c | 42 +++--- xlators/performance/quick-read/src/quick-read.c | 63 ++------- .../performance/write-behind/src/write-behind.c | 78 +++-------- 4 files changed, 71 insertions(+), 268 deletions(-) (limited to 'xlators/performance') diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 738bd66a2b6..a3ebaf47c0e 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -1497,144 +1497,32 @@ mem_acct_init (xlator_t *this) } int -validate_options (xlator_t *this, dict_t *options, char **op_errstr) +validate_options (xlator_t *this, char **op_errstr) { - int32_t cache_timeout; - int64_t min_file_size = 0; - int64_t max_file_size = 0; - char *tmp = NULL; - uint64_t cache_size; - char *cache_size_string = NULL; - int ret = 0; - - - if (dict_get (options, "cache-timeout")) { - cache_timeout = data_to_uint32 (dict_get (options, - "cache-timeout")); - if (cache_timeout < 0){ - gf_log (this->name, GF_LOG_WARNING, - "cache-timeout %d seconds invalid," - " has to be >=0", cache_timeout); - *op_errstr = gf_strdup ("Error, should be >= 0"); - ret = -1; - goto out; - } - - - if (cache_timeout > 60){ - gf_log (this->name, GF_LOG_WARNING, - "cache-timeout %d seconds invalid," - " has to be <=60", cache_timeout); - *op_errstr = gf_strdup ("Error, should be <= 60"); - ret = -1; - goto out; - } - - - - gf_log (this->name, GF_LOG_DEBUG, - "Validated cache-timeout revalidate cache"); - } - - - if (dict_get (options, "cache-size")) - cache_size_string = data_to_str (dict_get (options, - "cache-size")); - if (cache_size_string) { - if (gf_string2bytesize (cache_size_string, - &cache_size) != 0) { - gf_log ("io-cache", GF_LOG_ERROR, - "invalid number format \"%s\" of " - "\"option cache-size\" Defaulting" - "to old value", cache_size_string); - *op_errstr = gf_strdup ("Error, Invalid Format"); - ret = -1; - goto out; - } - - if (cache_size < ( 4 * GF_UNIT_MB)) { - gf_log(this->name, GF_LOG_WARNING, "Reconfiguration" - "'option cache-size %s' failed , Max value" - "can be 4MiB, Defaulting to old value " - "(%"PRIu64")", cache_size_string, - cache_size); - *op_errstr = gf_strdup ("Error, " - "Cannot be less than 4MB"); - ret = -1; - goto out; - } - - if (cache_size > ( 6 * GF_UNIT_GB)) { - gf_log(this->name, GF_LOG_WARNING, "Validation" - "'option cache-size %s' failed , Max value" - "can be 6GiB, Defaulting to old value " - "(%"PRIu64")", cache_size_string, - cache_size); - *op_errstr = gf_strdup ("Error, Cannot be more " - "than 6GB"); - ret = -1; - goto out; - } - - - gf_log (this->name, GF_LOG_DEBUG, "Validated " - " cache-size %"PRIu64"", cache_size); - } - - - tmp = data_to_str (dict_get (options, "min-file-size")); - if (tmp != NULL) { - if (gf_string2bytesize (tmp, - (uint64_t *)&min_file_size) - != 0) { - gf_log ("io-cache", GF_LOG_WARNING, - "invalid number format \"%s\" of " - "\"option min-file-size\"", tmp); - *op_errstr = gf_strdup ("Error, Invalid Format"); - ret = -1; - goto out; - } + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp; - gf_log (this->name, GF_LOG_DEBUG, - "Validated min-file-size %"PRIu64"", - min_file_size); - } - - - tmp = data_to_str (dict_get (options, "max-file-size")); - if (tmp != NULL) { - if (gf_string2bytesize (tmp, - (uint64_t *)&max_file_size) - != 0) { - gf_log ("io-cache", GF_LOG_WARNING, - "invalid number format \"%s\" of " - "\"option max-file-size\"", tmp); - *op_errstr = gf_strdup ("Error, Invalid Format"); - ret = -1; - goto out; - } - - - gf_log (this->name, GF_LOG_WARNING, - "Validated max-file-size %"PRIu64"", - max_file_size); + if (!this) { + gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr"); + ret =-1; + goto out; } - if ((max_file_size >= 0) & (min_file_size > max_file_size)) { - gf_log ("io-cache", GF_LOG_WARNING, "minimum size (%" - PRIu64") of a file that can be cached is " - "greater than maximum size (%"PRIu64"). ", - min_file_size, max_file_size); - *op_errstr = gf_strdup ("Error, min-file-size greater" - "than max-file-size"); - ret = -1; + if (list_empty (&this->volume_options)) goto out; - } + vol_opt = list_entry (this->volume_options.next, + volume_opt_list_t, list); + list_for_each_entry_safe (vol_opt, tmp, &this->volume_options, list) { + ret = validate_xlator_volume_options_attacherr (this, + vol_opt->given_opt, + op_errstr); + } out: - return ret; + return ret; } int @@ -1664,7 +1552,6 @@ reconfigure (xlator_t *this, dict_t *options) gf_log (this->name, GF_LOG_WARNING, "cache-timeout %d seconds invalid," " has to be >=0", cache_timeout); - ret = -1; goto out; } @@ -1673,7 +1560,6 @@ reconfigure (xlator_t *this, dict_t *options) gf_log (this->name, GF_LOG_WARNING, "cache-timeout %d seconds invalid," " has to be <=60", cache_timeout); - ret = -1; goto out; } @@ -1698,7 +1584,6 @@ reconfigure (xlator_t *this, dict_t *options) "invalid number format \"%s\" of " "\"option cache-size\" Defaulting" "to old value", cache_size_string); - ret = -1; goto out; } @@ -1709,7 +1594,6 @@ reconfigure (xlator_t *this, dict_t *options) "Max value can be 4MiB, Defaulting to " "old value (%"PRIu64")", cache_size_string, table->cache_size); - ret = -1; goto out; } @@ -1720,7 +1604,6 @@ reconfigure (xlator_t *this, dict_t *options) "Max value can be 6GiB, Defaulting to " "old value (%"PRIu64")", cache_size_string, table->cache_size); - ret = -1; goto out; } @@ -1794,7 +1677,6 @@ reconfigure (xlator_t *this, dict_t *options) "greater than maximum size (%"PRIu64"). " "Hence Defaulting to old value", table->min_file_size, table->max_file_size); - ret = -1; goto out; } @@ -2066,13 +1948,9 @@ struct volume_options options[] = { }, { .key = {"min-file-size"}, .type = GF_OPTION_TYPE_SIZET, - .min = -1, - .max = -1 }, { .key = {"max-file-size"}, .type = GF_OPTION_TYPE_SIZET, - .min = -1, - .max = -1 }, { .key = {NULL} }, }; diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index 09b240e8847..bdc808319d1 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -2081,35 +2081,29 @@ mem_acct_init (xlator_t *this) int -validate_options ( xlator_t *this, dict_t *options, char **op_errstr) +validate_options ( xlator_t *this, char **op_errstr) { - int ret = 0; - int thread_count; + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp; + if (!this) { + gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr"); + ret =-1; + goto out; + } - if (dict_get (options, "thread-count")) { - thread_count = data_to_int32 (dict_get (options, - "thread-count")); - - if (thread_count < IOT_MIN_THREADS) { - gf_log ("io-threads", GF_LOG_DEBUG, - "volume set thread_count WRONG,it is lesser"); - ret = -1; - *op_errstr = gf_strdup ("LESSER Than min. threads"); - goto out; - } + if (list_empty (&this->volume_options)) + goto out; - if (thread_count > IOT_MAX_THREADS) { - gf_log ("io-threads", GF_LOG_DEBUG, - "volume set thread_count WRONG,it is greater"); - *op_errstr = gf_strdup ("GREATER than max. threads"); - ret = -1; - goto out; - } + vol_opt = list_entry (this->volume_options.next, + volume_opt_list_t, list); + list_for_each_entry_safe (vol_opt, tmp, &this->volume_options, list) { + ret = validate_xlator_volume_options_attacherr (this, + vol_opt->given_opt, + op_errstr); } - ret = 0; - out: return ret; } @@ -2119,7 +2113,7 @@ int reconfigure ( xlator_t *this, dict_t *options) { iot_conf_t *conf = NULL; - int ret = -1; + int ret = 0; int thread_count; conf = this->private; diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 044b00fd58d..465881080a4 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -3172,64 +3172,29 @@ mem_acct_init (xlator_t *this) int -validate_options (xlator_t *this, dict_t *options, char **op_errstr) +validate_options (xlator_t *this, char **op_errstr) { - char *str = NULL; - int32_t ret = -1; - int32_t cache_timeout = 0; - uint64_t cache_size = 0; + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp; if (!this) { + gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr"); + ret =-1; goto out; } - ret = dict_get_str (this->options, "cache-timeout", &str); - if (ret == 0) { - ret = gf_string2uint_base10 (str, - (unsigned int *)&cache_timeout); - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cache-timeout value %s", str); - *op_errstr = "Invalid Format!!"; - ret = -1; - goto out; - } - if (ret < 1 || ret > 60) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cache-timeout value %s", str); - *op_errstr = "Range 1 <= value <= 60"; - ret = -1; - goto out; - } - } - - ret = dict_get_str (this->options, "cache-size", &str); - if (ret == 0) { - ret = gf_string2bytesize (str, &cache_size); - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cache-size value %s", str); - ret = -1; - goto out; - } - if (cache_size > 6 * GF_UNIT_GB) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cache-size value %s", str); - *op_errstr = "Range 4mb <= value <= 6gb"; - ret = -1; - goto out; - } - if (cache_size < 4* GF_UNIT_MB) { - gf_log (this->name, GF_LOG_ERROR, - "invalid cache-size value %s", str); - *op_errstr = "Range 4mb <= value <= 6gb"; - ret = -1; - goto out; - } + if (list_empty (&this->volume_options)) + goto out; + vol_opt = list_entry (this->volume_options.next, + volume_opt_list_t, list); + list_for_each_entry_safe (vol_opt, tmp, &this->volume_options, list) { + ret = validate_xlator_volume_options_attacherr (this, + vol_opt->given_opt, + op_errstr); } - ret =0; out: return ret; } diff --git a/xlators/performance/write-behind/src/write-behind.c b/xlators/performance/write-behind/src/write-behind.c index 61d4c316cff..cdc88969976 100644 --- a/xlators/performance/write-behind/src/write-behind.c +++ b/xlators/performance/write-behind/src/write-behind.c @@ -2867,65 +2867,34 @@ out: int -validate_options (xlator_t *this, dict_t *options, char **op_errstr) +validate_options (xlator_t *this, char **op_errstr) { - char *str = NULL; - uint64_t window_size = 0;; - gf_boolean_t flush_behind = 0; - int ret = 0; + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp; - ret = dict_get_str (options, "cache-size", &str); - if (ret == 0) { - ret = gf_string2bytesize (str, &window_size); - if (ret != 0) { - gf_log(this->name, GF_LOG_WARNING, "Validation" - "'option cache-size %s failed , Invalid" - " number format, ", str); - *op_errstr = gf_strdup ("Error, Invalid num format"); - ret = -1; - goto out; - } - - if (window_size < (512 * GF_UNIT_KB)) { - gf_log(this->name, GF_LOG_WARNING, "Validation" - "'option cache-size %s' failed , Min value" - "should be 512KiB ", str); - *op_errstr = gf_strdup ("Error, Should be min 512KB"); - ret = -1; - goto out; - } - - if (window_size > (1 * GF_UNIT_GB)) { - gf_log(this->name, GF_LOG_WARNING, "Reconfiguration" - "'option cache-size %s' failed , Max value" - "can be 1 GiB", str); - *op_errstr = gf_strdup ("Error, Max Value is 1GB"); - ret = -1; - goto out; - } - - gf_log(this->name, GF_LOG_WARNING, - "validated 'option cache-size %s '", str); + if (!this) { + gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr"); + ret =-1; + goto out; } - ret = dict_get_str (options, "flush-behind", &str); - if (ret == 0) { - ret = gf_string2boolean (str, &flush_behind); - if (ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "'flush-behind' takes only boolean arguments"); - *op_errstr = gf_strdup ("Error, should be boolean"); - ret = -1; - goto out; - } + if (list_empty (&this->volume_options)) + goto out; + + vol_opt = list_entry (this->volume_options.next, + volume_opt_list_t, list); + list_for_each_entry_safe (vol_opt, tmp, &this->volume_options, list) { + ret = validate_xlator_volume_options_attacherr (this, + vol_opt->given_opt, + op_errstr); } - ret =0; out: + return ret; } - int reconfigure (xlator_t *this, dict_t *options) { @@ -2944,8 +2913,7 @@ reconfigure (xlator_t *this, dict_t *options) "'option cache-size %s failed , Invalid" " number format, Defaulting to old value " "(%"PRIu64")", str, conf->window_size); - ret = -1; - goto out; + goto out; } if (window_size < (512 * GF_UNIT_KB)) { @@ -2953,8 +2921,7 @@ reconfigure (xlator_t *this, dict_t *options) "'option cache-size %s' failed , Max value" "can be 512KiB, Defaulting to old value " "(%"PRIu64")", str, conf->window_size); - ret = -1; - goto out; + goto out; } if (window_size > (2 * GF_UNIT_GB)) { @@ -2962,8 +2929,7 @@ reconfigure (xlator_t *this, dict_t *options) "'option cache-size %s' failed , Max value" "can be 1 GiB, Defaulting to old value " "(%"PRIu64")", str, conf->window_size); - ret = -1; - goto out; + goto out; } conf->window_size = window_size; @@ -2981,7 +2947,7 @@ reconfigure (xlator_t *this, dict_t *options) gf_log (this->name, GF_LOG_ERROR, "'flush-behind' takes only boolean arguments"); conf->flush_behind = 1; - return -1; + goto out; } if (conf->flush_behind) { -- cgit