summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-02-10 05:52:15 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-04 06:56:25 -0800
commitd059ac1a1a9fc2a286f29361830c1632dc8ce3cf (patch)
tree5bd2a8822cdb36ddb3449238fde1240c71c92b95 /cli
parentfe5927b6bd1ed795c9e85996e7c54c3abe36ceba (diff)
CLI/snapshot : Snapshot create CLI changes.
Syntax: gluster snapshot create <snap-name> <vol-names> [description <description>] [force]. New change: With the snap driven approach, While creating the snapshot, We have to mention the snap-name first and then the volumes to be associated with that. Corresponding changes has been made in CLI,and all the hyphenated options are replaced by keywords. Previous Syntax : snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>] Change-Id: I9b4caf9629fdc3195b682190d999db2ecd9ce3e1 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/6947 Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c317
-rw-r--r--cli/src/cli-cmd-snapshot.c2
2 files changed, 133 insertions, 186 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index c70c5a752..62c383c44 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -182,7 +182,7 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
char *invalid_volnames[] = {"volume", "type", "subvolumes", "option",
"end-volume", "all", "volume_not_in_ring",
- NULL};
+ "description", NULL};
char *w = NULL;
int op_count = 0;
int32_t replica_count = 1;
@@ -2763,19 +2763,10 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words,
desc = GF_CALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, sizeof(char),
gf_common_mt_char);
if (!desc) {
- gf_log ("", GF_LOG_ERROR, "Out Of Memory");
ret = -1;
goto out;
}
- /* Creating the description string */
- if ((strcmp (words[desc_opt_loc], "-n") == 0) ||
- (strcmp (words[desc_opt_loc], "-d") == 0)) {
- cli_out ("snapshot create: failed: Options(-n/-d) "
- "are not valid descriptions");
- ret = -1;
- goto out;
- }
if (strlen (words[desc_opt_loc]) >= MAX_SNAP_DESCRIPTION_LEN) {
cli_out ("snapshot create: description truncated: "
@@ -2791,7 +2782,8 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words,
ret = dict_set_dynstr (dict, "snap-description", desc);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save snap description");
+ gf_log ("cli", GF_LOG_ERROR, "Unable to save snap "
+ "description");
goto out;
}
@@ -2803,205 +2795,164 @@ out:
return ret;
}
-int32_t
-cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
- unsigned int cmdi)
-{
- unsigned int volcount = 0;
- unsigned int no_of_wrds_in_desc = 0;
- unsigned int name_opt_loc = 0;
- unsigned int desc_opt_loc = 0;
- char volname_buf[PATH_MAX] = "";
- int32_t ret = -1;
- int32_t i = 0;
-
- GF_ASSERT (cmdi > 0);
-
- /* Finding the "-n" and "-d" in the cli */
- for (i = cmdi + 1; i < wordcount; i++) {
- if ((strcmp (words[i], "-n") == 0) &&
- (name_opt_loc == 0))
- name_opt_loc = i;
-
- if ((strcmp (words[i], "-d") == 0) &&
- (desc_opt_loc == 0))
- desc_opt_loc = i;
- }
-
- if ((name_opt_loc == 0) && (desc_opt_loc == 0)) {
- /* No snap-name and description has been given */
-
- volcount = (wordcount - 1) - cmdi;
- } else if ((name_opt_loc > cmdi + 1) && (desc_opt_loc == 0)) {
- /* If only name and no description is given */
-
- /* if more than one or no snap name is given */
- if (((wordcount - 1) - name_opt_loc) != 1) {
- cli_out ("snapshot create: failed: "
- "Invalid snap name arguments");
- ret = -1;
- goto out;
- }
+/* Function to check whether the Volume name is repeated */
+int
+check_if_volname_repeated (const char **words, unsigned int start_index,
+ uint64_t end_index) {
+ uint64_t i = -1;
+ int ret = 0;
- volcount = (name_opt_loc - 1) - cmdi;
- } else if ((name_opt_loc == 0) && (desc_opt_loc > cmdi + 1)) {
- /* If no name and only description is given */
+ GF_ASSERT (words);
- /* Description should not be blank */
- no_of_wrds_in_desc = (wordcount - 1) - desc_opt_loc;
- if (no_of_wrds_in_desc != 1) {
- cli_out ("snapshot create: failed: "
- "Invalid description");
+ for (i = start_index ; i < end_index ; i++) {
+ if (strcmp (words[i], words[end_index]) == 0) {
ret = -1;
goto out;
}
+ }
+out :
+ return ret;
+}
- volcount = (desc_opt_loc - 1) - cmdi;
- } else if ((name_opt_loc > cmdi + 1) && (desc_opt_loc > cmdi + 1)) {
- /* Both name and description is given */
- /* Figuring out which comes first */
- if (name_opt_loc < desc_opt_loc) {
- /* if more than one or no snap name is given */
- if ((desc_opt_loc - name_opt_loc) != 2) {
- cli_out ("snapshot create: failed: "
- "Invalid snap name arguments");
- ret = -1;
- goto out;
- }
- /* Description should not be blank */
- no_of_wrds_in_desc = (wordcount - 1) - desc_opt_loc;
- if (no_of_wrds_in_desc != 1) {
- cli_out ("snapshot create: failed: "
- "Invalid description");
- ret = -1;
- goto out;
- }
+/* snapshot create <snap-name> <vol-name(s)> [description <description>]
+ * [force]
+ * @arg-0, dict : Request Dictionary to be sent to server side.
+ * @arg-1, words : Contains individual words of CLI command.
+ * @arg-2, wordcount: Contains number of words present in the CLI command.
+ * @arg-3, cmdi : command index, here cmdi is "2" (gluster snapshot create)
+ *
+ * return value : -1 on failure
+ * 0 on success
+ */
+int
+cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
+ unsigned int cmdi) {
+ uint64_t i = 0;
+ int ret = -1;
+ uint64_t volcount = 0;
+ char key[PATH_MAX] = "";
- volcount = (name_opt_loc - 1) - cmdi;
- } else if (desc_opt_loc < name_opt_loc) {
- /* if more than one or no snap name is given */
- if (((wordcount - 1) - name_opt_loc) != 1) {
- cli_out ("snapshot create: failed: "
- "Invalid snap name arguments");
- ret = -1;
- goto out;
- }
+ GF_ASSERT (words);
+ GF_ASSERT (dict);
- /* Description should not be blank */
- no_of_wrds_in_desc = (name_opt_loc) - desc_opt_loc -1;
- if (no_of_wrds_in_desc != 1) {
- cli_out ("snapshot create: failed: "
- "Invalid description");
- ret = -1;
- goto out;
- }
+ if (wordcount <= cmdi + 1) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Too less words for snap create command");
+ goto out;
+ }
- volcount = (desc_opt_loc - 1) - cmdi;
- }
+ /* 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;
}
- /*At least one volume name should be present */
- if (volcount < 1) {
- cli_out ("snapshot create: failed: No volume name provided");
- ret = -1;
+ ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save snap "
+ "name");
goto out;
}
- /* Saving the volume names */
- for (i = 2; i < volcount + 2; i++) {
- ret = snprintf (volname_buf, sizeof(volname_buf) - 1,
- "volname%d", i - 1);
- volname_buf[ret] = '\0';
+ /* Filling volume name in the dictionary */
+ for (i = cmdi + 1 ; i < wordcount
+ && (strcmp (words[i], "description")) != 0
+ && (strcmp (words[i], "force") != 0); i++) {
+ volcount++;
+ /* volume index starts from 1 */
+ ret = snprintf (key, sizeof (key),"volname%ld", volcount);
+ if (ret < 0) {
+ goto out;
+ }
- ret = dict_set_str (dict, volname_buf,
- (char *)words[i]);
+ ret = dict_set_str (dict, key, (char *)words[i]);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save %s",
- volname_buf);
+ gf_log ("cli", GF_LOG_ERROR, "Could not "
+ "save volume name");
goto out;
}
+
+ if (i >= cmdi + 2) {
+ ret = -1;
+ cli_out("Creating multiple volume snapshot is not "
+ "supported as of now");
+ goto out;
+ }
+ /* TODO : remove this above condition check once
+ * multiple volume snapshot is supported */
+ }
+
+ if (volcount == 0) {
+ ret = -1;
+ cli_out ("Please provide the volume name");
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
}
- /* Saving the volcount */
ret = dict_set_int32 (dict, "volcount", volcount);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save volcount");
+ gf_log ("cli", GF_LOG_ERROR, "Could not save volcount");
goto out;
}
- /* Saving snap-name/cg-name in dict */
- if (name_opt_loc > cmdi + 1) {
- if (strstr((char *)words[name_opt_loc + 1], " ")) {
- cli_out ("snapshot create: failed: Invalid snap name");
- ret = -1;
- goto out;
- }
+ /* Verify how we got out of "for" loop,
+ * if it is by reaching wordcount limit then goto "out",
+ * because we need not parse for "description" and "force"
+ * after this.
+ */
+ if (i == wordcount) {
+ goto out;
+ }
- if ((strcmp ((char *)words[name_opt_loc + 1], "-n") == 0) ||
- (strcmp ((char *)words[name_opt_loc + 1], "-d") == 0)) {
- cli_out ("snapshot create: failed: Options(-n/-d) "
- "are not valid snap names");
+ if ((strcmp (words[i], "description")) == 0) {
+ ++i;
+ if (i > (wordcount - 1)) {
ret = -1;
+ gf_log ("cli", GF_LOG_ERROR,
+ "Description not provided");
goto out;
}
- /* Decide if it's a cg-name or a snap-name */
- if (volcount > 1) {
- ret = dict_set_str (dict, "cg-name",
- (char *)words[name_opt_loc + 1]);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save cg-name");
- goto out;
- }
- } else {
- ret = dict_set_str (dict, "snap-name",
- (char *)words[name_opt_loc + 1]);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to save snap-name");
- goto out;
- }
- }
- }
-
- /* Parsing the description and saving it in the dict */
- if (desc_opt_loc > cmdi + 1) {
- /* desc_opt_loc contains the position of -d option
- used to indicate description. So send directly
- the position of the description (i.e desc_opt_loc + 1)
- for parsing
- */
- ret = cli_snap_create_desc_parse (dict, words,
- wordcount,
- desc_opt_loc + 1);
+ ret = cli_snap_create_desc_parse(dict, words, wordcount, i);
if (ret) {
- gf_log ("", GF_LOG_ERROR,
- "Unable to parse snap-description");
+ gf_log ("cli", GF_LOG_ERROR, "Could not save snap "
+ "description");
goto out;
}
+
+ if ( i == (wordcount - 1))
+ goto out;
+ i++;
+ /* point the index to next word.
+ * As description might be follwed by force option.
+ * Before that, check if wordcount limit is reached
+ */
}
-out:
- return ret;
-}
+ if ((strcmp (words[i], "force") != 0)) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+ ret = dict_set_int8 (dict, "snap-force", 1);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save "
+ "snap force option");
+ goto out;
+ }
-/* Function to check whether the Volume name is repeated */
-int
-check_if_volname_repeated (char *volname, const char **words,
- int64_t start_index, int64_t end_index) {
- int64_t i = -1;
- int ret = 0;
+ /* Check if the command has anything after "force" keyword */
+ if (++i < wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
- GF_ASSERT (volname);
- GF_ASSERT (words);
+ ret = 0;
- for (i = start_index ; i < end_index ; i++) {
- if (strcmp (words[i], (char *)volname) == 0) {
- ret = -1;
- goto out;
- }
- }
out :
return ret;
}
@@ -3152,12 +3103,6 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount,
for (i = 0; i < vol_count; ++i) {
vol_name = (char*) words[vol_start_index + i];
/* check if volume name is repeated */
- if (i >= 1)
- loop_ret = check_if_volname_repeated
- ((char *)vol_name, words,
- vol_start_index, vol_start_index+i);
- if (loop_ret == -1 && i>=1)
- continue;
snprintf (key, sizeof (key), "vol%ld", actual_vol_count);
ret = dict_set_str (dict, key, (char *)vol_name);
if (ret) {
@@ -3568,18 +3513,20 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
switch (type) {
case GF_SNAP_OPTION_TYPE_CREATE:
{
- /*syntax:
- snapshot create <volnames> [-n <snap-name/cg-name>]
- [-d <description>]
- */
-
- /* In cases where the vol-name is not given
- * parsing fails. volname cannot be an opword.
- * and that is what this check verifies */
+ /* Syntax :
+ * gluster snapshot create <snap-name> <vol-name(s)>
+ * [description <description>]
+ * [force]
+ */
+
+ /* In cases where the snap-name is not given then
+ * parsing fails & snapname cannot be an opword,
+ * that check is made here
+ */
w = str_getunamb (words[2], opwords);
if (w)
goto out;
- cmdi = 1;
+ cmdi = 2;
ret = cli_snap_create_parse (dict, words,
wordcount, cmdi);
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 1a5a2feef..44dbf8a7c 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -83,7 +83,7 @@ struct cli_cmd snapshot_cmds[] = {
cli_cmd_snapshot_help_cbk,
"display help for snapshot commands"
},
- { "snapshot create <volnames> [-n <snap-name|cg-name>] [-d <description>]",
+ { "snapshot create <snapname> <volnames> [description <description>] [force]",
cli_cmd_snapshot_cbk,
"Snapshot Create."
},