9ae3f9
From d7c52ddd2cbadb1d9a55767c2f7fe6ba38d9a2ed Mon Sep 17 00:00:00 2001
9ae3f9
From: Sheetal Pamecha <spamecha@redhat.com>
9ae3f9
Date: Wed, 20 Nov 2019 12:42:12 +0530
9ae3f9
Subject: [PATCH 431/449] glusterd: check for same node while adding bricks in
9ae3f9
 disperse volume
9ae3f9
9ae3f9
The optimal way for configuring disperse and replicate volumes
9ae3f9
is to have all bricks in different nodes.
9ae3f9
9ae3f9
During create operation it fails saying it is not optimal, user
9ae3f9
must use force to over-ride this behavior. Implementing same
9ae3f9
during add-brick operation to avoid situation where all the added
9ae3f9
bricks end up from same host. Operation will error out accordingly.
9ae3f9
and this can be over-ridden by using force same as create.
9ae3f9
9ae3f9
> Upstream Patch Link: https://review.gluster.org/#/c/glusterfs/+/23729
9ae3f9
> fixes: #1047
9ae3f9
> Change-Id: I3ee9c97c1a14b73f4532893bc00187ef9355238b
9ae3f9
> Signed-off-by: Sheetal Pamecha <spamecha@redhat.com>
9ae3f9
9ae3f9
BUG: 1524457
9ae3f9
Change-Id: I3ee9c97c1a14b73f4532893bc00187ef9355238b
9ae3f9
Signed-off-by: Sheetal Pamecha <spamecha@redhat.com>
9ae3f9
Reviewed-on: https://code.engineering.redhat.com/gerrit/202621
9ae3f9
Tested-by: RHGS Build Bot <nigelb@redhat.com>
9ae3f9
Reviewed-by: Sanju Rakonde <srakonde@redhat.com>
9ae3f9
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9ae3f9
---
9ae3f9
 xlators/mgmt/glusterd/src/glusterd-brick-ops.c  |  20 +-
9ae3f9
 xlators/mgmt/glusterd/src/glusterd-utils.c      | 224 ++++++++++++++++++
9ae3f9
 xlators/mgmt/glusterd/src/glusterd-utils.h      |   4 +
9ae3f9
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 293 +++---------------------
9ae3f9
 4 files changed, 276 insertions(+), 265 deletions(-)
9ae3f9
9ae3f9
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
9ae3f9
index c5141de..d424f31 100644
9ae3f9
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
9ae3f9
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
9ae3f9
@@ -21,7 +21,6 @@
9ae3f9
 #include "glusterd-messages.h"
9ae3f9
 #include "glusterd-server-quorum.h"
9ae3f9
 #include <glusterfs/run.h>
9ae3f9
-#include "glusterd-volgen.h"
9ae3f9
 #include <glusterfs/syscall.h>
9ae3f9
 #include <sys/signal.h>
9ae3f9
 
9ae3f9
@@ -1575,6 +1574,25 @@ glusterd_op_stage_add_brick(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
9ae3f9
 
9ae3f9
     is_force = dict_get_str_boolean(dict, "force", _gf_false);
9ae3f9
 
9ae3f9
+    /* Check brick order if the volume type is replicate or disperse. If
9ae3f9
+     * force at the end of command not given then check brick order.
9ae3f9
+     */
9ae3f9
+
9ae3f9
+    if (!is_force) {
9ae3f9
+        if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) ||
9ae3f9
+            (volinfo->type == GF_CLUSTER_TYPE_DISPERSE)) {
9ae3f9
+            ret = glusterd_check_brick_order(dict, msg, volinfo->type);
9ae3f9
+            if (ret) {
9ae3f9
+                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
9ae3f9
+                       "Not adding brick because of "
9ae3f9
+                       "bad brick order. %s",
9ae3f9
+                       msg);
9ae3f9
+                *op_errstr = gf_strdup(msg);
9ae3f9
+                goto out;
9ae3f9
+            }
9ae3f9
+        }
9ae3f9
+    }
9ae3f9
+
9ae3f9
     if (volinfo->replica_count < replica_count && !is_force) {
9ae3f9
         cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
9ae3f9
         {
9ae3f9
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
9ae3f9
index a1299bc..14e23d1 100644
9ae3f9
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
9ae3f9
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
9ae3f9
@@ -14759,3 +14759,227 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo)
9ae3f9
         return _gf_true;
9ae3f9
     return _gf_false;
9ae3f9
 }
9ae3f9
+
9ae3f9
+static gf_ai_compare_t
9ae3f9
+glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next)
9ae3f9
+{
9ae3f9
+    int ret = -1;
9ae3f9
+    struct addrinfo *tmp1 = NULL;
9ae3f9
+    struct addrinfo *tmp2 = NULL;
9ae3f9
+    char firstip[NI_MAXHOST] = {0.};
9ae3f9
+    char nextip[NI_MAXHOST] = {
9ae3f9
+        0,
9ae3f9
+    };
9ae3f9
+
9ae3f9
+    for (tmp1 = first; tmp1 != NULL; tmp1 = tmp1->ai_next) {
9ae3f9
+        ret = getnameinfo(tmp1->ai_addr, tmp1->ai_addrlen, firstip, NI_MAXHOST,
9ae3f9
+                          NULL, 0, NI_NUMERICHOST);
9ae3f9
+        if (ret)
9ae3f9
+            return GF_AI_COMPARE_ERROR;
9ae3f9
+        for (tmp2 = next; tmp2 != NULL; tmp2 = tmp2->ai_next) {
9ae3f9
+            ret = getnameinfo(tmp2->ai_addr, tmp2->ai_addrlen, nextip,
9ae3f9
+                              NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
9ae3f9
+            if (ret)
9ae3f9
+                return GF_AI_COMPARE_ERROR;
9ae3f9
+            if (!strcmp(firstip, nextip)) {
9ae3f9
+                return GF_AI_COMPARE_MATCH;
9ae3f9
+            }
9ae3f9
+        }
9ae3f9
+    }
9ae3f9
+    return GF_AI_COMPARE_NO_MATCH;
9ae3f9
+}
9ae3f9
+
9ae3f9
+/* Check for non optimal brick order for Replicate/Disperse :
9ae3f9
+ * Checks if bricks belonging to a replicate or disperse
9ae3f9
+ * volume are present on the same server
9ae3f9
+ */
9ae3f9
+int32_t
9ae3f9
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type)
9ae3f9
+{
9ae3f9
+    int ret = -1;
9ae3f9
+    int i = 0;
9ae3f9
+    int j = 0;
9ae3f9
+    int k = 0;
9ae3f9
+    xlator_t *this = NULL;
9ae3f9
+    addrinfo_list_t *ai_list = NULL;
9ae3f9
+    addrinfo_list_t *ai_list_tmp1 = NULL;
9ae3f9
+    addrinfo_list_t *ai_list_tmp2 = NULL;
9ae3f9
+    char *brick = NULL;
9ae3f9
+    char *brick_list = NULL;
9ae3f9
+    char *brick_list_dup = NULL;
9ae3f9
+    char *brick_list_ptr = NULL;
9ae3f9
+    char *tmpptr = NULL;
9ae3f9
+    char *volname = NULL;
9ae3f9
+    int32_t brick_count = 0;
9ae3f9
+    int32_t sub_count = 0;
9ae3f9
+    struct addrinfo *ai_info = NULL;
9ae3f9
+    char brick_addr[128] = {
9ae3f9
+        0,
9ae3f9
+    };
9ae3f9
+    int addrlen = 0;
9ae3f9
+
9ae3f9
+    const char failed_string[2048] =
9ae3f9
+        "Failed to perform brick order "
9ae3f9
+        "check. Use 'force' at the end of the command"
9ae3f9
+        " if you want to override this behavior. ";
9ae3f9
+    const char found_string[2048] =
9ae3f9
+        "Multiple bricks of a %s "
9ae3f9
+        "volume are present on the same server. This "
9ae3f9
+        "setup is not optimal. Bricks should be on "
9ae3f9
+        "different nodes to have best fault tolerant "
9ae3f9
+        "configuration. Use 'force' at the end of the "
9ae3f9
+        "command if you want to override this "
9ae3f9
+        "behavior. ";
9ae3f9
+
9ae3f9
+    this = THIS;
9ae3f9
+
9ae3f9
+    GF_ASSERT(this);
9ae3f9
+
9ae3f9
+    ai_list = MALLOC(sizeof(addrinfo_list_t));
9ae3f9
+    ai_list->info = NULL;
9ae3f9
+    CDS_INIT_LIST_HEAD(&ai_list->list);
9ae3f9
+
9ae3f9
+    ret = dict_get_strn(dict, "volname", SLEN("volname"), &volname);
9ae3f9
+    if (ret) {
9ae3f9
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
+               "Unable to get volume name");
9ae3f9
+        goto out;
9ae3f9
+    }
9ae3f9
+
9ae3f9
+    ret = dict_get_strn(dict, "bricks", SLEN("bricks"), &brick_list);
9ae3f9
+    if (ret) {
9ae3f9
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
+               "Bricks check : Could not "
9ae3f9
+               "retrieve bricks list");
9ae3f9
+        goto out;
9ae3f9
+    }
9ae3f9
+
9ae3f9
+    ret = dict_get_int32n(dict, "count", SLEN("count"), &brick_count);
9ae3f9
+    if (ret) {
9ae3f9
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
+               "Bricks check : Could not "
9ae3f9
+               "retrieve brick count");
9ae3f9
+        goto out;
9ae3f9
+    }
9ae3f9
+
9ae3f9
+    if (type != GF_CLUSTER_TYPE_DISPERSE) {
9ae3f9
+        ret = dict_get_int32n(dict, "replica-count", SLEN("replica-count"),
9ae3f9
+                              &sub_count);
9ae3f9
+        if (ret) {
9ae3f9
+            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
+                   "Bricks check : Could"
9ae3f9
+                   " not retrieve replica count");
9ae3f9
+            goto out;
9ae3f9
+        }
9ae3f9
+        gf_msg_debug(this->name, 0,
9ae3f9
+                     "Replicate cluster type "
9ae3f9
+                     "found. Checking brick order.");
9ae3f9
+    } else {
9ae3f9
+        ret = dict_get_int32n(dict, "disperse-count", SLEN("disperse-count"),
9ae3f9
+                              &sub_count);
9ae3f9
+        if (ret) {
9ae3f9
+            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
+                   "Bricks check : Could"
9ae3f9
+                   " not retrieve disperse count");
9ae3f9
+            goto out;
9ae3f9
+        }
9ae3f9
+        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DISPERSE_CLUSTER_FOUND,
9ae3f9
+               "Disperse cluster type"
9ae3f9
+               " found. Checking brick order.");
9ae3f9
+    }
9ae3f9
+    brick_list_dup = brick_list_ptr = gf_strdup(brick_list);
9ae3f9
+    /* Resolve hostnames and get addrinfo */
9ae3f9
+    while (i < brick_count) {
9ae3f9
+        ++i;
9ae3f9
+        brick = strtok_r(brick_list_dup, " \n", &tmpptr);
9ae3f9
+        brick_list_dup = tmpptr;
9ae3f9
+        if (brick == NULL)
9ae3f9
+            goto check_failed;
9ae3f9
+        tmpptr = strrchr(brick, ':');
9ae3f9
+        if (tmpptr == NULL)
9ae3f9
+            goto check_failed;
9ae3f9
+        addrlen = strlen(brick) - strlen(tmpptr);
9ae3f9
+        strncpy(brick_addr, brick, addrlen);
9ae3f9
+        brick_addr[addrlen] = '\0';
9ae3f9
+        ret = getaddrinfo(brick_addr, NULL, NULL, &ai_info);
9ae3f9
+        if (ret != 0) {
9ae3f9
+            ret = 0;
9ae3f9
+            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_RESOLVE_FAIL,
9ae3f9
+                   "unable to resolve host name for addr %s", brick_addr);
9ae3f9
+            goto out;
9ae3f9
+        }
9ae3f9
+        ai_list_tmp1 = MALLOC(sizeof(addrinfo_list_t));
9ae3f9
+        if (ai_list_tmp1 == NULL) {
9ae3f9
+            ret = 0;
9ae3f9
+            gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
9ae3f9
+                   "failed to allocate "
9ae3f9
+                   "memory");
9ae3f9
+            freeaddrinfo(ai_info);
9ae3f9
+            goto out;
9ae3f9
+        }
9ae3f9
+        ai_list_tmp1->info = ai_info;
9ae3f9
+        cds_list_add_tail(&ai_list_tmp1->list, &ai_list->list);
9ae3f9
+        ai_list_tmp1 = NULL;
9ae3f9
+    }
9ae3f9
+
9ae3f9
+    i = 0;
9ae3f9
+    ai_list_tmp1 = cds_list_entry(ai_list->list.next, addrinfo_list_t, list);
9ae3f9
+
9ae3f9
+    /* Check for bad brick order */
9ae3f9
+    while (i < brick_count) {
9ae3f9
+        ++i;
9ae3f9
+        ai_info = ai_list_tmp1->info;
9ae3f9
+        ai_list_tmp1 = cds_list_entry(ai_list_tmp1->list.next, addrinfo_list_t,
9ae3f9
+                                      list);
9ae3f9
+        if (0 == i % sub_count) {
9ae3f9
+            j = 0;
9ae3f9
+            continue;
9ae3f9
+        }
9ae3f9
+        ai_list_tmp2 = ai_list_tmp1;
9ae3f9
+        k = j;
9ae3f9
+        while (k < sub_count - 1) {
9ae3f9
+            ++k;
9ae3f9
+            ret = glusterd_compare_addrinfo(ai_info, ai_list_tmp2->info);
9ae3f9
+            if (GF_AI_COMPARE_ERROR == ret)
9ae3f9
+                goto check_failed;
9ae3f9
+            if (GF_AI_COMPARE_MATCH == ret)
9ae3f9
+                goto found_bad_brick_order;
9ae3f9
+            ai_list_tmp2 = cds_list_entry(ai_list_tmp2->list.next,
9ae3f9
+                                          addrinfo_list_t, list);
9ae3f9
+        }
9ae3f9
+        ++j;
9ae3f9
+    }
9ae3f9
+    gf_msg_debug(this->name, 0, "Brick order okay");
9ae3f9
+    ret = 0;
9ae3f9
+    goto out;
9ae3f9
+
9ae3f9
+check_failed:
9ae3f9
+    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER_CHECK_FAIL,
9ae3f9
+           "Failed bad brick order check");
9ae3f9
+    snprintf(err_str, sizeof(failed_string), failed_string);
9ae3f9
+    ret = -1;
9ae3f9
+    goto out;
9ae3f9
+
9ae3f9
+found_bad_brick_order:
9ae3f9
+    gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_BAD_BRKORDER,
9ae3f9
+           "Bad brick order found");
9ae3f9
+    if (type == GF_CLUSTER_TYPE_DISPERSE) {
9ae3f9
+        snprintf(err_str, sizeof(found_string), found_string, "disperse");
9ae3f9
+    } else {
9ae3f9
+        snprintf(err_str, sizeof(found_string), found_string, "replicate");
9ae3f9
+    }
9ae3f9
+
9ae3f9
+    ret = -1;
9ae3f9
+out:
9ae3f9
+    ai_list_tmp2 = NULL;
9ae3f9
+    GF_FREE(brick_list_ptr);
9ae3f9
+    cds_list_for_each_entry(ai_list_tmp1, &ai_list->list, list)
9ae3f9
+    {
9ae3f9
+        if (ai_list_tmp1->info)
9ae3f9
+            freeaddrinfo(ai_list_tmp1->info);
9ae3f9
+        free(ai_list_tmp2);
9ae3f9
+        ai_list_tmp2 = ai_list_tmp1;
9ae3f9
+    }
9ae3f9
+    free(ai_list_tmp2);
9ae3f9
+    return ret;
9ae3f9
+}
9ae3f9
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
9ae3f9
index ead16b2..e2e2454 100644
9ae3f9
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
9ae3f9
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
9ae3f9
@@ -881,4 +881,8 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo);
9ae3f9
 
9ae3f9
 char *
9ae3f9
 search_brick_path_from_proc(pid_t brick_pid, char *brickpath);
9ae3f9
+
9ae3f9
+int32_t
9ae3f9
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type);
9ae3f9
+
9ae3f9
 #endif
9ae3f9
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
9ae3f9
index 93042ab..8da2ff3 100644
9ae3f9
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
9ae3f9
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
9ae3f9
@@ -41,240 +41,6 @@
9ae3f9
 #define glusterd_op_start_volume_args_get(dict, volname, flags)                \
9ae3f9
     glusterd_op_stop_volume_args_get(dict, volname, flags)
9ae3f9
 
9ae3f9
-gf_ai_compare_t
9ae3f9
-glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next)
9ae3f9
-{
9ae3f9
-    int ret = -1;
9ae3f9
-    struct addrinfo *tmp1 = NULL;
9ae3f9
-    struct addrinfo *tmp2 = NULL;
9ae3f9
-    char firstip[NI_MAXHOST] = {0.};
9ae3f9
-    char nextip[NI_MAXHOST] = {
9ae3f9
-        0,
9ae3f9
-    };
9ae3f9
-
9ae3f9
-    for (tmp1 = first; tmp1 != NULL; tmp1 = tmp1->ai_next) {
9ae3f9
-        ret = getnameinfo(tmp1->ai_addr, tmp1->ai_addrlen, firstip, NI_MAXHOST,
9ae3f9
-                          NULL, 0, NI_NUMERICHOST);
9ae3f9
-        if (ret)
9ae3f9
-            return GF_AI_COMPARE_ERROR;
9ae3f9
-        for (tmp2 = next; tmp2 != NULL; tmp2 = tmp2->ai_next) {
9ae3f9
-            ret = getnameinfo(tmp2->ai_addr, tmp2->ai_addrlen, nextip,
9ae3f9
-                              NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
9ae3f9
-            if (ret)
9ae3f9
-                return GF_AI_COMPARE_ERROR;
9ae3f9
-            if (!strcmp(firstip, nextip)) {
9ae3f9
-                return GF_AI_COMPARE_MATCH;
9ae3f9
-            }
9ae3f9
-        }
9ae3f9
-    }
9ae3f9
-    return GF_AI_COMPARE_NO_MATCH;
9ae3f9
-}
9ae3f9
-
9ae3f9
-/* Check for non optimal brick order for replicate :
9ae3f9
- * Checks if bricks belonging to a replicate volume
9ae3f9
- * are present on the same server
9ae3f9
- */
9ae3f9
-int32_t
9ae3f9
-glusterd_check_brick_order(dict_t *dict, char *err_str)
9ae3f9
-{
9ae3f9
-    int ret = -1;
9ae3f9
-    int i = 0;
9ae3f9
-    int j = 0;
9ae3f9
-    int k = 0;
9ae3f9
-    xlator_t *this = NULL;
9ae3f9
-    addrinfo_list_t *ai_list = NULL;
9ae3f9
-    addrinfo_list_t *ai_list_tmp1 = NULL;
9ae3f9
-    addrinfo_list_t *ai_list_tmp2 = NULL;
9ae3f9
-    char *brick = NULL;
9ae3f9
-    char *brick_list = NULL;
9ae3f9
-    char *brick_list_dup = NULL;
9ae3f9
-    char *brick_list_ptr = NULL;
9ae3f9
-    char *tmpptr = NULL;
9ae3f9
-    char *volname = NULL;
9ae3f9
-    int32_t brick_count = 0;
9ae3f9
-    int32_t type = GF_CLUSTER_TYPE_NONE;
9ae3f9
-    int32_t sub_count = 0;
9ae3f9
-    struct addrinfo *ai_info = NULL;
9ae3f9
-    char brick_addr[128] = {
9ae3f9
-        0,
9ae3f9
-    };
9ae3f9
-    int addrlen = 0;
9ae3f9
-
9ae3f9
-    const char failed_string[2048] =
9ae3f9
-        "Failed to perform brick order "
9ae3f9
-        "check. Use 'force' at the end of the command"
9ae3f9
-        " if you want to override this behavior. ";
9ae3f9
-    const char found_string[2048] =
9ae3f9
-        "Multiple bricks of a %s "
9ae3f9
-        "volume are present on the same server. This "
9ae3f9
-        "setup is not optimal. Bricks should be on "
9ae3f9
-        "different nodes to have best fault tolerant "
9ae3f9
-        "configuration. Use 'force' at the end of the "
9ae3f9
-        "command if you want to override this "
9ae3f9
-        "behavior. ";
9ae3f9
-
9ae3f9
-    this = THIS;
9ae3f9
-
9ae3f9
-    GF_ASSERT(this);
9ae3f9
-
9ae3f9
-    ai_list = MALLOC(sizeof(addrinfo_list_t));
9ae3f9
-    ai_list->info = NULL;
9ae3f9
-    CDS_INIT_LIST_HEAD(&ai_list->list);
9ae3f9
-
9ae3f9
-    ret = dict_get_strn(dict, "volname", SLEN("volname"), &volname);
9ae3f9
-    if (ret) {
9ae3f9
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
-               "Unable to get volume name");
9ae3f9
-        goto out;
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
9ae3f9
-    if (ret) {
9ae3f9
-        snprintf(err_str, 512, "Unable to get type of volume %s", volname);
9ae3f9
-        gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
9ae3f9
-               err_str);
9ae3f9
-        goto out;
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    ret = dict_get_strn(dict, "bricks", SLEN("bricks"), &brick_list);
9ae3f9
-    if (ret) {
9ae3f9
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
-               "Bricks check : Could not "
9ae3f9
-               "retrieve bricks list");
9ae3f9
-        goto out;
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    ret = dict_get_int32n(dict, "count", SLEN("count"), &brick_count);
9ae3f9
-    if (ret) {
9ae3f9
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
-               "Bricks check : Could not "
9ae3f9
-               "retrieve brick count");
9ae3f9
-        goto out;
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    if (type != GF_CLUSTER_TYPE_DISPERSE) {
9ae3f9
-        ret = dict_get_int32n(dict, "replica-count", SLEN("replica-count"),
9ae3f9
-                              &sub_count);
9ae3f9
-        if (ret) {
9ae3f9
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
-                   "Bricks check : Could"
9ae3f9
-                   " not retrieve replica count");
9ae3f9
-            goto out;
9ae3f9
-        }
9ae3f9
-        gf_msg_debug(this->name, 0,
9ae3f9
-                     "Replicate cluster type "
9ae3f9
-                     "found. Checking brick order.");
9ae3f9
-    } else {
9ae3f9
-        ret = dict_get_int32n(dict, "disperse-count", SLEN("disperse-count"),
9ae3f9
-                              &sub_count);
9ae3f9
-        if (ret) {
9ae3f9
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
9ae3f9
-                   "Bricks check : Could"
9ae3f9
-                   " not retrieve disperse count");
9ae3f9
-            goto out;
9ae3f9
-        }
9ae3f9
-        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DISPERSE_CLUSTER_FOUND,
9ae3f9
-               "Disperse cluster type"
9ae3f9
-               " found. Checking brick order.");
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    brick_list_dup = brick_list_ptr = gf_strdup(brick_list);
9ae3f9
-    /* Resolve hostnames and get addrinfo */
9ae3f9
-    while (i < brick_count) {
9ae3f9
-        ++i;
9ae3f9
-        brick = strtok_r(brick_list_dup, " \n", &tmpptr);
9ae3f9
-        brick_list_dup = tmpptr;
9ae3f9
-        if (brick == NULL)
9ae3f9
-            goto check_failed;
9ae3f9
-        tmpptr = strrchr(brick, ':');
9ae3f9
-        if (tmpptr == NULL)
9ae3f9
-            goto check_failed;
9ae3f9
-        addrlen = strlen(brick) - strlen(tmpptr);
9ae3f9
-        strncpy(brick_addr, brick, addrlen);
9ae3f9
-        brick_addr[addrlen] = '\0';
9ae3f9
-        ret = getaddrinfo(brick_addr, NULL, NULL, &ai_info);
9ae3f9
-        if (ret != 0) {
9ae3f9
-            ret = 0;
9ae3f9
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_RESOLVE_FAIL,
9ae3f9
-                   "unable to resolve host name for addr %s", brick_addr);
9ae3f9
-            goto out;
9ae3f9
-        }
9ae3f9
-        ai_list_tmp1 = MALLOC(sizeof(addrinfo_list_t));
9ae3f9
-        if (ai_list_tmp1 == NULL) {
9ae3f9
-            ret = 0;
9ae3f9
-            gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
9ae3f9
-                   "failed to allocate "
9ae3f9
-                   "memory");
9ae3f9
-            freeaddrinfo(ai_info);
9ae3f9
-            goto out;
9ae3f9
-        }
9ae3f9
-        ai_list_tmp1->info = ai_info;
9ae3f9
-        cds_list_add_tail(&ai_list_tmp1->list, &ai_list->list);
9ae3f9
-        ai_list_tmp1 = NULL;
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    i = 0;
9ae3f9
-    ai_list_tmp1 = cds_list_entry(ai_list->list.next, addrinfo_list_t, list);
9ae3f9
-
9ae3f9
-    /* Check for bad brick order */
9ae3f9
-    while (i < brick_count) {
9ae3f9
-        ++i;
9ae3f9
-        ai_info = ai_list_tmp1->info;
9ae3f9
-        ai_list_tmp1 = cds_list_entry(ai_list_tmp1->list.next, addrinfo_list_t,
9ae3f9
-                                      list);
9ae3f9
-        if (0 == i % sub_count) {
9ae3f9
-            j = 0;
9ae3f9
-            continue;
9ae3f9
-        }
9ae3f9
-        ai_list_tmp2 = ai_list_tmp1;
9ae3f9
-        k = j;
9ae3f9
-        while (k < sub_count - 1) {
9ae3f9
-            ++k;
9ae3f9
-            ret = glusterd_compare_addrinfo(ai_info, ai_list_tmp2->info);
9ae3f9
-            if (GF_AI_COMPARE_ERROR == ret)
9ae3f9
-                goto check_failed;
9ae3f9
-            if (GF_AI_COMPARE_MATCH == ret)
9ae3f9
-                goto found_bad_brick_order;
9ae3f9
-            ai_list_tmp2 = cds_list_entry(ai_list_tmp2->list.next,
9ae3f9
-                                          addrinfo_list_t, list);
9ae3f9
-        }
9ae3f9
-        ++j;
9ae3f9
-    }
9ae3f9
-    gf_msg_debug(this->name, 0, "Brick order okay");
9ae3f9
-    ret = 0;
9ae3f9
-    goto out;
9ae3f9
-
9ae3f9
-check_failed:
9ae3f9
-    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER_CHECK_FAIL,
9ae3f9
-           "Failed bad brick order check");
9ae3f9
-    snprintf(err_str, sizeof(failed_string), failed_string);
9ae3f9
-    ret = -1;
9ae3f9
-    goto out;
9ae3f9
-
9ae3f9
-found_bad_brick_order:
9ae3f9
-    gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_BAD_BRKORDER,
9ae3f9
-           "Bad brick order found");
9ae3f9
-    if (type == GF_CLUSTER_TYPE_DISPERSE) {
9ae3f9
-        snprintf(err_str, sizeof(found_string), found_string, "disperse");
9ae3f9
-    } else {
9ae3f9
-        snprintf(err_str, sizeof(found_string), found_string, "replicate");
9ae3f9
-    }
9ae3f9
-
9ae3f9
-    ret = -1;
9ae3f9
-out:
9ae3f9
-    ai_list_tmp2 = NULL;
9ae3f9
-    GF_FREE(brick_list_ptr);
9ae3f9
-    cds_list_for_each_entry(ai_list_tmp1, &ai_list->list, list)
9ae3f9
-    {
9ae3f9
-        if (ai_list_tmp1->info)
9ae3f9
-            freeaddrinfo(ai_list_tmp1->info);
9ae3f9
-        free(ai_list_tmp2);
9ae3f9
-        ai_list_tmp2 = ai_list_tmp1;
9ae3f9
-    }
9ae3f9
-    free(ai_list_tmp2);
9ae3f9
-    return ret;
9ae3f9
-}
9ae3f9
-
9ae3f9
 int
9ae3f9
 __glusterd_handle_create_volume(rpcsvc_request_t *req)
9ae3f9
 {
9ae3f9
@@ -1337,6 +1103,35 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
9ae3f9
         }
9ae3f9
     }
9ae3f9
 
9ae3f9
+    /*Check brick order if the volume type is replicate or disperse. If
9ae3f9
+     * force at the end of command not given then check brick order.
9ae3f9
+     */
9ae3f9
+    if (is_origin_glusterd(dict)) {
9ae3f9
+        ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
9ae3f9
+        if (ret) {
9ae3f9
+            snprintf(msg, sizeof(msg),
9ae3f9
+                     "Unable to get type of "
9ae3f9
+                     "volume %s",
9ae3f9
+                     volname);
9ae3f9
+            gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
9ae3f9
+                   msg);
9ae3f9
+            goto out;
9ae3f9
+        }
9ae3f9
+
9ae3f9
+        if (!is_force) {
9ae3f9
+            if ((type == GF_CLUSTER_TYPE_REPLICATE) ||
9ae3f9
+                (type == GF_CLUSTER_TYPE_DISPERSE)) {
9ae3f9
+                ret = glusterd_check_brick_order(dict, msg, type);
9ae3f9
+                if (ret) {
9ae3f9
+                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
9ae3f9
+                           "Not creating volume because of "
9ae3f9
+                           "bad brick order");
9ae3f9
+                    goto out;
9ae3f9
+                }
9ae3f9
+            }
9ae3f9
+        }
9ae3f9
+    }
9ae3f9
+
9ae3f9
     while (i < brick_count) {
9ae3f9
         i++;
9ae3f9
         brick = strtok_r(brick_list, " \n", &tmpptr);
9ae3f9
@@ -1423,36 +1218,6 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
9ae3f9
         brick_info = NULL;
9ae3f9
     }
9ae3f9
 
9ae3f9
-    /*Check brick order if the volume type is replicate or disperse. If
9ae3f9
-     * force at the end of command not given then check brick order.
9ae3f9
-     */
9ae3f9
-    if (is_origin_glusterd(dict)) {
9ae3f9
-        ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
9ae3f9
-        if (ret) {
9ae3f9
-            snprintf(msg, sizeof(msg),
9ae3f9
-                     "Unable to get type of "
9ae3f9
-                     "volume %s",
9ae3f9
-                     volname);
9ae3f9
-            gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
9ae3f9
-                   msg);
9ae3f9
-            goto out;
9ae3f9
-        }
9ae3f9
-
9ae3f9
-        if (!is_force) {
9ae3f9
-            if ((type == GF_CLUSTER_TYPE_REPLICATE) ||
9ae3f9
-                (type == GF_CLUSTER_TYPE_DISPERSE)) {
9ae3f9
-                ret = glusterd_check_brick_order(dict, msg);
9ae3f9
-                if (ret) {
9ae3f9
-                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
9ae3f9
-                           "Not "
9ae3f9
-                           "creating volume because of "
9ae3f9
-                           "bad brick order");
9ae3f9
-                    goto out;
9ae3f9
-                }
9ae3f9
-            }
9ae3f9
-        }
9ae3f9
-    }
9ae3f9
-
9ae3f9
     ret = dict_set_int32n(rsp_dict, "brick_count", SLEN("brick_count"),
9ae3f9
                           local_brick_count);
9ae3f9
     if (ret) {
9ae3f9
-- 
9ae3f9
1.8.3.1
9ae3f9