overlay/042: remove wrong check for empty index
[xfstests-dev.git] / tests / overlay / 042
1 #! /bin/bash
2 # FS QA Test 042
3 #
4 # Test creating lower hardlinks for copied up files.
5 #
6 # kernel v4.13 introduced the index=on feature for not breaking hardlinks
7 # on copy-up.  With the index feature enabled a regression was introduced -
8 # lower files that are hardlined while overlay is offline can result in
9 # lookup error after overlay in mounted.
10 #
11 # The regression was fixed by upstream commit
12 #   6eaf011144af ovl: fix EIO from lookup of non-indexed upper
13 # that was merged to v4.14-rc7.
14 #
15 # This test verifies that behavior is sane after creating lower hardlinks
16 # for copied up files while overlayfs is offline.
17 #
18 #-----------------------------------------------------------------------
19 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
20 # Author: Amir Goldstein <amir73il@gmail.com>
21 #
22 # This program is free software; you can redistribute it and/or
23 # modify it under the terms of the GNU General Public License as
24 # published by the Free Software Foundation.
25 #
26 # This program is distributed in the hope that it would be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 # GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write the Free Software Foundation,
33 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
34 #-----------------------------------------------------------------------
35 #
36
37 seq=`basename $0`
38 seqres=$RESULT_DIR/$seq
39 echo "QA output created by $seq"
40
41 tmp=/tmp/$$
42 status=1        # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 _cleanup()
46 {
47         cd /
48         rm -f $tmp.*
49 }
50
51 # get standard environment, filters and checks
52 . ./common/rc
53 . ./common/filter
54
55 # remove previous $seqres.full before test
56 rm -f $seqres.full
57
58 # real QA test starts here
59 _supported_fs overlay
60 _supported_os Linux
61 _require_scratch
62 # Without overlay index feature hardlinks are broken on copy up
63 _require_scratch_feature index
64
65 # Remove all files from previous tests
66 _scratch_mkfs
67
68 # Create lower file
69 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
70 mkdir -p $lowerdir
71 touch $lowerdir/0
72
73 # Disable overlay index feature to copy up with no index
74 _scratch_mount -o index=off
75
76 # Copy up lower and create upper hardlink with no index
77 ln $SCRATCH_MNT/0 $SCRATCH_MNT/1
78
79 $UMOUNT_PROG $SCRATCH_MNT
80
81 # Add lower hardlinks while overlay is offline
82 ln $lowerdir/0 $lowerdir/2
83 ln $lowerdir/0 $lowerdir/3
84
85 # Enable overlay index feature to lookup copied up upper aliases
86 _scratch_mount -o index=on
87
88 # Stat upper hardlink that were created with no index and whose copy up
89 # origin is now an hardlink - expect same st_ino
90 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
91 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
92 [[ $ino0 == $ino1 ]] || \
93         echo "Mismatch inode number for non-indexed upper hardlinks"
94
95 # Copy up lower and create new upper hardlink with index, because
96 # lower is a hardlink and index is enabled. The new hardlinks are not
97 # associated with the hardlinks that were created when lower was not
98 # a hardlink.
99 ln $SCRATCH_MNT/2 $SCRATCH_MNT/4
100
101 # Mount cycle to reset inode/dentry cache
102 _scratch_cycle_mount index=on
103
104 # Stat files that were copied up with index and whose copy up origin
105 # is now an hardlink - expect same st_ino as lower aliases and different
106 # st_ino from non-indexed upper aliases.
107 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
108 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
109 ino2=$(stat -c '%i' $SCRATCH_MNT/2)
110 ino3=$(stat -c '%i' $SCRATCH_MNT/3)
111 ino4=$(stat -c '%i' $SCRATCH_MNT/4)
112 [[ $ino0 == $ino1 ]] || \
113         echo "Mismatch inode number for non-indexed upper hardlinks"
114 [[ $ino2 == $ino4 ]] || \
115         echo "Mismatch inode number for indexed upper hardlinks"
116 [[ $ino2 == $ino3 ]] || \
117         echo "Mismatch inode number for indexed upper and lower hardlinks"
118 [[ $ino2 != $ino0 ]] || \
119         echo "Unexpected matching inode number for indexed and non-indexed upper hardlinks"
120
121 # Mount cycle to reset inode/dentry cache
122 _scratch_cycle_mount index=on
123
124 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
125 # WARN_ON() in drop_nlink()
126 rm $SCRATCH_MNT/0
127 rm $SCRATCH_MNT/1
128 rm $SCRATCH_MNT/2
129 rm $SCRATCH_MNT/3
130 rm $SCRATCH_MNT/4
131
132 echo "Silence is golden"
133 status=0
134 exit