summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2016-06-07 21:27:10 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2016-07-29 09:00:46 -0700
commit263936a78901860977a6691c5c6d66bbc09a51df (patch)
tree40ccea0f818f44d67aa6b3080d37388c6d52f90a /xlators/storage
parent53b54f1a03a5fb93266f66453d228258598f8ef6 (diff)
storage/posix: Give correct errno for anon-fd operations
>Change-Id: Ia9e61d3baa6881eb7dc03dd8ddb6bfdde5a01958 >BUG: 1343906 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> >Reviewed-on: http://review.gluster.org/14669 >Smoke: Gluster Build System <jenkins@build.gluster.org> >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> >CentOS-regression: Gluster Build System <jenkins@build.gluster.org> >Reviewed-by: Raghavendra G <rgowdapp@redhat.com> BUG: 1360140 Change-Id: I553dd59424aaff9538e0798370846d653ca1cf32 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/15011 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix-aio.c6
-rw-r--r--xlators/storage/posix/src/posix-helpers.c29
-rw-r--r--xlators/storage/posix/src/posix.c59
-rw-r--r--xlators/storage/posix/src/posix.h3
4 files changed, 51 insertions, 46 deletions
diff --git a/xlators/storage/posix/src/posix-aio.c b/xlators/storage/posix/src/posix-aio.c
index 3d4d2f69dbd..685b298ce2f 100644
--- a/xlators/storage/posix/src/posix-aio.c
+++ b/xlators/storage/posix/src/posix-aio.c
@@ -179,9 +179,8 @@ posix_aio_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
priv = this->private;
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL from fd=%p", fd);
goto err;
@@ -337,9 +336,8 @@ posix_aio_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
priv = this->private;
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL from fd=%p", fd);
goto err;
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 731547b84dc..5831035815e 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -1613,7 +1613,8 @@ out:
}
static int
-__posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
+__posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p,
+ int *op_errno_p)
{
uint64_t tmp_pfd = 0;
struct posix_fd *pfd = NULL;
@@ -1621,6 +1622,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
char *real_path = NULL;
char *unlink_path = NULL;
int _fd = -1;
+ int op_errno = 0;
DIR *dir = NULL;
struct posix_private *priv = NULL;
@@ -1636,6 +1638,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_READ_FAILED,
"Failed to get fd context for a non-anonymous fd, "
"gfid: %s", uuid_utoa (fd->inode->gfid));
+ op_errno = EINVAL;
goto out;
}
@@ -1646,11 +1649,13 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
"Failed to create handle path (%s)",
uuid_utoa (fd->inode->gfid));
ret = -1;
+ op_errno = EINVAL;
goto out;
}
pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
if (!pfd) {
+ op_errno = ENOMEM;
goto out;
}
pfd->fd = -1;
@@ -1658,6 +1663,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
if (fd->inode->ia_type == IA_IFDIR) {
dir = opendir (real_path);
if (!dir) {
+ op_errno = errno;
GF_FREE (pfd);
pfd = NULL;
goto out;
@@ -1678,7 +1684,8 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
_fd = open (unlink_path, fd->flags);
}
if (_fd == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
+ op_errno = errno;
+ gf_msg (this->name, GF_LOG_ERROR, op_errno,
P_MSG_READ_FAILED,
"Failed to get anonymous "
"real_path: %s _fd = %d", real_path, _fd);
@@ -1694,6 +1701,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
ret = __fd_ctx_set (fd, this, (uint64_t) (long) pfd);
if (ret != 0) {
+ op_errno = ENOMEM;
if (_fd != -1)
close (_fd);
if (dir)
@@ -1705,6 +1713,9 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
ret = 0;
out:
+ if (ret < 0 && op_errno_p)
+ *op_errno_p = op_errno;
+
if (pfd_p)
*pfd_p = pfd;
return ret;
@@ -1712,13 +1723,14 @@ out:
int
-posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd)
+posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd,
+ int *op_errno)
{
int ret;
LOCK (&fd->inode->lock);
{
- ret = __posix_fd_ctx_get (fd, this, pfd);
+ ret = __posix_fd_ctx_get (fd, this, pfd, op_errno);
}
UNLOCK (&fd->inode->lock);
@@ -1929,16 +1941,17 @@ posix_fsyncer_process (xlator_t *this, call_stub_t *stub, gf_boolean_t do_fsync)
struct posix_fd *pfd = NULL;
int ret = -1;
struct posix_private *priv = NULL;
+ int op_errno = 0;
priv = this->private;
- ret = posix_fd_ctx_get (stub->args.fd, this, &pfd);
+ ret = posix_fd_ctx_get (stub->args.fd, this, &pfd, &op_errno);
if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
+ gf_msg (this->name, GF_LOG_ERROR, op_errno,
P_MSG_GET_FDCTX_FAILED,
"could not get fdctx for fd(%s)",
uuid_utoa (stub->args.fd->inode->gfid));
- call_unwind_error (stub, -1, EINVAL);
+ call_unwind_error (stub, -1, op_errno);
return;
}
@@ -1971,7 +1984,7 @@ posix_fsyncer_syncfs (xlator_t *this, struct list_head *head)
int ret = -1;
stub = list_entry (head->prev, call_stub_t, list);
- ret = posix_fd_ctx_get (stub->args.fd, this, &pfd);
+ ret = posix_fd_ctx_get (stub->args.fd, this, &pfd, NULL);
if (ret)
return;
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 836e90614f1..6c704588efb 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -571,9 +571,8 @@ posix_fsetattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
goto out;
}
@@ -663,6 +662,7 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iatt *statpre, struct iatt *statpost, dict_t *xdata)
{
int32_t ret = -1;
+ int32_t op_errno = 0;
struct posix_fd *pfd = NULL;
gf_boolean_t locked = _gf_false;
@@ -674,7 +674,7 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
goto out;
@@ -819,6 +819,7 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
dict_t *xdata)
{
int32_t ret = -1;
+ int32_t op_errno = 0;
struct posix_fd *pfd = NULL;
gf_boolean_t locked = _gf_false;
@@ -830,7 +831,7 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
goto out;
@@ -3001,9 +3002,8 @@ posix_readv (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL from fd=%p", fd);
goto out;
@@ -3237,7 +3237,7 @@ posix_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
VALIDATE_OR_GOTO (priv, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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,
"pfd is NULL from fd=%p", fd);
@@ -3423,9 +3423,8 @@ posix_flush (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL on fd=%p", fd);
goto out;
@@ -3546,9 +3545,8 @@ posix_fsync (call_frame_t *frame, xlator_t *this,
return 0;
}
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd not found in fd's ctx");
goto out;
@@ -4658,7 +4656,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, frame->root->gid);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
@@ -4880,9 +4878,8 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (fd, out);
VALIDATE_OR_GOTO (dict, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL from fd=%p", fd);
goto out;
@@ -5111,9 +5108,8 @@ posix_fremovexattr (call_frame_t *frame, xlator_t *this,
goto out;
}
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL from fd=%p", fd);
goto out;
@@ -5172,9 +5168,8 @@ posix_fsyncdir (call_frame_t *frame, xlator_t *this,
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (fd, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (ret < 0) {
- op_errno = -ret;
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
"pfd is NULL, fd=%p", fd);
goto out;
@@ -5543,12 +5538,12 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
VALIDATE_OR_GOTO (this, out);
if (fd) {
- op_ret = posix_fd_ctx_get (fd, this, &pfd);
+ op_ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, EBADFD,
+ gf_msg (this->name, GF_LOG_WARNING,
+ fop_log_level(GF_FOP_FXATTROP, op_errno),
P_MSG_PFD_GET_FAILED, "failed to get pfd from"
" fd=%p", fd);
- op_errno = EBADFD;
goto out;
}
_fd = pfd->fd;
@@ -5678,9 +5673,9 @@ posix_ftruncate (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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);
op_errno = -ret;
goto out;
@@ -5748,11 +5743,10 @@ posix_fstat (call_frame_t *frame, xlator_t *this,
priv = this->private;
VALIDATE_OR_GOTO (priv, out);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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);
- op_errno = -ret;
goto out;
}
@@ -5874,13 +5868,14 @@ posix_fill_readdir (fd_t *fd, DIR *dir, off_t off, size_t size,
char *hpath = NULL;
int len = 0;
int ret = 0;
+ int op_errno = 0;
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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);
count = -1;
- errno = -ret;
+ errno = op_errno;
goto out;
}
@@ -6164,11 +6159,10 @@ posix_do_readdir (call_frame_t *frame, xlator_t *this,
INIT_LIST_HEAD (&entries.list);
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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,
"pfd is NULL, fd=%p", fd);
- op_errno = -ret;
goto out;
}
@@ -6337,11 +6331,10 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
goto out;
}
- ret = posix_fd_ctx_get (fd, this, &pfd);
+ 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,
"pfd is NULL, fd=%p", fd);
- op_errno = -ret;
goto out;
}
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 80ddab64b50..7ca0fea90b7 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -248,7 +248,8 @@ int posix_gfid_heal (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr
int posix_entry_create_xattr_set (xlator_t *this, const char *path,
dict_t *dict);
-int posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd);
+int posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd,
+ int *op_errno);
void posix_fill_ino_from_gfid (xlator_t *this, struct iatt *buf);
gf_boolean_t posix_special_xattr (char **pattern, char *key);