summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--glusterfsd/src/glusterfsd-mgmt.c3
-rw-r--r--libglusterfs/src/Makefile.am33
-rw-r--r--libglusterfs/src/globals.c2
-rw-r--r--libglusterfs/src/graph.c84
-rw-r--r--libglusterfs/src/options.c908
-rw-r--r--libglusterfs/src/options.h248
-rw-r--r--libglusterfs/src/xlator.c1560
-rw-r--r--libglusterfs/src/xlator.h61
-rw-r--r--rpc/rpc-lib/src/rpc-transport.c441
-rw-r--r--rpc/rpc-lib/src/rpc-transport.h2
-rw-r--r--xlators/cluster/afr/src/afr.c649
-rw-r--r--xlators/cluster/dht/src/dht.c165
-rw-r--r--xlators/cluster/stripe/src/stripe.c103
-rw-r--r--xlators/debug/io-stats/src/io-stats.c186
-rw-r--r--xlators/features/quota/src/quota.c76
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c6
-rw-r--r--xlators/nfs/server/src/nfs.c29
-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
-rw-r--r--xlators/protocol/client/src/client.c166
-rw-r--r--xlators/protocol/server/src/authenticate.c5
-rw-r--r--xlators/protocol/server/src/server.c28
25 files changed, 1668 insertions, 3826 deletions
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
index ce9bac2e8f6..3a6829ff619 100644
--- a/glusterfsd/src/glusterfsd-mgmt.c
+++ b/glusterfsd/src/glusterfsd-mgmt.c
@@ -53,6 +53,7 @@ typedef ssize_t (*gf_serialize_t) (struct iovec outmsg, void *args);
int glusterfs_mgmt_pmap_signin (glusterfs_ctx_t *ctx);
int glusterfs_volfile_fetch (glusterfs_ctx_t *ctx);
int glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp);
+int glusterfs_graph_unknown_options (glusterfs_graph_t *graph);
int
mgmt_cbk_spec (void *data)
@@ -603,6 +604,8 @@ glusterfs_volfile_reconfigure (FILE *newvolfile_fp)
goto out;
}
+ glusterfs_graph_unknown_options (newvolfile_graph);
+
ret = 0;
out:
return ret;
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index 0f932cb303e..a950e67d1fa 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 d1985b7ed04..70c6c92ef60 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 acad239544b..1d7d943e66e 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 00000000000..37302e0daec
--- /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 00000000000..f95040c26c8
--- /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 7d949da67ad..67ecabce576 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 1ecde5d5f79..725a9a2d039 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 */
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 57d9b5adcb5..b97ba61bf2b 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -42,435 +42,8 @@
#define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL)
#endif
-int
-__volume_option_value_validate (char *name,
- 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_XLATOR:
- break;
-
- case GF_OPTION_TYPE_PATH:
- {
- if (strstr (pair->value->data, "../")) {
- gf_log (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 (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 (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 (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 (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 (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 (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 (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);
- }
- 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 (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_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 (strcasecmp (opt->value[i],
- pair->value->data) == 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (name, GF_LOG_ERROR,
- "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;
-}
-
-/* FIXME: this procedure should be removed from transport */
int
-validate_volume_options (char *name, dict_t *options, 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 = 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 (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 (name, pairs, trav);
- if (-1 == ret) {
- goto out;
- }
- }
-
- pairs = pairs->next;
- }
-
- ret = 0;
- out:
- return ret;
-}
-
-int32_t
rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
struct sockaddr_storage *sa, size_t salen)
{
@@ -731,11 +304,10 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
gf_log ("rpc-transport", GF_LOG_DEBUG,
"volume option validation not specified");
} else {
- /* FIXME: is adding really needed? */
- /* list_add_tail (&vol_opt->list, &xl->volume_options); */
- if (-1 ==
- validate_volume_options (trans_name, options,
- vol_opt->given_opt)) {
+ INIT_LIST_HEAD (&vol_opt->list);
+ list_add_tail (&vol_opt->list, &(THIS->volume_options));
+ if (xlator_options_validate_list (THIS, options, vol_opt,
+ NULL)) {
gf_log ("rpc-transport", GF_LOG_ERROR,
"volume option validation failed");
goto fail;
@@ -760,7 +332,6 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
GF_FREE (name);
}
- GF_FREE (vol_opt);
return return_trans;
fail:
@@ -772,10 +343,6 @@ fail:
GF_FREE (trans);
}
- if (vol_opt) {
- GF_FREE (vol_opt);
- }
-
if (name) {
GF_FREE (name);
}
diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h
index 42b36afd2d9..e3fb1712848 100644
--- a/rpc/rpc-lib/src/rpc-transport.h
+++ b/rpc/rpc-lib/src/rpc-transport.h
@@ -203,8 +203,6 @@ struct rpc_transport {
data_t *buf;
int32_t (*init) (rpc_transport_t *this);
void (*fini) (rpc_transport_t *this);
- int32_t (*validate_options) (rpc_transport_t *this,
- char **op_errstr);
int (*reconfigure) (rpc_transport_t *this, dict_t *options);
rpc_transport_notify_t notify;
void *notify_data;
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index 851c57fb01e..289a27d6079 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -62,284 +62,85 @@ mem_acct_init (xlator_t *this)
return ret;
}
+
int
-validate_options (xlator_t *this, char **op_errstr)
+xlator_subvolume_index (xlator_t *this, xlator_t *subvol)
{
- int ret = 0;
- volume_opt_list_t *vol_opt = NULL;
- volume_opt_list_t *tmp;
+ int index = -1;
+ int i = 0;
+ xlator_list_t *list = 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;
+ list = this->children;
- 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);
+ while (list) {
+ if (subvol == list->xlator ||
+ strcmp (subvol->name, list->xlator->name) == 0) {
+ index = i;
+ break;
+ }
+ list = list->next;
+ i++;
}
-out:
-
- return ret;
+ return index;
}
int
reconfigure (xlator_t *this, dict_t *options)
{
-
- gf_boolean_t metadata_self_heal; /* on/off */
- gf_boolean_t entry_self_heal;
- gf_boolean_t data_self_heal;
- gf_boolean_t data_change_log; /* on/off */
- gf_boolean_t metadata_change_log; /* on/off */
- gf_boolean_t entry_change_log; /* on/off */
- gf_boolean_t strict_readdir;
-
afr_private_t * priv = NULL;
- xlator_list_t * trav = NULL;
-
- char * read_subvol = NULL;
- char * self_heal = NULL;
- char * change_log = NULL;
- char * str_readdir = NULL;
- char * self_heal_algo = NULL;
-
- int32_t background_count = 0;
- int32_t window_size = 0;
-
- int read_ret = -1;
- int dict_ret = -1;
- int flag = 1;
- int ret = 0;
- int temp_ret = -1;
+ xlator_t * read_subvol = NULL;
+ int ret = -1;
+ int index = -1;
priv = this->private;
- dict_ret = dict_get_int32 (options, "background-self-heal-count",
- &background_count);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring background self-heal count to %d",
- background_count);
-
- priv->background_self_heal_count = background_count;
- }
+ GF_OPTION_RECONF ("background-self-heal-count",
+ priv->background_self_heal_count, options, uint32,
+ out);
- dict_ret = dict_get_str (options, "metadata-self-heal",
- &self_heal);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (self_heal, &metadata_self_heal);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Reconfiguration Invalid 'option metadata"
- "-self-heal %s'. Defaulting to old value.",
- self_heal);
- ret = -1;
- goto out;
- }
-
- priv->metadata_self_heal = metadata_self_heal;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option metadata"
- "-self-heal %s'.",
- self_heal);
- }
+ GF_OPTION_RECONF ("metadata-self-heal",
+ priv->metadata_self_heal, options, bool, out);
- dict_ret = dict_get_str (options, "data-self-heal", &self_heal);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (self_heal, &data_self_heal);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Reconfiguration Invalid 'option data"
- "-self-heal %s'. Defaulting to old value.",
- self_heal);
- ret = -1;
- goto out;
- }
-
- priv->data_self_heal = data_self_heal;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option data"
- "-self-heal %s'.", self_heal);
- }
+ GF_OPTION_RECONF ("data-self-heal", priv->data_self_heal, options, bool,
+ out);
- dict_ret = dict_get_str (options, "entry-self-heal",
- &self_heal);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (self_heal, &entry_self_heal);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Reconfiguration Invalid 'option data"
- "-self-heal %s'. Defaulting to old value.",
- self_heal);
- ret = -1;
- goto out;
- }
+ GF_OPTION_RECONF ("entry-self-heal", priv->entry_self_heal, options,
+ bool, out);
- priv->entry_self_heal = entry_self_heal;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option entry"
- "-self-heal %s'.", self_heal);
- }
+ GF_OPTION_RECONF ("strict-readdir", priv->strict_readdir, options, bool,
+ out);
+ GF_OPTION_RECONF ("data-self-heal-window-size",
+ priv->data_self_heal_window_size, options,
+ uint32, out);
- dict_ret = dict_get_str (options, "strict-readdir",
- &str_readdir);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (str_readdir, &strict_readdir);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option strict-readdir %s'. "
- "Defaulting to old value.",
- str_readdir);
- ret = -1;
- goto out;
- }
+ GF_OPTION_RECONF ("data-change-log", priv->data_change_log, options,
+ bool, out);
- priv->strict_readdir = strict_readdir;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option strict"
- "-readdir %s'.", str_readdir);
- }
+ GF_OPTION_RECONF ("metadata-change-log",
+ priv->metadata_change_log, options, bool, out);
- dict_ret = dict_get_int32 (options, "data-self-heal-window-size",
- &window_size);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring, Setting data self-heal window size to %d",
- window_size);
+ GF_OPTION_RECONF ("entry-change-log", priv->entry_change_log, options,
+ bool, out);
- priv->data_self_heal_window_size = window_size;
- }
- else {
- priv->data_self_heal_window_size = 16;
- }
+ GF_OPTION_RECONF ("data-self-heal-algorithm",
+ priv->data_self_heal_algorithm, options, str, out);
+ GF_OPTION_RECONF ("read-subvolume", read_subvol, options, xlator, out);
- dict_ret = dict_get_str (options, "data-change-log", &change_log);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (change_log, &data_change_log);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Reconfiguration Invalid 'option data-"
- "change-log %s'. Defaulting to old value.",
- change_log);
- ret = -1;
+ if (read_subvol) {
+ index = xlator_subvolume_index (this, read_subvol);
+ if (index == -1) {
+ gf_log (this->name, GF_LOG_ERROR, "%s not a subvolume",
+ read_subvol->name);
goto out;
}
-
- priv->data_change_log = data_change_log;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option data-"
- "change-log %s'.", change_log);
+ priv->read_child = index;
}
- dict_ret = dict_get_str (options, "metadata-change-log",
- &change_log);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (change_log,
- &metadata_change_log);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option metadata-change-log %s'. "
- "Defaulting to metadata-change-log as 'off'.",
- change_log);
- ret = -1;
- goto out;
- }
-
- priv->metadata_change_log = metadata_change_log;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option metadata-"
- "change-log %s'.", change_log);
- }
-
- dict_ret = dict_get_str (options, "entry-change-log",
- &change_log);
- if (dict_ret == 0) {
- temp_ret = gf_string2boolean (change_log, &entry_change_log);
- if (temp_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option entry-change-log %s'. "
- "Defaulting to entry-change-log as 'on'.",
- change_log);
- ret = -1;
- goto out;
- }
-
- priv->entry_change_log = entry_change_log;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option entry-"
- "change-log %s'.", change_log);
- }
-
- dict_ret = dict_get_str (options, "data-self-heal-algorithm",
- &self_heal_algo);
- if (dict_ret == 0) {
- /* Handling both strcmp cases - s1 > s2 and s1 < s2 */
-
- if (!strcmp (self_heal_algo, "full")) {
- priv->data_self_heal_algorithm = self_heal_algo;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option data-self"
- "heal-algorithm %s'.", self_heal_algo);
- goto next;
- }
-
- if (!strcmp (self_heal_algo, "diff")) {
- priv->data_self_heal_algorithm = self_heal_algo;
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring 'option data-self"
- "heal-algorithm %s'.", self_heal_algo);
- goto next;
- }
-
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid self-heal algorithm %s,"
- "defaulting back to old value",
- self_heal_algo);
- ret = -1;
- goto out;
- }
-
- read_ret = dict_get_str (options, "read-subvolume", &read_subvol);
-
- if (read_ret < 0)
- goto next;// No need to traverse, hence set the next option
-
- trav = this->children;
- flag = 0;
- while (trav) {
- if (!read_ret && !strcmp (read_subvol, trav->xlator->name)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Subvolume '%s' specified as read child.",
- trav->xlator->name);
-
- flag = 1;
- break;
- }
-
- trav = trav->next;
- }
-
- if (flag == 0 ) {
- gf_log (this->name, GF_LOG_ERROR,
- "Invalid 'option read-subvolume %s', no such subvolume"
- , read_subvol);
- ret = -1;
- goto out;
- }
-
-next:
+ ret = 0;
out:
return ret;
@@ -354,13 +155,6 @@ static const char *favorite_child_warning_str = "You have specified subvolume '%
"subvolumes. All versions of the file except that on '%s' "
"WILL BE LOST.";
-static const char *no_lock_servers_warning_str = "You have set lock-server-count = 0. "
- "This means correctness is NO LONGER GUARANTEED in all cases. If two or more "
- "applications write to the same region of a file, there is a possibility that "
- "its copies will be INCONSISTENT. Set it to a value greater than 0 unless you "
- "are ABSOLUTELY SURE of what you are doing and WILL NOT HOLD GlusterFS "
- "RESPONSIBLE for inconsistent data. If you are in doubt, set it to a value "
- "greater than 0.";
int32_t
init (xlator_t *this)
@@ -371,21 +165,8 @@ init (xlator_t *this)
int i = 0;
int ret = -1;
int op_errno = 0;
- char * read_subvol = NULL;
- char * fav_child = NULL;
- char * self_heal = NULL;
- char * algo = NULL;
- char * change_log = NULL;
- char * strict_readdir = NULL;
- char * inodelk_trace = NULL;
- char * entrylk_trace = NULL;
- char * def_val = NULL;
- int32_t background_count = 0;
- int32_t lock_server_count = 1;
- int32_t window_size = 0;
- int fav_ret = -1;
- int read_ret = -1;
- int dict_ret = -1;
+ xlator_t * read_subvol = NULL;
+ xlator_t * fav_child = NULL;
if (!this->children) {
@@ -404,276 +185,63 @@ init (xlator_t *this)
priv = this->private;
- read_ret = dict_get_str (this->options, "read-subvolume", &read_subvol);
priv->read_child = -1;
-
- fav_ret = dict_get_str (this->options, "favorite-child", &fav_child);
- priv->favorite_child = -1;
-
- priv->background_self_heal_count = 16;
-
- dict_ret = dict_get_int32 (this->options, "background-self-heal-count",
- &background_count);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Setting background self-heal count to %d",
- background_count);
-
- priv->background_self_heal_count = background_count;
- }
-
- /* Default values */
-
- priv->data_self_heal = 1;
- priv->metadata_self_heal = 1;
- priv->entry_self_heal = 1;
-
- dict_ret = dict_get_str (this->options, "data-self-heal", &self_heal);
- if (dict_ret == 0) {
- ret = gf_string2boolean (self_heal, &priv->data_self_heal);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option data-self-heal %s'. "
- "Defaulting to data-self-heal as 'on'",
- self_heal);
- priv->data_self_heal = 1;
- }
- }
-
- if (xlator_get_volopt_info (&this->volume_options,
- "data-self-heal-algorithm", &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- " data-self-heal-algorithm not found");
- ret = -1;
- goto out;
- } else {
- priv->data_self_heal_algorithm = def_val;
- }
- dict_ret = dict_get_str (this->options, "data-self-heal-algorithm",
- &algo);
- if (dict_ret == 0) {
- priv->data_self_heal_algorithm = gf_strdup (algo);
- }
-
- if (xlator_get_volopt_info (&this->volume_options,
- "data-self-heal-window-size",&def_val,
- NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "data-self-heal-window-size not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2int32 (def_val,
- (int *)&priv->data_self_heal_window_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "data-self-heal-window-size corrupt");
- ret = -1;
+ GF_OPTION_INIT ("read-subvolume", read_subvol, xlator, out);
+ if (read_subvol) {
+ priv->read_child = xlator_subvolume_index (this, read_subvol);
+ if (priv->read_child == -1) {
+ gf_log (this->name, GF_LOG_ERROR, "%s not a subvolume",
+ read_subvol->name);
goto out;
}
}
- dict_ret = dict_get_int32 (this->options, "data-self-heal-window-size",
- &window_size);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Setting data self-heal window size to %d",
- window_size);
-
- priv->data_self_heal_window_size = window_size;
- }
-
- dict_ret = dict_get_str (this->options, "metadata-self-heal",
- &self_heal);
- if (dict_ret == 0) {
- ret = gf_string2boolean (self_heal, &priv->metadata_self_heal);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option metadata-self-heal %s'. "
- "Defaulting to metadata-self-heal as 'on'.",
- self_heal);
- priv->metadata_self_heal = 1;
- }
- }
-
- dict_ret = dict_get_str (this->options, "entry-self-heal", &self_heal);
- if (dict_ret == 0) {
- ret = gf_string2boolean (self_heal, &priv->entry_self_heal);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option entry-self-heal %s'. "
- "Defaulting to entry-self-heal as 'on'.",
- self_heal);
- priv->entry_self_heal = 1;
- }
- }
-
- /* Change log options */
-
- priv->data_change_log = 1;
- priv->metadata_change_log = 1;
- priv->entry_change_log = 1;
- priv->optimistic_change_log = 1;
-
- dict_ret = dict_get_str (this->options, "data-change-log",
- &change_log);
- if (dict_ret == 0) {
- ret = gf_string2boolean (change_log, &priv->data_change_log);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option data-change-log %s'. "
- "Defaulting to data-change-log as 'on'.",
- change_log);
- priv->data_change_log = 1;
- }
- }
-
- dict_ret = dict_get_str (this->options, "metadata-change-log",
- &change_log);
- if (dict_ret == 0) {
- ret = gf_string2boolean (change_log,
- &priv->metadata_change_log);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option metadata-change-log %s'. "
- "Defaulting to metadata-change-log as 'off'.",
- change_log);
- priv->metadata_change_log = 0;
- }
- }
-
- dict_ret = dict_get_str (this->options, "entry-change-log",
- &change_log);
- if (dict_ret == 0) {
- ret = gf_string2boolean (change_log, &priv->entry_change_log);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option entry-change-log %s'. "
- "Defaulting to entry-change-log as 'on'.",
- change_log);
- priv->entry_change_log = 1;
- }
- }
-
- dict_ret = dict_get_str (this->options, "optimistic-change-log",
- &change_log);
- if (dict_ret == 0) {
- ret = gf_string2boolean (change_log, &priv->optimistic_change_log);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option optimistic-change-log %s'. "
- "Defaulting to optimistic-change-log as 'on'.",
- change_log);
- priv->optimistic_change_log = 1;
- }
- }
-
- /* Locking options */
-
- priv->inodelk_trace = 0;
- priv->entrylk_trace = 0;
-
- dict_ret = dict_get_str (this->options, "inodelk-trace",
- &inodelk_trace);
- if (dict_ret == 0) {
- ret = gf_string2boolean (inodelk_trace, &priv->inodelk_trace);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option inodelk-trace %s' ",
- inodelk_trace);
-
- priv->inodelk_trace = 0;
- }
- }
-
-
- dict_ret = dict_get_str (this->options, "entrylk-trace",
- &entrylk_trace);
- if (dict_ret == 0) {
- ret = gf_string2boolean (entrylk_trace, &priv->entrylk_trace);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option entrylk-trace %s' ",
- inodelk_trace);
-
- priv->entrylk_trace = 0;
+ priv->favorite_child = -1;
+ GF_OPTION_INIT ("favorite-child", fav_child, xlator, out);
+ if (fav_child) {
+ priv->favorite_child = xlator_subvolume_index (this, fav_child);
+ if (priv->favorite_child == -1) {
+ gf_log (this->name, GF_LOG_ERROR, "%s not a subvolume",
+ fav_child->name);
+ goto out;
}
+ gf_log (this->name, GF_LOG_WARNING,
+ favorite_child_warning_str, fav_child->name,
+ fav_child->name, fav_child->name);
}
- priv->data_lock_server_count = 1;
- priv->metadata_lock_server_count = 0;
- priv->entry_lock_server_count = 1;
+ GF_OPTION_INIT ("background-self-heal-count",
+ priv->background_self_heal_count, uint32, out);
- dict_ret = dict_get_int32 (this->options, "data-lock-server-count",
- &lock_server_count);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Setting data lock server count to %d.",
- lock_server_count);
+ GF_OPTION_INIT ("data-self-heal", priv->data_self_heal, bool, out);
- if (lock_server_count == 0)
- gf_log (this->name, GF_LOG_WARNING, "%s",
- no_lock_servers_warning_str);
+ GF_OPTION_INIT ("data-self-heal-algorithm",
+ priv->data_self_heal_algorithm, str, out);
- priv->data_lock_server_count = lock_server_count;
- }
+ GF_OPTION_INIT ("data-self-heal-window-size",
+ priv->data_self_heal_window_size, uint32, out);
+ GF_OPTION_INIT ("metadata-self-heal", priv->metadata_self_heal, bool,
+ out);
- dict_ret = dict_get_int32 (this->options,
- "metadata-lock-server-count",
- &lock_server_count);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Setting metadata lock server count to %d.",
- lock_server_count);
- priv->metadata_lock_server_count = lock_server_count;
- }
+ GF_OPTION_INIT ("entry-self-heal", priv->entry_self_heal, bool, out);
+ GF_OPTION_INIT ("data-change-log", priv->data_change_log, bool, out);
- dict_ret = dict_get_int32 (this->options, "entry-lock-server-count",
- &lock_server_count);
- if (dict_ret == 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Setting entry lock server count to %d.",
- lock_server_count);
+ GF_OPTION_INIT ("metadata-change-log", priv->metadata_change_log, bool,
+ out);
- priv->entry_lock_server_count = lock_server_count;
- }
+ GF_OPTION_INIT ("entry-change-log", priv->entry_change_log, bool, out);
- priv->strict_readdir = _gf_false;
-
- dict_ret = dict_get_str (this->options, "strict-readdir",
- &strict_readdir);
- if (dict_ret == 0) {
- ret = gf_string2boolean (strict_readdir, &priv->strict_readdir);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid 'option strict-readdir %s'. "
- "Defaulting to strict-readdir as 'off'.",
- strict_readdir);
- }
- }
+ GF_OPTION_INIT ("optimistic-change-log", priv->optimistic_change_log,
+ bool, out);
- trav = this->children;
- while (trav) {
- if (!read_ret && !strcmp (read_subvol, trav->xlator->name)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Subvolume '%s' specified as read child.",
- trav->xlator->name);
+ GF_OPTION_INIT ("inodelk-trace", priv->inodelk_trace, bool, out);
- priv->read_child = child_count;
- }
+ GF_OPTION_INIT ("entrylk-trace", priv->entrylk_trace, bool, out);
- if (fav_ret == 0 && !strcmp (fav_child, trav->xlator->name)) {
- gf_log (this->name, GF_LOG_WARNING,
- favorite_child_warning_str, trav->xlator->name,
- trav->xlator->name, trav->xlator->name);
- priv->favorite_child = child_count;
- }
-
- child_count++;
- trav = trav->next;
- }
+ GF_OPTION_INIT ("strict-readdir", priv->strict_readdir, bool, out);
priv->wait_count = 1;
@@ -827,10 +395,12 @@ struct volume_options options[] = {
},
{ .key = {"background-self-heal-count"},
.type = GF_OPTION_TYPE_INT,
- .min = 0
+ .min = 0,
+ .default_value = "16",
},
{ .key = {"data-self-heal"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"data-self-heal-algorithm"},
.type = GF_OPTION_TYPE_STR,
@@ -840,7 +410,7 @@ struct volume_options options[] = {
"source to sink. The \"diff\" algorithm copies to "
"sink only those blocks whose checksums don't match "
"with those of source.",
- .value = { "diff", "full" }
+ .value = { "diff", "full", "" }
},
{ .key = {"data-self-heal-window-size"},
.type = GF_OPTION_TYPE_INT,
@@ -851,37 +421,40 @@ struct volume_options options[] = {
"process would be applied simultaneously."
},
{ .key = {"metadata-self-heal"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"entry-self-heal"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"data-change-log"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"metadata-change-log"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"entry-change-log"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"optimistic-change-log"},
- .type = GF_OPTION_TYPE_BOOL
- },
- { .key = {"data-lock-server-count"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
- { .key = {"metadata-lock-server-count"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0
+ { .key = {"strict-readdir"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
},
- { .key = {"entry-lock-server-count"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0
+ { .key = {"inodelk-trace"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
},
- { .key = {"strict-readdir"},
+ { .key = {"entrylk-trace"},
.type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
},
{ .key = {NULL} },
};
diff --git a/xlators/cluster/dht/src/dht.c b/xlators/cluster/dht/src/dht.c
index c281bb15216..6c4c1ffcdcd 100644
--- a/xlators/cluster/dht/src/dht.c
+++ b/xlators/cluster/dht/src/dht.c
@@ -253,34 +253,6 @@ out:
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;
-
- 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)
@@ -288,9 +260,7 @@ reconfigure (xlator_t *this, dict_t *options)
dht_conf_t *conf = NULL;
char *temp_str = NULL;
gf_boolean_t search_unhashed;
- uint32_t temp_free_disk = 0;
int ret = -1;
- uint32_t dir_spread = 0;
GF_VALIDATE_OR_GOTO ("dht", this, out);
GF_VALIDATE_OR_GOTO ("dht", options, out);
@@ -323,45 +293,18 @@ reconfigure (xlator_t *this, dict_t *options)
}
}
- if (dict_get_str (options, "min-free-disk", &temp_str) == 0) {
- if (gf_string2percent (temp_str, &temp_free_disk) == 0) {
- if (temp_free_disk > 100) {
- gf_string2bytesize (temp_str,
- &conf->min_free_disk);
- conf->disk_unit = 'b';
- } else {
- conf->min_free_disk = (uint64_t)temp_free_disk;
- }
- } else {
- gf_string2bytesize (temp_str, &conf->min_free_disk);
- conf->disk_unit = 'b';
- }
-
- gf_log(this->name, GF_LOG_DEBUG, "Reconfigure:"
- " min-free-disk reconfigured to %s",
- temp_str);
- }
+ GF_OPTION_RECONF ("min-free-disk", conf->min_free_disk, options,
+ percent_or_size, out);
- if (dict_get_str (options, "directory-layout-spread", &temp_str) == 0) {
- ret = gf_string2uint32 (temp_str, &dir_spread);
- if (ret ||
- (dir_spread > conf->subvolume_cnt) ||
- (dir_spread < 1)) {
- gf_log (this->name, GF_LOG_ERROR,
- "wrong 'directory-layout-spread' option given "
- "(%s). setting to earlier value (%d)",
- temp_str, conf->dir_spread_cnt);
- ret = -1;
- goto out;
- }
- conf->dir_spread_cnt = dir_spread;
- }
+ GF_OPTION_RECONF ("directory-layout-spread", conf->dir_spread_cnt,
+ options, uint32, out);
ret = 0;
out:
return ret;
}
+
int
init (xlator_t *this)
{
@@ -369,8 +312,6 @@ init (xlator_t *this)
char *temp_str = NULL;
int ret = -1;
int i = 0;
- uint32_t temp_free_disk = 0;
- char *def_val = NULL;
GF_VALIDATE_OR_GOTO ("dht", this, err);
@@ -399,86 +340,20 @@ init (xlator_t *this)
conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_AUTO;
}
- conf->unhashed_sticky_bit = 0;
-
- if (dict_get_str (this->options, "unhashed-sticky-bit",
- &temp_str) == 0) {
- gf_string2boolean (temp_str, &conf->unhashed_sticky_bit);
- }
-
- conf->use_readdirp = 1;
+ GF_OPTION_INIT ("unhashed-sticky-bit", conf->unhashed_sticky_bit, bool,
+ err);
- if (dict_get_str (this->options, "use-readdirp",
- &temp_str) == 0) {
- gf_string2boolean (temp_str, &conf->use_readdirp);
- }
+ GF_OPTION_INIT ("use-readdirp", conf->use_readdirp, bool, err);
- if (xlator_get_volopt_info (&this->volume_options, "min-free-disk",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- " min-free-disk not found");
- ret = -1;
- goto err;
- } else {
- if (gf_string2percent (def_val, &temp_free_disk) == 0) {
- if (temp_free_disk > 100) {
- gf_string2bytesize (temp_str,
- &conf->min_free_disk);
- conf->disk_unit = 'b';
- } else {
- conf->min_free_disk = (uint64_t)temp_free_disk;
- conf->disk_unit = 'p';
- }
- } else {
- gf_string2bytesize (temp_str, &conf->min_free_disk);
- conf->disk_unit = 'b';
- }
- }
-
- if (dict_get_str (this->options, "min-free-disk", &temp_str) == 0) {
- if (gf_string2percent (temp_str, &temp_free_disk) == 0) {
- if (temp_free_disk > 100) {
- gf_string2bytesize (temp_str,
- &conf->min_free_disk);
- conf->disk_unit = 'b';
- } else {
- conf->min_free_disk = (uint64_t)temp_free_disk;
- }
- } else {
- gf_string2bytesize (temp_str, &conf->min_free_disk);
- conf->disk_unit = 'b';
- }
- }
+ GF_OPTION_INIT ("min-free-disk", conf->min_free_disk, percent_or_size,
+ err);
conf->dir_spread_cnt = conf->subvolume_cnt;
- if (dict_get_str (this->options, "directory-layout-spread",
- &temp_str) == 0) {
- ret = gf_string2uint32 (temp_str, &conf->dir_spread_cnt);
- if (ret ||
- (conf->dir_spread_cnt > conf->subvolume_cnt) ||
- (conf->dir_spread_cnt < 1)) {
- gf_log (this->name, GF_LOG_WARNING,
- "wrong 'directory-layout-spread' option given "
- "(%s). setting it to subvolume count",
- temp_str);
- conf->dir_spread_cnt = conf->subvolume_cnt;
- }
- }
-
- conf->assert_no_child_down = 0;
+ GF_OPTION_INIT ("directory-layout-spread", conf->dir_spread_cnt,
+ uint32, err);
- ret = dict_get_str_boolean (this->options, "assert-no-child-down", 0);
- if (ret != -1) {
- if (conf->assert_no_child_down != ret) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Changing assert-no-child-down from %d to %d",
- conf->assert_no_child_down, ret);
- }
- conf->assert_no_child_down = ret;
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "'assert-no-child-down' takes only boolean arguments");
- }
+ GF_OPTION_INIT ("assert-no-child-down", conf->assert_no_child_down,
+ bool, err);
ret = dht_init_subvolumes (this, conf);
if (ret == -1) {
@@ -598,7 +473,8 @@ struct volume_options options[] = {
{ .key = {"lookup-unhashed"},
.value = {"auto", "yes", "no", "enable", "disable", "1", "0",
"on", "off"},
- .type = GF_OPTION_TYPE_STR
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "on",
},
{ .key = {"min-free-disk"},
.type = GF_OPTION_TYPE_PERCENT_OR_SIZET,
@@ -607,13 +483,16 @@ struct volume_options options[] = {
"kept free."
},
{ .key = {"unhashed-sticky-bit"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
},
{ .key = {"use-readdirp"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "on",
},
{ .key = {"assert-no-child-down"},
- .type = GF_OPTION_TYPE_BOOL
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
},
{ .key = {"directory-layout-spread"},
.type = GF_OPTION_TYPE_INT,
diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c
index 529111ba718..9c41c405cf1 100644
--- a/xlators/cluster/stripe/src/stripe.c
+++ b/xlators/cluster/stripe/src/stripe.c
@@ -3984,63 +3984,20 @@ mem_acct_init (xlator_t *this)
out:
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;
-
- 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)
{
stripe_private_t *priv = NULL;
- data_t *data = NULL;
- int ret = 0;
+ int ret = -1;
priv = this->private;
- data = dict_get (options, "block-size");
- if (data) {
- gf_log (this->name, GF_LOG_TRACE,"Reconfiguring Stripe"
- " Block-size");
- ret = set_stripe_block_size (this, priv, data->data);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Reconfigue: Block-Size reconfiguration failed");
- ret = -1;
- goto out;
- }
- gf_log (this->name, GF_LOG_TRACE,
- "Reconfigue: Block-Size reconfigured Successfully");
- }
- else {
- priv->block_size = (128 * GF_UNIT_KB);
- }
+ GF_OPTION_RECONF ("block-size", priv->block_size, options, size, out);
+ ret = 0;
out:
return ret;
@@ -4057,7 +4014,6 @@ init (xlator_t *this)
stripe_private_t *priv = NULL;
xlator_list_t *trav = NULL;
data_t *data = NULL;
- char *def_blk_size = NULL;
int32_t count = 0;
int ret = -1;
@@ -4121,65 +4077,18 @@ init (xlator_t *this)
goto out;
}
- if (xlator_get_volopt_info (&this->volume_options, "block-size",
- &def_blk_size, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of stripe "
- "block-size corrupt");
- ret = -1;
- goto out;
- } else {
- if (gf_string2bytesize (def_blk_size, &priv->block_size)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "stripe block-size corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("block-size", priv->block_size, size, out);
/* option stripe-pattern *avi:1GB,*pdf:4096 */
data = dict_get (this->options, "block-size");
- if (!data) {
- gf_log (this->name, GF_LOG_DEBUG,
- "No \"option block-size <x>\" given, defaulting "
- "to %s", def_blk_size);
- } else {
+ if (data) {
ret = set_stripe_block_size (this, priv, data->data);
if (ret)
goto out;
}
- if (xlator_get_volopt_info (&this->volume_options, "use-xattr",
- &def_blk_size, NULL)) {
- ret = -1;
- gf_log (this->name, GF_LOG_ERROR,
- "error setting(default) hard check for extended"
- " attribute");
- goto out;
-
- }
- else {
- if (gf_string2boolean (def_blk_size,
- &priv->xattr_supported)) {
- ret = -1;
- gf_log (this->name, GF_LOG_ERROR,
- "error setting(default) hard check for extended"
- " attribute");
- goto out;
- }
- }
-
-
- data = dict_get (this->options, "use-xattr");
- if (data) {
- if (gf_string2boolean (data->data,
- &priv->xattr_supported) == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "error setting hard check for extended "
- "attribute");
- //return -1;
- }
- }
+ GF_OPTION_INIT ("use-xattr", priv->xattr_supported, bool, out);
/* notify related */
priv->nodes_down = priv->child_count;
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
index 6c5563cad86..7b334baa636 100644
--- a/xlators/debug/io-stats/src/io-stats.c
+++ b/xlators/debug/io-stats/src/io-stats.c
@@ -121,7 +121,7 @@ struct ios_conf {
struct ios_global_stats incremental;
gf_boolean_t dump_fd_stats;
gf_boolean_t count_fop_hits;
- int measure_latency;
+ gf_boolean_t measure_latency;
struct ios_stat_head list[IOS_STATS_TYPE_MAX];
struct ios_stat_head thru_list[IOS_STATS_THRU_MAX];
};
@@ -2327,140 +2327,41 @@ io_stats_forget (xlator_t *this, inode_t *inode)
return 0;
}
+
int
-iostats_configure_options (xlator_t *this, dict_t *xl_options,
- struct ios_conf *conf)
+reconfigure (xlator_t *this, dict_t *options)
{
- int ret = 0;
- int sys_log_level = -1;
+ struct ios_conf *conf = NULL;
+ int ret = -1;
char *sys_log_str = NULL;
- char *log_str = NULL;
- char *def_val = NULL;
- gf_boolean_t def_bool = _gf_false;
-
- GF_ASSERT (this);
- GF_ASSERT (xl_options);
- GF_ASSERT (conf);
+ int sys_log_level = -1;
- if (xlator_get_volopt_info (&this->volume_options, "dump-fd-stats", &def_val,
- NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- " dump-fd-stats not found");
- ret = -1;
+ if (!this || !this->private)
goto out;
- } else {
- if (gf_string2boolean (def_val, &def_bool)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "dump-fd-stats corrupt");
- ret = -1;
- goto out;
- }
- }
-
- ret = dict_get_str_boolean (xl_options, "dump-fd-stats", def_bool);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'dump-fd-stats' takes only boolean arguments");
- } else {
- conf->dump_fd_stats = ret;
- if (conf->dump_fd_stats)
- gf_log (this->name, GF_LOG_DEBUG, "enabling dump-fd-stats");
- else
- gf_log (this->name, GF_LOG_DEBUG, "disabling dump-fd-stats");
- }
- ret = dict_get_str_boolean (xl_options, "count-fop-hits", _gf_false);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'count-fop-hits' takes only boolean arguments");
- } else {
- conf->count_fop_hits = ret;
- if (conf->count_fop_hits)
- gf_log (this->name, GF_LOG_DEBUG,
- "enabling count-fop-hits");
- else
- gf_log (this->name, GF_LOG_DEBUG,
- "disabling count-fop-hits");
- }
+ conf = this->private;
- if (xlator_get_volopt_info (&this->volume_options, "latency-measurement",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "latency-measurement not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2boolean (def_val, &def_bool)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "latency-measurement corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_RECONF ("dump-fd-stats", conf->dump_fd_stats, options, bool,
+ out);
- ret = dict_get_str_boolean (xl_options, "latency-measurement",
- def_bool);
- if (ret != -1) {
- if (conf->measure_latency != ret) {
- gf_log (this->name, GF_LOG_DEBUG,
- "changing latency measurement from %d to %d",
- conf->measure_latency, ret);
- }
- conf->measure_latency = ret;
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "'latency-measurement' takes only boolean arguments");
- }
+ GF_OPTION_RECONF ("count-fop-hits", conf->count_fop_hits, options, bool,
+ out);
- ret = dict_get_str (xl_options, "log-level", &log_str);
- if (!ret) {
- if (!is_gf_log_command(this, "trusted.glusterfs.set-log-level",
- log_str)) {
- gf_log (this->name, GF_LOG_INFO,
- "changing log-level to %s", log_str);
- }
- }
+ GF_OPTION_RECONF ("latency-measurement", conf->measure_latency,
+ options, bool, out);
- ret = dict_get_str (xl_options, "sys-log-level", &sys_log_str);
- if (!ret) {
+ GF_OPTION_RECONF ("sys-log-level", sys_log_str, options, str, out);
+ if (sys_log_str) {
sys_log_level = glusterd_check_log_level (sys_log_str);
+ set_sys_log_level (sys_log_level);
}
- if (ret < 0 || sys_log_level == -1) {
- sys_log_level = glusterd_check_log_level ("CRITICAL");
- gf_log (this->name, GF_LOG_WARNING,
- "setting sys-log-level to CRITICAL");
- } else {
- gf_log (this->name, GF_LOG_WARNING,
- "setting sys-log-level to %s", sys_log_str);
- }
-
- set_sys_log_level (sys_log_level);
-
ret = 0;
- out:
- gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
+out:
+ gf_log (this->name, GF_LOG_DEBUG, "reconfigure returning %d", ret);
return ret;
}
-int
-reconfigure (xlator_t *this, dict_t *options)
-{
- struct ios_conf *conf = NULL;
- glusterfs_ctx_t *ctx = NULL;
-
- if (!this || !this->private)
- return -1;
-
- conf = this->private;
-
- iostats_configure_options (this, options, conf);
- ctx = glusterfs_ctx_get ();
- if (!ctx)
- return -1;
-
- return 0;
-}
int32_t
mem_acct_init (xlator_t *this)
@@ -2487,6 +2388,9 @@ init (xlator_t *this)
dict_t *options = NULL;
struct ios_conf *conf = NULL;
int i = 0;
+ char *sys_log_str = NULL;
+ int sys_log_level = -1;
+ int ret = -1;
if (!this)
return -1;
@@ -2550,10 +2454,23 @@ init (xlator_t *this)
LOCK_INIT (&conf->thru_list[i].lock);
}
- iostats_configure_options (this, options, conf);
- this->private = conf;
+ GF_OPTION_INIT ("dump-fd-stats", conf->dump_fd_stats, bool, out);
- return 0;
+ GF_OPTION_INIT ("count-fop-hits", conf->count_fop_hits, bool, out);
+
+ GF_OPTION_INIT ("latency-measurement", conf->measure_latency,
+ bool, out);
+
+ GF_OPTION_INIT ("sys-log-level", sys_log_str, str, out);
+ if (sys_log_str) {
+ sys_log_level = glusterd_check_log_level (sys_log_str);
+ set_sys_log_level (sys_log_level);
+ }
+
+ this->private = conf;
+ ret = 0;
+out:
+ return ret;
}
@@ -2578,34 +2495,7 @@ fini (xlator_t *this)
return;
}
-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
notify (xlator_t *this, int32_t event, void *data, ...)
{
diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c
index 2790672a7ce..392717c55ce 100644
--- a/xlators/features/quota/src/quota.c
+++ b/xlators/features/quota/src/quota.c
@@ -2597,37 +2597,9 @@ quota_forget (xlator_t *this, inode_t *inode)
return 0;
}
-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;
-}
-
-int32_t
-quota_parse_options (quota_priv_t *priv, xlator_t *this, dict_t *xl_options)
+int
+quota_parse_limits (quota_priv_t *priv, xlator_t *this, dict_t *xl_options)
{
int32_t ret = -1;
char *str = NULL;
@@ -2635,7 +2607,6 @@ quota_parse_options (quota_priv_t *priv, xlator_t *this, dict_t *xl_options)
char *path = NULL;
uint64_t value = 0;
limits_t *quota_lim = NULL;
- char *def_val = NULL;
ret = dict_get_str (xl_options, "limit-set", &str);
@@ -2668,37 +2639,6 @@ quota_parse_options (quota_priv_t *priv, xlator_t *this, dict_t *xl_options)
"no \"limit-set\" option provided");
}
- if (xlator_get_volopt_info (&this->volume_options, "timeout", &def_val,
- NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of timeout"
- "not found");
- ret = -1;
- goto err;
- } else {
- if (gf_string2bytesize (def_val,(uint64_t *) &priv->timeout )) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- " timeout corrupt");
- ret = -1;
- goto err;
- }
- }
-
- ret = dict_get_str (xl_options, "timeout", &str);
- if (str) {
- ret = gf_string2bytesize (str, &value);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_INFO,
- "Invalid quota timout value.");
- ret = -1;
- goto err;
- } else {
- priv->timeout = (int64_t) value;
- gf_log (this->name, GF_LOG_INFO,
- "quota timeout value = %"PRId64,
- priv->timeout);
- }
- }
-
list_for_each_entry (quota_lim, &priv->limit_head, limit_list) {
gf_log (this->name, GF_LOG_INFO, "%s:%"PRId64, quota_lim->path,
quota_lim->value);
@@ -2735,12 +2675,14 @@ init (xlator_t *this)
this->private = priv;
- ret = quota_parse_options (priv, this, this->options);
+ ret = quota_parse_limits (priv, this, this->options);
if (ret) {
goto err;
}
+ GF_OPTION_INIT ("timeout", priv->timeout, int64, err);
+
ret = 0;
err:
return ret;
@@ -2763,15 +2705,19 @@ reconfigure (xlator_t *this, dict_t *options)
GF_FREE (limit);
}
- ret = quota_parse_options (priv, this, options);
+ ret = quota_parse_limits (priv, this, options);
if (ret == -1) {
gf_log ("quota", GF_LOG_WARNING,
"quota reconfigure failed, "
"new changes will not take effect");
goto out;
}
+
+ GF_OPTION_RECONF ("timeout", priv->timeout, options, int64, out);
+
+ ret = 0;
out:
- return 0;
+ return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 557bd81a293..3722bdae708 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1789,12 +1789,12 @@ glusterd_get_volopt_content (gf_boolean_t xml_out)
ret = xlator_volopt_dynload (vme->voltype,
&dl_handle,
&vol_opt_handle);
- if (ret)
+ if (ret)
continue;
}
- ret = xlator_get_volopt_info (&vol_opt_handle.list, key,
- &def_val, &descr);
+ ret = xlator_option_info_list (&vol_opt_handle, key,
+ &def_val, &descr);
if (ret) /*Swallow Error i.e if option not found*/
continue;
diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c
index 50c1bc4c2bd..40685fa9b92 100644
--- a/xlators/nfs/server/src/nfs.c
+++ b/xlators/nfs/server/src/nfs.c
@@ -688,35 +688,6 @@ free_rpcsvc:
return nfs;
}
-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
init (xlator_t *this) {
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} },
};
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
index 7f8301be886..355b0d16043 100644
--- a/xlators/protocol/client/src/client.c
+++ b/xlators/protocol/client/src/client.c
@@ -1954,73 +1954,24 @@ int
build_client_config (xlator_t *this, clnt_conf_t *conf)
{
int ret = -1;
- char *def_val = NULL;
if (!conf)
goto out;
- if (xlator_get_volopt_info (&this->volume_options, "frame-timeout",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "frame-timeout not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2int32 (def_val, &conf->rpc_conf.rpc_timeout)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "frame-timeout corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("frame-timeout", conf->rpc_conf.rpc_timeout,
+ int32, out);
- ret = dict_get_int32 (this->options, "frame-timeout",
- &conf->rpc_conf.rpc_timeout);
- if (ret >= 0) {
- gf_log (this->name, GF_LOG_INFO,
- "setting frame-timeout to %d",
- conf->rpc_conf.rpc_timeout);
- }
-
- ret = dict_get_int32 (this->options, "remote-port",
- &conf->rpc_conf.remote_port);
- if (ret >= 0) {
- gf_log (this->name, GF_LOG_INFO,
- "remote-port is %d", conf->rpc_conf.remote_port);
- } else {
- gf_log (this->name, GF_LOG_DEBUG,
- "defaulting remote-port to 'auto'");
- }
-
- if (xlator_get_volopt_info (&this->volume_options, "ping-timeout",
- &def_val, NULL)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "ping-timeout not found");
- ret = -1;
- goto out;
- } else {
- if (gf_string2int32 (def_val, &conf->opt.ping_timeout)) {
- gf_log (this->name, GF_LOG_ERROR, "Default value of "
- "ping-timeout corrupt");
- ret = -1;
- goto out;
- }
- }
+ GF_OPTION_INIT ("remote-port", conf->rpc_conf.remote_port,
+ int32, out);
- ret = dict_get_int32 (this->options, "ping-timeout",
- &conf->opt.ping_timeout);
- if (ret >= 0) {
- gf_log (this->name, GF_LOG_INFO,
- "setting ping-timeout to %d", conf->opt.ping_timeout);
- }
+ GF_OPTION_INIT ("ping-timeout", conf->opt.ping_timeout,
+ int32, out);
- ret = dict_get_str (this->options, "remote-subvolume",
- &conf->opt.remote_subvolume);
- if (ret) {
- /* This is valid only if 'cluster/pump' is the parent */
- gf_log (this->name, GF_LOG_WARNING,
+ GF_OPTION_INIT ("remote-subvolume", conf->opt.remote_subvolume,
+ path, out);
+ if (!conf->opt.remote_subvolume) {
+ gf_log (this->name, GF_LOG_ERROR,
"option 'remote-subvolume' not given");
- ret = 1;
goto out;
}
@@ -2119,43 +2070,12 @@ out:
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;
-
- 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)
{
clnt_conf_t *conf = NULL;
- int ret = 0;
- int timeout_ret = 0;
- int ping_timeout = 0;
- int frame_timeout = 0;
+ int ret = -1;
int subvol_ret = 0;
char *old_remote_subvol = NULL;
char *new_remote_subvol = NULL;
@@ -2164,70 +2084,18 @@ reconfigure (xlator_t *this, dict_t *options)
conf = this->private;
- timeout_ret = dict_get_int32 (options, "frame-timeout",
- &frame_timeout);
- if (timeout_ret == 0) {
- if (frame_timeout < 5 ) {
- gf_log (this->name, GF_LOG_ERROR, "Reconfiguration"
- "'option frame-timeout %d failed , Min value"
- " can be 5, Defaulting to old value (%d)"
- , frame_timeout, conf->rpc_conf.rpc_timeout);
- goto out;
- }
-
- if (frame_timeout > 3600 ) {
- gf_log (this->name, GF_LOG_ERROR, "Reconfiguration"
- "'option frame-timeout %d failed , Max value"
- "can be 3600, Defaulting to old value (%d)"
- , frame_timeout, conf->rpc_conf.rpc_timeout);
- goto out;
- }
+ GF_OPTION_RECONF ("frame-timeout", conf->rpc_conf.rpc_timeout,
+ options, int32, out);
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Reconfiguring otion frame-timeout to %d",
- frame_timeout);
-
- conf->rpc_conf.rpc_timeout = frame_timeout;
- }
- else
- conf->rpc_conf.rpc_timeout = 1800;
-
- timeout_ret = dict_get_int32 (options, "ping-timeout",
- &ping_timeout);
- if (timeout_ret == 0) {
-
- if (ping_timeout < 5 ) {
- gf_log (this->name, GF_LOG_WARNING, "Reconfiguration"
- "'option ping-timeout %d failed , Min value"
- " can be 5, Defaulting to old value (%d)"
- , ping_timeout, conf->opt.ping_timeout);
- goto out;
- }
-
- if (ping_timeout > 1013 ) {
- gf_log (this->name, GF_LOG_WARNING, "Reconfiguration"
- "'option ping-timeout %d failed , Max value"
- "can be 1013, Defaulting to old value (%d)"
- , ping_timeout, conf->opt.ping_timeout);
- goto out;
- }
-
- gf_log (this->name, GF_LOG_DEBUG, "Reconfiguring "
- "'option ping-timeout' to %d", ping_timeout);
- conf->opt.ping_timeout = ping_timeout;
- }
- else
- conf->opt.ping_timeout = GF_UNIVERSAL_ANSWER;
+ GF_OPTION_RECONF ("ping-timeout", conf->opt.ping_timeout,
+ options, int32, out);
subvol_ret = dict_get_str (this->options, "remote-host",
&old_remote_host);
if (subvol_ret == 0) {
-
subvol_ret = dict_get_str (options, "remote-host",
&new_remote_host);
-
if (subvol_ret == 0) {
if (strcmp (old_remote_host, new_remote_host)) {
ret = 1;
@@ -2240,10 +2108,8 @@ reconfigure (xlator_t *this, dict_t *options)
&old_remote_subvol);
if (subvol_ret == 0) {
-
subvol_ret = dict_get_str (options, "remote-subvolume",
&new_remote_subvol);
-
if (subvol_ret == 0) {
if (strcmp (old_remote_subvol, new_remote_subvol)) {
ret = 1;
@@ -2252,11 +2118,13 @@ reconfigure (xlator_t *this, dict_t *options)
}
}
+ ret = 0;
out:
return ret;
}
+
int
init (xlator_t *this)
{
diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c
index 00ec3ef7b3d..de5bf9f437b 100644
--- a/xlators/protocol/server/src/authenticate.c
+++ b/xlators/protocol/server/src/authenticate.c
@@ -134,8 +134,9 @@ gf_auth_init (xlator_t *xl, dict_t *auth_modules)
list_add_tail (&(handle->vol_opt->list),
&(xl->volume_options));
- ret = validate_xlator_volume_options (xl,
- handle->vol_opt->given_opt);
+ ret = xlator_options_validate_list (xl, xl->options,
+ handle->vol_opt, NULL);
+
if (ret)
gf_log ("authenticate", GF_LOG_ERROR,
"volume option validation failed");
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
index df6d31a7c33..28df5c5dcc8 100644
--- a/xlators/protocol/server/src/server.c
+++ b/xlators/protocol/server/src/server.c
@@ -471,34 +471,6 @@ out:
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;
-
- 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;
-}
static void
_delete_auth_opt (dict_t *this,