summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/fd.c18
-rw-r--r--libglusterfs/src/inode.c18
2 files changed, 26 insertions, 10 deletions
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index 44149246b..918b6c14d 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -548,6 +548,7 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
{
int index = 0;
int ret = 0;
+ int set_idx = -1;
if (!fd || !xlator)
return -1;
@@ -555,18 +556,25 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
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))
+ if (!fd->_ctx[index].key) {
+ if (set_idx == -1)
+ set_idx = index;
+ /* dont break, to check if key already exists
+ further on */
+ }
+ if (fd->_ctx[index].key == (uint64_t)(long) xlator) {
+ set_idx = index;
break;
+ }
}
- if (index == xlator->ctx->xl_count) {
+ if (set_idx == -1) {
ret = -1;
goto unlock;
}
- fd->_ctx[index].key = (uint64_t)(long) xlator;
- fd->_ctx[index].value = value;
+ fd->_ctx[set_idx].key = (uint64_t)(long) xlator;
+ fd->_ctx[set_idx].value = value;
}
unlock:
UNLOCK (&fd->lock);
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index c62d7ca9e..90a84f955 100644
--- a/libglusterfs/src/inode.c
+++ b/libglusterfs/src/inode.c
@@ -1109,20 +1109,28 @@ __inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value)
{
int ret = 0;
int index = 0;
+ int put_idx = -1;
for (index = 0; index < xlator->ctx->xl_count; index++) {
- if (!inode->_ctx[index].key ||
- (inode->_ctx[index].key == (uint64_t)(long)xlator))
+ if (!inode->_ctx[index].key) {
+ if (put_idx == -1)
+ put_idx = index;
+ /* dont break, to check if key already exists
+ further on */
+ }
+ if (inode->_ctx[index].key == (uint64_t)(long) xlator) {
+ put_idx = index;
break;
+ }
}
- if (index == xlator->ctx->xl_count) {
+ if (put_idx == -1) {
ret = -1;
goto out;;
}
- inode->_ctx[index].key = (uint64_t)(long) xlator;
- inode->_ctx[index].value = value;
+ inode->_ctx[put_idx].key = (uint64_t)(long) xlator;
+ inode->_ctx[put_idx].value = value;
out:
return ret;
}