779907dc539bdd182b4e6c6cefdfe222a2d61b67
[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 #
13 #-----------------------------------------------------------------------
14 #
15 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
16 # Author: Amir Goldstein <amir73il@gmail.com>
17 #
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
21 #
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30 #-----------------------------------------------------------------------
31 #
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44         cd /
45         rm -f $tmp.*
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53 _supported_fs overlay
54 _supported_os Linux
55 _require_scratch
56 _require_test_program "af_unix"
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >>$seqres.full 2>&1
61
62 # Create our test files.
63 # Not dealing with hardlinks here, when hardlinks are broken they
64 # should not preserve the inode number.
65 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
66 mkdir -p $lowerdir
67 mkdir $lowerdir/dir
68 touch $lowerdir/file
69 ln -s $lowerdir/file $lowerdir/symlink
70 mknod $lowerdir/chrdev c 1 1
71 mknod $lowerdir/blkdev b 1 1
72 mknod $lowerdir/fifo p
73 $here/src/af_unix $lowerdir/socket
74
75
76 _scratch_mount
77
78
79 rm -f $tmp.*
80
81 # Test stable stat(2) st_ino
82
83 # Record inode numbers before and after copy up
84 for f in dir file symlink chrdev blkdev fifo socket; do
85         ls -id $SCRATCH_MNT/$f >> $tmp.before
86         # chown -h modifies all those file types
87         chown -h 100 $SCRATCH_MNT/$f
88         ls -id $SCRATCH_MNT/$f >> $tmp.after
89 done
90
91 # Test stable readdir(3)/getdents(2) d_ino
92
93 # find by inode number - expect to find file by inode number
94 cat $tmp.before | while read ino f; do
95         find $SCRATCH_MNT/ -maxdepth 1 -inum $ino | grep -q $f || \
96                 echo "$f not found by ino $ino"
97 done
98
99 # Compare before..after - expect silence
100 diff $tmp.before $tmp.after
101
102 echo "Silence is golden"
103 status=0
104 exit