summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-helpers.c
diff options
context:
space:
mode:
authorMohit Agrawal <moagrawa@redhat.com>2017-06-12 16:30:20 +0530
committerJeff Darcy <jeff@pl.atyp.us>2017-07-03 11:08:01 +0000
commit89faa4661d1ef66a9f8fe3b79e26bf4505ab6c61 (patch)
tree258e0f2701a1b097292ee9edb5fd596514122cf1 /xlators/storage/posix/src/posix-helpers.c
parent97a08698058962a4ddc783008c92ee94f08740a9 (diff)
posix: Avoid one extra call of l(get|list)xattr call after use buffer in posix_getxattr
Problem: In posix xlator posix_(f)getxattr is calling system call(sys_lgetxattr) two times to fetch the xattr value. Solution: After use the extra buffer for first time calling we can avoid second attempt of system call(sys_lgetxattr) calling in posix_getxattr for most of the xattrs. BUG: 1460659 Change-Id: I0d8da776c5bc86653d874a4629a73bbf65c621b8 Signed-off-by: Mohit Agrawal <moagrawa@redhat.com> Reviewed-on: https://review.gluster.org/17520 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Amar Tumballi <amarts@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Kinglong Mee
Diffstat (limited to 'xlators/storage/posix/src/posix-helpers.c')
-rw-r--r--xlators/storage/posix/src/posix-helpers.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 8457905..85005e0 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -2130,20 +2130,31 @@ posix_fetch_signature_xattr (char *real_path,
int32_t ret = 0;
char *memptr = NULL;
ssize_t xattrsize = 0;
+ char val_buf[2048] = {0,};
+ gf_boolean_t have_val = _gf_false;
- xattrsize = sys_lgetxattr (real_path, key, NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA)))
- return 0;
- if (xattrsize == -1)
- goto error_return;
-
+ xattrsize = sys_lgetxattr (real_path, key, val_buf,
+ sizeof(val_buf) - 1);
+ if (xattrsize >= 0) {
+ have_val = _gf_true;
+ } else {
+ if (errno == ERANGE)
+ xattrsize = sys_lgetxattr (real_path, key, NULL, 0);
+ if ((errno == ENOATTR) || (errno == ENODATA))
+ return 0;
+ if (xattrsize == -1)
+ goto error_return;
+ }
memptr = GF_CALLOC (xattrsize + 1, sizeof (char), gf_posix_mt_char);
if (!memptr)
goto error_return;
- ret = sys_lgetxattr (real_path, key, memptr, xattrsize);
- if (ret == -1)
- goto freemem;
-
+ if (have_val) {
+ memcpy (memptr, val_buf, xattrsize);
+ } else {
+ ret = sys_lgetxattr (real_path, key, memptr, xattrsize);
+ if (ret == -1)
+ goto freemem;
+ }
ret = dict_set_dynptr (xattr, (char *)key, memptr, xattrsize);
if (ret)
goto freemem;