From a62b16b72b03f2b7c25c24ea9ac5968453a92009 Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Thu, 29 Jun 2017 05:45:34 -0400 Subject: storage/posix: New gfid2path infra With this infra, a new xattr is stored on each entry creation as below. trusted.gfid2path. = / 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 storage.gfid2path on Updates: #139 Change-Id: I369974cd16703c45ee87f82e6c2ff5a987a6cc6a Signed-off-by: Kotresh HR Reviewed-on: https://review.gluster.org/17488 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Aravinda VK Reviewed-by: Amar Tumballi --- xlators/storage/posix/src/posix-gfid-path.c | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 xlators/storage/posix/src/posix-gfid-path.c (limited to 'xlators/storage/posix/src/posix-gfid-path.c') 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. + 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; +} -- cgit