overlay/075: fix wrong invocation of t_immutable
[xfstests-dev.git] / tests / overlay / 041
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
4 #
5 # FSQA Test No. 041
6 #
7 # Test consistent d_ino numbers on non-samefs setup
8 # This is a variant of overlay/038 to test consistent d_ino numbers
9 # for non-samefs setup.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/attr
30
31 # real QA test starts here
32 _supported_fs overlay
33 # Use non-default scratch underlying overlay dirs, we need to check
34 # them explicity after test.
35 _require_scratch_nocheck
36 _require_test
37 _require_attrs trusted
38 _require_test_program "t_dir_type"
39
40 rm -f $seqres.full
41
42 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
43 rm -rf $lowerdir
44 mkdir $lowerdir
45
46 # Create our test files.
47 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
48 touch $lowerdir/test_file
49
50 _scratch_mkfs
51
52 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
53 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
54
55 # Enabling xino in this test requires that base filesystem inode numbers will
56 # not use bit 63 in inode number of the test files, because bit 63 is used by
57 # overlayfs to indicate the layer. Let's just assume that this is true for all
58 # tested filesystems and if we are wrong, the test may fail.
59 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o xino=on || \
60         _notrun "cannot mount overlay with xino=on option"
61 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
62         _notrun "cannot enable xino feature"
63
64 test_dir=$SCRATCH_MNT/test_dir/
65
66 # Verify d_ino of '.' and '..' before and after dir becomes impure.
67 impure_dir=$test_dir/impure_dir
68 mkdir -p $impure_dir/subdir
69
70 impure_dir_st_ino=$(stat -c '%i' $impure_dir)
71 impure_dir_parent_st_ino=$(stat -c '%i' $test_dir)
72 impure_subdir_st_ino=$(stat -c '%i' $impure_dir/subdir)
73
74 # Before $impure_dir becomes impure
75 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
76 [[ $parent_d == ".. d" ]] || \
77     echo "Pure upper dir: Invalid d_ino reported for .."
78
79 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
80 [[ $current_d == ". d" ]] || \
81     echo "Pure upper dir: Invalid d_ino reported for ."
82
83 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
84 [[ $subdir_d == "subdir d" ]] || \
85     echo "Pure upper dir: Invalid d_ino reported for subdir"
86
87 # Move a copied up file into pure dir to make it impure
88 mv $SCRATCH_MNT/test_file $impure_dir
89 test_file_st_ino=$(stat -c '%i' $impure_dir/test_file)
90
91 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
92                         $upperdir/test_dir/impure_dir)
93 [[ $impure == "y" ]] || echo "Impure directory missing impure xattr"
94
95 # After $impure_dir becomes impure
96 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
97 [[ $parent_d == ".. d" ]] || \
98     echo "Impure dir: Invalid d_ino reported for .."
99
100 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
101 [[ $current_d == ". d" ]] || \
102     echo "Impure dir: Invalid d_ino reported for ."
103
104 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
105 [[ $subdir_d == "subdir d" ]] || \
106     echo "Impure dir: Invalid d_ino reported for subdir"
107
108 # Verify copy up file's d_ino
109 file_d=$($here/src/t_dir_type $impure_dir $test_file_st_ino)
110 [[ $file_d == "test_file f" ]] || \
111         echo "Impure dir: Invalid d_ino reported for entry with copy-up origin"
112
113 # Make $impure_dir pure
114 rm -rf $impure_dir/test_file
115 rm -rf $impure_dir/subdir
116
117 # Verify invalidation of readdir cache
118 $here/src/t_dir_type $impure_dir $test_file_st_ino
119 [[ $? != 0 ]] || echo "Directory's readdir cache has stale file entries"
120 $here/src/t_dir_type $impure_dir $impure_subdir_st_ino
121 [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries"
122
123 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
124                         $upperdir/test_dir/impure_dir 2>/dev/null)
125 [[ -z $impure ]] || echo "Pure directory has impure xattr"
126
127 # Verify d_ino values of subdir entries of a pure lower dir.
128 parent_st_ino=$(stat -c '%i' $test_dir)
129 pure_lower_dir=$SCRATCH_MNT/test_dir/pure_lower_dir
130 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
131 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
132
133 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
134 [[ $parent_d == ".. d" ]] || \
135         echo "Pure lower dir: Invalid d_ino reported for .."
136
137 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
138 [[ $current_d == ". d" ]] || \
139         echo "Pure lower dir: Invalid d_ino reported for ."
140
141 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
142 [[ $subdir_d == "subdir d" ]] || \
143         echo "Pure lower dir: Invalid d_ino reported for subdir"
144
145 # Create a file in pure lower dir to make it a merge dir
146 touch $pure_lower_dir/newfile
147
148 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
149 [[ $parent_d == ".. d" ]] || \
150         echo "Merged dir: Invalid d_ino reported for .."
151
152 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
153 [[ $current_d == ". d" ]] || \
154         echo "Merged dir: Invalid d_ino reported for ."
155
156 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
157 [[ $subdir_d == "subdir d" ]] || \
158         echo "Merged dir: Invalid d_ino reported for subdir"
159
160 $UMOUNT_PROG $SCRATCH_MNT
161
162 # check overlayfs
163 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o xino=on
164
165 # Verify pure lower residing in dir which has another lower layer
166 middir=$OVL_BASE_TEST_DIR/$seq-ovl-mid
167 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
168 rm -rf $middir
169 rm -rf $lowerdir
170 mkdir $middir
171 mkdir $lowerdir
172
173 mkdir -p $middir/test_dir
174 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
175
176 _scratch_mkfs
177
178 _overlay_scratch_mount_dirs $middir:$lowerdir $upperdir $workdir -o xino=on
179
180 # Copy up test_dir
181 touch $test_dir/test_file
182
183 test_dir_st_ino=$(stat -c '%i' $test_dir)
184 pure_lower_dir=$test_dir/pure_lower_dir
185 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
186 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
187
188 parent_d=$($here/src/t_dir_type $pure_lower_dir $test_dir_st_ino)
189 [[ $parent_d == ".. d" ]] || \
190         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for .."
191
192 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
193 [[ $current_d == ". d" ]] || \
194         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for ."
195
196 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
197 [[ $subdir_d == "subdir d" ]] || \
198         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for subdir"
199
200 # check overlayfs
201 _overlay_check_scratch_dirs "$middir:$lowerdir" $upperdir $workdir -o xino=on
202
203 echo "Silence is golden"
204 status=0
205 exit