summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-03-24 05:14:53 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-24 05:49:05 -0700
commita801b09e0bb50626354de080a39f87090dc0209d (patch)
treecd43aaa515c1dc87f8f345e6bb8e6cc689635fab
parente481921863d91dfce5550ce9722e99129f5979c2 (diff)
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 <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7324 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 8e914fa..0a2bb53 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;
}