summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c64
-rw-r--r--cli/src/cli-rpc-ops.c70
2 files changed, 78 insertions, 56 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 59e951636..1059ea90e 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");
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 6ee039fbc..6e88fba66 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");