summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-parser.c
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-06-23 09:35:52 +0530
committerVijay Bellur <vbellur@redhat.com>2014-09-23 02:01:04 -0700
commitc5aa277ec26cd7cf4109bc8854af50a254edbbd9 (patch)
treeecb9237e41389075052c5c36ca2f2c958e1092c8 /cli/src/cli-cmd-parser.c
parentcde7cf45c49a59a688788abc0358c482e30f4018 (diff)
feature/snapshot : Interface to delete all snapshots belonging to a system as-well-as to a particular volume
Problem : With the current design we can only delete a single snapshot. And the deletion of volume which contains snapshot is not allowed. Because of that user might be forced to delete all the snapshots manually before he is allowed to delete a volume. Solution: Following is the interface with which user can delete all the snapshots of a system or belonging to a particular volume. Syntax : gluster snapshot delete all *To delete all the snapshots present in a system Syntax : gluster snapshot delete volume <volname> *To deletes all the snapshot present in a volume specified. ======================================================================== Sample Output: Case 1 : Deleting a single snapshot. [root@snapshot-24 glusterfs]# gluster snapshot delete snap1 Deleting snap will erase all the information about the snap. Do you still want to continue? (y/n) y snapshot delete: snap1: snap removed successfully ----------------------------------------------------------------- Case 2 : Deleting all the snapshots in a Volume. [root@snapshot-24 glusterfs]# gluster snapshot delete volume vol1 Volume (vol1) contains 9 snapshot(s). Do you still want to continue and delete them? (y/n) y snapshot delete: snap2: snap removed successfully snapshot delete: snap3: snap removed successfully snapshot delete: snap4: snap removed successfully snapshot delete: snap5: snap removed successfully . . . ----------------------------------------------------------------- Case 3 : Deleting all the snapshots in a system. [root@snapshot-24 glusterfs]# gluster snapshot delete all System contains 4 snapshot(s). Do you still want to continue and delete them? (y/n) y snapshot delete: snap7: snap removed successfully snapshot delete: snap8: snap removed successfully snapshot delete: snap9: snap removed successfully snapshot delete: snap10: snap removed successfully ======================================================================== Change-Id: Ifec8e128ab2011cbbba208376b9c92cfbe7d8d71 BUG: 1145083 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/8162 Reviewed-by: Atin Mukherjee <amukherj@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Avra Sengupta <asengupt@redhat.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com> Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/8798 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r--cli/src/cli-cmd-parser.c73
1 files changed, 55 insertions, 18 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index b4dc3fe49bd..4811293dbb8 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3422,7 +3422,7 @@ cli_snap_info_parse (dict_t *dict, const char **words, int wordcount)
GF_ASSERT (dict);
if (wordcount > 4 || wordcount < cmdi) {
- gf_log ("", GF_LOG_ERROR, "Invalid syntax");
+ gf_log ("cli", GF_LOG_ERROR, "Invalid syntax");
goto out;
}
@@ -3473,7 +3473,7 @@ cli_snap_info_parse (dict_t *dict, const char **words, int wordcount)
ret = dict_set_str (dict, "volname", (char *)words[wordcount - 1]);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Count not save "
+ gf_log ("cli", GF_LOG_ERROR, "Could not save "
"volume name %s", words[wordcount - 1]);
goto out;
}
@@ -3634,34 +3634,71 @@ cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount,
int ret = -1;
const char *question = NULL;
+ int32_t cmd = -1;
+ unsigned int cmdi = 2;
gf_answer_t answer = GF_ANSWER_NO;
- question = "Deleting snap will erase all the information about "
- "the snap. Do you still want to continue?";
-
GF_ASSERT (words);
GF_ASSERT (dict);
- if (wordcount != 3) {
+ if (wordcount > 4 || wordcount <= cmdi) {
gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
goto out;
}
- ret = dict_set_str (dict, "snapname", (char *)words[2]);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Unable to save snapname %s",
- words[2]);
- goto out;
+ question = "Deleting snap will erase all the information about "
+ "the snap. Do you still want to continue?";
+
+ if (strcmp (words [cmdi], "all") == 0) {
+ ret = 0;
+ cmd = GF_SNAP_DELETE_TYPE_ALL;
+ } else if (strcmp (words [cmdi], "volume") == 0) {
+ if (++cmdi == wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ ret = dict_set_str (dict, "volname",
+ (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save "
+ "volume name %s", words[wordcount - 1]);
+ goto out;
+ }
+ cmd = GF_SNAP_DELETE_TYPE_VOL;
+ } else {
+ ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Unable to save "
+ "snapname %s", words[2]);
+ goto out;
+ }
+ cmd = GF_SNAP_DELETE_TYPE_SNAP;
}
- answer = cli_cmd_get_confirmation (state, question);
- if (GF_ANSWER_NO == answer) {
- ret = 1;
- gf_log ("cli", GF_LOG_DEBUG, "User cancelled "
- "snapshot delete operation for snap %s",
- (char *)words[2]);
+ if ((cmdi + 1) != wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
goto out;
}
+
+ if (cmd == GF_SNAP_DELETE_TYPE_SNAP) {
+ answer = cli_cmd_get_confirmation (state, question);
+ if (GF_ANSWER_NO == answer) {
+ ret = 1;
+ gf_log ("cli", GF_LOG_DEBUG, "User cancelled "
+ "snapshot delete operation for snap %s",
+ (char *)words[2]);
+ goto out;
+ }
+ }
+
+ ret = dict_set_int32 (dict, "delete-cmd", cmd);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save "
+ "type of snapshot delete");
+ }
out:
return ret;
}
@@ -4000,7 +4037,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
"activate", "deactivate", "list",
"status", "config", "info", NULL};
char *invalid_snapnames[] = {"description", "force",
- "volume", NULL};
+ "volume", "all", NULL};
GF_ASSERT (words);
GF_ASSERT (options);