fstests: move test group info to test files
[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 . ./common/preamble
24 _begin_fstest auto quick copyup redirect nested nonsamefs
25
26 # Override the default cleanup function.
27 _cleanup()
28 {
29         cd /
30         rm -f $tmp.*
31         # Unmount the nested overlay mount
32         $UMOUNT_PROG $mnt2 2>/dev/null
33         [ -z "$loopdev" ] || _destroy_loop_device $loopdev
34 }
35
36 # Import common functions.
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs overlay
41 _require_test
42 _require_scratch_nocheck
43 _require_test_program "af_unix"
44 _require_test_program "t_dir_type"
45 _require_command "$FLOCK_PROG" "flock"
46 # We need to require all features together, because nfs_export cannot
47 # be enabled when index is disabled
48 _require_scratch_overlay_features index nfs_export redirect_dir
49 _require_loop
50
51 # Lower overlay lower layer is on test fs, upper is on scratch fs
52 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
53 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
54 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
55 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
56 upper2=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER.2
57 work2=$OVL_BASE_SCRATCH_MNT/$OVL_WORK.2
58 mnt2=$OVL_BASE_SCRATCH_MNT/$OVL_MNT.2
59
60 lowerdir=$lower/lowertestdir
61 upperdir=$upper/uppertestdir
62 lowertestdir=$mnt2/lowertestdir
63 uppertestdir=$mnt2/uppertestdir
64
65 create_dirs()
66 {
67         # Create the underlying overlay dirs
68         _scratch_mkfs
69
70         # Re-create the nested overlay upper dirs
71         rm -rf $lower $upper2 $work2 $mnt2
72         mkdir $lower $upper2 $work2 $mnt2
73
74         # Create a loop device for blkdev tests
75         $XFS_IO_PROG -f -c "truncate 128k" $lower/img >> $seqres.full 2>&1
76         loopdev=`_create_loop_device $lower/img`
77 }
78
79 # Mount a nested overlay with $SCRATCH_MNT as lower layer
80 mount_dirs()
81 {
82         # Mount the underlying overlay with file handle support
83         _overlay_mount_dirs $lower $upper $work overlay1 $SCRATCH_MNT \
84                 -o "index=on,nfs_export=on,xino=on" || \
85                 _notrun "cannot mount overlay with xino=on option"
86         _fs_options overlay1 | grep -q "xino=on" || \
87                 _notrun "cannot enable xino feature on overlay"
88
89         # Mount the nested overlay
90         # Enable redirect_dir for renaming a merge directory.
91         # Enabling xino in this test requires that base filesystem inode numbers will
92         # not use bit 63 in inode number of the test files, because bit 63 is used by
93         # overlayfs to indicate the layer. Let's just assume that this is true for all
94         # tested filesystems and if we are wrong, the test may fail.
95         _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
96                 -o "redirect_dir=on,index=on,xino=on" || \
97                 _notrun "cannot mount nested overlay with xino=on option"
98         _fs_options overlay2 | grep -q "xino=on" || \
99                 _notrun "cannot enable xino feature on nested overlay"
100 }
101
102 # Unmount the nested overlay mount and check underlying overlay layers
103 unmount_dirs()
104 {
105         # unmount & check nested overlay
106         $UMOUNT_PROG $mnt2
107         _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
108                 -o "redirect_dir=on,index=on,xino=on"
109
110         # unmount & check underlying overlay
111         $UMOUNT_PROG $SCRATCH_MNT
112         _overlay_check_dirs $lower $upper $work \
113                 -o "index=on,nfs_export=on"
114 }
115
116 FILES="file symlink link chrdev blkdev fifo socket"
117
118 create_test_files()
119 {
120         local dir=$1
121
122         # Create our test files.
123         mkdir -p $dir
124         touch $dir/file
125         ln -s $dir/file $dir/symlink
126         touch $dir/link
127         ln $dir/link $dir/link2
128         cp -a /dev/zero $dir/chrdev
129         cp -a $loopdev $dir/blkdev
130         mknod $dir/fifo p
131         $here/src/af_unix $dir/socket
132 }
133
134 # Record inode numbers in format <ino> <basename>
135 record_inode_numbers()
136 {
137         local dir=$1
138         local outfile=$2
139
140         echo "record_inode_numbers $outfile" >> $seqres.full
141
142         for n in $FILES; do
143                 ls -id $dir/$n
144         done | \
145         while read ino file; do
146                 f=`basename $file`
147                 echo $ino $f | tee -a $seqres.full >> $outfile
148                 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
149                 # doesn't follow symlink, blocks on fifo and fails on socket
150                 [[ $f =~ fifo|socket|symlink ]] || \
151                 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
152                         echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
153         done
154 }
155
156 # Check inode numbers match recorder inode numbers
157 check_inode_numbers()
158 {
159         local dir=$1
160         local before=$2
161         local after=$3
162
163         record_inode_numbers $dir $after
164
165         # Test constant stat(2) st_ino -
166         # Compare before..after - expect silence
167         # We use diff -u so out.bad will tell us which stage failed
168         diff -u $before $after
169
170         # Test constant readdir(3)/getdents(2) d_ino -
171         # Expect to find file by inode number
172         cat $before | while read ino f; do
173                 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
174                         echo "$f not found by ino $ino (from $before) - see $seqres.full"
175         done
176 }
177
178 create_dirs
179
180 create_test_files $lowerdir
181 create_test_files $upperdir
182
183 mount_dirs
184
185 # Record inode numbers in the lower overlay
186 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
187 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
188
189 # Record inode numbers before copy up from nested upper
190 record_inode_numbers $lowertestdir $tmp.before.lo
191 record_inode_numbers $uppertestdir $tmp.before.up
192
193 # Copy up all files
194 for f in $FILES; do
195         # chown -h modifies all those file types
196         chown -h 100 $lowertestdir/$f
197         chown -h 100 $uppertestdir/$f
198 done
199
200 # Compare inode numbers before/after copy up
201 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
202 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
203
204 # Move all files to another dir
205 mkdir $lowertestdir.2 $uppertestdir.2
206
207 for f in $FILES; do
208         mv $lowertestdir/$f $lowertestdir.2/
209         mv $uppertestdir/$f $uppertestdir.2/
210 done
211
212 echo 3 > /proc/sys/vm/drop_caches
213
214 # Compare inode numbers before/after rename and drop caches
215 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
216 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
217
218 # Verify that the inode numbers survive a mount cycle
219 unmount_dirs
220 mount_dirs
221
222 # Compare inode numbers before/after mount cycle
223 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
224 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
225
226 unmount_dirs
227
228 echo "Silence is golden"
229 status=0
230 exit