diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-op-sm.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 243 |
1 files changed, 148 insertions, 95 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 3d193c7c043..679a6c90f57 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -1542,7 +1542,6 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr) char msg[2048] = {0,}; char *volname = NULL; char *brick = NULL; - char *shd_key = NULL; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; glusterd_brickinfo_t *brickinfo = NULL; @@ -1623,10 +1622,7 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr) } } else if ((cmd & GF_CLI_STATUS_SHD) != 0) { if (glusterd_is_shd_compatible_volume (volinfo)) { - shd_key = volgen_get_shd_key (volinfo); - shd_enabled = dict_get_str_boolean (vol_opts, - shd_key, - _gf_true); + shd_enabled = is_self_heal_enabled (volinfo, vol_opts); } else { ret = -1; snprintf (msg, sizeof (msg), @@ -3081,7 +3077,6 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr, uint32_t cmd = 0; char *volname = NULL; char *brick = NULL; - char *shd_key = NULL; xlator_t *this = NULL; glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; @@ -3254,12 +3249,9 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr, other_count++; node_count++; } - if (glusterd_is_shd_compatible_volume (volinfo)) { - shd_key = volgen_get_shd_key (volinfo); - shd_enabled = dict_get_str_boolean (vol_opts, - shd_key, - _gf_true); - } + + if (glusterd_is_shd_compatible_volume (volinfo)) + shd_enabled = is_self_heal_enabled (volinfo, vol_opts); if (shd_enabled) { ret = glusterd_add_node_to_dict (priv->shd_svc.name, rsp_dict, @@ -6057,13 +6049,13 @@ out: int _select_hxlator_with_matching_brick (xlator_t *this, - glusterd_volinfo_t *volinfo, dict_t *dict) + glusterd_volinfo_t *volinfo, dict_t *dict, + int *index) { char *hostname = NULL; char *path = NULL; glusterd_brickinfo_t *brickinfo = NULL; glusterd_conf_t *priv = NULL; - int index = 1; int hxl_children = 0; priv = this->private; @@ -6073,6 +6065,8 @@ _select_hxlator_with_matching_brick (xlator_t *this, return -1; hxl_children = _get_hxl_children_count (volinfo); + if ((*index) == 0) + (*index)++; cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { if (gf_uuid_is_null (brickinfo->uuid)) @@ -6080,22 +6074,21 @@ _select_hxlator_with_matching_brick (xlator_t *this, if (!gf_uuid_compare (MY_UUID, brickinfo->uuid)) { _add_hxlator_to_dict (dict, volinfo, - (index - 1)/hxl_children, 0); + ((*index) - 1)/hxl_children, 0); return 1; } - index++; + (*index)++; } return 0; } -int +void _select_hxlators_with_local_bricks (xlator_t *this, glusterd_volinfo_t *volinfo, - dict_t *dict) + dict_t *dict, int *index, + int *hxlator_count) { glusterd_brickinfo_t *brickinfo = NULL; glusterd_conf_t *priv = NULL; - int index = 1; - int hxlator_count = 0; int hxl_children = 0; gf_boolean_t add = _gf_false; int cmd_replica_index = -1; @@ -6103,6 +6096,9 @@ _select_hxlators_with_local_bricks (xlator_t *this, glusterd_volinfo_t *volinfo, priv = this->private; hxl_children = _get_hxl_children_count (volinfo); + if ((*index) == 0) + (*index)++; + cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { if (gf_uuid_is_null (brickinfo->uuid)) (void)glusterd_resolve_brick (brickinfo); @@ -6110,35 +6106,35 @@ _select_hxlators_with_local_bricks (xlator_t *this, glusterd_volinfo_t *volinfo, if (!gf_uuid_compare (MY_UUID, brickinfo->uuid)) add = _gf_true; - if (index % hxl_children == 0) { + if ((*index) % hxl_children == 0) { if (add) { - _add_hxlator_to_dict (dict, volinfo, - (index - 1)/hxl_children, - hxlator_count); - hxlator_count++; + _add_hxlator_to_dict (dict, volinfo, + ((*index) - 1)/hxl_children, + (*hxlator_count)); + (*hxlator_count)++; } add = _gf_false; } - index++; + (*index)++; } - return hxlator_count; } int _select_hxlators_for_full_self_heal (xlator_t *this, glusterd_volinfo_t *volinfo, - dict_t *dict) + dict_t *dict, int *index, + int *hxlator_count) { glusterd_brickinfo_t *brickinfo = NULL; glusterd_conf_t *priv = NULL; - int index = 1; - int hxlator_count = 0; int hxl_children = 0; uuid_t candidate = {0}; priv = this->private; + if ((*index) == 0) + (*index)++; if (volinfo->type == GF_CLUSTER_TYPE_DISPERSE) { hxl_children = volinfo->disperse_count; } else { @@ -6152,19 +6148,19 @@ _select_hxlators_for_full_self_heal (xlator_t *this, if (gf_uuid_compare (brickinfo->uuid, candidate) > 0) gf_uuid_copy (candidate, brickinfo->uuid); - if (index % hxl_children == 0) { + if ((*index) % hxl_children == 0) { if (!gf_uuid_compare (MY_UUID, candidate)) { _add_hxlator_to_dict (dict, volinfo, - (index-1)/hxl_children, - hxlator_count); - hxlator_count++; + ((*index)-1)/hxl_children, + (*hxlator_count)); + (*hxlator_count)++; } gf_uuid_clear (candidate); } - index++; + (*index)++; } - return hxlator_count; + return *hxlator_count; } @@ -6225,13 +6221,13 @@ out: static int fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, - cli_cmd_type type, dict_t *req_dict) + cli_cmd_type type, int *index, + dict_t *req_dict) { glusterd_brickinfo_t *brickinfo = NULL; char msg[1024] = {0,}; char key[1024] = {0,}; char value[1024] = {0,}; - int index = 0; int ret = 0; xlator_t *this = NULL; int cmd_replica_index = -1; @@ -6257,18 +6253,18 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, (void)glusterd_resolve_brick (brickinfo); if (gf_uuid_compare (MY_UUID, brickinfo->uuid)) { - index++; + (*index)++; continue; } if (type == PER_HEAL_XL) { - if (cmd_replica_index != (index/volinfo->replica_count)) { - index++; + if (cmd_replica_index != ((*index)/volinfo->replica_count)) { + (*index)++; continue; - } + } } - snprintf (key, sizeof (key), "%d-status",index); + snprintf (key, sizeof (key), "%d-status", (*index)); snprintf (value, sizeof (value), "%s %s",msg, uuid_utoa(MY_UUID)); ret = dict_set_dynstr (dict, key, gf_strdup(value)); @@ -6278,7 +6274,7 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, "set the dictionary for shd status msg"); goto out; } - snprintf (key, sizeof (key), "%d-shd-status",index); + snprintf (key, sizeof (key), "%d-shd-status", (*index)); ret = dict_set_str (dict, key, "off"); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -6287,58 +6283,29 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, goto out; } - index++; + (*index)++; } out: return ret; } - -static int -glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, - struct cds_list_head *selected, - dict_t *rsp_dict) +int +glusterd_shd_select_brick_xlator (dict_t *dict, gf_xl_afr_op_t heal_op, + glusterd_volinfo_t *volinfo, int *index, + int *hxlator_count, dict_t *rsp_dict) { int ret = -1; - char *volname = NULL; glusterd_conf_t *priv = NULL; - glusterd_volinfo_t *volinfo = NULL; xlator_t *this = NULL; char msg[2048] = {0,}; glusterd_pending_node_t *pending_node = NULL; - gf_xl_afr_op_t heal_op = GF_SHD_OP_INVALID; - int hxlator_count = 0; this = THIS; GF_ASSERT (this); priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "volname", &volname); - if (ret) { - gf_msg ("glusterd", GF_LOG_ERROR, 0, - GD_MSG_DICT_GET_FAILED, "volume name get failed"); - goto out; - } - - ret = glusterd_volinfo_find (volname, &volinfo); - if (ret) { - snprintf (msg, sizeof (msg), "Volume %s does not exist", - volname); - - *op_errstr = gf_strdup (msg); - gf_msg ("glusterd", GF_LOG_ERROR, 0, - GD_MSG_VOL_NOT_FOUND, "%s", msg); - goto out; - } - - ret = dict_get_int32 (dict, "heal-op", (int32_t*)&heal_op); - if (ret || (heal_op == GF_SHD_OP_INVALID)) { - gf_msg ("glusterd", GF_LOG_ERROR, 0, - GD_MSG_DICT_GET_FAILED, "heal op invalid"); - goto out; - } switch (heal_op) { case GF_SHD_OP_INDEX_SUMMARY: @@ -6354,6 +6321,7 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, ret = fill_shd_status_for_local_bricks (rsp_dict, volinfo, ALL_HEAL_XL, + index, dict); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, @@ -6375,6 +6343,7 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, ret = fill_shd_status_for_local_bricks (rsp_dict, volinfo, PER_HEAL_XL, + index, dict); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, @@ -6393,35 +6362,104 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, switch (heal_op) { case GF_SHD_OP_HEAL_FULL: - hxlator_count = _select_hxlators_for_full_self_heal (this, - volinfo, - dict); + _select_hxlators_for_full_self_heal (this, volinfo, dict, + index, hxlator_count); break; case GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA: - hxlator_count = _select_hxlator_with_matching_brick (this, - volinfo, - dict); + (*hxlator_count) += _select_hxlator_with_matching_brick (this, + volinfo, + dict, + index); break; default: - hxlator_count = _select_hxlators_with_local_bricks (this, - volinfo, - dict); + _select_hxlators_with_local_bricks (this, volinfo, dict, + index, hxlator_count); break; } + ret = (*hxlator_count); +out: + return ret; +} - if (!hxlator_count) + +static int +glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, + struct cds_list_head *selected, + dict_t *rsp_dict) +{ + int ret = -1; + char *volname = NULL; + glusterd_conf_t *priv = NULL; + glusterd_volinfo_t *volinfo = NULL; + glusterd_volinfo_t *dup_volinfo = NULL; + xlator_t *this = NULL; + char msg[2048] = {0,}; + glusterd_pending_node_t *pending_node = NULL; + gf_xl_afr_op_t heal_op = GF_SHD_OP_INVALID; + int hxlator_count = 0; + int index = 0; + + this = THIS; + GF_ASSERT (this); + priv = this->private; + GF_ASSERT (priv); + + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_msg ("glusterd", GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "volume name get failed"); goto out; - if (hxlator_count == -1) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_XLATOR_COUNT_GET_FAIL, "Could not determine the" - "translator count"); - ret = -1; + } + + ret = glusterd_volinfo_find (volname, &volinfo); + if (ret) { + snprintf (msg, sizeof (msg), "Volume %s does not exist", + volname); + + *op_errstr = gf_strdup (msg); + gf_msg ("glusterd", GF_LOG_ERROR, 0, + GD_MSG_VOL_NOT_FOUND, "%s", msg); goto out; } - ret = dict_set_int32 (dict, "count", hxlator_count); - if (ret) + ret = dict_get_int32 (dict, "heal-op", (int32_t *)&heal_op); + if (ret || (heal_op == GF_SHD_OP_INVALID)) { + gf_msg ("glusterd", GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "heal op invalid"); goto out; + } + if (volinfo->type == GF_CLUSTER_TYPE_TIER) { + ret = glusterd_create_sub_tier_volinfo (volinfo, &dup_volinfo, + _gf_false, volname); + if (ret < 0) + goto out; + + ret = glusterd_shd_select_brick_xlator (dict, heal_op, + dup_volinfo, + &index, &hxlator_count, + rsp_dict); + glusterd_volinfo_delete (dup_volinfo); + if (ret < 0) + goto out; + ret = glusterd_create_sub_tier_volinfo (volinfo, &dup_volinfo, + _gf_true, volname); + if (ret < 0) + goto out; + ret = glusterd_shd_select_brick_xlator (dict, heal_op, + dup_volinfo, + &index, &hxlator_count, + rsp_dict); + glusterd_volinfo_delete (dup_volinfo); + if (ret < 0) + goto out; + } else { + ret = glusterd_shd_select_brick_xlator (dict, heal_op, + volinfo, + &index, &hxlator_count, + rsp_dict); + if (ret < 0) + goto out; + } pending_node = GF_CALLOC (1, sizeof (*pending_node), gf_gld_mt_pending_node_t); @@ -6435,6 +6473,21 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, pending_node = NULL; } + if (!hxlator_count) + goto out; + if (hxlator_count == -1) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_XLATOR_COUNT_GET_FAIL, "Could not determine the" + "translator count"); + ret = -1; + goto out; + } + + ret = dict_set_int32 (dict, "count", hxlator_count); + if (ret) + goto out; + + out: gf_msg_debug (THIS->name, 0, "Returning ret %d", ret); return ret; |