diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2019-12-10 10:56:55 +0200 |
---|---|---|
committer | Amar Tumballi <amarts@gmail.com> | 2020-01-03 11:35:05 +0000 |
commit | 1e56e7acc3ced4f49d4494556bf6c86cd017b4ea (patch) | |
tree | 909b4e53b5a3bfb8b387092d0293a565044b6235 | |
parent | 5cfd4553d163b96c9c409db68264d1b6af2fe49e (diff) |
posix: improve posix_{set_gfid2path_xattr|remove_gfid2path_xattr} funcs
1. Move them to posix-entry-ops.c and make them static.
2. Remove useless 'val' parameter allocation and snprintf() in
posix_set_gfid2path_xattr(), as it was identical to pgfid_bname.
Change-Id: I41f3946c6c42aee9d7cf1150e21b442438fbcce2
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
-rw-r--r-- | xlators/storage/posix/src/posix-entry-ops.c | 64 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-gfid-path.c | 77 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-gfid-path.h | 4 |
3 files changed, 64 insertions, 81 deletions
diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index aadc590b376..d721304c79a 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -331,6 +331,38 @@ out: return 0; } +static 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; + const size_t key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + + GF_XXH64_DIGEST_LENGTH * 2 + 1; + int ret = 0; + int len; + + len = snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid), + bname); + gf_xxh64_wrapper((unsigned char *)pgfid_bname, len, + GF_XXHSUM64_DEFAULT_SEED, xxh64); + key = alloca(key_size); + snprintf(key, key_size, GFID2PATH_XATTR_KEY_PREFIX "%s", xxh64); + + ret = sys_lsetxattr(path, key, pgfid_bname, len, 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); + } + + return ret; +} + int posix_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, dev_t dev, mode_t umask, dict_t *xdata) @@ -1080,6 +1112,38 @@ posix_skip_non_linkto_unlink(dict_t *xdata, loc_t *loc, char *key, return skip_unlink; } +static 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; + const size_t key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + + GF_XXH64_DIGEST_LENGTH * 2 + 1; + int len; + + len = snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid), + bname); + gf_xxh64_wrapper((unsigned char *)pgfid_bname, len, + GF_XXHSUM64_DEFAULT_SEED, xxh64); + 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); + } + + return ret; +} + int32_t posix_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, dict_t *xdata) diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c index b5e141ebfd0..1b38e9b0479 100644 --- a/xlators/storage/posix/src/posix-gfid-path.c +++ b/xlators/storage/posix/src/posix-gfid-path.c @@ -18,83 +18,6 @@ #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; - const size_t key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + - GF_XXH64_DIGEST_LENGTH * 2 + 1; - const size_t val_size = UUID_CANONICAL_FORM_LEN + NAME_MAX + 2; - int ret = 0; - int len; - - GF_VALIDATE_OR_GOTO("posix", this, err); - - len = snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid), - bname); - gf_xxh64_wrapper((unsigned char *)pgfid_bname, len, - GF_XXHSUM64_DEFAULT_SEED, xxh64); - key = alloca(key_size); - snprintf(key, key_size, GFID2PATH_XATTR_KEY_PREFIX "%s", xxh64); - - val = alloca(val_size); - len = snprintf(val, val_size, "%s/%s", uuid_utoa(pgfid), bname); - - ret = sys_lsetxattr(path, key, val, len, 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; - const size_t key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + - GF_XXH64_DIGEST_LENGTH * 2 + 1; - int len; - - GF_VALIDATE_OR_GOTO("posix", this, err); - - len = snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid), - bname); - gf_xxh64_wrapper((unsigned char *)pgfid_bname, len, - GF_XXHSUM64_DEFAULT_SEED, xxh64); - 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) { diff --git a/xlators/storage/posix/src/posix-gfid-path.h b/xlators/storage/posix/src/posix-gfid-path.h index 63b2a8c61fa..79096e5893f 100644 --- a/xlators/storage/posix/src/posix-gfid-path.h +++ b/xlators/storage/posix/src/posix-gfid-path.h @@ -20,10 +20,6 @@ #include "uuid.h" // for uuid_t #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 *); gf_boolean_t posix_is_gfid2path_xattr(const char *name); int32_t |