Skip to content

Commit

Permalink
global options: add a sample option to handle
Browse files Browse the repository at this point in the history
Fixes #303

Change-Id: Icdaa804711c43c65b9684f2649437aae1b5c1ed5
Signed-off-by: Amar Tumballi <amarts@redhat.com>
  • Loading branch information
amarts committed Nov 3, 2017
1 parent cf62283 commit bf5c584
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
36 changes: 33 additions & 3 deletions libglusterfs/src/globals.c
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions libglusterfs/src/globals.h
Expand Up @@ -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())
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libglusterfs/src/options.h
Expand Up @@ -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); \
} \
Expand Down
15 changes: 14 additions & 1 deletion libglusterfs/src/xlator.c
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit bf5c584

Please sign in to comment.