summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-08-26 01:36:53 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-09-08 01:41:08 -0700
commit8c110d0aba119d199e2e8d29418ed45119aeb30c (patch)
tree455a204c8ba4450b2384bc59e450955cfb1c22d0 /xlators
parent3a0317982bfc8c507cfaf8dc919d5f4bab4371f7 (diff)
performance/stat-prefetch: introduce sp_fd_ctx_t to hold context of fds
- we need following extra members along with cache 1. basename of path on which fd is opened. This is necessary to search for cached entry in fd based fops. 2. inode corresponding to dirname of path on which fd is opened. This is necessary to get cache where entry corresponding to file on which fd is opened. Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 221 (stat prefetch implementation) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=221
Diffstat (limited to 'xlators')
-rw-r--r--xlators/performance/stat-prefetch/src/stat-prefetch.c142
-rw-r--r--xlators/performance/stat-prefetch/src/stat-prefetch.h13
2 files changed, 144 insertions, 11 deletions
diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c
index a6a864f9472..663ddc69a10 100644
--- a/xlators/performance/stat-prefetch/src/stat-prefetch.c
+++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c
@@ -35,7 +35,7 @@ sp_cache_init (void)
return cache;
}
-
+
void
sp_local_free (sp_local_t *local)
{
@@ -119,9 +119,10 @@ sp_cache_free (sp_cache_t *cache)
sp_cache_t *
sp_get_cache_fd (xlator_t *this, fd_t *fd)
{
- sp_cache_t *cache = NULL;
- uint64_t value = 0;
- int32_t ret = -1;
+ sp_cache_t *cache = NULL;
+ uint64_t value = 0;
+ int32_t ret = -1;
+ sp_fd_ctx_t *fd_ctx = NULL;
if (fd == NULL) {
goto out;
@@ -132,29 +133,115 @@ sp_get_cache_fd (xlator_t *this, fd_t *fd)
goto out;
}
- cache = (void *)(long) value;
+ fd_ctx = (void *)(long) value;
+
+ LOCK (&fd_ctx->lock);
+ {
+ cache = fd_ctx->cache;
+ }
+ UNLOCK (&fd_ctx->lock);
out:
return cache;
}
+void
+sp_fd_ctx_free (sp_fd_ctx_t *fd_ctx)
+{
+ if (fd_ctx == NULL) {
+ goto out;
+ }
+
+ if (fd_ctx->parent_inode) {
+ inode_unref (fd_ctx->parent_inode);
+ fd_ctx->parent_inode = NULL;
+ }
+
+ if (fd_ctx->name) {
+ FREE (fd_ctx->name);
+ fd_ctx->name = NULL;
+ }
+
+ if (fd_ctx->cache) {
+ sp_cache_free (fd_ctx->cache);
+ }
+
+ FREE (fd_ctx);
+out:
+ return;
+}
+
+
+inline sp_fd_ctx_t *
+sp_fd_ctx_init (void)
+{
+ sp_fd_ctx_t *fd_ctx = NULL;
+
+ fd_ctx = CALLOC (1, sizeof (*fd_ctx));
+ if (fd_ctx) {
+ LOCK_INIT (&fd_ctx->lock);
+ }
+
+ return fd_ctx;
+}
+
+
+sp_fd_ctx_t *
+sp_fd_ctx_new (xlator_t *this, inode_t *parent, char *name, sp_cache_t *cache)
+{
+ sp_fd_ctx_t *fd_ctx = NULL;
+
+ fd_ctx = sp_fd_ctx_init ();
+ if (fd_ctx == NULL) {
+ gf_log (this->name, GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ if (parent) {
+ fd_ctx->parent_inode = inode_ref (parent);
+ }
+
+ if (name) {
+ fd_ctx->name = strdup (name);
+ if (fd_ctx->name == NULL) {
+ sp_fd_ctx_free (fd_ctx);
+ fd_ctx = NULL;
+ }
+ }
+
+ fd_ctx->cache = cache;
+
+out:
+ return fd_ctx;
+}
+
+
sp_cache_t *
sp_del_cache_fd (xlator_t *this, fd_t *fd)
{
- sp_cache_t *cache = NULL;
- uint64_t value = 0;
- int32_t ret = -1;
+ sp_cache_t *cache = NULL;
+ uint64_t value = 0;
+ int32_t ret = -1;
+ sp_fd_ctx_t *fd_ctx = NULL;
if (fd == NULL) {
goto out;
}
- ret = fd_ctx_del (fd, this, &value);
+ ret = fd_ctx_get (fd, this, &value);
if (ret == -1) {
goto out;
}
- cache = (void *)(long) value;
+ fd_ctx = (void *)(long) value;
+
+ LOCK (&fd_ctx->lock);
+ {
+ cache = fd_ctx->cache;
+ fd_ctx->cache = NULL;
+ }
+ UNLOCK (&fd_ctx->lock);
+
out:
return cache;
}
@@ -184,7 +271,40 @@ out:
inline int32_t
sp_put_cache (xlator_t *this, fd_t *fd, sp_cache_t *cache)
{
- return fd_ctx_set (fd, this, (long)(void *)cache);
+ sp_fd_ctx_t *fd_ctx = NULL;
+ int32_t ret = -1;
+ uint64_t value = 0;
+
+ ret = fd_ctx_get (fd, this, &value);
+ if (!ret) {
+ fd_ctx = (void *)(long)value;
+ } else {
+ fd_ctx = sp_fd_ctx_init ();
+ if (fd_ctx == NULL) {
+ gf_log (this->name, GF_LOG_ERROR, "out of memory");
+ ret = -1;
+ goto out;
+ }
+
+ ret = fd_ctx_set (fd, this, (long)(void *)fd_ctx);
+ if (ret == -1) {
+ sp_fd_ctx_free (fd_ctx);
+ goto out;
+ }
+ }
+
+ LOCK (&fd_ctx->lock);
+ {
+ if (fd_ctx->cache) {
+ sp_cache_free (fd_ctx->cache);
+ }
+
+ fd_ctx->cache = cache;
+ }
+ UNLOCK (&fd_ctx->lock);
+
+out:
+ return ret;
}
diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.h b/xlators/performance/stat-prefetch/src/stat-prefetch.h
index 4a45261a4d4..05c5d436184 100644
--- a/xlators/performance/stat-prefetch/src/stat-prefetch.h
+++ b/xlators/performance/stat-prefetch/src/stat-prefetch.h
@@ -38,6 +38,19 @@ struct sp_cache {
};
typedef struct sp_cache sp_cache_t;
+struct sp_fd_ctx {
+ sp_cache_t *cache;
+ inode_t *parent_inode; /*
+ * inode corresponding to dirname (path)
+ */
+ char *name; /*
+ * basename of path on which this fd is
+ * opened
+ */
+ gf_lock_t lock;
+};
+typedef struct sp_fd_ctx sp_fd_ctx_t;
+
struct sp_local {
loc_t loc;
fd_t *fd;