diff options
author | Basavanagowda Kanur <gowda@gluster.com> | 2009-02-26 20:36:50 +0530 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-02-26 20:51:50 +0530 |
commit | d3a318973c9613cfef8b1a14256fb5178e417fb0 (patch) | |
tree | 4a4c1b5275319a9c8680653118fe457a2db84929 | |
parent | 431617ef19244272797106f2356ef31591e9c7b9 (diff) |
fd->lock added to protect transactions for accessing and modifying fd->_ctx.
fd->_ctx access and modifications are now protected by fd->lock.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rw-r--r-- | libglusterfs/src/fd.c | 94 | ||||
-rw-r--r-- | libglusterfs/src/fd.h | 3 |
2 files changed, 64 insertions, 33 deletions
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index 78c578842..bbd15201c 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -415,6 +415,8 @@ fd_destroy (fd_t *fd) } } } + + LOCK_DESTROY (&fd->lock); FREE (fd->_ctx); inode_unref (fd->inode); @@ -489,6 +491,8 @@ fd_create (inode_t *inode, pid_t pid) fd->pid = pid; INIT_LIST_HEAD (&fd->inode_list); + LOCK_INIT (&fd->lock); + LOCK (&inode->lock); fd = _fd_ref (fd); UNLOCK (&inode->lock); @@ -543,45 +547,61 @@ int fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) { int index = 0; + int ret = 0; if (!fd || !xlator) return -1; - - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (!fd->_ctx[index].key || - (fd->_ctx[index].key == (uint64_t)(long)xlator)) - break; - } + + LOCK (&fd->lock); + { + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (!fd->_ctx[index].key || + (fd->_ctx[index].key == (uint64_t)(long)xlator)) + break; + } - if (index == xlator->ctx->xl_count) - return -1; + if (index == xlator->ctx->xl_count) { + ret = -1; + goto unlock; + } - fd->_ctx[index].key = (uint64_t)(long) xlator; - fd->_ctx[index].value = value; + fd->_ctx[index].key = (uint64_t)(long) xlator; + fd->_ctx[index].value = value; + } +unlock: + UNLOCK (&fd->lock); - return 0; + return ret; } int fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) { int index = 0; + int ret = 0; if (!fd || !xlator) return -1; + + LOCK (&fd->lock); + { + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (fd->_ctx[index].key == (uint64_t)(long)xlator) + break; + } - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (fd->_ctx[index].key == (uint64_t)(long)xlator) - break; - } - - if (index == xlator->ctx->xl_count) - return -1; + if (index == xlator->ctx->xl_count) { + ret = -1; + goto unlock; + } - if (value) - *value = fd->_ctx[index].value; + if (value) + *value = fd->_ctx[index].value; + } +unlock: + UNLOCK (&fd->lock); - return 0; + return ret; } @@ -589,23 +609,31 @@ int fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) { int index = 0; + int ret = 0; if (!fd || !xlator) return -1; + + LOCK (&fd->lock); + { + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (fd->_ctx[index].key == (uint64_t)(long)xlator) + break; + } - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (fd->_ctx[index].key == (uint64_t)(long)xlator) - break; - } - - if (index == xlator->ctx->xl_count) - return -1; + if (index == xlator->ctx->xl_count) { + ret = -1; + goto unlock; + } - if (value) - *value = fd->_ctx[index].value; + if (value) + *value = fd->_ctx[index].value; - fd->_ctx[index].key = 0; - fd->_ctx[index].value = 0; + fd->_ctx[index].key = 0; + fd->_ctx[index].value = 0; + } +unlock: + UNLOCK (&fd->lock); - return 0; + return ret; } diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h index 8b8effdc3..29a79eb76 100644 --- a/libglusterfs/src/fd.h +++ b/libglusterfs/src/fd.h @@ -29,6 +29,7 @@ #include <sys/types.h> #include <unistd.h> #include "glusterfs.h" +#include "locking.h" struct _inode; struct _dict; @@ -44,6 +45,8 @@ struct _fd { struct list_head inode_list; struct _inode *inode; struct _dict *ctx; + gf_lock_t lock; /* used ONLY for manipulating + 'struct _fd_ctx' array (_ctx).*/ struct _fd_ctx *_ctx; }; typedef struct _fd fd_t; |