87c3ef
From a04592cce9aaa6ccb8a038bc3b4e31bc125d1d10 Mon Sep 17 00:00:00 2001
87c3ef
From: Sanju Rakonde <srakonde@redhat.com>
87c3ef
Date: Tue, 16 Jun 2020 18:03:21 +0530
87c3ef
Subject: [PATCH 453/456] glusterd: add-brick command failure
87c3ef
87c3ef
Problem: add-brick operation is failing when replica or disperse
87c3ef
count is not mentioned in the add-brick command.
87c3ef
87c3ef
Reason: with commit a113d93 we are checking brick order while
87c3ef
doing add-brick operation for replica and disperse volumes. If
87c3ef
replica count or disperse count is not mentioned in the command,
87c3ef
the dict get is failing and resulting add-brick operation failure.
87c3ef
87c3ef
> upstream patch: https://review.gluster.org/#/c/glusterfs/+/24581/
87c3ef
> fixes: #1306
87c3ef
> Change-Id: Ie957540e303bfb5f2d69015661a60d7e72557353
87c3ef
> Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
87c3ef
87c3ef
BUG: 1847081
87c3ef
Change-Id: Ie957540e303bfb5f2d69015661a60d7e72557353
87c3ef
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
87c3ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/203867
87c3ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
87c3ef
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
87c3ef
---
87c3ef
 tests/bugs/glusterd/brick-order-check-add-brick.t | 40 ++++++++++++++++++++++
87c3ef
 tests/cluster.rc                                  | 11 ++++--
87c3ef
 xlators/mgmt/glusterd/src/glusterd-brick-ops.c    | 39 ++++++++++++++-------
87c3ef
 xlators/mgmt/glusterd/src/glusterd-utils.c        | 30 ++---------------
87c3ef
 xlators/mgmt/glusterd/src/glusterd-utils.h        |  3 +-
87c3ef
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c   | 41 +++++++++++++++++++----
87c3ef
 6 files changed, 115 insertions(+), 49 deletions(-)
87c3ef
 create mode 100644 tests/bugs/glusterd/brick-order-check-add-brick.t
87c3ef
87c3ef
diff --git a/tests/bugs/glusterd/brick-order-check-add-brick.t b/tests/bugs/glusterd/brick-order-check-add-brick.t
87c3ef
new file mode 100644
87c3ef
index 0000000..29f0ed1
87c3ef
--- /dev/null
87c3ef
+++ b/tests/bugs/glusterd/brick-order-check-add-brick.t
87c3ef
@@ -0,0 +1,40 @@
87c3ef
+#!/bin/bash
87c3ef
+. $(dirname $0)/../../include.rc
87c3ef
+. $(dirname $0)/../../volume.rc
87c3ef
+. $(dirname $0)/../../cluster.rc
87c3ef
+. $(dirname $0)/../../snapshot.rc
87c3ef
+
87c3ef
+cleanup;
87c3ef
+
87c3ef
+TEST verify_lvm_version;
87c3ef
+#Create cluster with 3 nodes
87c3ef
+TEST launch_cluster 3 -NO_DEBUG -NO_FORCE
87c3ef
+TEST setup_lvm 3
87c3ef
+
87c3ef
+TEST $CLI_1 peer probe $H2
87c3ef
+TEST $CLI_1 peer probe $H3
87c3ef
+EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count
87c3ef
+
87c3ef
+TEST $CLI_1 volume create $V0 replica 3 $H1:$L1/$V0 $H2:$L2/$V0 $H3:$L3/$V0
87c3ef
+EXPECT '1 x 3 = 3' volinfo_field $V0 'Number of Bricks'
87c3ef
+EXPECT 'Created' volinfo_field $V0 'Status'
87c3ef
+
87c3ef
+TEST $CLI_1 volume start $V0
87c3ef
+EXPECT 'Started' volinfo_field $V0 'Status'
87c3ef
+
87c3ef
+#add-brick with or without mentioning the replica count should not fail
87c3ef
+TEST $CLI_1 volume add-brick $V0 replica 3 $H1:$L1/${V0}_1 $H2:$L2/${V0}_1 $H3:$L3/${V0}_1
87c3ef
+EXPECT '2 x 3 = 6' volinfo_field $V0 'Number of Bricks'
87c3ef
+
87c3ef
+TEST $CLI_1 volume add-brick $V0 $H1:$L1/${V0}_2 $H2:$L2/${V0}_2 $H3:$L3/${V0}_2
87c3ef
+EXPECT '3 x 3 = 9' volinfo_field $V0 'Number of Bricks'
87c3ef
+
87c3ef
+#adding bricks from same host should fail the brick order check
87c3ef
+TEST ! $CLI_1 volume add-brick $V0 $H1:$L1/${V0}_3 $H1:$L1/${V0}_4 $H1:$L1/${V0}_5
87c3ef
+EXPECT '3 x 3 = 9' volinfo_field $V0 'Number of Bricks'
87c3ef
+
87c3ef
+#adding bricks from same host with force should succeed
87c3ef
+TEST $CLI_1 volume add-brick $V0 $H1:$L1/${V0}_3 $H1:$L1/${V0}_4 $H1:$L1/${V0}_5 force
87c3ef
+EXPECT '4 x 3 = 12' volinfo_field $V0 'Number of Bricks'
87c3ef
+
87c3ef
+cleanup
87c3ef
diff --git a/tests/cluster.rc b/tests/cluster.rc
87c3ef
index 99be8e7..8b73153 100644
87c3ef
--- a/tests/cluster.rc
87c3ef
+++ b/tests/cluster.rc
87c3ef
@@ -11,7 +11,7 @@ function launch_cluster() {
87c3ef
     define_backends $count;
87c3ef
     define_hosts $count;
87c3ef
     define_glusterds $count $2;
87c3ef
-    define_clis $count;
87c3ef
+    define_clis $count $3;
87c3ef
 
87c3ef
     start_glusterds;
87c3ef
 }
87c3ef
@@ -133,8 +133,13 @@ function define_clis() {
87c3ef
         lopt1="--log-file=$logdir/$logfile1"
87c3ef
 
87c3ef
 
87c3ef
-        eval "CLI_$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt'";
87c3ef
-        eval "CLI$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt1'";
87c3ef
+        if [ "$2" == "-NO_FORCE" ]; then
87c3ef
+                eval "CLI_$i='$CLI_NO_FORCE --glusterd-sock=${!b}/glusterd/gd.sock $lopt'";
87c3ef
+                eval "CLI$i='$CLI_NO_FORCE --glusterd-sock=${!b}/glusterd/gd.sock $lopt1'";
87c3ef
+        else
87c3ef
+                eval "CLI_$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt'";
87c3ef
+                eval "CLI$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt1'";
87c3ef
+        fi
87c3ef
     done
87c3ef
 }
87c3ef
 
87c3ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
87c3ef
index 121346c..5ae577a 100644
87c3ef
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
87c3ef
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
87c3ef
@@ -1576,20 +1576,35 @@ glusterd_op_stage_add_brick(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
87c3ef
 
87c3ef
     /* Check brick order if the volume type is replicate or disperse. If
87c3ef
      * force at the end of command not given then check brick order.
87c3ef
+     * doing this check at the originator node is sufficient.
87c3ef
      */
87c3ef
 
87c3ef
-    if (!is_force) {
87c3ef
-        if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) ||
87c3ef
-            (volinfo->type == GF_CLUSTER_TYPE_DISPERSE)) {
87c3ef
-            ret = glusterd_check_brick_order(dict, msg, volinfo->type);
87c3ef
-            if (ret) {
87c3ef
-                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
87c3ef
-                       "Not adding brick because of "
87c3ef
-                       "bad brick order. %s",
87c3ef
-                       msg);
87c3ef
-                *op_errstr = gf_strdup(msg);
87c3ef
-                goto out;
87c3ef
-            }
87c3ef
+    if (is_origin_glusterd(dict) && !is_force) {
87c3ef
+        ret = 0;
87c3ef
+        if (volinfo->type == GF_CLUSTER_TYPE_REPLICATE) {
87c3ef
+            gf_msg_debug(this->name, 0,
87c3ef
+                         "Replicate cluster type "
87c3ef
+                         "found. Checking brick order.");
87c3ef
+            if (replica_count)
87c3ef
+                ret = glusterd_check_brick_order(dict, msg, volinfo->type,
87c3ef
+                                                 replica_count);
87c3ef
+            else
87c3ef
+                ret = glusterd_check_brick_order(dict, msg, volinfo->type,
87c3ef
+                                                 volinfo->replica_count);
87c3ef
+        } else if (volinfo->type == GF_CLUSTER_TYPE_DISPERSE) {
87c3ef
+            gf_msg_debug(this->name, 0,
87c3ef
+                         "Disperse cluster type"
87c3ef
+                         " found. Checking brick order.");
87c3ef
+            ret = glusterd_check_brick_order(dict, msg, volinfo->type,
87c3ef
+                                             volinfo->disperse_count);
87c3ef
+        }
87c3ef
+        if (ret) {
87c3ef
+            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
87c3ef
+                   "Not adding brick because of "
87c3ef
+                   "bad brick order. %s",
87c3ef
+                   msg);
87c3ef
+            *op_errstr = gf_strdup(msg);
87c3ef
+            goto out;
87c3ef
         }
87c3ef
     }
87c3ef
 
87c3ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
87c3ef
index 6f904ae..545e688 100644
87c3ef
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
87c3ef
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
87c3ef
@@ -14802,7 +14802,8 @@ glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next)
87c3ef
  * volume are present on the same server
87c3ef
  */
87c3ef
 int32_t
87c3ef
-glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type)
87c3ef
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type,
87c3ef
+                           int32_t sub_count)
87c3ef
 {
87c3ef
     int ret = -1;
87c3ef
     int i = 0;
87c3ef
@@ -14819,7 +14820,6 @@ glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type)
87c3ef
     char *tmpptr = NULL;
87c3ef
     char *volname = NULL;
87c3ef
     int32_t brick_count = 0;
87c3ef
-    int32_t sub_count = 0;
87c3ef
     struct addrinfo *ai_info = NULL;
87c3ef
     char brick_addr[128] = {
87c3ef
         0,
87c3ef
@@ -14870,31 +14870,6 @@ glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type)
87c3ef
         goto out;
87c3ef
     }
87c3ef
 
87c3ef
-    if (type != GF_CLUSTER_TYPE_DISPERSE) {
87c3ef
-        ret = dict_get_int32n(dict, "replica-count", SLEN("replica-count"),
87c3ef
-                              &sub_count);
87c3ef
-        if (ret) {
87c3ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
87c3ef
-                   "Bricks check : Could"
87c3ef
-                   " not retrieve replica count");
87c3ef
-            goto out;
87c3ef
-        }
87c3ef
-        gf_msg_debug(this->name, 0,
87c3ef
-                     "Replicate cluster type "
87c3ef
-                     "found. Checking brick order.");
87c3ef
-    } else {
87c3ef
-        ret = dict_get_int32n(dict, "disperse-count", SLEN("disperse-count"),
87c3ef
-                              &sub_count);
87c3ef
-        if (ret) {
87c3ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
87c3ef
-                   "Bricks check : Could"
87c3ef
-                   " not retrieve disperse count");
87c3ef
-            goto out;
87c3ef
-        }
87c3ef
-        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DISPERSE_CLUSTER_FOUND,
87c3ef
-               "Disperse cluster type"
87c3ef
-               " found. Checking brick order.");
87c3ef
-    }
87c3ef
     brick_list_dup = brick_list_ptr = gf_strdup(brick_list);
87c3ef
     /* Resolve hostnames and get addrinfo */
87c3ef
     while (i < brick_count) {
87c3ef
@@ -14989,5 +14964,6 @@ out:
87c3ef
         ai_list_tmp2 = ai_list_tmp1;
87c3ef
     }
87c3ef
     free(ai_list_tmp2);
87c3ef
+    gf_msg_debug("glusterd", 0, "Returning %d", ret);
87c3ef
     return ret;
87c3ef
 }
87c3ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
87c3ef
index e2e2454..5f5de82 100644
87c3ef
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
87c3ef
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
87c3ef
@@ -883,6 +883,7 @@ char *
87c3ef
 search_brick_path_from_proc(pid_t brick_pid, char *brickpath);
87c3ef
 
87c3ef
 int32_t
87c3ef
-glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type);
87c3ef
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type,
87c3ef
+                           int32_t sub_count);
87c3ef
 
87c3ef
 #endif
87c3ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
87c3ef
index 8da2ff3..134b04c 100644
87c3ef
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
87c3ef
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
87c3ef
@@ -1024,6 +1024,8 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
87c3ef
     int32_t local_brick_count = 0;
87c3ef
     int32_t i = 0;
87c3ef
     int32_t type = 0;
87c3ef
+    int32_t replica_count = 0;
87c3ef
+    int32_t disperse_count = 0;
87c3ef
     char *brick = NULL;
87c3ef
     char *tmpptr = NULL;
87c3ef
     xlator_t *this = NULL;
87c3ef
@@ -1119,15 +1121,42 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
87c3ef
         }
87c3ef
 
87c3ef
         if (!is_force) {
87c3ef
-            if ((type == GF_CLUSTER_TYPE_REPLICATE) ||
87c3ef
-                (type == GF_CLUSTER_TYPE_DISPERSE)) {
87c3ef
-                ret = glusterd_check_brick_order(dict, msg, type);
87c3ef
+            if (type == GF_CLUSTER_TYPE_REPLICATE) {
87c3ef
+                ret = dict_get_int32n(dict, "replica-count",
87c3ef
+                                      SLEN("replica-count"), &replica_count);
87c3ef
                 if (ret) {
87c3ef
-                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
87c3ef
-                           "Not creating volume because of "
87c3ef
-                           "bad brick order");
87c3ef
+                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
87c3ef
+                           "Bricks check : Could"
87c3ef
+                           " not retrieve replica count");
87c3ef
+                    goto out;
87c3ef
+                }
87c3ef
+                gf_msg_debug(this->name, 0,
87c3ef
+                             "Replicate cluster type "
87c3ef
+                             "found. Checking brick order.");
87c3ef
+                ret = glusterd_check_brick_order(dict, msg, type,
87c3ef
+                                                 replica_count);
87c3ef
+            } else if (type == GF_CLUSTER_TYPE_DISPERSE) {
87c3ef
+                ret = dict_get_int32n(dict, "disperse-count",
87c3ef
+                                      SLEN("disperse-count"), &disperse_count);
87c3ef
+                if (ret) {
87c3ef
+                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
87c3ef
+                           "Bricks check : Could"
87c3ef
+                           " not retrieve disperse count");
87c3ef
                     goto out;
87c3ef
                 }
87c3ef
+                gf_msg_debug(this->name, 0,
87c3ef
+                             "Disperse cluster type"
87c3ef
+                             " found. Checking brick order.");
87c3ef
+                ret = glusterd_check_brick_order(dict, msg, type,
87c3ef
+                                                 disperse_count);
87c3ef
+            }
87c3ef
+            if (ret) {
87c3ef
+                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
87c3ef
+                       "Not creating the volume because of "
87c3ef
+                       "bad brick order. %s",
87c3ef
+                       msg);
87c3ef
+                *op_errstr = gf_strdup(msg);
87c3ef
+                goto out;
87c3ef
             }
87c3ef
         }
87c3ef
     }
87c3ef
-- 
87c3ef
1.8.3.1
87c3ef