summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src/libglusterfsclient-dentry.c
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-03 01:31:37 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-03 00:39:59 -0700
commit57dc67ce5583ebaaa8c96900b6f279752b896e31 (patch)
tree2858ab742c416a380f238b4d27e36a1bf6bce216 /libglusterfsclient/src/libglusterfsclient-dentry.c
parentb896ec15fb123b77025394d53f019f7fa12bad3e (diff)
libglusterfsclient: Simplify inode and stat caching
There is a mechanism for caching the inode numbers got from a lookup and a struct stat got from a stat or fstat but I wasnt sure if it worked. This commit simplifies cache updates and checks and the accompanying tests have made sure that the cache does work. Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfsclient/src/libglusterfsclient-dentry.c')
-rw-r--r--libglusterfsclient/src/libglusterfsclient-dentry.c68
1 files changed, 13 insertions, 55 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient-dentry.c b/libglusterfsclient/src/libglusterfsclient-dentry.c
index 089a2c38c..09820457b 100644
--- a/libglusterfsclient/src/libglusterfsclient-dentry.c
+++ b/libglusterfsclient/src/libglusterfsclient-dentry.c
@@ -91,9 +91,8 @@ strcpy_till (char *dest, const char *dname, char delim)
* return - should never return NULL. should at least return '/' inode.
*/
static inode_t *
-__libgf_client_path_to_parenti (inode_table_t *itable,
- const char *path,
- time_t lookup_timeout,
+__libgf_client_path_to_parenti (libglusterfs_client_ctx_t *ctx,
+ inode_table_t *itable, const char *path,
char **reslv)
{
char *resolved_till = NULL;
@@ -104,10 +103,6 @@ __libgf_client_path_to_parenti (inode_table_t *itable,
inode_t *curr = NULL;
inode_t *parent = NULL;
size_t pathlen = 0;
- time_t current, prev;
- libglusterfs_client_inode_ctx_t *inode_ctx = NULL;
- uint64_t ptr = 0;
- int32_t op_ret = 0;
pathlen = STRLEN_0 (path);
resolved_till = CALLOC (1, pathlen);
@@ -126,27 +121,9 @@ __libgf_client_path_to_parenti (inode_table_t *itable,
if (!curr) {
break;
}
-
- op_ret = inode_ctx_get (curr, itable->xl, &ptr);
- if (op_ret == -1) {
- errno = EINVAL;
+ if (!libgf_is_iattr_cache_valid (ctx, curr, NULL,
+ LIBGF_VALIDATE_LOOKUP))
break;
- }
-
- inode_ctx = (libglusterfs_client_inode_ctx_t *)(long)ptr;
- memset (&current, 0, sizeof (current));
- current = time (NULL);
-
- pthread_mutex_lock (&inode_ctx->lock);
- {
- prev = inode_ctx->previous_lookup_time;
- }
- pthread_mutex_unlock (&inode_ctx->lock);
-
- if ((prev < 0)
- || (lookup_timeout < (current - prev))) {
- break;
- }
/* It is OK to append the component even if it is the
last component in the path, because, if 'next_component'
@@ -237,9 +214,6 @@ __do_path_resolve (loc_t *loc, libglusterfs_client_ctx_t *ctx,
loc_t new_loc = {0, };
char *pathname = NULL, *directory = NULL;
char *file = NULL;
- time_t current, prev;
- libglusterfs_client_inode_ctx_t *inode_ctx = NULL;
- uint64_t ptr = 0;
parent = loc->parent;
if (parent) {
@@ -251,9 +225,8 @@ __do_path_resolve (loc_t *loc, libglusterfs_client_ctx_t *ctx,
resolved = strdup (loc->path);
resolved = dirname (resolved);
} else {
- parent = __libgf_client_path_to_parenti (ctx->itable, loc->path,
- ctx->lookup_timeout,
- &resolved);
+ parent = __libgf_client_path_to_parenti (ctx, ctx->itable,
+ loc->path, &resolved);
}
if (parent == NULL) {
@@ -292,29 +265,14 @@ __do_path_resolve (loc_t *loc, libglusterfs_client_ctx_t *ctx,
new_loc.inode = inode_search (ctx->itable, parent->ino, file);
if (new_loc.inode) {
- op_ret = inode_ctx_get (new_loc.inode, ctx->itable->xl,
- &ptr);
- if (op_ret != -1) {
- inode_ctx = (libglusterfs_client_inode_ctx_t *)(long)ptr;
- memset (&current, 0, sizeof (current));
- current = time (NULL);
-
- pthread_mutex_lock (&inode_ctx->lock);
- {
- prev = inode_ctx->previous_lookup_time;
- }
- pthread_mutex_unlock (&inode_ctx->lock);
-
- if ((prev >= 0)
- && (ctx->lookup_timeout
- >= (current - prev))) {
- dentry = dentry_search_for_inode (new_loc.inode,
- parent->ino,
- file);
- }
- }
+ if (libgf_is_iattr_cache_valid (ctx, new_loc.inode,
+ NULL,
+ LIBGF_VALIDATE_LOOKUP))
+ dentry = dentry_search_for_inode (new_loc.inode,
+ parent->ino,
+ file);
}
-
+
if (dentry == NULL) {
op_ret = libgf_client_lookup (ctx, &new_loc, NULL, NULL,
0);