summaryrefslogtreecommitdiffstats
path: root/xlators/performance
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2011-08-11 16:08:36 +0530
committerAnand Avati <avati@gluster.com>2011-08-18 23:49:03 -0700
commitd2849bd349081b332540713cfeaa561f57356b2a (patch)
tree85ca2a53d39ced5cf7fd8dfb0df8cf292e9d29af /xlators/performance
parent6073fc29bf79fad0b0a3ae423d637ded39a00a3a (diff)
xlator options: revamp xlator option validation/reconfigure code
- move option handling to options.c (new file) - remove duplication of option validation code - remove duplication of gf_log / sprintf - get rid of xlator_t->validate_options - get rid of option validation in rpc-transport - get rid of validate_options() in every xlator - use xlator_volume_option_get to clean up many functions - introduce primitives to init/reconfigure option types Change-Id: I51798af72c8dc0a2b9e017424036eb3667dfc7ff BUG: 3415 Reviewed-on: http://review.gluster.com/235 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'xlators/performance')
-rw-r--r--xlators/performance/io-cache/src/io-cache.c299
-rw-r--r--xlators/performance/io-cache/src/io-cache.h4
-rw-r--r--xlators/performance/io-threads/src/io-threads.c107
-rw-r--r--xlators/performance/quick-read/src/quick-read.c127
-rw-r--r--xlators/performance/write-behind/src/write-behind.c202
5 files changed, 59 insertions, 680 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c
index 0a5ca0a7cb3..90c14ea7d6c 100644
--- a/xlators/performance/io-cache/src/io-cache.c
+++ b/xlators/performance/io-cache/src/io-cache.c
@@ -1513,47 +1513,13 @@ mem_acct_init (xlator_t *this)
return ret;
}
-int
-validate_options (xlator_t *this, char **op_errstr)
-{
- int ret = 0;
- volume_opt_list_t *vol_opt = NULL;
- volume_opt_list_t *tmp = NULL;
-
- if (!this) {
- gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr");
- 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);
- }
-
-out:
-
- return ret;
-}
int
reconfigure (xlator_t *this, dict_t *options)
{
data_t *data = NULL;
ioc_table_t *table = NULL;
- int32_t cache_timeout = 0;
- int64_t min_file_size = 0;
- int64_t max_file_size = 0;
- char *tmp = NULL;
- uint64_t cache_size = 0;
- char *cache_size_string = NULL;
- int ret = 0;
+ int ret = -1;
if (!this || !this->private)
goto out;
@@ -1562,72 +1528,11 @@ reconfigure (xlator_t *this, dict_t *options)
ioc_table_lock (table);
{
- data = dict_get (options, "cache-timeout");
- if (data) {
- cache_timeout = data_to_uint32 (data);
- if (cache_timeout < 0){
- gf_log (this->name, GF_LOG_WARNING,
- "cache-timeout %d seconds invalid,"
- " has to be >=0", cache_timeout);
- goto out;
- }
-
-
- if (cache_timeout > 60){
- gf_log (this->name, GF_LOG_WARNING,
- "cache-timeout %d seconds invalid,"
- " has to be <=60", cache_timeout);
- goto out;
- }
-
- table->cache_timeout = cache_timeout;
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring %d seconds to"
- " revalidate cache", table->cache_timeout);
- } else
- table->cache_timeout = 1;
-
- data = dict_get (options, "cache-size");
- if (data)
- cache_size_string = data_to_str (data);
-
- 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);
- goto out;
- }
-
- if (cache_size < (4 * GF_UNIT_MB)) {
- gf_log(this->name, GF_LOG_ERROR,
- "Reconfiguration"
- "'option cache-size %s' failed , "
- "Max value can be 4MiB, Defaulting to "
- "old value (%"PRIu64")",
- cache_size_string, table->cache_size);
- goto out;
- }
-
- if (cache_size > (6 * GF_UNIT_GB)) {
- gf_log (this->name, GF_LOG_ERROR,
- "Reconfiguration"
- "'option cache-size %s' failed , "
- "Max value can be 6GiB, Defaulting to "
- "old value (%"PRIu64")",
- cache_size_string, table->cache_size);
- goto out;
- }
-
+ GF_OPTION_RECONF ("cache-timeout", table->cache_timeout,
+ options, int32, unlock);
- gf_log (this->name, GF_LOG_DEBUG, "Reconfiguring "
- " cache-size %"PRIu64"", cache_size);
- table->cache_size = cache_size;
- } else
- table->cache_size = IOC_CACHE_SIZE;
+ GF_OPTION_RECONF ("cache-size", table->cache_size,
+ options, size, unlock);
data = dict_get (options, "priority");
if (data) {
@@ -1640,80 +1545,36 @@ reconfigure (xlator_t *this, dict_t *options)
&table->priority_list);
if (table->max_pri == -1) {
- ret = -1;
- goto out;
+ goto unlock;
}
table->max_pri ++;
}
- min_file_size = table->min_file_size;
- data = dict_get (options, "min-file-size");
- if (data) {
- tmp = data_to_str (data);
- if (tmp != NULL) {
- if (gf_string2bytesize (tmp,
- (uint64_t *)&min_file_size)
- != 0) {
- gf_log ("io-cache", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "\"option min-file-size\"", tmp);
- ret = -1;
- goto out;
- }
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring min-file-size %"PRIu64"",
- table->min_file_size);
- }
- }
-
- max_file_size = table->max_file_size;
- data = dict_get (options, "max-file-size");
- if (data) {
- tmp = data_to_str (data);
- if (tmp != NULL) {
- if (gf_string2bytesize (tmp,
- (uint64_t *)&max_file_size)
- != 0) {
- gf_log ("io-cache", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "\"option max-file-size\"", tmp);
- ret = -1;
- goto out;
- }
+ GF_OPTION_RECONF ("max-file-size", table->max_file_size,
+ options, size, unlock);
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring max-file-size %"PRIu64"",
- table->max_file_size);
- }
- }
+ GF_OPTION_RECONF ("min-file-size", table->min_file_size,
+ options, size, unlock);
- if ((max_file_size >= 0) && (min_file_size > max_file_size)) {
- gf_log ("io-cache", GF_LOG_ERROR, "minimum size (%"
+ if ((table->max_file_size >= 0) &&
+ (table->min_file_size > table->max_file_size)) {
+ gf_log (this->name, GF_LOG_ERROR, "minimum size (%"
PRIu64") of a file that can be cached is "
"greater than maximum size (%"PRIu64"). "
"Hence Defaulting to old value",
table->min_file_size, table->max_file_size);
- goto out;
+ goto unlock;
}
- table->min_file_size = min_file_size;
- table->max_file_size = max_file_size;
- data = dict_get (options, "min-file-size");
- if (data && !data_to_str (data))
- table->min_file_size = 0;
-
- data = dict_get (options, "max-file-size");
- if (data && !data_to_str (data))
- table->max_file_size = 0;
+ ret = 0;
}
-
+unlock:
ioc_table_unlock (table);
out:
return ret;
-
}
+
/*
* init -
* @this:
@@ -1725,11 +1586,9 @@ init (xlator_t *this)
ioc_table_t *table = NULL;
dict_t *xl_options = NULL;
uint32_t index = 0;
- char *cache_size_string = NULL, *tmp = NULL;
int32_t ret = -1;
glusterfs_ctx_t *ctx = NULL;
data_t *data = 0;
- char *def_val = NULL;
xl_options = this->options;
@@ -1754,61 +1613,13 @@ init (xlator_t *this)
table->xl = this;
table->page_size = this->ctx->page_size;
- if (xlator_get_volopt_info (&this->volume_options, "cache-size",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of cache-size "
- "not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_val, &table->cache_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size corrupt");
- ret = -1;
- goto out;
- }
- }
-
- data = dict_get (xl_options, "cache-size");
- if (data)
- cache_size_string = data_to_str (data);
-
- if (cache_size_string) {
- if (gf_string2bytesize (cache_size_string,
- &table->cache_size) != 0) {
- gf_log ("io-cache", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "\"option cache-size\"",
- cache_size_string);
- goto out;
- }
+ GF_OPTION_INIT ("cache-size", table->cache_size, size, out);
- gf_log (this->name, GF_LOG_TRACE,
- "using cache-size %"PRIu64"", table->cache_size);
- }
+ GF_OPTION_INIT ("cache-timeout", table->cache_timeout, int32, out);
- if (xlator_get_volopt_info (&this->volume_options, "cache-timeout",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-timeout not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2int32 (def_val, &table->cache_timeout)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-timeout corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("min-file-size", table->min_file_size, size, out);
- data = dict_get (xl_options, "cache-timeout");
- if (data) {
- table->cache_timeout = data_to_uint32 (data);
- gf_log (this->name, GF_LOG_TRACE,
- "Using %d seconds to revalidate cache",
- table->cache_timeout);
- }
+ GF_OPTION_INIT ("max-file-size", table->max_file_size, size, out);
INIT_LIST_HEAD (&table->priority_list);
table->max_pri = 1;
@@ -1827,74 +1638,6 @@ init (xlator_t *this)
}
table->max_pri ++;
- if (xlator_get_volopt_info (&this->volume_options, "min-file-size",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "min-file-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_val,
- (uint64_t *) &table->min_file_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "min-file-size corrupt");
- ret = -1;
- goto out;
- }
- }
-
- data = dict_get (xl_options, "min-file-size");
- if (data)
- tmp = data_to_str (data);
-
- if (tmp != NULL) {
- if (gf_string2bytesize (tmp,
- (uint64_t *)&table->min_file_size)
- != 0) {
- gf_log ("io-cache", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "\"option min-file-size\"", tmp);
- goto out;
- }
-
- gf_log (this->name, GF_LOG_TRACE,
- "using min-file-size %"PRIu64"", table->min_file_size);
- }
-
- if (xlator_get_volopt_info (&this->volume_options, "max-file-size",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "max-file-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_val,
- (uint64_t *) &table->max_file_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "max-file-size corrupt");
- ret = -1;
- goto out;
- }
- }
-
- tmp = NULL;
- data = dict_get (xl_options, "max-file-size");
- if (data)
- tmp = data_to_str (data);
-
- if (tmp != NULL) {
- if (gf_string2bytesize (tmp,
- (uint64_t *)&table->max_file_size)
- != 0) {
- gf_log ("io-cache", GF_LOG_ERROR,
- "invalid number format \"%s\" of "
- "\"option max-file-size\"", tmp);
- goto out;
- }
-
- gf_log (this->name, GF_LOG_TRACE,
- "using max-file-size %"PRIu64"", table->max_file_size);
- }
INIT_LIST_HEAD (&table->inodes);
if ((table->max_file_size >= 0)
diff --git a/xlators/performance/io-cache/src/io-cache.h b/xlators/performance/io-cache/src/io-cache.h
index 01ae462e445..eec24f143ba 100644
--- a/xlators/performance/io-cache/src/io-cache.h
+++ b/xlators/performance/io-cache/src/io-cache.h
@@ -164,8 +164,8 @@ struct ioc_table {
uint64_t page_size;
uint64_t cache_size;
uint64_t cache_used;
- int64_t min_file_size;
- int64_t max_file_size;
+ uint64_t min_file_size;
+ uint64_t max_file_size;
struct list_head inodes; /* list of inodes cached */
struct list_head active;
struct list_head *inode_lru;
diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c
index ffe71c8d721..03ebc66f2e3 100644
--- a/xlators/performance/io-threads/src/io-threads.c
+++ b/xlators/performance/io-threads/src/io-threads.c
@@ -2081,73 +2081,18 @@ mem_acct_init (xlator_t *this)
int
-validate_options ( xlator_t *this, char **op_errstr)
-{
- 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 (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;
-}
-
-
-int
-reconfigure ( xlator_t *this, dict_t *options)
+reconfigure (xlator_t *this, dict_t *options)
{
iot_conf_t *conf = NULL;
- int ret = 0;
- int thread_count;
+ int ret = -1;
conf = this->private;
if (!conf)
goto out;
- thread_count = conf->max_count;
-
- 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_WARNING,
- "Number of threads opted (%d) is less than "
- "min (%d). Restoring it to previous value (%d)",
- thread_count, IOT_MIN_THREADS, conf->max_count);
- goto out;
- }
-
- if (thread_count > IOT_MAX_THREADS) {
- gf_log ("io-threads", GF_LOG_WARNING,
- "Number of threads opted (%d) is greater than "
- "max (%d). Restoring it to previous value (%d)",
- thread_count, IOT_MAX_THREADS, conf->max_count);
- goto out;
- }
-
- conf->max_count = thread_count;
- } else
- conf->max_count = thread_count;
+ GF_OPTION_RECONF ("thread-count", conf->max_count, options, int32, out);
ret = 0;
-
out:
return ret;
}
@@ -2157,12 +2102,8 @@ int
init (xlator_t *this)
{
iot_conf_t *conf = NULL;
- dict_t *xl_options = this->options;
- int thread_count = IOT_DEFAULT_THREADS;
- int idle_time = IOT_DEFAULT_IDLE;
int ret = -1;
int i = 0;
- char *def_val = NULL;
if (!this->children || this->children->next) {
gf_log ("io-threads", GF_LOG_ERROR,
@@ -2197,46 +2138,9 @@ init (xlator_t *this)
set_stack_size (conf);
- if (xlator_get_volopt_info (&this->volume_options, "thread-count",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "thread-count not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2int32 (def_val, &conf->max_count)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "thread corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("thread-count", conf->max_count, int32, out);
- if (dict_get (xl_options, "thread-count")) {
- thread_count = data_to_int32 (dict_get (xl_options,
- "thread-count"));
- if (thread_count < IOT_MIN_THREADS) {
- gf_log ("io-threads", GF_LOG_WARNING,
- "Number of threads opted is less than min"
- "threads allowed scaling it up to min");
- thread_count = IOT_MIN_THREADS;
- }
- if (thread_count > IOT_MAX_THREADS) {
- gf_log ("io-threads", GF_LOG_WARNING,
- "Number of threads opted is more than max"
- " threads allowed scaling it down to max");
- thread_count = IOT_MAX_THREADS;
- }
- }
- conf->max_count = thread_count;
-
- if (dict_get (xl_options, "idle-time")) {
- idle_time = data_to_int32 (dict_get (xl_options,
- "idle-time"));
- if (idle_time < 0)
- idle_time = 1;
- }
- conf->idle_time = idle_time;
+ GF_OPTION_INIT ("idle-time", conf->idle_time, int32, out);
conf->this = this;
@@ -2328,6 +2232,7 @@ struct volume_options options[] = {
.type = GF_OPTION_TYPE_INT,
.min = 1,
.max = 0x7fffffff,
+ .default_value = "120",
},
{ .key = {NULL},
},
diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c
index e17d3db23e4..e8385089f1a 100644
--- a/xlators/performance/quick-read/src/quick-read.c
+++ b/xlators/performance/quick-read/src/quick-read.c
@@ -3407,43 +3407,11 @@ mem_acct_init (xlator_t *this)
int
-validate_options (xlator_t *this, char **op_errstr)
-{
- 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 (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;
-}
-
-
-int
reconfigure (xlator_t *this, dict_t *options)
{
- char *str = NULL;
int32_t ret = -1;
qr_private_t *priv = NULL;
qr_conf_t *conf = NULL;
- int32_t cache_timeout = 0;
- uint64_t cache_size = 0;
GF_VALIDATE_OR_GOTO ("quick-read", this, out);
GF_VALIDATE_OR_GOTO (this->name, this->private, out);
@@ -3456,40 +3424,10 @@ reconfigure (xlator_t *this, dict_t *options)
goto out;
}
- cache_timeout = conf->cache_timeout;
- ret = dict_get_str (options, "cache-timeout", &str);
- if (ret == 0) {
- ret = gf_string2uint_base10 (str,
- (unsigned int *)&conf->cache_timeout);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid cache-timeout value %s", str);
- ret = -1;
- goto out;
- }
- conf->cache_timeout = cache_timeout;
- } else {
- conf->cache_timeout = 1;
- }
-
- cache_size = conf->cache_size;
- ret = dict_get_str (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 %s(old value used)", str);
- conf->cache_size = cache_size;
- ret = -1;
- goto out;
- }
+ GF_OPTION_RECONF ("cache-timeout", conf->cache_timeout, options, int32,
+ out);
- gf_log (this->name, GF_LOG_WARNING,
- "Reconfiguring cache-siz to %"PRIu64, cache_size);
- conf->cache_size = cache_size;
- } else {
- conf->cache_size = QR_DEFAULT_CACHE_SIZE;
- }
+ GF_OPTION_RECONF ("cache-size", conf->cache_size, options, size, out);
ret = 0;
out:
@@ -3602,11 +3540,9 @@ out:
int32_t
init (xlator_t *this)
{
- char *str = NULL;
int32_t ret = -1, i = 0;
qr_private_t *priv = NULL;
qr_conf_t *conf = NULL;
- char *def_val = NULL;
if (!this->children || this->children->next) {
gf_log (this->name, GF_LOG_ERROR,
@@ -3628,59 +3564,12 @@ init (xlator_t *this)
LOCK_INIT (&priv->table.lock);
conf = &priv->conf;
- conf->max_file_size = 65536;
- ret = dict_get_str (this->options, "max-file-size",
- &str);
- if (ret == 0) {
- ret = gf_string2bytesize (str, &conf->max_file_size);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid number format \"%s\" of \"option "
- "max-file-size\"",
- str);
- ret = -1;
- goto out;
- }
- }
- conf->cache_timeout = 1;
- ret = dict_get_str (this->options, "cache-timeout", &str);
- if (ret == 0) {
- ret = gf_string2uint_base10 (str,
- (unsigned int *)&conf->cache_timeout);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid cache-timeout value %s", str);
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("max-file-size", conf->max_file_size, size, out);
- if (xlator_get_volopt_info (&this->volume_options, "cache-size",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_val, &conf->cache_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("cache-timeout", conf->cache_timeout, int32, out);
- ret = dict_get_str (this->options, "cache-size", &str);
- if (ret == 0) {
- ret = gf_string2bytesize (str, &conf->cache_size);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid cache-size value %s", str);
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("cache-size", conf->cache_size, size, out);
INIT_LIST_HEAD (&conf->priority_list);
conf->max_pri = 1;
@@ -3770,11 +3659,13 @@ struct volume_options options[] = {
{ .key = {"cache-timeout"},
.type = GF_OPTION_TYPE_INT,
.min = 1,
- .max = 60
+ .max = 60,
+ .default_value = "1",
},
{ .key = {"max-file-size"},
.type = GF_OPTION_TYPE_SIZET,
.min = 0,
.max = 1 * GF_UNIT_KB * 1000,
+ .default_value = "64KB",
},
};
diff --git a/xlators/performance/write-behind/src/write-behind.c b/xlators/performance/write-behind/src/write-behind.c
index 20991308374..1eff4385ae3 100644
--- a/xlators/performance/write-behind/src/write-behind.c
+++ b/xlators/performance/write-behind/src/write-behind.c
@@ -2882,100 +2882,21 @@ out:
int
-validate_options (xlator_t *this, char **op_errstr)
-{
- 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 (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;
-}
-
-int
reconfigure (xlator_t *this, dict_t *options)
{
- char *str = NULL;
- uint64_t window_size = 0;
- wb_conf_t *conf = NULL;
- int ret = 0;
+ wb_conf_t *conf = NULL;
+ int ret = -1;
conf = this->private;
- 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_ERROR, "Reconfiguration"
- "'option cache-size %s failed , Invalid"
- " number format, Defaulting to old value "
- "(%"PRIu64")", str, conf->window_size);
- goto out;
- }
+ GF_OPTION_RECONF ("cache-size", conf->window_size, options, size, out);
- if (window_size < (512 * GF_UNIT_KB)) {
- gf_log(this->name, GF_LOG_ERROR, "Reconfiguration"
- "'option cache-size %s' failed , Max value"
- "can be 512KiB, Defaulting to old value "
- "(%"PRIu64")", str, conf->window_size);
- goto out;
- }
-
- if (window_size > (2 * GF_UNIT_GB)) {
- gf_log(this->name, GF_LOG_ERROR, "Reconfiguration"
- "'option cache-size %s' failed , Max value"
- "can be 1 GiB, Defaulting to old value "
- "(%"PRIu64")", str, conf->window_size);
- goto out;
- }
-
- conf->window_size = window_size;
- gf_log(this->name, GF_LOG_WARNING, "Reconfiguring "
- "'option cache-size %s ' to %"PRIu64, str,
- conf->window_size);
- } else {
- conf->window_size = WB_WINDOW_SIZE;
- }
-
- ret = dict_get_str (options, "flush-behind", &str);
- if (ret == 0) {
- ret = gf_string2boolean (str, &conf->flush_behind);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'flush-behind' takes only boolean arguments");
- conf->flush_behind = 1;
- goto out;
- }
-
- if (conf->flush_behind) {
- gf_log (this->name, GF_LOG_WARNING,
- "enabling flush-behind");
- } else {
- gf_log (this->name, GF_LOG_WARNING,
- "disabling flush-behind");
- }
- }
+ GF_OPTION_RECONF ("flush-behind", conf->flush_behind, options, bool,
+ out);
+ ret = 0;
out:
- return 0;
+ return ret;
}
@@ -2984,9 +2905,7 @@ init (xlator_t *this)
{
dict_t *options = NULL;
wb_conf_t *conf = NULL;
- char *str = NULL;
int32_t ret = -1;
- char *def_val = NULL;
if ((this->children == NULL)
|| this->children->next) {
@@ -3008,63 +2927,16 @@ init (xlator_t *this)
goto out;
}
- conf->enable_O_SYNC = _gf_false;
- ret = dict_get_str (options, "enable-O_SYNC", &str);
- if (ret == 0) {
- ret = gf_string2boolean (str, &conf->enable_O_SYNC);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'enable-O_SYNC' takes only boolean arguments");
- goto out;
- }
- }
+ GF_OPTION_INIT("enable-O_SYNC", conf->enable_O_SYNC, bool, out);
/* configure 'options aggregate-size <size>' */
conf->aggregate_size = WB_AGGREGATE_SIZE;
- conf->disable_till = 0;
- ret = dict_get_str (options, "disable-for-first-nbytes", &str);
- if (ret == 0) {
- ret = gf_string2bytesize (str, &conf->disable_till);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid number format \"%s\" of \"option "
- "disable-for-first-nbytes\"",
- str);
- goto out;
- }
- }
- gf_log (this->name, GF_LOG_WARNING,
- "disabling write-behind for first %"PRIu64" bytes",
- conf->disable_till);
+ GF_OPTION_INIT("disable-for-first-nbytes", conf->disable_till, size,
+ out);
/* configure 'option window-size <size>' */
- if (xlator_get_volopt_info (&this->volume_options, "cache-size",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_val, &conf->window_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size corrupt");
- ret = -1;
- goto out;
- }
- }
-
- ret = dict_get_str (options, "cache-size", &str);
- if (ret == 0) {
- ret = gf_string2bytesize (str, &conf->window_size);
- if (ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "invalid number format \"%s\" of \"option "
- "window-size\"", str);
- GF_FREE (conf);
- goto out;
- }
- }
+ GF_OPTION_INIT ("cache-size", conf->window_size, size, out);
if (!conf->window_size && conf->aggregate_size) {
gf_log (this->name, GF_LOG_WARNING,
@@ -3079,58 +2951,23 @@ init (xlator_t *this)
"aggregate-size(%"PRIu64") cannot be more than "
"window-size(%"PRIu64")", conf->aggregate_size,
conf->window_size);
- GF_FREE (conf);
goto out;
}
/* configure 'option flush-behind <on/off>' */
+ GF_OPTION_INIT ("flush-behind", conf->flush_behind, bool, out);
- if (xlator_get_volopt_info (&this->volume_options, "flush-behind",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2boolean (def_val, &conf->flush_behind)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "cache-size corrupt");
- ret = -1;
- goto out;
- }
- }
-
- ret = dict_get_str (options, "flush-behind", &str);
- if (ret == 0) {
- ret = gf_string2boolean (str, &conf->flush_behind);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'flush-behind' takes only boolean arguments");
- goto out;
- }
-
- if (conf->flush_behind) {
- gf_log (this->name, GF_LOG_WARNING,
- "enabling flush-behind");
- }
- }
-
- conf->enable_trickling_writes = _gf_true;
- ret = dict_get_str (options, "enable-trickling-writes", &str);
- if (ret == 0) {
- ret = gf_string2boolean (str, &conf->enable_trickling_writes);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'enable-trickling_writes' takes only boolean"
- " arguments");
- goto out;
- }
- }
+ GF_OPTION_INIT ("enable-trickling-writes", conf->enable_trickling_writes,
+ bool, out);
this->private = conf;
ret = 0;
out:
+ if (ret) {
+ if (conf)
+ GF_FREE (conf);
+ }
return ret;
}
@@ -3200,12 +3037,15 @@ struct volume_options options[] = {
.type = GF_OPTION_TYPE_SIZET,
.min = 1,
.max = 1 * GF_UNIT_MB,
+ .default_value = "0",
},
{ .key = {"enable-O_SYNC"},
.type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"enable-trickling-writes"},
.type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {NULL} },
};