summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-gfid-path.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2019-08-28 19:38:01 +0300
committerKotresh HR <khiremat@redhat.com>2019-09-05 08:57:12 +0000
commitf6d6c0f65f7b512724694b3436358e1113cbfccb (patch)
tree7b04c3c1391bbbbb6bc87f9d0b94caff430ed089 /xlators/storage/posix/src/posix-gfid-path.c
parentee24c0438ce40b0c6faf6581fd4eb162767d8a90 (diff)
posix*.c: remove unneeded strlen() calls
In various places, we can re-use knowledge of string length or result of snprintf() and such instead of strlen(). Change-Id: I4c9b1decf1169b3f8ac83699a0afbd7c38fad746 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-gfid-path.c')
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
index d7ba324..37b68c2 100644
--- a/xlators/storage/posix/src/posix-gfid-path.c
+++ b/xlators/storage/posix/src/posix-gfid-path.c
@@ -30,26 +30,25 @@ posix_set_gfid2path_xattr(xlator_t *this, const char *path, uuid_t pgfid,
};
char *key = NULL;
char *val = NULL;
- size_t key_size = 0;
- size_t val_size = 0;
+ 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);
- snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid),
- bname);
- gf_xxh64_wrapper((unsigned char *)pgfid_bname, strlen(pgfid_bname),
+ 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_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);
+ len = snprintf(val, val_size, "%s/%s", uuid_utoa(pgfid), bname);
- ret = sys_lsetxattr(path, key, val, strlen(val), XATTR_CREATE);
+ 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);
@@ -72,16 +71,16 @@ posix_remove_gfid2path_xattr(xlator_t *this, const char *path, uuid_t pgfid,
};
int ret = 0;
char *key = NULL;
- size_t key_size = 0;
+ 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);
- snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid),
- bname);
- gf_xxh64_wrapper((unsigned char *)pgfid_bname, strlen(pgfid_bname),
+ 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_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);
@@ -214,7 +213,8 @@ 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;
@@ -244,7 +244,6 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
i++;
ignore:
- len = strlen(keybuffer);
remaining_size -= (len + 1);
list_offset += (len + 1);
} /* while (remaining_size > 0) */