diff options
Diffstat (limited to 'xlators/cluster/dht/src/tier.c')
| -rw-r--r-- | xlators/cluster/dht/src/tier.c | 57 | 
1 files changed, 53 insertions, 4 deletions
diff --git a/xlators/cluster/dht/src/tier.c b/xlators/cluster/dht/src/tier.c index 41032743c04..4cbcc81f311 100644 --- a/xlators/cluster/dht/src/tier.c +++ b/xlators/cluster/dht/src/tier.c @@ -198,10 +198,17 @@ out:  static int  tier_check_same_node (xlator_t *this, loc_t *loc, gf_defrag_info_t *defrag)  { -        int     ret            = -1; -        dict_t *dict           = NULL; -        char   *uuid_str       = NULL; -        uuid_t  node_uuid      = {0,}; +        int         ret                     = -1; +        dict_t     *dict                    = NULL; +        char       *uuid_str                = NULL; +        uuid_t      node_uuid               = {0,}; +        char       *dup_str                 = NULL; +        char       *str                     = NULL; +        char       *save_ptr                = NULL; +        int         count                   = 0; +        uint32_t    hashval                 = 0; +        int32_t     index                   = 0; +        char        buf[GF_UUID_BUF_SIZE]   = {0,};          GF_VALIDATE_OR_GOTO ("tier", this, out);          GF_VALIDATE_OR_GOTO (this->name, loc, out); @@ -215,15 +222,56 @@ tier_check_same_node (xlator_t *this, loc_t *loc, gf_defrag_info_t *defrag)                  goto out;          } + +        /*  This returns multiple node-uuids now - one for each brick +         *  of the subvol. +         */ +          if (dict_get_str (dict, GF_XATTR_NODE_UUID_KEY, &uuid_str) < 0) {                  gf_msg (this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR,                          "Failed to get node-uuid for %s", loc->path);                  goto out;          } +        dup_str = gf_strdup (uuid_str); +        str = dup_str; + +        /* How many uuids returned? +         * No need to check if one of these is that of the current node. +         */ + +        count = 1; +        while ((str = strchr (str, ' '))) { +                count++; +                str++; +        } + +        /* Only one node-uuid - pure distribute? */ +        if (count == 1) +                goto check_node; + +        uuid_utoa_r (loc->gfid, buf); +        ret = dht_hash_compute (this, 0, buf, &hashval); +        if (ret == 0) { +                index = (hashval % count); +        } + +        count = 0; +        str = dup_str; +        while ((uuid_str = strtok_r (str, " ", &save_ptr))) { +                if (count == index) +                        break; +                count++; +                str = NULL; +        } + + +check_node: +          if (gf_uuid_parse (uuid_str, node_uuid)) {                  gf_msg (this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR,                          "uuid_parse failed for %s", loc->path); +                ret = -1;                  goto out;          } @@ -239,6 +287,7 @@ out:          if (dict)                  dict_unref(dict); +        GF_FREE (dup_str);          return ret;  }  | 
