summaryrefslogtreecommitdiffstats
path: root/xlators/cluster
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/cluster')
-rw-r--r--xlators/cluster/afr/src/afr-transaction.c32
-rw-r--r--xlators/cluster/afr/src/afr.c15
2 files changed, 31 insertions, 16 deletions
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
index 3df9f07e5a3..f9a0a8806fc 100644
--- a/xlators/cluster/afr/src/afr-transaction.c
+++ b/xlators/cluster/afr/src/afr-transaction.c
@@ -67,20 +67,24 @@ __mark_all_success (int32_t *pending, int child_count)
static int
__is_first_write_on_fd (xlator_t *this, fd_t *fd)
{
- int op_ret = 0;
- int _ret = -1;
-
- _ret = fd_ctx_get (fd, this, NULL);
- if (_ret < 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "first writev() on fd=%p, writing changelog",
- fd);
-
- _ret = fd_ctx_set (fd, this, 0xaf1);
- op_ret = 1;
- }
-
- return op_ret;
+ int op_ret = 0;
+ int _ret = -1;
+
+ LOCK (&fd->inode->lock);
+ {
+ _ret = fd_ctx_get (fd, this, NULL);
+ if (_ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "first writev() on fd=%p, writing changelog",
+ fd);
+
+ _ret = fd_ctx_set (fd, this, 0xaf1);
+ op_ret = 1;
+ }
+ }
+ UNLOCK (&fd->inode->lock);
+
+ return op_ret;
}
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index 1be016a394b..e627da1fbd1 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -816,6 +816,8 @@ afr_flush (call_frame_t *frame, xlator_t *this, fd_t *fd)
int op_ret = -1;
int op_errno = 0;
+ int transaction_needed = 0;
+
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
VALIDATE_OR_GOTO (this->private, out);
@@ -832,9 +834,18 @@ afr_flush (call_frame_t *frame, xlator_t *this, fd_t *fd)
frame->local = local;
- if (__is_fd_ctx_set (this, fd)) {
- fd_ctx_del (fd, this, NULL);
+ LOCK (&fd->inode->lock);
+ {
+ if (__is_fd_ctx_set (this, fd)) {
+ transaction_needed = 1;
+ fd_ctx_del (fd, this, NULL);
+ } else {
+ transaction_needed = 0;
+ }
+ }
+ UNLOCK (&fd->inode->lock);
+ if (transaction_needed) {
local->op = GF_FOP_FLUSH;
local->transaction.fop = afr_flush_wind;
local->transaction.done = afr_flush_done;