From 7f2da3aab0f32daca97176c3bfed76c70497f9b2 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 24 Sep 2009 00:59:50 +0000 Subject: libglusterfsclient: Re-validate root inode on every path resolution If the root inode's is outdated, send a revalidate on it. A revalidate on root inode also reduces the window in which an op will fail over distribute because the layout of the root directory did not get constructed when we sent the lookup on root in glusterfs_init. That can happen when not all children of a distribute volume were up at the time of glusterfs_init. Signed-off-by: Anand V. Avati BUG: 256 (revalidates should be sent on '/' in libglusterfsclient.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=256 --- libglusterfsclient/src/libglusterfsclient-dentry.c | 23 ++++++++++++++++++++++ libglusterfsclient/src/libglusterfsclient.c | 1 + 2 files changed, 24 insertions(+) (limited to 'libglusterfsclient/src') diff --git a/libglusterfsclient/src/libglusterfsclient-dentry.c b/libglusterfsclient/src/libglusterfsclient-dentry.c index 1c8910159..22b9bc50c 100644 --- a/libglusterfsclient/src/libglusterfsclient-dentry.c +++ b/libglusterfsclient/src/libglusterfsclient-dentry.c @@ -103,6 +103,8 @@ __libgf_client_path_to_parenti (libglusterfs_client_ctx_t *ctx, inode_t *curr = NULL; inode_t *parent = NULL; size_t pathlen = 0; + loc_t rootloc = {0, }; + int ret = -1; pathlen = STRLEN_0 (path); resolved_till = CALLOC (1, pathlen); @@ -112,6 +114,27 @@ __libgf_client_path_to_parenti (libglusterfs_client_ctx_t *ctx, GF_VALIDATE_OR_GOTO("libglusterfsclient-dentry", pathdup, out); parent = inode_ref (itable->root); + /* If the root inode's is outdated, send a revalidate on it. + * A revalidate on root inode also reduces the window in which an + * op will fail over distribute because the layout of the root + * directory did not get constructed when we sent the lookup on + * root in glusterfs_init. That can happen when not all children of a + * distribute volume were up at the time of glusterfs_init. + */ + if (!libgf_is_iattr_cache_valid (ctx, parent, NULL, + LIBGF_VALIDATE_LOOKUP)) { + libgf_client_loc_fill (&rootloc, ctx, 1, 0, "/"); + ret = libgf_client_lookup (ctx, &rootloc, NULL, NULL, NULL); + if (ret == -1) { + gf_log ("libglusterfsclient-dentry", GF_LOG_ERROR, + "Root inode revalidation failed"); + inode_unref (parent); + parent = NULL; + goto out; + } + libgf_client_loc_wipe (&rootloc); + } + curr = NULL; component = strtok_r (pathdup, "/", &strtokptr); diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 408e4f9bf..87103666b 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -1355,6 +1355,7 @@ glusterfs_init (glusterfs_init_params_t *init_ctx, uint32_t fakefsid) return NULL; } libgf_client_loc_wipe (&new_loc); + libgf_alloc_inode_ctx (ctx, ctx->itable->root); first_init = 0; -- cgit