4 # Test constant inode numbers
6 # This simple test demonstrates a known issue with overlayfs:
7 # - stat file A shows inode number X
8 # - modify A to trigger copy up
9 # - stat file A shows inode number Y != X
11 # Also test if d_ino of readdir entries changes after copy up
12 # and if inode numbers persist after rename, drop caches and
15 #-----------------------------------------------------------------------
17 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
18 # Author: Amir Goldstein <amir73il@gmail.com>
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #-----------------------------------------------------------------------
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
41 status=1 # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
50 # get standard environment, filters and checks
54 # real QA test starts here
58 _require_test_program "af_unix"
59 _require_test_program "t_dir_type"
60 # Require redirect_dir for renaming a merge directory
61 _require_scratch_feature redirect_dir
65 _scratch_mkfs >>$seqres.full 2>&1
67 # Create our test files.
68 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
72 ln -s $lowerdir/file $lowerdir/symlink
73 mknod $lowerdir/chrdev c 1 1
74 mknod $lowerdir/blkdev b 1 1
75 mknod $lowerdir/fifo p
76 $here/src/af_unix $lowerdir/socket
78 FILES="dir file symlink chrdev blkdev fifo socket"
80 # Record inode numbers in format <ino> <basename>
81 function record_inode_numbers()
89 while read ino file; do
90 echo $ino `basename $file` >> $outfile
94 # Check inode numbers match recorder inode numbers
95 function check_inode_numbers()
101 record_inode_numbers $dir $after
103 # Test constant stat(2) st_ino -
104 # Compare before..after - expect silence
105 # We use diff -u so out.bad will tell us which stage failed
106 diff -u $before $after
108 # Test constant readdir(3)/getdents(2) d_ino -
109 # Expect to find file by inode number
110 cat $before | while read ino f; do
111 $here/src/t_dir_type $dir $ino | grep -q $f || \
112 echo "$f not found by ino $ino (from $before)"
116 # Enable redirect_dir for renaming a merge directory
117 _scratch_mount "-o redirect_dir=on"
120 testdir=$SCRATCH_MNT/test
123 # Record inode numbers before copy up
124 record_inode_numbers $SCRATCH_MNT $tmp.before
127 # chown -h modifies all those file types
128 chown -h 100 $SCRATCH_MNT/$f
131 # Compare inode numbers before/after copy up
132 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
135 # move to another dir
136 mv $SCRATCH_MNT/$f $testdir/
139 echo 3 > /proc/sys/vm/drop_caches
141 # Compare inode numbers before/after rename and drop caches
142 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
144 # Verify that the inode numbers survive a mount cycle
145 _scratch_cycle_mount "redirect_dir=on"
147 # Compare inode numbers before/after mount cycle
148 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
150 echo "Silence is golden"