overlay/017: use t_dir_type to find file by d_ino
[xfstests-dev.git] / tests / overlay / 017
1 #! /bin/bash
2 # FSQA Test No. 017
3 #
4 # Test constant inode numbers
5 #
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
10 #
11 # Also test if d_ino of readdir entries changes after copy up
12 # and if inode numbers persist after rename, drop caches and
13 # mount cycle.
14 #
15 #-----------------------------------------------------------------------
16 #
17 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
18 # Author: Amir Goldstein <amir73il@gmail.com>
19 #
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.
23 #
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.
28 #
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 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 here=`pwd`
40 tmp=/tmp/$$
41 status=1        # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
43
44 _cleanup()
45 {
46         cd /
47         rm -f $tmp.*
48 }
49
50 # get standard environment, filters and checks
51 . ./common/rc
52 . ./common/filter
53
54 # real QA test starts here
55 _supported_fs overlay
56 _supported_os Linux
57 _require_scratch
58 _require_test_program "af_unix"
59 _require_test_program "t_dir_type"
60
61 rm -f $seqres.full
62
63 _scratch_mkfs >>$seqres.full 2>&1
64
65 # Create our test files.
66 # Not dealing with hardlinks here, when hardlinks are broken they
67 # should not preserve the inode number.
68 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
69 mkdir -p $lowerdir
70 mkdir $lowerdir/dir
71 touch $lowerdir/file
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
77
78 FILES="dir file symlink chrdev blkdev fifo socket"
79
80 # Record inode numbers in format <ino> <basename>
81 function record_inode_numbers()
82 {
83         dir=$1
84         outfile=$2
85
86         for f in $FILES; do
87                 ls -id $dir/$f
88         done | \
89         while read ino file; do
90                 echo $ino `basename $file` >> $outfile
91         done
92 }
93
94 # Check inode numbers match recorder inode numbers
95 function check_inode_numbers()
96 {
97         dir=$1
98         before=$2
99         after=$3
100
101         record_inode_numbers $dir $after
102
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
107
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)"
113         done
114 }
115
116 _scratch_mount
117
118
119 rm -f $tmp.*
120 testdir=$SCRATCH_MNT/test
121 mkdir -p $testdir
122
123 # Record inode numbers before copy up
124 record_inode_numbers $SCRATCH_MNT $tmp.before
125
126 for f in $FILES; do
127         # chown -h modifies all those file types
128         chown -h 100 $SCRATCH_MNT/$f
129 done
130
131 # Compare inode numbers before/after copy up
132 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
133
134 for f in $FILES; do
135         # move to another dir
136         mv $SCRATCH_MNT/$f $testdir/
137 done
138
139 echo 3 > /proc/sys/vm/drop_caches
140
141 # Compare inode numbers before/after rename and drop caches
142 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
143
144 # Verify that the inode numbers survive a mount cycle
145 _scratch_cycle_mount
146
147 # Compare inode numbers before/after mount cycle
148 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
149
150 echo "Silence is golden"
151 status=0
152 exit