diff options
author | Susant Palai <spalai@redhat.com> | 2015-11-25 05:07:03 -0500 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2015-12-08 23:01:52 -0800 |
commit | 848bf0db0dde745e1f3a966db0143b7003bd49b5 (patch) | |
tree | 15075a00a06522f95b9610507b027b1acbedfad8 /xlators/storage | |
parent | 988495ef1f8bb737d5edd079dec5635309097a62 (diff) |
posix: fix posix_fgetxattr to return the correct error
posix_fgetxattr used to not updating op_ret
and op_errno (initialized to -1 and ENOENT respectively)
on success cases. Hence, it can return ENOENT even if all
the opertions were sucessful.
Change-Id: I5db3c1821208166a052d734b0be2553d009b8ee4
BUG: 1285230
Signed-off-by: Susant Palai <spalai@redhat.com>
Reviewed-on: http://review.gluster.org/12745
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r-- | xlators/storage/posix/src/posix.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index ac0cb5f4730..d727f930552 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -4239,7 +4239,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, dict_t *xdata) { int32_t op_ret = -1; - int32_t op_errno = ENOENT; + int32_t op_errno = EINVAL; struct posix_fd * pfd = NULL; int _fd = -1; int32_t list_offset = 0; @@ -4261,6 +4261,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, ret = posix_fd_ctx_get (fd, this, &pfd); if (ret < 0) { + op_ret = -1; op_errno = -ret; gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL, "pfd is NULL from fd=%p", fd); @@ -4272,15 +4273,21 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, /* Get the total size */ dict = get_new_dict (); if (!dict) { + op_ret = -1; + op_errno = ENOMEM; goto out; } if (name && !strcmp (name, GLUSTERFS_OPEN_FD_COUNT)) { ret = dict_set_uint32 (dict, (char *)name, 1); - if (ret < 0) + if (ret < 0) { + op_ret = -1; + size = -1; + op_errno = ENOMEM; gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_DICT_SET_FAILED, "Failed to set " "dictionary value for %s", name); + } goto done; } @@ -4288,8 +4295,11 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, strlen (GLUSTERFS_GET_OBJECT_SIGNATURE)) == 0) { op_ret = posix_fdget_objectsignature (_fd, dict); if (op_ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, 0, 0, + "posix_fdget_objectsignature failed"); op_errno = -op_ret; op_ret = -1; + size = -1; } goto done; @@ -4309,6 +4319,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, #endif size = sys_fgetxattr (_fd, key, NULL, 0); if (size == -1) { + op_ret = -1; op_errno = errno; if (errno == ENODATA || errno == ENOATTR) { gf_msg_debug (this->name, 0, "fgetxattr failed" @@ -4325,6 +4336,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, value = GF_CALLOC (size + 1, sizeof(char), gf_posix_mt_char); if (!value) { op_ret = -1; + op_errno = ENOMEM; goto out; } size = sys_fgetxattr (_fd, key, value, size); @@ -4337,20 +4349,25 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, GF_FREE (value); goto out; } + value [size] = '\0'; op_ret = dict_set_dynptr (dict, key, value, size); if (op_ret < 0) { + op_errno = -op_ret; + op_ret = -1; gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_DICT_SET_FAILED, "dict set operation " "on key %s failed", key); GF_FREE (value); goto out; } + goto done; } size = sys_flistxattr (_fd, NULL, 0); if (size == -1) { + op_ret = -1; op_errno = errno; if ((errno == ENOTSUP) || (errno == ENOSYS)) { GF_LOG_OCCASIONALLY (gf_posix_xattr_enotsup_log, @@ -4372,7 +4389,8 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, list = alloca (size + 1); if (!list) { - op_errno = errno; + op_ret = -1; + op_errno = ENOMEM; goto out; } @@ -4418,6 +4436,8 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, op_ret = dict_set_dynptr (dict, key, value, size); if (op_ret) { + op_errno = -op_ret; + op_ret = -1; gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_DICT_SET_FAILED, "dict set operation " "failed on key %s", key); |