summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-02-20 13:46:58 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-05 02:03:20 -0800
commitae62c3aec7b92dc5325a04add9ab0ac63ff05fa5 (patch)
tree811c34afa69f3910abc9f72f568dd3f60e00d927
parentcffe1de37453f81992047408e4c4ce5e35e21434 (diff)
cli/snapshot : snapshot list CLI
syntax: gluster snapshot list [volname] This will list all the snapshots (or) snapshots of a particular volume. Change-Id: If879e06fe13caf2236f48df345857f833ae83c5b Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7143 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c54
-rw-r--r--cli/src/cli-cmd-snapshot.c6
-rw-r--r--cli/src/cli-rpc-ops.c48
3 files changed, 104 insertions, 4 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 2505bbc..6b8f292 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2956,6 +2956,44 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
out :
return ret;
}
+
+/* snapshot list [volname]
+ * @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 list)
+ *
+ * return value : -1 on failure
+ * 0 on success
+ */
+int
+cli_snap_list_parse (dict_t *dict, const char **words, int wordcount,
+ unsigned int cmdi) {
+ int ret = -1;
+
+ GF_ASSERT (words);
+ GF_ASSERT (dict);
+
+ if (wordcount < cmdi || wordcount > 3) {
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ if (wordcount == 2) {
+ ret = 0;
+ goto out;
+ }
+
+ ret = dict_set_str (dict, "volname", (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Failed to save volname in dictionary");
+ goto out;
+ }
+out :
+ return ret;
+}
+
/* snapshot info [(snapname | volume <volname>)]
* @arg-0, dict : Request Dictionary to be sent to server side.
* @arg-1, words : Contains individual words of CLI command.
@@ -3458,6 +3496,22 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
cmdi);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
+ "snapshot info command");
+ goto out;
+ }
+ break;
+ }
+
+ case GF_SNAP_OPTION_TYPE_LIST:
+ {
+ /* Syntax :
+ * gluster snaphsot list [volname]
+ */
+
+ ret = cli_snap_list_parse (dict, words, wordcount,
+ cmdi);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
"snapshot list command");
goto out;
}
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index b5b4388..4d824a0 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 <snapname> <volnames> [description <description>] [force]",
+ { "snapshot create <snapname> <volname(s)> [description <description>] [force]",
cli_cmd_snapshot_cbk,
"Snapshot Create."
},
@@ -93,6 +93,10 @@ struct cli_cmd snapshot_cmds[] = {
},
{ "snapshot info [(snap-name | volume <volname>)]",
cli_cmd_snapshot_cbk,
+ "Snapshot Info."
+ },
+ { "snapshot list [volname]",
+ cli_cmd_snapshot_cbk,
"Snapshot List."
},
{"snapshot config < volname | all > [ snap-max-hard-limit <count> | snap-max-soft-limit <percent> ]",
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 340752a..b441e10 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7985,6 +7985,41 @@ cli_get_snaps_in_volume (dict_t *dict) {
out :
return ret;
}
+
+int
+cli_snapshot_list (dict_t *dict) {
+ int snapcount = 0;
+ char key[PATH_MAX] = "";
+ int ret = -1;
+ int i = 0;
+ char *get_buffer = NULL;
+
+ GF_ASSERT (dict);
+
+ ret = dict_get_int32 (dict, "snap-count", &snapcount);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not fetch snap count");
+ goto out;
+ }
+
+ for (i = 1 ; i <= snapcount ; i++) {
+ ret = snprintf (key, sizeof (key), "snapname%d",i);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = dict_get_str (dict, key, &get_buffer);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not get %s ", key);
+ goto out;
+ } else {
+ cli_out ("%s", get_buffer);
+ }
+ }
+out :
+ return ret;
+}
+
int
gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@@ -8125,9 +8160,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
}
- break;
-
-
+ break;
case GF_SNAP_OPTION_TYPE_CONFIG:
ret = cli_snapshot_config_display (dict, &rsp);
@@ -8138,6 +8171,15 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
}
break;
+ case GF_SNAP_OPTION_TYPE_LIST:
+ ret = cli_snapshot_list (dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Failed to display snapshot"
+ " list");
+ goto out;
+ }
+ break;
+
case GF_SNAP_OPTION_TYPE_DELETE:
ret = cli_snapshot_remove_reply (&rsp, dict, frame);
break;