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