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