diff options
author | Xavier Hernandez <xhernandez@datalab.es> | 2013-05-23 11:13:25 +0200 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2014-05-05 06:38:03 -0700 |
commit | b3fd7004a4a579c64ed29ee7eeb7e0fa57a3591f (patch) | |
tree | b7d783dfdf8e28693ec5f4016530ed3a9eba644f /xlators | |
parent | f863a9b69ecc9513b74cb07cb199f0c0ff38104e (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: 859581
Change-Id: I84405bf04562e647fc02445f45358e9451f9b479
Signed-off-by: Xavier Hernandez <xhernandez@datalab.es>
Reviewed-on: http://review.gluster.org/6736
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/storage/posix/src/posix-handle.c | 11 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-handle.h | 13 |
2 files changed, 16 insertions, 8 deletions
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c index 1d8e986314f..991b991874e 100644 --- a/xlators/storage/posix/src/posix-handle.c +++ b/xlators/storage/posix/src/posix-handle.c @@ -438,7 +438,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; @@ -491,9 +490,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) { @@ -683,7 +680,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) { @@ -750,11 +747,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 8874ca2655f..38da908545e 100644 --- a/xlators/storage/posix/src/posix-handle.h +++ b/xlators/storage/posix/src/posix-handle.h @@ -25,6 +25,10 @@ #define UUID0_STR "00000000-0000-0000-0000-000000000000" #define SLEN(str) (sizeof(str) - 1) +#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_PGFID_XATTR_KEY(var, prefix, pgfid) do { \ @@ -134,6 +138,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, \ |