From 736fd5d9073d00bd80595afd158b4f1ab2d4c253 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 13 Mar 2014 04:15:39 +0530 Subject: cli/snapshot : Fix for snapshot create with snapname l,r,i,d. Change-Id: Ib7fd1ca766997bce86062e5c10c5acf7e5edae60 BUG: 1075512 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7236 Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 4357e657e..15675c884 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2851,13 +2851,6 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, goto out; } - /* Snap name cannot be keyword "description" or "force" */ - if (strcmp (words[cmdi], "description") == 0 || - strcmp (words[cmdi], "force") == 0) { - gf_log ("cli", GF_LOG_ERROR, "snapname cannot be keyword"); - goto out; - } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Could not save snap " @@ -3378,6 +3371,24 @@ out : return ret; } +int +validate_snapname (const char *snapname, char **opwords) { + int ret = -1; + int i = 0; + + GF_ASSERT (snapname); + GF_ASSERT (opwords); + + for (i = 0 ; opwords[i] != NULL; i++) { + if (strcmp (opwords[i], snapname) == 0) { + cli_out ("\"%s\" cannot be a snapname", snapname); + goto out; + } + } + ret = 0; +out : + return ret; +} int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, @@ -3388,9 +3399,11 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; unsigned int cmdi = 0; char *w = NULL; - char *opwords[] = {"create", "delete", "restore", - "start", "stop", "list", "status", - "config", "info", NULL}; + char *opwords[] = {"create", "delete", "restore", "start", + "stop", "list", "status", "config", + "info", NULL}; + char *invalid_snapnames[] = {"description", "force", + "volume", NULL}; GF_ASSERT (words); GF_ASSERT (options); @@ -3452,12 +3465,13 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, */ /* In cases where the snapname is not given then - * parsing fails & snapname cannot be an opword, - * that check is made here + * parsing fails & snapname cannot be "description", + * "force" and "volume", that check is made here */ - w = str_getunamb (words[2], opwords); - if (w) + ret = validate_snapname (words[2], invalid_snapnames); + if (ret) { goto out; + } ret = cli_snap_create_parse (dict, words, wordcount, cmdi); -- cgit