9ae3f9
From 12ed9226fa24d073ab2b89692194b454a194c379 Mon Sep 17 00:00:00 2001
9ae3f9
From: Sanju Rakonde <srakonde@redhat.com>
9ae3f9
Date: Thu, 4 Jun 2020 15:14:29 +0530
9ae3f9
Subject: [PATCH 400/449] cli: throw a warning if replica count greater than 3
9ae3f9
9ae3f9
As volumes with replica count greater than 3 are not
9ae3f9
supported, a warning message is be thrown to user
9ae3f9
while creating the volume with replica count greater
9ae3f9
than 3 or while converting a volume to replica > 3
9ae3f9
volume by add-brick/remove-brick operations.
9ae3f9
9ae3f9
Label: DOWNSTREAM ONLY
9ae3f9
9ae3f9
BUG: 1763129
9ae3f9
Change-Id: I5a32a5a2d99b5175fb692dfcab27396089f24b72
9ae3f9
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
9ae3f9
Reviewed-on: https://code.engineering.redhat.com/gerrit/202338
9ae3f9
Tested-by: RHGS Build Bot <nigelb@redhat.com>
9ae3f9
Reviewed-by: Mohit Agrawal <moagrawa@redhat.com>
9ae3f9
Reviewed-by: Ravishankar Narayanankutty <ravishankar@redhat.com>
9ae3f9
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9ae3f9
---
9ae3f9
 cli/src/cli-cmd-parser.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
9ae3f9
 1 file changed, 45 insertions(+)
9ae3f9
9ae3f9
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
9ae3f9
index ac0a263..5e7ce53 100644
9ae3f9
--- a/cli/src/cli-cmd-parser.c
9ae3f9
+++ b/cli/src/cli-cmd-parser.c
9ae3f9
@@ -619,6 +619,23 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
9ae3f9
                     }
9ae3f9
                 }
9ae3f9
             }
9ae3f9
+
9ae3f9
+            if (replica_count > 3) {
9ae3f9
+                if (strcmp(words[wordcount - 1], "force")) {
9ae3f9
+                    question =
9ae3f9
+                        "Volumes with replica count greater than 3 are"
9ae3f9
+                        "not supported. \nDo you still want to continue?\n";
9ae3f9
+                    answer = cli_cmd_get_confirmation(state, question);
9ae3f9
+                    if (GF_ANSWER_NO == answer) {
9ae3f9
+                        gf_log("cli", GF_LOG_ERROR,
9ae3f9
+                               "Volume create "
9ae3f9
+                               "cancelled, exiting");
9ae3f9
+                        ret = -1;
9ae3f9
+                        goto out;
9ae3f9
+                    }
9ae3f9
+                }
9ae3f9
+            }
9ae3f9
+
9ae3f9
             ret = dict_set_int32(dict, "replica-count", replica_count);
9ae3f9
             if (ret)
9ae3f9
                 goto out;
9ae3f9
@@ -1815,6 +1832,20 @@ cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words,
9ae3f9
                     goto out;
9ae3f9
                 }
9ae3f9
             }
9ae3f9
+        } else if (count > 3) {
9ae3f9
+            if (strcmp(words[wordcount - 1], "force")) {
9ae3f9
+                question =
9ae3f9
+                    "Volumes with replica count greater than 3 are"
9ae3f9
+                    "not supported. \nDo you still want to continue?\n";
9ae3f9
+                answer = cli_cmd_get_confirmation(state, question);
9ae3f9
+                if (GF_ANSWER_NO == answer) {
9ae3f9
+                    gf_log("cli", GF_LOG_ERROR,
9ae3f9
+                           "add-brick "
9ae3f9
+                           "cancelled, exiting");
9ae3f9
+                    ret = -1;
9ae3f9
+                    goto out;
9ae3f9
+                }
9ae3f9
+            }
9ae3f9
         }
9ae3f9
     } else if ((strcmp(w, "stripe")) == 0) {
9ae3f9
         cli_err("stripe option not supported");
9ae3f9
@@ -2082,6 +2113,20 @@ cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words,
9ae3f9
                     goto out;
9ae3f9
                 }
9ae3f9
             }
9ae3f9
+        } else if (count > 3) {
9ae3f9
+            if (strcmp(words[wordcount - 1], "force")) {
9ae3f9
+                ques =
9ae3f9
+                    "Volumes with replica count greater than 3 are"
9ae3f9
+                    "not supported. \nDo you still want to continue?\n";
9ae3f9
+                answer = cli_cmd_get_confirmation(state, ques);
9ae3f9
+                if (GF_ANSWER_NO == answer) {
9ae3f9
+                    gf_log("cli", GF_LOG_ERROR,
9ae3f9
+                           "Remove-brick "
9ae3f9
+                           "cancelled, exiting");
9ae3f9
+                    ret = -1;
9ae3f9
+                    goto out;
9ae3f9
+                }
9ae3f9
+            }
9ae3f9
         }
9ae3f9
 
9ae3f9
         ret = dict_set_int32(dict, "replica-count", count);
9ae3f9
-- 
9ae3f9
1.8.3.1
9ae3f9