bdb608ffd419652e876621d7460bb8e74a2818d1
[xfstests-dev.git] / tests / overlay / 072
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 072
6 #
7 # Test overlay nlink when adding upper hardlinks.
8 #
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.
12 #
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
16 # by default.
17 #
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().
22 #
23 . ./common/preamble
24 _begin_fstest auto quick copyup hardlink
25
26 # Import common functions.
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs overlay
31 _require_scratch
32
33 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
34
35 # Remove all files from previous tests
36 _scratch_mkfs
37
38 # Create upper hardlink
39 mkdir -p $upperdir
40 touch $upperdir/0
41 ln $upperdir/0 $upperdir/1
42
43 _scratch_mount
44
45 # Verify overlay inode nlink 2 same as upper inode
46 stat -c '%h' $SCRATCH_MNT/0
47
48 # Add upper hardlinks while overlay is mounted - overlay inode nlink
49 # is not being updated
50 ln $upperdir/0 $upperdir/2
51 ln $upperdir/0 $upperdir/3
52
53 # Unlink the 2 un-accounted upper hardlinks - overlay inode nlinks
54 # drops 2 and may reach 0 if the situation is not detected
55 rm $SCRATCH_MNT/2
56 rm $SCRATCH_MNT/3
57
58 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
59 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
60
61 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
62 # WARN_ON() in drop_nlink()
63 rm $SCRATCH_MNT/0
64 rm $SCRATCH_MNT/1
65 rm $SCRATCH_MNT/4
66
67 echo "Silence is golden"
68 status=0
69 exit