e7a346
From 4c7460554f2f7c6515b77e70c878fc15d3813237 Mon Sep 17 00:00:00 2001
e7a346
From: Mohit Agrawal <moagrawal@redhat.com>
e7a346
Date: Sat, 4 Aug 2018 12:05:03 +0530
e7a346
Subject: [PATCH 344/351] glusterd: Compare volume_id before start/attach a
e7a346
 brick
e7a346
e7a346
Problem: After reboot a node brick is not coming up because
e7a346
         fsid comparison is failed before start a brick
e7a346
e7a346
Solution: Instead of comparing fsid compare volume_id to
e7a346
          resolve the same because fsid is changed after
e7a346
          reboot a node but volume_id persist as a xattr
e7a346
          on brick_root path at the time of creating a volume.
e7a346
e7a346
> Change-Id: Ic289aab1b4ebfd83bbcae8438fee26ae61a0fff4
e7a346
> fixes: bz#1612418
e7a346
> (Cherry pick from commit bd8fc26a278697c30537d879ea5402db7ebab577)
e7a346
> (Reviwed on upstream link https://review.gluster.org/#/c/glusterfs/+/20638/)
e7a346
e7a346
Change-Id: Ia183c1d67af662584debcb301171c35be5ac0d9d
e7a346
BUG: 1612098
e7a346
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/146835
e7a346
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 tests/{basic => bugs/glusterd}/bug-1595320.t |  9 +++---
e7a346
 xlators/mgmt/glusterd/src/glusterd-utils.c   | 47 ++++++++++++++++------------
e7a346
 2 files changed, 32 insertions(+), 24 deletions(-)
e7a346
 rename tests/{basic => bugs/glusterd}/bug-1595320.t (94%)
e7a346
e7a346
diff --git a/tests/basic/bug-1595320.t b/tests/bugs/glusterd/bug-1595320.t
e7a346
similarity index 94%
e7a346
rename from tests/basic/bug-1595320.t
e7a346
rename to tests/bugs/glusterd/bug-1595320.t
e7a346
index 9d856ee..f41df9d 100644
e7a346
--- a/tests/basic/bug-1595320.t
e7a346
+++ b/tests/bugs/glusterd/bug-1595320.t
e7a346
@@ -1,8 +1,8 @@
e7a346
 #!/bin/bash
e7a346
 
e7a346
-. $(dirname $0)/../include.rc
e7a346
-. $(dirname $0)/../volume.rc
e7a346
-. $(dirname $0)/../snapshot.rc
e7a346
+. $(dirname $0)/../../include.rc
e7a346
+. $(dirname $0)/../../volume.rc
e7a346
+. $(dirname $0)/../../snapshot.rc
e7a346
 
e7a346
 cleanup
e7a346
 
e7a346
@@ -52,7 +52,7 @@ EXPECT 0 count_brick_processes
e7a346
 
e7a346
 # Unmount 3rd brick root from node
e7a346
 brick_root=$L3
e7a346
-TEST umount -l $brick_root 2>/dev/null
e7a346
+_umount_lv 3
e7a346
 
e7a346
 # Start the volume only 2 brick should be start
e7a346
 TEST $CLI volume start $V0 force
e7a346
@@ -70,6 +70,7 @@ n=`ls -lrth /proc/$brick_pid/fd | grep -iw $L3 | grep -v ".glusterfs" | wc -l`
e7a346
 TEST [ $n -eq 0 ]
e7a346
 
e7a346
 # Mount the brick root
e7a346
+TEST mkdir -p $brick_root
e7a346
 TEST mount -t xfs -o nouuid  /dev/test_vg_3/brick_lvm $brick_root
e7a346
 
e7a346
 # Replace brick_pid file to test brick_attach code
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
index 6f7c787..1752425 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
@@ -5439,6 +5439,12 @@ attach_brick_callback (struct rpc_req *req, struct iovec *iov, int count,
e7a346
         frame->local = NULL;
e7a346
         frame->cookie = NULL;
e7a346
 
e7a346
+        if (!iov) {
e7a346
+              gf_log (frame->this->name, GF_LOG_ERROR, "iov is NULL");
e7a346
+              ret   = -1;
e7a346
+              goto out;
e7a346
+        }
e7a346
+
e7a346
         ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp);
e7a346
         if (ret < 0) {
e7a346
                 gf_log (frame->this->name, GF_LOG_ERROR, "XDR decoding error");
e7a346
@@ -6073,17 +6079,19 @@ glusterd_brick_start (glusterd_volinfo_t *volinfo,
e7a346
                       gf_boolean_t wait,
e7a346
                       gf_boolean_t only_connect)
e7a346
 {
e7a346
-        int                     ret   = -1;
e7a346
+        int                      ret   = -1;
e7a346
         xlator_t                *this = NULL;
e7a346
         glusterd_brickinfo_t    *other_brick;
e7a346
         glusterd_conf_t         *conf = NULL;
e7a346
-        int32_t                 pid                   = -1;
e7a346
-        char                    pidfile[PATH_MAX]     = {0};
e7a346
-        char                    socketpath[PATH_MAX]  = {0};
e7a346
-        char                    *brickpath            = NULL;
e7a346
+        int32_t                  pid                   = -1;
e7a346
+        char                     pidfile[PATH_MAX]     = {0};
e7a346
+        char                     socketpath[PATH_MAX]  = {0};
e7a346
+        char                    *brickpath             = NULL;
e7a346
         glusterd_volinfo_t      *other_vol;
e7a346
-        struct statvfs           brickstat = {0,};
e7a346
         gf_boolean_t             is_service_running = _gf_false;
e7a346
+        uuid_t                   volid                 = {0,};
e7a346
+        ssize_t                  size                  = -1;
e7a346
+
e7a346
 
e7a346
         this = THIS;
e7a346
         GF_ASSERT (this);
e7a346
@@ -6130,24 +6138,23 @@ glusterd_brick_start (glusterd_volinfo_t *volinfo,
e7a346
 
e7a346
         GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, conf);
e7a346
 
e7a346
-        ret = sys_statvfs (brickinfo->path, &brickstat);
e7a346
-        if (ret) {
e7a346
-                gf_msg (this->name, GF_LOG_ERROR,
e7a346
-                        errno, GD_MSG_BRICKINFO_CREATE_FAIL,
e7a346
-                        "failed to get statfs() call on brick %s",
e7a346
-                        brickinfo->path);
e7a346
+        /* Compare volume-id xattr is helpful to ensure the existence of a brick_root
e7a346
+           path before the start/attach a brick
e7a346
+        */
e7a346
+        size = sys_lgetxattr (brickinfo->path, GF_XATTR_VOL_ID_KEY, volid, 16);
e7a346
+        if (size != 16) {
e7a346
+                gf_log (this->name, GF_LOG_ERROR,
e7a346
+                        "Missing %s extended attribute on brick root (%s),"
e7a346
+                        " brick is deemed not to be a part of the volume (%s) ",
e7a346
+                        GF_XATTR_VOL_ID_KEY, brickinfo->path, volinfo->volname);
e7a346
                 goto out;
e7a346
         }
e7a346
 
e7a346
-        /* Compare fsid is helpful to ensure the existence of a brick_root
e7a346
-           path before the start/attach a brick
e7a346
-        */
e7a346
-        if (brickinfo->statfs_fsid &&
e7a346
-            (brickinfo->statfs_fsid != brickstat.f_fsid)) {
e7a346
+        if (strncmp (uuid_utoa (volinfo->volume_id), uuid_utoa(volid), GF_UUID_BUF_SIZE)) {
e7a346
                 gf_log (this->name, GF_LOG_ERROR,
e7a346
-                        "fsid comparison is failed it means Brick root path"
e7a346
-                        " %s is not created by glusterd, start/attach will also fail",
e7a346
-                        brickinfo->path);
e7a346
+                        "Mismatching %s extended attribute on brick root (%s),"
e7a346
+                        " brick is deemed not to be a part of the volume (%s)",
e7a346
+                        GF_XATTR_VOL_ID_KEY, brickinfo->path, volinfo->volname);
e7a346
                 goto out;
e7a346
         }
e7a346
         is_service_running = gf_is_service_running (pidfile, &pid;;
e7a346
-- 
e7a346
1.8.3.1
e7a346