diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 2088 |
1 files changed, 909 insertions, 1179 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 3c32cf90577..8d6fb5e0fac 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -13,29 +13,30 @@ #include <dlfcn.h> #include <utime.h> -#include "xlator.h" +#include <glusterfs/xlator.h> #include "glusterd.h" -#include "defaults.h" -#include "syscall.h" -#include "logging.h" -#include "dict.h" -#include "graph-utils.h" -#include "common-utils.h" +#include <glusterfs/defaults.h> +#include <glusterfs/syscall.h> +#include <glusterfs/logging.h> +#include <glusterfs/dict.h> +#include <glusterfs/graph-utils.h> +#include <glusterfs/common-utils.h> #include "glusterd-store.h" #include "glusterd-hooks.h" -#include "trie.h" +#include <glusterfs/trie.h> #include "glusterd-mem-types.h" #include "cli1-xdr.h" #include "glusterd-volgen.h" #include "glusterd-geo-rep.h" #include "glusterd-utils.h" #include "glusterd-messages.h" -#include "run.h" -#include "options.h" +#include <glusterfs/run.h> +#include <glusterfs/options.h> #include "glusterd-snapshot-utils.h" #include "glusterd-svc-mgmt.h" #include "glusterd-svc-helper.h" #include "glusterd-snapd-svc-helper.h" +#include "glusterd-shd-svc-helper.h" #include "glusterd-gfproxyd-svc-helper.h" struct gd_validate_reconf_opts { @@ -49,9 +50,9 @@ extern struct volopt_map_entry glusterd_volopt_map[]; do { \ char *_value = NULL; \ \ - if (dict_get_str(set_dict, CLI_OPT, &_value) == 0) { \ - if (xlator_set_option(XL, "transport.socket." XLATOR_OPT, \ - _value) != 0) { \ + if (dict_get_str_sizen(set_dict, CLI_OPT, &_value) == 0) { \ + if (xlator_set_fixed_option(XL, "transport.socket." XLATOR_OPT, \ + _value) != 0) { \ gf_msg("glusterd", GF_LOG_WARNING, errno, \ GD_MSG_XLATOR_SET_OPT_FAIL, \ "failed to set " XLATOR_OPT); \ @@ -89,6 +90,8 @@ xlator_instantiate_va(const char *type, const char *format, va_list arg) xlator_t *xl = NULL; char *volname = NULL; int ret = 0; + xlator_t *this = THIS; + GF_ASSERT(this); ret = gf_vasprintf(&volname, format, arg); if (ret < 0) { @@ -98,14 +101,21 @@ xlator_instantiate_va(const char *type, const char *format, va_list arg) } xl = GF_CALLOC(1, sizeof(*xl), gf_common_mt_xlator_t); - if (!xl) + if (!xl) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_NO_MEMORY, NULL); goto error; + } ret = xlator_set_type_virtual(xl, type); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_XLATOR_SET_OPT_FAIL, + NULL); goto error; + } xl->options = dict_new(); - if (!xl->options) + if (!xl->options) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto error; + } xl->name = volname; CDS_INIT_LIST_HEAD(&xl->volume_options); @@ -114,8 +124,8 @@ xlator_instantiate_va(const char *type, const char *format, va_list arg) return xl; error: - gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_XLATOR_CREATE_FAIL, - "creating xlator of type %s failed", type); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_XLATOR_CREATE_FAIL, "Type=%s", + type, NULL); GF_FREE(volname); if (xl) xlator_destroy(xl); @@ -123,19 +133,6 @@ error: return NULL; } -static xlator_t * -xlator_instantiate(const char *type, const char *format, ...) -{ - va_list arg; - xlator_t *xl; - - va_start(arg, format); - xl = xlator_instantiate_va(type, format, arg); - va_end(arg); - - return xl; -} - static int volgen_xlator_link(xlator_t *pxl, xlator_t *cxl) { @@ -225,15 +222,17 @@ volgen_graph_add(volgen_graph_t *graph, char *type, char *volname) return volgen_graph_add_as(graph, type, "%s-%s", volname, shorttype); } +#define xlator_set_fixed_option(xl, key, value) \ + xlator_set_option(xl, key, SLEN(key), value) + /* XXX Seems there is no such generic routine? * Maybe should put to xlator.c ?? */ static int -xlator_set_option(xlator_t *xl, char *key, char *value) +xlator_set_option(xlator_t *xl, char *key, const int keylen, char *value) { - char *dval = NULL; + char *dval = gf_strdup(value); - dval = gf_strdup(value); if (!dval) { gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_NO_MEMORY, "failed to set xlator opt: %s[%s] = %s", xl->name, key, value); @@ -241,14 +240,17 @@ xlator_set_option(xlator_t *xl, char *key, char *value) return -1; } - return dict_set_dynstr(xl->options, key, dval); + return dict_set_dynstrn(xl->options, key, keylen, dval); } +#define xlator_get_fixed_option(xl, key, value) \ + xlator_get_option(xl, key, SLEN(key), value) + static int -xlator_get_option(xlator_t *xl, char *key, char **value) +xlator_get_option(xlator_t *xl, char *key, const int keylen, char **value) { GF_ASSERT(xl); - return dict_get_str(xl->options, key, value); + return dict_get_strn(xl->options, key, keylen, value); } static xlator_t * @@ -317,7 +319,7 @@ volopt_trie_cbk(char *word, void *param) } static int -process_nodevec(struct trienodevec *nodevec, char **hint) +process_nodevec(struct trienodevec *nodevec, char **outputhint, char *inputhint) { int ret = 0; char *hint1 = NULL; @@ -326,14 +328,14 @@ process_nodevec(struct trienodevec *nodevec, char **hint) trienode_t **nodes = nodevec->nodes; if (!nodes[0]) { - *hint = NULL; + *outputhint = NULL; return 0; } #if 0 /* Limit as in git */ if (trienode_get_dist (nodes[0]) >= 6) { - *hint = NULL; + *outputhint = NULL; return 0; } #endif @@ -342,23 +344,30 @@ process_nodevec(struct trienodevec *nodevec, char **hint) return -1; if (nodevec->cnt < 2 || !nodes[1]) { - *hint = hint1; + *outputhint = hint1; return 0; } - if (trienode_get_word(nodes[1], &hint2)) + if (trienode_get_word(nodes[1], &hint2)) { + GF_FREE(hint1); return -1; + } - if (*hint) - hintinfx = *hint; - ret = gf_asprintf(hint, "%s or %s%s", hint1, hintinfx, hint2); + if (inputhint) + hintinfx = inputhint; + ret = gf_asprintf(outputhint, "%s or %s%s", hint1, hintinfx, hint2); if (ret > 0) ret = 0; + if (hint1) + GF_FREE(hint1); + if (hint2) + GF_FREE(hint2); return ret; } static int -volopt_trie_section(int lvl, char **patt, char *word, char **hint, int hints) +volopt_trie_section(int lvl, char **patt, char *word, char **outputhint, + char *inputhint, int hints) { trienode_t *nodes[] = {NULL, NULL}; struct trienodevec nodevec = {nodes, 2}; @@ -379,7 +388,7 @@ volopt_trie_section(int lvl, char **patt, char *word, char **hint, int hints) nodevec.cnt = hints; ret = trie_measure_vec(trie, word, &nodevec); if (!ret && nodevec.nodes[0]) - ret = process_nodevec(&nodevec, hint); + ret = process_nodevec(&nodevec, outputhint, inputhint); trie_destroy(trie); @@ -391,6 +400,7 @@ volopt_trie(char *key, char **hint) { char *patt[] = {NULL}; char *fullhint = NULL; + char *inputhint = NULL; char *dot = NULL; char *dom = NULL; int len = 0; @@ -400,7 +410,7 @@ volopt_trie(char *key, char **hint) dot = strchr(key, '.'); if (!dot) - return volopt_trie_section(1, patt, key, hint, 2); + return volopt_trie_section(1, patt, key, hint, inputhint, 2); len = dot - key; dom = gf_strdup(key); @@ -408,7 +418,7 @@ volopt_trie(char *key, char **hint) return -1; dom[len] = '\0'; - ret = volopt_trie_section(0, NULL, dom, patt, 1); + ret = volopt_trie_section(0, NULL, dom, patt, inputhint, 1); GF_FREE(dom); if (ret) { patt[0] = NULL; @@ -417,8 +427,8 @@ volopt_trie(char *key, char **hint) if (!patt[0]) goto out; - *hint = "..."; - ret = volopt_trie_section(1, patt, dot + 1, hint, 2); + inputhint = "..."; + ret = volopt_trie_section(1, patt, dot + 1, hint, inputhint, 2); if (ret) goto out; if (*hint) { @@ -458,7 +468,7 @@ struct opthandler_data { void *param; }; -static int +static void process_option(char *key, data_t *value, void *param) { struct opthandler_data *odt = param; @@ -467,7 +477,7 @@ process_option(char *key, data_t *value, void *param) }; if (odt->rv) - return 0; + return; odt->found = _gf_true; vme.key = key; @@ -488,7 +498,7 @@ process_option(char *key, data_t *value, void *param) vme.value = value->data; odt->rv = odt->handler(odt->graph, &vme, odt->param); - return 0; + return; } static int @@ -500,6 +510,7 @@ volgen_graph_set_options_generic(volgen_graph_t *graph, dict_t *dict, 0, }; data_t *data = NULL; + int keylen; odt.graph = graph; odt.handler = handler; @@ -507,16 +518,17 @@ volgen_graph_set_options_generic(volgen_graph_t *graph, dict_t *dict, (void)data; for (vme = glusterd_volopt_map; vme->key; vme++) { - odt.vme = vme; - odt.found = _gf_false; - odt.data_t_fake = _gf_false; - - data = dict_get(dict, vme->key); - if (!strcmp(vme->key, "performance.client-io-threads") && + keylen = strlen(vme->key); + if (keylen == SLEN("performance.client-io-threads") && + !strcmp(vme->key, "performance.client-io-threads") && dict_get_str_boolean(dict, "skip-CLIOT", _gf_false) == _gf_true) { continue; } + odt.vme = vme; + odt.found = _gf_false; + odt.data_t_fake = _gf_false; + data = dict_getn(dict, vme->key, keylen); if (data) process_option(vme->key, data, &odt); if (odt.rv) @@ -551,8 +563,15 @@ no_filter_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, for (trav = first_of(graph); trav; trav = trav->next) { if (strcmp(trav->type, vme->voltype) != 0) continue; - - ret = xlator_set_option(trav, vme->option, vme->value); + if (strcmp(vme->option, "ta-remote-port") == 0) { + if (strstr(trav->name, "-ta-") != NULL) { + ret = xlator_set_option(trav, "remote-port", + strlen(vme->option), vme->value); + } + continue; + } + ret = xlator_set_option(trav, vme->option, strlen(vme->option), + vme->value); if (ret) break; } @@ -855,6 +874,8 @@ _xl_link_children(xlator_t *parent, xlator_t *children, size_t child_count) xlator_t *trav = NULL; size_t seek = 0; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); if (child_count == 0) goto out; @@ -863,9 +884,12 @@ _xl_link_children(xlator_t *parent, xlator_t *children, size_t child_count) ; for (; child_count--; trav = trav->prev) { ret = volgen_xlator_link(parent, trav); - gf_msg_debug(THIS->name, 0, "%s:%s", parent->name, trav->name); - if (ret) + gf_msg_debug(this->name, 0, "%s:%s", parent->name, trav->name); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_XLATOR_LINK_FAIL, + NULL); goto out; + } } ret = 0; out: @@ -923,8 +947,10 @@ volgen_apply_filters(char *orig_volfile) entry = sys_readdir(filterdir, scratch); - if (!entry || errno != 0) + if (!entry || errno != 0) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_READ_ERROR, NULL); break; + } if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; @@ -1110,6 +1136,7 @@ get_vol_transport_type(glusterd_volinfo_t *volinfo, char *tt) transport_type_to_str(volinfo->transport_type, tt); } +#ifdef BUILD_GNFS /* If no value has specified for tcp,rdma volume from cli * use tcp as default value.Otherwise, use transport type * mentioned in volinfo @@ -1125,6 +1152,7 @@ get_vol_nfs_transport_type(glusterd_volinfo_t *volinfo, char *tt) } else transport_type_to_str(volinfo->transport_type, tt); } +#endif /* gets the volinfo, dict, a character array for filling in * the transport type and a boolean option which says whether @@ -1138,21 +1166,19 @@ get_transport_type(glusterd_volinfo_t *volinfo, dict_t *set_dict, char *transt, { int ret = -1; char *tt = NULL; - char *key = NULL; - typedef void (*transport_type)(glusterd_volinfo_t * volinfo, char *tt); - transport_type get_transport; if (is_nfs == _gf_false) { - key = "client-transport-type"; - get_transport = get_vol_transport_type; + ret = dict_get_str_sizen(set_dict, "client-transport-type", &tt); + if (ret) + get_vol_transport_type(volinfo, transt); } else { - key = "nfs.transport-type"; - get_transport = get_vol_nfs_transport_type; +#ifdef BUILD_GNFS + ret = dict_get_str_sizen(set_dict, "nfs.transport-type", &tt); + if (ret) + get_vol_nfs_transport_type(volinfo, transt); +#endif } - ret = dict_get_str(set_dict, key, &tt); - if (ret) - get_transport(volinfo, transt); if (!ret) strcpy(transt, tt); } @@ -1175,7 +1201,7 @@ server_auth_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, /* from 'auth.allow' -> 'allow', and 'auth.reject' -> 'reject' */ key = strchr(vme->key, '.') + 1; - ret = xlator_get_option(xl, "auth-path", &auth_path); + ret = xlator_get_fixed_option(xl, "auth-path", &auth_path); if (ret) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DEFAULT_OPT_INFO, "Failed to get auth-path from server graph"); @@ -1183,7 +1209,7 @@ server_auth_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, } ret = gf_asprintf(&aa, "auth.addr.%s.%s", auth_path, key); if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); + ret = xlator_set_option(xl, aa, ret, vme->value); GF_FREE(aa); } if (ret) @@ -1213,6 +1239,26 @@ loglevel_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, } static int +threads_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, + void *param) +{ + char *role = param; + struct volopt_map_entry vme2 = { + 0, + }; + + if ((strcmp(vme->option, "!client-threads") != 0 && + strcmp(vme->option, "!brick-threads") != 0) || + !strstr(vme->key, role)) + return 0; + + memcpy(&vme2, vme, sizeof(vme2)); + vme2.option = "threads"; + + return basic_option_handler(graph, &vme2, NULL); +} + +static int server_check_changelog_off(volgen_graph_t *graph, struct volopt_map_entry *vme, glusterd_volinfo_t *volinfo) { @@ -1442,14 +1488,22 @@ volgen_graph_set_xl_options(volgen_graph_t *graph, dict_t *dict) }; /* for posix* -> *posix* */ char *loglevel = NULL; xlator_t *trav = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - ret = dict_get_str(dict, "xlator", &xlator); - if (ret) + ret = dict_get_str_sizen(dict, "xlator", &xlator); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=xlator", NULL); goto out; + } - ret = dict_get_str(dict, "loglevel", &loglevel); - if (ret) + ret = dict_get_str_sizen(dict, "loglevel", &loglevel); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=loglevel", NULL); goto out; + } snprintf(xlator_match, 1024, "*%s", xlator); @@ -1457,7 +1511,7 @@ volgen_graph_set_xl_options(volgen_graph_t *graph, dict_t *dict) if (fnmatch(xlator_match, trav->type, FNM_NOESCAPE) == 0) { gf_msg_debug("glusterd", 0, "Setting log level for xlator: %s", trav->type); - ret = xlator_set_option(trav, "log-level", loglevel); + ret = xlator_set_fixed_option(trav, "log-level", loglevel); if (ret) break; } @@ -1504,6 +1558,9 @@ server_spec_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, if (!ret) ret = log_localtime_logging_option_handler(graph, vme, "brick"); + if (!ret) + ret = threads_option_handler(graph, vme, "brick"); + return ret; } @@ -1539,29 +1596,37 @@ gfproxy_server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char key[1024] = { 0, }; + int keylen; /*char port_str[7] = {0, };*/ int ret = 0; char *username = NULL; char *password = NULL; /*int rclusters = 0;*/ + xlator_t *this = THIS; + GF_ASSERT(this); /* We are a trusted client */ ret = dict_set_uint32(set_dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret != 0) + if (ret != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } - ret = dict_set_int32n(set_dict, "gfproxy-server", SLEN("gfproxy-server"), - 1); - if (ret != 0) + ret = dict_set_int32_sizen(set_dict, "gfproxy-server", 1); + if (ret != 0) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=gfproxy-server", NULL); goto out; + } /* Build the client section of the graph first */ build_client_graph(graph, volinfo, set_dict); /* Clear this setting so that future users of set_dict do not end up * thinking they are a gfproxy server */ - dict_deln(set_dict, "gfproxy-server", SLEN("gfproxy-server")); - dict_deln(set_dict, "trusted-client", SLEN("trusted-client")); + dict_del_sizen(set_dict, "gfproxy-server"); + dict_del_sizen(set_dict, "trusted-client"); /* Then add the server to it */ get_vol_transport_type(volinfo, transt); @@ -1569,7 +1634,7 @@ gfproxy_server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (!xl) goto out; - ret = xlator_set_option(xl, "transport-type", transt); + ret = xlator_set_fixed_option(xl, "transport-type", transt); if (ret != 0) goto out; @@ -1577,22 +1642,22 @@ gfproxy_server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, username = glusterd_auth_get_username(volinfo); password = glusterd_auth_get_password(volinfo); if (username) { - snprintf(key, sizeof(key), "auth.login.gfproxyd-%s.allow", - volinfo->volname); - ret = xlator_set_option(xl, key, username); + keylen = snprintf(key, sizeof(key), "auth.login.gfproxyd-%s.allow", + volinfo->volname); + ret = xlator_set_option(xl, key, keylen, username); if (ret) return -1; } if (password) { - snprintf(key, sizeof(key), "auth.login.%s.password", username); - ret = xlator_set_option(xl, key, password); + keylen = snprintf(key, sizeof(key), "auth.login.%s.password", username); + ret = xlator_set_option(xl, key, keylen, password); if (ret != 0) goto out; } snprintf(key, sizeof(key), "gfproxyd-%s", volinfo->volname); - ret = xlator_set_option(xl, "auth-path", key); + ret = xlator_set_fixed_option(xl, "auth-path", key); out: return ret; @@ -1611,9 +1676,18 @@ brick_graph_add_posix(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, gf_boolean_t pgfid_feat = _gf_false; char *value = NULL; xlator_t *xl = NULL; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + + this = THIS; - if (!graph || !volinfo || !set_dict || !brickinfo) + if (!graph || !volinfo || !set_dict || !brickinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } + + priv = this->private; + GF_VALIDATE_OR_GOTO("glusterd", priv, out); ret = glusterd_volinfo_get(volinfo, VKEY_FEATURES_QUOTA, &value); if (value) { @@ -1642,23 +1716,30 @@ brick_graph_add_posix(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (!xl) goto out; - ret = xlator_set_option(xl, "directory", brickinfo->path); + ret = xlator_set_fixed_option(xl, "directory", brickinfo->path); if (ret) goto out; - ret = xlator_set_option(xl, "volume-id", uuid_utoa(volinfo->volume_id)); + ret = xlator_set_fixed_option(xl, "volume-id", + uuid_utoa(volinfo->volume_id)); if (ret) goto out; if (quota_enabled || pgfid_feat || trash_enabled) { - ret = xlator_set_option(xl, "update-link-count-parent", "on"); + ret = xlator_set_fixed_option(xl, "update-link-count-parent", "on"); if (ret) { goto out; } } + if (priv->op_version >= GD_OP_VERSION_7_0) { + ret = xlator_set_fixed_option(xl, "fips-mode-rchecksum", "on"); + if (ret) { + goto out; + } + } snprintf(tmpstr, sizeof(tmpstr), "%d", brickinfo->fs_share_count); - ret = xlator_set_option(xl, "shared-brick-count", tmpstr); + ret = xlator_set_fixed_option(xl, "shared-brick-count", tmpstr); out: return ret; } @@ -1669,9 +1750,13 @@ brick_graph_add_selinux(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo) + if (!graph || !volinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/selinux", volinfo->volname); if (!xl) @@ -1692,13 +1777,13 @@ brick_graph_add_trash(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, xl = volgen_graph_add(graph, "features/trash", volinfo->volname); if (!xl) goto out; - ret = xlator_set_option(xl, "trash-dir", ".trashcan"); + ret = xlator_set_fixed_option(xl, "trash-dir", ".trashcan"); if (ret) goto out; - ret = xlator_set_option(xl, "brick-path", brickinfo->path); + ret = xlator_set_fixed_option(xl, "brick-path", brickinfo->path); if (ret) goto out; - ret = xlator_set_option(xl, "trash-internal-op", "off"); + ret = xlator_set_fixed_option(xl, "trash-internal-op", "off"); if (ret) goto out; out: @@ -1706,28 +1791,6 @@ out: } static int -brick_graph_add_decompounder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, - dict_t *set_dict, glusterd_brickinfo_t *brickinfo) -{ - xlator_t *xl = NULL; - xlator_t *this = NULL; - glusterd_conf_t *conf = NULL; - int ret = -1; - - this = THIS; - GF_VALIDATE_OR_GOTO("glusterd", this, out); - conf = this->private; - GF_VALIDATE_OR_GOTO(this->name, conf, out); - - xl = volgen_graph_add_as(graph, "performance/decompounder", - brickinfo->path); - if (xl) - ret = 0; -out: - return ret; -} - -static int brick_graph_add_arbiter(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict, glusterd_brickinfo_t *brickinfo) { @@ -1752,41 +1815,6 @@ out: } static int -brick_graph_add_bd(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, - dict_t *set_dict, glusterd_brickinfo_t *brickinfo) -{ - int ret = -1; - - if (!graph || !volinfo || !set_dict || !brickinfo) - goto out; - - ret = 0; - -#ifdef HAVE_BD_XLATOR - if (*brickinfo->vg != '\0') { - xlator_t *xl = NULL; - /* Now add BD v2 xlator if volume is BD type */ - xl = volgen_graph_add(graph, "storage/bd", volinfo->volname); - if (!xl) { - ret = -1; - goto out; - } - - ret = xlator_set_option(xl, "device", "vg"); - if (ret) - goto out; - - ret = xlator_set_option(xl, "export", brickinfo->vg); - if (ret) - goto out; - } -#endif - -out: - return ret; -} - -static int brick_graph_add_bitrot_stub(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict, glusterd_brickinfo_t *brickinfo) { @@ -1795,14 +1823,16 @@ brick_graph_add_bitrot_stub(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *value = NULL; xlator_t *this = THIS; - if (!graph || !volinfo || !set_dict || !brickinfo) + if (!graph || !volinfo || !set_dict || !brickinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/bitrot-stub", volinfo->volname); if (!xl) goto out; - ret = xlator_set_option(xl, "export", brickinfo->path); + ret = xlator_set_fixed_option(xl, "export", brickinfo->path); if (ret) { gf_log(this->name, GF_LOG_WARNING, "failed to set the export " @@ -1811,7 +1841,7 @@ brick_graph_add_bitrot_stub(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, } ret = glusterd_volinfo_get(volinfo, VKEY_FEATURES_BITROT, &value); - ret = xlator_set_option(xl, "bitrot", value); + ret = xlator_set_fixed_option(xl, "bitrot", value); if (ret) gf_log(this->name, GF_LOG_WARNING, "failed to set bitrot " @@ -1831,102 +1861,48 @@ brick_graph_add_changelog(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, }; int ret = -1; int32_t len = 0; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict || !brickinfo) + if (!graph || !volinfo || !set_dict || !brickinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/changelog", volinfo->volname); if (!xl) goto out; - ret = xlator_set_option(xl, "changelog-brick", brickinfo->path); + ret = xlator_set_fixed_option(xl, "changelog-brick", brickinfo->path); if (ret) goto out; len = snprintf(changelog_basepath, sizeof(changelog_basepath), "%s/%s", brickinfo->path, ".glusterfs/changelogs"); if ((len < 0) || (len >= sizeof(changelog_basepath))) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL); ret = -1; goto out; } - ret = xlator_set_option(xl, "changelog-dir", changelog_basepath); - if (ret) - goto out; -out: - return ret; -} - -#if USE_GFDB /* only add changetimerecorder when GFDB is enabled */ -static int -brick_graph_add_changetimerecorder(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, - dict_t *set_dict, - glusterd_brickinfo_t *brickinfo) -{ - xlator_t *xl = NULL; - int ret = -1; - char *brickname = NULL; - char *path = NULL; - char index_basepath[PATH_MAX] = {0}; - char *hotbrick = NULL; - - if (!graph || !volinfo || !set_dict || !brickinfo) - goto out; - - path = brickinfo->path; - - xl = volgen_graph_add(graph, "features/changetimerecorder", - volinfo->volname); - if (!xl) - goto out; - - ret = xlator_set_option(xl, "db-type", "sqlite3"); - if (ret) - goto out; - - 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", brickname); - ret = xlator_set_option(xl, "db-name", index_basepath); - if (ret) - goto out; - - snprintf(index_basepath, sizeof(index_basepath), "%s/%s", path, - ".glusterfs/"); - ret = xlator_set_option(xl, "db-path", index_basepath); - if (ret) - goto out; - - ret = xlator_set_option(xl, "record-exit", "off"); - if (ret) - goto out; - - ret = xlator_set_option(xl, "ctr_link_consistency", "off"); + ret = xlator_set_fixed_option(xl, "changelog-dir", changelog_basepath); if (ret) goto out; - ret = xlator_set_option(xl, "ctr_lookupheal_link_timeout", "300"); - if (ret) - goto out; - - ret = xlator_set_option(xl, "ctr_lookupheal_inode_timeout", "300"); - if (ret) - goto out; - - ret = xlator_set_option(xl, "record-entry", "on"); - if (ret) + ret = glusterd_is_bitrot_enabled(volinfo); + if (ret == -1) { goto out; - + } else if (ret) { + ret = xlator_set_fixed_option(xl, "changelog-notification", "on"); + if (ret) + goto out; + } else { + ret = xlator_set_fixed_option(xl, "changelog-notification", "off"); + if (ret) + goto out; + } out: return ret; } -#endif /* USE_GFDB */ static int brick_graph_add_acl(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, @@ -1934,14 +1910,31 @@ brick_graph_add_acl(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } - xl = volgen_graph_add(graph, "features/access-control", volinfo->volname); - if (!xl) + ret = dict_get_str_boolean(set_dict, "features.acl", 1); + if (!ret) { + /* Skip creating this volume if option is disabled */ + /* By default, this is 'true' */ goto out; + } else if (ret < 0) { + /* lets not treat this as error, as this option is not critical, + and implemented for debug help */ + gf_log(THIS->name, GF_LOG_INFO, + "failed to get 'features.acl' flag from dict"); + } + xl = volgen_graph_add(graph, "features/access-control", volinfo->volname); + if (!xl) { + ret = -1; + goto out; + } ret = 0; out: return ret; @@ -1953,9 +1946,13 @@ brick_graph_add_locks(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/locks", volinfo->volname); if (!xl) @@ -1966,37 +1963,19 @@ out: return ret; } -/* Add this before (above) io-threads because it's not thread-safe yet. */ -static int -brick_graph_add_fdl(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, - dict_t *set_dict, glusterd_brickinfo_t *brickinfo) -{ - xlator_t *xl = NULL; - int ret = -1; - - if (!graph || !volinfo || !set_dict) - goto out; - - if (dict_get_str_boolean(set_dict, "features.fdl", 0)) { - xl = volgen_graph_add(graph, "experimental/fdl", volinfo->volname); - if (!xl) - goto out; - } - ret = 0; - -out: - return ret; -} - static int brick_graph_add_iot(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict, glusterd_brickinfo_t *brickinfo) { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "performance/io-threads", volinfo->volname); if (!xl) @@ -2012,9 +1991,12 @@ brick_graph_add_barrier(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; - if (!graph || !volinfo) + if (!graph || !volinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/barrier", volinfo->volname); if (!xl) @@ -2031,9 +2013,13 @@ brick_graph_add_sdfs(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo) + if (!graph || !volinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } if (!dict_get_str_boolean(set_dict, "features.sdfs", 0)) { /* update only if option is enabled */ @@ -2044,6 +2030,11 @@ brick_graph_add_sdfs(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, xl = volgen_graph_add(graph, "features/sdfs", volinfo->volname); if (!xl) goto out; + /* If we don't set this option here, the translator by default marks + it 'pass-through' */ + ret = xlator_set_fixed_option(xl, "pass-through", "false"); + if (ret) + goto out; ret = 0; out: @@ -2056,9 +2047,13 @@ brick_graph_add_namespace(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } ret = dict_get_str_boolean(set_dict, "features.tag-namespaces", 0); if (ret == -1) @@ -2088,13 +2083,13 @@ add_one_peer(volgen_graph_t *graph, glusterd_brickinfo_t *peer, char *volname, } /* TBD: figure out where to get the proper transport list */ - if (xlator_set_option(kid, "transport-type", "socket")) { + if (xlator_set_fixed_option(kid, "transport-type", "socket")) { return NULL; } - if (xlator_set_option(kid, "remote-host", peer->hostname)) { + if (xlator_set_fixed_option(kid, "remote-host", peer->hostname)) { return NULL; } - if (xlator_set_option(kid, "remote-subvolume", peer->path)) { + if (xlator_set_fixed_option(kid, "remote-subvolume", peer->path)) { return NULL; } /* TBD: deal with RDMA, SSL */ @@ -2102,75 +2097,6 @@ add_one_peer(volgen_graph_t *graph, glusterd_brickinfo_t *peer, char *volname, return kid; } -int -add_jbr_stuff(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, - glusterd_brickinfo_t *brickinfo) -{ - xlator_t *me; - glusterd_brickinfo_t *peer; - glusterd_brickinfo_t *prev_peer; - char *leader_opt; - uint16_t index = 0; - xlator_t *kid; - - /* Create the JBR xlator, but defer linkage for now. */ - me = xlator_instantiate("experimental/jbr", "%s-jbr", volinfo->volname); - if (!me || volgen_xlator_link(me, first_of(graph))) { - return -1; - } - - /* Figure out if we should start as leader, mark appropriately. */ - peer = list_prev(brickinfo, &volinfo->bricks, glusterd_brickinfo_t, - brick_list); - leader_opt = (!peer || (peer->group != brickinfo->group)) ? "yes" : "no"; - if (xlator_set_option(me, "leader", leader_opt)) { - /* - * TBD: fix memory leak ("me" and associated dictionary) - * There seems to be no function already to clean up a - * just-allocated translator object if something else fails. - * Apparently the convention elsewhere in this file is to return - * without freeing anything, but we can't keep being that sloppy - * forever. - */ - return -1; - } - - /* - * Make sure we're at the beginning of the list of bricks in this - * replica set. This way all bricks' volfiles have peers in a - * consistent order. - */ - peer = brickinfo; - for (;;) { - prev_peer = list_prev(peer, &volinfo->bricks, glusterd_brickinfo_t, - brick_list); - if (!prev_peer || (prev_peer->group != brickinfo->group)) { - break; - } - peer = prev_peer; - } - - /* Actually add the peers. */ - do { - if (peer != brickinfo) { - gf_log("glusterd", GF_LOG_INFO, "%s:%s needs client for %s:%s", - brickinfo->hostname, brickinfo->path, peer->hostname, - peer->path); - kid = add_one_peer(graph, peer, volinfo->volname, index++); - if (!kid || volgen_xlator_link(me, kid)) { - return -1; - } - } - peer = list_next(peer, &volinfo->bricks, glusterd_brickinfo_t, - brick_list); - } while (peer && (peer->group == brickinfo->group)); - - /* Finish linkage to client file. */ - glusterfs_graph_set_first(&graph->graph, me); - - return 0; -} - static int brick_graph_add_index(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict, glusterd_brickinfo_t *brickinfo) @@ -2180,13 +2106,12 @@ brick_graph_add_index(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char index_basepath[PATH_MAX] = {0}; int ret = -1; int32_t len = 0; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !brickinfo || !set_dict) + if (!graph || !volinfo || !brickinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; - - /* For JBR we don't need/want index. */ - if (glusterd_volinfo_get_boolean(volinfo, "cluster.jbr") > 0) { - return add_jbr_stuff(graph, volinfo, brickinfo); } xl = volgen_graph_add(graph, "features/index", volinfo->volname); @@ -2196,28 +2121,30 @@ brick_graph_add_index(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, len = snprintf(index_basepath, sizeof(index_basepath), "%s/%s", brickinfo->path, ".glusterfs/indices"); if ((len < 0) || (len >= sizeof(index_basepath))) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL); goto out; } - ret = xlator_set_option(xl, "index-base", index_basepath); + ret = xlator_set_fixed_option(xl, "index-base", index_basepath); if (ret) goto out; if (volinfo->type == GF_CLUSTER_TYPE_DISPERSE) { - ret = xlator_set_option(xl, "xattrop64-watchlist", "trusted.ec.dirty"); + ret = xlator_set_fixed_option(xl, "xattrop64-watchlist", + "trusted.ec.dirty"); if (ret) goto out; } - if ((volinfo->type == GF_CLUSTER_TYPE_STRIPE_REPLICATE || - volinfo->type == GF_CLUSTER_TYPE_REPLICATE || + if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE || volinfo->type == GF_CLUSTER_TYPE_NONE)) { - ret = xlator_set_option(xl, "xattrop-dirty-watchlist", - "trusted.afr.dirty"); + ret = xlator_set_fixed_option(xl, "xattrop-dirty-watchlist", + "trusted.afr.dirty"); if (ret) goto out; ret = gf_asprintf(&pending_xattr, "trusted.afr.%s-", volinfo->volname); if (ret < 0) goto out; - ret = xlator_set_option(xl, "xattrop-pending-watchlist", pending_xattr); + ret = xlator_set_fixed_option(xl, "xattrop-pending-watchlist", + pending_xattr); if (ret) goto out; } @@ -2241,25 +2168,29 @@ brick_graph_add_marker(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char buf[32] = { 0, }; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/marker", volinfo->volname); if (!xl) goto out; gf_uuid_unparse(volinfo->volume_id, volume_id); - ret = xlator_set_option(xl, "volume-uuid", volume_id); + ret = xlator_set_fixed_option(xl, "volume-uuid", volume_id); if (ret) goto out; get_vol_tstamp_file(tstamp_file, volinfo); - ret = xlator_set_option(xl, "timestamp-file", tstamp_file); + ret = xlator_set_fixed_option(xl, "timestamp-file", tstamp_file); if (ret) goto out; snprintf(buf, sizeof(buf), "%d", volinfo->quota_xattr_version); - ret = xlator_set_option(xl, "quota-version", buf); + ret = xlator_set_fixed_option(xl, "quota-version", buf); if (ret) goto out; @@ -2274,21 +2205,25 @@ brick_graph_add_quota(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, int ret = -1; xlator_t *xl = NULL; char *value = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/quota", volinfo->volname); if (!xl) goto out; - ret = xlator_set_option(xl, "volume-uuid", volinfo->volname); + ret = xlator_set_fixed_option(xl, "volume-uuid", volinfo->volname); if (ret) goto out; ret = glusterd_volinfo_get(volinfo, VKEY_FEATURES_QUOTA, &value); if (value) { - ret = xlator_set_option(xl, "server-quota", value); + ret = xlator_set_fixed_option(xl, "server-quota", value); if (ret) goto out; } @@ -2302,9 +2237,13 @@ brick_graph_add_ro(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { int ret = -1; xlator_t *xl = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } if (dict_get_str_boolean(set_dict, "features.read-only", 0) && (dict_get_str_boolean(set_dict, "features.worm", 0) || @@ -2318,7 +2257,7 @@ brick_graph_add_ro(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, xl = volgen_graph_add(graph, "features/read-only", volinfo->volname); if (!xl) return -1; - ret = xlator_set_option(xl, "read-only", "off"); + ret = xlator_set_fixed_option(xl, "read-only", "off"); if (ret) return -1; @@ -2334,9 +2273,13 @@ brick_graph_add_worm(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { int ret = -1; xlator_t *xl = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } if (dict_get_str_boolean(set_dict, "features.read-only", 0) && (dict_get_str_boolean(set_dict, "features.worm", 0) || @@ -2363,9 +2306,13 @@ brick_graph_add_cdc(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { int ret = -1; xlator_t *xl = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } /* Check for compress volume option, and add it to the graph on * server side */ @@ -2378,7 +2325,7 @@ brick_graph_add_cdc(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = -1; goto out; } - ret = xlator_set_option(xl, "mode", "server"); + ret = xlator_set_fixed_option(xl, "mode", "server"); if (ret) goto out; } @@ -2392,18 +2339,29 @@ brick_graph_add_io_stats(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { int ret = -1; xlator_t *xl = NULL; + xlator_t *this = THIS; + glusterd_conf_t *priv = this->private; - if (!graph || !volinfo || !set_dict || !brickinfo) + if (!graph || !set_dict || !brickinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } - xl = volgen_graph_add(graph, "debug/io-stats", volinfo->volname); + xl = volgen_graph_add_as(graph, "debug/io-stats", brickinfo->path); if (!xl) goto out; - ret = xlator_set_option(xl, "unique-id", brickinfo->path); + ret = xlator_set_fixed_option(xl, "unique-id", brickinfo->path); if (ret) goto out; + if (priv->op_version >= GD_OP_VERSION_7_1) { + ret = xlator_set_fixed_option(xl, "volume-id", + uuid_utoa(volinfo->volume_id)); + if (ret) + goto out; + } + ret = 0; out: return ret; @@ -2415,9 +2373,13 @@ brick_graph_add_upcall(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/upcall", volinfo->volname); if (!xl) { @@ -2437,9 +2399,13 @@ brick_graph_add_leases(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { xlator_t *xl = NULL; int ret = -1; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } xl = volgen_graph_add(graph, "features/leases", volinfo->volname); if (!xl) { @@ -2469,9 +2435,13 @@ brick_graph_add_server(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *volname = NULL; char *address_family_data = NULL; int32_t len = 0; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict || !brickinfo) + if (!graph || !volinfo || !set_dict || !brickinfo) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } get_vol_transport_type(volinfo, transt); @@ -2482,16 +2452,16 @@ brick_graph_add_server(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (!xl) goto out; - ret = xlator_set_option(xl, "transport-type", transt); + ret = xlator_set_fixed_option(xl, "transport-type", transt); if (ret) goto out; /*In the case of running multiple glusterds on a single machine, * we should ensure that bricks don't listen on all IPs on that * machine and break the IP based separation being brought about.*/ - if (dict_get(THIS->options, "transport.socket.bind-address")) { - ret = xlator_set_option(xl, "transport.socket.bind-address", - brickinfo->hostname); + if (dict_get_sizen(THIS->options, "transport.socket.bind-address")) { + ret = xlator_set_fixed_option(xl, "transport.socket.bind-address", + brickinfo->hostname); if (ret) return -1; } @@ -2505,10 +2475,10 @@ brick_graph_add_server(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, RPC_SET_OPT(xl, SSL_DH_PARAM_OPT, "ssl-dh-param", return -1); RPC_SET_OPT(xl, SSL_EC_CURVE_OPT, "ssl-ec-curve", return -1); - if (dict_get_str(volinfo->dict, "transport.address-family", - &address_family_data) == 0) { - ret = xlator_set_option(xl, "transport.address-family", - address_family_data); + if (dict_get_str_sizen(volinfo->dict, "transport.address-family", + &address_family_data) == 0) { + ret = xlator_set_fixed_option(xl, "transport.address-family", + address_family_data); if (ret) { gf_log("glusterd", GF_LOG_WARNING, "failed to set transport.address-family"); @@ -2523,22 +2493,22 @@ brick_graph_add_server(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, return -1; } - ret = xlator_set_option(xl, key, username); + ret = xlator_set_option(xl, key, len, username); if (ret) return -1; } if (password) { - snprintf(key, sizeof(key), "auth.login.%s.password", username); - - ret = xlator_set_option(xl, key, password); + len = snprintf(key, sizeof(key), "auth.login.%s.password", username); + if ((len < 0) || (len >= sizeof(key))) { + return -1; + } + ret = xlator_set_option(xl, key, len, password); if (ret) return -1; } - snprintf(key, sizeof(key), "auth-path"); - - ret = xlator_set_option(xl, key, brickinfo->path); + ret = xlator_set_fixed_option(xl, "auth-path", brickinfo->path); if (ret) return -1; @@ -2546,21 +2516,19 @@ brick_graph_add_server(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, : volinfo->volname; if (volname && !strcmp(volname, GLUSTER_SHARED_STORAGE)) { - snprintf(key, sizeof(key), "strict-auth-accept"); - - ret = xlator_set_option(xl, key, "true"); + ret = xlator_set_fixed_option(xl, "strict-auth-accept", "true"); if (ret) return -1; } - if (dict_get_str(volinfo->dict, "auth.ssl-allow", &ssl_user) == 0) { + if (dict_get_str_sizen(volinfo->dict, "auth.ssl-allow", &ssl_user) == 0) { len = snprintf(key, sizeof(key), "auth.login.%s.ssl-allow", brickinfo->path); if ((len < 0) || (len >= sizeof(key))) { return -1; } - ret = xlator_set_option(xl, key, ssl_user); + ret = xlator_set_option(xl, key, len, ssl_user); if (ret) return -1; } @@ -2582,13 +2550,20 @@ brick_graph_add_pump(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *password = NULL; char *ptranst = NULL; char *address_family_data = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!graph || !volinfo || !set_dict) + if (!graph || !volinfo || !set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } ret = dict_get_int32(volinfo->dict, "enable-pump", &pump); - if (ret == -ENOENT) + if (ret == -ENOENT) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=enable-pump", NULL); ret = pump = 0; + } if (ret) return -1; @@ -2617,26 +2592,26 @@ brick_graph_add_pump(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, RPC_SET_OPT(rbxl, SSL_EC_CURVE_OPT, "ssl-ec-curve", return -1); if (username) { - ret = xlator_set_option(rbxl, "username", username); + ret = xlator_set_fixed_option(rbxl, "username", username); if (ret) return -1; } if (password) { - ret = xlator_set_option(rbxl, "password", password); + ret = xlator_set_fixed_option(rbxl, "password", password); if (ret) return -1; } - ret = xlator_set_option(rbxl, "transport-type", ptranst); + ret = xlator_set_fixed_option(rbxl, "transport-type", ptranst); GF_FREE(ptranst); if (ret) return -1; - if (dict_get_str(volinfo->dict, "transport.address-family", - &address_family_data) == 0) { - ret = xlator_set_option(rbxl, "transport.address-family", - address_family_data); + if (dict_get_str_sizen(volinfo->dict, "transport.address-family", + &address_family_data) == 0) { + ret = xlator_set_fixed_option(rbxl, "transport.address-family", + address_family_data); if (ret) { gf_log("glusterd", GF_LOG_WARNING, "failed to set transport.address-family"); @@ -2664,7 +2639,6 @@ out: * the topology of the brick graph */ static volgen_brick_xlator_t server_graph_table[] = { {brick_graph_add_server, NULL}, - {brick_graph_add_decompounder, "decompounder"}, {brick_graph_add_io_stats, "NULL"}, {brick_graph_add_sdfs, "sdfs"}, {brick_graph_add_namespace, "namespace"}, @@ -2674,7 +2648,6 @@ static volgen_brick_xlator_t server_graph_table[] = { {brick_graph_add_barrier, NULL}, {brick_graph_add_marker, "marker"}, {brick_graph_add_selinux, "selinux"}, - {brick_graph_add_fdl, "fdl"}, {brick_graph_add_iot, "io-threads"}, {brick_graph_add_upcall, "upcall"}, {brick_graph_add_leases, "leases"}, @@ -2685,10 +2658,6 @@ static volgen_brick_xlator_t server_graph_table[] = { {brick_graph_add_acl, "acl"}, {brick_graph_add_bitrot_stub, "bitrot-stub"}, {brick_graph_add_changelog, "changelog"}, -#if USE_GFDB /* changetimerecorder depends on gfdb */ - {brick_graph_add_changetimerecorder, "changetimerecorder"}, -#endif - {brick_graph_add_bd, "bd"}, {brick_graph_add_trash, "trash"}, {brick_graph_add_arbiter, "arbiter"}, {brick_graph_add_posix, "posix"}, @@ -2815,11 +2784,11 @@ server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, i--; } - ret = dict_get_str(set_dict, "xlator", &xlator); + ret = dict_get_str_sizen(set_dict, "xlator", &xlator); /* got a cli log level request */ if (!ret) { - ret = dict_get_str(set_dict, "loglevel", &loglevel); + ret = dict_get_str_sizen(set_dict, "loglevel", &loglevel); if (ret) { gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "could not get both" @@ -2881,8 +2850,7 @@ perfxl_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, * performance */ if (!strcmp(vme->key, "performance.client-io-threads") && - (GF_CLUSTER_TYPE_STRIPE_REPLICATE == volinfo->type || - GF_CLUSTER_TYPE_REPLICATE == volinfo->type)) + (GF_CLUSTER_TYPE_REPLICATE == volinfo->type)) return 0; } @@ -2930,6 +2898,7 @@ gfproxy_client_perfxl_option_handler(volgen_graph_t *graph, return 0; } +#ifdef BUILD_GNFS static int nfsperfxl_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, void *param) @@ -2952,6 +2921,7 @@ nfsperfxl_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, else return -1; } +#endif #if (HAVE_LIB_XML) int @@ -3109,8 +3079,10 @@ _get_xlator_opt_key_from_vme(struct volopt_map_entry *vme, char **key) *key = gf_strdup(AUTH_ALLOW_OPT_KEY); else if (!strcmp(vme->key, AUTH_REJECT_MAP_KEY)) *key = gf_strdup(AUTH_REJECT_OPT_KEY); +#ifdef BUILD_GNFS else if (!strcmp(vme->key, NFS_DISABLE_MAP_KEY)) *key = gf_strdup(NFS_DISABLE_OPT_KEY); +#endif else { if (vme->option) { if (vme->option[0] == '!') { @@ -3176,34 +3148,34 @@ volgen_graph_build_client(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (!xl) goto err; - ret = xlator_set_option(xl, "ping-timeout", "42"); + ret = xlator_set_fixed_option(xl, "ping-timeout", "42"); if (ret) goto err; if (hostname) { - ret = xlator_set_option(xl, "remote-host", hostname); + ret = xlator_set_fixed_option(xl, "remote-host", hostname); if (ret) goto err; } if (port) { - ret = xlator_set_option(xl, "remote-port", port); + ret = xlator_set_fixed_option(xl, "remote-port", port); if (ret) goto err; } - ret = xlator_set_option(xl, "remote-subvolume", subvol); + ret = xlator_set_fixed_option(xl, "remote-subvolume", subvol); if (ret) goto err; - ret = xlator_set_option(xl, "transport-type", transt); + ret = xlator_set_fixed_option(xl, "transport-type", transt); if (ret) goto err; - if (dict_get_str(volinfo->dict, "transport.address-family", - &address_family_data) == 0) { - ret = xlator_set_option(xl, "transport.address-family", - address_family_data); + if (dict_get_str_sizen(volinfo->dict, "transport.address-family", + &address_family_data) == 0) { + ret = xlator_set_fixed_option(xl, "transport.address-family", + address_family_data); if (ret) { gf_log("glusterd", GF_LOG_WARNING, "failed to set transport.address-family"); @@ -3218,24 +3190,24 @@ volgen_graph_build_client(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, str = NULL; str = glusterd_auth_get_username(volinfo); if (str) { - ret = xlator_set_option(xl, "username", str); + ret = xlator_set_fixed_option(xl, "username", str); if (ret) goto err; } str = glusterd_auth_get_password(volinfo); if (str) { - ret = xlator_set_option(xl, "password", str); + ret = xlator_set_fixed_option(xl, "password", str); if (ret) goto err; } } - if (dict_get_str(set_dict, "client.ssl", &ssl_str) == 0) { + if (dict_get_str_sizen(set_dict, "client.ssl", &ssl_str) == 0) { if (gf_string2boolean(ssl_str, &ssl_bool) == 0) { if (ssl_bool) { - ret = xlator_set_option(xl, "transport.socket.ssl-enabled", - "true"); + ret = xlator_set_fixed_option( + xl, "transport.socket.ssl-enabled", "true"); if (ret) { goto err; } @@ -3267,7 +3239,10 @@ volgen_graph_build_clients(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, 0, }; glusterd_brickinfo_t *brick = NULL; + glusterd_brickinfo_t *ta_brick = NULL; xlator_t *xl = NULL; + int subvol_index = 0; + int thin_arbiter_index = 0; if (volinfo->brick_count == 0) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLUME_INCONSISTENCY, @@ -3275,8 +3250,7 @@ volgen_graph_build_clients(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, goto out; } - if ((volinfo->type != GF_CLUSTER_TYPE_TIER) && - (volinfo->dist_leaf_count < volinfo->brick_count) && + if ((volinfo->dist_leaf_count < volinfo->brick_count) && ((volinfo->brick_count % volinfo->dist_leaf_count) != 0)) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLUME_INCONSISTENCY, "volume inconsistency: " @@ -3295,6 +3269,30 @@ volgen_graph_build_clients(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, i = 0; cds_list_for_each_entry(brick, &volinfo->bricks, brick_list) { + /* insert ta client xlator entry. + * eg - If subvol count is > 1, then after every two client xlator + * entries there should be a ta client xlator entry in the volfile. ta + * client xlator indexes are - 2, 5, 8 etc depending on the index of + * subvol. + */ + if (volinfo->thin_arbiter_count && + (i + 1) % (volinfo->replica_count + 1) == 0) { + thin_arbiter_index = 0; + cds_list_for_each_entry(ta_brick, &volinfo->ta_bricks, brick_list) + { + if (thin_arbiter_index == subvol_index) { + xl = volgen_graph_build_client( + graph, volinfo, ta_brick->hostname, NULL, + ta_brick->path, ta_brick->brick_id, transt, set_dict); + if (!xl) { + ret = -1; + goto out; + } + } + thin_arbiter_index++; + } + subvol_index++; + } xl = volgen_graph_build_client(graph, volinfo, brick->hostname, NULL, brick->path, brick->brick_id, transt, set_dict); @@ -3306,6 +3304,28 @@ volgen_graph_build_clients(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, i++; } + /* Add ta client xlator entry for last subvol + * Above loop will miss out on making the ta client + * xlator entry for the last subvolume in the volfile + */ + if (volinfo->thin_arbiter_count) { + thin_arbiter_index = 0; + cds_list_for_each_entry(ta_brick, &volinfo->ta_bricks, brick_list) + { + if (thin_arbiter_index == subvol_index) { + xl = volgen_graph_build_client( + graph, volinfo, ta_brick->hostname, NULL, ta_brick->path, + ta_brick->brick_id, transt, set_dict); + if (!xl) { + ret = -1; + goto out; + } + } + + thin_arbiter_index++; + } + } + if (i != volinfo->brick_count) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLUME_INCONSISTENCY, "volume inconsistency: actual number of bricks (%d) " @@ -3321,50 +3341,6 @@ out: } static int -volgen_graph_build_clients_for_tier_shd(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, - dict_t *set_dict) -{ - int ret = 0; - glusterd_volinfo_t *dup_volinfo = NULL; - gf_boolean_t is_hot_tier = _gf_false; - gf_boolean_t is_hot_shd = _gf_false; - gf_boolean_t is_cold_shd = _gf_false; - - is_cold_shd = glusterd_is_shd_compatible_type(volinfo->tier_info.cold_type); - is_hot_shd = glusterd_is_shd_compatible_type(volinfo->tier_info.hot_type); - - if (is_cold_shd && is_hot_shd) { - ret = volgen_graph_build_clients(graph, volinfo, set_dict, NULL); - return ret; - } - - if (is_cold_shd) { - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo, - is_hot_tier, volinfo->volname); - if (ret) - goto out; - ret = volgen_graph_build_clients(graph, dup_volinfo, set_dict, NULL); - if (ret) - goto out; - } - if (is_hot_shd) { - is_hot_tier = _gf_true; - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo, - is_hot_tier, volinfo->volname); - if (ret) - goto out; - ret = volgen_graph_build_clients(graph, dup_volinfo, set_dict, NULL); - if (ret) - goto out; - } -out: - if (dup_volinfo) - glusterd_volinfo_delete(dup_volinfo); - return ret; -} - -static int volgen_link_bricks(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *xl_type, char *xl_namefmt, size_t child_count, size_t sub_count, size_t start_count, xlator_t *trav) @@ -3383,13 +3359,22 @@ volgen_link_bricks(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if ((i % sub_count) == 0) { xl = volgen_graph_add_nolink(graph, xl_type, xl_namefmt, volname, j); - if (!xl) { - ret = -1; - goto out; - } j++; } + if (!xl) { + ret = -1; + goto out; + } + + if (strncmp(xl_type, "performance/readdir-ahead", + SLEN("performance/readdir-ahead")) == 0) { + ret = xlator_set_fixed_option(xl, "performance.readdir-ahead", + "on"); + if (ret) + goto out; + } + ret = volgen_xlator_link(xl, trav); if (ret) goto out; @@ -3425,22 +3410,6 @@ volgen_link_bricks_from_list_tail_start(volgen_graph_t *graph, } static int -volgen_link_bricks_from_list_head_start(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, - char *xl_type, char *xl_namefmt, - size_t child_count, size_t sub_count, - size_t start_count) -{ - xlator_t *trav = NULL; - - for (trav = first_of(graph); trav->next; trav = trav->next) - ; - - return volgen_link_bricks(graph, volinfo, xl_type, xl_namefmt, child_count, - sub_count, start_count, trav); -} - -static int volgen_link_bricks_from_list_tail(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *xl_type, char *xl_namefmt, size_t child_count, @@ -3459,21 +3428,6 @@ volgen_link_bricks_from_list_tail(volgen_graph_t *graph, sub_count, 0, trav); } -static int -volgen_link_bricks_from_list_head(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, char *xl_type, - char *xl_namefmt, size_t child_count, - size_t sub_count) -{ - xlator_t *trav = NULL; - - for (trav = first_of(graph); trav->next; trav = trav->next) - ; - - return volgen_link_bricks(graph, volinfo, xl_type, xl_namefmt, child_count, - sub_count, 0, trav); -} - /** * This is the build graph function for user-serviceable snapshots. * Generates snapview-client @@ -3553,7 +3507,7 @@ _xl_is_client_decommissioned(xlator_t *xl, glusterd_volinfo_t *volinfo) char *path = NULL; GF_ASSERT(!strcmp(xl->type, "protocol/client")); - ret = xlator_get_option(xl, "remote-host", &hostname); + ret = xlator_get_fixed_option(xl, "remote-host", &hostname); if (ret) { GF_ASSERT(0); gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_REMOTE_HOST_GET_FAIL, @@ -3562,7 +3516,7 @@ _xl_is_client_decommissioned(xlator_t *xl, glusterd_volinfo_t *volinfo) xl->name); goto out; } - ret = xlator_get_option(xl, "remote-subvolume", &path); + ret = xlator_get_fixed_option(xl, "remote-subvolume", &path); if (ret) { GF_ASSERT(0); gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_REMOTE_HOST_GET_FAIL, @@ -3648,13 +3602,13 @@ volgen_graph_build_readdir_ahead(volgen_graph_t *graph, int32_t clusters = 0; if (graph->type == GF_QUOTAD || graph->type == GF_SNAPD || - !glusterd_volinfo_get_boolean(volinfo, VKEY_PARALLEL_READDIR) || - !glusterd_volinfo_get_boolean(volinfo, VKEY_READDIR_AHEAD)) + !glusterd_volinfo_get_boolean(volinfo, VKEY_PARALLEL_READDIR)) goto out; clusters = volgen_link_bricks_from_list_tail( graph, volinfo, "performance/readdir-ahead", "%s-readdir-ahead-%d", child_count, 1); + out: return clusters; } @@ -3698,19 +3652,14 @@ volgen_graph_build_dht_cluster(volgen_graph_t *graph, if (clusters < 0) goto out; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = 0; - goto out; - } - dht = first_of(graph); ret = _graph_get_decommissioned_children(dht, volinfo, &decommissioned_children); if (ret) goto out; if (decommissioned_children) { - ret = xlator_set_option(dht, "decommissioned-bricks", - decommissioned_children); + ret = xlator_set_fixed_option(dht, "decommissioned-bricks", + decommissioned_children); if (ret) goto out; } @@ -3732,11 +3681,6 @@ volgen_graph_build_ec_clusters(volgen_graph_t *graph, char option[32] = {0}; int start_count = 0; - if (volinfo->tier_info.cur_tier_hot && - volinfo->tier_info.cold_type == GF_CLUSTER_TYPE_DISPERSE) - start_count = volinfo->tier_info.cold_brick_count / - volinfo->tier_info.cold_disperse_count; - clusters = volgen_link_bricks_from_list_tail_start( graph, volinfo, disperse_args[0], disperse_args[1], volinfo->brick_count, volinfo->disperse_count, start_count); @@ -3746,7 +3690,7 @@ volgen_graph_build_ec_clusters(volgen_graph_t *graph, sprintf(option, "%d", volinfo->redundancy_count); ec = first_of(graph); for (i = 0; i < clusters; i++) { - ret = xlator_set_option(ec, "redundancy", option); + ret = xlator_set_fixed_option(ec, "redundancy", option); if (ret) { clusters = -1; goto out; @@ -3767,12 +3711,15 @@ set_afr_pending_xattrs_option(volgen_graph_t *graph, xlator_t *this = NULL; glusterd_conf_t *conf = NULL; glusterd_brickinfo_t *brick = NULL; + glusterd_brickinfo_t *ta_brick = NULL; char *ptr = NULL; int i = 0; int index = -1; int ret = 0; char *afr_xattrs_list = NULL; int list_size = -1; + int ta_brick_index = 0; + int subvol_index = 0; this = THIS; GF_VALIDATE_OR_GOTO("glusterd", this, out); @@ -3811,13 +3758,44 @@ set_afr_pending_xattrs_option(volgen_graph_t *graph, break; strncat(ptr, brick->brick_id, strlen(brick->brick_id)); if (i == volinfo->replica_count) { - ret = xlator_set_option(afr_xlators_list[index++], - "afr-pending-xattr", afr_xattrs_list); + /* add ta client xlator in afr-pending-xattrs before making entries + * for client xlators in volfile. + * ta client xlator indexes are - 2, 5, 8 depending on the index of + * subvol. e.g- For first subvol ta client xlator id is volname-ta-2 + * For pending-xattr, ta name would be + * 'volname-ta-2.{{volume-uuid}}' from GD_OP_VERSION_7_3. + */ + ta_brick_index = 0; + if (volinfo->thin_arbiter_count == 1) { + ptr[strlen(brick->brick_id)] = ','; + cds_list_for_each_entry(ta_brick, &volinfo->ta_bricks, + brick_list) + { + if (ta_brick_index == subvol_index) { + break; + } + ta_brick_index++; + } + if (conf->op_version < GD_OP_VERSION_7_3) { + strncat(ptr, ta_brick->brick_id, + strlen(ta_brick->brick_id)); + } else { + char ta_volname[PATH_MAX] = ""; + int len = snprintf(ta_volname, PATH_MAX, "%s.%s", + ta_brick->brick_id, + uuid_utoa(volinfo->volume_id)); + strncat(ptr, ta_volname, len); + } + } + + ret = xlator_set_fixed_option(afr_xlators_list[index++], + "afr-pending-xattr", afr_xattrs_list); if (ret) goto out; memset(afr_xattrs_list, 0, list_size); ptr = afr_xattrs_list; i = 1; + subvol_index++; continue; } ptr[strlen(brick->brick_id)] = ','; @@ -3832,36 +3810,70 @@ out: } static int +set_volfile_id_option(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, + int clusters) +{ + xlator_t *xlator = NULL; + int i = 0; + int ret = -1; + glusterd_conf_t *conf = NULL; + xlator_t *this = NULL; + + this = THIS; + GF_VALIDATE_OR_GOTO("glusterd", this, out); + conf = this->private; + GF_VALIDATE_OR_GOTO(this->name, conf, out); + + if (conf->op_version < GD_OP_VERSION_9_0) + return 0; + xlator = first_of(graph); + + for (i = 0; i < clusters; i++) { + ret = xlator_set_fixed_option(xlator, "volume-id", + uuid_utoa(volinfo->volume_id)); + if (ret) + goto out; + + xlator = xlator->next; + } + +out: + return ret; +} + +static int volgen_graph_build_afr_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo) { int i = 0; int ret = 0; int clusters = 0; - char *replicate_type = NULL; + char *replicate_type = "cluster/replicate"; char *replicate_name = "%s-replicate-%d"; xlator_t *afr = NULL; char option[32] = {0}; - int start_count = 0; + glusterd_brickinfo_t *ta_brick = NULL; + int ta_brick_index = 0; + int ta_replica_offset = 0; + int ta_brick_offset = 0; + char ta_option[4096] = { + 0, + }; - if (glusterd_volinfo_get_boolean(volinfo, "cluster.jbr") > 0) { - replicate_type = "experimental/jbrc"; - } else { - replicate_type = "cluster/replicate"; + /* In thin-arbiter case brick count and replica count remain same + * but due to additional entries of ta client xlators in the volfile, + * GD1 is manipulated to include these client xlators while linking them to + * afr/cluster entry in the volfile. + */ + if (volinfo->thin_arbiter_count == 1) { + ta_replica_offset = 1; + ta_brick_offset = volinfo->subvol_count; } - if (volinfo->tier_info.cold_type == GF_CLUSTER_TYPE_REPLICATE) - start_count = volinfo->tier_info.cold_brick_count / - volinfo->tier_info.cold_replica_count; - - if (volinfo->tier_info.cur_tier_hot) - clusters = volgen_link_bricks_from_list_head_start( - graph, volinfo, replicate_type, replicate_name, - volinfo->brick_count, volinfo->replica_count, start_count); - else - clusters = volgen_link_bricks_from_list_tail( - graph, volinfo, replicate_type, replicate_name, - volinfo->brick_count, volinfo->replica_count); + clusters = volgen_link_bricks_from_list_tail( + graph, volinfo, replicate_type, replicate_name, + volinfo->brick_count + ta_brick_offset, + volinfo->replica_count + ta_replica_offset); if (clusters < 0) goto out; @@ -3871,18 +3883,50 @@ volgen_graph_build_afr_clusters(volgen_graph_t *graph, clusters = -1; goto out; } - if (!volinfo->arbiter_count) + + ret = set_volfile_id_option(graph, volinfo, clusters); + if (ret) { + clusters = -1; + goto out; + } + + if (!volinfo->arbiter_count && !volinfo->thin_arbiter_count) goto out; afr = first_of(graph); - sprintf(option, "%d", volinfo->arbiter_count); - for (i = 0; i < clusters; i++) { - ret = xlator_set_option(afr, "arbiter-count", option); - if (ret) { - clusters = -1; - goto out; + + if (volinfo->arbiter_count) { + sprintf(option, "%d", volinfo->arbiter_count); + for (i = 0; i < clusters; i++) { + ret = xlator_set_fixed_option(afr, "arbiter-count", option); + if (ret) { + clusters = -1; + goto out; + } + + afr = afr->next; + } + } + + if (volinfo->thin_arbiter_count == 1) { + for (i = 0; i < clusters; i++) { + ta_brick_index = 0; + cds_list_for_each_entry(ta_brick, &volinfo->ta_bricks, brick_list) + { + if (ta_brick_index == i) { + break; + } + ta_brick_index++; + } + snprintf(ta_option, sizeof(ta_option), "%s:%s", ta_brick->hostname, + ta_brick->path); + ret = xlator_set_fixed_option(afr, "thin-arbiter", ta_option); + if (ret) { + clusters = -1; + goto out; + } + afr = afr->next; } - afr = afr->next; } out: return clusters; @@ -3893,15 +3937,9 @@ volume_volgen_graph_build_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, gf_boolean_t is_quotad) { - char *tier_args[] = {"cluster/tier", "%s-tier-%d"}; - char *stripe_args[] = {"cluster/stripe", "%s-stripe-%d"}; - int rclusters = 0; int clusters = 0; int dist_count = 0; int ret = -1; - char tmp_volname[GD_VOLUME_NAME_MAX_TIER] = { - 0, - }; if (!volinfo->dist_leaf_count) goto out; @@ -3916,35 +3954,6 @@ volume_volgen_graph_build_clusters(volgen_graph_t *graph, if (clusters < 0) goto out; break; - case GF_CLUSTER_TYPE_STRIPE: - clusters = volgen_link_bricks_from_list_tail( - graph, volinfo, stripe_args[0], stripe_args[1], - volinfo->brick_count, volinfo->stripe_count); - if (clusters < 0) - goto out; - break; - case GF_CLUSTER_TYPE_TIER: - ret = volgen_link_bricks_from_list_head( - graph, volinfo, tier_args[0], tier_args[1], - volinfo->brick_count, volinfo->replica_count); - break; - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: - /* Replicate after the clients, then stripe */ - if (volinfo->replica_count == 0) - goto out; - clusters = volgen_graph_build_afr_clusters(graph, volinfo); - if (clusters < 0) - goto out; - - rclusters = volinfo->brick_count / volinfo->replica_count; - GF_ASSERT(rclusters == clusters); - clusters = volgen_link_bricks_from_list_tail( - graph, volinfo, stripe_args[0], stripe_args[1], rclusters, - volinfo->stripe_count); - if (clusters < 0) - goto out; - break; - case GF_CLUSTER_TYPE_DISPERSE: clusters = volgen_graph_build_ec_clusters(graph, volinfo); if (clusters < 0) @@ -3964,24 +3973,11 @@ build_distribute: ret = -1; goto out; } - if (volinfo->tier_info.hot_brick_count) { - if (snprintf(tmp_volname, GD_VOLUME_NAME_MAX_TIER, "%s", - volinfo->volname) >= GD_VOLUME_NAME_MAX_TIER) { - ret = -1; - goto out; - } - if (volinfo->tier_info.cur_tier_hot) - strcat(volinfo->volname, "-hot"); - else - strcat(volinfo->volname, "-cold"); - } clusters = volgen_graph_build_readdir_ahead(graph, volinfo, dist_count); if (clusters < 0) goto out; ret = volgen_graph_build_dht_cluster(graph, volinfo, dist_count, is_quotad); - if (volinfo->tier_info.hot_brick_count) - strcpy(volinfo->volname, tmp_volname); if (ret) goto out; @@ -4022,7 +4018,7 @@ client_graph_set_rda_options(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, * glusterd_volinfo_get, so that we consider key value of the in * progress volume set option. */ - ret = dict_get_str(set_dict, VKEY_RDA_CACHE_LIMIT, &rda_cache_s); + ret = dict_get_str_sizen(set_dict, VKEY_RDA_CACHE_LIMIT, &rda_cache_s); if (ret < 0) { ret = glusterd_volinfo_get(volinfo, VKEY_RDA_CACHE_LIMIT, &rda_cache_s); if (ret < 0) @@ -4035,7 +4031,7 @@ client_graph_set_rda_options(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, goto out; } - ret = dict_get_str(set_dict, VKEY_RDA_REQUEST_SIZE, &rda_req_s); + ret = dict_get_str_sizen(set_dict, VKEY_RDA_REQUEST_SIZE, &rda_req_s); if (ret < 0) { ret = glusterd_volinfo_get(volinfo, VKEY_RDA_REQUEST_SIZE, &rda_req_s); if (ret < 0) @@ -4061,7 +4057,7 @@ client_graph_set_rda_options(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, else rda_req_size = new_cache_size; - snprintf(new_req_size_str, sizeof(new_req_size_str), "%ld%s", + snprintf(new_req_size_str, sizeof(new_req_size_str), "%" PRId64 "%s", rda_req_size, "B"); ret = dict_set_dynstr_with_alloc(set_dict, VKEY_RDA_REQUEST_SIZE, new_req_size_str); @@ -4069,7 +4065,7 @@ client_graph_set_rda_options(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, goto out; } - snprintf(new_cache_size_str, sizeof(new_cache_size_str), "%ld%s", + snprintf(new_cache_size_str, sizeof(new_cache_size_str), "%" PRId64 "%s", new_cache_size, "B"); ret = dict_set_dynstr_with_alloc(set_dict, VKEY_RDA_CACHE_LIMIT, new_cache_size_str); @@ -4084,8 +4080,6 @@ static int client_graph_set_perf_options(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict) { - data_t *tmp_data = NULL; - char *volname = NULL; int ret = 0; /* @@ -4114,15 +4108,19 @@ client_graph_set_perf_options(volgen_graph_t *graph, if (ret < 0) return ret; - volname = volinfo->volname; +#ifdef BUILD_GNFS + data_t *tmp_data = NULL; + char *volname = NULL; - tmp_data = dict_get(set_dict, "nfs-volume-file"); - if (!tmp_data) - return volgen_graph_set_options_generic(graph, set_dict, volinfo, - &perfxl_option_handler); - else + tmp_data = dict_get_sizen(set_dict, "nfs-volume-file"); + if (tmp_data) { + volname = volinfo->volname; return volgen_graph_set_options_generic(graph, set_dict, volname, &nfsperfxl_option_handler); + } else +#endif + return volgen_graph_set_options_generic(graph, set_dict, volinfo, + &perfxl_option_handler); } static int @@ -4185,138 +4183,15 @@ graph_set_generic_options(xlator_t *this, volgen_graph_t *graph, gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_GRAPH_SET_OPT_FAIL, "Failed to change " "log-localtime-logging option"); - return 0; -} - -static int -volume_volgen_graph_build_clusters_tier(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, - gf_boolean_t is_quotad) -{ - int ret = -1; - xlator_t *xl, *hxl, *cxl; - char *rule = NULL; - int st_brick_count = 0; - int st_replica_count = 0; - int st_disperse_count = 0; - int st_dist_leaf_count = 0; - int st_type = 0; - int dist_count = 0; - int start_count = 0; - char *decommissioned_children = NULL; - glusterd_volinfo_t *dup_volinfo = NULL; - gf_boolean_t is_hot_tier = _gf_false; - - st_brick_count = volinfo->brick_count; - st_replica_count = volinfo->replica_count; - st_disperse_count = volinfo->disperse_count; - st_type = volinfo->type; - st_dist_leaf_count = volinfo->dist_leaf_count; - - volinfo->dist_leaf_count = volinfo->tier_info.cold_dist_leaf_count; - volinfo->brick_count = volinfo->tier_info.cold_brick_count; - volinfo->replica_count = volinfo->tier_info.cold_replica_count; - volinfo->disperse_count = volinfo->tier_info.cold_disperse_count; - volinfo->redundancy_count = volinfo->tier_info.cold_redundancy_count; - volinfo->type = volinfo->tier_info.cold_type; - volinfo->tier_info.cur_tier_hot = 0; - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo, is_hot_tier, - volinfo->volname); - if (ret) - goto out; - - ret = volume_volgen_graph_build_clusters(graph, dup_volinfo, is_quotad); - if (ret) - goto out; - cxl = first_of(graph); - - volinfo->type = volinfo->tier_info.hot_type; - volinfo->brick_count = volinfo->tier_info.hot_brick_count; - volinfo->replica_count = volinfo->tier_info.hot_replica_count; - volinfo->dist_leaf_count = glusterd_get_dist_leaf_count(volinfo); - volinfo->disperse_count = 0; - volinfo->tier_info.cur_tier_hot = 1; - - dist_count = volinfo->brick_count / volinfo->dist_leaf_count; - - if (volinfo->tier_info.cold_type == GF_CLUSTER_TYPE_REPLICATE) { - start_count = volinfo->tier_info.cold_brick_count / - volinfo->tier_info.cold_replica_count; - } - if (volinfo->dist_leaf_count != 1) { - ret = volgen_link_bricks_from_list_head_start( - graph, volinfo, "cluster/replicate", "%s-replicate-%d", - volinfo->brick_count, volinfo->replica_count, start_count); - if (ret != -1) { - ret = set_afr_pending_xattrs_option(graph, volinfo, ret); - if (ret) - goto out; - volgen_link_bricks_from_list_tail( - graph, volinfo, "cluster/distribute", "%s-hot-dht", dist_count, - dist_count); - } - } else { - ret = volgen_link_bricks_from_list_head( - graph, volinfo, "cluster/distribute", "%s-hot-dht", dist_count, - dist_count); - } - if (ret == -1) - goto out; - - hxl = first_of(graph); - - volinfo->type = GF_CLUSTER_TYPE_TIER; - if (!is_quotad) { - xl = volgen_graph_add_nolink(graph, "cluster/tier", "%s-%s", - volinfo->volname, "tier-dht"); - } else { - xl = volgen_graph_add_nolink(graph, "cluster/tier", "%s", - volinfo->volname); - } - if (!xl) - goto out; - - gf_asprintf(&rule, "%s-hot-dht", volinfo->volname); - - ret = xlator_set_option(xl, "rule", rule); - if (ret) - goto out; - - /*Each dht/tier layer must have a different xattr name*/ - ret = xlator_set_option(xl, "xattr-name", "trusted.tier.tier-dht"); - if (ret) - goto out; - - ret = volgen_xlator_link(xl, cxl); - ret = volgen_xlator_link(xl, hxl); - - st_type = GF_CLUSTER_TYPE_TIER; + ret = volgen_graph_set_options_generic(graph, set_dict, "client", + &threads_option_handler); - ret = _graph_get_decommissioned_children(xl, volinfo, - &decommissioned_children); if (ret) - goto out; - if (decommissioned_children) { - ret = xlator_set_option(xl, "decommissioned-bricks", - decommissioned_children); - if (ret) - goto out; - } + gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_GRAPH_SET_OPT_FAIL, + "changing %s threads failed", identifier); -out: - volinfo->brick_count = st_brick_count; - volinfo->replica_count = st_replica_count; - volinfo->disperse_count = st_disperse_count; - volinfo->type = st_type; - volinfo->dist_leaf_count = st_dist_leaf_count; - volinfo->tier_info.cur_tier_hot = 0; - - if (dup_volinfo) - glusterd_volinfo_delete(dup_volinfo); - GF_FREE(rule); - GF_FREE(decommissioned_children); - return ret; + return 0; } static int @@ -4350,9 +4225,6 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret) goto out; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) - ret = volume_volgen_graph_build_clusters_tier(graph, volinfo, - _gf_false); else ret = volume_volgen_graph_build_clusters(graph, volinfo, _gf_false); @@ -4371,23 +4243,38 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, "tcp", set_dict); } - ret = dict_get_str_boolean(set_dict, "features.shard", _gf_false); + ret = dict_get_str_boolean(set_dict, "features.cloudsync", _gf_false); if (ret == -1) goto out; if (ret) { - xl = volgen_graph_add(graph, "features/shard", volname); + xl = volgen_graph_add(graph, "features/cloudsync", volname); if (!xl) { ret = -1; goto out; } } - ret = dict_get_str_boolean(set_dict, "features.utime", _gf_false); + ret = dict_get_str_boolean(set_dict, "features.shard", _gf_false); if (ret == -1) goto out; if (ret) { + xl = volgen_graph_add(graph, "features/shard", volname); + if (!xl) { + ret = -1; + goto out; + } + } + /* a. ret will be -1 if features.ctime is not set in the volinfo->dict which + * means ctime should be loaded into the graph. + * b. ret will be 1 if features.ctime is explicitly turned on through + * volume set and in that case ctime should be loaded into the graph. + * c. ret will be 0 if features.ctime is explicitly turned off and in that + * case ctime shouldn't be loaded into the graph. + */ + ret = dict_get_str_boolean(set_dict, "features.ctime", -1); + if (conf->op_version >= GD_OP_VERSION_5_0 && ret) { xl = volgen_graph_add(graph, "features/utime", volname); if (!xl) { ret = -1; @@ -4409,7 +4296,7 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = -1; goto out; } - ret = xlator_set_option(xl, "read-only", "on"); + ret = xlator_set_fixed_option(xl, "read-only", "on"); if (ret) goto out; } @@ -4425,22 +4312,11 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = -1; goto out; } - ret = xlator_set_option(xl, "mode", "client"); + ret = xlator_set_fixed_option(xl, "mode", "client"); if (ret) goto out; } - ret = dict_get_str_boolean(set_dict, "features.encryption", _gf_false); - if (ret == -1) - goto out; - if (ret) { - xl = volgen_graph_add(graph, "encryption/crypt", volname); - if (!xl) { - ret = -1; - goto out; - } - } - /* gfproxy needs the quiesce translator */ if (gfproxy_clnt) { xl = volgen_graph_add(graph, "features/quiesce", volname); @@ -4466,9 +4342,9 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, /* Do not allow changing read-after-open option if root-squash is enabled. */ - ret = dict_get_str(set_dict, "performance.read-after-open", &tmp); + ret = dict_get_str_sizen(set_dict, "performance.read-after-open", &tmp); if (!ret) { - ret = dict_get_str(volinfo->dict, "server.root-squash", &tmp); + ret = dict_get_str_sizen(volinfo->dict, "server.root-squash", &tmp); if (!ret) { ob = _gf_false; ret = gf_string2boolean(tmp, &ob); @@ -4491,15 +4367,15 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, root-squash is enabled, open-behind's option to read after open is done is also enabled. */ - ret = dict_get_str(set_dict, "server.root-squash", &tmp); + ret = dict_get_str_sizen(set_dict, "server.root-squash", &tmp); if (!ret) { ret = gf_string2boolean(tmp, &var); if (ret) goto out; if (var) { - ret = dict_get_str(volinfo->dict, "performance.read-after-open", - &tmp); + ret = dict_get_str_sizen(volinfo->dict, + "performance.read-after-open", &tmp); if (!ret) { ret = gf_string2boolean(tmp, &ob); /* go ahead with turning read-after-open on @@ -4507,11 +4383,11 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, OR if read-after-open option is turned off */ if (ret || !ob) - ret = dict_set_str(set_dict, "performance.read-after-open", - "yes"); + ret = dict_set_sizen_str_sizen( + set_dict, "performance.read-after-open", "yes"); } else { - ret = dict_set_str(set_dict, "performance.read-after-open", - "yes"); + ret = dict_set_sizen_str_sizen( + set_dict, "performance.read-after-open", "yes"); } } else { /* When root-squash has to be turned off, open-behind's @@ -4521,14 +4397,14 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, option was not set before turning on root-squash. */ ob = _gf_false; - ret = dict_get_str(volinfo->dict, "performance.read-after-open", - &tmp); + ret = dict_get_str_sizen(volinfo->dict, + "performance.read-after-open", &tmp); if (!ret) { ret = gf_string2boolean(tmp, &ob); if (!ret && ob) { - ret = dict_set_str(set_dict, "performance.read-after-open", - "yes"); + ret = dict_set_sizen_str_sizen( + set_dict, "performance.read-after-open", "yes"); } } /* consider operation is failure only if read-after-open @@ -4548,8 +4424,8 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = dict_get_str_boolean(set_dict, "server.manage-gids", _gf_false); if (ret != -1) { - ret = dict_set_str(set_dict, "client.send-gids", - ret ? "false" : "true"); + ret = dict_set_str_sizen(set_dict, "client.send-gids", + ret ? "false" : "true"); if (ret) gf_msg(THIS->name, GF_LOG_WARNING, errno, GD_MSG_DICT_SET_FAILED, "changing client" @@ -4575,22 +4451,21 @@ client_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret) return -1; - ret = dict_get_str_boolean(set_dict, "features.cloudsync", _gf_false); - if (ret == -1) - goto out; - - if (ret) { - xl = volgen_graph_add(graph, "features/cloudsync", volname); - if (!xl) { - ret = -1; - goto out; - } + /* if the client is part of 'gfproxyd' server, then we need to keep the + volume name as 'gfproxyd-<volname>', for better portmapper options */ + subvol = volname; + ret = dict_get_str_boolean(set_dict, "gfproxy-server", 0); + if (ret > 0) { + namelen = strlen(volinfo->volname) + SLEN("gfproxyd-") + 1; + subvol = alloca(namelen); + snprintf(subvol, namelen, "gfproxyd-%s", volname); } ret = -1; - xl = volgen_graph_add_as(graph, "debug/io-stats", volname); - if (!xl) + xl = volgen_graph_add_as(graph, "debug/io-stats", subvol); + if (!xl) { goto out; + } ret = graph_set_generic_options(this, graph, set_dict, "client"); out: @@ -4621,18 +4496,18 @@ bitrot_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, void *param) { xlator_t *xl = NULL; - char *bitrot_option = NULL; int ret = 0; xl = first_of(graph); if (!strcmp(vme->option, "expiry-time")) { - ret = gf_asprintf(&bitrot_option, "expiry-time"); - if (ret != -1) { - ret = xlator_set_option(xl, bitrot_option, vme->value); - GF_FREE(bitrot_option); - } + ret = xlator_set_fixed_option(xl, "expiry-time", vme->value); + if (ret) + return -1; + } + if (!strcmp(vme->option, "signer-threads")) { + ret = xlator_set_fixed_option(xl, "signer-threads", vme->value); if (ret) return -1; } @@ -4645,41 +4520,25 @@ scrubber_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, void *param) { xlator_t *xl = NULL; - char *scrub_option = NULL; int ret = 0; xl = first_of(graph); if (!strcmp(vme->option, "scrub-throttle")) { - ret = gf_asprintf(&scrub_option, "scrub-throttle"); - if (ret != -1) { - ret = xlator_set_option(xl, scrub_option, vme->value); - GF_FREE(scrub_option); - } - + ret = xlator_set_fixed_option(xl, "scrub-throttle", vme->value); if (ret) return -1; } if (!strcmp(vme->option, "scrub-frequency")) { - ret = gf_asprintf(&scrub_option, "scrub-freq"); - if (ret != -1) { - ret = xlator_set_option(xl, scrub_option, vme->value); - GF_FREE(scrub_option); - } - + ret = xlator_set_fixed_option(xl, "scrub-freq", vme->value); if (ret) return -1; } if (!strcmp(vme->option, "scrubber")) { if (!strcmp(vme->value, "pause")) { - ret = gf_asprintf(&scrub_option, "scrub-state"); - if (ret != -1) { - ret = xlator_set_option(xl, scrub_option, vme->value); - GF_FREE(scrub_option); - } - + ret = xlator_set_fixed_option(xl, "scrub-state", vme->value); if (ret) return -1; } @@ -4709,157 +4568,92 @@ out: return ret; } +#ifdef BUILD_GNFS static int nfs_option_handler(volgen_graph_t *graph, struct volopt_map_entry *vme, void *param) { + static struct nfs_opt nfs_opts[] = { + /* {pattern, printf_pattern} */ + {"!rpc-auth.addr.*.allow", "rpc-auth.addr.%s.allow"}, + {"!rpc-auth.addr.*.reject", "rpc-auth.addr.%s.reject"}, + {"!rpc-auth.auth-unix.*", "rpc-auth.auth-unix.%s"}, + {"!rpc-auth.auth-null.*", "rpc-auth.auth-null.%s"}, + {"!nfs3.*.trusted-sync", "nfs3.%s.trusted-sync"}, + {"!nfs3.*.trusted-write", "nfs3.%s.trusted-write"}, + {"!nfs3.*.volume-access", "nfs3.%s.volume-access"}, + {"!rpc-auth.ports.*.insecure", "rpc-auth.ports.%s.insecure"}, + {"!nfs-disable", "nfs.%s.disable"}, + {NULL, NULL}}; xlator_t *xl = NULL; char *aa = NULL; int ret = 0; glusterd_volinfo_t *volinfo = NULL; + int keylen; + struct nfs_opt *opt = NULL; volinfo = param; - xl = first_of(graph); - - if (!volinfo || (volinfo->volname[0] == '\0')) - return 0; - - if (!vme || !(vme->option)) + if (!volinfo || (volinfo->volname[0] == '\0')) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); return 0; - - if (!strcmp(vme->option, "!rpc-auth.addr.*.allow")) { - ret = gf_asprintf(&aa, "rpc-auth.addr.%s.allow", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } - - if (ret) - return -1; - } - - if (!strcmp(vme->option, "!rpc-auth.addr.*.reject")) { - ret = gf_asprintf(&aa, "rpc-auth.addr.%s.reject", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } - - if (ret) - return -1; - } - - if (!strcmp(vme->option, "!rpc-auth.auth-unix.*")) { - ret = gf_asprintf(&aa, "rpc-auth.auth-unix.%s", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } - - if (ret) - return -1; - } - if (!strcmp(vme->option, "!rpc-auth.auth-null.*")) { - ret = gf_asprintf(&aa, "rpc-auth.auth-null.%s", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } - - if (ret) - return -1; } - if (!strcmp(vme->option, "!nfs3.*.trusted-sync")) { - ret = gf_asprintf(&aa, "nfs3.%s.trusted-sync", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } - - if (ret) - return -1; + if (!vme || !(vme->option)) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); + return 0; } - if (!strcmp(vme->option, "!nfs3.*.trusted-write")) { - ret = gf_asprintf(&aa, "nfs3.%s.trusted-write", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } + xl = first_of(graph); - if (ret) - return -1; - } + for (opt = nfs_opts; opt->pattern; opt++) { + if (!strcmp(vme->option, opt->pattern)) { + keylen = gf_asprintf(&aa, opt->printf_pattern, volinfo->volname); - if (!strcmp(vme->option, "!nfs3.*.volume-access")) { - ret = gf_asprintf(&aa, "nfs3.%s.volume-access", volinfo->volname); + if (keylen == -1) { + return -1; + } - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); + ret = xlator_set_option(xl, aa, keylen, vme->value); GF_FREE(aa); - } - if (ret) - return -1; - } - - if (!strcmp(vme->option, "!nfs3.*.export-dir")) { - ret = gf_asprintf(&aa, "nfs3.%s.export-dir", volinfo->volname); - - if (ret != -1) { - ret = gf_canonicalize_path(vme->value); if (ret) return -1; - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); + goto out; } - - if (ret) - return -1; } - if (!strcmp(vme->option, "!rpc-auth.ports.*.insecure")) { - ret = gf_asprintf(&aa, "rpc-auth.ports.%s.insecure", volinfo->volname); - - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); - GF_FREE(aa); - } + if (!strcmp(vme->option, "!nfs3.*.export-dir")) { + keylen = gf_asprintf(&aa, "nfs3.%s.export-dir", volinfo->volname); - if (ret) + if (keylen == -1) { return -1; - } - - if (!strcmp(vme->option, "!nfs-disable")) { - ret = gf_asprintf(&aa, "nfs.%s.disable", volinfo->volname); + } - if (ret != -1) { - ret = xlator_set_option(xl, aa, vme->value); + ret = gf_canonicalize_path(vme->value); + if (ret) { GF_FREE(aa); + return -1; } + ret = xlator_set_option(xl, aa, keylen, vme->value); + GF_FREE(aa); if (ret) return -1; - } - - if ((strcmp(vme->voltype, "nfs/server") == 0) && (vme->option[0] != '!')) { - ret = xlator_set_option(xl, vme->option, vme->value); + } else if ((strcmp(vme->voltype, "nfs/server") == 0) && + (vme->option[0] != '!')) { + ret = xlator_set_option(xl, vme->option, strlen(vme->option), + vme->value); if (ret) return -1; } +out: return 0; } +#endif char * volgen_get_shd_key(int type) { @@ -4867,7 +4661,6 @@ volgen_get_shd_key(int type) switch (type) { case GF_CLUSTER_TYPE_REPLICATE: - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: key = "cluster.self-heal-daemon"; break; case GF_CLUSTER_TYPE_DISPERSE: @@ -4881,6 +4674,27 @@ volgen_get_shd_key(int type) return key; } +static int +volgen_set_shd_key_enable(dict_t *set_dict, const int type) +{ + int ret = 0; + + switch (type) { + case GF_CLUSTER_TYPE_REPLICATE: + ret = dict_set_sizen_str_sizen(set_dict, "cluster.self-heal-daemon", + "enable"); + break; + case GF_CLUSTER_TYPE_DISPERSE: + ret = dict_set_sizen_str_sizen( + set_dict, "cluster.disperse-self-heal-daemon", "enable"); + break; + default: + break; + } + + return ret; +} + static gf_boolean_t volgen_is_shd_compatible_xl(char *xl_type) { @@ -4901,7 +4715,7 @@ volgen_graph_set_iam_shd(volgen_graph_t *graph) if (!volgen_is_shd_compatible_xl(trav->type)) continue; - ret = xlator_set_option(trav, "iam-self-heal-daemon", "yes"); + ret = xlator_set_fixed_option(trav, "iam-self-heal-daemon", "yes"); if (ret) break; } @@ -4909,54 +4723,21 @@ volgen_graph_set_iam_shd(volgen_graph_t *graph) } static int -glusterd_prepare_shd_volume_options_for_tier(glusterd_volinfo_t *volinfo, - dict_t *set_dict) -{ - int ret = -1; - char *key = NULL; - - key = volgen_get_shd_key(volinfo->tier_info.cold_type); - if (key) { - ret = dict_set_str(set_dict, key, "enable"); - if (ret) - goto out; - } - - key = volgen_get_shd_key(volinfo->tier_info.hot_type); - if (key) { - ret = dict_set_str(set_dict, key, "enable"); - if (ret) - goto out; - } -out: - return ret; -} - -static int prepare_shd_volume_options(glusterd_volinfo_t *volinfo, dict_t *mod_dict, dict_t *set_dict) { - char *key = NULL; int ret = 0; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = glusterd_prepare_shd_volume_options_for_tier(volinfo, set_dict); - if (ret) - goto out; - } else { - key = volgen_get_shd_key(volinfo->type); - if (!key) { - ret = -1; - goto out; - } - ret = dict_set_str(set_dict, key, "enable"); - if (ret) - goto out; - } + ret = volgen_set_shd_key_enable(set_dict, volinfo->type); + if (ret) + goto out; ret = dict_set_uint32(set_dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret) + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } dict_copy(volinfo->dict, set_dict); if (mod_dict) @@ -4971,7 +4752,6 @@ build_afr_ec_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo) int clusters = -1; switch (volinfo->type) { case GF_CLUSTER_TYPE_REPLICATE: - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: clusters = volgen_graph_build_afr_clusters(graph, volinfo); break; @@ -4983,70 +4763,17 @@ build_afr_ec_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo) } static int -build_afr_ec_clusters_for_tier(volgen_graph_t *graph, - glusterd_volinfo_t *volinfo, dict_t *set_dict) -{ - int ret = 0; - glusterd_volinfo_t *dup_volinfo[2] = {NULL, NULL}; - int clusters = 0; - int i = 0; - gf_boolean_t is_hot_tier = _gf_false; - - if (glusterd_is_shd_compatible_type(volinfo->tier_info.cold_type)) { - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo[0], - is_hot_tier, volinfo->volname); - if (ret) - goto out; - } - if (glusterd_is_shd_compatible_type(volinfo->tier_info.hot_type)) { - is_hot_tier = _gf_true; - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo[1], - is_hot_tier, volinfo->volname); - if (ret) - goto out; - dup_volinfo[1]->tier_info.cur_tier_hot = 1; - } - - for (i = 0; i < 2; i++) { - if (!dup_volinfo[i]) - continue; - ret = build_afr_ec_clusters(graph, dup_volinfo[i]); - if (ret < 0) - goto out; - clusters += ret; - } - ret = 0; -out: - for (i = 0; i < 2; i++) { - if (dup_volinfo[i]) - glusterd_volinfo_delete(dup_volinfo[i]); - } - - if (ret) - clusters = -1; - - return clusters; -} - -static int build_shd_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict) { int ret = 0; int clusters = -1; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = volgen_graph_build_clients_for_tier_shd(graph, volinfo, set_dict); - if (ret) - goto out; + ret = volgen_graph_build_clients(graph, volinfo, set_dict, NULL); + if (ret) + goto out; + clusters = build_afr_ec_clusters(graph, volinfo); - clusters = build_afr_ec_clusters_for_tier(graph, volinfo, set_dict); - } else { - ret = volgen_graph_build_clients(graph, volinfo, set_dict, NULL); - if (ret) - goto out; - clusters = build_afr_ec_clusters(graph, volinfo); - } out: return clusters; } @@ -5061,21 +4788,10 @@ gd_is_self_heal_enabled(glusterd_volinfo_t *volinfo, dict_t *dict) switch (volinfo->type) { case GF_CLUSTER_TYPE_REPLICATE: - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: case GF_CLUSTER_TYPE_DISPERSE: shd_key = volgen_get_shd_key(volinfo->type); shd_enabled = dict_get_str_boolean(dict, shd_key, _gf_true); break; - case GF_CLUSTER_TYPE_TIER: - shd_key = volgen_get_shd_key(volinfo->tier_info.cold_type); - if (shd_key) - shd_enabled = dict_get_str_boolean(dict, shd_key, _gf_true); - - shd_key = volgen_get_shd_key(volinfo->tier_info.hot_type); - if (shd_key) - shd_enabled |= dict_get_str_boolean(dict, shd_key, _gf_true); - - break; default: break; } @@ -5126,12 +4842,7 @@ build_rebalance_volfile(glusterd_volinfo_t *volinfo, char *filepath, if (ret) goto out; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) - ret = volume_volgen_graph_build_clusters_tier(&graph, volinfo, - _gf_false); - else - ret = volume_volgen_graph_build_clusters(&graph, volinfo, _gf_false); - + ret = volume_volgen_graph_build_clusters(&graph, volinfo, _gf_false); if (ret) goto out; @@ -5162,24 +4873,15 @@ out: static int build_shd_volume_graph(xlator_t *this, volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *mod_dict, - dict_t *set_dict, gf_boolean_t graph_check, - gf_boolean_t *valid_config) + dict_t *set_dict, gf_boolean_t graph_check) { volgen_graph_t cgraph = {0}; int ret = 0; int clusters = -1; - if (!graph_check && (volinfo->status != GLUSTERD_STATUS_STARTED)) - goto out; - if (!glusterd_is_shd_compatible_volume(volinfo)) goto out; - /* Shd graph is valid only when there is at least one - * replica/disperse volume is present - */ - *valid_config = _gf_true; - ret = prepare_shd_volume_options(volinfo, mod_dict, set_dict); if (ret) goto out; @@ -5209,51 +4911,43 @@ out: } int -build_shd_graph(volgen_graph_t *graph, dict_t *mod_dict) +build_shd_graph(glusterd_volinfo_t *volinfo, volgen_graph_t *graph, + dict_t *mod_dict) { - glusterd_volinfo_t *voliter = NULL; xlator_t *this = NULL; - glusterd_conf_t *priv = NULL; dict_t *set_dict = NULL; int ret = 0; - gf_boolean_t valid_config = _gf_false; xlator_t *iostxl = NULL; gf_boolean_t graph_check = _gf_false; this = THIS; - priv = this->private; set_dict = dict_new(); if (!set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); ret = -ENOMEM; goto out; } if (mod_dict) graph_check = dict_get_str_boolean(mod_dict, "graph-check", 0); - iostxl = volgen_graph_add_as(graph, "debug/io-stats", "glustershd"); + iostxl = volgen_graph_add_as(graph, "debug/io-stats", volinfo->volname); if (!iostxl) { ret = -1; goto out; } - cds_list_for_each_entry(voliter, &priv->volumes, vol_list) - { - ret = build_shd_volume_graph(this, graph, voliter, mod_dict, set_dict, - graph_check, &valid_config); - ret = dict_reset(set_dict); - if (ret) - goto out; - } + ret = build_shd_volume_graph(this, graph, volinfo, mod_dict, set_dict, + graph_check); out: if (set_dict) dict_unref(set_dict); - if (!valid_config) - ret = -EINVAL; return ret; } +#ifdef BUILD_GNFS + static int volgen_graph_set_iam_nfsd(const volgen_graph_t *graph) { @@ -5264,7 +4958,7 @@ volgen_graph_set_iam_nfsd(const volgen_graph_t *graph) if (strcmp(trav->type, "cluster/replicate") != 0) continue; - ret = xlator_set_option(trav, "iam-nfs-daemon", "yes"); + ret = xlator_set_fixed_option(trav, "iam-nfs-daemon", "yes"); if (ret) break; } @@ -5308,15 +5002,15 @@ build_nfs_graph(volgen_graph_t *graph, dict_t *mod_dict) ret = -1; goto out; } - ret = xlator_set_option(nfsxl, "nfs.dynamic-volumes", "on"); + ret = xlator_set_fixed_option(nfsxl, "nfs.dynamic-volumes", "on"); if (ret) goto out; - ret = xlator_set_option(nfsxl, "nfs.nlm", "on"); + ret = xlator_set_fixed_option(nfsxl, "nfs.nlm", "on"); if (ret) goto out; - ret = xlator_set_option(nfsxl, "nfs.drc", "off"); + ret = xlator_set_fixed_option(nfsxl, "nfs.drc", "off"); if (ret) goto out; @@ -5334,7 +5028,7 @@ build_nfs_graph(volgen_graph_t *graph, dict_t *mod_dict) "Out of memory"); goto out; } - ret = xlator_set_option(nfsxl, skey, "*"); + ret = xlator_set_option(nfsxl, skey, ret, "*"); GF_FREE(skey); if (ret) goto out; @@ -5345,7 +5039,8 @@ build_nfs_graph(volgen_graph_t *graph, dict_t *mod_dict) "Out of memory"); goto out; } - ret = xlator_set_option(nfsxl, skey, uuid_utoa(voliter->volume_id)); + ret = xlator_set_option(nfsxl, skey, ret, + uuid_utoa(voliter->volume_id)); GF_FREE(skey); if (ret) goto out; @@ -5366,27 +5061,44 @@ build_nfs_graph(volgen_graph_t *graph, dict_t *mod_dict) else get_transport_type(voliter, voliter->dict, nfs_xprt, _gf_true); - ret = dict_set_str(set_dict, "performance.stat-prefetch", "off"); - if (ret) + ret = dict_set_sizen_str_sizen(set_dict, "performance.stat-prefetch", + "off"); + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=performance.stat-prefetch", NULL); goto out; + } - ret = dict_set_str(set_dict, "performance.client-io-threads", "off"); - if (ret) + ret = dict_set_sizen_str_sizen(set_dict, + "performance.client-io-threads", "off"); + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=performance.client-io-threads", NULL); goto out; + } - ret = dict_set_str(set_dict, "client-transport-type", nfs_xprt); - if (ret) + ret = dict_set_str_sizen(set_dict, "client-transport-type", nfs_xprt); + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=client-transport-type", NULL); goto out; + } ret = dict_set_uint32(set_dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret) + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } - ret = dict_set_str(set_dict, "nfs-volume-file", "yes"); - if (ret) + ret = dict_set_sizen_str_sizen(set_dict, "nfs-volume-file", "yes"); + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=nfs-volume-file", NULL); goto out; + } - if (mod_dict && (data = dict_get(mod_dict, "volume-name"))) { + if (mod_dict && (data = dict_get_sizen(mod_dict, "volume-name"))) { volname = data->data; if (strcmp(volname, voliter->volname) == 0) dict_copy(mod_dict, set_dict); @@ -5443,7 +5155,7 @@ out: return ret; } - +#endif /**************************** * * Volume generation interface @@ -5509,7 +5221,7 @@ glusterd_is_valid_volfpath(char *volname, char *brick) ret = 0; goto out; } - strncpy(volinfo->volname, volname, strlen(volname)); + (void)snprintf(volinfo->volname, sizeof(volinfo->volname), "%s", volname); get_brick_filepath(volfpath, volinfo, brickinfo, NULL); ret = ((strlen(volfpath) < PATH_MAX) && @@ -5626,8 +5338,11 @@ build_quotad_graph(volgen_graph_t *graph, dict_t *mod_dict) continue; ret = dict_set_uint32(set_dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } dict_copy(voliter->dict, set_dict); if (mod_dict) @@ -5639,7 +5354,7 @@ build_quotad_graph(volgen_graph_t *graph, dict_t *mod_dict) "Out of memory"); goto out; } - ret = xlator_set_option(quotad_xl, skey, voliter->volname); + ret = xlator_set_option(quotad_xl, skey, ret, voliter->volname); GF_FREE(skey); if (ret) goto out; @@ -5649,12 +5364,7 @@ build_quotad_graph(volgen_graph_t *graph, dict_t *mod_dict) if (ret) goto out; - if (voliter->type == GF_CLUSTER_TYPE_TIER) - ret = volume_volgen_graph_build_clusters_tier(&cgraph, voliter, - _gf_true); - else - ret = volume_volgen_graph_build_clusters(&cgraph, voliter, - _gf_true); + ret = volume_volgen_graph_build_clusters(&cgraph, voliter, _gf_true); if (ret) { ret = -1; goto out; @@ -5716,23 +5426,6 @@ get_parent_vol_tstamp_file(char *filename, glusterd_volinfo_t *volinfo) } } -void -assign_jbr_uuids(glusterd_volinfo_t *volinfo) -{ - glusterd_brickinfo_t *brickinfo = NULL; - int in_group = 0; - uuid_t tmp_uuid; - - list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) - { - if (in_group == 0) - gf_uuid_generate(tmp_uuid); - gf_uuid_copy(brickinfo->jbr_uuid, tmp_uuid); - if (++in_group >= volinfo->replica_count) - in_group = 0; - } -} - int generate_brick_volfiles(glusterd_volinfo_t *volinfo) { @@ -5800,10 +5493,6 @@ generate_brick_volfiles(glusterd_volinfo_t *volinfo) } } - if (glusterd_volinfo_get_boolean(volinfo, "cluster.jbr") > 0) { - assign_jbr_uuids(volinfo); - } - ret = glusterd_volume_brick_for_each(volinfo, NULL, glusterd_generate_brick_volfile); if (ret) @@ -5849,16 +5538,23 @@ glusterd_generate_client_per_brick_volfile(glusterd_volinfo_t *volinfo) int ret = -1; char *ssl_str = NULL; gf_boolean_t ssl_bool = _gf_false; + xlator_t *this = THIS; + GF_ASSERT(this); dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto out; + } ret = dict_set_uint32(dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto free_dict; + } - if (dict_get_str(volinfo->dict, "client.ssl", &ssl_str) == 0) { + if (dict_get_str_sizen(volinfo->dict, "client.ssl", &ssl_str) == 0) { if (gf_string2boolean(ssl_str, &ssl_bool) == 0) { if (ssl_bool) { if (dict_set_dynstr_with_alloc(dict, "client.ssl", "on") != 0) { @@ -5938,17 +5634,25 @@ generate_dummy_client_volfiles(glusterd_volinfo_t *volinfo) enumerate_transport_reqs(volinfo->transport_type, types); dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto out; + } for (i = 0; types[i]; i++) { ret = dict_set_str(dict, "client-transport-type", types[i]); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=client-transport-type", NULL); goto out; + } type = transport_str_to_type(types[i]); ret = dict_set_uint32(dict, "trusted-client", GF_CLIENT_OTHER); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } ret = glusterd_get_dummy_client_filepath(filepath, volinfo, type); if (ret) { @@ -6009,24 +5713,31 @@ generate_client_volfiles(glusterd_volinfo_t *volinfo, enumerate_transport_reqs(volinfo->transport_type, types); dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto out; + } for (i = 0; types[i]; i++) { ret = dict_set_str(dict, "client-transport-type", types[i]); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=client-transport-type", NULL); goto out; + } type = transport_str_to_type(types[i]); ret = dict_set_uint32(dict, "trusted-client", client_type); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } if (client_type == GF_CLIENT_TRUSTED) { ret = glusterd_get_trusted_client_filepath(filepath, volinfo, type); } else if (client_type == GF_CLIENT_TRUSTED_PROXY) { glusterd_get_gfproxy_client_volfile(volinfo, filepath, PATH_MAX); - ret = dict_set_int32n(dict, "gfproxy-client", - SLEN("gfproxy-client"), 1); + ret = dict_set_int32_sizen(dict, "gfproxy-client", 1); } else { ret = glusterd_get_client_filepath(filepath, volinfo, type); } @@ -6073,7 +5784,6 @@ glusterd_snapdsvc_generate_volfile(volgen_graph_t *graph, dict_t *set_dict = NULL; char *loglevel = NULL; char *xlator = NULL; - char auth_path[] = "auth-path"; char *ssl_str = NULL; gf_boolean_t ssl_bool = _gf_false; @@ -6081,9 +5791,9 @@ glusterd_snapdsvc_generate_volfile(volgen_graph_t *graph, if (!set_dict) return -1; - ret = dict_get_str(set_dict, "xlator", &xlator); + ret = dict_get_str_sizen(set_dict, "xlator", &xlator); if (!ret) { - ret = dict_get_str(set_dict, "loglevel", &loglevel); + ret = dict_get_str_sizen(set_dict, "loglevel", &loglevel); if (ret) { gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "could not get both" @@ -6097,7 +5807,7 @@ glusterd_snapdsvc_generate_volfile(volgen_graph_t *graph, if (!xl) return -1; - ret = xlator_set_option(xl, "volname", volinfo->volname); + ret = xlator_set_fixed_option(xl, "volname", volinfo->volname); if (ret) return -1; @@ -6114,15 +5824,15 @@ glusterd_snapdsvc_generate_volfile(volgen_graph_t *graph, if (!xl) return -1; - ret = xlator_set_option(xl, "transport-type", "tcp"); + ret = xlator_set_fixed_option(xl, "transport-type", "tcp"); if (ret) return -1; - if (dict_get_str(set_dict, "server.ssl", &ssl_str) == 0) { + if (dict_get_str_sizen(set_dict, "server.ssl", &ssl_str) == 0) { if (gf_string2boolean(ssl_str, &ssl_bool) == 0) { if (ssl_bool) { - ret = xlator_set_option(xl, "transport.socket.ssl-enabled", - "true"); + ret = xlator_set_fixed_option( + xl, "transport.socket.ssl-enabled", "true"); if (ret) { return -1; } @@ -6142,18 +5852,19 @@ glusterd_snapdsvc_generate_volfile(volgen_graph_t *graph, username = glusterd_auth_get_username(volinfo); passwd = glusterd_auth_get_password(volinfo); - snprintf(key, sizeof(key), "auth.login.snapd-%s.allow", volinfo->volname); - ret = xlator_set_option(xl, key, username); + ret = snprintf(key, sizeof(key), "auth.login.snapd-%s.allow", + volinfo->volname); + ret = xlator_set_option(xl, key, ret, username); if (ret) return -1; - snprintf(key, sizeof(key), "auth.login.%s.password", username); - ret = xlator_set_option(xl, key, passwd); + ret = snprintf(key, sizeof(key), "auth.login.%s.password", username); + ret = xlator_set_option(xl, key, ret, passwd); if (ret) return -1; snprintf(key, sizeof(key), "snapd-%s", volinfo->volname); - ret = xlator_set_option(xl, auth_path, key); + ret = xlator_set_fixed_option(xl, "auth-path", key); if (ret) return -1; @@ -6170,10 +5881,15 @@ prepare_bitrot_scrub_volume_options(glusterd_volinfo_t *volinfo, dict_t *mod_dict, dict_t *set_dict) { int ret = 0; + xlator_t *this = THIS; + GF_ASSERT(this); ret = dict_set_uint32(set_dict, "trusted-client", GF_CLIENT_TRUSTED); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=trusted-client", NULL); goto out; + } dict_copy(volinfo->dict, set_dict); if (mod_dict) @@ -6204,7 +5920,7 @@ build_bitd_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret < 0) goto out; - ret = xlator_set_option(xl, "brick-count", brick_hint); + ret = xlator_set_fixed_option(xl, "brick-count", brick_hint); if (ret) goto out; @@ -6241,6 +5957,7 @@ build_bitd_volume_graph(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, set_dict = dict_new(); if (!set_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); ret = -1; goto out; } @@ -6251,7 +5968,7 @@ build_bitd_volume_graph(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, get_transport_type(volinfo, set_dict, transt, _gf_false); if (!strncmp(transt, "tcp,rdma", SLEN("tcp,rdma"))) - strncpy(transt, "tcp", sizeof(transt)); + (void)snprintf(transt, sizeof(transt), "%s", "tcp"); cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { @@ -6365,7 +6082,7 @@ build_scrub_clusters(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, xl = first_of(graph); - ret = xlator_set_option(xl, "scrubber", "true"); + ret = xlator_set_fixed_option(xl, "scrubber", "true"); if (ret) goto out; @@ -6410,7 +6127,7 @@ build_scrub_volume_graph(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, get_transport_type(volinfo, set_dict, transt, _gf_false); if (!strncmp(transt, "tcp,rdma", SLEN("tcp,rdma"))) - strncpy(transt, "tcp", sizeof(transt)); + (void)snprintf(transt, sizeof(transt), "%s", "tcp"); cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { @@ -6565,7 +6282,11 @@ glusterd_create_volfiles(glusterd_volinfo_t *volinfo) if (ret) gf_log(this->name, GF_LOG_ERROR, "Could not generate gfproxy volfiles"); - dict_del(volinfo->dict, "skip-CLIOT"); + ret = glusterd_shdsvc_create_volfile(volinfo); + if (ret) + gf_log(this->name, GF_LOG_ERROR, "Could not generate shd volfiles"); + + dict_del_sizen(volinfo->dict, "skip-CLIOT"); out: return ret; @@ -6642,10 +6363,13 @@ validate_shdopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, ret = 0; goto out; } - ret = dict_set_int32n(val_dict, "graph-check", SLEN("graph-check"), 1); - if (ret) + ret = dict_set_int32_sizen(val_dict, "graph-check", 1); + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=graph-check", NULL); goto out; - ret = build_shd_graph(&graph, val_dict); + } + ret = build_shd_graph(volinfo, &graph, val_dict); if (!ret) ret = graph_reconf_validateopt(&graph.graph, op_errstr); @@ -6653,11 +6377,12 @@ validate_shdopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, gf_msg_debug("glusterd", 0, "Returning %d", ret); out: - dict_deln(val_dict, "graph-check", SLEN("graph-check")); + dict_del_sizen(val_dict, "graph-check"); return ret; } -int +#ifdef BUILD_GNFS +static int validate_nfsopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, char **op_errstr) { @@ -6679,7 +6404,7 @@ validate_nfsopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, graph.errstr = op_errstr; get_vol_transport_type(volinfo, transport_type); - ret = dict_get_str(val_dict, "nfs.transport-type", &tt); + ret = dict_get_str_sizen(val_dict, "nfs.transport-type", &tt); if (!ret) { if (volinfo->transport_type != GF_TRANSPORT_BOTH_TCP_RDMA) { snprintf(err_str, sizeof(err_str), @@ -6697,13 +6422,15 @@ validate_nfsopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, "wrong transport " "type %s", tt); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_INCOMPATIBLE_VALUE, + "Type=%s", tt, NULL); *op_errstr = gf_strdup(err_str); ret = -1; goto out; } } - ret = dict_set_str(val_dict, "volume-name", volinfo->volname); + ret = dict_set_str_sizen(val_dict, "volume-name", volinfo->volname); if (ret) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, "Failed to set volume name"); @@ -6717,11 +6444,12 @@ validate_nfsopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, volgen_graph_free(&graph); out: - if (dict_get(val_dict, "volume-name")) - dict_del(val_dict, "volume-name"); + if (dict_get_sizen(val_dict, "volume-name")) + dict_del_sizen(val_dict, "volume-name"); gf_msg_debug(this->name, 0, "Returning %d", ret); return ret; } +#endif int validate_clientopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, @@ -6764,6 +6492,7 @@ validate_brickopts(glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo, graph.errstr = op_errstr; full_dict = dict_new(); if (!full_dict) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); ret = -1; goto out; } @@ -6839,13 +6568,13 @@ glusterd_validate_globalopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, gf_msg_debug("glusterd", 0, "Could not Validate client"); goto out; } - +#ifdef BUILD_GNFS ret = validate_nfsopts(volinfo, val_dict, op_errstr); if (ret) { gf_msg_debug("glusterd", 0, "Could not Validate nfs"); goto out; } - +#endif ret = validate_shdopts(volinfo, val_dict, op_errstr); if (ret) { gf_msg_debug("glusterd", 0, "Could not Validate self-heald"); @@ -6895,12 +6624,13 @@ glusterd_validate_reconfopts(glusterd_volinfo_t *volinfo, dict_t *val_dict, goto out; } +#ifdef BUILD_GNFS ret = validate_nfsopts(volinfo, val_dict, op_errstr); if (ret) { gf_msg_debug("glusterd", 0, "Could not Validate nfs"); goto out; } - +#endif ret = validate_shdopts(volinfo, val_dict, op_errstr); if (ret) { gf_msg_debug("glusterd", 0, "Could not Validate self-heald"); @@ -6912,13 +6642,16 @@ out: return ret; } -static struct volopt_map_entry * -_gd_get_vmep(char *key) +struct volopt_map_entry * +gd_get_vmep(const char *key) { char *completion = NULL; struct volopt_map_entry *vmep = NULL; int ret = 0; + if (!key) + return NULL; + COMPLETE_OPTION((char *)key, completion, ret); for (vmep = glusterd_volopt_map; vmep->key; vmep++) { if (strcmp(vmep->key, key) == 0) @@ -6929,13 +6662,8 @@ _gd_get_vmep(char *key) } uint32_t -glusterd_get_op_version_for_key(char *key) +glusterd_get_op_version_from_vmep(struct volopt_map_entry *vmep) { - struct volopt_map_entry *vmep = NULL; - - GF_ASSERT(key); - - vmep = _gd_get_vmep(key); if (vmep) return vmep->op_version; @@ -6943,13 +6671,8 @@ glusterd_get_op_version_for_key(char *key) } gf_boolean_t -gd_is_client_option(char *key) +gd_is_client_option(struct volopt_map_entry *vmep) { - struct volopt_map_entry *vmep = NULL; - - GF_ASSERT(key); - - vmep = _gd_get_vmep(key); if (vmep && (vmep->flags & VOLOPT_FLAG_CLIENT_OPT)) return _gf_true; @@ -6957,23 +6680,17 @@ gd_is_client_option(char *key) } gf_boolean_t -gd_is_xlator_option(char *key) +gd_is_xlator_option(struct volopt_map_entry *vmep) { - struct volopt_map_entry *vmep = NULL; - - GF_ASSERT(key); - - vmep = _gd_get_vmep(key); if (vmep && (vmep->flags & VOLOPT_FLAG_XLATOR_OPT)) return _gf_true; return _gf_false; } -volume_option_type_t -_gd_get_option_type(char *key) +static volume_option_type_t +_gd_get_option_type(struct volopt_map_entry *vmep) { - struct volopt_map_entry *vmep = NULL; void *dl_handle = NULL; volume_opt_list_t vol_opt_list = { {0}, @@ -6983,10 +6700,6 @@ _gd_get_option_type(char *key) char *xlopt_key = NULL; volume_option_type_t opt_type = GF_OPTION_TYPE_MAX; - GF_ASSERT(key); - - vmep = _gd_get_vmep(key); - if (vmep) { CDS_INIT_LIST_HEAD(&vol_opt_list.list); ret = xlator_volopt_dynload(vmep->voltype, &dl_handle, &vol_opt_list); @@ -7013,12 +6726,29 @@ out: } gf_boolean_t -gd_is_boolean_option(char *key) +gd_is_boolean_option(struct volopt_map_entry *vmep) { - GF_ASSERT(key); - - if (GF_OPTION_TYPE_BOOL == _gd_get_option_type(key)) + if (GF_OPTION_TYPE_BOOL == _gd_get_option_type(vmep)) return _gf_true; return _gf_false; } + +int +glusterd_shdsvc_generate_volfile(glusterd_volinfo_t *volinfo, char *filename, + dict_t *mode_dict) +{ + int ret = -1; + volgen_graph_t graph = { + 0, + }; + + graph.type = GF_SHD; + ret = build_shd_graph(volinfo, &graph, mode_dict); + if (!ret) + ret = volgen_write_volfile(&graph, filename); + + volgen_graph_free(&graph); + + return ret; +} |
