diff options
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 74 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 95 |
3 files changed, 128 insertions, 45 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 7676513cc50..df5ac17242b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -98,6 +98,79 @@ extern struct volopt_map_entry glusterd_volopt_map[]; static glusterd_lock_t lock; +static int +_brick_for_each (glusterd_volinfo_t *volinfo, dict_t *mod_dict, + void *data, + int (*fn) (glusterd_volinfo_t *, glusterd_brickinfo_t *, + dict_t *mod_dict, void *)) +{ + int ret = 0; + glusterd_brickinfo_t *brickinfo = NULL; + xlator_t *this = THIS; + + cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { + gf_msg_debug (this->name, 0, "Found a brick - %s:%s", + brickinfo->hostname, brickinfo->path); + ret = fn (volinfo, brickinfo, mod_dict, data); + if (ret) + goto out; + } +out: + return ret; +} + +int +glusterd_volume_brick_for_each (glusterd_volinfo_t *volinfo, void *data, + int (*fn) (glusterd_volinfo_t *, glusterd_brickinfo_t *, + dict_t *mod_dict, void *)) +{ + dict_t *mod_dict = NULL; + glusterd_volinfo_t *dup_volinfo = NULL; + int ret = 0; + + if (volinfo->type != GF_CLUSTER_TYPE_TIER) { + ret = _brick_for_each (volinfo, NULL, data, fn); + if (ret) + goto out; + } else { + ret = glusterd_create_sub_tier_volinfo (volinfo, &dup_volinfo, + _gf_true, + volinfo->volname); + if (ret) + goto out; + + mod_dict = dict_new(); + if (!mod_dict) { + ret = -1; + goto out; + } + + ret = dict_set_str (mod_dict, "hot-brick", "on"); + if (ret) + goto out; + + ret = _brick_for_each (dup_volinfo, mod_dict, data, fn); + if (ret) + goto out; + GF_FREE (dup_volinfo); + dup_volinfo = NULL; + ret = glusterd_create_sub_tier_volinfo (volinfo, &dup_volinfo, + _gf_false, + volinfo->volname); + if (ret) + goto out; + ret = _brick_for_each (dup_volinfo, NULL, data, fn); + if (ret) + goto out; + } +out: + if (dup_volinfo) + glusterd_volinfo_delete (dup_volinfo); + + if (mod_dict) + dict_unref (mod_dict); + return ret; +} int32_t glusterd_get_lock_owner (uuid_t *uuid) @@ -654,6 +727,7 @@ glusterd_create_sub_tier_volinfo (glusterd_volinfo_t *volinfo, return ret; } + gf_uuid_copy ((*dup_volinfo)->volume_id, volinfo->volume_id); (*dup_volinfo)->is_snap_volume = volinfo->is_snap_volume; (*dup_volinfo)->status = volinfo->status; (*dup_volinfo)->snapshot = volinfo->snapshot; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index d0fce5efb89..99225c674eb 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -688,4 +688,8 @@ glusterd_disallow_op_for_tier (glusterd_volinfo_t *volinfo, glusterd_op_t op, int32_t glusterd_count_connected_peers (int32_t *count); +int +glusterd_volume_brick_for_each (glusterd_volinfo_t *volinfo, void *data, + int (*fn) (glusterd_volinfo_t *, glusterd_brickinfo_t *, + dict_t *mod_dict, void *)); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 0bad4bd144f..988c6053d41 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -41,6 +41,11 @@ #include "glusterd-svc-helper.h" #include "glusterd-snapd-svc-helper.h" +struct gd_validate_reconf_opts { + dict_t *options; + char **op_errstr; +}; + extern struct volopt_map_entry glusterd_volopt_map[]; #define RPC_SET_OPT(XL, CLI_OPT, XLATOR_OPT, ERROR_CMD) do { \ @@ -1682,8 +1687,8 @@ brick_graph_add_changetimerecorder (volgen_graph_t *graph, char *brickname = NULL; char *path = NULL; char *volname = NULL; - int bricknum = 0; char index_basepath[PATH_MAX] = {0}; + char *hotbrick = NULL; if (!graph || !volinfo || !set_dict || !brickinfo) goto out; @@ -1698,18 +1703,12 @@ brick_graph_add_changetimerecorder (volgen_graph_t *graph, if (ret) goto out; - bricknum = 0; - cds_list_for_each_entry_safe (brickiter, tmp, &volinfo->bricks, - brick_list) { - if (brickiter == brickinfo) - break; - bricknum++; - } - if (bricknum < volinfo->tier_info.hot_brick_count) { - ret = xlator_set_option (xl, "hot-brick", "on"); - } else { - ret = xlator_set_option (xl, "hot-brick", "off"); - } + if (!set_dict || dict_get_str (set_dict, "hot-brick", &hotbrick)) + hotbrick = "off"; + + ret = xlator_set_option (xl, "hot-brick", hotbrick); + if (ret) + goto out; brickname = strrchr(path, '/') + 1; snprintf (index_basepath, sizeof (index_basepath), "%s.db", @@ -4884,7 +4883,8 @@ out: static int glusterd_generate_brick_volfile (glusterd_volinfo_t *volinfo, - glusterd_brickinfo_t *brickinfo) + glusterd_brickinfo_t *brickinfo, + dict_t *mod_dict, void *data) { volgen_graph_t graph = {0,}; char filename[PATH_MAX] = {0,}; @@ -4895,7 +4895,7 @@ glusterd_generate_brick_volfile (glusterd_volinfo_t *volinfo, get_brick_filepath (filename, volinfo, brickinfo); - ret = build_server_graph (&graph, volinfo, NULL, brickinfo); + ret = build_server_graph (&graph, volinfo, mod_dict, brickinfo); if (!ret) ret = volgen_write_volfile (&graph, filename); @@ -5104,16 +5104,10 @@ generate_brick_volfiles (glusterd_volinfo_t *volinfo) } } - cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - gf_msg_debug (this->name, 0, - "Found a brick - %s:%s", brickinfo->hostname, - brickinfo->path); - - ret = glusterd_generate_brick_volfile (volinfo, brickinfo); - if (ret) - goto out; - - } + ret = glusterd_volume_brick_for_each (volinfo, NULL, + glusterd_generate_brick_volfile); + if (ret) + goto out; ret = 0; @@ -5671,7 +5665,7 @@ glusterd_create_rb_volfiles (glusterd_volinfo_t *volinfo, { int ret = -1; - ret = glusterd_generate_brick_volfile (volinfo, brickinfo); + ret = glusterd_generate_brick_volfile (volinfo, brickinfo, NULL, NULL); if (!ret) ret = generate_client_volfiles (volinfo, GF_CLIENT_TRUSTED); if (!ret) @@ -5880,23 +5874,42 @@ validate_clientopts (glusterd_volinfo_t *volinfo, int validate_brickopts (glusterd_volinfo_t *volinfo, - glusterd_brickinfo_t *brickinfo, - dict_t *val_dict, - char **op_errstr) + glusterd_brickinfo_t *brickinfo, dict_t *mod_dict, + void *reconf) { - volgen_graph_t graph = {0,}; - int ret = -1; + volgen_graph_t graph = {0,}; + int ret = -1; + struct gd_validate_reconf_opts *brickreconf = reconf; + dict_t *val_dict = brickreconf->options; + char **op_errstr = brickreconf->op_errstr; + dict_t *full_dict = NULL; GF_ASSERT (volinfo); graph.errstr = op_errstr; + full_dict = dict_new(); + if (!full_dict) { + ret = -1; + goto out; + } + + if (mod_dict) + dict_copy (mod_dict, full_dict); + + if (val_dict) + dict_copy (val_dict, full_dict); + - ret = build_server_graph (&graph, volinfo, val_dict, brickinfo); + ret = build_server_graph (&graph, volinfo, full_dict, brickinfo); if (!ret) ret = graph_reconf_validateopt (&graph.graph, op_errstr); volgen_graph_free (&graph); +out: + if (full_dict) + dict_unref (full_dict); + gf_msg_debug ("glusterd", 0, "Returning %d", ret); return ret; } @@ -5908,20 +5921,12 @@ glusterd_validate_brickreconf (glusterd_volinfo_t *volinfo, { glusterd_brickinfo_t *brickinfo = NULL; int ret = -1; + struct gd_validate_reconf_opts brickreconf = {0}; - cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - gf_msg_debug ("glusterd", 0, - "Validating %s", brickinfo->hostname); - - ret = validate_brickopts (volinfo, brickinfo, val_dict, - op_errstr); - if (ret) - goto out; - } - - ret = 0; - -out: + brickreconf.options = val_dict; + brickreconf.op_errstr = op_errstr; + ret = glusterd_volume_brick_for_each (volinfo, &brickreconf, + validate_brickopts); return ret; } |