12a457
From 5e67c691c1d61e23788835a8f7d3fc66a5d9cf42 Mon Sep 17 00:00:00 2001
12a457
From: Atin Mukherjee <amukherj@redhat.com>
12a457
Date: Thu, 31 Mar 2016 14:58:02 +0530
12a457
Subject: [PATCH 47/80] glusterd: build realpath post recreate of brick mount for snapshot
12a457
12a457
Backport of http://review.gluster.org/#/c/13869
12a457
            http://review.gluster.org/#/c/13905
12a457
12a457
Commit a60c39d introduced a new field called real_path in brickinfo to hold the
12a457
realpath() conversion. However at restore path for all snapshots and snapshot
12a457
restored volumes the brickpath gets recreated post restoration of bricks  which
12a457
means the realpath () call will fail here for all the snapshots and cloned
12a457
volumes.
12a457
12a457
Fix is to store the realpath for snapshots and clones post recreating the brick
12a457
mounts. For normal volume it would be done during retrieving the brick details
12a457
from the store.
12a457
12a457
Change-Id: Ia34853acddb28bcb7f0f70ca85fabcf73276ef13
12a457
BUG: 1322765
12a457
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
12a457
Reviewed-on: http://review.gluster.org/13869
12a457
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-by: Avra Sengupta <asengupt@redhat.com>
12a457
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/71478
12a457
---
12a457
 .../bug-1322772-real-path-fix-for-snapshot.t       |   34 ++++++++++++
12a457
 xlators/mgmt/glusterd/src/glusterd-store.c         |   58 ++++++++++++++------
12a457
 2 files changed, 76 insertions(+), 16 deletions(-)
12a457
 create mode 100644 tests/bugs/snapshot/bug-1322772-real-path-fix-for-snapshot.t
12a457
12a457
diff --git a/tests/bugs/snapshot/bug-1322772-real-path-fix-for-snapshot.t b/tests/bugs/snapshot/bug-1322772-real-path-fix-for-snapshot.t
12a457
new file mode 100644
12a457
index 0000000..68dc0bb
12a457
--- /dev/null
12a457
+++ b/tests/bugs/snapshot/bug-1322772-real-path-fix-for-snapshot.t
12a457
@@ -0,0 +1,34 @@
12a457
+#!/bin/bash
12a457
+
12a457
+. $(dirname $0)/../../volume.rc
12a457
+. $(dirname $0)/../../snapshot.rc
12a457
+. $(dirname $0)/../../include.rc
12a457
+cleanup;
12a457
+
12a457
+TEST verify_lvm_version
12a457
+TEST init_n_bricks 1
12a457
+TEST setup_lvm 1
12a457
+
12a457
+TEST glusterd
12a457
+TEST pidof glusterd
12a457
+
12a457
+TEST $CLI volume create $V0 $H0:$L1
12a457
+EXPECT 'Created' volinfo_field $V0 'Status'
12a457
+
12a457
+TEST $CLI volume start $V0
12a457
+EXPECT 'Started' volinfo_field $V0 'Status'
12a457
+
12a457
+TEST $CLI snapshot create ${V0}_snap $V0
12a457
+
12a457
+# Simulate a node reboot by unmounting the brick, snap_brick and followed by
12a457
+# deleting the brick. Now once glusterd restarts, it should be able to construct
12a457
+# and remount the snap brick
12a457
+snap_brick=`gluster snap status | grep "Brick Path" | awk -F ":"  '{print $3}'`
12a457
+
12a457
+pkill gluster
12a457
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $L1
12a457
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $snap_brick
12a457
+rm -rf $snap_brick
12a457
+
12a457
+TEST glusterd
12a457
+TEST pidof glusterd
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
index 9a2420f..f16417f 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
@@ -2410,24 +2410,34 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
12a457
                        GLUSTERD_ASSIGN_BRICKID_TO_BRICKINFO (brickinfo, volinfo,
12a457
                                                              brickid++);
12a457
                 }
12a457
-                /* By now if the brick is a local brick then it will be able to
12a457
-                 * resolve which is the only thing we want now for checking
12a457
-                 * whether the brickinfo->uuid matches with MY_UUID for realpath
12a457
-                 * check. Hence do not handle error
12a457
+                /* Populate brickinfo->real_path for normal volumes, for
12a457
+                 * snapshot or snapshot restored volume this would be done post
12a457
+                 * creating the brick mounts
12a457
                  */
12a457
-                (void)glusterd_resolve_brick (brickinfo);
12a457
-                if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) {
12a457
-                        if (!realpath (brickinfo->path, abspath)) {
12a457
-                                gf_msg (this->name, GF_LOG_CRITICAL, errno,
12a457
-                                        GD_MSG_BRICKINFO_CREATE_FAIL, "realpath"
12a457
-                                        " () failed for brick %s. The "
12a457
-                                        "underlying file system may be in bad"
12a457
-                                        " state", brickinfo->path);
12a457
-                                ret = -1;
12a457
-                                goto out;
12a457
+                if (!volinfo->is_snap_volume &&
12a457
+                    gf_uuid_is_null (volinfo->restored_from_snap)) {
12a457
+                        /* By now if the brick is a local brick then it will be
12a457
+                         * able to resolve which is the only thing we want now
12a457
+                         * for checking  whether the brickinfo->uuid matches
12a457
+                         * with MY_UUID for realpath check. Hence do not handle
12a457
+                         * error
12a457
+                         */
12a457
+                        (void)glusterd_resolve_brick (brickinfo);
12a457
+                        if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) {
12a457
+                                if (!realpath (brickinfo->path, abspath)) {
12a457
+                                        gf_msg (this->name, GF_LOG_CRITICAL,
12a457
+                                                errno,
12a457
+                                                GD_MSG_BRICKINFO_CREATE_FAIL,
12a457
+                                                "realpath() failed for brick %s"
12a457
+                                                ". The underlying file system "
12a457
+                                                "may be in bad state",
12a457
+                                                brickinfo->path);
12a457
+                                        ret = -1;
12a457
+                                        goto out;
12a457
+                                }
12a457
+                                strncpy (brickinfo->real_path, abspath,
12a457
+                                         strlen(abspath));
12a457
                         }
12a457
-                        strncpy (brickinfo->real_path, abspath,
12a457
-                                 strlen(abspath));
12a457
                 }
12a457
                 cds_list_add_tail (&brickinfo->brick_list, &volinfo->bricks);
12a457
                 brick_count++;
12a457
@@ -3241,6 +3251,7 @@ glusterd_recreate_vol_brick_mounts (xlator_t  *this,
12a457
         glusterd_brickinfo_t    *brickinfo           = NULL;
12a457
         int32_t                  ret                 = -1;
12a457
         struct stat              st_buf              = {0, };
12a457
+        char                     abspath[PATH_MAX]   = {0};
12a457
 
12a457
         GF_ASSERT (this);
12a457
         GF_ASSERT (volinfo);
12a457
@@ -3297,6 +3308,21 @@ glusterd_recreate_vol_brick_mounts (xlator_t  *this,
12a457
                                 GD_MSG_BRK_MNTPATH_MOUNT_FAIL,
12a457
                                 "Failed to mount brick_mount_path");
12a457
                 }
12a457
+                if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) {
12a457
+                        if (!realpath (brickinfo->path, abspath)) {
12a457
+                                gf_msg (this->name, GF_LOG_CRITICAL,
12a457
+                                        errno,
12a457
+                                        GD_MSG_BRICKINFO_CREATE_FAIL,
12a457
+                                        "realpath() failed for brick %s"
12a457
+                                        ". The underlying file system "
12a457
+                                        "may be in bad state",
12a457
+                                        brickinfo->path);
12a457
+                                ret = -1;
12a457
+                                goto out;
12a457
+                        }
12a457
+                        strncpy (brickinfo->real_path, abspath,
12a457
+                                 strlen(abspath));
12a457
+                }
12a457
 
12a457
                 if (brick_mount_path) {
12a457
                         GF_FREE (brick_mount_path);
12a457
-- 
12a457
1.7.1
12a457