d1681e
From d08f81216085cda58a64f51872b4d2497958a7ea Mon Sep 17 00:00:00 2001
d1681e
From: Pranith Kumar K <pkarampu@redhat.com>
d1681e
Date: Fri, 6 Jul 2018 12:28:53 +0530
d1681e
Subject: [PATCH 314/325] cluster/afr: Prevent execution of code after
d1681e
 call_count decrementing
d1681e
d1681e
      Upstream-patch: https://review.gluster.org/20470
d1681e
d1681e
Problem:
d1681e
When call_count is decremented by one thread, another thread can
d1681e
go ahead with the operation leading to undefined behavior for the
d1681e
thread executing statements after decrementing call count.
d1681e
d1681e
Fix:
d1681e
Do the operations necessary before decrementing call count.
d1681e
d1681e
 >fixes bz#1598663
d1681e
BUG: 1598105
d1681e
Change-Id: Icc90cd92ac16e5fbdfe534d9f0a61312943393fe
d1681e
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/143624
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d1681e
---
d1681e
 xlators/cluster/afr/src/afr-lk-common.c | 15 ++++++++-------
d1681e
 1 file changed, 8 insertions(+), 7 deletions(-)
d1681e
d1681e
diff --git a/xlators/cluster/afr/src/afr-lk-common.c b/xlators/cluster/afr/src/afr-lk-common.c
d1681e
index be3de01..dff6644 100644
d1681e
--- a/xlators/cluster/afr/src/afr-lk-common.c
d1681e
+++ b/xlators/cluster/afr/src/afr-lk-common.c
d1681e
@@ -970,6 +970,14 @@ afr_nonblocking_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
d1681e
         local    = frame->local;
d1681e
         int_lock = &local->internal_lock;
d1681e
 
d1681e
+        if (op_ret == 0 && local->transaction.type == AFR_DATA_TRANSACTION) {
d1681e
+                LOCK (&local->inode->lock);
d1681e
+                {
d1681e
+                        local->inode_ctx->lock_count++;
d1681e
+                }
d1681e
+                UNLOCK (&local->inode->lock);
d1681e
+        }
d1681e
+
d1681e
         LOCK (&frame->lock);
d1681e
         {
d1681e
 		if (op_ret < 0) {
d1681e
@@ -994,13 +1002,6 @@ afr_nonblocking_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
d1681e
         }
d1681e
         UNLOCK (&frame->lock);
d1681e
 
d1681e
-        if (op_ret == 0 && local->transaction.type == AFR_DATA_TRANSACTION) {
d1681e
-                LOCK (&local->inode->lock);
d1681e
-                {
d1681e
-                        local->inode_ctx->lock_count++;
d1681e
-                }
d1681e
-                UNLOCK (&local->inode->lock);
d1681e
-        }
d1681e
         if (call_count == 0) {
d1681e
                 gf_msg_trace (this->name, 0,
d1681e
                               "Last inode locking reply received");
d1681e
-- 
d1681e
1.8.3.1
d1681e