From cd1872ae49d7bc83403fce6821c102edc4e97796 Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Mon, 28 Oct 2019 21:53:01 +0530 Subject: posix: Improve MAKE_HANDLE_PATH Pass the maximum buffer (PATH_MAX) to posix_handle_path to avoid the posix_handle_path call again. Change-Id: I7d18313870218dc028c5f7fc94d6ec85a2bdb332 Updates #761 Signed-off-by: Mohit Agrawal --- xlators/storage/posix/src/posix-entry-ops.c | 13 +++++++------ xlators/storage/posix/src/posix-inode-fd-ops.c | 23 ++++------------------- xlators/storage/posix/src/posix-inode-handle.h | 13 ++++++------- 3 files changed, 17 insertions(+), 32 deletions(-) (limited to 'xlators/storage') diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index 795a8d6a043..4d83c094b98 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -645,12 +645,13 @@ posix_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, if (!gf_uuid_is_null(uuid_req)) { op_ret = posix_istat(this, loc->inode, uuid_req, NULL, &stbuf); if ((op_ret == 0) && IA_ISDIR(stbuf.ia_type)) { - size = posix_handle_path(this, uuid_req, NULL, NULL, 0); - if (size > 0) - gfid_path = alloca(size); - - if (gfid_path) - posix_handle_path(this, uuid_req, NULL, gfid_path, size); + gfid_path = alloca(PATH_MAX); + size = posix_handle_path(this, uuid_req, NULL, gfid_path, PATH_MAX); + if (size <= 0) { + op_errno = ESTALE; + op_ret = -1; + goto out; + } if (frame->root->pid != GF_CLIENT_PID_SELF_HEALD) { gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_DIR_OF_SAME_ID, diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index 56f8d344640..17c2fe4fab4 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -5297,20 +5297,13 @@ posix_fill_readdir(fd_t *fd, DIR *dir, off_t off, size_t size, } if (skip_dirs) { - len = posix_handle_path(this, fd->inode->gfid, NULL, NULL, 0); + hpath = alloca(PATH_MAX); + len = posix_handle_path(this, fd->inode->gfid, NULL, hpath, PATH_MAX); if (len <= 0) { errno = ESTALE; count = -1; goto out; } - hpath = alloca(len + 256); /* NAME_MAX */ - - if (posix_handle_path(this, fd->inode->gfid, NULL, hpath, len) <= 0) { - errno = ESTALE; - count = -1; - goto out; - } - len = strlen(hpath); hpath[len] = '/'; } @@ -5478,22 +5471,14 @@ posix_readdirp_fill(xlator_t *this, fd_t *fd, gf_dirent_t *entries, itable = fd->inode->table; - len = posix_handle_path(this, fd->inode->gfid, NULL, NULL, 0); + hpath = alloca(PATH_MAX); + len = posix_handle_path(this, fd->inode->gfid, NULL, hpath, PATH_MAX); if (len <= 0) { gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLEPATH_FAILED, "Failed to create handle path, fd=%p, gfid=%s", fd, uuid_utoa(fd->inode->gfid)); return -1; } - - hpath = alloca(len + 256); /* NAME_MAX */ - if (posix_handle_path(this, fd->inode->gfid, NULL, hpath, len) <= 0) { - gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLEPATH_FAILED, - "Failed to create handle path, fd=%p, gfid=%s", fd, - uuid_utoa(fd->inode->gfid)); - return -1; - } - len = strlen(hpath); hpath[len] = '/'; diff --git a/xlators/storage/posix/src/posix-inode-handle.h b/xlators/storage/posix/src/posix-inode-handle.h index 78a85b34c31..36c47f2bebc 100644 --- a/xlators/storage/posix/src/posix-inode-handle.h +++ b/xlators/storage/posix/src/posix-inode-handle.h @@ -44,14 +44,13 @@ #define MAKE_HANDLE_PATH(var, this, gfid, base) \ do { \ - int __len; \ - __len = posix_handle_path(this, gfid, base, NULL, 0); \ - if (__len <= 0) \ - break; \ - var = alloca(__len); \ - __len = posix_handle_path(this, gfid, base, var, __len); \ - if (__len <= 0) \ + int __len = 0; \ + int tot = PATH_MAX; \ + var = alloca(tot); \ + __len = posix_handle_path(this, gfid, base, var, tot); \ + if (__len <= 0) { \ var = NULL; \ + } \ } while (0) /* TODO: it is not a good idea to change a variable which -- cgit