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