summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
Diffstat (limited to 'xlators')
-rw-r--r--xlators/cluster/dht/src/nufa.c76
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c13
2 files changed, 79 insertions, 10 deletions
diff --git a/xlators/cluster/dht/src/nufa.c b/xlators/cluster/dht/src/nufa.c
index a2a97ab3c76..701d7ae8da7 100644
--- a/xlators/cluster/dht/src/nufa.c
+++ b/xlators/cluster/dht/src/nufa.c
@@ -491,6 +491,26 @@ fini (xlator_t *this)
return;
}
+gf_boolean_t
+same_first_part (char *str1, char term1, char *str2, char term2)
+{
+ gf_boolean_t ended1;
+ gf_boolean_t ended2;
+
+ for (;;) {
+ ended1 = ((*str1 == '\0') || (*str1 == term1));
+ ended2 = ((*str2 == '\0') || (*str2 == term2));
+ if (ended1 && ended2) {
+ return _gf_true;
+ }
+ if (ended1 || ended2 || (*str1 != *str2)) {
+ return _gf_false;
+ }
+ ++str1;
+ ++str2;
+ }
+}
+
int
init (xlator_t *this)
{
@@ -504,6 +524,9 @@ init (xlator_t *this)
char my_hostname[256];
double temp_free_disk = 0;
uint64_t size = 0;
+ xlator_t *local_subvol = NULL;
+ char *brick_host = NULL;
+ xlator_t *kid = NULL;
if (!this->children) {
gf_log (this->name, GF_LOG_CRITICAL,
@@ -562,23 +585,58 @@ init (xlator_t *this)
local_volname = data->data;
}
- trav = this->children;
- while (trav) {
+ for (trav = this->children; trav; trav = trav->next) {
if (strcmp (trav->xlator->name, local_volname) == 0)
break;
- trav = trav->next;
+ if (local_subvol) {
+ continue;
+ }
+ kid = trav->xlator;
+ for (;;) {
+ if (dict_get_str(trav->xlator->options,"remote-host",
+ &brick_host) == 0) {
+ /* Found it. */
+ break;
+ }
+ if (!kid->children) {
+ /* Nowhere further to look. */
+ gf_log (this->name, GF_LOG_ERROR,
+ "could not get remote-host");
+ goto err;
+ }
+ if (kid->children->next) {
+ /* Multiple choices, can't/shouldn't decide. */
+ gf_log (this->name, GF_LOG_ERROR,
+ "NUFA found fan-out (type %s) volume",
+ kid->type);
+ goto err;
+ }
+ /* One-to-one xlators are OK, try the next one. */
+ kid = kid->children->xlator;
+ }
+ if (same_first_part(my_hostname,'.',brick_host,'.')) {
+ local_subvol = trav->xlator;
+ }
}
- if (!trav) {
+ if (trav) {
+ gf_log (this->name, GF_LOG_INFO,
+ "Using specified subvol %s", local_volname);
+ conf->private = trav->xlator;
+ }
+ else if (local_subvol) {
+ gf_log (this->name, GF_LOG_INFO,
+ "Using first local subvol %s", local_subvol->name);
+ conf->private = local_subvol;
+ }
+ else {
gf_log (this->name, GF_LOG_ERROR,
- "Could not find subvolume named '%s'. "
- "Please define volume with the name as the hostname "
- "or override it with 'option local-volume-name'",
- local_volname);
+ "Could not find specified or local subvol");
goto err;
+
}
+
/* The volume specified exists */
- conf->private = trav->xlator;
conf->min_free_disk = 10;
conf->disk_unit = 'p';
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index da1c2a4ef94..40b2e32a2b4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -108,6 +108,7 @@ static struct volopt_map_entry glusterd_volopt_map[] = {
{"cluster.rebalance-stats", "cluster/distribute", NULL, NULL, NO_DOC, 0, 2},
{"cluster.subvols-per-directory", "cluster/distribute", "directory-layout-spread", NULL, NO_DOC, 0, 2},
{"cluster.readdir-optimize", "cluster/distribute", NULL, NULL, NO_DOC, 0, 2},
+ {"cluster.nufa", "cluster/distribute", "!nufa", NULL, NO_DOC, 0, 2},
/* AFR xlator options */
{"cluster.entry-change-log", "cluster/replicate", NULL, NULL, NO_DOC, 0, 1},
@@ -2399,9 +2400,19 @@ volgen_graph_build_dht_cluster (volgen_graph_t *graph,
int ret = -1;
char *decommissioned_children = NULL;
xlator_t *dht = NULL;
+ char *optstr = NULL;
+ gf_boolean_t use_nufa = _gf_false;
+ if (dict_get_str(volinfo->dict,"cluster.nufa",&optstr) == 0) {
+ /* Keep static analyzers quiet by "using" the value. */
+ ret = gf_string2boolean(optstr,&use_nufa);
+ }
+
clusters = volgen_graph_build_clusters (graph, volinfo,
- "cluster/distribute", "%s-dht",
+ use_nufa
+ ? "cluster/nufa"
+ : "cluster/distribute",
+ "%s-dht",
child_count, child_count);
if (clusters < 0)
goto out;