summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand V. Avati <avati@amp.gluster.com>2009-03-03 20:10:47 +0530
committerAnand V. Avati <avati@amp.gluster.com>2009-03-03 20:30:42 +0530
commit1b51e542b9aa7996e2753a7686c7743ffc8ecefd (patch)
treed35a72918ef9e1cf42b4b18889fb7957e7a11d5d
parent5ed5ea9bffe018512edc6babff18fd4d44bcdd70 (diff)
inode_ctx_t locks added
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rw-r--r--libglusterfs/src/inode.c84
1 files changed, 54 insertions, 30 deletions
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index 3664dee745e..1b028ef3063 100644
--- a/libglusterfs/src/inode.c
+++ b/libglusterfs/src/inode.c
@@ -1108,45 +1108,61 @@ int
inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value)
{
int index = 0;
+ int ret = 0;
if (!inode || !xlator)
return -1;
- for (index = 0; index < xlator->ctx->xl_count; index++) {
- if (!inode->_ctx[index].key ||
- (inode->_ctx[index].key == (uint64_t)(long)xlator))
- break;
- }
+ LOCK (&inode->lock);
+ {
+ for (index = 0; index < xlator->ctx->xl_count; index++) {
+ if (!inode->_ctx[index].key ||
+ (inode->_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;
+ }
- inode->_ctx[index].key = (uint64_t)(long) xlator;
- inode->_ctx[index].value = value;
+ inode->_ctx[index].key = (uint64_t)(long) xlator;
+ inode->_ctx[index].value = value;
+ }
+unlock:
+ UNLOCK (&inode->lock);
- return 0;
+ return ret;
}
int
inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value)
{
int index = 0;
+ int ret = 0;
if (!inode || !xlator)
return -1;
- for (index = 0; index < xlator->ctx->xl_count; index++) {
- if (inode->_ctx[index].key == (uint64_t)(long)xlator)
- break;
- }
+ LOCK (&inode->lock);
+ {
+ for (index = 0; index < xlator->ctx->xl_count; index++) {
+ if (inode->_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 = inode->_ctx[index].value;
+ if (value)
+ *value = inode->_ctx[index].value;
+ }
+unlock:
+ UNLOCK (&inode->lock);
- return 0;
+ return ret;
}
@@ -1154,23 +1170,31 @@ int
inode_ctx_del (inode_t *inode, xlator_t *xlator, uint64_t *value)
{
int index = 0;
+ int ret = 0;
if (!inode || !xlator)
return -1;
- for (index = 0; index < xlator->ctx->xl_count; index++) {
- if (inode->_ctx[index].key == (uint64_t)(long)xlator)
- break;
- }
+ LOCK (&inode->lock);
+ {
+ for (index = 0; index < xlator->ctx->xl_count; index++) {
+ if (inode->_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 = inode->_ctx[index].value;
+ if (value)
+ *value = inode->_ctx[index].value;
- inode->_ctx[index].key = 0;
- inode->_ctx[index].value = 0;
+ inode->_ctx[index].key = 0;
+ inode->_ctx[index].value = 0;
+ }
+unlock:
+ UNLOCK (&inode->lock);
- return 0;
+ return ret;
}