summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-gfid-path.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage/posix/src/posix-gfid-path.c')
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c116
1 files changed, 21 insertions, 95 deletions
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
index 4a81be28169..1b38e9b0479 100644
--- a/xlators/storage/posix/src/posix-gfid-path.c
+++ b/xlators/storage/posix/src/posix-gfid-path.c
@@ -8,102 +8,24 @@
cases as published by the Free Software Foundation.
*/
-#include "common-utils.h"
-#include "xlator.h"
-#include "syscall.h"
-#include "logging.h"
+#include <stdint.h>
+
+#include <glusterfs/compat-errno.h>
+#include <glusterfs/syscall.h>
+#include <glusterfs/logging.h>
#include "posix-messages.h"
#include "posix-mem-types.h"
#include "posix-gfid-path.h"
#include "posix.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 = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + 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 = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + 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;
-}
-
gf_boolean_t
posix_is_gfid2path_xattr(const char *name)
{
if (name && strncmp(GFID2PATH_XATTR_KEY_PREFIX, name,
- GFID2PATH_XATTR_KEY_PREFIX_LENGTH) == 0) {
+ GFID2PATH_XATTR_KEY_PREFIX_LENGTH) == 0)
return _gf_true;
- } else {
- return _gf_false;
- }
+
+ return _gf_false;
}
static int gf_posix_xattr_enotsup_log;
@@ -128,9 +50,7 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
char keybuffer[4096] = {
0,
};
- char value_buf[8192] = {
- 0,
- };
+
uuid_t pargfid = {
0,
};
@@ -161,6 +81,12 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
}
found = _gf_true;
} else {
+ char value_buf[8192] = {
+ 0,
+ };
+ char xattr_value[8192] = {
+ 0,
+ };
have_val = _gf_false;
size = sys_llistxattr(real_path, value_buf, sizeof(value_buf) - 1);
if (size > 0) {
@@ -209,15 +135,16 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
remaining_size = size;
list_offset = 0;
while (remaining_size > 0) {
- snprintf(keybuffer, sizeof(keybuffer), "%s", list + list_offset);
+ len = snprintf(keybuffer, sizeof(keybuffer), "%s",
+ list + list_offset);
if (!posix_is_gfid2path_xattr(keybuffer)) {
goto ignore;
}
found = _gf_true;
- size = sys_lgetxattr(real_path, keybuffer, value_buf,
- sizeof(value_buf) - 1);
+ size = sys_lgetxattr(real_path, keybuffer, xattr_value,
+ sizeof(xattr_value) - 1);
if (size == -1) {
ret = -1;
*op_errno = errno;
@@ -229,17 +156,16 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
}
/* Parse pargfid from xattr value*/
- strncpy(pargfid_str, value_buf, 36);
+ strncpy(pargfid_str, xattr_value, 36);
pargfid_str[36] = '\0';
gf_uuid_parse(pargfid_str, pargfid);
/* Convert pargfid to path */
ret = posix_resolve_dirgfid_to_path(pargfid, priv->base_path,
- &value_buf[37], &paths[i]);
+ &xattr_value[37], &paths[i]);
i++;
ignore:
- len = strlen(keybuffer);
remaining_size -= (len + 1);
list_offset += (len + 1);
} /* while (remaining_size > 0) */