xfs: Check for extent overflow when trivally adding a new extent
[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 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 tmp=/tmp/$$
28 status=1        # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33         cd /
34         rm -f $tmp.*
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40
41 # remove previous $seqres.full before test
42 rm -f $seqres.full
43
44 # real QA test starts here
45 _supported_fs overlay
46 _require_scratch
47
48 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
49
50 # Remove all files from previous tests
51 _scratch_mkfs
52
53 # Create upper hardlink
54 mkdir -p $upperdir
55 touch $upperdir/0
56 ln $upperdir/0 $upperdir/1
57
58 _scratch_mount
59
60 # Verify overlay inode nlink 2 same as upper inode
61 stat -c '%h' $SCRATCH_MNT/0
62
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
67
68 # Unlink the 2 un-accounted upper hardlinks - overlay inode nlinks
69 # drops 2 and may reach 0 if the situation is not detected
70 rm $SCRATCH_MNT/2
71 rm $SCRATCH_MNT/3
72
73 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
74 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
75
76 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
77 # WARN_ON() in drop_nlink()
78 rm $SCRATCH_MNT/0
79 rm $SCRATCH_MNT/1
80 rm $SCRATCH_MNT/4
81
82 echo "Silence is golden"
83 status=0
84 exit