Blob Blame History Raw
From 40fc4a711a064ca4a3b3197c79fa4b72faa8832e Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Tue, 5 Sep 2017 13:30:53 +0530
Subject: [PATCH 608/616] features/shard: Increment counts in locks

       Backport of https://review.gluster.org/18203

Problem:
Because create_count/eexist_count are incremented without locks, all the shards may not
be created because call_count will be lesser than what it needs to be. This can lead
to crash in shard_common_inode_write_do() because inode on which we want to do
fd_anonymous() is NULL

Fix:
Increment the counts in frame->lock

 >Change-Id: Ibc87dcb1021e9f4ac2929f662da07aa7662ab0d6
 >BUG: 1488354
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>

Change-Id: Ibc87dcb1021e9f4ac2929f662da07aa7662ab0d6
BUG: 1488860
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/117343
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/features/shard/src/shard.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index b97608f..0d0ab4a 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -1703,7 +1703,11 @@ shard_common_lookup_shards_cbk (call_frame_t *frame, void *cookie,
                 case GF_FOP_FALLOCATE:
                         if ((!local->first_lookup_done) &&
                             (op_errno == ENOENT)) {
-                                local->create_count++;
+                                LOCK (&frame->lock);
+                                {
+                                        local->create_count++;
+                                }
+                                UNLOCK (&frame->lock);
                                 goto done;
                         }
                         break;
@@ -3233,7 +3237,11 @@ shard_common_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
 
         if (op_ret < 0) {
                 if (op_errno == EEXIST) {
-                        local->eexist_count++;
+                        LOCK (&frame->lock);
+                        {
+                                local->eexist_count++;
+                        }
+                        UNLOCK (&frame->lock);
                 } else {
                         local->op_ret = op_ret;
                         local->op_errno = op_errno;
-- 
1.8.3.1