12a457
From 197f0019e59283929484e19fb7b9f061985fad4f Mon Sep 17 00:00:00 2001
12a457
From: Mohammed Rafi KC <rkavunga@redhat.com>
12a457
Date: Fri, 1 Apr 2016 23:10:51 +0530
12a457
Subject: [PATCH 48/80] glusterd: fill real_path variable in brickinfo during volume import
12a457
12a457
Backport of http://review.gluster.org/#/c/13890
12a457
            http://review.gluster.org/#/c/13914
12a457
12a457
Variable "real_path" in brick info was used to store absolute path
12a457
and using this we check the availability of the newly added bricks.
12a457
12a457
But we were not populating the variable when we import a volume
12a457
from peers. That caused to reset the real_path variable to zero,
12a457
which resulted in validation failure for all new brick creation.
12a457
12a457
Change-Id: I62be7bf452f0dcdf6aec3a4ec33c2e1fba2951ca
12a457
BUG: 1323119
12a457
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
12a457
Reviewed-on: http://review.gluster.org/13890
12a457
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
12a457
Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/71498
12a457
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
---
12a457
 .../bug-1323287-real_path-handshake-test.t         |   39 ++++++++++++++++++++
12a457
 xlators/mgmt/glusterd/src/glusterd-utils.c         |   15 ++++++++
12a457
 2 files changed, 54 insertions(+), 0 deletions(-)
12a457
 create mode 100644 tests/bugs/glusterd/bug-1323287-real_path-handshake-test.t
12a457
12a457
diff --git a/tests/bugs/glusterd/bug-1323287-real_path-handshake-test.t b/tests/bugs/glusterd/bug-1323287-real_path-handshake-test.t
12a457
new file mode 100644
12a457
index 0000000..12b722b
12a457
--- /dev/null
12a457
+++ b/tests/bugs/glusterd/bug-1323287-real_path-handshake-test.t
12a457
@@ -0,0 +1,39 @@
12a457
+#!/bin/bash
12a457
+
12a457
+. $(dirname $0)/../../include.rc
12a457
+. $(dirname $0)/../../cluster.rc
12a457
+. $(dirname $0)/../../volume.rc
12a457
+
12a457
+function volume_get_field()
12a457
+{
12a457
+     local vol=$1
12a457
+     local field=$2
12a457
+     $CLI_2 volume get $vol $field | tail -1 | awk '{print $2}'
12a457
+}
12a457
+
12a457
+cleanup;
12a457
+TEST launch_cluster 2;
12a457
+TEST $CLI_1 peer probe $H2;
12a457
+
12a457
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
12a457
+
12a457
+TEST $CLI_1 volume create $V0 $H1:$B1/$V0  $H2:$B2/$V0
12a457
+EXPECT 'Created' cluster_volinfo_field 1 $V0 'Status';
12a457
+
12a457
+TEST $CLI_1 volume start $V0
12a457
+EXPECT 'Started' cluster_volinfo_field 1 $V0 'Status';
12a457
+
12a457
+#kill glusterd2 and do a volume set command to change the version
12a457
+kill_glusterd 2
12a457
+
12a457
+TEST $CLI_1 volume set $V0 performance.write-behind off
12a457
+TEST start_glusterd 2;
12a457
+
12a457
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
12a457
+
12a457
+#Check for handshake completion.
12a457
+EXPECT_WITHIN $PROBE_TIMEOUT 'off' volume_get_field $V0 'write-behind'
12a457
+
12a457
+#During hanndshake, if we failed to populate real_path,
12a457
+#then volume create will fail.
12a457
+TEST $CLI_1 volume create $V1 $H1:$B1/$V1  $H2:$B2/$V1
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
index 639404a..97b2e31 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
@@ -3029,6 +3029,7 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count,
12a457
         char                    msg[2048] = {0};
12a457
         xlator_t                *this     = NULL;
12a457
         char                    *brick_uuid_str = NULL;
12a457
+        char                    abspath[PATH_MAX] = {0};
12a457
 
12a457
         this = THIS;
12a457
         GF_ASSERT (this);
12a457
@@ -3092,7 +3093,21 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count,
12a457
         ret = dict_get_str (peer_data, key, &brick_uuid_str);
12a457
         if (ret)
12a457
                 goto out;
12a457
+
12a457
         gf_uuid_parse (brick_uuid_str, new_brickinfo->uuid);
12a457
+        if (!gf_uuid_compare(new_brickinfo->uuid, MY_UUID)) {
12a457
+                if (!realpath (new_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 underlying file "
12a457
+                                "system may be in bad state",
12a457
+                                new_brickinfo->path);
12a457
+                        ret = -1;
12a457
+                        goto out;
12a457
+                }
12a457
+                strncpy (new_brickinfo->real_path, abspath,
12a457
+                         strlen(abspath));
12a457
+        }
12a457
 
12a457
         *brickinfo = new_brickinfo;
12a457
 out:
12a457
-- 
12a457
1.7.1
12a457