summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-parser.c103
-rw-r--r--cli/src/cli-cmd-snapshot.c10
-rw-r--r--cli/src/cli-rpc-ops.c70
3 files changed, 118 insertions, 65 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 59e951636..6abd97ce7 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2754,12 +2754,10 @@ out:
int32_t
cli_snap_create_desc_parse (dict_t *dict, const char **words,
- int wordcount, int32_t desc_opt_loc,
- unsigned int no_of_wrds_in_desc)
+ size_t wordcount, int32_t desc_opt_loc)
{
int32_t ret = -1;
char *desc = NULL;
- int32_t i = 0;
int32_t desc_len = 0;
desc = GF_CALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, sizeof(char),
@@ -2771,31 +2769,26 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words,
}
/* Creating the description string */
- for (i = 0; i < no_of_wrds_in_desc; i++) {
- if ((strcmp (words[desc_opt_loc + 1 + i], "-n") == 0) ||
- (strcmp (words[desc_opt_loc + 1 + i], "-d") == 0)) {
- cli_out ("snapshot create: failed: Options(-n/-d) "
- "are not valid descriptions");
- ret = -1;
- goto out;
- }
-
- strcat (desc, words[desc_opt_loc + 1 + i]);
- strcat (desc, " ");
- /* Calculating the size of the description as given by the user */
- desc_len += strlen(words[desc_opt_loc + 1 + i]);
- desc_len++;
+ 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;
}
- /* Removing the last space in the string */
- desc[--desc_len] = '\0';
-
- if (desc_len > MAX_SNAP_DESCRIPTION_LEN) {
+ if (strlen (words[desc_opt_loc]) >= MAX_SNAP_DESCRIPTION_LEN) {
cli_out ("snapshot create: description truncated: "
"Description provided is longer than 1024 characters");
- desc[MAX_SNAP_DESCRIPTION_LEN] = '\0';
+ desc_len = MAX_SNAP_DESCRIPTION_LEN;
+ } else {
+ desc_len = strlen (words[desc_opt_loc]);
}
+ strncpy (desc, words[desc_opt_loc], desc_len);
+ desc[desc_len] = '\0';
+ /* Calculating the size of the description as given by the user */
+
ret = dict_set_dynstr (dict, "snap-description", desc);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to save snap description");
@@ -2804,11 +2797,8 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words,
ret = 0;
out:
-
- if (ret) {
- if (desc)
- GF_FREE (desc);
- }
+ if (ret && desc)
+ GF_FREE (desc);
return ret;
}
@@ -2859,9 +2849,9 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
/* Description should not be blank */
no_of_wrds_in_desc = (wordcount - 1) - desc_opt_loc;
- if (no_of_wrds_in_desc == 0) {
+ if (no_of_wrds_in_desc != 1) {
cli_out ("snapshot create: failed: "
- "No description provided");
+ "Invalid description");
ret = -1;
goto out;
}
@@ -2882,9 +2872,9 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
/* Description should not be blank */
no_of_wrds_in_desc = (wordcount - 1) - desc_opt_loc;
- if (no_of_wrds_in_desc == 0) {
+ if (no_of_wrds_in_desc != 1) {
cli_out ("snapshot create: failed: "
- "No description provided");
+ "Invalid description");
ret = -1;
goto out;
}
@@ -2901,9 +2891,9 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
/* Description should not be blank */
no_of_wrds_in_desc = (name_opt_loc) - desc_opt_loc -1;
- if (no_of_wrds_in_desc == 0) {
+ if (no_of_wrds_in_desc != 1) {
cli_out ("snapshot create: failed: "
- "No description provided");
+ "Invalid description");
ret = -1;
goto out;
}
@@ -2977,10 +2967,14 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
/* 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,
- no_of_wrds_in_desc);
+ desc_opt_loc + 1);
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Unable to parse snap-description");
@@ -3184,6 +3178,11 @@ out:
return ret;
}
+/* function cli_snap_config_parse
+ return value: -1 on failure
+ 1 if user cancels the operation
+ 0 on success
+*/
int32_t
cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
struct cli_state *state)
@@ -3297,7 +3296,9 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
answer = cli_cmd_get_confirmation (state,
conf_vals->question);
if (GF_ANSWER_NO == answer) {
- ret = -1;
+ ret = 1;
+ gf_log ("", GF_LOG_DEBUG, "User cancelled "
+ "snapshot config operation");
goto out;
}
}
@@ -3312,15 +3313,23 @@ out:
also should be given in the command. If cg should be removed,
then volume name is not necessary.
"gluster snapshot delete (<volname> -s <snapname> | -c <cgname>)"
+ return value: -1 on failure
+ 1 if user cancels the operation
+ 0 on success
*/
int32_t
cli_snap_remove_parse (dict_t *dict, const char **words, int wordcount,
- unsigned int cmdi)
+ unsigned int cmdi, struct cli_state *state)
{
uint32_t name_opt_loc = 0;
int32_t ret = -1;
uint32_t i = 0;
gf_boolean_t is_cg = _gf_false;
+ const char *question = NULL;
+ gf_answer_t answer = GF_ANSWER_NO;
+
+ question = "Deleting snap will erase all information about the snap. "
+ "Do you want to continue?";
GF_ASSERT (dict);
GF_ASSERT (words);
@@ -3395,6 +3404,14 @@ cli_snap_remove_parse (dict_t *dict, const char **words, int wordcount,
}
}
+ answer = cli_cmd_get_confirmation (state, question);
+ if (GF_ANSWER_NO == answer) {
+ ret = 1;
+ gf_log ("", GF_LOG_DEBUG, "User cancelled "
+ "snapshot delete operation");
+ goto out;
+ }
+
out:
return ret;
}
@@ -3613,10 +3630,11 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
cmdi = 2;
ret = cli_snap_remove_parse (dict, words,
- wordcount, cmdi);
+ wordcount, cmdi, state);
if (ret) {
- gf_log ("", GF_LOG_ERROR,
- "remove command parsing failed.");
+ if (ret < 0)
+ gf_log ("", GF_LOG_ERROR,
+ "remove command parsing failed.");
goto out;
}
break;
@@ -3628,8 +3646,9 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
ret = cli_snap_config_parse (words, wordcount, dict,
state);
if (ret) {
- gf_log ("cli", GF_LOG_ERROR,
- "config command parsing failed.");
+ if (ret < 0)
+ gf_log ("cli", GF_LOG_ERROR,
+ "config command parsing failed.");
goto out;
}
break;
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 6d31dc2d5..f16e68dd6 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -53,8 +53,14 @@ cli_cmd_snapshot_cbk (struct cli_state *state, struct cli_cmd_word *word,
/* Parses the command entered by the user */
ret = cli_cmd_snapshot_parse (words, wordcount, &options, state);
if (ret) {
- cli_usage_out (word->pattern);
- parse_err = 1;
+ if (ret < 0) {
+ cli_usage_out (word->pattern);
+ parse_err = 1;
+ }
+ else {
+ /* User might have cancelled the snapshot operation */
+ ret = 0;
+ }
goto out;
}
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 648ab6d65..e9c24fe21 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7560,22 +7560,25 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) {
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (ret == 0) {
cli_out ("%s",get_buffer);
ret = 0;
goto out;
}
+
ret = snprintf (buffer, sizeof(buffer), "%s.volname", prefix_str);
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (get_buffer == NULL){
ret = 0;
goto out;
}
- cli_out ("\nVolume Name : %s", get_buffer);
+ cli_out ("\n%-28s %s %s", "Volume Name", ":", get_buffer);
/* if Volume is present then get the snapcount.
* string is "snaplist.vol{0..}.snap-count.
*/
@@ -7584,6 +7587,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_uint64 (dict_n, buffer, &snapcount);
if (ret) {
gf_log("", GF_LOG_ERROR, "Could not fetch snapcount");
@@ -7610,9 +7614,11 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) {
goto out;
}
+
ret = dict_get_uint64 (dict_n, buffer, &snapcount_total);
if (!ret)
- cli_out ("Number of snaps taken : %ld", snapcount_total);
+ cli_out ("%-28s %s %ld", "Number of snaps taken", ":",
+ snapcount_total);
else
gf_log ("", GF_LOG_ERROR, "Failed to get snapcount total");
@@ -7621,13 +7627,15 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) {
goto out;
}
+
ret = dict_get_uint64 (dict_n, buffer, &snap_available);
if (!ret)
- cli_out ("Number of snaps available : %ld",
- snap_available);
+ cli_out ("%-28s %s %ld", "Number of snaps available",
+ ":", snap_available);
else
gf_log ("", GF_LOG_ERROR, "Failed to get snap-available");
+
for (i = 0 ; i < snapcount; i++) {
/* get snapname "snaplist.vol-{0..}.snap-{0..}.snapname" */
ret = snprintf (buffer, sizeof(buffer),
@@ -7635,22 +7643,28 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out ("\n\tSnap Name : %s",get_buffer);
+ cli_out ("\n\t%-17s %s %s", "Snap Name", ":",
+ get_buffer);
else
- cli_out ("\n\tSnap Name : %s","Does not exist");
+ cli_out ("\n\t%-17s %s %s", "Snap Name", ":",
+ "Does not exist");
ret = snprintf (buffer, sizeof(buffer),
"%s.snap-%ld.snap-time", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out ("\tSnap Time : %s",get_buffer);
+ cli_out ("\t%-17s %s %s", "Snap Time", ":",
+ get_buffer);
else
- cli_out ("\tSnap Time : %s","Does not exist");
+ cli_out ("\t%-17s %s %s", "Snap Time", ":",
+ "Does not exist");
ret = snprintf (buffer, sizeof(buffer), "%s.snap-%ld.snap-id"
@@ -7658,11 +7672,14 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out("\tSnap ID : %s",get_buffer);
+ cli_out("\t%-17s %s %s", "Snap UUID", ":",
+ get_buffer);
else
- cli_out("\tSnap ID : %s","Does not exist");
+ cli_out("\t%-17s %s %s", "Snap UUID", ":",
+ "Does not exist");
if(detail == 0) {
/* if snap_details is set to zero
@@ -7675,45 +7692,56 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out("\tCG Name : %s",get_buffer);
+ cli_out("\t%-17s %s %s", "CG Name", ":",
+ get_buffer);
else
- cli_out("\tCG Name : %s","Does not exist");
+ cli_out("\t%-17s %s %s","CG Name", ":",
+ "Does not exist");
ret = snprintf (buffer, sizeof(buffer),
"%s.snap-%ld.cg-id", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out("\tCG ID : %s",get_buffer);
+ cli_out("\t%-17s %s %s", "CG ID", ":",
+ get_buffer);
else
- cli_out("\tCG ID : %s","Does not exist");
+ cli_out("\t%-17s %s %s", "CG ID", ":",
+ "Does not exist");
ret = snprintf (buffer, sizeof(buffer),
"%s.snap-%ld.snap-desc", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out ("\tSnap Description : %s",get_buffer);
+ cli_out ("\t%-17s %s %s", "Snap Description", ":",
+ get_buffer);
else
- cli_out ("\tSnap Description : %s",
- "Description not present");
+ cli_out ("\t%-17s %s %s", "Snap Description", ":",
+ "Description not present");
ret = snprintf (buffer, sizeof(buffer),
"%s.snap-%ld.snap-status", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
+
ret = dict_get_str (dict_n, buffer, &get_buffer);
if (!ret)
- cli_out ("\tSnap Status : %s",get_buffer);
+ cli_out ("\t%-17s %s %s", "Snap Status", ":",
+ get_buffer);
else
- cli_out ("\tSnap Status : %s","Does not exist");
+ cli_out ("\t%-17s %s %s", "Snap Status", ":",
+ "Does not exist");
ret = 0;
}
@@ -8117,9 +8145,9 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
- ret = dict_get_str (dict, "cg-name", &cg_name);
+ ret = dict_get_str (dict, "cgname", &cg_name);
if (ret) {
- ret = dict_get_str (dict, "snap-name", &snap_name);
+ ret = dict_get_str (dict, "snapname", &snap_name);
if (ret) {
gf_log (frame->this->name, GF_LOG_ERROR,
"Failed to get CG name or snap name");