diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 224 |
1 files changed, 207 insertions, 17 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 127e4c46..148cea9c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -1423,6 +1423,7 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *vg = NULL; glusterd_brickinfo_t *brickinfo = NULL; char changelog_basepath[PATH_MAX] = {0,}; + char *value = NULL; brickinfo = param; path = brickinfo->path; @@ -1607,7 +1608,18 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret) return -1; - if (dict_get_str_boolean (set_dict, "features.read-only", 0) && + xl = volgen_graph_add (graph, "features/quota", volname); + if (!xl) + return -1; + + ret = glusterd_volinfo_get (volinfo, VKEY_FEATURES_QUOTA, &value); + if (value) { + ret = xlator_set_option (xl, "server-quota", value); + if (ret) + return -1; + } + + if (dict_get_str_boolean (set_dict, "features.read-only", 0) && dict_get_str_boolean (set_dict, "features.worm",0)) { gf_log (THIS->name, GF_LOG_ERROR, "read-only and worm cannot be set together"); @@ -2315,7 +2327,8 @@ out: static int volgen_graph_build_dht_cluster (volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, size_t child_count) + glusterd_volinfo_t *volinfo, size_t child_count, + gf_boolean_t is_quotad) { int32_t clusters = 0; int ret = -1; @@ -2323,17 +2336,23 @@ volgen_graph_build_dht_cluster (volgen_graph_t *graph, xlator_t *dht = NULL; char *optstr = NULL; gf_boolean_t use_nufa = _gf_false; + char *name_fmt = NULL; if (dict_get_str(volinfo->dict,"cluster.nufa",&optstr) == 0) { /* Keep static analyzers quiet by "using" the value. */ ret = gf_string2boolean(optstr,&use_nufa); } + if (is_quotad) + name_fmt = "%s"; + else + name_fmt = "%s-dht"; + clusters = volgen_graph_build_clusters (graph, volinfo, use_nufa ? "cluster/nufa" : "cluster/distribute", - "%s-dht", + name_fmt, child_count, child_count); if (clusters < 0) goto out; @@ -2356,7 +2375,8 @@ out: static int volume_volgen_graph_build_clusters (volgen_graph_t *graph, - glusterd_volinfo_t *volinfo) + glusterd_volinfo_t *volinfo, + gf_boolean_t is_quotad) { char *replicate_args[] = {"cluster/replicate", "%s-replicate-%d"}; @@ -2429,7 +2449,7 @@ build_distribute: } ret = volgen_graph_build_dht_cluster (graph, volinfo, - dist_count); + dist_count, is_quotad); if (ret) goto out; @@ -2446,25 +2466,30 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, xlator_t *xl = NULL; char *volname = NULL; data_t *tmp_data = NULL; + glusterd_conf_t *conf = THIS->private; + GF_ASSERT (conf); volname = volinfo->volname; ret = volgen_graph_build_clients (graph, volinfo, set_dict, param); if (ret) goto out; - ret = volume_volgen_graph_build_clusters (graph, volinfo); + ret = volume_volgen_graph_build_clusters (graph, volinfo, _gf_false); if (ret) goto out; - ret = glusterd_volinfo_get_boolean (volinfo, VKEY_FEATURES_QUOTA); - if (ret == -1) - goto out; - if (ret) { - xl = volgen_graph_add (graph, "features/quota", volname); - - if (!xl) { - ret = -1; + if (conf->op_version == GD_OP_VERSION_MIN) { + ret = glusterd_volinfo_get_boolean (volinfo, + VKEY_FEATURES_QUOTA); + if (ret == -1) goto out; + if (ret) { + xl = volgen_graph_add (graph, "features/quota", + volname); + if (!xl) { + ret = -1; + goto out; + } } } @@ -2734,6 +2759,60 @@ nfs_option_handler (volgen_graph_t *graph, } static int +set_quotad_xlator_option (char *fmt_str, char *opt_name, char *volname, + xlator_t *xl, char *value) +{ + int ret = -1; + char *opt_str = NULL; + + ret = gf_asprintf (&opt_str, fmt_str, volname, opt_name); + if (opt_str == NULL) { + ret = -1; + goto out; + } + ret = xlator_set_option (xl, opt_str, value); + +out: + GF_FREE (opt_str); + return ret; +} + +int +quotad_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, + void *param) +{ + xlator_t *xl = NULL; + char *opt_str = NULL; + int ret = 0; + glusterd_volinfo_t *volinfo = NULL; + int i = 0; + char *ptr = NULL; + char *options[] = {"!*.soft-timeout", "!*.hard-timeout", + "limit-set", "!*.alert-time", + "default-soft-limit", NULL}; + + volinfo = param; + xl = first_of (graph); + + for (i = 0; options[i]; i++) { + if (!strcmp (vme->option, options[i])) { + ptr = strchr (options[i], '.'); + if (!ptr) + opt_str = options[i]; + else + opt_str = ptr + 1; + ret = set_quotad_xlator_option ("%s.%s", opt_str, + volinfo->volname, xl, + vme->value); + if (ret) + return -1; + } + } + + return 0; +} + +static int volgen_graph_set_iam_shd (volgen_graph_t *graph) { xlator_t *trav; @@ -3018,9 +3097,6 @@ build_nfs_graph (volgen_graph_t *graph, dict_t *mod_dict) return ret; } - - - /**************************** * * Volume generation interface @@ -3107,7 +3183,109 @@ glusterd_generate_brick_volfile (glusterd_volinfo_t *volinfo, return ret; } +static int +build_quotad_graph (volgen_graph_t *graph, dict_t *mod_dict) +{ + volgen_graph_t cgraph = {0}; + glusterd_volinfo_t *voliter = NULL; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + dict_t *set_dict = NULL; + int ret = 0; + xlator_t *quotad_xl = NULL; + + this = THIS; + priv = this->private; + + set_dict = dict_new (); + if (!set_dict) { + ret = -ENOMEM; + goto out; + } + + quotad_xl = volgen_graph_add_as (graph, "features/quotad", "quotad"); + if (!quotad_xl) { + ret = -1; + goto out; + } + + list_for_each_entry (voliter, &priv->volumes, vol_list) { + if (voliter->status != GLUSTERD_STATUS_STARTED) + continue; + + if (1 != glusterd_is_volume_quota_enabled (voliter)) + continue; + + ret = dict_set_uint32 (set_dict, "trusted-client", + GF_CLIENT_TRUSTED); + if (ret) + goto out; + + dict_copy (voliter->dict, set_dict); + if (mod_dict) + dict_copy (mod_dict, set_dict); + + memset (&cgraph, 0, sizeof (cgraph)); + ret = volgen_graph_build_clients (&cgraph, voliter, set_dict, + NULL); + if (ret) + goto out; + + ret = volume_volgen_graph_build_clusters (&cgraph, voliter, + _gf_true); + if (ret) { + ret = -1; + goto out; + } + + if (mod_dict) { + dict_copy (mod_dict, set_dict); + ret = volgen_graph_set_options_generic (&cgraph, set_dict, + voliter, + basic_option_handler); + } else { + ret = volgen_graph_set_options_generic (&cgraph, + voliter->dict, + voliter, + basic_option_handler); + } + if (ret) + goto out; + + ret = volgen_graph_merge_sub (graph, &cgraph, 1); + if (ret) + goto out; + + ret = dict_reset (set_dict); + if (ret) + goto out; + } + list_for_each_entry (voliter, &priv->volumes, vol_list) { + if (voliter->status != GLUSTERD_STATUS_STARTED) + continue; + + if (1 != glusterd_is_volume_quota_enabled (voliter)) + continue; + if (mod_dict) { + ret = volgen_graph_set_options_generic (graph, mod_dict, + voliter, + quotad_option_handler); + } else { + ret = volgen_graph_set_options_generic (graph, + voliter->dict, voliter, + quotad_option_handler); + } + + if (ret) + gf_log (THIS->name, GF_LOG_ERROR, "Failed to set " + "options for the volume %s", voliter->volname); + } +out: + if (set_dict) + dict_unref (set_dict); + return ret; +} static void get_vol_tstamp_file (char *filename, glusterd_volinfo_t *volinfo) @@ -3375,6 +3553,18 @@ out: } int +glusterd_create_quotad_volfile () +{ + char filepath[PATH_MAX] = {0,}; + glusterd_conf_t *conf = THIS->private; + + glusterd_get_nodesvc_volfile ("quotad", conf->workdir, + filepath, sizeof (filepath)); + return glusterd_create_global_volfile (build_quotad_graph, + filepath, NULL); +} + +int glusterd_check_nfs_volfile_identical (gf_boolean_t *identical) { char nfsvol[PATH_MAX] = {0,}; |
