fabfbb5e61924b814be53297484d82d10f7f1a24
[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
60 rm -f $seqres.full
61
62 _scratch_mkfs >>$seqres.full 2>&1
63
64 # Create our test files.
65 # Not dealing with hardlinks here, when hardlinks are broken they
66 # should not preserve the inode number.
67 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
68 mkdir -p $lowerdir
69 mkdir $lowerdir/dir
70 touch $lowerdir/file
71 ln -s $lowerdir/file $lowerdir/symlink
72 mknod $lowerdir/chrdev c 1 1
73 mknod $lowerdir/blkdev b 1 1
74 mknod $lowerdir/fifo p
75 $here/src/af_unix $lowerdir/socket
76
77 FILES="dir file symlink chrdev blkdev fifo socket"
78
79 # Record inode numbers in format <ino> <basename>
80 function record_inode_numbers()
81 {
82         dir=$1
83         outfile=$2
84
85         for f in $FILES; do
86                 ls -id $dir/$f
87         done | \
88         while read ino file; do
89                 echo $ino `basename $file` >> $outfile
90         done
91 }
92
93 # Check inode numbers match recorder inode numbers
94 function check_inode_numbers()
95 {
96         dir=$1
97         before=$2
98         after=$3
99
100         record_inode_numbers $dir $after
101
102         # Test constant stat(2) st_ino -
103         #   Compare before..after - expect silence
104         # We use diff -u so out.bad will tell us which stage failed
105         diff -u $before $after
106
107         # Test constant readdir(3)/getdents(2) d_ino -
108         #   Expect to find file by inode number
109         cat $before | while read ino f; do
110                 find $dir/ -maxdepth 1 -inum $ino | grep -q $f || \
111                         echo "$f not found by ino $ino (from $before)"
112         done
113 }
114
115 _scratch_mount
116
117
118 rm -f $tmp.*
119 testdir=$SCRATCH_MNT/test
120 mkdir -p $testdir
121
122 # Record inode numbers before copy up
123 record_inode_numbers $SCRATCH_MNT $tmp.before
124
125 for f in $FILES; do
126         # chown -h modifies all those file types
127         chown -h 100 $SCRATCH_MNT/$f
128 done
129
130 # Compare inode numbers before/after copy up
131 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
132
133 for f in $FILES; do
134         # move to another dir
135         mv $SCRATCH_MNT/$f $testdir/
136 done
137
138 echo 3 > /proc/sys/vm/drop_caches
139
140 # Compare inode numbers before/after rename and drop caches
141 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
142
143 # Verify that the inode numbers survive a mount cycle
144 _scratch_cycle_mount
145
146 # Compare inode numbers before/after mount cycle
147 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
148
149 echo "Silence is golden"
150 status=0
151 exit