summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-gfid-path.c
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2017-06-29 05:45:34 -0400
committerJeff Darcy <jeff@pl.atyp.us>2017-07-10 14:51:14 +0000
commita62b16b72b03f2b7c25c24ea9ac5968453a92009 (patch)
tree7521978a597377f082172a2b5454e83bbab02bbf /xlators/storage/posix/src/posix-gfid-path.c
parent9156a743aa76c955d18c9bfcb7c1a38ba00da890 (diff)
storage/posix: New gfid2path infra
With this infra, a new xattr is stored on each entry creation as below. trusted.gfid2path.<xxhash> = <pargfid>/<basename> If there are hardlinks, multiple xattrs would be present. Fops which are impacted: create, mknod, link, symlink, rename, unlink Option to enable: gluster vol set <VOLNAME> storage.gfid2path on Updates: #139 Change-Id: I369974cd16703c45ee87f82e6c2ff5a987a6cc6a Signed-off-by: Kotresh HR <khiremat@redhat.com> Reviewed-on: https://review.gluster.org/17488 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Aravinda VK <avishwan@redhat.com> Reviewed-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-gfid-path.c')
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c85
1 files changed, 85 insertions, 0 deletions
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;
+}