summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-03-13 04:15:39 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-13 04:44:49 -0700
commit736fd5d9073d00bd80595afd158b4f1ab2d4c253 (patch)
treef92e976bef9a0df61ba74dd17bb4eaf0548d1c9b /cli/src
parent4f6c888c5cc32381273d563b184bcb032ee38cc9 (diff)
cli/snapshot : Fix for snapshot create with snapname l,r,i,d.
Change-Id: Ib7fd1ca766997bce86062e5c10c5acf7e5edae60 BUG: 1075512 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7236 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-parser.c42
1 files changed, 28 insertions, 14 deletions
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);