From 83d4349b695893a9f0957a6e2c3629dce4b7354e Mon Sep 17 00:00:00 2001 From: Ravishankar N Date: Mon, 29 May 2017 21:38:14 +0530 Subject: posix: use the correct op_errno Problem: If readdir/fstat was performed on a directory that was removed, posix_fd_ctx_get() fails with ENOENT but we incorrectly use the ret value (-1 in this case) as op_errno, logging "Operation not permitted" messages in the brick logs. Also in case of fstat, the -1 op_errno was also propagated to the client via stack unwind, causing the message to appear in protocol/client logs as well. Fix: Use the right op_errno in readdir, fstat and writev. Also, if posix_fd_ctx_get() failed with ENOENT, convert it into EBADF because ENOENT is not a valid error for an fd operation. > Reviewed-on: https://review.gluster.org/17414 > Smoke: Gluster Build System > Reviewed-by: Pranith Kumar Karampuri > Tested-by: Pranith Kumar Karampuri > NetBSD-regression: NetBSD Build System > Reviewed-by: Amar Tumballi > CentOS-regression: Gluster Build System (cherry picked from commit de92c363c95d16966dbcc9d8763fd4448dd84d13) Change-Id: Ie43c0789d5040ec73b7cf885d015a183b8c64d70 BUG: 1457616 Signed-off-by: Ravishankar N Reviewed-on: https://review.gluster.org/17435 NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Pranith Kumar Karampuri --- xlators/storage/posix/src/posix-helpers.c | 18 +++++++++++++----- xlators/storage/posix/src/posix.c | 4 +--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 3a97da6a79f..d39a77bbe06 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -1695,7 +1695,13 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p, if (fd->inode->ia_type == IA_IFDIR) { dir = sys_opendir (real_path); if (!dir) { - op_errno = errno; + (errno == ENOENT) ? (op_errno = EBADF) : + (op_errno = errno); + gf_msg (this->name, GF_LOG_ERROR, errno, + P_MSG_READ_FAILED, + "Failed to get anonymous fd for " + "real_path: %s. Returning %s.", real_path, + strerror(op_errno)); GF_FREE (pfd); pfd = NULL; goto out; @@ -1716,11 +1722,13 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p, _fd = open (unlink_path, fd->flags); } if (_fd == -1) { - op_errno = errno; - gf_msg (this->name, GF_LOG_ERROR, op_errno, + (errno == ENOENT) ? (op_errno = EBADF) : + (op_errno = errno); + gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READ_FAILED, - "Failed to get anonymous " - "real_path: %s _fd = %d", real_path, _fd); + "Failed to get anonymous fd for " + "real_path: %s. Returning %s.", real_path, + strerror(op_errno)); GF_FREE (pfd); pfd = NULL; goto out; diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index c78decd8482..b1a529bcfee 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -3419,7 +3419,6 @@ posix_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, if (ret < 0) { gf_msg (this->name, GF_LOG_WARNING, ret, P_MSG_PFD_NULL, "pfd is NULL from fd=%p", fd); - op_errno = -ret; goto out; } @@ -5956,7 +5955,6 @@ posix_fstat (call_frame_t *frame, xlator_t *this, if (ret < 0) { gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL, "pfd is NULL, fd=%p", fd); - op_errno = -ret; goto out; } @@ -6388,7 +6386,7 @@ posix_do_readdir (call_frame_t *frame, xlator_t *this, ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno); if (ret < 0) { - gf_msg (this->name, GF_LOG_WARNING, -ret, P_MSG_PFD_NULL, + gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL, "pfd is NULL, fd=%p", fd); goto out; } -- cgit