From a801b09e0bb50626354de080a39f87090dc0209d Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Mon, 24 Mar 2014 05:14:53 +0530 Subject: cli/snapshot : Clear messages while creating SNAP with invalid scenarios. 1) Create with Description key and without actual description will display proper message. 2) Create with snapname containing special character will fail (volname convention is followed). 3) Create with Multiple Description will fail with proper message. Change-Id: I9173a0ffe2bf77c10a4e383268bd8d99906217a0 BUG: 1040978 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7324 Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 8e914fa87..0a2bb5318 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2833,24 +2833,37 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, int ret = -1; uint64_t volcount = 0; char key[PATH_MAX] = ""; + char *snapname = NULL; GF_ASSERT (words); GF_ASSERT (dict); if (wordcount <= cmdi + 1) { + cli_err ("Invalid Syntax."); gf_log ("cli", GF_LOG_ERROR, "Too less words for snap create command"); goto out; } if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) { - cli_out ("snapshot create: failed: snapname cannot exceed " + cli_err ("snapshot create: failed: snapname cannot exceed " "256 characters."); gf_log ("cli", GF_LOG_ERROR, "Snapname too long"); goto out; } + snapname = (char *) words[cmdi]; + for (i = 0 ; i < strlen (snapname); i++) { + /* Following volume name convention */ + if (!isalnum (snapname[i]) && (snapname[i] != '_' + && (snapname[i] != '-'))) { + /* TODO : Is this message enough?? */ + cli_err ("Please provide a valid snapname"); + goto out; + } + } + ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Could not save snap " @@ -2878,7 +2891,7 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, if (i >= cmdi + 2) { ret = -1; - cli_out("Creating multiple volume snapshot is not " + cli_err("Creating multiple volume snapshot is not " "supported as of now"); goto out; } @@ -2888,7 +2901,7 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, if (volcount == 0) { ret = -1; - cli_out ("Please provide the volume name"); + cli_err ("Please provide the volume name"); gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } @@ -2912,6 +2925,7 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, ++i; if (i > (wordcount - 1)) { ret = -1; + cli_err ("Please provide a description"); gf_log ("cli", GF_LOG_ERROR, "Description not provided"); goto out; @@ -2935,6 +2949,7 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, if ((strcmp (words[i], "force") != 0)) { ret = -1; + cli_err ("Invalid Syntax."); gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } -- cgit