4 # Test overlay nlink when adding lower hardlinks.
6 # nlink of overlay inode could be dropped indefinitely by adding
7 # unaccounted lower hardlinks underneath a mounted overlay and
8 # trying to remove them.
10 # The simplest way to understand this test is this:
11 # Imagine that you have a tool (e.g. xfs_db) with which you can add
12 # hardlinks, without changing the value of nlink stored on-disk for the
13 # inode. This is exactly what this test does when it adds lower hardlinks
14 # underneath a mounted overlay.
16 # Commit 5f8415d6b87e ("ovl: persistent overlay inode nlink for indexed
17 # inodes") fixes this issue, although the issue was never exposed in any
20 # With overlayfs indexed copy up and without the fix, the test triggers
21 # WARN_ON(inode->i_nlink == 0) in drop_link().
23 #-----------------------------------------------------------------------
24 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
25 # Author: Amir Goldstein <amir73il@gmail.com>
27 # This program is free software; you can redistribute it and/or
28 # modify it under the terms of the GNU General Public License as
29 # published by the Free Software Foundation.
31 # This program is distributed in the hope that it would be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 # GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License
37 # along with this program; if not, write the Free Software Foundation,
38 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 #-----------------------------------------------------------------------
43 seqres=$RESULT_DIR/$seq
44 echo "QA output created by $seq"
47 status=1 # failure is the default!
48 trap "_cleanup; exit \$status" 0 1 2 3 15
56 # get standard environment, filters and checks
60 # remove previous $seqres.full before test
63 # real QA test starts here
67 # Without overlay index feature hardlinks are broken on copy up
68 _require_scratch_feature index
70 # Remove all files from previous tests
73 # Create lower hardlink
74 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
77 ln $lowerdir/0 $lowerdir/1
79 # Enable overlay index feature to prevent breaking hardlinks on copy up
80 _scratch_mount -o index=on
82 # Copy up lower hardlink - overlay inode nlink 2 is copied from lower
85 # Add lower hardlinks while overlay is mounted - overlay inode nlink
86 # is not being updated
87 ln $lowerdir/0 $lowerdir/2
88 ln $lowerdir/0 $lowerdir/3
90 # Unlink the 2 un-accounted lower hardlinks - overlay inode nlinks
91 # drops 2 and may reach 0 if the situation is not detected
95 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
96 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
98 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
99 # WARN_ON() in drop_nlink()
104 # Verify that orphan index is cleaned on mount
105 _scratch_cycle_mount index=on
106 ls $OVL_BASE_SCRATCH_MNT/$OVL_WORK/index
108 echo "Silence is golden"