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 all layers of both overlays are on the
11 # This simple test demonstrates an issue with overlayfs on kernel < v4.17:
12 # - stat file A shows inode number X
13 # - modify A to trigger copy up
14 # - stat file A shows inode number Y != X
16 # Also test that d_ino of readdir entries and i_ino from /proc/locks are
17 # consistent with st_ino and that inode numbers persist after rename to
18 # new parent, drop caches and mount cycle.
21 _begin_fstest auto quick copyup redirect nested
23 # Override the default cleanup function.
28 # Unmount the nested overlay mount
29 $UMOUNT_PROG $mnt2 2>/dev/null
30 [ -z "$loopdev" ] || _destroy_loop_device $loopdev
33 # Import common functions.
36 # real QA test starts here
38 _fixed_in_kernel_version "v4.17"
40 _require_scratch_nocheck
41 _require_test_program "af_unix"
42 _require_test_program "t_dir_type"
43 _require_command "$FLOCK_PROG" "flock"
44 # We need to require all features together, because nfs_export cannot
45 # be enabled when index is disabled
46 _require_scratch_overlay_features index nfs_export redirect_dir
49 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
50 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
51 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
52 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
53 upper2=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER.2
54 work2=$OVL_BASE_SCRATCH_MNT/$OVL_WORK.2
55 mnt2=$OVL_BASE_SCRATCH_MNT/$OVL_MNT.2
57 lowerdir=$lower/lowertestdir
58 upperdir=$upper/uppertestdir
59 lowertestdir=$mnt2/lowertestdir
60 uppertestdir=$mnt2/uppertestdir
64 # Create the underlying overlay dirs
67 # Create the nested overlay upper dirs
68 mkdir -p $upper2 $work2 $mnt2
70 # Create a loop device for blkdev tests
71 $XFS_IO_PROG -f -c "truncate 128k" $lower/img >> $seqres.full 2>&1
72 loopdev=`_create_loop_device $lower/img`
75 # Mount a nested overlay with $SCRATCH_MNT as lower layer
78 # Mount the underlying overlay with file handle support
79 _scratch_mount -o "index=on,nfs_export=on"
81 # Mount the nested overlay
82 # Enable redirect_dir for renaming a merge directory.
83 # Enabling xino in this test requires that base filesystem inode numbers will
84 # not use bit 63 in inode number of the test files, because bit 63 is used by
85 # overlayfs to indicate the layer. Let's just assume that this is true for all
86 # tested filesystems and if we are wrong, the test may fail.
87 _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
88 -o "redirect_dir=on,index=on,xino=on" || \
89 _notrun "cannot mount nested overlay with xino=on option"
90 _fs_options overlay2 | grep -q "xino=on" || \
91 _notrun "cannot enable xino feature on nested overlay"
94 # Unmount the nested overlay mount and check underlying overlay layers
97 # unmount & check nested overlay
99 _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
100 -o "redirect_dir=on,index=on,xino=on"
102 # unmount & check underlying overlay
103 $UMOUNT_PROG $SCRATCH_MNT
104 _overlay_check_scratch_dirs $lower $upper $work \
105 -o "index=on,nfs_export=on"
108 FILES="dir file symlink link chrdev blkdev fifo socket"
114 # Create our test files.
117 ln -s $dir/file $dir/symlink
119 ln $dir/link $dir/link2
120 cp -a /dev/zero $dir/chrdev
121 cp -a $loopdev $dir/blkdev
123 $here/src/af_unix $dir/socket
126 # Record inode numbers in format <ino> <basename>
127 record_inode_numbers()
132 echo "record_inode_numbers $outfile" >> $seqres.full
137 while read ino file; do
139 echo $ino $f | tee -a $seqres.full >> $outfile
140 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
141 # doesn't follow symlink, blocks on fifo and fails on socket
142 [[ $f =~ fifo|socket|symlink ]] || \
143 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
144 echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
148 # Check inode numbers match recorder inode numbers
149 check_inode_numbers()
155 record_inode_numbers $dir $after
157 # Test constant stat(2) st_ino -
158 # Compare before..after - expect silence
159 # We use diff -u so out.bad will tell us which stage failed
160 diff -u $before $after
162 # Test constant readdir(3)/getdents(2) d_ino -
163 # Expect to find file by inode number
164 cat $before | while read ino f; do
165 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
166 echo "$f not found by ino $ino (from $before) - see $seqres.full"
172 create_test_files $lowerdir
173 create_test_files $upperdir
177 # Record inode numbers in the lower overlay
178 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
179 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
181 # Record inode numbers before copy up
182 record_inode_numbers $lowertestdir $tmp.before.lo
183 record_inode_numbers $uppertestdir $tmp.before.up
187 # chown -h modifies all those file types
188 chown -h 100 $lowertestdir/$f
189 chown -h 100 $uppertestdir/$f
192 # Compare inode numbers before/after copy up
193 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
194 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
196 # Move all files to another dir
197 mkdir $lowertestdir.2 $uppertestdir.2
200 mv $lowertestdir/$f $lowertestdir.2/
201 mv $uppertestdir/$f $uppertestdir.2/
204 echo 3 > /proc/sys/vm/drop_caches
206 # Compare inode numbers before/after rename and drop caches
207 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
208 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
210 # Verify that the inode numbers survive a mount cycle
214 # Compare inode numbers before/after mount cycle
215 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
216 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
220 echo "Silence is golden"