summaryrefslogtreecommitdiffstats
path: root/xlators/performance
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-11-25 13:53:23 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-11-26 09:27:00 -0800
commitc05707b41a325ec6a0cd4f24a6068a1efdf18d6a (patch)
tree5f0457d398699fb74fcd7065544c9a9543bf741b /xlators/performance
parentd01ba463de631fb38f96b2aa02907f0ac40db4eb (diff)
performance/stat-prefetch: Add refcounting to cache objects
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 405 (Segmentation fault in stat-prefetch.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=405
Diffstat (limited to 'xlators/performance')
-rw-r--r--xlators/performance/stat-prefetch/src/stat-prefetch.c131
1 files changed, 109 insertions, 22 deletions
diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c
index 73fac4c7c..9d799ef6a 100644
--- a/xlators/performance/stat-prefetch/src/stat-prefetch.c
+++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c
@@ -21,6 +21,49 @@
#define GF_SP_CACHE_BUCKETS 4096
+
+sp_cache_t *
+sp_cache_ref (sp_cache_t *cache)
+{
+ if (cache == NULL) {
+ goto out;
+ }
+
+ LOCK (&cache->lock);
+ {
+ cache->ref++;
+ }
+ UNLOCK (&cache->lock);
+
+out:
+ return cache;;
+}
+
+
+void
+sp_cache_unref (sp_cache_t *cache)
+{
+ int refcount = 0;
+ if (cache == NULL) {
+ goto out;
+ }
+
+ LOCK (&cache->lock);
+ {
+ refcount = --cache->ref;
+ }
+ UNLOCK (&cache->lock);
+
+ if (refcount == 0) {
+ rbthash_table_destroy (cache->table);
+ FREE (cache);
+ }
+
+out:
+ return;
+}
+
+
int32_t
sp_process_inode_ctx (call_frame_t *frame, xlator_t *this, loc_t *loc,
call_stub_t *stub, char *need_unwind, char *need_lookup,
@@ -230,8 +273,7 @@ void
sp_cache_free (sp_cache_t *cache)
{
sp_cache_remove_entry (cache, NULL, 1);
- rbthash_table_destroy (cache->table);
- FREE (cache);
+ sp_cache_unref (cache);
}
@@ -269,6 +311,9 @@ sp_get_cache_fd (xlator_t *this, fd_t *fd)
LOCK (&fd->lock);
{
cache = __sp_get_cache_fd (this, fd);
+ if (cache != NULL) {
+ sp_cache_ref (cache);
+ }
}
UNLOCK (&fd->lock);
@@ -316,9 +361,11 @@ sp_fd_ctx_init (void)
sp_fd_ctx_t *
-sp_fd_ctx_new (xlator_t *this, inode_t *parent, char *name, sp_cache_t *cache)
+sp_fd_ctx_new (xlator_t *this, inode_t *parent, fd_t *fd, char *name,
+ sp_cache_t *cache)
{
sp_fd_ctx_t *fd_ctx = NULL;
+ int32_t op_ret = -1;
fd_ctx = sp_fd_ctx_init ();
if (fd_ctx == NULL) {
@@ -339,6 +386,13 @@ sp_fd_ctx_new (xlator_t *this, inode_t *parent, char *name, sp_cache_t *cache)
}
fd_ctx->cache = cache;
+ op_ret = fd_ctx_set (fd, this, (long)(void *)fd_ctx);
+ if (op_ret == -1) {
+ sp_fd_ctx_free (fd_ctx);
+ fd_ctx = NULL;
+ }
+
+
out:
return fd_ctx;
@@ -563,6 +617,7 @@ sp_cache_remove_parent_entry (call_frame_t *frame, xlator_t *this, char *path)
path = basename (cpy);
sp_cache_remove_entry (cache_gp, path, 0);
FREE (cpy);
+ sp_cache_unref (cache_gp);
}
inode_unref (inode_gp);
}
@@ -619,6 +674,7 @@ sp_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (cache) {
sp_cache_remove_entry (cache, (char *)local->loc.name,
0);
+ sp_cache_unref (cache);
}
}
@@ -798,10 +854,12 @@ wind:
if (entry_cached) {
if (cache) {
cache->hits++;
+ sp_cache_unref (cache);
}
} else {
if (cache) {
cache->miss++;
+ sp_cache_unref (cache);
}
LOCK (&inode_ctx->lock);
@@ -846,10 +904,11 @@ int32_t
sp_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, gf_dirent_t *entries)
{
- sp_local_t *local = NULL;
- sp_cache_t *cache = NULL;
- fd_t *fd = NULL;
- int32_t ret = 0;
+ sp_local_t *local = NULL;
+ sp_cache_t *cache = NULL;
+ fd_t *fd = NULL;
+ int32_t ret = 0;
+ char was_present = 1;
if (op_ret == -1) {
goto out;
@@ -866,6 +925,7 @@ sp_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
{
cache = __sp_get_cache_fd (this, fd);
if (cache == NULL) {
+ was_present = 0;
cache = sp_cache_init ();
if (cache == NULL) {
goto unlock;
@@ -877,12 +937,18 @@ sp_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
goto unlock;
}
}
+
+ sp_cache_ref (cache);
}
unlock:
UNLOCK (&fd->lock);
if (cache != NULL) {
sp_cache_add_entries (cache, entries);
+
+ if (was_present) {
+ sp_cache_unref (cache);
+ }
}
out:
@@ -905,6 +971,8 @@ sp_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
if (off != cache->expected_offset) {
sp_cache_remove_entry (cache, NULL, 1);
}
+
+ sp_cache_unref (cache);
}
ret = inode_path (fd->inode, NULL, &path);
@@ -1012,8 +1080,9 @@ sp_chmod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
-
+
stub = fop_chmod_stub (frame, sp_chmod_helper, loc, mode);
if (stub == NULL) {
op_errno = ENOMEM;
@@ -1054,14 +1123,10 @@ sp_fd_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno,
EINVAL);
- fd_ctx = sp_fd_ctx_new (this, local->loc.parent,
+ fd_ctx = sp_fd_ctx_new (this, local->loc.parent, fd,
(char *)local->loc.name, NULL);
- GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, fd_ctx, out, op_errno,
- ENOMEM);
-
- op_ret = fd_ctx_set (fd, this, (long)(void *)fd_ctx);
- if (op_ret == -1) {
- sp_fd_ctx_free (fd_ctx);
+ if (fd_ctx == NULL) {
+ op_ret = -1;
op_errno = ENOMEM;
}
@@ -1180,14 +1245,10 @@ sp_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, out, op_errno,
EINVAL);
- fd_ctx = sp_fd_ctx_new (this, local->loc.parent,
+ fd_ctx = sp_fd_ctx_new (this, local->loc.parent, fd,
(char *)local->loc.name, NULL);
- GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, fd_ctx, out, op_errno,
- ENOMEM);
-
- op_ret = fd_ctx_set (fd, this, (long)(void *)fd_ctx);
- if (op_ret == -1) {
- sp_fd_ctx_free (fd_ctx);
+ if (fd_ctx == NULL) {
+ op_ret = -1;
op_errno = ENOMEM;
}
@@ -1784,6 +1845,7 @@ sp_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc)
cache = sp_get_cache_inode (this, oldloc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)oldloc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_link_stub (frame, sp_link_helper, oldloc, newloc);
@@ -1842,6 +1904,7 @@ sp_fchmod (call_frame_t *frame, xlator_t *this, fd_t *fd, mode_t mode)
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this),
@@ -1916,6 +1979,7 @@ sp_chown (call_frame_t *frame, xlator_t *this, loc_t *loc, uid_t uid, gid_t gid)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_chown_stub (frame, sp_chown_helper, loc, uid, gid);
@@ -1966,6 +2030,7 @@ sp_fchown (call_frame_t *frame, xlator_t *this, fd_t *fd, uid_t uid, gid_t gid)
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this),
@@ -2040,6 +2105,7 @@ sp_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_truncate_stub (frame, sp_truncate_helper, loc, offset);
@@ -2092,6 +2158,7 @@ sp_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset)
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this),
@@ -2167,6 +2234,7 @@ sp_utimens (call_frame_t *frame, xlator_t *this, loc_t *loc,
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_utimens_stub (frame, sp_utimens_helper, loc, tv);
@@ -2265,6 +2333,7 @@ sp_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_readlink_stub (frame, sp_readlink_helper, loc, size);
@@ -2362,6 +2431,7 @@ sp_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
ret = sp_cache_remove_parent_entry (frame, this, (char *)loc->path);
@@ -2408,6 +2478,7 @@ sp_remove_caches_from_all_fds_opened (xlator_t *this, inode_t *inode)
cache = sp_get_cache_fd (this, fd);
if (cache) {
sp_cache_remove_entry (cache, NULL, 1);
+ sp_cache_unref (cache);
}
}
}
@@ -2480,6 +2551,7 @@ sp_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
ret = sp_cache_remove_parent_entry (frame, this, (char *)loc->path);
@@ -2548,6 +2620,7 @@ sp_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_readv_cbk, FIRST_CHILD(this),
@@ -2584,6 +2657,7 @@ sp_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_stbuf_cbk, FIRST_CHILD(this),
@@ -2620,6 +2694,7 @@ sp_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags)
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_err_cbk, FIRST_CHILD(this),
@@ -2756,11 +2831,13 @@ sp_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc)
cache = sp_get_cache_inode (this, oldloc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)oldloc->name, 0);
+ sp_cache_unref (cache);
}
cache = sp_get_cache_inode (this, newloc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)newloc->name, 0);
+ sp_cache_unref (cache);
}
ret = sp_cache_remove_parent_entry (frame, this, (char *)oldloc->path);
@@ -2922,6 +2999,7 @@ sp_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_setxattr_stub (frame, sp_setxattr_helper, loc, dict, flags);
@@ -3013,6 +3091,7 @@ sp_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_removexattr_stub (frame, sp_removexattr_helper, loc, name);
@@ -3065,6 +3144,7 @@ sp_setdents (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
cache = sp_get_cache_fd (this, fd);
@@ -3072,6 +3152,8 @@ sp_setdents (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
for (trav = entries->next; trav; trav = trav->next) {
sp_cache_remove_entry (cache, trav->name, 0);
}
+
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_err_cbk, FIRST_CHILD(this),
@@ -3112,6 +3194,7 @@ sp_getdents_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
sp_cache_remove_entry (cache, trav->name, 0);
}
}
+ sp_cache_unref (cache);
}
out:
@@ -3145,6 +3228,7 @@ sp_getdents (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
local = CALLOC (1, sizeof (*local));
@@ -3236,6 +3320,7 @@ sp_checksum (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flag)
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_checksum_stub (frame, sp_checksum_helper, loc, flag);
@@ -3335,6 +3420,7 @@ sp_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc,
cache = sp_get_cache_inode (this, loc->parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, (char *)loc->name, 0);
+ sp_cache_unref (cache);
}
stub = fop_xattrop_stub (frame, sp_xattrop_helper, loc, flags, dict);
@@ -3386,6 +3472,7 @@ sp_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd,
cache = sp_get_cache_inode (this, parent, frame->root->pid);
if (cache) {
sp_cache_remove_entry (cache, name, 0);
+ sp_cache_unref (cache);
}
STACK_WIND (frame, sp_xattrop_cbk, FIRST_CHILD(this),