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