overlay/017: verify constant inode number after rename
[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 and drop caches.
13 #
14 #-----------------------------------------------------------------------
15 #
16 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
17 # Author: Amir Goldstein <amir73il@gmail.com>
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32 #
33
34 seq=`basename $0`
35 seqres=$RESULT_DIR/$seq
36 echo "QA output created by $seq"
37
38 here=`pwd`
39 tmp=/tmp/$$
40 status=1        # failure is the default!
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 _cleanup()
44 {
45         cd /
46         rm -f $tmp.*
47 }
48
49 # get standard environment, filters and checks
50 . ./common/rc
51 . ./common/filter
52
53 # real QA test starts here
54 _supported_fs overlay
55 _supported_os Linux
56 _require_scratch
57 _require_test_program "af_unix"
58
59 rm -f $seqres.full
60
61 _scratch_mkfs >>$seqres.full 2>&1
62
63 # Create our test files.
64 # Not dealing with hardlinks here, when hardlinks are broken they
65 # should not preserve the inode number.
66 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
67 mkdir -p $lowerdir
68 mkdir $lowerdir/dir
69 touch $lowerdir/file
70 ln -s $lowerdir/file $lowerdir/symlink
71 mknod $lowerdir/chrdev c 1 1
72 mknod $lowerdir/blkdev b 1 1
73 mknod $lowerdir/fifo p
74 $here/src/af_unix $lowerdir/socket
75
76 FILES="dir file symlink chrdev blkdev fifo socket"
77
78 # Record inode numbers in format <ino> <basename>
79 function record_inode_numbers()
80 {
81         dir=$1
82         outfile=$2
83
84         for f in $FILES; do
85                 ls -id $dir/$f
86         done | \
87         while read ino file; do
88                 echo $ino `basename $file` >> $outfile
89         done
90 }
91
92 # Check inode numbers match recorder inode numbers
93 function check_inode_numbers()
94 {
95         dir=$1
96         before=$2
97         after=$3
98
99         record_inode_numbers $dir $after
100
101         # Test constant stat(2) st_ino -
102         #   Compare before..after - expect silence
103         # We use diff -u so out.bad will tell us which stage failed
104         diff -u $before $after
105
106         # Test constant readdir(3)/getdents(2) d_ino -
107         #   Expect to find file by inode number
108         cat $before | while read ino f; do
109                 find $dir/ -maxdepth 1 -inum $ino | grep -q $f || \
110                         echo "$f not found by ino $ino (from $before)"
111         done
112 }
113
114 _scratch_mount
115
116
117 rm -f $tmp.*
118 testdir=$SCRATCH_MNT/test
119 mkdir -p $testdir
120
121 # Record inode numbers before copy up
122 record_inode_numbers $SCRATCH_MNT $tmp.before
123
124 for f in $FILES; do
125         # chown -h modifies all those file types
126         chown -h 100 $SCRATCH_MNT/$f
127 done
128
129 # Compare inode numbers before/after copy up
130 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
131
132 for f in $FILES; do
133         # move to another dir
134         mv $SCRATCH_MNT/$f $testdir/
135 done
136
137 echo 3 > /proc/sys/vm/drop_caches
138
139 # Compare inode numbers before/after rename and drop caches
140 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
141
142 echo "Silence is golden"
143 status=0
144 exit