diff options
author | Csaba Henk <csaba@gluster.com> | 2011-09-22 10:12:24 +0200 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-09-22 05:24:57 -0700 |
commit | 21eabe9bae81b3cc732fcf773fb5c1995f19d0d7 (patch) | |
tree | 3b259c119d6139f50f9d7a141827bb0750e53615 | |
parent | b27b9d36de798bb18eaa95524f3900f9e17ce3e5 (diff) |
geo-rep: add support to glob patterns with "geo-rep config"
Change-Id: I0d54cea72e4363eab85ade774cc918081d8036e9
BUG: 3610
Reviewed-on: http://review.gluster.com/489
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
-rw-r--r-- | cli/src/cli-cmd-parser.c | 31 | ||||
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/gsyncd.py | 10 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 10 |
3 files changed, 41 insertions, 10 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index a8ac5410640..2b3db193925 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1281,6 +1281,12 @@ gsyncd_url_check (const char *w) return !!strpbrk (w, ":/"); } +static gf_boolean_t +gsyncd_glob_check (const char *w) +{ + return !!strpbrk (w, "*?["); +} + int32_t cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) { @@ -1293,6 +1299,7 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) int i = 0; unsigned masteri = 0; unsigned slavei = 0; + unsigned glob = 0; unsigned cmdi = 0; char *opwords[] = { "status", "start", "stop", "config", NULL }; @@ -1316,12 +1323,25 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) goto out; for (i = 2; i <= 3 && i < wordcount - 1; i++) { + if (gsyncd_glob_check (words[i])) + glob = i; if (gsyncd_url_check (words[i])) { slavei = i; break; } } + if (glob && !slavei) + /* glob is allowed only for config, thus it implies there is a + * slave argument; but that might have not been recognized on + * the first scan as it's url characteristics has been covered + * by the glob syntax. + * + * In this case, the slave is perforce the last glob-word -- the + * upcoming one is neither glob, nor url, so it's definitely not + * the slave. + */ + slavei = glob; if (slavei) { cmdi = slavei + 1; if (slavei == 3) @@ -1346,7 +1366,7 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) if (masteri && gsyncd_url_check (words[masteri])) goto out; - if (slavei && !gsyncd_url_check (words[slavei])) + if (slavei && !glob && !gsyncd_url_check (words[slavei])) goto out; w = str_getunamb (words[cmdi], opwords); @@ -1376,7 +1396,8 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) } else GF_ASSERT (!"opword mismatch"); - if (type != GF_GSYNC_OPTION_TYPE_CONFIG && cmdi < wordcount - 1) + if (type != GF_GSYNC_OPTION_TYPE_CONFIG && + (cmdi < wordcount - 1 || glob)) goto out; /* If got so far, input is valid, assemble the message */ @@ -1397,7 +1418,8 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) case 1: if (words[cmdi + 1][0] == '!') { (words[cmdi + 1])++; - subop = gf_strdup ("del"); + if (gf_asprintf (&subop, "del%s", glob ? "-glob" : "") == -1) + subop = NULL; } else subop = gf_strdup ("get"); @@ -1406,7 +1428,8 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) goto out; break; default: - subop = gf_strdup ("set"); + if (gf_asprintf (&subop, "set%s", glob ? "-glob" : "") == -1) + subop = NULL; ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1])); if (ret < 0) diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py index f3b5988ade0..67a873cb57c 100644 --- a/xlators/features/marker/utils/syncdaemon/gsyncd.py +++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py @@ -9,6 +9,7 @@ import signal import select import optparse import fcntl +import fnmatch from optparse import OptionParser, SUPPRESS_HELP from logging import Logger from errno import EEXIST, ENOENT @@ -177,7 +178,7 @@ def main_i(): op.add_option('--config-' + a, metavar='OPT', type=str, dest='config', action='callback', callback=store_local_obj(a, lambda vx: {'opt': vx})) op.add_option('--config-get-all', dest='config', action='callback', callback=store_local_obj('get', lambda vx: {'opt': None})) - for m in ('', '-rx'): + for m in ('', '-rx', '-glob'): # call this code 'Pythonic' eh? # have to define a one-shot local function to be able to inject (a value depending on the) # iteration variable into the inner lambda @@ -186,7 +187,7 @@ def main_i(): callback=store_local_obj('set', lambda vx: {'opt': vx[0], 'val': vx[1], 'rx': rx})) op.add_option('--config-del' + m, metavar='OPT', type=str, dest='config', action='callback', callback=store_local_obj('del', lambda vx: {'opt': vx, 'rx': rx})) - conf_mod_opt_regex_variant(not not m) + conf_mod_opt_regex_variant(m and m[1:] or False) op.add_option('--normalize-url', dest='url_print', action='callback', callback=store_local_curry('normal')) op.add_option('--canonicalize-url', dest='url_print', action='callback', callback=store_local_curry('canon')) @@ -226,8 +227,11 @@ def main_i(): raise GsyncdError('tunable %s is not set to value %s required for restricted SSH invocaton' % \ (k, v)) - if getattr(confdata, 'rx', None): + confrx = getattr(confdata, 'rx', None) + if confrx: # peers are regexen, don't try to parse them + if confrx == 'glob': + args = [ '\A' + fnmatch.translate(a) for a in args ] canon_peers = args namedict = {} else: diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 19975a689f4..eae5dd827b4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -484,6 +484,7 @@ gsync_verify_config_options (dict_t *dict, char **op_errstr) char *slave = NULL; char *op_name = NULL; char *op_value = NULL; + char *t = NULL; gf_boolean_t banned = _gf_true; if (dict_get_str (dict, "subop", &subop) != 0) { @@ -517,13 +518,16 @@ gsync_verify_config_options (dict_t *dict, char **op_errstr) if (strcmp (subop, "get") == 0) return 0; - if (strcmp (subop, "set") != 0 && strcmp (subop, "del") != 0) { + t = strtail (subop, "set"); + if (!t) + t = strtail (subop, "del"); + if (!t || (t[0] && strcmp (t, "-glob") != 0)) { gf_log ("", GF_LOG_WARNING, "unknown subop %s", subop); *op_errstr = gf_strdup ("Invalid config request"); return -1; } - if (strcmp (subop, "set") == 0 && + if (strtail (subop, "set") && dict_get_str (dict, "op_value", &op_value) != 0) { gf_log ("", GF_LOG_WARNING, "missing value for set"); *op_errstr = gf_strdup ("missing value"); @@ -1105,7 +1109,7 @@ glusterd_gsync_configure (glusterd_volinfo_t *volinfo, char *slave, if (ret != 0) goto out; - if (strcmp (subop, "set") == 0) { + if (strtail (subop, "set")) { ret = dict_get_str (dict, "op_value", &op_value); if (ret != 0) goto out; |