From e8669dc707ffd60fea34c4b8b04f545a9169d5ee Mon Sep 17 00:00:00 2001 From: Atin Mukherjee Date: Mon, 9 Jan 2017 10:56:13 +0530 Subject: glusterd: bypass add-brick validation with force Commit c916a2f added a validation to restrict add-brick operation if a replica configuration is changed and any of the bricks belonging to the volume is down. However we should bypass this validation with a force option if users really want to have add-brick to go through at the sake of the corner cases of data loss issue. The original problem of add-brick getting failed when layout is not set will still be a problem with a force option as the issue has to be taken care in the DHT layer. Change-Id: I0ed3df91ea712f77674eb8afc6fdfa577f25a7bb BUG: 1406411 Signed-off-by: Atin Mukherjee Reviewed-on: http://review.gluster.org/16358 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Ravishankar N CentOS-regression: Gluster Build System --- .../glusterd/bug-1406411-fail-add-brick-on-replica-count-change.t | 4 ++-- tests/include.rc | 1 + xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/bugs/glusterd/bug-1406411-fail-add-brick-on-replica-count-change.t b/tests/bugs/glusterd/bug-1406411-fail-add-brick-on-replica-count-change.t index bbd2d4cc948..a9dd2b7a811 100644 --- a/tests/bugs/glusterd/bug-1406411-fail-add-brick-on-replica-count-change.t +++ b/tests/bugs/glusterd/bug-1406411-fail-add-brick-on-replica-count-change.t @@ -16,7 +16,7 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2 TEST kill_brick $V0 $H0 $B0/${V0}1 #add-brick should fail -TEST ! $CLI volume add-brick $V0 replica 3 $H0:$B0/${V0}3 +TEST ! $CLI_NO_FORCE volume add-brick $V0 replica 3 $H0:$B0/${V0}3 TEST $CLI volume start $V0 force EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1 @@ -31,7 +31,7 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V1 $H0 $B0/${V1}2 TEST kill_brick $V1 $H0 $B0/${V1}1 #add-brick should fail -TEST ! $CLI volume add-brick $V1 replica 2 $H0:$B0/${V1}{3,4} +TEST ! $CLI_NO_FORCE volume add-brick $V1 replica 2 $H0:$B0/${V1}{3,4} TEST $CLI volume start $V1 force EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V1 $H0 $B0/${V1}1 diff --git a/tests/include.rc b/tests/include.rc index e713bcd1590..b83972a111b 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -90,6 +90,7 @@ LOGDIR=$(gluster --print-logdir) statedumpdir=`gluster --print-statedumpdir`; # Default directory for statedump CLI="gluster --mode=script --wignore"; +CLI_NO_FORCE="gluster --mode-script"; GFS="glusterfs --attribute-timeout=0 --entry-timeout=0"; mkdir -p $WORKDIRS diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 08a878388a3..938663ba863 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -1724,7 +1724,9 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } } - if (volinfo->replica_count < replica_count) { + is_force = dict_get_str_boolean (dict, "force", _gf_false); + + if (volinfo->replica_count < replica_count && !is_force) { cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { if (gf_uuid_compare (brickinfo->uuid, MY_UUID)) @@ -1812,8 +1814,6 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - is_force = dict_get_str_boolean (dict, "force", _gf_false); - if (bricks) { brick_list = gf_strdup (bricks); all_bricks = gf_strdup (bricks); -- cgit