7c2869
From 247bea1a8a76a1ac37b84d679d9767bbce4782cd Mon Sep 17 00:00:00 2001
7c2869
From: Krutika Dhananjay <kdhananj@redhat.com>
7c2869
Date: Thu, 15 Feb 2018 16:12:12 +0530
7c2869
Subject: [PATCH 665/675] features/shard: Fix shard inode refcount when it's
7c2869
 part of priv->lru_list.
7c2869
7c2869
For as long as a shard's inode is in priv->lru_list, it should have a non-zero
7c2869
ref-count. This patch achieves it by taking a ref on the inode when it
7c2869
is added to lru list. When it's time for the inode to be evicted
7c2869
from the lru list, a corresponding unref is done.
7c2869
7c2869
> Upstream: https://review.gluster.org/19608
7c2869
> BUG: 1468483
7c2869
> Change-Id: I289ffb41e7be5df7489c989bc1bbf53377433c86
7c2869
7c2869
Change-Id: I289ffb41e7be5df7489c989bc1bbf53377433c86
7c2869
BUG: 1583462
7c2869
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
7c2869
Reviewed-on: https://code.engineering.redhat.com/gerrit/140381
7c2869
Tested-by: RHGS Build Bot <nigelb@redhat.com>
7c2869
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
7c2869
---
7c2869
 tests/bugs/shard/shard-inode-refcount-test.t | 27 +++++++++++++++++++++++++++
7c2869
 tests/volume.rc                              | 18 ++++++++++++++++++
7c2869
 xlators/features/shard/src/shard.c           | 26 +++++++++++++++++---------
7c2869
 3 files changed, 62 insertions(+), 9 deletions(-)
7c2869
 create mode 100644 tests/bugs/shard/shard-inode-refcount-test.t
7c2869
7c2869
diff --git a/tests/bugs/shard/shard-inode-refcount-test.t b/tests/bugs/shard/shard-inode-refcount-test.t
7c2869
new file mode 100644
7c2869
index 0000000..6358097
7c2869
--- /dev/null
7c2869
+++ b/tests/bugs/shard/shard-inode-refcount-test.t
7c2869
@@ -0,0 +1,27 @@
7c2869
+#!/bin/bash
7c2869
+
7c2869
+. $(dirname $0)/../../include.rc
7c2869
+. $(dirname $0)/../../volume.rc
7c2869
+
7c2869
+cleanup
7c2869
+
7c2869
+TEST glusterd
7c2869
+TEST pidof glusterd
7c2869
+TEST $CLI volume create $V0 $H0:$B0/${V0}0
7c2869
+TEST $CLI volume set $V0 features.shard on
7c2869
+TEST $CLI volume set $V0 features.shard-block-size 4MB
7c2869
+TEST $CLI volume start $V0
7c2869
+
7c2869
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0
7c2869
+
7c2869
+TEST dd if=/dev/zero of=$M0/one-plus-five-shards bs=1M count=23
7c2869
+
7c2869
+ACTIVE_INODES_BEFORE=$(get_mount_active_size_value $V0)
7c2869
+TEST rm -f $M0/one-plus-five-shards
7c2869
+EXPECT `expr $ACTIVE_INODES_BEFORE - 5` get_mount_active_size_value $V0
7c2869
+
7c2869
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
7c2869
+TEST $CLI volume stop $V0
7c2869
+TEST $CLI volume delete $V0
7c2869
+
7c2869
+cleanup
7c2869
diff --git a/tests/volume.rc b/tests/volume.rc
7c2869
index 5d6c96c..9ab31af 100644
7c2869
--- a/tests/volume.rc
7c2869
+++ b/tests/volume.rc
7c2869
@@ -760,3 +760,21 @@ function count_sh_entries()
7c2869
 {
7c2869
     ls $1/.glusterfs/indices/xattrop | grep -v "xattrop-" | wc -l
7c2869
 }
7c2869
+
7c2869
+function get_mount_active_size_value {
7c2869
+        local vol=$1
7c2869
+        local statedump=$(generate_mount_statedump $vol)
7c2869
+        sleep 1
7c2869
+        local val=$(grep "active_size" $statedump | cut -f2 -d'=' | tail -1)
7c2869
+        rm -f $statedump
7c2869
+        echo $val
7c2869
+}
7c2869
+
7c2869
+function get_mount_lru_size_value {
7c2869
+        local vol=$1
7c2869
+        local statedump=$(generate_mount_statedump $vol)
7c2869
+        sleep 1
7c2869
+        local val=$(grep "lru_size" $statedump | cut -f2 -d'=' | tail -1)
7c2869
+        rm -f $statedump
7c2869
+        echo $val
7c2869
+}
7c2869
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
7c2869
index 4351220..c57a426 100644
7c2869
--- a/xlators/features/shard/src/shard.c
7c2869
+++ b/xlators/features/shard/src/shard.c
7c2869
@@ -502,6 +502,10 @@ __shard_update_shards_inode_list (inode_t *linked_inode, xlator_t *this,
7c2869
                  * by empty list), and if there is still space in the priv list,
7c2869
                  * add this ctx to the tail of the list.
7c2869
                  */
7c2869
+                        /* For as long as an inode is in lru list, we try to
7c2869
+                         * keep it alive by holding a ref on it.
7c2869
+                         */
7c2869
+                        inode_ref (linked_inode);
7c2869
                         gf_uuid_copy (ctx->base_gfid, base_inode->gfid);
7c2869
                         ctx->block_num = block_num;
7c2869
                         list_add_tail (&ctx->ilist, &priv->ilist_head);
7c2869
@@ -527,8 +531,16 @@ __shard_update_shards_inode_list (inode_t *linked_inode, xlator_t *this,
7c2869
                         /* The following unref corresponds to the ref held by
7c2869
                          * inode_find() above.
7c2869
                          */
7c2869
-                        inode_forget (lru_inode, 0);
7c2869
                         inode_unref (lru_inode);
7c2869
+                        /* The following unref corresponds to the ref held at
7c2869
+                         * the time the shard was created or looked up
7c2869
+                         */
7c2869
+                        inode_unref (lru_inode);
7c2869
+                        inode_forget (lru_inode, 0);
7c2869
+                        /* For as long as an inode is in lru list, we try to
7c2869
+                         * keep it alive by holding a ref on it.
7c2869
+                         */
7c2869
+                        inode_ref (linked_inode);
7c2869
                         gf_uuid_copy (ctx->base_gfid, base_inode->gfid);
7c2869
                         ctx->block_num = block_num;
7c2869
                         list_add_tail (&ctx->ilist, &priv->ilist_head);
7c2869
@@ -1658,11 +1670,6 @@ shard_link_block_inode (shard_local_t *local, int block_num, inode_t *inode,
7c2869
                                    buf);
7c2869
         inode_lookup (linked_inode);
7c2869
         list_index = block_num - local->first_block;
7c2869
-
7c2869
-        /* Defer unref'ing the inodes until write is complete. These inodes are
7c2869
-         * unref'd in the event of a failure or after successful fop completion
7c2869
-         * in shard_local_wipe().
7c2869
-         */
7c2869
         local->inode_list[list_index] = linked_inode;
7c2869
 
7c2869
         LOCK(&priv->lock);
7c2869
@@ -2520,10 +2527,11 @@ shard_unlink_block_inode (shard_local_t *local, int shard_block_num)
7c2869
                 if (!list_empty (&ctx->ilist)) {
7c2869
                         list_del_init (&ctx->ilist);
7c2869
                         priv->inode_count--;
7c2869
+                        GF_ASSERT (priv->inode_count >= 0);
7c2869
+                        inode_unlink (inode, priv->dot_shard_inode, block_bname);
7c2869
+                        inode_unref (inode);
7c2869
+                        inode_forget (inode, 0);
7c2869
                 }
7c2869
-                GF_ASSERT (priv->inode_count >= 0);
7c2869
-                inode_unlink (inode, priv->dot_shard_inode, block_bname);
7c2869
-                inode_forget (inode, 0);
7c2869
         }
7c2869
         UNLOCK(&priv->lock);
7c2869
 
7c2869
-- 
7c2869
1.8.3.1
7c2869