From 5304eaa662b263791baf0e5a9bd616446a3919ef Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Mon, 28 Oct 2019 18:42:41 +0530 Subject: posix: Improve MAKE_HANDLE_GFID_PATH and MAKE_HANDLE_RELPATH Avoid one function call to set the gfid_path in buffer Change-Id: If9b95801b05c34d262fac9a275492c794d12bf58 Updates #748 Signed-off-by: Mohit Agrawal --- xlators/storage/posix/src/posix-entry-ops.c | 6 ++--- xlators/storage/posix/src/posix-handle.c | 36 +++++++---------------------- xlators/storage/posix/src/posix-handle.h | 20 ++++++++-------- xlators/storage/posix/src/posix-helpers.c | 2 +- xlators/storage/posix/src/posix.h | 4 ++++ 5 files changed, 26 insertions(+), 42 deletions(-) diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index ef2ef0a8b3b..795a8d6a043 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -108,7 +108,7 @@ posix_symlinks_match(xlator_t *this, loc_t *loc, uuid_t gfid) loc->pargfid[0], loc->pargfid[1], uuid_utoa(loc->pargfid), loc->name); - MAKE_HANDLE_GFID_PATH(dir_handle, this, gfid, NULL); + MAKE_HANDLE_GFID_PATH(dir_handle, this, gfid); len = sys_readlink(dir_handle, linkname_actual, PATH_MAX); if (len < 0 || len == PATH_MAX) { if (len == PATH_MAX) { @@ -930,12 +930,12 @@ posix_move_gfid_to_unlink(xlator_t *this, uuid_t gfid, loc_t *loc) { char *unlink_path = NULL; char *gfid_path = NULL; - int ret = 0; + int ret = -1; struct posix_private *priv_posix = NULL; priv_posix = (struct posix_private *)this->private; - MAKE_HANDLE_GFID_PATH(gfid_path, this, gfid, NULL); + MAKE_HANDLE_GFID_PATH(gfid_path, this, gfid); POSIX_GET_FILE_UNLINK_PATH(priv_posix->base_path, loc->inode->gfid, unlink_path); diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c index f4686a96ed9..f58f5416ff0 100644 --- a/xlators/storage/posix/src/posix-handle.c +++ b/xlators/storage/posix/src/posix-handle.c @@ -263,9 +263,7 @@ posix_handle_relpath(xlator_t *this, uuid_t gfid, const char *basename, char *uuid_str = NULL; int len = 0; - len = SLEN("../") + SLEN("../") + SLEN("00/") + SLEN("00/") + - SLEN(UUID0_STR) + 1 /* '\0' */ - ; + len = POSIX_GFID_HANDLE_RELSIZE; if (basename) { len += (strlen(basename) + 1); @@ -449,8 +447,7 @@ out: } int -posix_handle_gfid_path(xlator_t *this, uuid_t gfid, const char *basename, - char *buf, size_t buflen) +posix_handle_gfid_path(xlator_t *this, uuid_t gfid, char *buf, size_t buflen) { struct posix_private *priv = NULL; char *uuid_str = NULL; @@ -458,16 +455,9 @@ posix_handle_gfid_path(xlator_t *this, uuid_t gfid, const char *basename, priv = this->private; - len = priv->base_path_length /* option directory "/export" */ - + SLEN("/") + SLEN(GF_HIDDEN_PATH) + SLEN("/") + SLEN("00/") + - SLEN("00/") + SLEN(UUID0_STR) + 1 /* '\0' */ - ; + len = POSIX_GFID_HANDLE_SIZE(priv->base_path_length); - if (basename) { - len += (strlen(basename) + 1); - } else { - len += 256; /* worst-case for directory's symlink-handle expansion */ - } + len += 256; /* worst-case for directory's symlink-handle expansion */ if ((buflen < len) || !buf) return len; @@ -475,22 +465,12 @@ posix_handle_gfid_path(xlator_t *this, uuid_t gfid, const char *basename, uuid_str = uuid_utoa(gfid); if (__is_root_gfid(gfid)) { - if (basename) { - len = snprintf(buf, buflen, "%s/%s", priv->base_path, basename); - } else { - len = snprintf(buf, buflen, "%s", priv->base_path); - } - goto out; - } - - if (basename) { - len = snprintf(buf, buflen, "%s/%s/%02x/%02x/%s/%s", priv->base_path, - GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str, basename); + len = snprintf(buf, buflen, "%s", priv->base_path); } else { len = snprintf(buf, buflen, "%s/%s/%02x/%02x/%s", priv->base_path, GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str); } -out: + return len; } @@ -869,10 +849,10 @@ int posix_handle_unset_gfid(xlator_t *this, uuid_t gfid) { char *path = NULL; - int ret = 0; + int ret = -1; struct stat stat; - MAKE_HANDLE_GFID_PATH(path, this, gfid, NULL); + MAKE_HANDLE_GFID_PATH(path, this, gfid); ret = sys_lstat(path, &stat); diff --git a/xlators/storage/posix/src/posix-handle.h b/xlators/storage/posix/src/posix-handle.h index 3e9020c0f8a..70c68c3d89c 100644 --- a/xlators/storage/posix/src/posix-handle.h +++ b/xlators/storage/posix/src/posix-handle.h @@ -111,22 +111,23 @@ } \ } while (0) -#define MAKE_HANDLE_GFID_PATH(var, this, gfid, base) \ +#define MAKE_HANDLE_GFID_PATH(var, this, gfid) \ do { \ int __len = 0; \ - __len = posix_handle_gfid_path(this, gfid, base, NULL, 0); \ - if (__len <= 0) \ - break; \ + struct posix_private *__priv = this->private; \ + __len = POSIX_GFID_HANDLE_SIZE(__priv->base_path_length); \ + __len += 256; \ var = alloca(__len); \ - __len = posix_handle_gfid_path(this, gfid, base, var, __len); \ + __len = posix_handle_gfid_path(this, gfid, var, __len); \ } while (0) #define MAKE_HANDLE_RELPATH(var, this, gfid, base) \ do { \ int __len; \ - __len = posix_handle_relpath(this, gfid, base, NULL, 0); \ - if (__len <= 0) \ - break; \ + __len = POSIX_GFID_HANDLE_RELSIZE; \ + if (base) { \ + __len += (strlen(base) + 1); \ + } \ var = alloca(__len); \ __len = posix_handle_relpath(this, gfid, base, var, __len); \ } while (0) @@ -184,8 +185,7 @@ } while (0) int -posix_handle_gfid_path(xlator_t *this, uuid_t gfid, const char *basename, - char *buf, size_t len); +posix_handle_gfid_path(xlator_t *this, uuid_t gfid, char *buf, size_t len); int posix_handle_hard(xlator_t *this, const char *path, uuid_t gfid, diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 96061acd5a3..ef3c3284636 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -1351,7 +1351,7 @@ del_stale_dir_handle(xlator_t *this, uuid_t gfid) 0, }; - MAKE_HANDLE_GFID_PATH(hpath, this, gfid, NULL); + MAKE_HANDLE_GFID_PATH(hpath, this, gfid); /* check that it is valid directory handle */ size = sys_lstat(hpath, &stbuf); diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index bbcd7e564e8..8c4e1c0d103 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -59,6 +59,10 @@ #define POSIX_GFID_HANDLE_SIZE(base_path_len) \ (base_path_len + SLEN("/") + SLEN(GF_HIDDEN_PATH) + SLEN("/") + \ SLEN("00/") + SLEN("00/") + SLEN(UUID0_STR) + 1) /* '\0' */; + +#define POSIX_GFID_HANDLE_RELSIZE \ + SLEN("../") + SLEN("../") + SLEN("00/") + SLEN("00/") + SLEN(UUID0_STR) + 1; + #define GF_UNLINK_TRUE 0x0000000000000001 #define GF_UNLINK_FALSE 0x0000000000000000 -- cgit