From 515d1b4577d989fa99f236d9e344a71db7d001a0 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Tue, 5 Nov 2019 18:05:38 +0200 Subject: glusterd-volgen.c: improve volgen_graph_set_options_generic() Skip fetching "skip-CLIOT" unconditionally on every invocation of volgen_graph_set_options_generic(). Instead, fetch only if the vme->key matches to it. We calculate the length of vme->key (but we would have done it anyway in dict_get() later on, so now we can use dict_getn() instead and re-use that key length) and check if the lengths match before doing a strcmp() between them. Lastly, if they match, we actually do the fetch. Change-Id: I9d9a7104f9e920bf81477128adb5fc87f5d30627 updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/mgmt/glusterd/src/glusterd-volgen.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 4dbc78a8e02..b93c7b84c90 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -459,7 +459,7 @@ struct opthandler_data { void *param; }; -static int +static void process_option(char *key, data_t *value, void *param) { struct opthandler_data *odt = param; @@ -468,7 +468,7 @@ process_option(char *key, data_t *value, void *param) }; if (odt->rv) - return 0; + return; odt->found = _gf_true; vme.key = key; @@ -489,7 +489,7 @@ process_option(char *key, data_t *value, void *param) vme.value = value->data; odt->rv = odt->handler(odt->graph, &vme, odt->param); - return 0; + return; } static int @@ -501,7 +501,7 @@ volgen_graph_set_options_generic(volgen_graph_t *graph, dict_t *dict, 0, }; data_t *data = NULL; - const int skip_cliot = dict_get_str_boolean(dict, "skip-CLIOT", _gf_false); + int keylen; odt.graph = graph; odt.handler = handler; @@ -509,16 +509,17 @@ volgen_graph_set_options_generic(volgen_graph_t *graph, dict_t *dict, (void)data; for (vme = glusterd_volopt_map; vme->key; vme++) { - odt.vme = vme; - odt.found = _gf_false; - odt.data_t_fake = _gf_false; - - data = dict_get(dict, vme->key); - if (skip_cliot == _gf_true && - !strcmp(vme->key, "performance.client-io-threads")) { + keylen = strlen(vme->key); + if (keylen == SLEN("performance.client-io-threads") && + !strcmp(vme->key, "performance.client-io-threads") && + dict_get_str_boolean(dict, "skip-CLIOT", _gf_false) == _gf_true) { continue; } + odt.vme = vme; + odt.found = _gf_false; + odt.data_t_fake = _gf_false; + data = dict_getn(dict, vme->key, keylen); if (data) process_option(vme->key, data, &odt); if (odt.rv) -- cgit