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 a known issue with overlayfs:
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 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # Unmount the nested overlay mount
34 $UMOUNT_PROG $mnt2 2>/dev/null
35 [ -z "$loopdev" ] || _destroy_loop_device $loopdev
38 # get standard environment, filters and checks
42 # real QA test starts here
44 _require_scratch_nocheck
45 _require_test_program "af_unix"
46 _require_test_program "t_dir_type"
47 _require_command "$FLOCK_PROG" "flock"
48 # We need to require all features together, because nfs_export cannot
49 # be enabled when index is disabled
50 _require_scratch_overlay_features index nfs_export redirect_dir
53 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
54 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
55 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
56 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
57 upper2=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER.2
58 work2=$OVL_BASE_SCRATCH_MNT/$OVL_WORK.2
59 mnt2=$OVL_BASE_SCRATCH_MNT/$OVL_MNT.2
61 lowerdir=$lower/lowertestdir
62 upperdir=$upper/uppertestdir
63 lowertestdir=$mnt2/lowertestdir
64 uppertestdir=$mnt2/uppertestdir
68 # Create the underlying overlay dirs
71 # Create the nested overlay upper dirs
72 mkdir -p $upper2 $work2 $mnt2
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`
79 # Mount a nested overlay with $SCRATCH_MNT as lower layer
82 # Mount the underlying overlay with file handle support
83 _scratch_mount -o "index=on,nfs_export=on"
85 # Mount the nested overlay
86 # Enable redirect_dir for renaming a merge directory.
87 # Enabling xino in this test requires that base filesystem inode numbers will
88 # not use bit 63 in inode number of the test files, because bit 63 is used by
89 # overlayfs to indicate the layer. Let's just assume that this is true for all
90 # tested filesystems and if we are wrong, the test may fail.
91 _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
92 -o "redirect_dir=on,index=on,xino=on" || \
93 _notrun "cannot mount nested overlay with xino=on option"
94 _fs_options overlay2 | grep -q "xino=on" || \
95 _notrun "cannot enable xino feature on nested overlay"
98 # Unmount the nested overlay mount and check underlying overlay layers
101 # unmount & check nested overlay
103 _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
104 -o "redirect_dir=on,index=on,xino=on"
106 # unmount & check underlying overlay
107 $UMOUNT_PROG $SCRATCH_MNT
108 _overlay_check_scratch_dirs $lower $upper $work \
109 -o "index=on,nfs_export=on"
112 FILES="dir file symlink link chrdev blkdev fifo socket"
118 # Create our test files.
121 ln -s $dir/file $dir/symlink
123 ln $dir/link $dir/link2
124 cp -a /dev/zero $dir/chrdev
125 cp -a $loopdev $dir/blkdev
127 $here/src/af_unix $dir/socket
130 # Record inode numbers in format <ino> <basename>
131 record_inode_numbers()
136 echo "record_inode_numbers $outfile" >> $seqres.full
141 while read ino file; do
143 echo $ino $f | tee -a $seqres.full >> $outfile
144 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
145 # doesn't follow symlink, blocks on fifo and fails on socket
146 [[ $f =~ fifo|socket|symlink ]] || \
147 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
148 echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
152 # Check inode numbers match recorder inode numbers
153 check_inode_numbers()
159 record_inode_numbers $dir $after
161 # Test constant stat(2) st_ino -
162 # Compare before..after - expect silence
163 # We use diff -u so out.bad will tell us which stage failed
164 diff -u $before $after
166 # Test constant readdir(3)/getdents(2) d_ino -
167 # Expect to find file by inode number
168 cat $before | while read ino f; do
169 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
170 echo "$f not found by ino $ino (from $before) - see $seqres.full"
178 create_test_files $lowerdir
179 create_test_files $upperdir
183 # Record inode numbers in the lower overlay
184 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
185 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
187 # Record inode numbers before copy up
188 record_inode_numbers $lowertestdir $tmp.before.lo
189 record_inode_numbers $uppertestdir $tmp.before.up
193 # chown -h modifies all those file types
194 chown -h 100 $lowertestdir/$f
195 chown -h 100 $uppertestdir/$f
198 # Compare inode numbers before/after copy up
199 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
200 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
202 # Move all files to another dir
203 mkdir $lowertestdir.2 $uppertestdir.2
206 mv $lowertestdir/$f $lowertestdir.2/
207 mv $uppertestdir/$f $uppertestdir.2/
210 echo 3 > /proc/sys/vm/drop_caches
212 # Compare inode numbers before/after rename and drop caches
213 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
214 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
216 # Verify that the inode numbers survive a mount cycle
220 # Compare inode numbers before/after mount cycle
221 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
222 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
226 echo "Silence is golden"