From 11a19ce031932640584f8bc207274f4e08d97c5f Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Fri, 27 Apr 2012 18:43:23 +0530 Subject: Resolve: Assign correct path while resolving Change-Id: Ia17ff38a60225dd2e9115aaa298bed42f9e43f56 BUG: 812277 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.com/3248 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/inode.c | 7 +++--- libglusterfs/src/inode.h | 1 + libglusterfs/src/xlator.c | 36 ++++++++++++++++++++++++++++ libglusterfs/src/xlator.h | 1 + xlators/mount/fuse/src/fuse-resolve.c | 5 ++-- xlators/protocol/server/src/server-resolve.c | 15 ++++-------- 6 files changed, 49 insertions(+), 16 deletions(-) diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index 1db829792..c1a7efc09 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -1095,8 +1095,9 @@ __inode_path (inode_t *inode, const char *name, char **bufp) int len = 0; char *buf = NULL; - if (!inode) { - gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found"); + if (!inode || uuid_is_null (inode->gfid)) { + GF_ASSERT (0); + gf_log_callingfn (THIS->name, GF_LOG_WARNING, "invalid inode"); return -1; } @@ -1153,7 +1154,7 @@ __inode_path (inode_t *inode, const char *name, char **bufp) if (!__is_root_gfid (itrav->gfid)) { snprintf (&buf[i-GFID_STR_PFX_LEN], GFID_STR_PFX_LEN, - "", uuid_utoa (itrav->gfid)); + INODE_PATH_FMT, uuid_utoa (itrav->gfid)); buf[i-1] = '>'; } diff --git a/libglusterfs/src/inode.h b/libglusterfs/src/inode.h index f6401c5b9..7a296e0d2 100644 --- a/libglusterfs/src/inode.h +++ b/libglusterfs/src/inode.h @@ -29,6 +29,7 @@ #include #define DEFAULT_INODE_MEMPOOL_ENTRIES 32 * 1024 +#define INODE_PATH_FMT "" struct _inode_table; typedef struct _inode_table inode_table_t; diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 1641a1909..16a931716 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -552,6 +552,42 @@ loc_wipe (loc_t *loc) memset (loc, 0, sizeof (*loc)); } +int +loc_path (loc_t *loc, const char *bname) +{ + int ret = 0; + + if (loc->path) + goto out; + + ret = -1; + + if (bname && !strlen (bname)) + bname = NULL; + + if (!bname) + goto inode_path; + + if (loc->parent && !uuid_is_null (loc->parent->gfid)) { + ret = inode_path (loc->parent, bname, (char**)&loc->path); + } else if (!uuid_is_null (loc->pargfid)) { + ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT"/%s", + uuid_utoa (loc->pargfid), bname); + } + + if (loc->path) + goto out; + +inode_path: + if (loc->inode && !uuid_is_null (loc->inode->gfid)) { + ret = inode_path (loc->inode, NULL, (char **)&loc->path); + } else if (!uuid_is_null (loc->gfid)) { + ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT, + uuid_utoa (loc->gfid)); + } +out: + return ret; +} int loc_copy (loc_t *dst, loc_t *src) diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 2663b041a..4c55e979f 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -876,6 +876,7 @@ void inode_destroy_notify (inode_t *inode, const char *xlname); int loc_copy (loc_t *dst, loc_t *src); #define loc_dup(src, dst) loc_copy(dst, src) void loc_wipe (loc_t *loc); +int loc_path (loc_t *loc, const char *bname); int xlator_mem_acct_init (xlator_t *xl, int num_types); int is_gf_log_command (xlator_t *trans, const char *name, char *value); int glusterd_check_log_level (const char *value); diff --git a/xlators/mount/fuse/src/fuse-resolve.c b/xlators/mount/fuse/src/fuse-resolve.c index abb11dbb1..b1eff83dc 100644 --- a/xlators/mount/fuse/src/fuse-resolve.c +++ b/xlators/mount/fuse/src/fuse-resolve.c @@ -197,12 +197,11 @@ fuse_resolve_gfid (fuse_state_t *state) } resolve_loc->inode = inode_new (state->itable); - ret = inode_path (resolve_loc->inode, NULL, - (char **)&resolve_loc->path); + ret = loc_path (resolve_loc, NULL); if (ret <= 0) { gf_log (THIS->name, GF_LOG_WARNING, - "failed to get the path from inode %s", + "failed to get the path for inode %s", uuid_utoa (resolve->gfid)); } diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c index 4992fb530..e44fc2de3 100644 --- a/xlators/protocol/server/src/server-resolve.c +++ b/xlators/protocol/server/src/server-resolve.c @@ -179,17 +179,13 @@ resolve_gfid (call_frame_t *frame) resolve = state->resolve_now; resolve_loc = &resolve->resolve_loc; - if (!uuid_is_null (resolve->pargfid)) { + if (!uuid_is_null (resolve->pargfid)) uuid_copy (resolve_loc->gfid, resolve->pargfid); - resolve_loc->inode = inode_new (state->itable); - ret = inode_path (resolve_loc->inode, NULL, - (char **)&resolve_loc->path); - } else if (!uuid_is_null (resolve->gfid)) { + else if (!uuid_is_null (resolve->gfid)) uuid_copy (resolve_loc->gfid, resolve->gfid); - resolve_loc->inode = inode_new (state->itable); - ret = inode_path (resolve_loc->inode, NULL, - (char **)&resolve_loc->path); - } + + resolve_loc->inode = inode_new (state->itable); + ret = loc_path (resolve_loc, NULL); STACK_WIND (frame, resolve_gfid_cbk, BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, @@ -197,7 +193,6 @@ resolve_gfid (call_frame_t *frame) return 0; } - int resolve_continue (call_frame_t *frame) { -- cgit