diff options
author | Amar Tumballi <amarts@redhat.com> | 2017-09-18 23:03:32 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2017-11-03 14:40:52 +0530 |
commit | bf5c5841c443a8da5b8f73c27b2ed83420f2303e (patch) | |
tree | 2006ede8204f8b27b46765840c08e395d79d05e9 /libglusterfs/src | |
parent | cf62283467d7dd30b89b80717f1fbc24670cb44b (diff) |
global options: add a sample option to handle
Fixes #303
Change-Id: Icdaa804711c43c65b9684f2649437aae1b5c1ed5
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/globals.c | 36 | ||||
-rw-r--r-- | libglusterfs/src/globals.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/options.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 15 |
4 files changed, 50 insertions, 5 deletions
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index a43b80aa060..f182b1c7208 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -144,8 +144,20 @@ static struct xlator_fops global_fops = { static int global_xl_reconfigure (xlator_t *this, dict_t *options) { + int ret = -1; + gf_boolean_t bool_opt = _gf_false; + + /* This is not added in volume dump, hence adding the options in log + would be helpful for debugging later */ dict_dump_to_log (options); - return 0; + + GF_OPTION_RECONF ("measure-latency", bool_opt, options, bool, out); + this->ctx->measure_latency = bool_opt; + + /* TODO: add more things here */ + ret = 0; +out: + return ret; } static int @@ -160,11 +172,25 @@ global_xl_fini (xlator_t *this) return; } +struct volume_options global_xl_options[] = { + { .key = {"measure-latency"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "no", + .op_version = {GD_OP_VERSION_4_0_0}, + .flags = OPT_FLAG_SETTABLE, + .tags = {"global", "context"}, + .description = "Use this option to toggle measuring latency" + }, + + { .key = {NULL},}, +}; + +static volume_opt_list_t global_xl_opt_list; + int glusterfs_this_init () { - int ret = 0; - + int ret = 0; ret = pthread_key_create (&this_xlator_key, glusterfs_this_destroy); if (ret != 0) { gf_msg ("", GF_LOG_WARNING, ret, @@ -182,6 +208,10 @@ glusterfs_this_init () global_xlator.fini = global_xl_fini; INIT_LIST_HEAD (&global_xlator.volume_options); + INIT_LIST_HEAD (&global_xl_opt_list.list); + global_xl_opt_list.given_opt = global_xl_options; + + list_add_tail (&global_xl_opt_list.list, &global_xlator.volume_options); return ret; } diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h index bf73f2e6671..1fc9b562b9b 100644 --- a/libglusterfs/src/globals.h +++ b/libglusterfs/src/globals.h @@ -98,6 +98,7 @@ #define GD_OP_VER_PERSISTENT_AFR_XATTRS GD_OP_VERSION_3_6_0 #include "xlator.h" +#include "options.h" /* THIS */ #define THIS (*__glusterfs_this_location()) @@ -108,6 +109,7 @@ xlator_t *glusterfs_this_get (void); int glusterfs_this_set (xlator_t *); extern xlator_t global_xlator; +extern struct volume_options global_xl_options[]; /* syncopctx */ void *syncopctx_getctx (void); diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h index 6308773a3e1..af6a651a41d 100644 --- a/libglusterfs/src/options.h +++ b/libglusterfs/src/options.h @@ -296,7 +296,7 @@ xlator_option_reconf_##type (xlator_t *this, dict_t *options, char *key, \ "option %s using default value %s", \ key, value); \ } else { \ - gf_msg_debug (this->name, 0, \ + gf_msg (this->name, GF_LOG_INFO, 0, 0, \ "option %s using set value %s", \ key, value); \ } \ diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index fdc2be144a6..4817da43da1 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -308,6 +308,8 @@ xlator_set_type (xlator_t *xl, const char *type) /* Handle 'global' translator differently */ if (!strncmp (GF_GLOBAL_XLATOR_NAME, type, strlen (GF_GLOBAL_XLATOR_NAME))) { + volume_opt_list_t *vol_opt = NULL; + /* set the required values from Global xlator */ xl->type = gf_strdup (GF_GLOBAL_XLATOR_NAME); xl->cbks = global_xlator.cbks; @@ -316,10 +318,21 @@ xlator_set_type (xlator_t *xl, const char *type) xl->fini = global_xlator.fini; xl->reconfigure = global_xlator.reconfigure; + vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!vol_opt) { + ret = -1; + goto out; + } + + vol_opt->given_opt = global_xl_options; + INIT_LIST_HEAD (&xl->volume_options); + INIT_LIST_HEAD (&vol_opt->list); + list_add_tail (&vol_opt->list, &xl->volume_options); fill_defaults(xl); - + ret = 0; goto out; } |