summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-09-01 23:44:54 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-02 03:12:25 -0700
commit4c5e364c36baa92374eb0eac60dafb8da3786286 (patch)
tree6712d972370fc7c8b375628cc8b37defb0be4730 /cli
parent1d6e57d4a8bf4d69f724774d019f3cb7b4c0e1c3 (diff)
Remove brick validation
Added checks for duplicate bricks in cli arguments, valid bricks for the volume, valid volume name, and prevent removing of incorrect pairs for replica. Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1486 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1486
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c43
-rw-r--r--cli/src/cli3_1-cops.c2
2 files changed, 44 insertions, 1 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 48c4a4fd9ef..f43349416be 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -439,6 +439,10 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
int count = 0;
char key[50];
int brick_count = 0, brick_index = 0;
+ int32_t tmp_index = 0;
+ int32_t j = 0;
+ char *tmp_brick = NULL;
+ char *tmp_brick1 = NULL;
GF_ASSERT (words);
GF_ASSERT (options);
@@ -495,6 +499,25 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
if (ret)
goto out;
+ tmp_index = brick_index;
+ tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char);
+
+ if (!tmp_brick) {
+ gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
+ "Unable to get memory");
+ ret = -1;
+ goto out;
+ }
+
+ tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char);
+
+ if (!tmp_brick1) {
+ gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
+ "Unable to get memory");
+ ret = -1;
+ goto out;
+ }
+
while (brick_index < wordcount) {
delimiter = strchr(words[brick_index], ':');
if (!delimiter || delimiter == words[brick_index]
@@ -504,7 +527,20 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
ret = -1;
goto out;
}
-
+ j = tmp_index;
+ strcpy(tmp_brick, words[brick_index]);
+ while ( j < brick_index) {
+ strcpy(tmp_brick1, words[j]);
+ if (!(strcmp (tmp_brick, tmp_brick1))) {
+ gf_log("",GF_LOG_ERROR, "Duplicate bricks"
+ " found %s", words[brick_index]);
+ cli_out("Duplicate bricks found %s",
+ words[brick_index]);
+ ret = -1;
+ goto out;
+ }
+ j++;
+ }
snprintf (key, 50, "brick%d", ++brick_count);
ret = dict_set_str (dict, key, (char *)words[brick_index++]);
@@ -526,6 +562,11 @@ out:
dict_destroy (dict);
}
+ if (tmp_brick)
+ GF_FREE (tmp_brick);
+ if (tmp_brick1)
+ GF_FREE (tmp_brick1);
+
return ret;
}
diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 6971a242d91..e4b41c4db3a 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -704,6 +704,8 @@ gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,
gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick");
cli_out ("Remove Brick %s", (rsp.op_ret) ? "unsuccessful":
"successful");
+ if (rsp.op_ret && rsp.op_errstr)
+ cli_out ("%s", rsp.op_errstr);
ret = rsp.op_ret;