overlay/075: fix wrong invocation of t_immutable
[xfstests-dev.git] / tests / overlay / 043
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
4 #
5 # FSQA Test No. 043
6 #
7 # Test constant inode numbers on non-samefs setup
8 # This is a variant of overlay/017 to test constant st_ino numbers for
9 # non-samefs setup.
10 #
11 # This simple test demonstrates a known issue with overlayfs:
12 # - stat file A shows inode number X
13 # - modify A to trigger copy up
14 # - stat file A shows inode number Y != X
15 #
16 # Also test if d_ino of readdir entries changes after copy up
17 # and if inode numbers persist after rename, drop caches and
18 # mount cycle.
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs overlay
41 # Use non-default scratch underlying overlay dirs, we need to check
42 # them explicity after test.
43 _require_scratch_nocheck
44 _require_test
45 _require_test_program "af_unix"
46 _require_test_program "t_dir_type"
47 # Require redirect_dir for renaming a merge directory
48 _require_scratch_feature redirect_dir
49
50 rm -f $seqres.full
51
52 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
53 rm -rf $lowerdir
54 mkdir $lowerdir
55
56 # Create our test files.
57 mkdir $lowerdir/dir
58 touch $lowerdir/file
59 ln -s $lowerdir/file $lowerdir/symlink
60 mknod $lowerdir/chrdev c 1 1
61 mknod $lowerdir/blkdev b 1 1
62 mknod $lowerdir/fifo p
63 $here/src/af_unix $lowerdir/socket
64
65 _scratch_mkfs >>$seqres.full 2>&1
66
67 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
68 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
69
70 # Enable redirect_dir for renaming a merge directory.
71 # Enabling xino in this test requires that base filesystem inode numbers will
72 # not use bit 63 in inode number of the test files, because bit 63 is used by
73 # overlayfs to indicate the layer. Let's just assume that this is true for all
74 # tested filesystems and if we are wrong, the test may fail.
75 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on || \
76         _notrun "cannot mount overlay with xino=on option"
77 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
78         _notrun "cannot enable xino feature"
79
80 FILES="dir file symlink chrdev blkdev fifo socket"
81
82 # Record inode numbers in format <ino> <basename>
83 function record_inode_numbers()
84 {
85         dir=$1
86         outfile=$2
87
88         for f in $FILES; do
89                 ls -id $dir/$f
90         done | \
91         while read ino file; do
92                 echo $ino `basename $file` >> $outfile
93         done
94 }
95
96 # Check inode numbers match recorder inode numbers
97 function check_inode_numbers()
98 {
99         dir=$1
100         before=$2
101         after=$3
102
103         record_inode_numbers $dir $after
104
105         # Test constant stat(2) st_ino -
106         # Compare before..after - expect silence
107         # We use diff -u so out.bad will tell us which stage failed
108         diff -u $before $after
109
110         # Test constant readdir(3)/getdents(2) d_ino -
111         # Expect to find file by inode number
112         cat $before | while read ino f; do
113                 $here/src/t_dir_type $dir $ino | grep -q $f || \
114                         echo "$f not found by ino $ino (from $before)"
115         done
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 $UMOUNT_PROG $SCRATCH_MNT
145 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
146
147 # Compare inode numbers before/after mount cycle
148 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
149
150 # check overlayfs
151 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
152
153 echo "Silence is golden"
154 status=0
155 exit