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 _begin_fstest auto quick copyup hardlink
26 # Import common functions.
29 # real QA test starts here
31 _fixed_by_kernel_commit 83552eacdfc0 "ovl: fix WARN_ON nlink drop to zero"
35 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
37 # Remove all files from previous tests
40 # Create upper hardlink
43 ln $upperdir/0 $upperdir/1
47 # Verify overlay inode nlink 2 same as upper inode
48 stat -c '%h' $SCRATCH_MNT/0
50 # Add upper hardlinks while overlay is mounted - overlay inode nlink
51 # is not being updated
52 ln $upperdir/0 $upperdir/2
53 ln $upperdir/0 $upperdir/3
55 # Unlink the 2 un-accounted upper hardlinks - overlay inode nlinks
56 # drops 2 and may reach 0 if the situation is not detected
60 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
61 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
63 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
64 # WARN_ON() in drop_nlink()
69 echo "Silence is golden"