summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/Makefile.am5
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c85
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.h25
-rw-r--r--xlators/storage/posix/src/posix.c79
-rw-r--r--xlators/storage/posix/src/posix.h1
5 files changed, 193 insertions, 2 deletions
diff --git a/xlators/storage/posix/src/Makefile.am b/xlators/storage/posix/src/Makefile.am
index 2245098c9e4..8ec460578b5 100644
--- a/xlators/storage/posix/src/Makefile.am
+++ b/xlators/storage/posix/src/Makefile.am
@@ -4,12 +4,13 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage
posix_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
-posix_la_SOURCES = posix.c posix-helpers.c posix-handle.c posix-aio.c
+posix_la_SOURCES = posix.c posix-helpers.c posix-handle.c posix-aio.c \
+ posix-gfid-path.c
posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(LIBAIO) \
$(ACL_LIBS)
noinst_HEADERS = posix.h posix-mem-types.h posix-handle.h posix-aio.h \
- posix-messages.h
+ posix-messages.h posix-gfid-path.h
AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
-I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src \
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
new file mode 100644
index 00000000000..500f4d81c24
--- /dev/null
+++ b/xlators/storage/posix/src/posix-gfid-path.c
@@ -0,0 +1,85 @@
+/*
+ Copyright (c) 2017 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of GlusterFS.
+
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+*/
+
+#include "common-utils.h"
+#include "xlator.h"
+#include "syscall.h"
+#include "logging.h"
+#include "posix-messages.h"
+
+int32_t
+posix_set_gfid2path_xattr (xlator_t *this, const char *path, uuid_t pgfid,
+ const char *bname)
+{
+ char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,};
+ char pgfid_bname[1024] = {0,};
+ char *key = NULL;
+ char *val = NULL;
+ size_t key_size = 0;
+ size_t val_size = 0;
+ int ret = 0;
+
+ GF_VALIDATE_OR_GOTO ("posix", this, err);
+
+ snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid),
+ bname);
+ gf_xxh64_wrapper ((unsigned char *) pgfid_bname,
+ strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64);
+ key_size = strlen(GFID2PATH_XATTR_KEY_PREFIX) + GF_XXH64_DIGEST_LENGTH*2+1;
+ key = alloca (key_size);
+ snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64);
+
+ val_size = UUID_CANONICAL_FORM_LEN + NAME_MAX + 2;
+ val = alloca (val_size);
+ snprintf (val, val_size, "%s/%s", uuid_utoa (pgfid), bname);
+
+ ret = sys_lsetxattr (path, key, val, strlen(val), XATTR_CREATE);
+ if (ret == -1) {
+ gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
+ "setting gfid2path xattr failed on %s: key = %s ",
+ path, key);
+ goto err;
+ }
+ return 0;
+ err:
+ return -1;
+}
+
+int32_t
+posix_remove_gfid2path_xattr (xlator_t *this, const char *path,
+ uuid_t pgfid, const char *bname)
+{
+ char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,};
+ char pgfid_bname[1024] = {0,};
+ int ret = 0;
+ char *key = NULL;
+ size_t key_size = 0;
+
+ GF_VALIDATE_OR_GOTO ("posix", this, err);
+
+ snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid),
+ bname);
+ gf_xxh64_wrapper ((unsigned char *) pgfid_bname,
+ strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64);
+ key_size = strlen(GFID2PATH_XATTR_KEY_PREFIX) + GF_XXH64_DIGEST_LENGTH*2+1;
+ key = alloca (key_size);
+ snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64);
+
+ ret = sys_lremovexattr (path, key);
+ if (ret == -1) {
+ gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
+ "removing gfid2path xattr failed on %s: key = %s",
+ path, key);
+ goto err;
+ }
+ return 0;
+ err:
+ return -1;
+}
diff --git a/xlators/storage/posix/src/posix-gfid-path.h b/xlators/storage/posix/src/posix-gfid-path.h
new file mode 100644
index 00000000000..dbe0c59540d
--- /dev/null
+++ b/xlators/storage/posix/src/posix-gfid-path.h
@@ -0,0 +1,25 @@
+/*
+ Copyright (c) 2017 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of GlusterFS.
+
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+*/
+
+#ifndef _POSIX_GFID_PATH_H
+#define _POSIX_GFID_PATH_H
+
+#include "xlator.h"
+#include "common-utils.h"
+
+#define MAX_GFID2PATH_LINK_SUP 500
+
+int32_t
+posix_set_gfid2path_xattr (xlator_t *, const char *, uuid_t,
+ const char *);
+int32_t
+posix_remove_gfid2path_xattr (xlator_t *, const char *, uuid_t,
+ const char *);
+#endif /* _POSIX_GFID_PATH_H */
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 45c35203480..87da16694a5 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -57,6 +57,7 @@
#include "glusterfs-acl.h"
#include "posix-messages.h"
#include "events.h"
+#include "posix-gfid-path.h"
extern char *marker_xattrs[];
#define ALIGN_SIZE 4096
@@ -1415,6 +1416,11 @@ post_op:
XATTR_CREATE, op_ret, this, ignore);
}
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
+ loc->name);
+ }
+
ignore:
op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
if (op_ret) {
@@ -2121,6 +2127,17 @@ posix_unlink (call_frame_t *frame, xlator_t *this,
}
}
+ if (priv->gfid2path && (stbuf.ia_nlink > 1)) {
+ op_ret = posix_remove_gfid2path_xattr (this, real_path,
+ loc->pargfid,
+ loc->name);
+ if (op_ret < 0) {
+ /* Allow unlink if pgfid xattr is not set. */
+ if (errno != ENOATTR)
+ goto out;
+ }
+ }
+
unwind_dict = dict_new ();
if (!unwind_dict) {
op_errno = -ENOMEM;
@@ -2382,6 +2399,12 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,
XATTR_CREATE, op_ret, this, ignore);
}
+
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
+ loc->name);
+ }
+
ignore:
op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
if (op_ret) {
@@ -2459,6 +2482,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
int nlink = 0;
char *pgfid_xattr_key = NULL;
int32_t nlink_samepgfid = 0;
+ char *gfid_path = NULL;
dict_t *unwind_dict = NULL;
gf_boolean_t locked = _gf_false;
gf_boolean_t get_link_count = _gf_false;
@@ -2645,7 +2669,20 @@ posix_rename (call_frame_t *frame, xlator_t *this,
op_ret,
this, unlock);
}
+
+ if (!IA_ISDIR (oldloc->inode->ia_type) && priv->gfid2path) {
+ MAKE_HANDLE_ABSPATH (gfid_path, this,
+ oldloc->inode->gfid);
+
+ posix_remove_gfid2path_xattr (this, gfid_path,
+ oldloc->pargfid,
+ oldloc->name);
+ posix_set_gfid2path_xattr (this, gfid_path,
+ newloc->pargfid,
+ newloc->name);
+ }
}
+
unlock:
if (locked) {
pthread_mutex_unlock (&ctx_new->pgfid_lock);
@@ -2823,6 +2860,23 @@ posix_link (call_frame_t *frame, xlator_t *this,
}
}
+ if (priv->gfid2path) {
+ if (stbuf.ia_nlink <= MAX_GFID2PATH_LINK_SUP) {
+ op_ret = posix_set_gfid2path_xattr (this, real_newpath,
+ newloc->pargfid,
+ newloc->name);
+ if (op_ret) {
+ op_errno = errno;
+ goto out;
+ }
+ } else {
+ gf_msg (this->name, GF_LOG_INFO, 0,
+ P_MSG_XATTR_NOTSUP, "Link count exceeded. "
+ "gfid2path xattr not set (path:%s gfid:%s)",
+ real_newpath, uuid_utoa (newloc->inode->gfid));
+ }
+ }
+
op_ret = 0;
out:
@@ -3012,6 +3066,11 @@ posix_create (call_frame_t *frame, xlator_t *this,
SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,
XATTR_CREATE, op_ret, this, ignore);
}
+
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
+ loc->name);
+ }
ignore:
op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
if (op_ret) {
@@ -6918,6 +6977,9 @@ struct posix_private *priv = NULL;
GF_OPTION_RECONF ("update-link-count-parent", priv->update_pgfid_nlinks,
options, bool, out);
+ GF_OPTION_RECONF ("gfid2path", priv->gfid2path,
+ options, bool, out);
+
GF_OPTION_RECONF ("node-uuid-pathinfo", priv->node_uuid_pathinfo,
options, bool, out);
@@ -7396,6 +7458,18 @@ init (xlator_t *this)
" set.");
}
+ tmp_data = dict_get (this->options, "gfid2path");
+ if (tmp_data) {
+ if (gf_string2boolean (tmp_data->data,
+ &_private->gfid2path) == -1) {
+ ret = -1;
+ gf_msg (this->name, GF_LOG_ERROR, 0,
+ P_MSG_INVALID_OPTION, "wrong value provided "
+ "for 'gfid2path'");
+ goto out;
+ }
+ }
+
ret = dict_get_str (this->options, "glusterd-uuid", &guuid);
if (!ret) {
if (gf_uuid_parse (guuid, _private->glusterd_uuid))
@@ -7728,6 +7802,11 @@ struct volume_options options[] = {
.default_value = "off",
.description = "Enable placeholders for gfid to path conversion"
},
+ { .key = {"gfid2path"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "Enable logging metadata for gfid to path conversion"
+ },
#if GF_DARWIN_HOST_OS
{ .key = {"xattr-user-namespace-mode"},
.type = GF_OPTION_TYPE_STR,
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index febd4326aa1..332c0ab4f49 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -160,6 +160,7 @@ struct posix_private {
uint32_t batch_fsync_delay_usec;
gf_boolean_t update_pgfid_nlinks;
+ gf_boolean_t gfid2path;
/* seconds to sleep between health checks */
uint32_t health_check_interval;