summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2013-10-24 10:35:58 +0000
committershishir gowda <sgowda@redhat.com>2013-11-15 14:39:42 +0530
commit30e6c5364a0484fddc655d43cd3a0224f21343e4 (patch)
tree3755b631aa3dec14f0aaffa4051e4f2754f79d25
parent2123e83976b1ca77bb253cabda3092e79c406145 (diff)
CLI : Snapshot List,Integration with glusterd
Change in Naming convention: "snap_details", "snap_count" and so on is replaced by "snap-details", "snap-count" so on. Total snapcount introduced. Separate check is made for repeated Volume Name Ex : "gluster snapshot list vol1 vol2 vol1 vol2" is considered as "gluster snapshot list vol1 vol2" *This is still a work in progress* *have to test CG list once CG Store is ready* Change-Id: I45e2904eb8bdbf78de8665f20ba9605c38320307 Signed-off-by: Sachin Pandit <spandit@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c96
-rw-r--r--cli/src/cli-rpc-ops.c66
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c30
3 files changed, 135 insertions, 57 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index cf743e2..cf79091 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2972,6 +2972,26 @@ out:
return ret;
}
+/* 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;
+
+ GF_ASSERT (volname);
+ GF_ASSERT (words);
+
+ for (i = start_index ; i < end_index ; i++) {
+ if (strcmp (words[i], (char *)volname) == 0) {
+ ret = -1;
+ goto out;
+ }
+ }
+out :
+ return ret;
+}
+
/* snapshot list [<volnames> | <volname> -s <snapname> | -c <cgname>] [-d]
* cmdi is command index which contains number of standard arguments in
* command, here cmdi is 2 i.e "gluster snapshot list"
@@ -2979,21 +2999,29 @@ out:
int
cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
{
- int ret = -1;
- int i = 0;
- int64_t vol_count = 0;
- int vol_start_index = -1;
- int8_t snap_details = 0;
- char *snap_name = NULL;
- char *cg_name = NULL;
- char *vol_name = NULL;
- char key[256] = "";
+ int ret = -1;
+ int loop_ret = -1;
+ int64_t actual_vol_count = 0;
+ int64_t i = 0;
+ int64_t vol_count = 0;
+ int vol_start_index = -1;
+ int8_t snap_details = 0;
+ const char *snap_name = NULL;
+ const char *cg_name = NULL;
+ const char *vol_name = NULL;
+ char key[256] = "";
GF_ASSERT (dict);
GF_ASSERT (words);
GF_ASSERT (wordcount >= cmdi);
/* if command is "gluster snapshot list*/
if (wordcount == cmdi) {
+ ret = dict_set_int8 (dict, "snap-details", snap_details);
+ if (ret) {
+ gf_log("", GF_LOG_ERROR, "Failed to set snap-details");
+ ret = -1;
+ goto out;
+ }
ret = 0;
goto out;
}
@@ -3004,6 +3032,7 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
/* If option is already set */
gf_log("", GF_LOG_ERROR,
"snap_details already set");
+ ret = -1;
goto out;
}
snap_details = 1;
@@ -3018,10 +3047,12 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
*/
gf_log("", GF_LOG_ERROR, "Invalid snap_name"
" or snap_name already parsed"
- " or volname specified is not equal 1");
+ " or number of volumes greater than 1");
+ ret = -1;
goto out;
}
- snap_name = (char*) words[i]; // word followed by -s is snapname
+ /* word followed by -s is snapname */
+ snap_name = words[i];
} else if (strcmp (words[i], "-c") == 0) {
if ((wordcount - 1) == i || (cg_name != NULL)
|| strcmp (words[++i], "-d") == 0
@@ -3031,14 +3062,16 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
*/
gf_log("", GF_LOG_ERROR, "Invalid cg_name"
" or cg_name already parsed");
+ ret = -1;
goto out;
}
- cg_name = (char*) words[i];
+ cg_name = words[i];
} else {
if (vol_count != 0) {
/* if vol names already set */
gf_log("", GF_LOG_ERROR,
"Vol Names already set");
+ ret = -1;
goto out;
}
@@ -3061,6 +3094,11 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
}
}
+ ret = dict_set_int8 (dict, "snap-details", snap_details);
+ if (ret) {
+ gf_log("", GF_LOG_ERROR, "Failed to set snap-details");
+ goto out;
+ }
/* if CG name is present in the command then fill it to dictionary */
if (cg_name != NULL) {
if (snap_name != NULL || vol_count != 0) {
@@ -3070,11 +3108,13 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
*/
gf_log("", GF_LOG_ERROR, "details of single snap"
" belonging to a CG is not supported");
+ ret = -1;
goto out;
}
- ret = dict_set_str(dict, "cg_name", cg_name);
+ ret = dict_set_str(dict, "cgname", (char *)cg_name);
if (ret) {
- gf_log("", GF_LOG_ERROR, "Failed to set cg_name");
+ gf_log("", GF_LOG_ERROR,
+ "Failed to set CG name %s", cg_name);
goto out;
}
} else {
@@ -3082,25 +3122,41 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi)
* then fill it to dictionary
*/
if (snap_name != NULL) {
- ret = dict_set_str (dict, "snap_name", snap_name);
+ ret = dict_set_str (dict, "snapname",
+ (char *)snap_name);
if (ret) {
gf_log ("", GF_LOG_ERROR,
- "Failed to set snap_name");
+ "Failed to set snap name %s",
+ snap_name);
+ ret = -1;
goto out;
}
}
- ret = dict_set_int64 (dict, "vol_count", vol_count);
/* fill volume name in dictionary */
for (i = 0; i < vol_count; ++i) {
vol_name = (char*) words[vol_start_index + i];
- snprintf (key, sizeof (key), "vol%d", i);
- ret = dict_set_str (dict, key, vol_name);
+ /* 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) {
gf_log("", GF_LOG_ERROR,
- "Failed to set vol_name");
+ "Failed to set Volume Name %s",
+ vol_name);
goto out;
}
+ actual_vol_count++;
+ }
+ ret = dict_set_int64 (dict, "vol-count", actual_vol_count);
+ if (ret) {
+ gf_log("", GF_LOG_ERROR, "Failed to set Volume Count");
+ ret = -1;
}
}
out:
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 50eeda3..20cad3b 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7522,6 +7522,7 @@ out:
/*Function to list the snap "gluster snapshot list" */
static int
list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
+ int64_t snapcount_total = -1 ;
int64_t snapcount = -1 ;
char buffer[PATH_MAX] = "" ;
char *get_buffer = NULL;
@@ -7541,7 +7542,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
* if volume not present then display that volume doesnot exist
* and try to fetch next volume mentioned
*/
- ret = snprintf (buffer, sizeof(buffer), "%s.vol_name", prefix_str);
+ ret = snprintf (buffer, sizeof(buffer), "%s.volname", prefix_str);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7552,10 +7553,10 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
}
cli_out ("Vol Name : %s", get_buffer);
/* if Volume is present then get the snapcount.
- * string is "snaplist.vol{0..}.snap_count.
+ * string is "snaplist.vol{0..}.snap-count.
*/
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap_count", prefix_str);
+ "%s.snap-count", prefix_str);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7566,28 +7567,38 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
}
/* To check if the user has given "-d" option */
- ret = dict_get_int8 (dict_n, "snap_details", &detail);
+ ret = dict_get_int8 (dict_n, "snap-details", &detail);
if (ret) {
gf_log ("",GF_LOG_ERROR, "could not get snap_details status");
goto out;
}
- cli_out ("Number of Snaps Taken : %ld", snapcount);
+ ret = snprintf (buffer, sizeof (buffer),
+ "%s.snap-count-total", prefix_str);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = dict_get_int64 (dict_n, buffer, &snapcount_total);
+ if (!ret)
+ cli_out ("Total Snap Count : %ld", snapcount_total);
+ else
+ gf_log ("", GF_LOG_ERROR, "Failed to get snapcount total");
+
for (i = 0 ; i < snapcount; i++) {
- /* get snapname "snaplist.vol{0..}.snap{0..}.snap_name" */
+ /* get snapname "snaplist.vol-{0..}.snap-{0..}.snapname" */
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.snap_name", prefix_str,i);
+ "%s.snap-%ld.snapname", 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 Name : %s",get_buffer);
+ cli_out ("\n\tSnap Name : %s",get_buffer);
else
- cli_out ("\tSnap Name : %s","Does not exist");
+ cli_out ("\n\tSnap Name : %s","Does not exist");
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.snap_time", prefix_str, i);
+ "%s.snap-%ld.snap-time", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7598,7 +7609,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
cli_out ("\tSnap Time : %s","Does not exist");
- ret = snprintf (buffer, sizeof(buffer), "%s.snap%ld.snap_id"
+ ret = snprintf (buffer, sizeof(buffer), "%s.snap-%ld.snap-id"
, prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
@@ -7616,7 +7627,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
continue;
}
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.cg_name", prefix_str, i);
+ "%s.snap-%ld.cgname", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7627,7 +7638,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
cli_out("\tCG Name : %s","Does not exist");
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.cg_id", prefix_str, i);
+ "%s.snap-%ld.cg-id", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7638,7 +7649,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
cli_out("\tCG ID : %s","Does not exist");
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.snap_desc", prefix_str, i);
+ "%s.snap-%ld.snap-desc", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7650,7 +7661,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
"Description not present");
ret = snprintf (buffer, sizeof(buffer),
- "%s.snap%ld.snap_status", prefix_str, i);
+ "%s.snap-%ld.snap-status", prefix_str, i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7683,13 +7694,13 @@ list_snap_of_cg (dict_t *dict) {
* or else we can keep that string in some variable
* and use the same variable every where
*/
- ret = dict_get_int8 (dict, "snap_details", &detail);
+ ret = dict_get_int8 (dict, "snap-details", &detail);
if (ret) {
gf_log ("", GF_LOG_ERROR, "could not get snap_details status");
goto out;
}
- ret = dict_get_str (dict, "snaplist.cg0.cg_name", &get_buffer);
+ ret = dict_get_str (dict, "snaplist.cg-0.cgname", &get_buffer);
if (ret) {
/* if cg_name is not present then exit, it is not necessary
* to check other details if cg_name is not present
@@ -7700,14 +7711,15 @@ list_snap_of_cg (dict_t *dict) {
}
cli_out ("CG Name : %s", get_buffer);
- ret = dict_get_str (dict, "snaplist.cg0.cg_id", &get_buffer);
+ ret = dict_get_str (dict, "snaplist.cg-0.cg-id", &get_buffer);
if (!ret)
cli_out ("CG ID : %s",get_buffer);
else
cli_out ("CG ID : %s","Does not exist");
if (detail == 1) {
- ret = dict_get_str (dict, "snaplist.cg0.cg_desc", &get_buffer);
+ ret = dict_get_str (dict,
+ "snaplist.cg-0.cg-desc", &get_buffer);
if (!ret)
cli_out ("CG Description : %s",
get_buffer);
@@ -7715,7 +7727,7 @@ list_snap_of_cg (dict_t *dict) {
cli_out ("CG Description : %s",
"Does not exist");
- ret = dict_get_str (dict, "snaplist.cg0.cg_status",
+ ret = dict_get_str (dict, "snaplist.cg-0.cg-status",
&get_buffer);
if (!ret)
cli_out ("CG Status : %s", get_buffer);
@@ -7725,7 +7737,7 @@ list_snap_of_cg (dict_t *dict) {
}
- ret = dict_get_int64 (dict, "snaplist.cg0.vol_count", &cg_volcount);
+ ret = dict_get_int64 (dict, "snaplist.cg-0.vol-count", &cg_volcount);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Could not fetch cg_volcount");
goto out;
@@ -7733,7 +7745,7 @@ list_snap_of_cg (dict_t *dict) {
/* list the snaps of each volume present in a CG*/
for (i = 0 ; i < cg_volcount ; i++){
ret = snprintf (cg_name_list, sizeof(cg_name_list),
- "snaplist.cg0.vol%ld",i);
+ "snaplist.cg-0.vol%ld",i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7752,20 +7764,20 @@ static int
call_list_snap_of_volume(dict_t *dict){
int ret = -1;
int64_t volcount = -1;
- int i = -1;
+ int64_t i = -1;
char vol_name_prefix[PATH_MAX] = "";
- ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount);
+ ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Could not fetch volcount");
goto out;
}
for (i = 0 ; i < volcount ; i++) {
/* list the snap of each volume
- * vol_name_prefix = "snaplist.vol{0..}"
+ * vol_name_prefix = "snaplist.vol-{0..}"
*/
ret = snprintf (vol_name_prefix, sizeof(vol_name_prefix),
- "snaplist.vol%d", i);
+ "snaplist.vol%ld", i);
if (ret < 0) { /* Negative value is an error */
goto out;
}
@@ -7875,7 +7887,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
/* get the vol_count
* if vol_count = 0, then there must be presence of CG
*/
- ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount);
+ ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount);
if (ret){
gf_log("", GF_LOG_ERROR, "Could not fetch volcount");
ret = -1;
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index f8ce8a6..c946e4d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -472,7 +472,7 @@ glusterd_snapshot_get_snapdetail_lk (dict_t *dict, char *keyprefix,
goto out;
}
- snprintf (key, sizeof (key), "%s.snap-name", keyprefix);
+ snprintf (key, sizeof (key), "%s.snapname", keyprefix);
ret = dict_set_dynstr (dict, key, value);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to set "
@@ -751,7 +751,7 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
}
/* First set the volume name */
- ret = snprintf (key, sizeof (key), "%s.vol-name", keyprefix);
+ ret = snprintf (key, sizeof (key), "%s.volname", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
}
@@ -762,6 +762,16 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
goto out;
}
+ ret = snprintf (key, sizeof (key), "%s.snap-count-total", keyprefix);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = dict_set_int64 (dict, key, volinfo->snap_count);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set total snap count");
+ goto out;
+ }
/* Ownership of value transferred to dict. Therefore we must initalize
* it to NULL */
value = NULL;
@@ -773,7 +783,7 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
list_for_each_entry_safe_reverse (entry, tmp, &volinfo->snaps,
snap_list) {
++index;
- ret = snprintf (key, sizeof (key), "%s.snap%ld", keyprefix, index);
+ ret = snprintf (key, sizeof (key), "%s.snap-%ld", keyprefix, index);
if (ret < 0) { /* Only negative value is error */
goto out;
}
@@ -802,7 +812,7 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
}
/* snap found */
- ret = snprintf (key, sizeof (key), "%s.snap0", keyprefix);
+ ret = snprintf (key, sizeof (key), "%s.snap-0", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
}
@@ -989,7 +999,7 @@ glusterd_snapshot_cg_get_snaplist_lk (dict_t *dict, glusterd_snap_cg_t *cg,
goto out;
}
- ret = snprintf (key, sizeof (key), "%s.cg-name", keyprefix);
+ ret = snprintf (key, sizeof (key), "%s.cgname", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
}
@@ -1245,7 +1255,7 @@ glusterd_snapshot_get_snaplist (dict_t *voldict, dict_t *rspdict,
ret = dict_get_str (voldict, key, &volname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get"
"volname for %s", key);
goto out;
}
@@ -1309,14 +1319,14 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
/* All these options are optonal. Therefore ignore
* error returned by following dictionary operations
*/
- ret = dict_get_str (dict, "snap-name", &snapname);
+ ret = dict_get_str (dict, "snapname", &snapname);
/* Ignore error */
ret = dict_get_int8 (dict, "snap-details", &detail);
ret = dict_get_int64 (dict, "vol-count", &volcount);
if (ret) {
/* Ignore error */
- ret = dict_get_str (dict, "cg-name", &cgname);
+ ret = dict_get_str (dict, "cgname", &cgname);
}
@@ -1339,7 +1349,7 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
*/
/* TODO: Handle multiple CG if needed */
- ret = snprintf (key, sizeof (key), "%s.cg0", keyprefix);
+ ret = snprintf (key, sizeof (key), "%s.cg-0", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
}
@@ -1374,7 +1384,7 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
}
/* Get the volume count */
- ret = dict_get_int32 (voldict, "vol-count", &vol_count);
+ ret = dict_get_int32 (voldict, "vol_count", &vol_count);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to get volume"
" count");