xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / overlay / 071
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 CTERA Networks. All Rights Reserved.
4 #
5 # FSQA Test No. 071
6 #
7 # This is a variant of overlay/017 to test constant st_ino numbers for
8 # nested overlay setup, where lower overlay layers are not on the same fs.
9 #
10 # This simple test demonstrates a known issue with overlayfs:
11 # - stat file A shows inode number X
12 # - modify A to trigger copy up
13 # - stat file A shows inode number Y != X
14 #
15 # Also test that d_ino of readdir entries and i_ino from /proc/locks are
16 # consistent with st_ino and that inode numbers persist after rename to
17 # new parent, drop caches and mount cycle.
18 #
19 # With nested xino configuration, directory st_ino is not persistent and
20 # its st_ino/d_ino/i_ino values are not consistent, so test only non-dir
21 # in this test.
22 #
23 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34         cd /
35         rm -f $tmp.*
36         # Unmount the nested overlay mount
37         $UMOUNT_PROG $mnt2 2>/dev/null
38         [ -z "$loopdev" ] || _destroy_loop_device $loopdev
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46 _supported_fs overlay
47 _supported_os Linux
48 _require_test
49 _require_scratch_nocheck
50 _require_test_program "af_unix"
51 _require_test_program "t_dir_type"
52 _require_command "$FLOCK_PROG" "flock"
53 # We need to require all features together, because nfs_export cannot
54 # be enabled when index is disabled
55 _require_scratch_overlay_features index nfs_export redirect_dir
56 _require_loop
57
58 # Lower overlay lower layer is on test fs, upper is on scratch fs
59 lower=$OVL_BASE_TEST_MNT/$OVL_LOWER-$seq
60 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
61 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
62 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
63 upper2=$OVL_BASE_SCRATCH_DIR/$OVL_UPPER.2
64 work2=$OVL_BASE_SCRATCH_DIR/$OVL_WORK.2
65 mnt2=$OVL_BASE_SCRATCH_DIR/$OVL_MNT.2
66
67 lowerdir=$lower/lowertestdir
68 upperdir=$upper/uppertestdir
69 lowertestdir=$mnt2/lowertestdir
70 uppertestdir=$mnt2/uppertestdir
71
72 create_dirs()
73 {
74         # Create the underlying overlay dirs
75         _scratch_mkfs
76
77         # Re-create the nested overlay upper dirs
78         rm -rf $lower $upper2 $work2 $mnt2
79         mkdir $lower $upper2 $work2 $mnt2
80
81         # Create a loop device for blkdev tests
82         $XFS_IO_PROG -f -c "truncate 128k" $lower/img >> $seqres.full 2>&1
83         loopdev=`_create_loop_device $lower/img`
84 }
85
86 # Mount a nested overlay with $SCRATCH_MNT as lower layer
87 mount_dirs()
88 {
89         # Mount the underlying overlay with file handle support
90         _overlay_mount_dirs $lower $upper $work overlay1 $SCRATCH_MNT \
91                 -o "index=on,nfs_export=on,xino=on" || \
92                 _notrun "cannot mount overlay with xino=on option"
93         _fs_options overlay1 | grep -q "xino=on" || \
94                 _notrun "cannot enable xino feature on overlay"
95
96         # Mount the nested overlay
97         # Enable redirect_dir for renaming a merge directory.
98         # Enabling xino in this test requires that base filesystem inode numbers will
99         # not use bit 63 in inode number of the test files, because bit 63 is used by
100         # overlayfs to indicate the layer. Let's just assume that this is true for all
101         # tested filesystems and if we are wrong, the test may fail.
102         _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
103                 -o "redirect_dir=on,index=on,xino=on" || \
104                 _notrun "cannot mount nested overlay with xino=on option"
105         _fs_options overlay2 | grep -q "xino=on" || \
106                 _notrun "cannot enable xino feature on nested overlay"
107 }
108
109 # Unmount the nested overlay mount and check underlying overlay layers
110 unmount_dirs()
111 {
112         # unmount & check nested overlay
113         $UMOUNT_PROG $mnt2
114         _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
115                 -o "redirect_dir=on,index=on,xino=on"
116
117         # unmount & check underlying overlay
118         $UMOUNT_PROG $SCRATCH_MNT
119         _overlay_check_dirs $lower $upper $work \
120                 -o "index=on,nfs_export=on"
121 }
122
123 FILES="file symlink link chrdev blkdev fifo socket"
124
125 create_test_files()
126 {
127         local dir=$1
128
129         # Create our test files.
130         mkdir -p $dir
131         touch $dir/file
132         ln -s $dir/file $dir/symlink
133         touch $dir/link
134         ln $dir/link $dir/link2
135         cp -a /dev/zero $dir/chrdev
136         cp -a $loopdev $dir/blkdev
137         mknod $dir/fifo p
138         $here/src/af_unix $dir/socket
139 }
140
141 # Record inode numbers in format <ino> <basename>
142 record_inode_numbers()
143 {
144         local dir=$1
145         local outfile=$2
146
147         echo "record_inode_numbers $outfile" >> $seqres.full
148
149         for n in $FILES; do
150                 ls -id $dir/$n
151         done | \
152         while read ino file; do
153                 f=`basename $file`
154                 echo $ino $f | tee -a $seqres.full >> $outfile
155                 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
156                 # doesn't follow symlink, blocks on fifo and fails on socket
157                 [[ $f =~ fifo|socket|symlink ]] || \
158                 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
159                         echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
160         done
161 }
162
163 # Check inode numbers match recorder inode numbers
164 check_inode_numbers()
165 {
166         local dir=$1
167         local before=$2
168         local after=$3
169
170         record_inode_numbers $dir $after
171
172         # Test constant stat(2) st_ino -
173         # Compare before..after - expect silence
174         # We use diff -u so out.bad will tell us which stage failed
175         diff -u $before $after
176
177         # Test constant readdir(3)/getdents(2) d_ino -
178         # Expect to find file by inode number
179         cat $before | while read ino f; do
180                 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
181                         echo "$f not found by ino $ino (from $before) - see $seqres.full"
182         done
183 }
184
185 rm -f $seqres.full
186
187 create_dirs
188
189 create_test_files $lowerdir
190 create_test_files $upperdir
191
192 mount_dirs
193
194 # Record inode numbers in the lower overlay
195 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
196 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
197
198 # Compare inode numbers in lower overlay vs. nested overlay
199 # With nested xino lower/lower, all inode numbers overflow xino bits and
200 # d_ino/i_ino in nested overlay are the same as in lower overlay.
201 check_inode_numbers $lowertestdir $tmp.lower.lo $tmp.before.lo
202
203 # Record inode numbers before copy up from nested upper
204 record_inode_numbers $uppertestdir $tmp.before.up
205
206 # Copy up all files
207 for f in $FILES; do
208         # chown -h modifies all those file types
209         chown -h 100 $lowertestdir/$f
210         chown -h 100 $uppertestdir/$f
211 done
212
213 # Compare inode numbers before/after copy up
214 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
215 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
216
217 # Move all files to another dir
218 mkdir $lowertestdir.2 $uppertestdir.2
219
220 for f in $FILES; do
221         mv $lowertestdir/$f $lowertestdir.2/
222         mv $uppertestdir/$f $uppertestdir.2/
223 done
224
225 echo 3 > /proc/sys/vm/drop_caches
226
227 # Compare inode numbers before/after rename and drop caches
228 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
229 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
230
231 # Verify that the inode numbers survive a mount cycle
232 unmount_dirs
233 mount_dirs
234
235 # Compare inode numbers before/after mount cycle
236 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
237 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
238
239 unmount_dirs
240
241 echo "Silence is golden"
242 status=0
243 exit