summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage/posix/src')
-rw-r--r--xlators/storage/posix/src/Makefile.am4
-rw-r--r--xlators/storage/posix/src/posix-handle.c621
-rw-r--r--xlators/storage/posix/src/posix-handle.h148
-rw-r--r--xlators/storage/posix/src/posix-helpers.c323
-rw-r--r--xlators/storage/posix/src/posix.c730
-rw-r--r--xlators/storage/posix/src/posix.h36
6 files changed, 1313 insertions, 549 deletions
diff --git a/xlators/storage/posix/src/Makefile.am b/xlators/storage/posix/src/Makefile.am
index 90ea1fd51ee..d1d420017e7 100644
--- a/xlators/storage/posix/src/Makefile.am
+++ b/xlators/storage/posix/src/Makefile.am
@@ -4,10 +4,10 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage
posix_la_LDFLAGS = -module -avoidversion
-posix_la_SOURCES = posix.c posix-helpers.c
+posix_la_SOURCES = posix.c posix-helpers.c posix-handle.c
posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
-noinst_HEADERS = posix.h posix-mem-types.h
+noinst_HEADERS = posix.h posix-mem-types.h posix-handle.h
AM_CFLAGS = -fPIC -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE \
-D$(GF_HOST_OS) -Wall -I$(top_srcdir)/libglusterfs/src -shared \
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c
new file mode 100644
index 00000000000..b0693324d32
--- /dev/null
+++ b/xlators/storage/posix/src/posix-handle.c
@@ -0,0 +1,621 @@
+/*
+ Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <alloca.h>
+
+#include "posix-handle.h"
+#include "posix.h"
+#include "xlator.h"
+
+
+#define HANDLE_PFX ".glusterfs"
+
+#define UUID0_STR "00000000-0000-0000-0000-000000000000"
+#define SLEN(str) (sizeof(str) - 1)
+
+
+int
+posix_handle_relpath (xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t buflen)
+{
+ char *uuid_str = NULL;
+ int len = 0;
+
+ len = SLEN("../")
+ + SLEN("../")
+ + SLEN("00/")
+ + SLEN("00/")
+ + SLEN(UUID0_STR)
+ + 1 /* '\0' */
+ ;
+
+ if (basename) {
+ len += (strlen (basename) + 1);
+ }
+
+ if (buflen < len || !buf)
+ return len;
+
+ uuid_str = uuid_utoa (gfid);
+
+ if (basename) {
+ len = snprintf (buf, buflen, "../../%02x/%02x/%s/%s",
+ gfid[0], gfid[1], uuid_str, basename);
+ } else {
+ len = snprintf (buf, buflen, "../../%02x/%02x/%s",
+ gfid[0], gfid[1], uuid_str);
+ }
+
+ return len;
+}
+
+
+/*
+ TODO: explain how this pump fixes ELOOP
+*/
+int
+posix_handle_pump (xlator_t *this, char *buf, int len, int maxlen,
+ char *base_str, int base_len, int pfx_len)
+{
+ char linkname[512] = {0,}; /* "../../<gfid>/<NAME_MAX>" */
+ int ret = 0;
+ int blen = 0;
+ int link_len = 0;
+
+ /* is a directory's symlink-handle */
+ ret = readlink (base_str, linkname, 512);
+ if (ret == -1) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "internal readlink failed on %s (%s)",
+ base_str, strerror (errno));
+ goto err;
+ }
+
+ if (ret < 512)
+ linkname[ret] = 0;
+
+ link_len = ret;
+
+ if ((ret == 8) && memcmp (linkname, "../../..", 8) == 0) {
+ if (strcmp (base_str, buf) == 0) {
+ strncpy (buf + pfx_len, "..", 3);
+ }
+ goto out;
+ }
+
+ if (ret < 50 || ret >= 512) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "malformed internal link %s for %s",
+ linkname, base_str);
+ goto err;
+ }
+
+ if (memcmp (linkname, "../../", 6) != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "malformed internal link %s for %s",
+ linkname, base_str);
+ goto err;
+ }
+
+ if ((linkname[2] != '/') ||
+ (linkname[5] != '/') ||
+ (linkname[8] != '/') ||
+ (linkname[11] != '/') ||
+ (linkname[48] != '/')) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "malformed internal link %s for %s",
+ linkname, base_str);
+ goto err;
+ }
+
+ if ((linkname[20] != '-') ||
+ (linkname[25] != '-') ||
+ (linkname[30] != '-') ||
+ (linkname[35] != '-')) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "malformed internal link %s for %s",
+ linkname, base_str);
+ goto err;
+ }
+
+ blen = link_len - 48;
+ memmove (buf + base_len + blen, buf + base_len,
+ (strlen (buf) - base_len) + 1);
+
+ strncpy (base_str + pfx_len, linkname + 6, 42);
+
+ if (len + blen < maxlen)
+ strncpy (buf + pfx_len, linkname + 6, link_len - 6);
+out:
+ return len + blen;
+err:
+ return -1;
+}
+
+
+/*
+ posix_handle_path differs from posix_handle_gfid_path in the way that the
+ path filled in @buf by posix_handle_path will return type IA_IFDIR when
+ an lstat() is performed on it, whereas posix_handle_gfid_path returns path
+ to the handle symlink (typically used for the purpose of unlinking it).
+
+ posix_handle_path also guarantees immunity to ELOOP on the path returned by it
+*/
+
+int
+posix_handle_path (xlator_t *this, uuid_t gfid, const char *basename,
+ char *ubuf, size_t size)
+{
+ struct posix_private *priv = NULL;
+ char *uuid_str = NULL;
+ int len = 0;
+ int ret = -1;
+ struct stat stat;
+ char *base_str = NULL;
+ int base_len = 0;
+ int pfx_len;
+ int maxlen;
+ char *buf;
+
+ priv = this->private;
+
+ uuid_str = uuid_utoa (gfid);
+
+ if (ubuf) {
+ buf = ubuf;
+ maxlen = size;
+ } else {
+ maxlen = PATH_MAX;
+ buf = alloca (maxlen);
+ }
+
+ base_len = (priv->base_path_length + SLEN(HANDLE_PFX) + 45);
+ base_str = alloca (base_len + 1);
+ base_len = snprintf (base_str, base_len + 1, "%s/%s/%02x/%02x/%s",
+ priv->base_path, HANDLE_PFX, gfid[0], gfid[1],
+ uuid_str);
+
+ pfx_len = priv->base_path_length + 1 + SLEN(HANDLE_PFX) + 1;
+
+ if (basename) {
+ len = snprintf (buf, maxlen, "%s/%s", base_str, basename);
+ } else {
+ len = snprintf (buf, maxlen, "%s", base_str);
+ }
+
+ ret = lstat (base_str, &stat);
+
+ if (!(ret == 0 && S_ISLNK(stat.st_mode) && stat.st_nlink == 1))
+ goto out;
+
+ do {
+ errno = 0;
+ ret = posix_handle_pump (this, buf, len, maxlen,
+ base_str, base_len, pfx_len);
+ if (ret == -1)
+ break;
+
+ len = ret;
+
+ ret = lstat (buf, &stat);
+ } while ((ret == -1) && errno == ELOOP);
+
+out:
+ return len + 1;
+}
+
+
+int
+posix_handle_gfid_path (xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t buflen)
+{
+ struct posix_private *priv = NULL;
+ char *uuid_str = NULL;
+ int len = 0;
+
+ priv = this->private;
+
+ len = priv->base_path_length /* option directory "/export" */
+ + SLEN("/")
+ + SLEN(HANDLE_PFX)
+ + SLEN("/")
+ + SLEN("00/")
+ + SLEN("00/")
+ + SLEN(UUID0_STR)
+ + 1 /* '\0' */
+ ;
+
+ if (basename) {
+ len += (strlen (basename) + 1);
+ } else {
+ len += 256; /* worst-case for directory's symlink-handle expansion */
+ }
+
+ if ((buflen < len) || !buf)
+ return len;
+
+ uuid_str = uuid_utoa (gfid);
+
+ if (__is_root_gfid (gfid)) {
+ if (basename) {
+ len = snprintf (buf, buflen, "%s/%s", priv->base_path,
+ basename);
+ } else {
+ strncpy (buf, priv->base_path, buflen);
+ }
+ goto out;
+ }
+
+ if (basename) {
+ len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s/%s", priv->base_path,
+ HANDLE_PFX, gfid[0], gfid[1], uuid_str, basename);
+ } else {
+ len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s", priv->base_path,
+ HANDLE_PFX, gfid[0], gfid[1], uuid_str);
+ }
+out:
+ return len;
+}
+
+
+int
+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;
+ char *rootstr = NULL;
+ uuid_t gfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
+
+ priv = this->private;
+
+ ret = stat (priv->base_path, &exportbuf);
+ if (ret || !S_ISDIR (exportbuf.st_mode)) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Not a directory: %s", priv->base_path);
+ return -1;
+ }
+
+ handle_pfx = alloca (priv->base_path_length + 1 + strlen (HANDLE_PFX)
+ + 1);
+
+ sprintf (handle_pfx, "%s/%s", priv->base_path, HANDLE_PFX);
+
+ ret = stat (handle_pfx, &stbuf);
+ switch (ret) {
+ case -1:
+ if (errno == ENOENT) {
+ ret = mkdir (handle_pfx, 0600);
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Creating directory %s failed: %s",
+ handle_pfx, strerror (errno));
+ return -1;
+ }
+ } else {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Checking for %s failed: %s",
+ handle_pfx, strerror (errno));
+ return -1;
+ }
+ break;
+ case 0:
+ if (!S_ISDIR (stbuf.st_mode)) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Not a directory: %s",
+ handle_pfx);
+ return -1;
+ }
+ break;
+ default:
+ break;
+ }
+
+ 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);
+
+ ret = stat (rootstr, &rootbuf);
+ switch (ret) {
+ case -1:
+ if (errno != ENOENT) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s: %s", priv->base_path,
+ strerror (errno));
+ return -1;
+ }
+
+ ret = posix_handle_mkdir_hashes (this, rootstr);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "mkdir %s failed (%s)",
+ rootstr, strerror (errno));
+ return -1;
+ }
+
+ ret = symlink ("../../..", rootstr);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "symlink %s creation failed (%s)",
+ rootstr, strerror (errno));
+ return -1;
+ }
+ break;
+ case 0:
+ if ((exportbuf.st_ino == rootbuf.st_ino) &&
+ (exportbuf.st_dev == rootbuf.st_dev))
+ return 0;
+
+ gf_log (this->name, GF_LOG_ERROR,
+ "Different dirs %s (%lld/%lld) != %s (%lld/%lld)",
+ priv->base_path, (long long) exportbuf.st_ino,
+ (long long) exportbuf.st_dev, rootstr,
+ (long long) rootbuf.st_ino, (long long) rootbuf.st_dev);
+ return -1;
+
+ break;
+ }
+
+ return 0;
+}
+
+
+int
+posix_handle_mkdir_hashes (xlator_t *this, const char *newpath)
+{
+ char *duppath = NULL;
+ char *parpath = NULL;
+ int ret = 0;
+
+ duppath = strdupa (newpath);
+ parpath = dirname (duppath);
+ parpath = dirname (duppath);
+
+ ret = mkdir (parpath, 0700);
+ if (ret == -1 && errno != EEXIST) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "error mkdir hash-1 %s (%s)",
+ parpath, strerror (errno));
+ return -1;
+ }
+
+ strcpy (duppath, newpath);
+ parpath = dirname (duppath);
+
+ ret = mkdir (parpath, 0700);
+ if (ret == -1 && errno != EEXIST) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "error mkdir hash-2 %s (%s)",
+ parpath, strerror (errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int
+posix_handle_hard (xlator_t *this, const char *oldpath, uuid_t gfid, struct stat *oldbuf)
+{
+ char *newpath = NULL;
+ struct stat newbuf;
+ int ret = -1;
+
+
+ MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
+
+ ret = lstat (newpath, &newbuf);
+ if (ret == -1 && errno != ENOENT) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "%s: %s", newpath, strerror (errno));
+ return -1;
+ }
+
+ if (ret == -1 && errno == ENOENT) {
+ ret = posix_handle_mkdir_hashes (this, newpath);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "mkdir %s failed (%s)",
+ newpath, strerror (errno));
+ return -1;
+ }
+
+ ret = link (oldpath, newpath);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "link %s -> %s failed (%s)",
+ oldpath, newpath, strerror (errno));
+ return -1;
+ }
+
+ ret = lstat (newpath, &newbuf);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "lstat on %s failed (%s)",
+ newpath, strerror (errno));
+ return -1;
+ }
+ }
+
+ ret = lstat (newpath, &newbuf);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "lstat on %s failed (%s)", newpath, strerror (errno));
+ return -1;
+ }
+
+ if (newbuf.st_ino != oldbuf->st_ino ||
+ newbuf.st_dev != oldbuf->st_dev) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "mismatching ino/dev between file %s (%lld/%lld) "
+ "and handle %s (%lld/%lld)",
+ oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,
+ newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev);
+ ret = -1;
+ }
+
+ return ret;
+}
+
+
+int
+posix_handle_soft (xlator_t *this, const char *real_path, loc_t *loc,
+ uuid_t gfid, struct stat *oldbuf)
+{
+ char *oldpath = NULL;
+ char *newpath = NULL;
+ struct stat newbuf;
+ int ret = -1;
+
+
+ MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
+ 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,
+ "%s: %s", newpath, strerror (errno));
+ return -1;
+ }
+
+ if (ret == -1 && errno == ENOENT) {
+ ret = posix_handle_mkdir_hashes (this, newpath);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "mkdir %s failed (%s)",
+ newpath, strerror (errno));
+ return -1;
+ }
+
+ ret = symlink (oldpath, newpath);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "symlink %s -> %s failed (%s)",
+ oldpath, newpath, strerror (errno));
+ return -1;
+ }
+
+ ret = lstat (newpath, &newbuf);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "stat on %s failed (%s)",
+ newpath, strerror (errno));
+ return -1;
+ }
+ }
+
+ ret = stat (real_path, &newbuf);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "stat on %s failed (%s)", newpath, strerror (errno));
+ return -1;
+ }
+
+ if (!oldbuf)
+ return ret;
+
+ if (newbuf.st_ino != oldbuf->st_ino ||
+ newbuf.st_dev != oldbuf->st_dev) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "mismatching ino/dev between file %s (%lld/%lld) "
+ "and handle %s (%lld/%lld)",
+ oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,
+ newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev);
+ ret = -1;
+ }
+
+ return ret;
+}
+
+
+static int
+posix_handle_unset_gfid (xlator_t *this, uuid_t gfid)
+{
+ char *path = NULL;
+ int ret = 0;
+ struct stat stat;
+
+ MAKE_HANDLE_GFID_PATH (path, this, gfid, NULL);
+
+ ret = lstat (path, &stat);
+
+ if (ret == -1) {
+ if (errno != ENOENT) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "%s: %s", path, strerror (errno));
+ }
+ goto out;
+ }
+
+ ret = unlink (path);
+ if (ret == -1) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "unlink %s failed (%s)", path, strerror (errno));
+ }
+
+out:
+ return ret;
+}
+
+
+int
+posix_handle_unset (xlator_t *this, uuid_t gfid, const char *basename)
+{
+ int ret;
+ struct iatt stat;
+ char *path = NULL;
+
+
+ if (!basename) {
+ ret = posix_handle_unset_gfid (this, gfid);
+ return ret;
+ }
+
+ MAKE_HANDLE_PATH (path, this, gfid, basename);
+
+ ret = posix_istat (this, gfid, basename, &stat);
+
+ if (ret == -1) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "%s: %s", path, strerror (errno));
+ return -1;
+ }
+
+ ret = posix_handle_unset_gfid (this, stat.ia_gfid);
+
+ return ret;
+}
+
diff --git a/xlators/storage/posix/src/posix-handle.h b/xlators/storage/posix/src/posix-handle.h
new file mode 100644
index 00000000000..b22149f6317
--- /dev/null
+++ b/xlators/storage/posix/src/posix-handle.h
@@ -0,0 +1,148 @@
+/*
+ Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _POSIX_HANDLE_H
+#define _POSIX_HANDLE_H
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include "xlator.h"
+
+
+#define LOC_HAS_ABSPATH(loc) ((loc) && (loc->path) && (loc->path[0] == '/'))
+
+#define MAKE_REAL_PATH(var, this, path) do { \
+ var = alloca (strlen (path) + POSIX_BASE_PATH_LEN(this) + 2); \
+ strcpy (var, POSIX_BASE_PATH(this)); \
+ strcpy (&var[POSIX_BASE_PATH_LEN(this)], path); \
+ } while (0)
+
+
+#define MAKE_HANDLE_PATH(var, this, gfid, base) do { \
+ int __len; \
+ __len = posix_handle_path (this, gfid, base, NULL, 0); \
+ if (__len <= 0) \
+ break; \
+ var = alloca (__len); \
+ __len = posix_handle_path (this, gfid, base, var, __len); \
+ } while (0)
+
+
+#define MAKE_HANDLE_GFID_PATH(var, this, gfid, base) do { \
+ int __len = 0; \
+ __len = posix_handle_gfid_path (this, gfid, base, NULL, 0); \
+ if (__len <= 0) \
+ break; \
+ var = alloca (__len); \
+ __len = posix_handle_gfid_path (this, gfid, base, var, __len); \
+ } while (0)
+
+
+#define MAKE_HANDLE_RELPATH(var, this, gfid, base) do { \
+ int __len; \
+ __len = posix_handle_relpath (this, gfid, base, NULL, 0); \
+ if (__len <= 0) \
+ break; \
+ var = alloca (__len); \
+ __len = posix_handle_relpath (this, gfid, base, var, __len); \
+ } 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, \
+ "null gfid for path %s", loc->path); \
+ break; \
+ } \
+ errno = 0; \
+ op_ret = posix_istat (this, loc->gfid, NULL, iatt_p); \
+ if (errno != ELOOP) { \
+ MAKE_HANDLE_PATH (rpath, this, loc->gfid, NULL); \
+ break; \
+ } \
+ /* __ret == -1 && errno == ELOOP */ \
+ if (LOC_HAS_ABSPATH (loc)) { \
+ MAKE_REAL_PATH (rpath, this, loc->path); \
+ op_ret = posix_pstat (this, loc->gfid, rpath, iatt_p); \
+ break; \
+ } \
+ } while (0)
+
+
+#define MAKE_ENTRY_HANDLE(entp, parp, this, loc, ent_p) do { \
+ char *__parp; \
+ \
+ if (uuid_is_null (loc->pargfid) || !loc->name) { \
+ gf_log (this->name, GF_LOG_ERROR, \
+ "null pargfid/name for path %s", loc->path); \
+ break; \
+ } \
+ \
+ errno = 0; \
+ op_ret = posix_istat (this, loc->pargfid, loc->name, ent_p); \
+ if (errno != ELOOP) { \
+ MAKE_HANDLE_PATH (parp, this, loc->pargfid, NULL); \
+ MAKE_HANDLE_PATH (entp, this, loc->pargfid, loc->name); \
+ break; \
+ } \
+ /* __ret == -1 && errno == ELOOP */ \
+ if (LOC_HAS_ABSPATH (loc)) { \
+ MAKE_REAL_PATH (entp, this, loc->path); \
+ __parp = strdupa (entp); \
+ parp = dirname (__parp); \
+ op_ret = posix_pstat (this, NULL, entp, ent_p); \
+ break; \
+ } \
+ /* expand ELOOP */ \
+ } while (0)
+
+
+
+int
+posix_handle_path (xlator_t *this, uuid_t gfid, const char *basename, char *buf,
+ size_t len);
+int
+posix_handle_path_safe (xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t len);
+
+int
+posix_handle_gfid_path (xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t len);
+
+int
+posix_handle_hard (xlator_t *this, const char *path, uuid_t gfid,
+ struct stat *buf);
+
+
+int
+posix_handle_soft (xlator_t *this, const char *real_path, loc_t *loc,
+ uuid_t gfid, struct stat *buf);
+
+int
+posix_handle_unset (xlator_t *this, uuid_t gfid, const char *basename);
+
+int posix_handle_mkdir_hashes (xlator_t *this, const char *newpath);
+
+int posix_handle_init (xlator_t *this);
+
+#endif /* !_POSIX_HANDLE_H */
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index edc64f583da..31a4e667d17 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -264,19 +264,22 @@ out:
}
int
-posix_lstat_with_gfid (xlator_t *this, const char *path, struct iatt *stbuf_p)
+posix_fdstat (xlator_t *this, int fd, struct iatt *stbuf_p)
{
int ret = 0;
- struct stat lstatbuf = {0, };
+ struct stat fstatbuf = {0, };
struct iatt stbuf = {0, };
- ret = lstat (path, &lstatbuf);
+ ret = fstat (fd, &fstatbuf);
if (ret == -1)
goto out;
- iatt_from_stat (&stbuf, &lstatbuf);
+ if (fstatbuf.st_nlink && !S_ISDIR (fstatbuf.st_mode))
+ fstatbuf.st_nlink--;
- ret = posix_fill_gfid_path (this, path, &stbuf);
+ iatt_from_stat (&stbuf, &fstatbuf);
+
+ ret = posix_fill_gfid_fd (this, fd, &stbuf);
if (ret)
gf_log_callingfn (this->name, GF_LOG_DEBUG, "failed to get gfid");
@@ -284,33 +287,105 @@ posix_lstat_with_gfid (xlator_t *this, const char *path, struct iatt *stbuf_p)
if (stbuf_p)
*stbuf_p = stbuf;
+
out:
return ret;
}
int
-posix_fstat_with_gfid (xlator_t *this, int fd, struct iatt *stbuf_p)
+posix_istat (xlator_t *this, uuid_t gfid, const char *basename,
+ struct iatt *buf_p)
{
- int ret = 0;
- struct stat fstatbuf = {0, };
- struct iatt stbuf = {0, };
+ char *real_path = NULL;
+ struct stat lstatbuf = {0, };
+ struct iatt stbuf = {0, };
+ int ret = 0;
+ struct posix_private *priv = NULL;
- ret = fstat (fd, &fstatbuf);
- if (ret == -1)
+
+ priv = this->private;
+
+ MAKE_HANDLE_PATH (real_path, this, gfid, basename);
+
+ ret = lstat (real_path, &lstatbuf);
+
+ if (ret == -1) {
+ if (errno != ENOENT && errno != ELOOP)
+ gf_log (this->name, GF_LOG_WARNING,
+ "lstat failed on %s (%s)",
+ real_path, strerror (errno));
goto out;
+ }
- iatt_from_stat (&stbuf, &fstatbuf);
+ if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
+ (lstatbuf.st_dev == priv->handledir.st_dev)) {
+ errno = ENOENT;
+ return -1;
+ }
- ret = posix_fill_gfid_fd (this, fd, &stbuf);
- if (ret)
- gf_log_callingfn (this->name, GF_LOG_DEBUG, "failed to get gfid");
+ if (!S_ISDIR (lstatbuf.st_mode))
+ lstatbuf.st_nlink --;
+
+ iatt_from_stat (&stbuf, &lstatbuf);
+
+ if (basename)
+ posix_fill_gfid_path (this, real_path, &stbuf);
+ else
+ uuid_copy (stbuf.ia_gfid, gfid);
posix_fill_ino_from_gfid (this, &stbuf);
- if (stbuf_p)
- *stbuf_p = stbuf;
+ if (buf_p)
+ *buf_p = stbuf;
+out:
+ return ret;
+}
+
+
+int
+posix_pstat (xlator_t *this, uuid_t gfid, const char *path,
+ struct iatt *buf_p)
+{
+ struct stat lstatbuf = {0, };
+ struct iatt stbuf = {0, };
+ int ret = 0;
+ struct posix_private *priv = NULL;
+
+
+ priv = this->private;
+
+ ret = lstat (path, &lstatbuf);
+
+ if (ret == -1) {
+ if (errno != ENOENT)
+ gf_log (this->name, GF_LOG_WARNING,
+ "lstat failed on %s (%s)",
+ path, strerror (errno));
+ goto out;
+ }
+
+ if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
+ (lstatbuf.st_dev == priv->handledir.st_dev)) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ if (!S_ISDIR (lstatbuf.st_mode))
+ lstatbuf.st_nlink --;
+
+ iatt_from_stat (&stbuf, &lstatbuf);
+
+ if (gfid && !uuid_is_null (gfid))
+ uuid_copy (stbuf.ia_gfid, gfid);
+ else
+ posix_fill_gfid_path (this, path, &stbuf);
+
+ posix_fill_ino_from_gfid (this, &stbuf);
+
+ if (buf_p)
+ *buf_p = stbuf;
out:
return ret;
}
@@ -340,63 +415,15 @@ out:
}
-/*
- * If the parent directory of {real_path} has the setgid bit set,
- * then set {gid} to the gid of the parent. Otherwise,
- * leave {gid} unchanged.
- */
-
-int
-setgid_override (xlator_t *this, char *real_path, gid_t *gid)
-{
- char * tmp_path = NULL;
- char * parent_path = NULL;
- struct iatt parent_stbuf;
-
- int op_ret = 0;
-
- tmp_path = gf_strdup (real_path);
- if (!tmp_path) {
- op_ret = -ENOMEM;
- goto out;
- }
-
- parent_path = dirname (tmp_path);
-
- op_ret = posix_lstat_with_gfid (this, parent_path, &parent_stbuf);
- if (op_ret == -1) {
- op_ret = -errno;
- gf_log_callingfn (this->name, GF_LOG_ERROR,
- "lstat on parent directory (%s) failed: %s",
- parent_path, strerror (errno));
- goto out;
- }
-
- if (parent_stbuf.ia_prot.sgid) {
- /*
- * Entries created inside a setgid directory
- * should inherit the gid from the parent
- */
-
- *gid = parent_stbuf.ia_gid;
- }
-out:
-
- if (tmp_path)
- GF_FREE (tmp_path);
-
- return op_ret;
-}
-
-
int
-posix_gfid_set (xlator_t *this, const char *path, dict_t *xattr_req)
+posix_gfid_set (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
{
void *uuid_req = NULL;
uuid_t uuid_curr;
int ret = 0;
struct stat stat = {0, };
+
if (!xattr_req)
goto out;
@@ -406,17 +433,31 @@ posix_gfid_set (xlator_t *this, const char *path, dict_t *xattr_req)
ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
if (ret == 16) {
ret = 0;
- goto out;
+ goto verify_handle;
}
ret = dict_get_ptr (xattr_req, "gfid-req", &uuid_req);
if (ret) {
- gf_log_callingfn (this->name, GF_LOG_DEBUG,
- "failed to get the gfid from dict");
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get the gfid from dict for %s",
+ loc->path);
goto out;
}
ret = sys_lsetxattr (path, GFID_XATTR_KEY, uuid_req, 16, XATTR_CREATE);
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "setting GFID on %s failed (%s)", path,
+ strerror (errno));
+ goto out;
+ }
+ uuid_copy (uuid_curr, uuid_req);
+
+verify_handle:
+ if (!S_ISDIR (stat.st_mode))
+ ret = posix_handle_hard (this, path, uuid_curr, &stat);
+ else
+ ret = posix_handle_soft (this, path, loc, uuid_curr, &stat);
out:
return ret;
@@ -424,22 +465,26 @@ out:
int
-posix_set_file_contents (xlator_t *this, const char *real_path,
- data_pair_t *trav, int flags)
+posix_set_file_contents (xlator_t *this, const char *path, data_pair_t *trav,
+ int flags)
{
char * key = NULL;
- char real_filepath[ZR_PATH_MAX] = {0,};
+ char real_path[PATH_MAX];
int32_t file_fd = -1;
int op_ret = 0;
int ret = -1;
+
+ /* XXX: does not handle assigning GFID to created files */
+ return -1;
+
key = &(trav->key[15]);
- sprintf (real_filepath, "%s/%s", real_path, key);
+ sprintf (real_path, "%s/%s", path, key);
if (flags & XATTR_REPLACE) {
/* if file exists, replace it
* else, error out */
- file_fd = open (real_filepath, O_TRUNC|O_WRONLY);
+ file_fd = open (real_path, O_TRUNC|O_WRONLY);
if (file_fd == -1) {
goto create;
@@ -453,7 +498,7 @@ posix_set_file_contents (xlator_t *this, const char *real_path,
gf_log (this->name, GF_LOG_ERROR,
"write failed while doing setxattr "
"for key %s on path %s: %s",
- key, real_filepath, strerror (errno));
+ key, real_path, strerror (errno));
goto out;
}
@@ -462,14 +507,14 @@ posix_set_file_contents (xlator_t *this, const char *real_path,
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR,
"close failed on %s: %s",
- real_filepath, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
}
create: /* we know file doesn't exist, create it */
- file_fd = open (real_filepath, O_CREAT|O_WRONLY, 0644);
+ file_fd = open (real_path, O_CREAT|O_WRONLY, 0644);
if (file_fd == -1) {
op_ret = -errno;
@@ -485,7 +530,7 @@ posix_set_file_contents (xlator_t *this, const char *real_path,
gf_log (this->name, GF_LOG_ERROR,
"write failed on %s while setxattr with "
"key %s: %s",
- real_filepath, key, strerror (errno));
+ real_path, key, strerror (errno));
goto out;
}
@@ -495,7 +540,7 @@ posix_set_file_contents (xlator_t *this, const char *real_path,
gf_log (this->name, GF_LOG_ERROR,
"close failed on %s while setxattr with "
"key %s: %s",
- real_filepath, key, strerror (errno));
+ real_path, key, strerror (errno));
goto out;
}
}
@@ -506,33 +551,32 @@ out:
int
-posix_get_file_contents (xlator_t *this, const char *real_path,
+posix_get_file_contents (xlator_t *this, uuid_t pargfid,
const char *name, char **contents)
{
- char real_filepath[ZR_PATH_MAX] = {0,};
- char * key = NULL;
+ char *real_path = NULL;
int32_t file_fd = -1;
struct iatt stbuf = {0,};
int op_ret = 0;
int ret = -1;
- key = (char *) &(name[15]);
- sprintf (real_filepath, "%s/%s", real_path, key);
- op_ret = posix_lstat_with_gfid (this, real_filepath, &stbuf);
+ MAKE_HANDLE_PATH (real_path, this, pargfid, name);
+
+ op_ret = posix_istat (this, pargfid, name, &stbuf);
if (op_ret == -1) {
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR, "lstat failed on %s: %s",
- real_filepath, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
- file_fd = open (real_filepath, O_RDONLY);
+ file_fd = open (real_path, O_RDONLY);
if (file_fd == -1) {
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR, "open failed on %s: %s",
- real_filepath, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
@@ -547,7 +591,7 @@ posix_get_file_contents (xlator_t *this, const char *real_path,
if (ret <= 0) {
op_ret = -1;
gf_log (this->name, GF_LOG_ERROR, "read on %s failed: %s",
- real_filepath, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
@@ -558,7 +602,7 @@ posix_get_file_contents (xlator_t *this, const char *real_path,
if (op_ret == -1) {
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR, "close on %s failed: %s",
- real_filepath, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
@@ -775,9 +819,6 @@ posix_janitor_thread_proc (void *data)
closedir (pfd->dir);
}
- if (pfd->path)
- GF_FREE (pfd->path);
-
GF_FREE (pfd);
}
}
@@ -882,3 +923,97 @@ posix_entry_create_xattr_set (xlator_t *this, const char *path,
out:
return ret;
}
+
+
+static int
+__posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
+{
+ uint64_t tmp_pfd = 0;
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
+ char *real_path = NULL;
+ int _fd = -1;
+ DIR *dir = NULL;
+
+ ret = __fd_ctx_get (fd, this, &tmp_pfd);
+ if (ret == 0) {
+ pfd = (void *)(long) tmp_pfd;
+ ret = 0;
+ goto out;
+ }
+
+ if (fd->pid != -1)
+ /* anonymous fd */
+ goto out;
+
+ MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL);
+
+ pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
+ if (!pfd) {
+ goto out;
+ }
+ pfd->fd = -1;
+
+ if (fd->inode->ia_type == IA_IFDIR) {
+ dir = opendir (real_path);
+ if (!dir) {
+ GF_FREE (pfd);
+ pfd = NULL;
+ goto out;
+ }
+ _fd = dirfd (dir);
+ }
+
+ if (fd->inode->ia_type == IA_IFREG) {
+ _fd = open (real_path, O_RDWR|O_LARGEFILE);
+ if (_fd == -1) {
+ GF_FREE (pfd);
+ pfd = NULL;
+ goto out;
+ }
+ }
+
+ pfd->fd = _fd;
+ pfd->dir = dir;
+
+ ret = __fd_ctx_set (fd, this, (uint64_t) (long) pfd);
+ if (ret != 0) {
+ if (_fd != -1)
+ close (_fd);
+ if (dir)
+ closedir (dir);
+ GF_FREE (pfd);
+ pfd = NULL;
+ goto out;
+ }
+
+ ret = 0;
+out:
+ if (pfd_p)
+ *pfd_p = pfd;
+ return ret;
+}
+
+
+int
+posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd)
+{
+ int ret;
+
+ LOCK (&fd->inode->lock);
+ {
+ ret = __posix_fd_ctx_get (fd, this, pfd);
+ }
+ UNLOCK (&fd->inode->lock);
+
+ return ret;
+}
+
+
+int
+posix_fd_ctx_get_off (fd_t *fd, xlator_t *this, struct posix_fd **pfd,
+ off_t offset)
+{
+ return posix_fd_ctx_get (fd, this, pfd);
+}
+
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index cf5d855fede..5257633cec1 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -101,13 +101,12 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
loc_t *loc, dict_t *xattr_req)
{
struct iatt buf = {0, };
- char * real_path = NULL;
int32_t op_ret = -1;
int32_t entry_ret = 0;
int32_t op_errno = 0;
dict_t * xattr = NULL;
- char * pathdup = NULL;
- char * parentpath = NULL;
+ char * real_path = NULL;
+ char * par_path = NULL;
struct iatt postparent = {0,};
VALIDATE_OR_GOTO (frame, out);
@@ -115,18 +114,23 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
VALIDATE_OR_GOTO (loc->path, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ if (uuid_is_null (loc->pargfid)) {
+ /* nameless lookup */
+ MAKE_INODE_HANDLE (real_path, this, loc, &buf);
+ } else {
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &buf);
- posix_gfid_set (this, real_path, xattr_req);
+ if (uuid_is_null (loc->inode->gfid))
+ posix_gfid_set (this, real_path, loc, xattr_req);
+ }
- op_ret = posix_lstat_with_gfid (this, real_path, &buf);
op_errno = errno;
if (op_ret == -1) {
if (op_errno != ENOENT) {
gf_log (this->name, GF_LOG_ERROR,
"lstat on %s failed: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
}
entry_ret = -1;
@@ -139,27 +143,19 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
}
parent:
- if (loc->parent) {
- pathdup = gf_strdup (real_path);
- GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
-
- parentpath = dirname (pathdup);
-
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ if (par_path) {
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
}
op_ret = entry_ret;
out:
- if (pathdup)
- GF_FREE (pathdup);
-
if (xattr)
dict_ref (xattr);
@@ -177,10 +173,10 @@ int32_t
posix_stat (call_frame_t *frame, xlator_t *this, loc_t *loc)
{
struct iatt buf = {0,};
- char * real_path = NULL;
int32_t op_ret = -1;
int32_t op_errno = 0;
struct posix_private *priv = NULL;
+ char *real_path = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -192,13 +188,13 @@ posix_stat (call_frame_t *frame, xlator_t *this, loc_t *loc)
VALIDATE_OR_GOTO (priv, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
- op_ret = posix_lstat_with_gfid (this, real_path, &buf);
+ MAKE_INODE_HANDLE (real_path, this, loc, &buf);
+
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "lstat on %s failed: %s", loc->path,
+ "lstat on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
@@ -328,9 +324,8 @@ posix_setattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, &statpre);
- op_ret = posix_lstat_with_gfid (this, real_path, &statpre);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -384,7 +379,7 @@ posix_setattr (call_frame_t *frame, xlator_t *this,
}
}
- op_ret = posix_lstat_with_gfid (this, real_path, &statpost);
+ op_ret = posix_pstat (this, loc->gfid, real_path, &statpost);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -456,7 +451,6 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
struct iatt statpre = {0,};
struct iatt statpost = {0,};
struct posix_fd *pfd = NULL;
- uint64_t tmp_pfd = 0;
int32_t ret = -1;
DECLARE_OLD_FS_ID_VAR;
@@ -467,16 +461,15 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_DEBUG,
"pfd is NULL from fd=%p", fd);
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
- op_ret = posix_fstat_with_gfid (this, pfd->fd, &statpre);
+ op_ret = posix_fdstat (this, pfd->fd, &statpre);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -531,7 +524,7 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
}
}
- op_ret = posix_fstat_with_gfid (this, pfd->fd, &statpost);
+ op_ret = posix_fdstat (this, pfd->fd, &statpost);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -570,7 +563,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (fd, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
dir = opendir (real_path);
@@ -578,7 +571,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"opendir failed on %s: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
@@ -587,7 +580,7 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"dirfd() failed on %s: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
@@ -599,16 +592,12 @@ posix_opendir (call_frame_t *frame, xlator_t *this,
pfd->dir = dir;
pfd->fd = dirfd (dir);
- pfd->path = gf_strdup (real_path);
- if (!pfd->path) {
- goto out;
- }
op_ret = fd_ctx_set (fd, this, (uint64_t)(long)pfd);
if (op_ret)
gf_log (this->name, GF_LOG_WARNING,
"failed to set the fd context path=%s fd=%p",
- loc->path, fd);
+ real_path, fd);
op_ret = 0;
@@ -619,8 +608,6 @@ out:
dir = NULL;
}
if (pfd) {
- if (pfd->path)
- GF_FREE (pfd->path);
GF_FREE (pfd);
pfd = NULL;
}
@@ -654,19 +641,12 @@ posix_releasedir (xlator_t *this,
pfd = (struct posix_fd *)(long)tmp_pfd;
if (!pfd->dir) {
gf_log (this->name, GF_LOG_WARNING,
- "pfd->dir is NULL for fd=%p path=%s",
- fd, pfd->path ? pfd->path : "<NULL>");
+ "pfd->dir is NULL for fd=%p", fd);
goto out;
}
priv = this->private;
- if (!pfd->path) {
- gf_log (this->name, GF_LOG_WARNING,
- "pfd->path was NULL. fd=%p pfd=%p",
- fd, pfd);
- }
-
pthread_mutex_lock (&priv->janitor_lock);
{
INIT_LIST_HEAD (&pfd->list);
@@ -686,7 +666,6 @@ posix_readlink (call_frame_t *frame, xlator_t *this,
{
char * dest = NULL;
int32_t op_ret = -1;
- int32_t lstat_ret = -1;
int32_t op_errno = 0;
char * real_path = NULL;
struct iatt stbuf = {0,};
@@ -699,29 +678,25 @@ posix_readlink (call_frame_t *frame, xlator_t *this,
dest = alloca (size + 1);
- MAKE_REAL_PATH (real_path, this, loc->path);
-
- op_ret = readlink (real_path, dest, size);
+ MAKE_INODE_HANDLE (real_path, this, loc, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "readlink on %s failed: %s", loc->path,
+ "lstat on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- dest[op_ret] = 0;
-
- lstat_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
- if (lstat_ret == -1) {
- op_ret = -1;
+ op_ret = readlink (real_path, dest, size);
+ if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "lstat on %s failed: %s", loc->path,
+ "readlink on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
+ dest[op_ret] = 0;
out:
SET_TO_OLD_FS_ID ();
@@ -739,14 +714,13 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char *real_path = 0;
+ char *par_path = 0;
struct iatt stbuf = { 0, };
char was_present = 1;
struct posix_private *priv = NULL;
gid_t gid = 0;
- char *pathdup = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
- char *parentpath = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -757,32 +731,25 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
gid = frame->root->gid;
- op_ret = setgid_override (this, real_path, &gid);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
-
SET_FS_ID (frame->root->uid, gid);
- pathdup = gf_strdup (real_path);
- GF_VALIDATE_OR_GOTO (this->name, pathdup, out);
- parentpath = dirname (pathdup);
-
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
+
#ifdef __NetBSD__
if (S_ISFIFO(mode))
op_ret = mkfifo (real_path, mode);
@@ -799,23 +766,23 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
if (tmp_fd == -1) {
gf_log (this->name, GF_LOG_ERROR,
"create failed on %s: %s",
- loc->path, strerror (errno));
+ real_path, strerror (errno));
goto out;
}
close (tmp_fd);
} else {
gf_log (this->name, GF_LOG_ERROR,
- "mknod on %s failed: %s", loc->path,
+ "mknod on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
}
- op_ret = posix_gfid_set (this, real_path, params);
+ op_ret = posix_gfid_set (this, real_path, loc, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting gfid on %s failed", loc->path);
+ "setting gfid on %s failed", real_path);
}
#ifndef HAVE_SET_FSID
@@ -823,7 +790,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "lchown on %s failed: %s", loc->path,
+ "lchown on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
@@ -832,41 +799,38 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
op_ret = posix_acl_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting ACLs on %s failed (%s)", loc->path,
+ "setting ACLs on %s failed (%s)", real_path,
strerror (errno));
}
op_ret = posix_entry_create_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting xattrs on %s failed (%s)", loc->path,
+ "setting xattrs on %s failed (%s)", real_path,
strerror (errno));
}
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_path, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "mknod on %s failed: %s", loc->path,
+ "mknod on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (pathdup)
- GF_FREE (pathdup);
-
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno,
@@ -879,6 +843,7 @@ out:
return 0;
}
+
int
posix_mkdir (call_frame_t *frame, xlator_t *this,
loc_t *loc, mode_t mode, dict_t *params)
@@ -886,12 +851,11 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char *real_path = NULL;
+ char *par_path = NULL;
struct iatt stbuf = {0, };
char was_present = 1;
struct posix_private *priv = NULL;
gid_t gid = 0;
- char *pathdup = NULL;
- char *parentpath = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
@@ -904,51 +868,44 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
gid = frame->root->gid;
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_path, &stbuf);
if ((op_ret == -1) && (errno == ENOENT)) {
was_present = 0;
}
- op_ret = setgid_override (this, real_path, &gid);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
-
SET_FS_ID (frame->root->uid, gid);
- pathdup = gf_strdup (real_path);
- if (!pathdup)
- goto out;
-
- parentpath = dirname (pathdup);
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ mode |= S_ISGID;
+ }
+
op_ret = mkdir (real_path, mode);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "mkdir of %s failed: %s", loc->path,
+ "mkdir of %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- op_ret = posix_gfid_set (this, real_path, params);
+ op_ret = posix_gfid_set (this, real_path, loc, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting gfid on %s failed", loc->path);
+ "setting gfid on %s failed", real_path);
}
#ifndef HAVE_SET_FSID
@@ -956,7 +913,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "chown on %s failed: %s", loc->path,
+ "chown on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
@@ -965,41 +922,38 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
op_ret = posix_acl_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting ACLs on %s failed (%s)", loc->path,
+ "setting ACLs on %s failed (%s)", real_path,
strerror (errno));
}
op_ret = posix_entry_create_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting xattrs on %s failed (%s)", loc->path,
+ "setting xattrs on %s failed (%s)", real_path,
strerror (errno));
}
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_path, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "lstat on %s failed: %s", loc->path,
+ "lstat on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (pathdup)
- GF_FREE (pathdup);
-
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno,
@@ -1020,9 +974,9 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char *real_path = NULL;
- char *pathdup = NULL;
- char *parentpath = NULL;
+ char *par_path = NULL;
int32_t fd = -1;
+ struct iatt stbuf;
struct posix_private *priv = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
@@ -1034,23 +988,20 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
-
- pathdup = gf_strdup (real_path);
- if (!pathdup)
- goto out;
-
- parentpath = dirname (pathdup);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
+ if (stbuf.ia_nlink == 1)
+ posix_handle_unset (this, stbuf.ia_gfid, NULL);
+
priv = this->private;
if (priv->background_unlink) {
if (IA_ISREG (loc->inode->ia_type)) {
@@ -1059,7 +1010,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
op_ret = -1;
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "open of %s failed: %s", loc->path,
+ "open of %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
@@ -1070,26 +1021,23 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "unlink of %s failed: %s", loc->path,
+ "unlink of %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (pathdup)
- GF_FREE (pathdup);
-
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno,
@@ -1110,10 +1058,10 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char * real_path = NULL;
- char * pathdup = NULL;
- char * parentpath = NULL;
+ char * par_path = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
+ struct iatt stbuf;
struct posix_private *priv = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -1125,20 +1073,14 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
priv = this->private;
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
-
- pathdup = gf_strdup (real_path);
- if (!pathdup)
- goto out;
-
- parentpath = dirname (pathdup);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
@@ -1155,6 +1097,10 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
}
op_errno = errno;
+ if (op_ret == 0) {
+ posix_handle_unset (this, stbuf.ia_gfid, NULL);
+ }
+
if (op_errno == EEXIST)
/* Solaris sets errno = EEXIST instead of ENOTEMPTY */
op_errno = ENOTEMPTY;
@@ -1162,7 +1108,7 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
/* No need to log a common error as ENOTEMPTY */
if (op_ret == -1 && op_errno != ENOTEMPTY) {
gf_log (this->name, GF_LOG_ERROR,
- "rmdir of %s failed: %s", loc->path,
+ "rmdir of %s failed: %s", real_path,
strerror (op_errno));
}
@@ -1170,23 +1116,20 @@ posix_rmdir (call_frame_t *frame, xlator_t *this,
gf_log (this->name,
(op_errno == ENOTEMPTY) ? GF_LOG_DEBUG : GF_LOG_ERROR,
"%s on %s failed", (flags) ? "rename" : "rmdir",
- loc->path);
+ real_path);
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ par_path, strerror (op_errno));
goto out;
}
out:
- if (pathdup)
- GF_FREE (pathdup);
-
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno,
@@ -1203,12 +1146,11 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char * real_path = 0;
+ char * par_path = 0;
struct iatt stbuf = { 0, };
struct posix_private *priv = NULL;
gid_t gid = 0;
char was_present = 1;
- char *pathdup = NULL;
- char *parentpath = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
@@ -1222,52 +1164,43 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
if ((op_ret == -1) && (errno == ENOENT)){
was_present = 0;
}
- gid = frame->root->gid;
-
- op_ret = setgid_override (this, real_path, &gid);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
-
SET_FS_ID (frame->root->uid, gid);
- pathdup = gf_strdup (real_path);
- if (!pathdup)
- goto out;
- parentpath = dirname (pathdup);
+ gid = frame->root->gid;
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
+
op_ret = symlink (linkname, real_path);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"symlink of %s --> %s failed: %s",
- loc->path, linkname, strerror (op_errno));
+ real_path, linkname, strerror (op_errno));
goto out;
}
- op_ret = posix_gfid_set (this, real_path, params);
+ op_ret = posix_gfid_set (this, real_path, loc, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting gfid on %s failed", loc->path);
+ "setting gfid on %s failed", real_path);
}
#ifndef HAVE_SET_FSID
@@ -1276,7 +1209,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"lchown failed on %s: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
#endif
@@ -1284,41 +1217,38 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
op_ret = posix_acl_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting ACLs on %s failed (%s)", loc->path,
+ "setting ACLs on %s failed (%s)", real_path,
strerror (errno));
}
op_ret = posix_entry_create_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting xattrs on %s failed (%s)", loc->path,
+ "setting xattrs on %s failed (%s)", real_path,
strerror (errno));
}
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_path, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"lstat failed on %s: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (pathdup)
- GF_FREE (pathdup);
-
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno,
@@ -1340,19 +1270,20 @@ posix_rename (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
char *real_oldpath = NULL;
char *real_newpath = NULL;
+ char *par_oldpath = NULL;
+ char *par_newpath = NULL;
struct iatt stbuf = {0, };
struct posix_private *priv = NULL;
char was_present = 1;
- char *oldpathdup = NULL;
- char *oldparentpath = NULL;
- char *newpathdup = NULL;
- char *newparentpath = NULL;
struct iatt preoldparent = {0, };
struct iatt postoldparent = {0, };
struct iatt prenewparent = {0, };
struct iatt postnewparent = {0, };
char olddirid[64];
char newdirid[64];
+ uuid_t victim;
+ int was_dir;
+ int nlink;
DECLARE_OLD_FS_ID_VAR;
@@ -1365,42 +1296,35 @@ posix_rename (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (priv, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_oldpath, this, oldloc->path);
- MAKE_REAL_PATH (real_newpath, this, newloc->path);
-
- oldpathdup = gf_strdup (real_oldpath);
- if (!oldpathdup)
- goto out;
+ MAKE_ENTRY_HANDLE (real_oldpath, par_oldpath, this, oldloc, NULL);
+ MAKE_ENTRY_HANDLE (real_newpath, par_newpath, this, newloc, &stbuf);
- oldparentpath = dirname (oldpathdup);
-
- op_ret = posix_lstat_with_gfid (this, oldparentpath, &preoldparent);
+ op_ret = posix_pstat (this, oldloc->pargfid, par_oldpath, &preoldparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- oldloc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_oldpath, strerror (op_errno));
goto out;
}
- newpathdup = gf_strdup (real_newpath);
- if (!newpathdup)
- goto out;
-
- newparentpath = dirname (newpathdup);
-
- op_ret = posix_lstat_with_gfid (this, newparentpath, &prenewparent);
+ op_ret = posix_pstat (this, newloc->pargfid, par_newpath, &prenewparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"pre-operation lstat on parent of %s failed: %s",
- newloc->path, strerror (op_errno));
+ par_newpath, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, real_newpath, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_newpath, &stbuf);
if ((op_ret == -1) && (errno == ENOENT)){
was_present = 0;
+ } else {
+ uuid_copy (victim, stbuf.ia_gfid);
+ if (IA_ISDIR (stbuf.ia_type))
+ was_dir = 1;
+ nlink = stbuf.ia_nlink;
}
if (was_present && IA_ISDIR(stbuf.ia_type) && !newloc->inode) {
@@ -1424,17 +1348,32 @@ posix_rename (call_frame_t *frame, xlator_t *this,
goto out;
}
+ if (IA_ISDIR (oldloc->inode->ia_type)) {
+ posix_handle_unset (this, oldloc->inode->gfid, NULL);
+ }
+
op_ret = sys_rename (real_oldpath, real_newpath);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name,
(op_errno == ENOTEMPTY ? GF_LOG_DEBUG : GF_LOG_ERROR),
"rename of %s to %s failed: %s",
- oldloc->path, newloc->path, strerror (op_errno));
+ real_oldpath, real_newpath, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, real_newpath, &stbuf);
+ if (was_dir)
+ posix_handle_unset (this, victim, NULL);
+
+ if (was_present && !was_dir && nlink == 2)
+ posix_handle_unset (this, victim, NULL);
+
+ if (IA_ISDIR (oldloc->inode->ia_type)) {
+ posix_handle_soft (this, real_newpath, newloc,
+ oldloc->inode->gfid, NULL);
+ }
+
+ op_ret = posix_pstat (this, NULL, real_newpath, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -1443,33 +1382,27 @@ posix_rename (call_frame_t *frame, xlator_t *this,
goto out;
}
- op_ret = posix_lstat_with_gfid (this, oldparentpath, &postoldparent);
+ op_ret = posix_pstat (this, oldloc->pargfid, par_oldpath, &postoldparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- oldloc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_oldpath, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, newparentpath, &postnewparent);
+ op_ret = posix_pstat (this, newloc->pargfid, par_newpath, &postnewparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- newloc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_newpath, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (oldpathdup)
- GF_FREE (oldpathdup);
-
- if (newpathdup)
- GF_FREE (newpathdup);
-
SET_TO_OLD_FS_ID ();
@@ -1493,11 +1426,10 @@ posix_link (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
char *real_oldpath = 0;
char *real_newpath = 0;
+ char *par_newpath = 0;
struct iatt stbuf = {0, };
struct posix_private *priv = NULL;
char was_present = 1;
- char *newpathdup = NULL;
- char *newparentpath = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
@@ -1512,26 +1444,18 @@ posix_link (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (priv, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_oldpath, this, oldloc->path);
- MAKE_REAL_PATH (real_newpath, this, newloc->path);
+ MAKE_INODE_HANDLE (real_oldpath, this, oldloc, &stbuf);
- op_ret = posix_lstat_with_gfid (this, real_newpath, &stbuf);
+ MAKE_ENTRY_HANDLE (real_newpath, par_newpath, this, newloc, &stbuf);
if ((op_ret == -1) && (errno == ENOENT)) {
was_present = 0;
}
- newpathdup = gf_strdup (real_newpath);
- if (!newpathdup) {
- op_errno = ENOMEM;
- goto out;
- }
-
- newparentpath = dirname (newpathdup);
- op_ret = posix_lstat_with_gfid (this, newparentpath, &preparent);
+ op_ret = posix_pstat (this, newloc->pargfid, par_newpath, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "lstat failed: %s: %s",
- newparentpath, strerror (op_errno));
+ par_newpath, strerror (op_errno));
goto out;
}
@@ -1551,11 +1475,11 @@ posix_link (call_frame_t *frame, xlator_t *this,
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"link %s to %s failed: %s",
- oldloc->path, newloc->path, strerror (op_errno));
+ real_oldpath, real_newpath, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, real_newpath, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_newpath, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -1564,19 +1488,17 @@ posix_link (call_frame_t *frame, xlator_t *this,
goto out;
}
- op_ret = posix_lstat_with_gfid (this, newparentpath, &postparent);
+ op_ret = posix_pstat (this, newloc->pargfid, par_newpath, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "lstat failed: %s: %s",
- newparentpath, strerror (op_errno));
+ par_newpath, strerror (op_errno));
goto out;
}
op_ret = 0;
out:
- if (newpathdup)
- GF_FREE (newpathdup);
SET_TO_OLD_FS_ID ();
STACK_UNWIND_STRICT (link, frame, op_ret, op_errno,
@@ -1611,14 +1533,13 @@ posix_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset)
VALIDATE_OR_GOTO (priv, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
- op_ret = posix_lstat_with_gfid (this, real_path, &prebuf);
+ MAKE_INODE_HANDLE (real_path, this, loc, &prebuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"pre-operation lstat on %s failed: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
@@ -1627,11 +1548,11 @@ posix_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset)
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
"truncate on %s failed: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
- op_ret = posix_lstat_with_gfid (this, real_path, &postbuf);
+ op_ret = posix_pstat (this, loc->gfid, real_path, &postbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "lstat on %s failed: %s",
@@ -1651,7 +1572,7 @@ out:
}
-int32_t
+int
posix_create (call_frame_t *frame, xlator_t *this,
loc_t *loc, int32_t flags, mode_t mode,
fd_t *fd, dict_t *params)
@@ -1661,14 +1582,13 @@ posix_create (call_frame_t *frame, xlator_t *this,
int32_t _fd = -1;
int _flags = 0;
char * real_path = NULL;
+ char * par_path = NULL;
struct iatt stbuf = {0, };
struct posix_fd * pfd = NULL;
struct posix_private * priv = NULL;
char was_present = 1;
gid_t gid = 0;
- char *pathdup = NULL;
- char *parentpath = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
@@ -1683,33 +1603,25 @@ posix_create (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
gid = frame->root->gid;
- op_ret = setgid_override (this, real_path, &gid);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
-
SET_FS_ID (frame->root->uid, gid);
- pathdup = gf_strdup (real_path);
- if (!pathdup)
- goto out;
-
- parentpath = dirname (pathdup);
- op_ret = posix_lstat_with_gfid (this, parentpath, &preparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "pre-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "pre-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
+
if (!flags) {
_flags = O_CREAT | O_RDWR | O_EXCL;
}
@@ -1717,7 +1629,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
_flags = flags | O_CREAT;
}
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
+ op_ret = posix_pstat (this, NULL, real_path, &stbuf);
if ((op_ret == -1) && (errno == ENOENT)) {
was_present = 0;
}
@@ -1731,15 +1643,15 @@ posix_create (call_frame_t *frame, xlator_t *this,
op_errno = errno;
op_ret = -1;
gf_log (this->name, GF_LOG_ERROR,
- "open on %s failed: %s", loc->path,
+ "open on %s failed: %s", real_path,
strerror (op_errno));
goto out;
}
- op_ret = posix_gfid_set (this, real_path, params);
+ op_ret = posix_gfid_set (this, real_path, loc, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting gfid on %s failed", loc->path);
+ "setting gfid on %s failed", real_path);
}
#ifndef HAVE_SET_FSID
@@ -1755,18 +1667,18 @@ posix_create (call_frame_t *frame, xlator_t *this,
op_ret = posix_acl_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting ACLs on %s failed (%s)", loc->path,
+ "setting ACLs on %s failed (%s)", real_path,
strerror (errno));
}
op_ret = posix_entry_create_xattr_set (this, real_path, params);
if (op_ret) {
gf_log (this->name, GF_LOG_ERROR,
- "setting xattrs on %s failed (%s)", loc->path,
+ "setting xattrs on %s failed (%s)", real_path,
strerror (errno));
}
- op_ret = posix_fstat_with_gfid (this, _fd, &stbuf);
+ op_ret = posix_fdstat (this, _fd, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -1774,12 +1686,12 @@ posix_create (call_frame_t *frame, xlator_t *this,
goto out;
}
- op_ret = posix_lstat_with_gfid (this, parentpath, &postparent);
+ op_ret = posix_pstat (this, loc->pargfid, par_path, &postparent);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
- "post-operation lstat on parent of %s failed: %s",
- loc->path, strerror (op_errno));
+ "post-operation lstat on parent %s failed: %s",
+ par_path, strerror (op_errno));
goto out;
}
@@ -1797,7 +1709,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
if (op_ret)
gf_log (this->name, GF_LOG_WARNING,
"failed to set the fd context path=%s fd=%p",
- loc->path, fd);
+ real_path, fd);
LOCK (&priv->lock);
{
@@ -1808,8 +1720,6 @@ posix_create (call_frame_t *frame, xlator_t *this,
op_ret = 0;
out:
- if (pathdup)
- GF_FREE (pathdup);
SET_TO_OLD_FS_ID ();
if ((-1 == op_ret) && (_fd != -1)) {
@@ -1837,7 +1747,6 @@ posix_open (call_frame_t *frame, xlator_t *this,
int32_t _fd = -1;
struct posix_fd *pfd = NULL;
struct posix_private *priv = NULL;
- gid_t gid = 0;
struct iatt stbuf = {0, };
DECLARE_OLD_FS_ID_VAR;
@@ -1851,22 +1760,13 @@ posix_open (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, &stbuf);
- op_ret = setgid_override (this, real_path, &gid);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
-
- SET_FS_ID (frame->root->uid, gid);
+ SET_FS_ID (frame->root->uid, frame->root->gid);
if (priv->o_direct)
flags |= O_DIRECT;
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
-
_fd = open (real_path, flags, 0);
if (_fd == -1) {
op_ret = -1;
@@ -1891,30 +1791,7 @@ posix_open (call_frame_t *frame, xlator_t *this,
if (op_ret)
gf_log (this->name, GF_LOG_WARNING,
"failed to set the fd context path=%s fd=%p",
- loc->path, fd);
-
-#ifndef HAVE_SET_FSID
- if (flags & O_CREAT) {
- op_ret = chown (real_path, frame->root->uid, gid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_log (this->name, GF_LOG_ERROR,
- "chown on %s failed: %s",
- real_path, strerror (op_errno));
- goto out;
- }
- }
-#endif
-
- if (flags & O_CREAT) {
- op_ret = posix_lstat_with_gfid (this, real_path, &stbuf);
- if (op_ret == -1) {
- op_errno = errno;
- gf_log (this->name, GF_LOG_ERROR, "lstat on (%s) "
- "failed: %s", real_path, strerror (op_errno));
- goto out;
- }
- }
+ real_path, fd);
LOCK (&priv->lock);
{
@@ -1945,7 +1822,6 @@ int
posix_readv (call_frame_t *frame, xlator_t *this,
fd_t *fd, size_t size, off_t offset)
{
- uint64_t tmp_pfd = 0;
int32_t op_ret = -1;
int32_t op_errno = 0;
int _fd = -1;
@@ -1965,14 +1841,13 @@ posix_readv (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL from fd=%p", fd);
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
if (!size) {
op_errno = EINVAL;
@@ -2014,7 +1889,7 @@ posix_readv (call_frame_t *frame, xlator_t *this,
* we read from
*/
- op_ret = posix_fstat_with_gfid (this, _fd, &stbuf);
+ op_ret = posix_fdstat (this, _fd, &stbuf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -2142,7 +2017,6 @@ posix_writev (call_frame_t *frame, xlator_t *this,
struct iatt postop = {0,};
int ret = -1;
- uint64_t tmp_pfd = 0;
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
@@ -2154,18 +2028,17 @@ posix_writev (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (priv, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL from fd=%p", fd);
op_errno = -ret;
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
- op_ret = posix_fstat_with_gfid (this, _fd, &preop);
+ op_ret = posix_fdstat (this, _fd, &preop);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -2201,7 +2074,7 @@ posix_writev (call_frame_t *frame, xlator_t *this,
fsync (_fd);
}
- ret = posix_fstat_with_gfid (this, _fd, &postop);
+ ret = posix_fdstat (this, _fd, &postop);
if (ret == -1) {
op_ret = -1;
op_errno = errno;
@@ -2235,7 +2108,7 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
VALIDATE_OR_GOTO (this->private, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
priv = this->private;
@@ -2273,13 +2146,13 @@ posix_flush (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
int ret = -1;
- uint64_t tmp_pfd = 0;
+ struct posix_fd *pfd = NULL;
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
@@ -2310,7 +2183,7 @@ posix_release (xlator_t *this,
priv = this->private;
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = fd_ctx_del (fd, this, &tmp_pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL from fd=%p", fd);
@@ -2352,7 +2225,6 @@ posix_fsync (call_frame_t *frame, xlator_t *this,
int _fd = -1;
struct posix_fd * pfd = NULL;
int ret = -1;
- uint64_t tmp_pfd = 0;
struct iatt preop = {0,};
struct iatt postop = {0,};
@@ -2370,18 +2242,17 @@ posix_fsync (call_frame_t *frame, xlator_t *this,
goto out;
#endif
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
"pfd not found in fd's ctx");
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
- op_ret = posix_fstat_with_gfid (this, _fd, &preop);
+ op_ret = posix_fdstat (this, _fd, &preop);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_WARNING,
@@ -2411,7 +2282,7 @@ posix_fsync (call_frame_t *frame, xlator_t *this,
}
}
- op_ret = posix_fstat_with_gfid (this, _fd, &postop);
+ op_ret = posix_fdstat (this, _fd, &postop);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_WARNING,
@@ -2450,7 +2321,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
VALIDATE_OR_GOTO (dict, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
dict_del (dict, GFID_XATTR_KEY);
@@ -2506,13 +2377,13 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (loc, out);
SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
priv = this->private;
if (loc->inode && IA_ISDIR(loc->inode->ia_type) && name &&
ZR_FILE_CONTENT_REQUEST(name)) {
- ret = posix_get_file_contents (this, real_path, name,
+ ret = posix_get_file_contents (this, loc->gfid, &name[15],
&file_contents);
if (ret < 0) {
op_errno = -ret;
@@ -2677,7 +2548,6 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
{
int32_t op_ret = -1;
int32_t op_errno = ENOENT;
- uint64_t tmp_pfd = 0;
struct posix_fd * pfd = NULL;
int _fd = -1;
int32_t list_offset = 0;
@@ -2697,14 +2567,13 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL from fd=%p", fd);
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
@@ -2832,7 +2701,6 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
struct posix_fd * pfd = NULL;
- uint64_t tmp_pfd = 0;
int _fd = -1;
data_pair_t * trav = NULL;
int ret = -1;
@@ -2845,14 +2713,13 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (fd, out);
VALIDATE_OR_GOTO (dict, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL from fd=%p", fd);
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
dict_del (dict, GFID_XATTR_KEY);
@@ -2889,13 +2756,14 @@ posix_removexattr (call_frame_t *frame, xlator_t *this,
DECLARE_OLD_FS_ID_VAR;
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
+
if (!strcmp (GFID_XATTR_KEY, name)) {
gf_log (this->name, GF_LOG_WARNING, "Remove xattr called"
- " on gfid for file %s", loc->path);
+ " on gfid for file %s", real_path);
goto out;
}
- MAKE_REAL_PATH (real_path, this, loc->path);
SET_FS_ID (frame->root->uid, frame->root->gid);
@@ -2904,7 +2772,7 @@ posix_removexattr (call_frame_t *frame, xlator_t *this,
op_errno = errno;
if (op_errno != ENOATTR && op_errno != EPERM)
gf_log (this->name, GF_LOG_ERROR,
- "removexattr on %s (for %s): %s", loc->path,
+ "removexattr on %s (for %s): %s", real_path,
name, strerror (op_errno));
goto out;
}
@@ -2926,13 +2794,13 @@ posix_fsyncdir (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
int ret = -1;
- uint64_t tmp_pfd = 0;
+ struct posix_fd *pfd = NULL;
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
op_errno = -ret;
gf_log (this->name, GF_LOG_WARNING,
@@ -3006,7 +2874,6 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
int ret = 0;
int _fd = -1;
- uint64_t tmp_pfd = 0;
struct posix_fd *pfd = NULL;
data_pair_t *trav = NULL;
@@ -3021,7 +2888,7 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
trav = xattr->members_list;
if (fd) {
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"failed to get pfd from fd=%p",
@@ -3030,15 +2897,14 @@ do_xattrop (call_frame_t *frame, xlator_t *this,
op_errno = EBADFD;
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
}
- if (loc && loc->path)
- MAKE_REAL_PATH (real_path, this, loc->path);
+ if (loc && !uuid_is_null (loc->gfid))
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
- if (loc) {
- path = gf_strdup (loc->path);
+ if (real_path) {
+ path = gf_strdup (real_path);
inode = loc->inode;
} else if (fd) {
inode = fd->inode;
@@ -3207,13 +3073,13 @@ posix_access (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (loc, out);
- MAKE_REAL_PATH (real_path, this, loc->path);
+ MAKE_INODE_HANDLE (real_path, this, loc, NULL);
op_ret = access (real_path, mask & 07);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "access failed on %s: %s",
- loc->path, strerror (op_errno));
+ real_path, strerror (op_errno));
goto out;
}
op_ret = 0;
@@ -3237,7 +3103,6 @@ posix_ftruncate (call_frame_t *frame, xlator_t *this,
struct iatt postop = {0,};
struct posix_fd *pfd = NULL;
int ret = -1;
- uint64_t tmp_pfd = 0;
struct posix_private *priv = NULL;
DECLARE_OLD_FS_ID_VAR;
@@ -3250,18 +3115,17 @@ posix_ftruncate (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL, fd=%p", fd);
op_errno = -ret;
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
- op_ret = posix_fstat_with_gfid (this, _fd, &preop);
+ op_ret = posix_fdstat (this, _fd, &preop);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -3280,7 +3144,7 @@ posix_ftruncate (call_frame_t *frame, xlator_t *this,
goto out;
}
- op_ret = posix_fstat_with_gfid (this, _fd, &postop);
+ op_ret = posix_fdstat (this, _fd, &postop);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -3309,7 +3173,6 @@ posix_fstat (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
struct iatt buf = {0,};
struct posix_fd *pfd = NULL;
- uint64_t tmp_pfd = 0;
int ret = -1;
struct posix_private *priv = NULL;
@@ -3323,18 +3186,17 @@ posix_fstat (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL, fd=%p", fd);
op_errno = -ret;
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
_fd = pfd->fd;
- op_ret = posix_fstat_with_gfid (this, _fd, &buf);
+ op_ret = posix_fdstat (this, _fd, &buf);
if (op_ret == -1) {
op_errno = errno;
gf_log (this->name, GF_LOG_ERROR, "fstat failed on fd=%p: %s",
@@ -3425,18 +3287,17 @@ posix_fentrylk (call_frame_t *frame, xlator_t *this,
int
-__posix_fill_readdir (DIR *dir, off_t off, size_t size, gf_dirent_t *entries,
- const char *real_path, const char *base_path)
+posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
+ gf_dirent_t *entries)
{
off_t in_case = -1;
size_t filled = 0;
- int ret = 0;
int count = 0;
+ char entrybuf[sizeof(struct dirent) + 256 + 8];
struct dirent *entry = NULL;
int32_t this_size = -1;
gf_dirent_t *this_entry = NULL;
- char hidden_path[PATH_MAX] = {0, };
- struct stat statbuf = {0, };
+ uuid_t rootgfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
if (!off) {
rewinddir (dir);
@@ -3455,7 +3316,8 @@ __posix_fill_readdir (DIR *dir, off_t off, size_t size, gf_dirent_t *entries,
}
errno = 0;
- entry = readdir (dir);
+ entry = NULL;
+ readdir_r (dir, (struct dirent *)entrybuf, &entry);
if (!entry) {
if (errno == EBADF) {
@@ -3467,7 +3329,7 @@ __posix_fill_readdir (DIR *dir, off_t off, size_t size, gf_dirent_t *entries,
break;
}
- if ((!strcmp (real_path, base_path))
+ if ((uuid_compare (fd->inode->gfid, rootgfid) == 0)
&& (!strcmp (entry->d_name, GF_REPLICATE_TRASH_DIR)))
continue;
@@ -3480,19 +3342,15 @@ __posix_fill_readdir (DIR *dir, off_t off, size_t size, gf_dirent_t *entries,
* when the cluster/dht xlator decides to distribute
* exended attribute backing file accross storage servers.
*/
- if ((!strcmp(real_path, base_path))
+ if ((uuid_compare (fd->inode->gfid, rootgfid) == 0)
&& (!strcmp(entry->d_name, ".attribute")))
continue;
#endif /* __NetBSD__ */
- if ((!strcmp (real_path, base_path))
+ if ((uuid_compare (fd->inode->gfid, rootgfid) == 0)
&& (!strncmp (GF_HIDDEN_PATH, entry->d_name,
strlen (GF_HIDDEN_PATH)))) {
- snprintf (hidden_path, PATH_MAX, "%s/%s", real_path,
- entry->d_name);
- ret = lstat (hidden_path, &statbuf);
- if (!ret && S_ISDIR (statbuf.st_mode))
- continue;
+ continue;
}
this_size = max (sizeof (gf_dirent_t),
@@ -3533,7 +3391,6 @@ int32_t
posix_do_readdir (call_frame_t *frame, xlator_t *this,
fd_t *fd, size_t size, off_t off, int whichop)
{
- uint64_t tmp_pfd = 0;
struct posix_fd *pfd = NULL;
DIR *dir = NULL;
int ret = -1;
@@ -3541,14 +3398,12 @@ posix_do_readdir (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
gf_dirent_t entries;
- char *real_path = NULL;
- int real_path_len = -1;
- char *entry_path = NULL;
- int entry_path_len = -1;
struct iatt stbuf = {0, };
- char base_path[PATH_MAX] = {0,};
gf_dirent_t *tmp_entry = NULL;
-
+#ifdef IGNORE_READDIRP_ATTRS
+ uuid_t gfid;
+ ia_type_t entry_type = 0;
+#endif
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
@@ -3556,38 +3411,13 @@ posix_do_readdir (call_frame_t *frame, xlator_t *this,
INIT_LIST_HEAD (&entries.list);
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL, fd=%p", fd);
op_errno = -ret;
goto out;
}
- pfd = (struct posix_fd *)(long)tmp_pfd;
- if (!pfd->path) {
- op_errno = EBADFD;
- gf_log (this->name, GF_LOG_WARNING,
- "pfd does not have path set (possibly file "
- "fd, fd=%p)", fd);
- goto out;
- }
-
- real_path = pfd->path;
- real_path_len = strlen (real_path);
-
- entry_path_len = real_path_len + NAME_MAX;
- entry_path = alloca (entry_path_len);
-
- strncpy(base_path, POSIX_BASE_PATH(this), sizeof(base_path));
- base_path[strlen(base_path)] = '/';
-
- if (!entry_path) {
- op_errno = errno;
- goto out;
- }
-
- strncpy (entry_path, real_path, entry_path_len);
- entry_path[real_path_len] = '/';
dir = pfd->dir;
@@ -3598,23 +3428,30 @@ posix_do_readdir (call_frame_t *frame, xlator_t *this,
goto out;
}
-
- LOCK (&fd->lock);
- {
- count = __posix_fill_readdir (dir, off, size, &entries,
- real_path, base_path);
-
- }
- UNLOCK (&fd->lock);
+ count = posix_fill_readdir (fd, dir, off, size, &entries);
/* pick ENOENT to indicate EOF */
op_errno = errno;
if (whichop == GF_FOP_READDIRP) {
list_for_each_entry (tmp_entry, &entries.list, list) {
- strcpy (entry_path + real_path_len + 1,
- tmp_entry->d_name);
- posix_lstat_with_gfid (this, entry_path, &stbuf);
+#ifdef IGNORE_READDIRP_ATTRS
+ ret = inode_grep_for_gfid (fd->inode->table, fd->inode,
+ tmp_entry->d_name, gfid,
+ &entry_type);
+ if (ret == 0) {
+ memset (&stbuf, 0, sizeof (stbuf));
+ uuid_copy (stbuf.ia_gfid, gfid);
+ posix_fill_ino_from_gfid (this, &stbuf);
+ stbuf.ia_type = entry_type;
+ } else {
+ posix_istat (this, fd->inode->gfid,
+ tmp_entry->d_name, &stbuf);
+ }
+#else
+ posix_istat (this, fd->inode->gfid,
+ tmp_entry->d_name, &stbuf);
+#endif
if (stbuf.ia_ino)
tmp_entry->d_ino = stbuf.ia_ino;
tmp_entry->d_stat = stbuf;
@@ -3690,7 +3527,6 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
char *buf = NULL;
int _fd = -1;
- uint64_t tmp_pfd = 0;
struct posix_fd *pfd = NULL;
@@ -3714,14 +3550,13 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
goto out;
}
- ret = fd_ctx_get (fd, this, &tmp_pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
gf_log (this->name, GF_LOG_WARNING,
"pfd is NULL, fd=%p", fd);
op_errno = -ret;
goto out;
}
- pfd = (struct posix_fd *)(long) tmp_pfd;
_fd = pfd->fd;
@@ -3809,6 +3644,7 @@ init (xlator_t *this)
uuid_t old_uuid = {0,};
uuid_t dict_uuid = {0,};
uuid_t gfid = {0,};
+ uuid_t rootgfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
dir_data = dict_get (this->options, "directory");
@@ -3949,6 +3785,16 @@ init (xlator_t *this)
"%s: failed to fetch gfid (%s)",
dir_data->data, strerror (errno));
goto out;
+ } else {
+ /* First time volume, set the GFID */
+ ret = sys_lsetxattr (dir_data->data, "trusted.gfid", rootgfid,
+ 16, XATTR_CREATE);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s: failed to set gfid (%s)",
+ dir_data->data, strerror (errno));
+ goto out;
+ }
}
op_ret = sys_lgetxattr (dir_data->data, "system.posix_acl_access",
@@ -4096,6 +3942,14 @@ init (xlator_t *this)
#endif
this->private = (void *)_private;
+ op_ret = posix_handle_init (this);
+ if (op_ret == -1) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Posix handle setup failed");
+ ret = -1;
+ goto out;
+ }
+
pthread_mutex_init (&_private->janitor_lock, NULL);
pthread_cond_init (&_private->janitor_cond, NULL);
INIT_LIST_HEAD (&_private->janitor_fds);
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 1733eadd1a8..c72adac9e45 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -52,6 +52,8 @@
#include "compat.h"
#include "timer.h"
#include "posix-mem-types.h"
+#include "posix-handle.h"
+
/**
* posix_fd - internal structure common to file and directory fd's
@@ -60,9 +62,10 @@
struct posix_fd {
int fd; /* fd returned by the kernel */
int32_t flags; /* flags for open/creat */
- char * path; /* used by setdents/getdents */
DIR * dir; /* handle returned by the kernel */
int flushwrites;
+ int odirect;
+ int op_performed;
struct list_head list; /* to add to the janitor list */
};
@@ -102,12 +105,12 @@ struct posix_private {
gf_boolean_t o_direct; /* always open files in O_DIRECT mode */
-/*
+/*
decide whether posix_unlink does open (file), unlink (file), close (fd)
instead of just unlink (file). with the former approach there is no lockout
of access to parent directory during removal of very large files for the
entire duration of freeing of data blocks.
-*/
+*/
gf_boolean_t background_unlink;
/* janitor thread which cleans up /.trash (created by replicate) */
@@ -116,31 +119,30 @@ struct posix_private {
char * trash_path;
/* lock for brick dir */
DIR *mount_lock;
+
+ struct stat handledir;
+
};
#define POSIX_BASE_PATH(this) (((struct posix_private *)this->private)->base_path)
#define POSIX_BASE_PATH_LEN(this) (((struct posix_private *)this->private)->base_path_length)
-#define MAKE_REAL_PATH(var, this, path) do { \
- var = alloca (strlen (path) + POSIX_BASE_PATH_LEN(this) + 2); \
- strcpy (var, POSIX_BASE_PATH(this)); \
- strcpy (&var[POSIX_BASE_PATH_LEN(this)], path); \
- } while (0)
-
-
/* Helper functions */
-int setgid_override (xlator_t *this, char *real_path, gid_t *gid);
-int posix_gfid_set (xlator_t *this, const char *path, dict_t *xattr_req);
-int posix_fstat_with_gfid (xlator_t *this, int fd, struct iatt *stbuf_p);
-int posix_lstat_with_gfid (xlator_t *this, const char *path, struct iatt *buf);
+int posix_gfid_set (xlator_t *this, const char *path, loc_t *loc,
+ dict_t *xattr_req);
+int posix_fdstat (xlator_t *this, int fd, struct iatt *stbuf_p);
+int posix_istat (xlator_t *this, uuid_t gfid, const char *basename,
+ struct iatt *iatt);
+int posix_pstat (xlator_t *this, uuid_t gfid, const char *real_path,
+ struct iatt *iatt);
dict_t *posix_lookup_xattr_fill (xlator_t *this, const char *path,
loc_t *loc, dict_t *xattr, struct iatt *buf);
int posix_handle_pair (xlator_t *this, const char *real_path,
data_pair_t *trav, int flags);
int posix_fhandle_pair (xlator_t *this, int fd, data_pair_t *trav, int flags);
void posix_spawn_janitor_thread (xlator_t *this);
-int posix_get_file_contents (xlator_t *this, const char *path,
+int posix_get_file_contents (xlator_t *this, uuid_t pargfid,
const char *name, char **contents);
int posix_set_file_contents (xlator_t *this, const char *path,
data_pair_t *trav, int flags);
@@ -149,5 +151,9 @@ int posix_gfid_heal (xlator_t *this, const char *path, dict_t *xattr_req);
int posix_entry_create_xattr_set (xlator_t *this, const char *path,
dict_t *dict);
+int posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd);
+int posix_fd_ctx_get_off (fd_t *fd, xlator_t *this, struct posix_fd **pfd,
+ off_t off);
+void posix_fill_ino_from_gfid (xlator_t *this, struct iatt *buf);
#endif /* _POSIX_H */