21ab4e
From 06bd636d7b453c17190389ae456b1e4369b6bfc9 Mon Sep 17 00:00:00 2001
21ab4e
From: Ravishankar N <ravishankar@redhat.com>
21ab4e
Date: Thu, 15 Jun 2017 15:36:07 +0530
21ab4e
Subject: [PATCH 515/525] index: Do not proceed with init if brick is not
21ab4e
 mounted
21ab4e
21ab4e
Backport of: https://review.gluster.org/17426
21ab4e
21ab4e
..or else when a volume start force is given, we end up creating
21ab4e
/brick-path/.glusterfs/indices folder and various subdirs under it and
21ab4e
eventually starting the brick process.
21ab4e
21ab4e
As a part of this patch, glusterd_get_index_basepath() is added in
21ab4e
glusterd, who will then use it to create the basepath during
21ab4e
volume-create, add-brick, replace-brick and reset-brick. It also uses this
21ab4e
function to set the 'index-base' xlator option for the index translator.
21ab4e
21ab4e
Change-Id: I2d9180d591b1a4effd1376c4343f20e68dfbac5e
21ab4e
BUG: 1455022
21ab4e
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/109354
21ab4e
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 tests/basic/afr/resolve.t                   |  5 +++++
21ab4e
 tests/bugs/replicate/bug-1130892.t          |  5 +++++
21ab4e
 tests/bugs/replicate/bug-1402730.t          |  6 ++++++
21ab4e
 tests/bugs/replicate/bug-830665.t           |  5 +++++
21ab4e
 xlators/features/index/src/index.c          |  7 +++++++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-utils.c  | 18 ++++++++++++++++--
21ab4e
 xlators/mgmt/glusterd/src/glusterd-utils.h  | 11 +++++++++++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-volgen.c |  5 +++--
21ab4e
 8 files changed, 58 insertions(+), 4 deletions(-)
21ab4e
21ab4e
diff --git a/tests/basic/afr/resolve.t b/tests/basic/afr/resolve.t
21ab4e
index 2d40056..f7351f8 100644
21ab4e
--- a/tests/basic/afr/resolve.t
21ab4e
+++ b/tests/basic/afr/resolve.t
21ab4e
@@ -23,6 +23,11 @@ echo abc > g
21ab4e
 TEST kill_brick $V0 $H0 $B0/${V0}0
21ab4e
 rm -rf $B0/${V0}0/.glusterfs $B0/${V0}0/a
21ab4e
 
21ab4e
+#Ideally, disk replacement is done using reset-brick or replace-brick gluster CLI
21ab4e
+#which will create .glusterfs/indices folder.
21ab4e
+mkdir $B0/${V0}0/.glusterfs && chmod 600 $B0/${V0}0/.glusterfs
21ab4e
+mkdir $B0/${V0}0/.glusterfs/indices && chmod 600 $B0/${V0}0/.glusterfs/indices
21ab4e
+
21ab4e
 TEST $CLI volume start $V0 force
21ab4e
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_meta $M0 $V0-replicate-0 0
21ab4e
 #Test that the lookup returns ENOENT instead of ESTALE
21ab4e
diff --git a/tests/bugs/replicate/bug-1130892.t b/tests/bugs/replicate/bug-1130892.t
21ab4e
index 7442ab8..9005791 100644
21ab4e
--- a/tests/bugs/replicate/bug-1130892.t
21ab4e
+++ b/tests/bugs/replicate/bug-1130892.t
21ab4e
@@ -39,6 +39,11 @@ TEST kill_brick $V0 $H0 $B0/${V0}-1
21ab4e
 TEST rm -rf $B0/${V0}-1/one
21ab4e
 TEST rm -rf $B0/${V0}-1/.glusterfs
21ab4e
 
21ab4e
+#Ideally, disk replacement is done using reset-brick or replace-brick gluster CLI
21ab4e
+#which will create .glusterfs/indices folder.
21ab4e
+mkdir $B0/${V0}-1/.glusterfs && chmod 600 $B0/${V0}-1/.glusterfs
21ab4e
+mkdir $B0/${V0}-1/.glusterfs/indices && chmod 600 $B0/${V0}-1/.glusterfs/indices
21ab4e
+
21ab4e
 # Start force
21ab4e
 TEST $CLI volume start $V0 force
21ab4e
 
21ab4e
diff --git a/tests/bugs/replicate/bug-1402730.t b/tests/bugs/replicate/bug-1402730.t
21ab4e
index c6768a0..1384f99 100644
21ab4e
--- a/tests/bugs/replicate/bug-1402730.t
21ab4e
+++ b/tests/bugs/replicate/bug-1402730.t
21ab4e
@@ -22,6 +22,12 @@ cd $M0/a/b/c
21ab4e
 TEST kill_brick $V0 $H0 $B0/${V0}2
21ab4e
 rm -rf $B0/${V0}2/*
21ab4e
 rm -rf $B0/${V0}2/.glusterfs
21ab4e
+
21ab4e
+#Ideally, disk replacement is done using reset-brick or replace-brick gluster CLI
21ab4e
+#which will create .glusterfs/indices folder.
21ab4e
+mkdir $B0/${V0}2/.glusterfs && chmod 600 $B0/${V0}2/.glusterfs
21ab4e
+mkdir $B0/${V0}2/.glusterfs/indices && chmod 600 $B0/${V0}2/.glusterfs/indices
21ab4e
+
21ab4e
 TEST $CLI volume start $V0 force
21ab4e
 
21ab4e
 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 0
21ab4e
diff --git a/tests/bugs/replicate/bug-830665.t b/tests/bugs/replicate/bug-830665.t
21ab4e
index c748c13..d044dae 100755
21ab4e
--- a/tests/bugs/replicate/bug-830665.t
21ab4e
+++ b/tests/bugs/replicate/bug-830665.t
21ab4e
@@ -76,6 +76,11 @@ volid=$(getfattr -e hex -n trusted.glusterfs.volume-id $B0/${V0}-0 2> /dev/null
21ab4e
 	| grep = | cut -d= -f2)
21ab4e
 rm -rf $B0/${V0}-0;
21ab4e
 mkdir $B0/${V0}-0;
21ab4e
+#Ideally, disk replacement is done using reset-brick or replace-brick gluster CLI
21ab4e
+#which will create .glusterfs/indices folder.
21ab4e
+mkdir $B0/${V0}-0/.glusterfs && chmod 600 $B0/${V0}-0/.glusterfs
21ab4e
+mkdir $B0/${V0}-0/.glusterfs/indices && chmod 600 $B0/${V0}-0/.glusterfs/indices
21ab4e
+
21ab4e
 setfattr -n trusted.glusterfs.volume-id -v $volid $B0/${V0}-0
21ab4e
 
21ab4e
 ## Restart and remount. Note that we use actimeo=0 so that the stat calls
21ab4e
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
21ab4e
index 29437d0..fd84997 100644
21ab4e
--- a/xlators/features/index/src/index.c
21ab4e
+++ b/xlators/features/index/src/index.c
21ab4e
@@ -2335,6 +2335,13 @@ init (xlator_t *this)
21ab4e
         }
21ab4e
 
21ab4e
         GF_OPTION_INIT ("index-base", priv->index_basepath, path, out);
21ab4e
+        if (gf_lstat_dir (priv->index_basepath, NULL) != 0) {
21ab4e
+                ret = -1;
21ab4e
+                gf_log (this->name, GF_LOG_ERROR,
21ab4e
+                        "Failed to find index basepath %s.",
21ab4e
+                         priv->index_basepath);
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
 
21ab4e
         GF_OPTION_INIT ("xattrop64-watchlist", watchlist, str, out);
21ab4e
         ret = index_make_xattrop_watchlist (this, priv, watchlist,
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
21ab4e
index 5450be4..fcb4340 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
21ab4e
@@ -1329,6 +1329,7 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
21ab4e
         struct stat  root_st             = {0,};
21ab4e
         char         msg[2048]           = {0,};
21ab4e
         gf_boolean_t is_created          = _gf_false;
21ab4e
+        char         index_basepath[PATH_MAX] = {0};
21ab4e
 
21ab4e
         ret = sys_mkdir (brickinfo->path, 0777);
21ab4e
         if (ret) {
21ab4e
@@ -1343,6 +1344,18 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
21ab4e
                 is_created = _gf_true;
21ab4e
         }
21ab4e
 
21ab4e
+        glusterd_get_index_basepath (brickinfo, index_basepath,
21ab4e
+                                     sizeof(index_basepath));
21ab4e
+
21ab4e
+        ret = mkdir_p (index_basepath, 0600, _gf_true);
21ab4e
+        if (ret && (errno != EEXIST)) {
21ab4e
+                snprintf (msg, sizeof (msg), "Failed to create index "
21ab4e
+                          "basepath (%s) for brick %s:%s. Reason : %s ",
21ab4e
+                          index_basepath, brickinfo->hostname,
21ab4e
+                          brickinfo->path, strerror (errno));
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
         ret = sys_lstat (brickinfo->path, &brick_st);
21ab4e
         if (ret) {
21ab4e
                 snprintf (msg, sizeof (msg), "lstat failed on %s. Reason : %s",
21ab4e
@@ -1422,8 +1435,9 @@ glusterd_validate_and_create_brickpath (glusterd_brickinfo_t *brickinfo,
21ab4e
         ret = 0;
21ab4e
 
21ab4e
 out:
21ab4e
-        if (ret && is_created)
21ab4e
-                sys_rmdir (brickinfo->path);
21ab4e
+        if (ret && is_created) {
21ab4e
+                recursive_rmdir (brickinfo->path);
21ab4e
+        }
21ab4e
         if (ret && !*op_errstr && msg[0] != '\0')
21ab4e
                 *op_errstr = gf_strdup (msg);
21ab4e
 
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
21ab4e
index c8e1667..e717c40 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
21ab4e
@@ -830,4 +830,15 @@ glusterd_brick_op_prerequisites (dict_t *dict,
21ab4e
 int
21ab4e
 glusterd_get_volinfo_from_brick (char *brick, glusterd_volinfo_t **volinfo);
21ab4e
 
21ab4e
+#define INDEX_BASEPATH ".glusterfs/indices"
21ab4e
+static inline void
21ab4e
+glusterd_get_index_basepath (glusterd_brickinfo_t *brickinfo, char *buffer,
21ab4e
+                             size_t size)
21ab4e
+{
21ab4e
+        if (!buffer)
21ab4e
+                return;
21ab4e
+        snprintf (buffer, size, "%s/%s", brickinfo->path, INDEX_BASEPATH);
21ab4e
+
21ab4e
+}
21ab4e
+
21ab4e
 #endif
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
index 55cd430..701cccf 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
21ab4e
@@ -1872,8 +1872,9 @@ brick_graph_add_index (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
21ab4e
         if (!xl)
21ab4e
                 goto out;
21ab4e
 
21ab4e
-        snprintf (index_basepath, sizeof (index_basepath), "%s/%s",
21ab4e
-                  brickinfo->path, ".glusterfs/indices");
21ab4e
+        glusterd_get_index_basepath (brickinfo, index_basepath,
21ab4e
+                                     sizeof(index_basepath));
21ab4e
+
21ab4e
         ret = xlator_set_option (xl, "index-base", index_basepath);
21ab4e
         if (ret)
21ab4e
                 goto out;
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e