12a457
From 53092bbaab60944c19e7477940d3edd140e7e720 Mon Sep 17 00:00:00 2001
12a457
From: Atin Mukherjee <amukherj@redhat.com>
12a457
Date: Tue, 26 Apr 2016 15:27:43 +0530
12a457
Subject: [PATCH 105/139] glusterd: persist brickinfo->real_path
12a457
12a457
Backport of http://review.gluster.org/14124
12a457
            http://review.gluster.org/14075
12a457
12a457
Since real_path was not persisted and gets constructed at every glusterd
12a457
restart, glusterd will fail to come up if one of the brick's underlying file
12a457
system is crashed.
12a457
12a457
Solution is to construct real_path only once and get it persisted.
12a457
12a457
Change-Id: I97abc30372c1ffbbb2d43b716d7af09172147b47
12a457
BUG: 1330385
12a457
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
12a457
Reviewed-on: http://review.gluster.org/14075
12a457
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-by: Kaushal M <kaushal@redhat.com>
12a457
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
Reviewed-on: http://review.gluster.org/14124
12a457
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/73410
12a457
---
12a457
 xlators/mgmt/glusterd/src/glusterd-store.c |   39 ++++++++++++++++++----------
12a457
 xlators/mgmt/glusterd/src/glusterd-store.h |    1 +
12a457
 xlators/mgmt/glusterd/src/glusterd-utils.c |   24 +++++++++--------
12a457
 3 files changed, 39 insertions(+), 25 deletions(-)
12a457
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
index 8b76cbf..4408081 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
12a457
@@ -383,6 +383,11 @@ glusterd_store_brickinfo_write (int fd, glusterd_brickinfo_t *brickinfo)
12a457
         if (ret)
12a457
                 goto out;
12a457
 
12a457
+        ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_REAL_PATH,
12a457
+                                   brickinfo->path);
12a457
+        if (ret)
12a457
+                goto out;
12a457
+
12a457
         snprintf (value, sizeof(value), "%d", brickinfo->port);
12a457
         ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_PORT, value);
12a457
 
12a457
@@ -2314,6 +2319,10 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
12a457
                                     strlen (GLUSTERD_STORE_KEY_BRICK_PATH))) {
12a457
                                 strncpy (brickinfo->path, value,
12a457
                                          sizeof (brickinfo->path));
12a457
+                        } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_REAL_PATH,
12a457
+                                    strlen (GLUSTERD_STORE_KEY_BRICK_REAL_PATH))) {
12a457
+                                strncpy (brickinfo->real_path, value,
12a457
+                                         sizeof (brickinfo->real_path));
12a457
                         } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_PORT,
12a457
                                     strlen (GLUSTERD_STORE_KEY_BRICK_PORT))) {
12a457
                                 gf_string2int (value, &brickinfo->port);
12a457
@@ -2414,8 +2423,8 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
12a457
                  * snapshot or snapshot restored volume this would be done post
12a457
                  * creating the brick mounts
12a457
                  */
12a457
-                if (!volinfo->is_snap_volume &&
12a457
-                    gf_uuid_is_null (volinfo->restored_from_snap)) {
12a457
+                if (brickinfo->real_path[0] == '\0' && !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
@@ -3309,19 +3318,21 @@ glusterd_recreate_vol_brick_mounts (xlator_t  *this,
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
+                        if (brickinfo->real_path[0] == '\0') {
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
 
12a457
                 if (brick_mount_path) {
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
12a457
index 683edae..93096d9 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
12a457
@@ -90,6 +90,7 @@ typedef enum glusterd_store_ver_ac_{
12a457
 
12a457
 #define GLUSTERD_STORE_KEY_BRICK_HOSTNAME       "hostname"
12a457
 #define GLUSTERD_STORE_KEY_BRICK_PATH           "path"
12a457
+#define GLUSTERD_STORE_KEY_BRICK_REAL_PATH      "real_path"
12a457
 #define GLUSTERD_STORE_KEY_BRICK_PORT           "listen-port"
12a457
 #define GLUSTERD_STORE_KEY_BRICK_RDMA_PORT      "rdma.listen-port"
12a457
 #define GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED "decommissioned"
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
index d100ec3..1c6541c 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
@@ -1113,7 +1113,7 @@ glusterd_brickinfo_new_from_brick (char *brick,
12a457
         strncpy (new_brickinfo->hostname, hostname, 1024);
12a457
         strncpy (new_brickinfo->path, path, 1024);
12a457
 
12a457
-        if (construct_real_path) {
12a457
+        if (construct_real_path && new_brickinfo->real_path[0] == '\0') {
12a457
                 if (!realpath (new_brickinfo->path, abspath)) {
12a457
                         /* ENOENT indicates that brick path has not been created
12a457
                          * which is a valid scenario */
12a457
@@ -3103,17 +3103,19 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count,
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
+                if (new_brickinfo->real_path[0] == '\0') {
12a457
+                        if (!realpath (new_brickinfo->path, abspath)) {
12a457
+                                gf_msg (this->name, GF_LOG_CRITICAL, errno,
12a457
+                                        GD_MSG_BRICKINFO_CREATE_FAIL,
12a457
+                                        "realpath() failed for brick %s. The "
12a457
+                                        "underlying file system may be in bad "
12a457
+                                        "state", new_brickinfo->path);
12a457
+                                ret = -1;
12a457
+                                goto out;
12a457
+                        }
12a457
+                        strncpy (new_brickinfo->real_path, abspath,
12a457
+                                 strlen(abspath));
12a457
                 }
12a457
-                strncpy (new_brickinfo->real_path, abspath,
12a457
-                         strlen(abspath));
12a457
         }
12a457
 
12a457
         *brickinfo = new_brickinfo;
12a457
-- 
12a457
1.7.1
12a457