From c2a543ec947ac56f882a9c0a890f49c63dedeaff Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Wed, 17 Oct 2018 23:03:04 +0530 Subject: xlator: add generic option parsing framework As an example, and also as an enhancement, added 'log-level' as a default option to every translator (glusterfs already support infrastructure to handle xl->loglevel). Corresponding infrastructure to add per xlator log-level is not present in glusterd volume-set. Plan is to get it sorted out in later patches or in GD2. * Why this is needed? - Mainly because we need to only add different log-level to some xlator to debug few things in a production system, while not changing overall log-level. This helps in better debug-ability. Updates: bz#1193929 Change-Id: Ia4098ce39197cd423345b3d31fe8315481681ab8 Signed-off-by: Amar Tumballi --- libglusterfs/src/options.c | 1 + libglusterfs/src/xlator.c | 64 +++++++++++++++++++++++++++++++++++----------- libglusterfs/src/xlator.h | 4 +++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 601baf9004f..12078327b4f 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -1120,6 +1120,7 @@ xlator_reconfigure_rec(xlator_t *old_xl, xlator_t *new_xl) THIS = old_xl; xlator_init_lock(); + handle_default_options(old_xl, new_xl->options); ret = old_xl->reconfigure(old_xl, new_xl->options); xlator_init_unlock(); diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index b305ad50e5d..cbbe8cf7f12 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -45,9 +45,38 @@ xlator_init_unlock(void) static struct xlator_cbks default_cbks = {}; struct volume_options default_options[] = { - {.key = {NULL}}, + { + .key = {"log-level"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_6_0}, + .flags = OPT_FLAG_SETTABLE, + .tags = {"generic"}, + .value = {"DEBUG", "WARNING", "ERROR", "INFO", "CRITICAL", "NONE", + "TRACE"}, + .description = "Option to set log-level of given translator", + }, + { + .key = {NULL}, + }, }; +/* Handle the common options in each translator */ +void +handle_default_options(xlator_t *xl, dict_t *options) +{ + int ret; + char *value; + + /* log-level */ + ret = dict_get_str(options, "log-level", &value); + if (!ret) { + int log_level = glusterd_check_log_level(value); + if (log_level != -1) { + xl->loglevel = log_level; + } + } +} + static void fill_defaults(xlator_t *xl) { @@ -302,13 +331,11 @@ xlator_dynload_oldway(xlator_t *xl) goto out; } - if (!(vol_opt->given_opt = dlsym(handle, "options"))) { - gf_msg_trace(xl->name, 0, - "Strict option validation not " - "enforced -- neglecting (%s)", - dlerror()); - } INIT_LIST_HEAD(&vol_opt->list); + vol_opt->given_opt = dlsym(handle, "options"); + if (!vol_opt->given_opt) { + vol_opt->given_opt = default_options; + } list_add_tail(&vol_opt->list, &xl->volume_options); /* make sure 'min' is set to high value, so it would be @@ -406,17 +433,23 @@ xlator_dynload_newway(xlator_t *xl) if (!vol_opt) { goto out; } - - vol_opt->given_opt = xlapi->options; - if (!vol_opt->given_opt) { - gf_msg("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR, - "%s: options not provided, using default", xl->name); - vol_opt->given_opt = default_options; - } - INIT_LIST_HEAD(&vol_opt->list); + + vol_opt->given_opt = default_options; list_add_tail(&vol_opt->list, &xl->volume_options); + if (xlapi->options) { + vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!vol_opt) { + goto out; + } + INIT_LIST_HEAD(&vol_opt->list); + + vol_opt->given_opt = xlapi->options; + list_add_tail(&vol_opt->list, &xl->volume_options); + } + xl->id = xlapi->xlator_id; xl->flags = xlapi->flags; xl->identifier = xlapi->identifier; @@ -681,6 +714,7 @@ __xlator_init(xlator_t *xl) GF_ATOMIC_INIT(xl->stats.interval.count, 0); xlator_init_lock(); + handle_default_options(xl, xl->options); ret = xl->init(xl); xlator_init_unlock(); diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 9bdbd7f0e26..64a61ac0bed 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -1078,4 +1078,8 @@ xlator_memrec_free(xlator_t *xl); void xlator_mem_cleanup(xlator_t *this); + +void +handle_default_options(xlator_t *xl, dict_t *options); + #endif /* _XLATOR_H */ -- cgit