From 6e27b9744f89430d4a33b36f96a78d7b048b16ff Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Tue, 28 Apr 2015 19:17:40 +0530 Subject: tiering/cli: Check replica count and bricks are proper or not Back port of http://review.gluster.org/10428 Right now, attach-tier calls parsing function for add-brick. Add-brick does not have any check for brick count and replca count compatibility. >Change-Id: I44ec13eadffc003a9ebf8c4eb0193df559933a68 >BUG: 1215122 >Signed-off-by: Mohammed Rafi KC >Reviewed-on: http://review.gluster.org/10428 >Reviewed-by: Dan Lambright >Tested-by: Gluster Build System >Reviewed-by: Vijay Bellur Change-Id: Ie86d5b61b044386a062bfc9782178853e3af0f11 BUG: 1219850 Signed-off-by: Mohammed Rafi KC Reviewed-on: http://review.gluster.org/10710 Reviewed-by: Dan Lambright Tested-by: Gluster Build System --- cli/src/cli-cmd-volume.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/basic/tier/tier.t | 3 ++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ecd838d52c0..a6df78ff188 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -834,6 +834,53 @@ out: return ret; } +int +cli_tier_validate_replica_type (dict_t *dict, int type) +{ + + int brick_count = -1; + int replica_count = 1; + int ret = -1; + + ret = dict_get_int32 (dict, "count", &brick_count); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to get brick count"); + goto out; + } + + ret = dict_get_int32 (dict, "replica-count", &replica_count); + if (ret) { + gf_log ("cli", GF_LOG_DEBUG, "Failed to get replica count. " + "Defaulting to one"); + replica_count = 1; + } + + /* + * Change the calculation of sub_count once attach-tier support + * disperse volume. + * sub_count = disperse_count for disperse volume + * */ + + + if (brick_count % replica_count) { + if (type == GF_CLUSTER_TYPE_REPLICATE) + cli_err ("number of bricks is not a multiple of " + "replica count"); + else if (type == GF_CLUSTER_TYPE_DISPERSE) + cli_err ("number of bricks is not a multiple of " + "disperse count"); + else + cli_err ("number of bricks given doesn't match " + "required count"); + + ret = -1; + goto out; + } + ret = 0; +out: + return ret; +} + int cli_cmd_volume_attach_tier_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, @@ -869,6 +916,16 @@ cli_cmd_volume_attach_tier_cbk (struct cli_state *state, goto out; } + /* + * Merge this check when attach-tier has it's own cli parse function. + */ + ret = cli_tier_validate_replica_type (options, type); + if (ret) { + cli_usage_out (word->pattern); + parse_error = 1; + goto out; + } + if (state->mode & GLUSTER_MODE_WIGNORE) { ret = dict_set_int32 (options, "force", _gf_true); if (ret) { diff --git a/tests/basic/tier/tier.t b/tests/basic/tier/tier.t index 81abc5779ab..8e72071af1a 100755 --- a/tests/basic/tier/tier.t +++ b/tests/basic/tier/tier.t @@ -59,11 +59,12 @@ PROMOTE_TIMEOUT=5 MIGRATION_TIMEOUT=10 cleanup - TEST glusterd TEST pidof glusterd TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0..$LAST_BRICK} +# testing bug 1215122, ie should fail if replica count and bricks are not compatible. +TEST ! $CLI volume attach-tier $V0 replica 5 $H0:$B0/${V0}$CACHE_BRICK_FIRST $H0:$B0/${V0}$CACHE_BRICK_LAST TEST $CLI volume attach-tier $V0 replica 2 $H0:$B0/${V0}$CACHE_BRICK_FIRST $H0:$B0/${V0}$CACHE_BRICK_LAST TEST $CLI volume start $V0 TEST $CLI volume set $V0 features.ctr-enabled on -- cgit