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