summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-parser.c
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-03-06 11:09:58 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-13 02:54:13 -0700
commitb458f7b40b19727258fa3268cc8d1147f630fe26 (patch)
treee5bc4ce287ef23174e137a33aeb1c5eb03ea747f /cli/src/cli-cmd-parser.c
parent7817de70fedaeffbc320ffb629c1ff6c14f81ecd (diff)
feature/snapshot : Snapshot status.
Snapshot status command is used to display the status of available snapshot. The status command will display the Brick path, Volume Group, Brick pid, Whether brick is online, Percentage of data filled, Logical Volume size. The syntax for using snapshot status is : gluster snapshot status [(snapname | volume <volname>)] Change-Id: I621911c305e20ca83d958ff1f8762bef1f2f12f0 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7134 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r--cli/src/cli-cmd-parser.c110
1 files changed, 104 insertions, 6 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 2ad5d430c..c5d6fa009 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3290,6 +3290,85 @@ out :
return ret;
}
+/* snapshot status [(snapname | volume <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 status)
+ *
+ * return value : -1 on failure
+ * 0 on success
+ */
+int
+cli_snap_status_parse (dict_t *dict, const char **words, int wordcount,
+ unsigned int cmdi) {
+
+ int ret = -1;
+ int32_t cmd = GF_SNAP_STATUS_TYPE_ALL;
+
+ GF_ASSERT (words);
+ GF_ASSERT (dict);
+
+ if (wordcount > 4 || wordcount < cmdi) {
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ if (wordcount == cmdi) {
+ ret = 0;
+ goto out;
+ }
+
+ /* if 3rd word is not "volume", then it must be "snapname"
+ */
+ if (strcmp (words[cmdi], "volume") != 0) {
+ ret = dict_set_str (dict, "snapname",
+ (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Count not save "
+ "snap name %s", words[cmdi]);
+ goto out;
+ }
+
+ if ((cmdi + 1) != wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ ret = 0;
+ cmd = GF_SNAP_STATUS_TYPE_SNAP;
+ goto out;
+ }
+
+ /* If 3rd word is "volume", then check if next word is present.
+ * As, "snapshot info volume" is an invalid command
+ */
+ if ((cmdi + 1) == wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ ret = dict_set_str (dict, "volname", (char *)words [wordcount - 1]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Count not save "
+ "volume name %s", words[wordcount - 1]);
+ goto out;
+ }
+ cmd = GF_SNAP_STATUS_TYPE_VOL;
+
+out :
+ if (ret == 0) {
+ ret = dict_set_int32 (dict, "cmd", cmd);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save cmd "
+ "of snapshot status");
+ }
+ }
+ return ret;
+}
+
int32_t
cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
@@ -3326,18 +3405,21 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
goto out;
}
- if (!strcmp (w, "create"))
+ if (!strcmp (w, "create")) {
type = GF_SNAP_OPTION_TYPE_CREATE;
- if (!strcmp (w, "list"))
+ } else if (!strcmp (w, "list")) {
type = GF_SNAP_OPTION_TYPE_LIST;
- if (!strcmp (w, "info"))
+ } else if (!strcmp (w, "info")) {
type = GF_SNAP_OPTION_TYPE_INFO;
- if (!strcmp (w, "delete"))
+ } else if (!strcmp (w, "delete")) {
type = GF_SNAP_OPTION_TYPE_DELETE;
- if (!strcmp (w, "config"))
+ } else if (!strcmp (w, "config")) {
type = GF_SNAP_OPTION_TYPE_CONFIG;
- if (!strcmp (w, "restore"))
+ } else if (!strcmp (w, "restore")) {
type = GF_SNAP_OPTION_TYPE_RESTORE;
+ } else if (!strcmp (w, "status")) {
+ type = GF_SNAP_OPTION_TYPE_STATUS;
+ }
if (type != GF_SNAP_OPTION_TYPE_CONFIG) {
ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true);
@@ -3437,6 +3519,22 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
}
break;
}
+ case GF_SNAP_OPTION_TYPE_STATUS:
+ {
+ /* Syntax :
+ * gluster snapshot status [(snapname |
+ * volume <volname>)]
+ */
+ ret = cli_snap_status_parse (dict, words, wordcount,
+ cmdi);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
+ "snapshot status command");
+ goto out;
+ }
+ break;
+ }
+
case GF_SNAP_OPTION_TYPE_RESTORE:
{
/* Syntax: