diff options
author | Raghavendra Bhat <raghavendrabhat@gluster.com> | 2010-11-08 06:40:21 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-11-09 02:12:07 -0800 |
commit | 8205e939178ba2253117869024a306442b30d3d1 (patch) | |
tree | d19d66d2b8663ea69d921ee4a6a2c2b6ac776a4a /xlators/mgmt | |
parent | e3808ac86f8ff5baebea59e610a791cef5f5f2c9 (diff) |
check if the brick being added is the destination brick of replace brick
Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 2033 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2033
Diffstat (limited to 'xlators/mgmt')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 79 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 41 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 3 |
4 files changed, 124 insertions, 2 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index b20f6bd6eba..62dd7fa90cc 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -680,6 +680,8 @@ glusterd_op_stage_add_brick (gd1_mgmt_stage_op_req *req, char **op_errstr) glusterd_conf_t *priv = NULL; char msg[2048] = {0,}; gf_boolean_t brick_alloc = _gf_false; + char *all_bricks = NULL; + char *str_ret = NULL; GF_ASSERT (req); @@ -733,12 +735,26 @@ glusterd_op_stage_add_brick (gd1_mgmt_stage_op_req *req, char **op_errstr) if (bricks) { brick_list = gf_strdup (bricks); + all_bricks = gf_strdup (bricks); free_ptr = brick_list; } + /* Check whether any of the bricks given is the destination brick of the + replace brick running */ + + str_ret = glusterd_check_brick_rb_part (all_bricks, count, volinfo); + if (str_ret) { + gf_log ("glusterd", GF_LOG_ERROR, + "%s", str_ret); + *op_errstr = gf_strdup (str_ret); + ret = -1; + goto out; + } + if (count) brick = strtok_r (brick_list+1, " \n", &saveptr); + while ( i < count) { ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, &brickinfo); @@ -756,6 +772,7 @@ glusterd_op_stage_add_brick (gd1_mgmt_stage_op_req *req, char **op_errstr) } brick_alloc = _gf_true; } + snprintf (cmd_str, 1024, "%s", brickinfo->path); ret = glusterd_resolve_brick (brickinfo); if (ret) { @@ -786,12 +803,74 @@ out: GF_FREE (free_ptr); if (brick_alloc && brickinfo) glusterd_brickinfo_delete (brickinfo); + if (str_ret) + GF_FREE (str_ret); + if (all_bricks) + GF_FREE (all_bricks); gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; } +char * +glusterd_check_brick_rb_part (char *bricks, int count, glusterd_volinfo_t *volinfo) +{ + char *saveptr = NULL; + char *brick = NULL; + char *brick_list = NULL; + int ret = 0; + glusterd_brickinfo_t *brickinfo = NULL; + uint32_t i = 0; + char *str = NULL; + char msg[2048] = {0,}; + + brick_list = gf_strdup (bricks); + if (!brick_list) { + gf_log ("glusterd", GF_LOG_ERROR, + "Out of memory"); + ret = -1; + goto out; + } + + if (count) + brick = strtok_r (brick_list+1, " \n", &saveptr); + + + while ( i < count) { + ret = glusterd_brickinfo_from_brick (brick, &brickinfo); + if (ret) { + snprintf (msg, sizeof(msg), "Unable to" + " get brickinfo"); + gf_log ("", GF_LOG_ERROR, "%s", msg); + ret = -1; + goto out; + } + + if (glusterd_is_replace_running (volinfo, brickinfo)) { + snprintf (msg, sizeof(msg), "Volume %s: replace brick is running" + " and the brick %s:%s you are trying to add is the destination brick" + " for replace brick", volinfo->volname, brickinfo->hostname, brickinfo->path); + ret = -1; + goto out; + } + + glusterd_brickinfo_delete (brickinfo); + brickinfo = NULL; + brick = strtok_r (NULL, " \n", &saveptr); + i++; + } + +out: + if (brick_list) + GF_FREE(brick_list); + if (brickinfo) + glusterd_brickinfo_delete (brickinfo); + if (ret) + str = gf_strdup (msg); + return str; +} + static int glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req, char **op_errstr, dict_t *rsp_dict) diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 27314781b2b..f8f624c22a0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -224,6 +224,9 @@ glusterd_check_option_exists(char *optstring, char **completion); int set_xlator_option (dict_t *dict, char *key, char *value); +char * +glusterd_check_brick_rb_part (char *bricks, int count, glusterd_volinfo_t *volinfo); + void glusterd_do_replace_brick (void *data); int diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index d5209f48d72..b6328663029 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -2244,6 +2244,43 @@ glusterd_is_defrag_on (glusterd_volinfo_t *volinfo) } int +glusterd_is_replace_running (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo) +{ + int ret = 0; + char *src_hostname = NULL; + char *brick_hostname = NULL; + + if (volinfo->src_brick) { + src_hostname = gf_strdup (volinfo->src_brick->hostname); + if (!src_hostname) { + ret = -1; + goto out; + } + } else { + gf_log ("glusterd", GF_LOG_DEBUG, + "replace brick is not running"); + goto out; + } + + brick_hostname = gf_strdup (brickinfo->hostname); + if (!brick_hostname) { + ret = -1; + goto out; + } + if (!glusterd_is_local_addr (src_hostname) && !glusterd_is_local_addr (brick_hostname)) { + if (glusterd_is_rb_started (volinfo) || glusterd_is_rb_paused (volinfo)) + ret = -1; + } + +out: + if (src_hostname) + GF_FREE (src_hostname); + if (brick_hostname) + GF_FREE (brick_hostname); + return ret; +} + +int glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo, char *op_errstr, size_t len) { @@ -2314,7 +2351,7 @@ out: return ret; } -inline int +int glusterd_is_rb_started(glusterd_volinfo_t *volinfo) { gf_log ("", GF_LOG_DEBUG, @@ -2323,7 +2360,7 @@ glusterd_is_rb_started(glusterd_volinfo_t *volinfo) } -inline int +int glusterd_is_rb_paused ( glusterd_volinfo_t *volinfo) { gf_log ("", GF_LOG_DEBUG, diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 8d4fac48942..79b2454c085 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -225,6 +225,9 @@ int glusterd_set_rb_status (glusterd_volinfo_t *volinfo, gf_rb_status_t status); int +glusterd_is_replace_running (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo); + +int glusterd_rb_check_bricks (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *src_brick, glusterd_brickinfo_t *dst_brick); int |