diff options
author | Anand Avati <avati@gluster.com> | 2011-08-11 16:08:36 +0530 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-08-18 23:49:03 -0700 |
commit | d2849bd349081b332540713cfeaa561f57356b2a (patch) | |
tree | 85ca2a53d39ced5cf7fd8dfb0df8cf292e9d29af /libglusterfs/src | |
parent | 6073fc29bf79fad0b0a3ae423d637ded39a00a3a (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 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/Makefile.am | 33 | ||||
-rw-r--r-- | libglusterfs/src/globals.c | 2 | ||||
-rw-r--r-- | libglusterfs/src/graph.c | 84 | ||||
-rw-r--r-- | libglusterfs/src/options.c | 908 | ||||
-rw-r--r-- | libglusterfs/src/options.h | 248 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 1560 | ||||
-rw-r--r-- | libglusterfs/src/xlator.h | 61 |
7 files changed, 1391 insertions, 1505 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 0f932cb30..a950e67d1 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -1,14 +1,37 @@ -libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) +libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) \ + $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) -libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -D$(GF_HOST_OS) -I$(CONTRIBDIR)/rbtree -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" -I$(CONTRIBDIR)/md5 +libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 \ + -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \ + -D$(GF_HOST_OS) -I$(CONTRIBDIR)/rbtree \ + -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" \ + -I$(CONTRIBDIR)/md5 libglusterfs_la_LIBADD = @LEXLIB@ lib_LTLIBRARIES = libglusterfs.la -libglusterfs_la_SOURCES = dict.c graph.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c iobuf.c globals.c statedump.c stack.c checksum.c daemon.c $(CONTRIBDIR)/md5/md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c graph.c $(CONTRIBDIR)/uuid/clear.c $(CONTRIBDIR)/uuid/copy.c $(CONTRIBDIR)/uuid/gen_uuid.c $(CONTRIBDIR)/uuid/pack.c $(CONTRIBDIR)/uuid/parse.c $(CONTRIBDIR)/uuid/unparse.c $(CONTRIBDIR)/uuid/uuid_time.c $(CONTRIBDIR)/uuid/compare.c $(CONTRIBDIR)/uuid/isnull.c $(CONTRIBDIR)/uuid/unpack.c syncop.c graph-print.c trie.c run.c - -noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h checksum.h daemon.h $(CONTRIBDIR)/md5/md5.h $(CONTRIBDIR)/rbtree/rb.h rbthash.h iatt.h latency.h mem-types.h $(CONTRIBDIR)/uuid/uuidd.h $(CONTRIBDIR)/uuid/uuid.h $(CONTRIBDIR)/uuid/uuidP.h $(CONTRIBDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h run.h +libglusterfs_la_SOURCES = dict.c graph.lex.c y.tab.c xlator.c logging.c \ + hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c \ + compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c \ + iobuf.c globals.c statedump.c stack.c checksum.c daemon.c \ + $(CONTRIBDIR)/md5/md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c \ + graph.c $(CONTRIBDIR)/uuid/clear.c $(CONTRIBDIR)/uuid/copy.c \ + $(CONTRIBDIR)/uuid/gen_uuid.c $(CONTRIBDIR)/uuid/pack.c \ + $(CONTRIBDIR)/uuid/parse.c $(CONTRIBDIR)/uuid/unparse.c \ + $(CONTRIBDIR)/uuid/uuid_time.c $(CONTRIBDIR)/uuid/compare.c \ + $(CONTRIBDIR)/uuid/isnull.c $(CONTRIBDIR)/uuid/unpack.c syncop.c \ + graph-print.c trie.c run.c options.c + +noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h \ + logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h \ + fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h \ + gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h \ + checksum.h daemon.h $(CONTRIBDIR)/md5/md5.h $(CONTRIBDIR)/rbtree/rb.h \ + rbthash.h iatt.h latency.h mem-types.h $(CONTRIBDIR)/uuid/uuidd.h \ + $(CONTRIBDIR)/uuid/uuid.h $(CONTRIBDIR)/uuid/uuidP.h \ + $(CONTRIBDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h run.h \ + options.h EXTRA_DIST = graph.l graph.y diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index d1985b7ed..70c6c92ef 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -154,6 +154,8 @@ glusterfs_this_init () global_xlator.type = "global"; global_xlator.ctx = glusterfs_ctx; + INIT_LIST_HEAD (&global_xlator.volume_options); + return ret; } diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index acad23954..1d7d943e6 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -84,44 +84,6 @@ _gf_dump_details (int argc, char **argv) #endif -static int -_log_if_option_is_invalid (xlator_t *xl, data_pair_t *pair) -{ - volume_opt_list_t *vol_opt = NULL; - volume_option_t *opt = NULL; - int i = 0; - int index = 0; - int found = 0; - - /* Get the first volume_option */ - list_for_each_entry (vol_opt, &xl->volume_options, list) { - /* Warn for extra option */ - if (!vol_opt->given_opt) - break; - - opt = vol_opt->given_opt; - for (index = 0; - ((index < ZR_OPTION_MAX_ARRAY_SIZE) && - (opt[index].key && opt[index].key[0])); index++) - for (i = 0; (i < ZR_VOLUME_MAX_NUM_KEY) && - opt[index].key[i]; i++) { - if (fnmatch (opt[index].key[i], - pair->key, - FNM_NOESCAPE) == 0) { - found = 1; - break; - } - } - } - - if (!found) { - gf_log (xl->name, GF_LOG_WARNING, - "option '%s' is not recognized", - pair->key); - } - return 0; -} - int glusterfs_xlator_link (xlator_t *pxl, xlator_t *cxl) @@ -299,7 +261,7 @@ gf_add_cmdline_options (glusterfs_graph_t *graph, cmd_args_t *cmd_args) cmd_option->key, cmd_option->value); if (ret == 0) { - gf_log (trav->name, GF_LOG_WARNING, + gf_log (trav->name, GF_LOG_INFO, "adding option '%s' for " "volume '%s' with value '%s'", cmd_option->key, trav->name, @@ -324,6 +286,7 @@ glusterfs_graph_validate_options (glusterfs_graph_t *graph) volume_opt_list_t *vol_opt = NULL; xlator_t *trav = NULL; int ret = -1; + char *errstr = NULL; trav = graph->first; @@ -334,11 +297,10 @@ glusterfs_graph_validate_options (glusterfs_graph_t *graph) vol_opt = list_entry (trav->volume_options.next, volume_opt_list_t, list); - ret = validate_xlator_volume_options (trav, - vol_opt->given_opt); + ret = xlator_options_validate (trav, trav->options, &errstr); if (ret) { gf_log (trav->name, GF_LOG_ERROR, - "validating translator failed"); + "validation failed: %s", errstr); return ret; } trav = trav->next; @@ -370,24 +332,36 @@ glusterfs_graph_init (glusterfs_graph_t *graph) } -int -glusterfs_graph_unknown_options (glusterfs_graph_t *graph) +static void +_log_if_unknown_option (dict_t *dict, char *key, data_t *value, void *data) { - data_pair_t *pair = NULL; - xlator_t *trav = NULL; + volume_option_t *found = NULL; + xlator_t *xl = NULL; - trav = graph->first; + xl = data; - /* Validate again phase */ - while (trav) { - pair = trav->options->members_list; - while (pair) { - _log_if_option_is_invalid (trav, pair); - pair = pair->next; - } - trav = trav->next; + found = xlator_volume_option_get (xl, key); + + if (!found) { + gf_log (xl->name, GF_LOG_WARNING, + "option '%s' is not recognized", key); } + return; +} + + +static void +_xlator_check_unknown_options (xlator_t *xl, void *data) +{ + dict_foreach (xl->options, _log_if_unknown_option, xl); +} + + +int +glusterfs_graph_unknown_options (glusterfs_graph_t *graph) +{ + xlator_foreach (graph->first, _xlator_check_unknown_options, NULL); return 0; } diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c new file mode 100644 index 000000000..37302e0da --- /dev/null +++ b/libglusterfs/src/options.c @@ -0,0 +1,908 @@ +/* + Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + <http://www.gnu.org/licenses/>. +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include <fnmatch.h> + +#include "xlator.h" + +#define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) + + +static int +xlator_option_validate_path (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + + if (strstr (value, "../")) { + snprintf (errstr, 256, + "invalid path given '%s'", + value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + /* Make sure the given path is valid */ + if (value[0] != '/') { + snprintf (errstr, 256, + "option %s %s: '%s' is not an " + "absolute path name", + key, value, value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_int (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + long long inputll = 0; + int ret = -1; + char errstr[256]; + + /* Check the range */ + if (gf_string2longlong (value, &inputll) != 0) { + snprintf (errstr, 256, + "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check required for 'option %s %s'", + key, value); + ret = 0; + goto out; + } + + if ((inputll < opt->min) || (inputll > opt->max)) { + snprintf (errstr, 256, + "'%lld' in 'option %s %s' is out of range " + "[%"PRId64" - %"PRId64"]", + inputll, key, value, opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + uint64_t size = 0; + int ret = -1; + char errstr[256]; + + /* Check the range */ + if (gf_string2bytesize (value, &size) != 0) { + snprintf (errstr, 256, + "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check required for 'option %s %s'", + key, value); + ret = 0; + goto out; + } + + if ((size < opt->min) || (size > opt->max)) { + snprintf (errstr, 256, + "'%"PRId64"' in 'option %s %s' is out of range " + "[%"PRId64" - %"PRId64"]", + size, key, value, opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_bool (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + gf_boolean_t bool; + + + /* Check if the value is one of + '0|1|on|off|no|yes|true|false|enable|disable' */ + + if (gf_string2boolean (value, &bool) != 0) { + snprintf (errstr, 256, + "option %s %s: '%s' is not a valid boolean value", + key, value, value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_xlator (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + xlator_t *xlopt = NULL; + + + /* Check if the value is one of the xlators */ + xlopt = xl; + while (xlopt->prev) + xlopt = xlopt->prev; + + while (xlopt) { + if (strcmp (value, xlopt->name) == 0) { + ret = 0; + break; + } + xlopt = xlopt->next; + } + + if (!xlopt) { + snprintf (errstr, 256, + "option %s %s: '%s' is not a valid volume name", + key, value, value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_str (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + int i = 0; + char errstr[256]; + char given_array[4096] = {0,}; + + /* Check if the '*str' is valid */ + if (GF_OPTION_LIST_EMPTY(opt)) { + ret = 0; + goto out; + } + + for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i]; i++) { + #ifdef GF_DARWIN_HOST_OS + if (fnmatch (opt->value[i], value, 0) == 0) { + ret = 0; + break; + } + #else + if (fnmatch (opt->value[i], value, FNM_EXTMATCH) == 0) { + ret = 0; + break; + } + #endif + } + + if ((i <= ZR_OPTION_MAX_ARRAY_SIZE) && (!opt->value[i])) { + /* enter here only if + * 1. reached end of opt->value array and haven't + * validated input + * OR + * 2. valid input list is less than + * ZR_OPTION_MAX_ARRAY_SIZE and input has not + * matched all possible input values. + */ + + for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i];) { + strcat (given_array, opt->value[i]); + if (((++i) < ZR_OPTION_MAX_ARRAY_SIZE) && + (opt->value[i])) + strcat (given_array, ", "); + else + strcat (given_array, "."); + } + snprintf (errstr, 256, + "option %s %s: '%s' is not valid " + "(possible options are %s)", + key, value, value, given_array); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + uint32_t percent = 0; + + + /* Check if the value is valid percentage */ + if (gf_string2percent (value, &percent) != 0) { + snprintf (errstr, 256, + "invalid percent format \"%s\" in \"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if ((percent < 0) || (percent > 100)) { + snprintf (errstr, 256, + "'%d' in 'option %s %s' is out of range [0 - 100]", + percent, key, value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +/* TODO: clean this up */ +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]; + uint32_t percent = 0; + uint64_t size = 0; + + /* Check if the value is valid percentage */ + if (gf_string2percent (value, &percent) == 0) { + if (percent > 100) { + gf_log (xl->name, GF_LOG_DEBUG, + "value given was greater than 100, " + "assuming this is actually a size"); + if (gf_string2bytesize (value, &size) == 0) { + /* Check the range */ + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check rquired for " + "'option %s %s'", + key, value); + // It is a size + ret = 0; + goto out; + } + if ((size < opt->min) || (size > opt->max)) { + snprintf (errstr, 256, + "'%"PRId64"' in 'option %s %s' " + "is out of range [%"PRId64" - " + "%"PRId64"]", + size, key, value, + opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", + errstr); + goto out; + } + // It is a size + ret = 0; + goto out; + } else { + // It's not a percent or size + snprintf (errstr, 256, + "invalid number format \"%s\" " + "in \"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + } + // It is a percent + ret = 0; + goto out; + } else { + if (gf_string2bytesize (value, &size) == 0) { + /* Check the range */ + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check required for " + "'option %s %s'", + key, value); + // It is a size + ret = 0; + goto out; + } + if ((size < opt->min) || (size > opt->max)) { + snprintf (errstr, 256, + "'%"PRId64"' in 'option %s %s'" + " is out of range [%"PRId64" -" + " %"PRId64"]", + size, key, value, opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + } else { + // It's not a percent or size + snprintf (errstr, 256, + "invalid number format \"%s\" in \"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + //It is a size + ret = 0; + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_time (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + uint32_t input_time = 0; + + /* Check if the value is valid percentage */ + if (gf_string2time (value, &input_time) != 0) { + snprintf (errstr, 256, + "invalid time format \"%s\" in " + "\"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check required for " + "'option %s %s'", + key, value); + ret = 0; + goto out; + } + + if ((input_time < opt->min) || (input_time > opt->max)) { + snprintf (errstr, 256, + "'%"PRIu32"' in 'option %s %s' is " + "out of range [%"PRId64" - %"PRId64"]", + input_time, key, value, + opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_double (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + double val = 0.0; + + /* Check if the value is valid double */ + if (gf_string2double (value, &val) != 0) { + snprintf (errstr, 256, + "invalid double \"%s\" in \"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if (val < 0.0) { + snprintf (errstr, 256, + "invalid double \"%s\" in \"option %s\"", + value, key); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_log (xl->name, GF_LOG_DEBUG, + "no range check required for 'option %s %s'", + key, value); + ret = 0; + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + return ret; +} + + +static int +xlator_option_validate_addr (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + + if (!valid_internet_address ((char *)value)) { + snprintf (errstr, 256, + "internet address '%s' does not conform to standards.", + value); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + } + + if (ret && op_errstr) + *op_errstr = gf_strdup (errstr); + + ret = 0; + + return ret; +} + + +static int +xlator_option_validate_any (xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + return 0; +} + + +typedef int (xlator_option_validator_t) (xlator_t *xl, const char *key, + const char *value, + volume_option_t *opt, char **operrstr); + +int +xlator_option_validate (xlator_t *xl, char *key, char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + xlator_option_validator_t *validate; + xlator_option_validator_t *validators[] = { + [GF_OPTION_TYPE_PATH] = xlator_option_validate_path, + [GF_OPTION_TYPE_INT] = xlator_option_validate_int, + [GF_OPTION_TYPE_SIZET] = xlator_option_validate_sizet, + [GF_OPTION_TYPE_BOOL] = xlator_option_validate_bool, + [GF_OPTION_TYPE_XLATOR] = xlator_option_validate_xlator, + [GF_OPTION_TYPE_STR] = xlator_option_validate_str, + [GF_OPTION_TYPE_PERCENT] = xlator_option_validate_percent, + [GF_OPTION_TYPE_PERCENT_OR_SIZET] = + xlator_option_validate_percent_or_sizet, + [GF_OPTION_TYPE_TIME] = xlator_option_validate_time, + [GF_OPTION_TYPE_DOUBLE] = xlator_option_validate_double, + [GF_OPTION_TYPE_INTERNET_ADDRESS] = xlator_option_validate_addr, + [GF_OPTION_TYPE_ANY] = xlator_option_validate_any, + [GF_OPTION_TYPE_MAX] = NULL, + }; + + if (opt->type < 0 || opt->type >= GF_OPTION_TYPE_MAX) { + gf_log (xl->name, GF_LOG_ERROR, + "unknown option type '%d'", opt->type); + goto out; + } + + validate = validators[opt->type]; + + ret = validate (xl, key, value, opt, op_errstr); +out: + return ret; +} + + +static volume_option_t * +xlator_volume_option_get_list (volume_opt_list_t *vol_list, const char *key) +{ + volume_option_t *opt = NULL; + volume_option_t *found = NULL; + int index = 0; + int i = 0; + char *cmp_key = NULL; + + opt = vol_list->given_opt; + for (index = 0; opt[index].key && opt[index].key[0]; index++) { + for (i = 0; i < ZR_VOLUME_MAX_NUM_KEY; i++) { + cmp_key = opt[index].key[i]; + if (!cmp_key) + break; + if (fnmatch (cmp_key, key, FNM_NOESCAPE) == 0) { + found = &opt[index]; + goto out; + } + } + } +out: + return found; +} + + +volume_option_t * +xlator_volume_option_get (xlator_t *xl, const char *key) +{ + volume_opt_list_t *vol_list = NULL; + volume_option_t *found = NULL; + + list_for_each_entry (vol_list, &xl->volume_options, list) { + found = xlator_volume_option_get_list (vol_list, key); + if (found) + break; + } + + return found; +} + + +static void +xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data) +{ + xlator_t *xl = NULL; + volume_opt_list_t *vol_opt = NULL; + volume_option_t *opt = NULL; + int ret = 0; + char *errstr = NULL; + + struct { + xlator_t *this; + volume_opt_list_t *vol_opt; + char *errstr; + } *stub; + + stub = data; + xl = stub->this; + vol_opt = stub->vol_opt; + + opt = xlator_volume_option_get_list (vol_opt, key); + if (!opt) + return; + + ret = xlator_option_validate (xl, key, value->data, opt, &errstr); + if (errstr) + /* possible small leak of previously set stub->errstr */ + stub->errstr = errstr; + + if (fnmatch (opt->key[0], key, FNM_NOESCAPE) != 0) { + gf_log (xl->name, GF_LOG_WARNING, "option '%s' is deprecated, " + "preferred is '%s', continuing with correction", + key, opt->key[0]); + dict_set (dict, opt->key[0], value); + dict_del (dict, key); + } + return; +} + + +int +xlator_options_validate_list (xlator_t *xl, dict_t *options, + volume_opt_list_t *vol_opt, char **op_errstr) +{ + int ret = 0; + struct { + xlator_t *this; + volume_opt_list_t *vol_opt; + char *errstr; + } stub; + + stub.this = xl; + stub.vol_opt = vol_opt; + stub.errstr = NULL; + + dict_foreach (options, xl_opt_validate, &stub); + if (stub.errstr) { + ret = -1; + if (op_errstr) + *op_errstr = stub.errstr; + } + + return ret; +} + + +int +xlator_options_validate (xlator_t *xl, dict_t *options, char **op_errstr) +{ + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + + + if (!xl) { + gf_log (THIS->name, GF_LOG_DEBUG, "'this' not a valid ptr"); + ret = -1; + goto out; + } + + if (list_empty (&xl->volume_options)) + goto out; + + list_for_each_entry (vol_opt, &xl->volume_options, list) { + ret = xlator_options_validate_list (xl, options, vol_opt, + op_errstr); + } +out: + return ret; +} + + +int +xlator_validate_rec (xlator_t *xlator, char **op_errstr) +{ + int ret = -1; + xlator_list_t *trav = NULL; + xlator_t *old_THIS = NULL; + + GF_VALIDATE_OR_GOTO ("xlator", xlator, out); + + trav = xlator->children; + + while (trav) { + if (xlator_validate_rec (trav->xlator, op_errstr)) { + gf_log ("xlator", GF_LOG_WARNING, "validate_rec failed"); + goto out; + } + + trav = trav->next; + } + + if (xlator_dynload (xlator)) + gf_log (xlator->name, GF_LOG_DEBUG, "Did not load the symbols"); + + old_THIS = THIS; + THIS = xlator; + ret = xlator_options_validate (xlator, xlator->options, op_errstr); + THIS = old_THIS; + + if (ret) { + gf_log (xlator->name, GF_LOG_INFO, "%s", *op_errstr); + goto out; + } + + gf_log (xlator->name, GF_LOG_DEBUG, "Validated options"); + + ret = 0; +out: + return ret; +} + + +int +graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr) +{ + xlator_t *xlator = NULL; + int ret = -1; + + GF_ASSERT (graph); + + xlator = graph->first; + + ret = xlator_validate_rec (xlator, op_errstr); + + return ret; +} + + +static int +xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl) +{ + xlator_list_t *trav1 = NULL; + xlator_list_t *trav2 = NULL; + int32_t ret = -1; + xlator_t *old_THIS = NULL; + + GF_VALIDATE_OR_GOTO ("xlator", old_xl, out); + GF_VALIDATE_OR_GOTO ("xlator", new_xl, out); + + trav1 = old_xl->children; + trav2 = new_xl->children; + + while (trav1 && trav2) { + ret = xlator_reconfigure_rec (trav1->xlator, trav2->xlator); + if (ret) + goto out; + + gf_log (trav1->xlator->name, GF_LOG_DEBUG, "reconfigured"); + + trav1 = trav1->next; + trav2 = trav2->next; + } + + if (old_xl->reconfigure) { + old_THIS = THIS; + THIS = old_xl; + + ret = old_xl->reconfigure (old_xl, new_xl->options); + + THIS = old_THIS; + + if (ret) + goto out; + } else { + gf_log (old_xl->name, GF_LOG_DEBUG, "No reconfigure() found"); + } + + ret = 0; +out: + return ret; +} + + +int +xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl) +{ + xlator_t *new_top = NULL; + xlator_t *old_top = NULL; + + GF_ASSERT (old_xl); + GF_ASSERT (new_xl); + + old_top = old_xl; + new_top = new_xl; + + return xlator_reconfigure_rec (old_top, new_top); +} + + +int +xlator_option_info_list (volume_opt_list_t *list, char *key, + char **def_val, char **descr) +{ + int ret = -1; + volume_option_t *opt = NULL; + + + opt = xlator_volume_option_get_list (list, key); + if (!opt) + goto out; + + if (def_val) + *def_val = opt->default_value; + if (descr) + *descr = opt->description; + + ret = 0; +out: + return ret; +} + + +static int +not_null (char *in, char **out) +{ + if (!in || !out) + return -1; + + *out = in; + return 0; +} + + +static int +xl_by_name (char *in, xlator_t **out) +{ + xlator_t *xl = NULL; + + xl = xlator_search_by_name (THIS, in); + + if (!xl) + return -1; + *out = xl; + return 0; +} + + +static int +pc_or_size (char *in, uint64_t *out) +{ + uint32_t pc = 0; + int ret = 0; + + if (gf_string2percent (in, &pc) == 0) { + if (pc > 100) { + ret = gf_string2bytesize (in, out); + } else { + *out = pc; + } + } else { + ret = gf_string2bytesize (in, out); + } + return ret; +} + + +DEFINE_INIT_OPT(char *, str, not_null); +DEFINE_INIT_OPT(uint64_t, uint64, gf_string2uint64); +DEFINE_INIT_OPT(int64_t, int64, gf_string2int64); +DEFINE_INIT_OPT(uint32_t, uint32, gf_string2uint32); +DEFINE_INIT_OPT(int32_t, int32, gf_string2int32); +DEFINE_INIT_OPT(uint64_t, size, gf_string2bytesize); +DEFINE_INIT_OPT(uint32_t, percent, gf_string2percent); +DEFINE_INIT_OPT(uint64_t, percent_or_size, pc_or_size); +DEFINE_INIT_OPT(gf_boolean_t, bool, gf_string2boolean); +DEFINE_INIT_OPT(xlator_t *, xlator, xl_by_name); +DEFINE_INIT_OPT(char *, path, not_null); + + + +DEFINE_RECONF_OPT(char *, str, not_null); +DEFINE_RECONF_OPT(uint64_t, uint64, gf_string2uint64); +DEFINE_RECONF_OPT(int64_t, int64, gf_string2int64); +DEFINE_RECONF_OPT(uint32_t, uint32, gf_string2uint32); +DEFINE_RECONF_OPT(int32_t, int32, gf_string2int32); +DEFINE_RECONF_OPT(uint64_t, size, gf_string2bytesize); +DEFINE_RECONF_OPT(uint32_t, percent, gf_string2percent); +DEFINE_RECONF_OPT(uint64_t, percent_or_size, pc_or_size); +DEFINE_RECONF_OPT(gf_boolean_t, bool, gf_string2boolean); +DEFINE_RECONF_OPT(xlator_t *, xlator, xl_by_name); +DEFINE_RECONF_OPT(char *, path, not_null); diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h new file mode 100644 index 000000000..f95040c26 --- /dev/null +++ b/libglusterfs/src/options.h @@ -0,0 +1,248 @@ +/* + Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + <http://www.gnu.org/licenses/>. +*/ + +#ifndef _OPTIONS_H +#define _OPTIONS_H + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +#include "xlator.h" +/* Add possible new type of option you may need */ +typedef enum { + GF_OPTION_TYPE_ANY = 0, + GF_OPTION_TYPE_STR, + GF_OPTION_TYPE_INT, + GF_OPTION_TYPE_SIZET, + GF_OPTION_TYPE_PERCENT, + GF_OPTION_TYPE_PERCENT_OR_SIZET, + GF_OPTION_TYPE_BOOL, + GF_OPTION_TYPE_XLATOR, + GF_OPTION_TYPE_PATH, + GF_OPTION_TYPE_TIME, + GF_OPTION_TYPE_DOUBLE, + GF_OPTION_TYPE_INTERNET_ADDRESS, + GF_OPTION_TYPE_MAX, +} volume_option_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]; + /* 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]; + /* If specified, will check for one of + the value from this array */ + char *default_value; + char *description; /* about the key */ +} volume_option_t; + + +typedef struct vol_opt_list { + struct list_head list; + volume_option_t *given_opt; +} volume_opt_list_t; + + +int xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl); +int xlator_validate_rec (xlator_t *xlator, char **op_errstr); +int graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr); +int xlator_option_info_list (volume_opt_list_t *list, char *key, + char **def_val, char **descr); +/* +int validate_xlator_volume_options (xlator_t *xl, dict_t *options, + volume_option_t *opt, char **op_errstr); +*/ +int xlator_options_validate_list (xlator_t *xl, dict_t *options, + volume_opt_list_t *list, char **op_errstr); +int xlator_option_validate (xlator_t *xl, char *key, char *value, + volume_option_t *opt, char **op_errstr); +int xlator_options_validate (xlator_t *xl, dict_t *options, char **errstr); +volume_option_t * +xlator_volume_option_get (xlator_t *xl, const char *key); + + +#define DECLARE_INIT_OPT(type_t, type) \ +int \ +xlator_option_init_##type (xlator_t *this, dict_t *options, char *key, \ + type_t *val_p); + +DECLARE_INIT_OPT(char *, str); +DECLARE_INIT_OPT(uint64_t, uint64); +DECLARE_INIT_OPT(int64_t, int64); +DECLARE_INIT_OPT(uint32_t, uint32); +DECLARE_INIT_OPT(int32_t, int32); +DECLARE_INIT_OPT(uint64_t, size); +DECLARE_INIT_OPT(uint32_t, percent); +DECLARE_INIT_OPT(uint64_t, percent_or_size); +DECLARE_INIT_OPT(gf_boolean_t, bool); +DECLARE_INIT_OPT(xlator_t *, xlator); +DECLARE_INIT_OPT(char *, path); + + +#define DEFINE_INIT_OPT(type_t, type, conv) \ +int \ +xlator_option_init_##type (xlator_t *this, dict_t *options, char *key, \ + type_t *val_p) \ +{ \ + int ret = 0; \ + volume_option_t *opt = NULL; \ + char *def_value = NULL; \ + char *set_value = NULL; \ + char *value = NULL; \ + xlator_t *old_THIS = NULL; \ + \ + opt = xlator_volume_option_get (this, key); \ + if (!opt) { \ + gf_log (this->name, GF_LOG_WARNING, \ + "unknown option: %s", key); \ + ret = -1; \ + return ret; \ + } \ + def_value = opt->default_value; \ + ret = dict_get_str (options, key, &set_value); \ + \ + if (def_value) \ + value = def_value; \ + if (set_value) \ + value = set_value; \ + if (!value) { \ + gf_log (this->name, GF_LOG_TRACE, "option %s not set", \ + key); \ + return 0; \ + } \ + if (value == def_value) { \ + gf_log (this->name, GF_LOG_TRACE, \ + "option %s using default value %s", \ + key, value); \ + } else { \ + gf_log (this->name, GF_LOG_DEBUG, \ + "option %s using set value %s", \ + key, value); \ + } \ + old_THIS = THIS; \ + THIS = this; \ + ret = conv (value, val_p); \ + THIS = old_THIS; \ + if (ret) \ + return ret; \ + ret = xlator_option_validate (this, key, value, opt, NULL); \ + return ret; \ +} + +#define GF_OPTION_INIT(key, val, type, err_label) do { \ + int val_ret = 0; \ + val_ret = xlator_option_init_##type (THIS, THIS->options, \ + key, &(val)); \ + if (val_ret) \ + goto err_label; \ + } while (0) + + + +#define DECLARE_RECONF_OPT(type_t, type) \ +int \ +xlator_option_reconf_##type (xlator_t *this, dict_t *options, char *key,\ + type_t *val_p); + +DECLARE_RECONF_OPT(char *, str); +DECLARE_RECONF_OPT(uint64_t, uint64); +DECLARE_RECONF_OPT(int64_t, int64); +DECLARE_RECONF_OPT(uint32_t, uint32); +DECLARE_RECONF_OPT(int32_t, int32); +DECLARE_RECONF_OPT(uint64_t, size); +DECLARE_RECONF_OPT(uint32_t, percent); +DECLARE_RECONF_OPT(uint64_t, percent_or_size); +DECLARE_RECONF_OPT(gf_boolean_t, bool); +DECLARE_RECONF_OPT(xlator_t *, xlator); +DECLARE_RECONF_OPT(char *, path); + + +#define DEFINE_RECONF_OPT(type_t, type, conv) \ +int \ +xlator_option_reconf_##type (xlator_t *this, dict_t *options, char *key, \ + type_t *val_p) \ +{ \ + int ret = 0; \ + volume_option_t *opt = NULL; \ + char *def_value = NULL; \ + char *set_value = NULL; \ + char *value = NULL; \ + xlator_t *old_THIS = NULL; \ + \ + opt = xlator_volume_option_get (this, key); \ + if (!opt) { \ + gf_log (this->name, GF_LOG_WARNING, \ + "unknown option: %s", key); \ + ret = -1; \ + return ret; \ + } \ + def_value = opt->default_value; \ + ret = dict_get_str (options, key, &set_value); \ + \ + if (def_value) \ + value = def_value; \ + if (set_value) \ + value = set_value; \ + if (!value) { \ + gf_log (this->name, GF_LOG_TRACE, "option %s not set", \ + key); \ + return 0; \ + } \ + if (value == def_value) { \ + gf_log (this->name, GF_LOG_TRACE, \ + "option %s using default value %s", \ + key, value); \ + } else { \ + gf_log (this->name, GF_LOG_DEBUG, \ + "option %s using set value %s", \ + key, value); \ + } \ + old_THIS = THIS; \ + THIS = this; \ + ret = conv (value, val_p); \ + THIS = old_THIS; \ + if (ret) \ + return ret; \ + ret = xlator_option_validate (this, key, value, opt, NULL); \ + return ret; \ +} + +#define GF_OPTION_RECONF(key, val, opt, type, err_label) do { \ + int val_ret = 0; \ + val_ret = xlator_option_reconf_##type (THIS, opt, key, \ + &(val)); \ + if (val_ret) \ + goto err_label; \ + } while (0) + + +#endif /* !_OPTIONS_H */ diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 7d949da67..67ecabce5 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -29,1142 +29,82 @@ #include "defaults.h" #define SET_DEFAULT_FOP(fn) do { \ - if (!xl->fops->fn) \ - xl->fops->fn = default_##fn; \ - } while (0) + if (!xl->fops->fn) \ + xl->fops->fn = default_##fn; \ + } while (0) #define SET_DEFAULT_CBK(fn) do { \ - if (!xl->cbks->fn) \ - xl->cbks->fn = default_##fn; \ - } while (0) + if (!xl->cbks->fn) \ + xl->cbks->fn = default_##fn; \ + } while (0) -#define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) - static void fill_defaults (xlator_t *xl) { - if (xl == NULL) { - gf_log_callingfn ("xlator", GF_LOG_WARNING, "invalid argument"); - return; - } - - SET_DEFAULT_FOP (create); - SET_DEFAULT_FOP (open); - SET_DEFAULT_FOP (stat); - SET_DEFAULT_FOP (readlink); - SET_DEFAULT_FOP (mknod); - SET_DEFAULT_FOP (mkdir); - SET_DEFAULT_FOP (unlink); - SET_DEFAULT_FOP (rmdir); - SET_DEFAULT_FOP (symlink); - SET_DEFAULT_FOP (rename); - SET_DEFAULT_FOP (link); - SET_DEFAULT_FOP (truncate); - SET_DEFAULT_FOP (readv); - SET_DEFAULT_FOP (writev); - SET_DEFAULT_FOP (statfs); - SET_DEFAULT_FOP (flush); - SET_DEFAULT_FOP (fsync); - SET_DEFAULT_FOP (setxattr); - SET_DEFAULT_FOP (getxattr); - SET_DEFAULT_FOP (fsetxattr); - SET_DEFAULT_FOP (fgetxattr); - SET_DEFAULT_FOP (removexattr); - SET_DEFAULT_FOP (opendir); - SET_DEFAULT_FOP (readdir); - SET_DEFAULT_FOP (readdirp); - SET_DEFAULT_FOP (fsyncdir); - SET_DEFAULT_FOP (access); - SET_DEFAULT_FOP (ftruncate); - SET_DEFAULT_FOP (fstat); - SET_DEFAULT_FOP (lk); - SET_DEFAULT_FOP (inodelk); - SET_DEFAULT_FOP (finodelk); - SET_DEFAULT_FOP (entrylk); - SET_DEFAULT_FOP (fentrylk); - SET_DEFAULT_FOP (lookup); - SET_DEFAULT_FOP (rchecksum); - SET_DEFAULT_FOP (xattrop); - SET_DEFAULT_FOP (fxattrop); + if (xl == NULL) { + gf_log_callingfn ("xlator", GF_LOG_WARNING, "invalid argument"); + return; + } + + SET_DEFAULT_FOP (create); + SET_DEFAULT_FOP (open); + SET_DEFAULT_FOP (stat); + SET_DEFAULT_FOP (readlink); + SET_DEFAULT_FOP (mknod); + SET_DEFAULT_FOP (mkdir); + SET_DEFAULT_FOP (unlink); + SET_DEFAULT_FOP (rmdir); + SET_DEFAULT_FOP (symlink); + SET_DEFAULT_FOP (rename); + SET_DEFAULT_FOP (link); + SET_DEFAULT_FOP (truncate); + SET_DEFAULT_FOP (readv); + SET_DEFAULT_FOP (writev); + SET_DEFAULT_FOP (statfs); + SET_DEFAULT_FOP (flush); + SET_DEFAULT_FOP (fsync); + SET_DEFAULT_FOP (setxattr); + SET_DEFAULT_FOP (getxattr); + SET_DEFAULT_FOP (fsetxattr); + SET_DEFAULT_FOP (fgetxattr); + SET_DEFAULT_FOP (removexattr); + SET_DEFAULT_FOP (opendir); + SET_DEFAULT_FOP (readdir); + SET_DEFAULT_FOP (readdirp); + SET_DEFAULT_FOP (fsyncdir); + SET_DEFAULT_FOP (access); + SET_DEFAULT_FOP (ftruncate); + SET_DEFAULT_FOP (fstat); + SET_DEFAULT_FOP (lk); + SET_DEFAULT_FOP (inodelk); + SET_DEFAULT_FOP (finodelk); + SET_DEFAULT_FOP (entrylk); + SET_DEFAULT_FOP (fentrylk); + SET_DEFAULT_FOP (lookup); + SET_DEFAULT_FOP (rchecksum); + SET_DEFAULT_FOP (xattrop); + SET_DEFAULT_FOP (fxattrop); SET_DEFAULT_FOP (setattr); SET_DEFAULT_FOP (fsetattr); SET_DEFAULT_FOP (getspec); - SET_DEFAULT_CBK (release); - SET_DEFAULT_CBK (releasedir); - SET_DEFAULT_CBK (forget); + SET_DEFAULT_CBK (release); + SET_DEFAULT_CBK (releasedir); + SET_DEFAULT_CBK (forget); - if (!xl->notify) - xl->notify = default_notify; + if (!xl->notify) + xl->notify = default_notify; if (!xl->mem_acct_init) xl->mem_acct_init = default_mem_acct_init; - return; -} - -int -_volume_option_value_validate_attacherr (xlator_t *xl, - data_pair_t *pair, - volume_option_t *opt, - char **op_errstr) -{ - int i = 0; - int ret = -1; - uint64_t input_size = 0; - long long inputll = 0; - char errstr[256] = {0, }; - - /* Key is valid, validate the option */ - switch (opt->type) { - case GF_OPTION_TYPE_PATH: - { - if (strstr (pair->value->data, "../")) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid path given '%s'", - pair->value->data); - snprintf (errstr, 256, - "invalid path given '%s'", - pair->value->data); - - *op_errstr = gf_strdup (errstr); - ret = -1; - goto out; - } - - /* Make sure the given path is valid */ - if (pair->value->data[0] != '/') { - gf_log (xl->name, GF_LOG_WARNING, - "option %s %s: '%s' is not an " - "absolute path name", - pair->key, pair->value->data, - pair->value->data); - snprintf (errstr, 256, - "option %s %s: '%s' is not an " - "absolute path name", - pair->key, pair->value->data, - pair->value->data); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_INT: - { - /* Check the range */ - if (gf_string2longlong (pair->value->data, - &inputll) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - snprintf (errstr, 256, - "invalid number format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - break; - } - if ((inputll < opt->min) || - (inputll > opt->max)) { - gf_log (xl->name, GF_LOG_WARNING, - "'%lld' in 'option %s %s' is out of " - "range [%"PRId64" - %"PRId64"]", - inputll, pair->key, - pair->value->data, - opt->min, opt->max); - snprintf (errstr, 256, - "'%lld' in 'option %s %s' is out of " - "range [%"PRId64" - %"PRId64"]", - inputll, pair->key, - pair->value->data, - opt->min, opt->max); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_SIZET: - { - /* Check the range */ - if (gf_string2bytesize (pair->value->data, - &input_size) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid size format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - snprintf (errstr, 256, - "invalid size format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - break; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRId64"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - snprintf (errstr, 256, - "'%"PRId64"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_BOOL: - { - /* Check if the value is one of - '0|1|on|off|no|yes|true|false|enable|disable' */ - gf_boolean_t bool_value; - if (gf_string2boolean (pair->value->data, - &bool_value) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not a valid " - "boolean value", - pair->key, pair->value->data, - pair->value->data); - snprintf (errstr, 256, - "option %s %s: '%s' is not a valid " - "boolean value", - pair->key, pair->value->data, - pair->value->data); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_XLATOR: - { - /* Check if the value is one of the xlators */ - xlator_t *xlopt = xl; - while (xlopt->prev) - xlopt = xlopt->prev; - - while (xlopt) { - if (strcmp (pair->value->data, - xlopt->name) == 0) { - ret = 0; - break; - } - xlopt = xlopt->next; - } - if (!xlopt) { - gf_log (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not a " - "valid volume name", - pair->key, pair->value->data, - pair->value->data); - snprintf (errstr, 256, - "option %s %s: '%s' is not a " - "valid volume name", - pair->key, pair->value->data, - pair->value->data); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_STR: - { - /* Check if the '*str' is valid */ - if (GF_OPTION_LIST_EMPTY(opt)) { - ret = 0; - goto out; - } - - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && - opt->value[i]; i++) { - if (fnmatch (opt->value[i], pair->value->data, - FNM_EXTMATCH) == 0) { - ret = 0; - break; - } - } - - if ((i == ZR_OPTION_MAX_ARRAY_SIZE) - || ((i < ZR_OPTION_MAX_ARRAY_SIZE) - && (!opt->value[i]))) { - /* enter here only if - * 1. reached end of opt->value array and haven't - * validated input - * OR - * 2. valid input list is less than - * ZR_OPTION_MAX_ARRAY_SIZE and input has not - * matched all possible input values. - */ - char given_array[4096] = {0,}; - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && - opt->value[i];) { - strcat (given_array, opt->value[i]); - if(((++i) < ZR_OPTION_MAX_ARRAY_SIZE) && - (opt->value[i])) - strcat (given_array, ", "); - else - strcat (given_array, "."); - } - - gf_log_callingfn (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not valid " - "(possible options are %s)", - pair->key, pair->value->data, - pair->value->data, given_array); - snprintf (errstr, 256, - "option %s %s: '%s' is not valid " - "(possible options are %s)", - pair->key, pair->value->data, - pair->value->data, given_array); - - *op_errstr = gf_strdup (errstr); - goto out; - } - } - break; - case GF_OPTION_TYPE_PERCENT: - { - uint32_t percent = 0; - - - /* Check if the value is valid percentage */ - if (gf_string2percent (pair->value->data, - &percent) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid percent format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - snprintf (errstr, 256, - "invalid percent format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if ((percent < 0) || (percent > 100)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%d' in 'option %s %s' is out of " - "range [0 - 100]", - percent, pair->key, - pair->value->data); - snprintf (errstr, 256, - "'%d' in 'option %s %s' is out of " - "range [0 - 100]", - percent, pair->key, - pair->value->data); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_PERCENT_OR_SIZET: - { - uint32_t percent = 0; - uint64_t input_size = 0; - - /* Check if the value is valid percentage */ - if (gf_string2percent (pair->value->data, - &percent) == 0) { - if (percent > 100) { - gf_log (xl->name, GF_LOG_DEBUG, - "value given was greater than 100, " - "assuming this is actually a size"); - if (gf_string2bytesize (pair->value->data, - &input_size) == 0) { - /* Check the range */ - if ((opt->min == 0) && - (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check " - "required for " - "'option %s %s'", - pair->key, - pair->value->data); - // It is a size - ret = 0; - goto out; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRId64"' in " - "'option %s %s' is out" - " of range [%"PRId64"" - "- %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - snprintf (errstr, 256, - "'%"PRId64"' in " - "'option %s %s' is " - " out of range [" - "%"PRId64"- %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - - *op_errstr = gf_strdup (errstr); - goto out; - } - // It is a size - ret = 0; - goto out; - } else { - // It's not a percent or size - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - - snprintf (errstr, 256, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - - - *op_errstr = gf_strdup (errstr); - goto out; - } - - } - // It is a percent - ret = 0; - goto out; - } else { - if (gf_string2bytesize (pair->value->data, - &input_size) == 0) { - /* Check the range */ - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - // It is a size - ret = 0; - goto out; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRId64"' in 'option %s %s'" - " is out of range [%"PRId64" -" - " %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - snprintf (errstr, 256, - "'%"PRId64"' in 'option %s %s'" - " is out of range [%"PRId64" -" - " %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - - *op_errstr = gf_strdup (errstr); - goto out; - } - } else { - // It's not a percent or size - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - snprintf (errstr, 256, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - //It is a size - ret = 0; - goto out; - } - - } - break; - case GF_OPTION_TYPE_TIME: - { - uint32_t input_time = 0; - - /* Check if the value is valid percentage */ - if (gf_string2time (pair->value->data, - &input_time) != 0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid time format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - - snprintf (errstr, 256, - "invalid time format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - goto out; - } - if ((input_time < opt->min) || - (input_time > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRIu32"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_time, pair->key, - pair->value->data, - opt->min, opt->max); - - snprintf (errstr, 256, - "'%"PRIu32"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_time, pair->key, - pair->value->data, - opt->min, opt->max); - - *op_errstr = gf_strdup (errstr); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_DOUBLE: - { - double input_time = 0.0; - - /* Check if the value is valid double */ - if (gf_string2double (pair->value->data, - &input_time) != 0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid double \"%s\" in \"option %s\"", - pair->value->data, pair->key); - - snprintf (errstr, 256, - "invalid double \"%s\" in \"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if (input_time < 0.0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid time format \"%s\" in \"option %s\"", - pair->value->data, pair->key); - - snprintf (errstr, 256, - "invalid double \"%s\" in \"option %s\"", - pair->value->data, pair->key); - - *op_errstr = gf_strdup (errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for 'option %s %s'", - pair->key, pair->value->data); - ret = 0; - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_INTERNET_ADDRESS: - { - if (!valid_internet_address (pair->value->data)) { - gf_log (xl->name, GF_LOG_WARNING, "internet address '%s'" - " does not conform to standards.", - pair->value->data); - - snprintf (errstr, 256, - "internet address '%s'" - " does not conform to standards.", - pair->value->data); - - *op_errstr = gf_strdup (errstr); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_ANY: - /* NO CHECK */ - ret = 0; - break; - } - -out: - return ret; -} - - -int -_volume_option_value_validate (xlator_t *xl, - data_pair_t *pair, - volume_option_t *opt) -{ - int i = 0; - int ret = -1; - uint64_t input_size = 0; - long long inputll = 0; - - /* Key is valid, validate the option */ - switch (opt->type) { - case GF_OPTION_TYPE_PATH: - { - if (strstr (pair->value->data, "../")) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid path given '%s'", - pair->value->data); - ret = -1; - goto out; - } - - /* Make sure the given path is valid */ - if (pair->value->data[0] != '/') { - gf_log (xl->name, GF_LOG_WARNING, - "option %s %s: '%s' is not an " - "absolute path name", - pair->key, pair->value->data, - pair->value->data); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_INT: - { - /* Check the range */ - if (gf_string2longlong (pair->value->data, - &inputll) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - break; - } - if ((inputll < opt->min) || - (inputll > opt->max)) { - gf_log (xl->name, GF_LOG_WARNING, - "'%lld' in 'option %s %s' is out of " - "range [%"PRId64" - %"PRId64"]", - inputll, pair->key, - pair->value->data, - opt->min, opt->max); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_SIZET: - { - /* Check the range */ - if (gf_string2bytesize (pair->value->data, - &input_size) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid size format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - break; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_WARNING, - "'%"PRId64"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_BOOL: - { - /* Check if the value is one of - '0|1|on|off|no|yes|true|false|enable|disable' */ - gf_boolean_t bool_value; - if (gf_string2boolean (pair->value->data, - &bool_value) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not a valid " - "boolean value", - pair->key, pair->value->data, - pair->value->data); - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_XLATOR: - { - /* Check if the value is one of the xlators */ - xlator_t *xlopt = xl; - while (xlopt->prev) - xlopt = xlopt->prev; - - while (xlopt) { - if (strcmp (pair->value->data, - xlopt->name) == 0) { - ret = 0; - break; - } - xlopt = xlopt->next; - } - if (!xlopt) { - gf_log (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not a " - "valid volume name", - pair->key, pair->value->data, - pair->value->data); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_STR: - { - /* Check if the '*str' is valid */ - if (GF_OPTION_LIST_EMPTY(opt)) { - ret = 0; - goto out; - } - - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && - opt->value[i]; i++) { - #ifdef GF_DARWIN_HOST_OS - if (fnmatch (opt->value[i], - pair->value->data, 0) == 0) { - #else - if (fnmatch (opt->value[i], - pair->value->data, FNM_EXTMATCH) == 0) { - #endif - ret = 0; - break; - } - } - - if ((i == ZR_OPTION_MAX_ARRAY_SIZE) - || ((i < ZR_OPTION_MAX_ARRAY_SIZE) - && (!opt->value[i]))) { - /* enter here only if - * 1. reached end of opt->value array and haven't - * validated input - * OR - * 2. valid input list is less than - * ZR_OPTION_MAX_ARRAY_SIZE and input has not - * matched all possible input values. - */ - char given_array[4096] = {0,}; - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && - opt->value[i];) { - strcat (given_array, opt->value[i]); - if(((++i) < ZR_OPTION_MAX_ARRAY_SIZE) && - (opt->value[i])) - strcat (given_array, ", "); - else - strcat (given_array, "."); - } - - gf_log (xl->name, GF_LOG_ERROR, - "option %s %s: '%s' is not valid " - "(possible options are %s)", - pair->key, pair->value->data, - pair->value->data, given_array); - - goto out; - } - } - break; - case GF_OPTION_TYPE_PERCENT: - { - uint32_t percent = 0; - - - /* Check if the value is valid percentage */ - if (gf_string2percent (pair->value->data, - &percent) != 0) { - gf_log (xl->name, GF_LOG_ERROR, - "invalid percent format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if ((percent < 0) || (percent > 100)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%d' in 'option %s %s' is out of " - "range [0 - 100]", - percent, pair->key, - pair->value->data); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_PERCENT_OR_SIZET: - { - uint32_t percent = 0; - uint64_t input_size = 0; - - /* Check if the value is valid percentage */ - if (gf_string2percent (pair->value->data, - &percent) == 0) { - if (percent > 100) { - gf_log (xl->name, GF_LOG_DEBUG, - "value given was greater than 100, " - "assuming this is actually a size"); - if (gf_string2bytesize (pair->value->data, - &input_size) == 0) { - /* Check the range */ - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check " - "required for " - "'option %s %s'", - pair->key, - pair->value->data); - // It is a size - ret = 0; - goto out; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRId64"' in " - "'option %s %s' is out" - " of range [%"PRId64"" - "- %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - } - // It is a size - ret = 0; - goto out; - } else { - // It's not a percent or size - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - } - - } - // It is a percent - ret = 0; - goto out; - } else { - if (gf_string2bytesize (pair->value->data, - &input_size) == 0) { - /* Check the range */ - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - // It is a size - ret = 0; - goto out; - } - if ((input_size < opt->min) || - (input_size > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRId64"' in 'option %s %s'" - " is out of range [%"PRId64" -" - " %"PRId64"]", - input_size, pair->key, - pair->value->data, - opt->min, opt->max); - } - } else { - // It's not a percent or size - gf_log (xl->name, GF_LOG_ERROR, - "invalid number format \"%s\" " - "in \"option %s\"", - pair->value->data, pair->key); - } - //It is a size - ret = 0; - goto out; - } - - } - break; - case GF_OPTION_TYPE_TIME: - { - uint32_t input_time = 0; - - /* Check if the value is valid percentage */ - if (gf_string2time (pair->value->data, - &input_time) != 0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid time format \"%s\" in " - "\"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for " - "'option %s %s'", - pair->key, pair->value->data); - ret = 0; - goto out; - } - if ((input_time < opt->min) || - (input_time > opt->max)) { - gf_log (xl->name, GF_LOG_ERROR, - "'%"PRIu32"' in 'option %s %s' is " - "out of range [%"PRId64" - %"PRId64"]", - input_time, pair->key, - pair->value->data, - opt->min, opt->max); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_DOUBLE: - { - double input_time = 0.0; - - /* Check if the value is valid double */ - if (gf_string2double (pair->value->data, - &input_time) != 0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid time format \"%s\" in \"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if (input_time < 0.0) { - gf_log (xl->name, - GF_LOG_ERROR, - "invalid time format \"%s\" in \"option %s\"", - pair->value->data, pair->key); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_log (xl->name, GF_LOG_DEBUG, - "no range check required for 'option %s %s'", - pair->key, pair->value->data); - ret = 0; - goto out; - } - ret = 0; - } - break; - case GF_OPTION_TYPE_INTERNET_ADDRESS: - { - if (!valid_internet_address (pair->value->data)) { - gf_log (xl->name, GF_LOG_WARNING, "internet address '%s'" - " does not conform to standards.", - pair->value->data); - } - ret = 0; - } - break; - case GF_OPTION_TYPE_ANY: - /* NO CHECK */ - ret = 0; - break; - } - -out: - return ret; -} - -int -validate_xlator_volume_options_attacherr (xlator_t *xl, - volume_option_t *opt, - char **op_errstr) -{ - int i = 0; - int ret = -1; - int index = 0; - volume_option_t *trav = NULL; - data_pair_t *pairs = NULL; - - if (!opt) { - ret = 0; - goto out; - } - - /* First search for not supported options, if any report error */ - pairs = xl->options->members_list; - while (pairs) { - ret = -1; - for (index = 0; - opt[index].key && opt[index].key[0] ; index++) { - trav = &(opt[index]); - for (i = 0 ; - (i < ZR_VOLUME_MAX_NUM_KEY) && - trav->key[i]; i++) { - /* Check if the key is valid */ - if (fnmatch (trav->key[i], - pairs->key, FNM_NOESCAPE) == 0) { - ret = 0; - break; - } - } - if (!ret) { - if (i) { - gf_log (xl->name, GF_LOG_WARNING, - "option '%s' is deprecated, " - "preferred is '%s', continuing" - " with correction", - trav->key[i], trav->key[0]); - /* TODO: some bytes lost */ - pairs->key = gf_strdup (trav->key[0]); - } - break; - } - } - if (!ret) { - ret = _volume_option_value_validate_attacherr (xl, - pairs, - trav, - op_errstr); - if (-1 == ret) { - goto out; - } - } - - pairs = pairs->next; - } - - ret = 0; - out: - return ret; + return; } int -validate_xlator_volume_options (xlator_t *xl, volume_option_t *opt) -{ - int i = 0; - int ret = -1; - int index = 0; - volume_option_t *trav = NULL; - data_pair_t *pairs = NULL; - - if (!opt) { - ret = 0; - goto out; - } - - /* First search for not supported options, if any report error */ - pairs = xl->options->members_list; - while (pairs) { - ret = -1; - for (index = 0; opt[index].key && opt[index].key[0] ; index++) { - trav = &(opt[index]); - for (i = 0 ; (i < ZR_VOLUME_MAX_NUM_KEY) && trav->key[i]; i++) { - /* Check if the key is valid */ - if (fnmatch (trav->key[i], - pairs->key, FNM_NOESCAPE) == 0) { - ret = 0; - break; - } - } - if (!ret) { - if (i) { - gf_log (xl->name, GF_LOG_WARNING, - "option '%s' is deprecated, " - "preferred is '%s', continuing" - " with correction", - trav->key[i], trav->key[0]); - /* TODO: some bytes lost */ - pairs->key = gf_strdup (trav->key[0]); - } - break; - } - } - if (!ret) { - ret = _volume_option_value_validate (xl, pairs, trav); - if (-1 == ret) { - goto out; - } - } - - pairs = pairs->next; - } - - ret = 0; - out: - return ret; -} - -int32_t xlator_set_type_virtual (xlator_t *xl, const char *type) { GF_VALIDATE_OR_GOTO ("xlator", xl, out); @@ -1178,9 +118,11 @@ xlator_set_type_virtual (xlator_t *xl, const char *type) out: return -1; } -int32_t + + +int xlator_volopt_dynload (char *xlator_type, void **dl_handle, - volume_opt_list_t *opt_list) + volume_opt_list_t *opt_list) { int ret = -1; char *name = NULL; @@ -1237,17 +179,19 @@ xlator_volopt_dynload (char *xlator_type, void **dl_handle, } -int32_t + +int xlator_dynload (xlator_t *xl) { - int ret = -1; - char *name = NULL; - void *handle = NULL; - volume_opt_list_t *vol_opt = NULL; + int ret = -1; + char *name = NULL; + void *handle = NULL; + volume_opt_list_t *vol_opt = NULL; + GF_VALIDATE_OR_GOTO ("xlator", xl, out); - ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type); + ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type); if (-1 == ret) { gf_log ("xlator", GF_LOG_ERROR, "asprintf failed"); goto out; @@ -1255,48 +199,48 @@ xlator_dynload (xlator_t *xl) ret = -1; - gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name); + gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name); - handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); - if (!handle) { - gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ()); + handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); + if (!handle) { + gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ()); goto out; - } + } xl->dlhandle = handle; - if (!(xl->fops = dlsym (handle, "fops"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(fops) on %s", - dlerror ()); + if (!(xl->fops = dlsym (handle, "fops"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(fops) on %s", + dlerror ()); goto out; - } + } - if (!(xl->cbks = dlsym (handle, "cbks"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(cbks) on %s", - dlerror ()); + if (!(xl->cbks = dlsym (handle, "cbks"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(cbks) on %s", + dlerror ()); goto out; - } + } - if (!(xl->init = dlsym (handle, "init"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s", - dlerror ()); + if (!(xl->init = dlsym (handle, "init"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s", + dlerror ()); goto out; - } + } - if (!(xl->fini = dlsym (handle, "fini"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s", - dlerror ()); + if (!(xl->fini = dlsym (handle, "fini"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s", + dlerror ()); goto out; - } + } - if (!(xl->notify = dlsym (handle, "notify"))) { - gf_log ("xlator", GF_LOG_DEBUG, - "dlsym(notify) on %s -- neglecting", dlerror ()); - } + if (!(xl->notify = dlsym (handle, "notify"))) { + gf_log ("xlator", GF_LOG_DEBUG, + "dlsym(notify) on %s -- neglecting", dlerror ()); + } - if (!(xl->dumpops = dlsym (handle, "dumpops"))) { - gf_log ("xlator", GF_LOG_DEBUG, - "dlsym(dumpops) on %s -- neglecting", dlerror ()); - } + if (!(xl->dumpops = dlsym (handle, "dumpops"))) { + gf_log ("xlator", GF_LOG_DEBUG, + "dlsym(dumpops) on %s -- neglecting", dlerror ()); + } if (!(xl->mem_acct_init = dlsym (handle, "mem_acct_init"))) { gf_log (xl->name, GF_LOG_DEBUG, @@ -1304,47 +248,40 @@ xlator_dynload (xlator_t *xl) dlerror ()); } - if (!(xl->reconfigure = dlsym (handle, "reconfigure"))) { - gf_log ("xlator", GF_LOG_DEBUG, - "dlsym(reconfigure) on %s -- neglecting", - dlerror()); - } - - if (!(xl->validate_options = dlsym (handle, "validate_options"))) { + if (!(xl->reconfigure = dlsym (handle, "reconfigure"))) { gf_log ("xlator", GF_LOG_DEBUG, - "dlsym(validate_options) on %s -- neglecting", + "dlsym(reconfigure) on %s -- neglecting", dlerror()); } + INIT_LIST_HEAD (&xl->volume_options); - INIT_LIST_HEAD (&xl->volume_options); - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), + vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); if (!vol_opt) { goto out; } - if (!(vol_opt->given_opt = dlsym (handle, "options"))) { - dlerror (); - gf_log (xl->name, GF_LOG_DEBUG, - "Strict option validation not enforced -- neglecting"); - } - list_add_tail (&vol_opt->list, &xl->volume_options); + if (!(vol_opt->given_opt = dlsym (handle, "options"))) { + dlerror (); + gf_log (xl->name, GF_LOG_DEBUG, + "Strict option validation not enforced -- neglecting"); + } + list_add_tail (&vol_opt->list, &xl->volume_options); - fill_defaults (xl); + fill_defaults (xl); ret = 0; out: if (name) GF_FREE (name); - return ret; + return ret; } -int32_t +int xlator_set_type (xlator_t *xl, const char *type) { int ret = 0; @@ -1359,31 +296,30 @@ xlator_set_type (xlator_t *xl, const char *type) void xlator_foreach (xlator_t *this, - void (*fn)(xlator_t *each, - void *data), - void *data) + void (*fn)(xlator_t *each, + void *data), + void *data) { - xlator_t *first = NULL; + xlator_t *first = NULL; xlator_t *old_THIS = NULL; GF_VALIDATE_OR_GOTO ("xlator", this, out); GF_VALIDATE_OR_GOTO ("xlator", fn, out); - GF_VALIDATE_OR_GOTO ("xlator", data, out); - first = this; + first = this; - while (first->prev) - first = first->prev; + while (first->prev) + first = first->prev; - while (first) { + while (first) { old_THIS = THIS; THIS = first; - fn (first, data); + fn (first, data); THIS = old_THIS; - first = first->next; - } + first = first->next; + } out: return; @@ -1393,24 +329,24 @@ out: xlator_t * xlator_search_by_name (xlator_t *any, const char *name) { - xlator_t *search = NULL; + xlator_t *search = NULL; GF_VALIDATE_OR_GOTO ("xlator", any, out); GF_VALIDATE_OR_GOTO ("xlator", name, out); - search = any; + search = any; - while (search->prev) - search = search->prev; + while (search->prev) + search = search->prev; - while (search) { - if (!strcmp (search->name, name)) - break; - search = search->next; - } + while (search) { + if (!strcmp (search->name, name)) + break; + search = search->next; + } out: - return search; + return search; } @@ -1434,7 +370,7 @@ __xlator_init(xlator_t *xl) int xlator_init (xlator_t *xl) { - int32_t ret = -1; + int32_t ret = -1; GF_VALIDATE_OR_GOTO ("xlator", xl, out); @@ -1460,145 +396,49 @@ xlator_init (xlator_t *xl) ret = 0; out: - return ret; + return ret; } static void xlator_fini_rec (xlator_t *xl) { - xlator_list_t *trav = NULL; + xlator_list_t *trav = NULL; xlator_t *old_THIS = NULL; GF_VALIDATE_OR_GOTO ("xlator", xl, out); - trav = xl->children; - - while (trav) { - if (!trav->xlator->init_succeeded) { - break; - } - - xlator_fini_rec (trav->xlator); - gf_log (trav->xlator->name, GF_LOG_DEBUG, "fini done"); - trav = trav->next; - } - - if (xl->init_succeeded) { - if (xl->fini) { - old_THIS = THIS; - THIS = xl; - - xl->fini (xl); - - THIS = old_THIS; - } else { - gf_log (xl->name, GF_LOG_DEBUG, "No fini() found"); - } - xl->init_succeeded = 0; - } - -out: - return; -} - -static int -xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl) -{ - xlator_list_t *trav1 = NULL; - xlator_list_t *trav2 = NULL; - int32_t ret = -1; - xlator_t *old_THIS = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", old_xl, out); - GF_VALIDATE_OR_GOTO ("xlator", new_xl, out); - - trav1 = old_xl->children; - trav2 = new_xl->children; - - while (trav1 && trav2) { - ret = xlator_reconfigure_rec (trav1->xlator, trav2->xlator); - if (ret) - goto out; - - gf_log (trav1->xlator->name, GF_LOG_DEBUG, "reconfigured"); - - trav1 = trav1->next; - trav2 = trav2->next; - } - - if (old_xl->reconfigure) { - old_THIS = THIS; - THIS = old_xl; - - ret = old_xl->reconfigure (old_xl, new_xl->options); - - THIS = old_THIS; - - if (ret) - goto out; - } else { - gf_log (old_xl->name, GF_LOG_DEBUG, "No reconfigure() found"); - } - - ret = 0; -out: - return ret; -} - -int -xlator_validate_rec (xlator_t *xlator, char **op_errstr) -{ - int ret = -1; - xlator_list_t *trav = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", xlator, out); - - trav = xlator->children; + trav = xl->children; while (trav) { - if (xlator_validate_rec (trav->xlator, op_errstr)) { - gf_log ("xlator", GF_LOG_WARNING, "validate_rec failed"); - goto out; + if (!trav->xlator->init_succeeded) { + break; } + xlator_fini_rec (trav->xlator); + gf_log (trav->xlator->name, GF_LOG_DEBUG, "fini done"); trav = trav->next; } - if (xlator_dynload (xlator)) - gf_log (xlator->name, GF_LOG_DEBUG, "Did not load the symbols"); + if (xl->init_succeeded) { + if (xl->fini) { + old_THIS = THIS; + THIS = xl; - if (xlator->validate_options) { - if (xlator->validate_options (xlator, op_errstr)) { - gf_log (xlator->name, GF_LOG_INFO, "%s", *op_errstr); - goto out; - } - gf_log (xlator->name, GF_LOG_DEBUG, "Validated option"); + xl->fini (xl); + THIS = old_THIS; + } else { + gf_log (xl->name, GF_LOG_DEBUG, "No fini() found"); + } + xl->init_succeeded = 0; } - gf_log (xlator->name, GF_LOG_DEBUG, "No validate_options() found"); - - ret = 0; out: - return ret; + return; } -int -graph_reconf_validateopt (glusterfs_graph_t *graph, - char **op_errstr) -{ - xlator_t *xlator = NULL; - int ret = -1; - GF_ASSERT (graph); - - xlator = graph->first; - - ret = xlator_validate_rec (xlator, op_errstr); - - return ret; -} int xlator_notify (xlator_t *xl, int event, void *data, ...) { @@ -1646,40 +486,27 @@ xlator_mem_acct_init (xlator_t *xl, int num_types) return 0; } + void xlator_tree_fini (xlator_t *xl) { - xlator_t *top = NULL; + xlator_t *top = NULL; GF_VALIDATE_OR_GOTO ("xlator", xl, out); - top = xl; - xlator_fini_rec (top); + top = xl; + xlator_fini_rec (top); out: return; } -int -xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl) -{ - xlator_t *new_top = NULL; - xlator_t *old_top = NULL; - - GF_ASSERT (old_xl); - GF_ASSERT (new_xl); - - old_top = old_xl; - new_top = new_xl; - - return xlator_reconfigure_rec (old_top, new_top); -} - int xlator_tree_free (xlator_t *tree) { - xlator_t *trav = tree, *prev = tree; + xlator_t *trav = tree; + xlator_t *prev = tree; if (!tree) { gf_log ("parser", GF_LOG_ERROR, "Translator tree not found"); @@ -1721,32 +548,32 @@ loc_wipe (loc_t *loc) int loc_copy (loc_t *dst, loc_t *src) { - int ret = -1; + int ret = -1; GF_VALIDATE_OR_GOTO ("xlator", dst, err); GF_VALIDATE_OR_GOTO ("xlator", src, err); - dst->ino = src->ino; + dst->ino = src->ino; uuid_copy (dst->gfid, src->gfid); uuid_copy (dst->pargfid, src->pargfid); - if (src->inode) - dst->inode = inode_ref (src->inode); + if (src->inode) + dst->inode = inode_ref (src->inode); - if (src->parent) - dst->parent = inode_ref (src->parent); + if (src->parent) + dst->parent = inode_ref (src->parent); dst->path = gf_strdup (src->path); - if (!dst->path) - goto out; + if (!dst->path) + goto out; - dst->name = strrchr (dst->path, '/'); - if (dst->name) - dst->name++; + dst->name = strrchr (dst->path, '/'); + if (dst->name) + dst->name++; - ret = 0; + ret = 0; out: if (ret == -1) { if (dst->inode) @@ -1757,7 +584,7 @@ out: } err: - return ret; + return ret; } @@ -1807,6 +634,8 @@ xlator_destroy (xlator_t *xl) return 0; } + + int is_gf_log_command (xlator_t *this, const char *name, char *value) { @@ -1850,6 +679,7 @@ is_gf_log_command (xlator_t *this, const char *name, char *value) ret = 0; goto out; } + if (!strcmp (name, "trusted.glusterfs.fuse.set-log-level")) { /* */ gf_log (this->name, gf_log_get_xl_loglevel (this), @@ -1883,6 +713,7 @@ out: return ret; } + int glusterd_check_log_level (const char *value) { @@ -1911,50 +742,3 @@ glusterd_check_log_level (const char *value) return log_level; } -int -xlator_get_volopt_info (struct list_head *opt_list, char *key, char **def_val, - char **descr) -{ - - int index = 0; - int ret = -1; - volume_opt_list_t *vol_list = NULL; - volume_option_t *opt = NULL; - - if (!opt_list || !key || !def_val ) { - gf_log ("", GF_LOG_WARNING, " Parameters to the function not " - "valid"); - ret = -1; - goto out; - } - - if (list_empty (opt_list)) { - gf_log ("xlator", GF_LOG_WARNING, "No elements in Volume option" - " list"); - ret = -1; - goto out; - } - - - vol_list = list_entry (opt_list->next, volume_opt_list_t, list); - - opt = vol_list->given_opt; - - for (index = 0; opt[index].key && opt[index].key[0] ; index++) { - if (strncmp (key, opt[index].key[0], strlen (key))) - continue; - - *def_val = opt[index].default_value; - if (descr) - *descr = opt[index].description; - ret = 0; - goto out; - } - - ret = -1; - -out: - gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); - return ret; - -} diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 1ecde5d5f..725a9a2d0 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -74,6 +74,8 @@ typedef int32_t (*event_notify_fn_t) (xlator_t *this, int32_t event, void *data, #include "fd.h" #include "globals.h" #include "iatt.h" +#include "options.h" + struct _loc { const char *path; @@ -756,46 +758,6 @@ typedef struct xlator_list { struct xlator_list *next; } xlator_list_t; -/* Add possible new type of option you may need */ -typedef enum { - GF_OPTION_TYPE_ANY = 0, - GF_OPTION_TYPE_STR, - GF_OPTION_TYPE_INT, - GF_OPTION_TYPE_SIZET, - GF_OPTION_TYPE_PERCENT, - GF_OPTION_TYPE_PERCENT_OR_SIZET, - GF_OPTION_TYPE_BOOL, - GF_OPTION_TYPE_XLATOR, - GF_OPTION_TYPE_PATH, - GF_OPTION_TYPE_TIME, - GF_OPTION_TYPE_DOUBLE, - GF_OPTION_TYPE_INTERNET_ADDRESS, -} volume_option_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]; - /* 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]; - /* If specified, will check for one of - the value from this array */ - char *default_value; - char *description; /* about the key */ -} volume_option_t; - - -typedef struct vol_opt_list { - struct list_head list; - volume_option_t *given_opt; -} volume_opt_list_t; - struct _xlator { /* Built during parsing */ @@ -818,7 +780,6 @@ struct _xlator { int32_t (*init) (xlator_t *this); int32_t (*reconfigure) (xlator_t *this, dict_t *options); int32_t (*mem_acct_init) (xlator_t *this); - int32_t (*validate_options) (xlator_t *this, char **op_errstr); event_notify_fn_t notify; gf_loglevel_t loglevel; /* Log level for translator */ @@ -837,8 +798,6 @@ struct _xlator { #define xlator_has_parent(xl) (xl->parents != NULL) -int validate_xlator_volume_options (xlator_t *xl, volume_option_t *opt); - int32_t xlator_set_type_virtual (xlator_t *xl, const char *type); int32_t xlator_set_type (xlator_t *xl, const char *type); @@ -870,20 +829,8 @@ int loc_copy (loc_t *dst, loc_t *src); #define loc_dup(src, dst) loc_copy(dst, src) void loc_wipe (loc_t *loc); int xlator_mem_acct_init (xlator_t *xl, int num_types); -int xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl); int is_gf_log_command (xlator_t *trans, const char *name, char *value); -int xlator_validate_rec (xlator_t *xlator, char **op_errstr); -int graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr); int glusterd_check_log_level (const char *value); -int validate_xlator_volume_options_attacherr (xlator_t *xl, - volume_option_t *opt, - char **op_errstr); -int _volume_option_value_validate_attacherr (xlator_t *xl, - data_pair_t *pair, - volume_option_t *opt, - char **op_errstr); -int32_t xlator_volopt_dynload (char *xlator_type, void **dl_handle, - volume_opt_list_t *vol_opt_handle); -int xlator_get_volopt_info (struct list_head *opt_list, char *key, - char **def_val, char **descr); +int xlator_volopt_dynload (char *xlator_type, void **dl_handle, + volume_opt_list_t *vol_opt_handle); #endif /* _XLATOR_H */ |