2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 CTERA Networks. All Rights Reserved.
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.
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
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.
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
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # Unmount the nested overlay mount
37 $UMOUNT_PROG $mnt2 2>/dev/null
38 [ -z "$loopdev" ] || _destroy_loop_device $loopdev
41 # get standard environment, filters and checks
45 # real QA test starts here
48 _require_scratch_nocheck
49 _require_test_program "af_unix"
50 _require_test_program "t_dir_type"
51 _require_command "$FLOCK_PROG" "flock"
52 # We need to require all features together, because nfs_export cannot
53 # be enabled when index is disabled
54 _require_scratch_overlay_features index nfs_export redirect_dir
57 # Lower overlay lower layer is on test fs, upper is on scratch fs
58 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
59 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
60 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
61 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
62 upper2=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER.2
63 work2=$OVL_BASE_SCRATCH_MNT/$OVL_WORK.2
64 mnt2=$OVL_BASE_SCRATCH_MNT/$OVL_MNT.2
66 lowerdir=$lower/lowertestdir
67 upperdir=$upper/uppertestdir
68 lowertestdir=$mnt2/lowertestdir
69 uppertestdir=$mnt2/uppertestdir
73 # Create the underlying overlay dirs
76 # Re-create the nested overlay upper dirs
77 rm -rf $lower $upper2 $work2 $mnt2
78 mkdir $lower $upper2 $work2 $mnt2
80 # Create a loop device for blkdev tests
81 $XFS_IO_PROG -f -c "truncate 128k" $lower/img >> $seqres.full 2>&1
82 loopdev=`_create_loop_device $lower/img`
85 # Mount a nested overlay with $SCRATCH_MNT as lower layer
88 # Mount the underlying overlay with file handle support
89 _overlay_mount_dirs $lower $upper $work overlay1 $SCRATCH_MNT \
90 -o "index=on,nfs_export=on,xino=on" || \
91 _notrun "cannot mount overlay with xino=on option"
92 _fs_options overlay1 | grep -q "xino=on" || \
93 _notrun "cannot enable xino feature on overlay"
95 # Mount the nested overlay
96 # Enable redirect_dir for renaming a merge directory.
97 # Enabling xino in this test requires that base filesystem inode numbers will
98 # not use bit 63 in inode number of the test files, because bit 63 is used by
99 # overlayfs to indicate the layer. Let's just assume that this is true for all
100 # tested filesystems and if we are wrong, the test may fail.
101 _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
102 -o "redirect_dir=on,index=on,xino=on" || \
103 _notrun "cannot mount nested overlay with xino=on option"
104 _fs_options overlay2 | grep -q "xino=on" || \
105 _notrun "cannot enable xino feature on nested overlay"
108 # Unmount the nested overlay mount and check underlying overlay layers
111 # unmount & check nested overlay
113 _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
114 -o "redirect_dir=on,index=on,xino=on"
116 # unmount & check underlying overlay
117 $UMOUNT_PROG $SCRATCH_MNT
118 _overlay_check_dirs $lower $upper $work \
119 -o "index=on,nfs_export=on"
122 FILES="file symlink link chrdev blkdev fifo socket"
128 # Create our test files.
131 ln -s $dir/file $dir/symlink
133 ln $dir/link $dir/link2
134 cp -a /dev/zero $dir/chrdev
135 cp -a $loopdev $dir/blkdev
137 $here/src/af_unix $dir/socket
140 # Record inode numbers in format <ino> <basename>
141 record_inode_numbers()
146 echo "record_inode_numbers $outfile" >> $seqres.full
151 while read ino file; do
153 echo $ino $f | tee -a $seqres.full >> $outfile
154 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
155 # doesn't follow symlink, blocks on fifo and fails on socket
156 [[ $f =~ fifo|socket|symlink ]] || \
157 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
158 echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
162 # Check inode numbers match recorder inode numbers
163 check_inode_numbers()
169 record_inode_numbers $dir $after
171 # Test constant stat(2) st_ino -
172 # Compare before..after - expect silence
173 # We use diff -u so out.bad will tell us which stage failed
174 diff -u $before $after
176 # Test constant readdir(3)/getdents(2) d_ino -
177 # Expect to find file by inode number
178 cat $before | while read ino f; do
179 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
180 echo "$f not found by ino $ino (from $before) - see $seqres.full"
188 create_test_files $lowerdir
189 create_test_files $upperdir
193 # Record inode numbers in the lower overlay
194 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
195 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
197 # Compare inode numbers in lower overlay vs. nested overlay
198 # With nested xino lower/lower, all inode numbers overflow xino bits and
199 # d_ino/i_ino in nested overlay are the same as in lower overlay.
200 check_inode_numbers $lowertestdir $tmp.lower.lo $tmp.before.lo
202 # Record inode numbers before copy up from nested upper
203 record_inode_numbers $uppertestdir $tmp.before.up
207 # chown -h modifies all those file types
208 chown -h 100 $lowertestdir/$f
209 chown -h 100 $uppertestdir/$f
212 # Compare inode numbers before/after copy up
213 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
214 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
216 # Move all files to another dir
217 mkdir $lowertestdir.2 $uppertestdir.2
220 mv $lowertestdir/$f $lowertestdir.2/
221 mv $uppertestdir/$f $uppertestdir.2/
224 echo 3 > /proc/sys/vm/drop_caches
226 # Compare inode numbers before/after rename and drop caches
227 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
228 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
230 # Verify that the inode numbers survive a mount cycle
234 # Compare inode numbers before/after mount cycle
235 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
236 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
240 echo "Silence is golden"