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