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