2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 CTERA Networks. All Rights Reserved.
7 # Test overlay nlink when adding upper hardlinks.
9 # nlink of overlay inode could be dropped indefinitely by adding
10 # unaccounted upper hardlinks underneath a mounted overlay and
11 # trying to remove them.
13 # This is a variant of test overlay/034 with mangling of upper instead
14 # of lower hardlinks. Unlike overlay/034, this test does not require the
15 # inode index feature and will pass whether is it enabled or disabled
18 # This is a regression test for kernel commit 83552eacdfc0
19 # ("ovl: fix WARN_ON nlink drop to zero").
20 # Without the fix, the test triggers
21 # WARN_ON(inode->i_nlink == 0) in drop_link().
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
41 # remove previous $seqres.full before test
44 # real QA test starts here
48 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
50 # Remove all files from previous tests
53 # Create upper hardlink
56 ln $upperdir/0 $upperdir/1
60 # Verify overlay inode nlink 2 same as upper inode
61 stat -c '%h' $SCRATCH_MNT/0
63 # Add upper hardlinks while overlay is mounted - overlay inode nlink
64 # is not being updated
65 ln $upperdir/0 $upperdir/2
66 ln $upperdir/0 $upperdir/3
68 # Unlink the 2 un-accounted upper hardlinks - overlay inode nlinks
69 # drops 2 and may reach 0 if the situation is not detected
73 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
74 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
76 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
77 # WARN_ON() in drop_nlink()
82 echo "Silence is golden"