summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Hernandez <xhernandez@datalab.es>2013-05-23 11:13:25 +0200
committerKaleb KEITHLEY <kkeithle@redhat.com>2014-05-22 04:09:16 -0700
commit4f8f96c62b21185f27d8e76912a808af80e22608 (patch)
tree1ea2b76cc4c82d6233bdcee16624e0c6e15d21c7
parent27482ac4678ce7df56126bb9accfebceab1d9fa8 (diff)
storage/posix: do not dereference gfid symlinks before posix_handle_mkdir_hashes()
Whenever a new directory is created, its corresponding gfid file must also be created. This was done first calling MAKE_HANDLE_PATH() to get the path of the gfid file, then calling posix_handle_mkdir_hashes() to create the parent directories of the gfid, and finally creating the soft-link. In normal circumstances, the gfid we want to create won't exist and MAKE_HANDLE_PATH() will return a simple path to the new gfid. However if the volume is damaged and a self-heal is running, it is possible that we try to create an already existing gfid. In this case, MAKE_HANDLE_PATH() will return a path to the directory instead of the path to the gfid. To solve this problem, every time a path to a gfid is needed, a call to MAKE_HANDLE_ABSPATH() is made instead of the call to MAKE_HANDLE_PATH(). BUG: 1099955 Change-Id: I5bcd2b3c38d172c75946f33519e057e76d960a24 Signed-off-by: Xavier Hernandez <xhernandez@datalab.es> Reviewed-on: http://review.gluster.org/6737 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
-rwxr-xr-xtests/bugs/bug-859581.t47
-rw-r--r--xlators/storage/posix/src/posix-handle.c11
-rw-r--r--xlators/storage/posix/src/posix-handle.h13
3 files changed, 63 insertions, 8 deletions
diff --git a/tests/bugs/bug-859581.t b/tests/bugs/bug-859581.t
new file mode 100755
index 00000000000..f31e8b311ef
--- /dev/null
+++ b/tests/bugs/bug-859581.t
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2}
+EXPECT 'Created' volinfo_field $V0 'Status';
+TEST $CLI volume start $V0
+EXPECT 'Started' volinfo_field $V0 'Status';
+# Needed to be sure self-heal daemon is running
+sleep 5
+
+TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0;
+
+mkdir -p $M0/dir1/dir2
+
+TEST rm -f $(gf_get_gfid_backend_file_path $B0/${V0}1 "dir1")
+TEST rmdir $B0/${V0}1/dir1/dir2
+
+TEST $CLI volume heal $V0 full
+sleep 5
+
+TEST [ -d $B0/${V0}1/dir1/dir2 ]
+TEST [ ! -d $(gf_get_gfid_backend_file_path $B0/${V0}1 "dir1") ]
+
+# Stop the volume to flush caches and force symlink recreation
+TEST umount $M0
+TEST $CLI volume stop $V0
+EXPECT 'Stopped' volinfo_field $V0 'Status';
+TEST $CLI volume start $V0
+EXPECT 'Started' volinfo_field $V0 'Status';
+TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0;
+
+ls -l $M0/
+
+TEST [ -h $(gf_get_gfid_backend_file_path $B0/${V0}1 "dir1") ]
+
+TEST umount $M0
+TEST $CLI volume stop $V0
+TEST $CLI volume delete $V0
+
+cleanup
+
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c
index 33bf3db56a5..a19b3ff00f5 100644
--- a/xlators/storage/posix/src/posix-handle.c
+++ b/xlators/storage/posix/src/posix-handle.c
@@ -284,7 +284,6 @@ posix_handle_init (xlator_t *this)
struct posix_private *priv = NULL;
char *handle_pfx = NULL;
int ret = 0;
- int len = 0;
struct stat stbuf;
struct stat rootbuf;
struct stat exportbuf;
@@ -337,9 +336,7 @@ posix_handle_init (xlator_t *this)
stat (handle_pfx, &priv->handledir);
- len = posix_handle_path (this, gfid, NULL, NULL, 0);
- rootstr = alloca (len);
- posix_handle_path (this, gfid, NULL, rootstr, len);
+ MAKE_HANDLE_ABSPATH(rootstr, this, gfid);
ret = stat (rootstr, &rootbuf);
switch (ret) {
@@ -529,7 +526,7 @@ posix_handle_hard (xlator_t *this, const char *oldpath, uuid_t gfid, struct stat
int ret = -1;
- MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
+ MAKE_HANDLE_ABSPATH (newpath, this, gfid);
ret = lstat (newpath, &newbuf);
if (ret == -1 && errno != ENOENT) {
@@ -603,11 +600,9 @@ posix_handle_soft (xlator_t *this, const char *real_path, loc_t *loc,
struct stat newbuf;
int ret = -1;
-
- MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
+ MAKE_HANDLE_ABSPATH (newpath, this, gfid);
MAKE_HANDLE_RELPATH (oldpath, this, loc->pargfid, loc->name);
-
ret = lstat (newpath, &newbuf);
if (ret == -1 && errno != ENOENT) {
gf_log (this->name, GF_LOG_WARNING,
diff --git a/xlators/storage/posix/src/posix-handle.h b/xlators/storage/posix/src/posix-handle.h
index f1163b72795..51fb834d734 100644
--- a/xlators/storage/posix/src/posix-handle.h
+++ b/xlators/storage/posix/src/posix-handle.h
@@ -19,6 +19,10 @@
#include "xlator.h"
+#define HANDLE_ABSPATH_LEN(this) (POSIX_BASE_PATH_LEN(this) + \
+ SLEN("/" GF_HIDDEN_PATH "/00/00/" \
+ UUID0_STR) + 1)
+
#define LOC_HAS_ABSPATH(loc) ((loc) && (loc->path) && (loc->path[0] == '/'))
#define MAKE_REAL_PATH(var, this, path) do { \
@@ -58,6 +62,15 @@
} while (0)
+#define MAKE_HANDLE_ABSPATH(var, this, gfid) do { \
+ struct posix_private * __priv = this->private; \
+ int __len = HANDLE_ABSPATH_LEN(this); \
+ var = alloca(__len); \
+ snprintf(var, __len, "%s/" GF_HIDDEN_PATH "/%02x/%02x/%s", \
+ __priv->base_path, gfid[0], gfid[1], uuid_utoa(gfid)); \
+ } while (0)
+
+
#define MAKE_INODE_HANDLE(rpath, this, loc, iatt_p) do { \
if (uuid_is_null (loc->gfid)) { \
gf_log (this->name, GF_LOG_ERROR, \