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 _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 _require_scratch_nocheck
39 _require_test_program "af_unix"
40 _require_test_program "t_dir_type"
41 _require_command "$FLOCK_PROG" "flock"
42 # We need to require all features together, because nfs_export cannot
43 # be enabled when index is disabled
44 _require_scratch_overlay_features index nfs_export redirect_dir
47 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
48 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
49 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
50 # Lower dir of nested overlay is the scratch overlay mount at SCRATCH_MNT
51 upper2=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER.2
52 work2=$OVL_BASE_SCRATCH_MNT/$OVL_WORK.2
53 mnt2=$OVL_BASE_SCRATCH_MNT/$OVL_MNT.2
55 lowerdir=$lower/lowertestdir
56 upperdir=$upper/uppertestdir
57 lowertestdir=$mnt2/lowertestdir
58 uppertestdir=$mnt2/uppertestdir
62 # Create the underlying overlay dirs
65 # Create the nested overlay upper dirs
66 mkdir -p $upper2 $work2 $mnt2
68 # Create a loop device for blkdev tests
69 $XFS_IO_PROG -f -c "truncate 128k" $lower/img >> $seqres.full 2>&1
70 loopdev=`_create_loop_device $lower/img`
73 # Mount a nested overlay with $SCRATCH_MNT as lower layer
76 # Mount the underlying overlay with file handle support
77 _scratch_mount -o "index=on,nfs_export=on"
79 # Mount the nested overlay
80 # Enable redirect_dir for renaming a merge directory.
81 # Enabling xino in this test requires that base filesystem inode numbers will
82 # not use bit 63 in inode number of the test files, because bit 63 is used by
83 # overlayfs to indicate the layer. Let's just assume that this is true for all
84 # tested filesystems and if we are wrong, the test may fail.
85 _overlay_mount_dirs $SCRATCH_MNT $upper2 $work2 overlay2 $mnt2 \
86 -o "redirect_dir=on,index=on,xino=on" || \
87 _notrun "cannot mount nested overlay with xino=on option"
88 _fs_options overlay2 | grep -q "xino=on" || \
89 _notrun "cannot enable xino feature on nested overlay"
92 # Unmount the nested overlay mount and check underlying overlay layers
95 # unmount & check nested overlay
97 _overlay_check_dirs $SCRATCH_MNT $upper2 $work2 \
98 -o "redirect_dir=on,index=on,xino=on"
100 # unmount & check underlying overlay
101 $UMOUNT_PROG $SCRATCH_MNT
102 _overlay_check_scratch_dirs $lower $upper $work \
103 -o "index=on,nfs_export=on"
106 FILES="dir file symlink link chrdev blkdev fifo socket"
112 # Create our test files.
115 ln -s $dir/file $dir/symlink
117 ln $dir/link $dir/link2
118 cp -a /dev/zero $dir/chrdev
119 cp -a $loopdev $dir/blkdev
121 $here/src/af_unix $dir/socket
124 # Record inode numbers in format <ino> <basename>
125 record_inode_numbers()
130 echo "record_inode_numbers $outfile" >> $seqres.full
135 while read ino file; do
137 echo $ino $f | tee -a $seqres.full >> $outfile
138 # /proc/locks exposes i_ino - compare it to st_ino. flock -n
139 # doesn't follow symlink, blocks on fifo and fails on socket
140 [[ $f =~ fifo|socket|symlink ]] || \
141 $FLOCK_PROG -n $file cat /proc/locks | tee -a $seqres.full | grep -q ":$ino " || \
142 echo "lock for $f not found by ino $ino ($outfile) - see $seqres.full"
146 # Check inode numbers match recorder inode numbers
147 check_inode_numbers()
153 record_inode_numbers $dir $after
155 # Test constant stat(2) st_ino -
156 # Compare before..after - expect silence
157 # We use diff -u so out.bad will tell us which stage failed
158 diff -u $before $after
160 # Test constant readdir(3)/getdents(2) d_ino -
161 # Expect to find file by inode number
162 cat $before | while read ino f; do
163 $here/src/t_dir_type $dir $ino | tee -a $seqres.full | grep -q $f || \
164 echo "$f not found by ino $ino (from $before) - see $seqres.full"
170 create_test_files $lowerdir
171 create_test_files $upperdir
175 # Record inode numbers in the lower overlay
176 record_inode_numbers $SCRATCH_MNT/lowertestdir $tmp.lower.lo
177 record_inode_numbers $SCRATCH_MNT/uppertestdir $tmp.lower.up
179 # Record inode numbers before copy up
180 record_inode_numbers $lowertestdir $tmp.before.lo
181 record_inode_numbers $uppertestdir $tmp.before.up
185 # chown -h modifies all those file types
186 chown -h 100 $lowertestdir/$f
187 chown -h 100 $uppertestdir/$f
190 # Compare inode numbers before/after copy up
191 check_inode_numbers $lowertestdir $tmp.before.lo $tmp.after_copyup.lo
192 check_inode_numbers $uppertestdir $tmp.before.up $tmp.after_copyup.up
194 # Move all files to another dir
195 mkdir $lowertestdir.2 $uppertestdir.2
198 mv $lowertestdir/$f $lowertestdir.2/
199 mv $uppertestdir/$f $uppertestdir.2/
202 echo 3 > /proc/sys/vm/drop_caches
204 # Compare inode numbers before/after rename and drop caches
205 check_inode_numbers $lowertestdir.2 $tmp.after_copyup.lo $tmp.after_move.lo
206 check_inode_numbers $uppertestdir.2 $tmp.after_copyup.up $tmp.after_move.up
208 # Verify that the inode numbers survive a mount cycle
212 # Compare inode numbers before/after mount cycle
213 check_inode_numbers $lowertestdir.2 $tmp.after_move.lo $tmp.after_cycle.lo
214 check_inode_numbers $uppertestdir.2 $tmp.after_move.up $tmp.after_cycle.up
218 echo "Silence is golden"