Blob Blame History Raw
From b4c2715028ff0a28da97510f521bfb670b3b2777 Mon Sep 17 00:00:00 2001
From: Susant Palai <spalai@redhat.com>
Date: Wed, 25 Nov 2015 05:07:03 -0500
Subject: [PATCH 08/26] 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.

BUG: 1319634
Change-Id: I8ec4bab6f405b2fdf91fe386e960b603d4fbc3a8
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>
Signed-off-by: Susant Palai <spalai@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/70312
Reviewed-by: Nithya Balachandran <nbalacha@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 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 761bc4e..512af41 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -4447,7 +4447,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;
@@ -4469,6 +4469,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);
@@ -4480,15 +4481,21 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
         /* Get the total size */
         dict = dict_new ();
         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;
         }
 
@@ -4496,8 +4503,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;
@@ -4517,6 +4527,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"
@@ -4533,6 +4544,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);
@@ -4545,20 +4557,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,
@@ -4580,7 +4597,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;
         }
 
@@ -4626,6 +4644,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);
-- 
1.7.1