diff options
Diffstat (limited to 'xlators/storage/posix/src/posix-helpers.c')
-rw-r--r-- | xlators/storage/posix/src/posix-helpers.c | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index b6f3bf6686b..c2da976533a 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -1609,7 +1609,6 @@ out: return ret; } - static int __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p) { @@ -1617,13 +1616,25 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p) struct posix_fd *pfd = NULL; int ret = -1; char *real_path = NULL; + char *unlink_path = NULL; int _fd = -1; DIR *dir = NULL; + struct posix_private *priv = NULL; + + priv = this->private; + ret = __fd_ctx_get (fd, this, &tmp_pfd); if (ret == 0) { pfd = (void *)(long) tmp_pfd; - ret = 0; + goto out; + } + if (!fd_is_anonymous(fd)) { + gf_msg (this->name, GF_LOG_ERROR, 0, + P_MSG_READ_FAILED, + "Failed to get fd context for a non-anonymous fd, " + "file: %s, gfid: %s", real_path, + uuid_utoa (fd->inode->gfid)); goto out; } @@ -1634,7 +1645,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p) MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL); if (!real_path) { gf_msg (this->name, GF_LOG_ERROR, 0, - P_MSG_HANDLE_PATH_CREATE_FAILED, + P_MSG_READ_FAILED, "Failed to create handle path (%s)", uuid_utoa (fd->inode->gfid)); ret = -1; @@ -1660,6 +1671,16 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p) if (fd->inode->ia_type == IA_IFREG) { _fd = open (real_path, O_RDWR|O_LARGEFILE); if (_fd == -1) { + POSIX_GET_FILE_UNLINK_PATH (priv->base_path, + fd->inode->gfid, + unlink_path); + _fd = open (unlink_path, fd->flags); + } + if (_fd == -1) { + gf_msg (this->name, GF_LOG_ERROR, errno, + P_MSG_READ_FAILED, + "Failed to get anonymous " + "real_path: %s _fd = %d", real_path, _fd); GF_FREE (pfd); pfd = NULL; goto out; @@ -2161,3 +2182,40 @@ posix_fdget_objectsignature (int fd, dict_t *xattr) error_return: return -EINVAL; } + + +int +posix_inode_ctx_get (inode_t *inode, xlator_t *this, uint64_t *ctx) +{ + int ret = -1; + uint64_t ctx_int = 0; + + GF_VALIDATE_OR_GOTO (this->name, this, out); + GF_VALIDATE_OR_GOTO (this->name, inode, out); + + ret = inode_ctx_get (inode, this, &ctx_int); + + if (ret) + return ret; + + if (ctx) + *ctx = ctx_int; + +out: + return ret; +} + + +int +posix_inode_ctx_set (inode_t *inode, xlator_t *this, uint64_t ctx) +{ + int ret = -1; + + GF_VALIDATE_OR_GOTO (this->name, this, out); + GF_VALIDATE_OR_GOTO (this->name, inode, out); + GF_VALIDATE_OR_GOTO (this->name, ctx, out); + + ret = inode_ctx_set (inode, this, &ctx); +out: + return ret; +} |