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
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
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
67 lowerdir=$lower/lowertestdir
68 upperdir=$upper/uppertestdir
69 lowertestdir=$mnt2/lowertestdir
70 uppertestdir=$mnt2/uppertestdir
74 # Create the underlying overlay dirs
77 # Re-create the nested overlay upper dirs
78 rm -rf $lower $upper2 $work2 $mnt2
79 mkdir $lower $upper2 $work2 $mnt2
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`
86 # Mount a nested overlay with $SCRATCH_MNT as lower layer
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"
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"
109 # Unmount the nested overlay mount and check underlying overlay layers
112 # unmount & check nested overlay
114 _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
115 -o "redirect_dir=on,index=on,xino=on"
117 # unmount & check underlying overlay
118 $UMOUNT_PROG $SCRATCH_MNT
119 _overlay_check_dirs $lower $upper $work \
120 -o "index=on,nfs_export=on"
123 FILES="file symlink link chrdev blkdev fifo socket"
129 # Create our test files.
132 ln -s $dir/file $dir/symlink
134 ln $dir/link $dir/link2
135 cp -a /dev/zero $dir/chrdev
136 cp -a $loopdev $dir/blkdev
138 $here/src/af_unix $dir/socket
141 # Record inode numbers in format <ino> <basename>
142 record_inode_numbers()
147 echo "record_inode_numbers $outfile" >> $seqres.full
152 while read ino file; do
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"
163 # Check inode numbers match recorder inode numbers
164 check_inode_numbers()
170 record_inode_numbers $dir $after
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
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"
189 create_test_files $lowerdir
190 create_test_files $upperdir
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
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
203 # Record inode numbers before copy up from nested upper
204 record_inode_numbers $uppertestdir $tmp.before.up
208 # chown -h modifies all those file types
209 chown -h 100 $lowertestdir/$f
210 chown -h 100 $uppertestdir/$f
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
217 # Move all files to another dir
218 mkdir $lowertestdir.2 $uppertestdir.2
221 mv $lowertestdir/$f $lowertestdir.2/
222 mv $uppertestdir/$f $uppertestdir.2/
225 echo 3 > /proc/sys/vm/drop_caches
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
231 # Verify that the inode numbers survive a mount cycle
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
241 echo "Silence is golden"