4 # Test fsck.overlay how to deal with whiteouts in overlayfs.
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2018 Huawei. All Rights Reserved.
8 # Author: zhangyi (F) <yi.zhang@huawei.com>
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
45 # remove previous $seqres.full before test
48 # real QA test starts here
51 _require_scratch_nocheck
53 _require_command "$FSCK_OVERLAY_PROG" fsck.overlay
55 OVL_XATTR_OPAQUE_VAL=y
57 # remove all files from previous tests
64 local ttype=`stat -c "%F:%t,%T" $arg`
66 [[ "$ttype" == "character special file:0,0" ]] || \
67 echo "Valid whiteout removed incorrectly"
79 # Create an opaque directory
85 $SETFATTR_PROG -n $OVL_XATTR_OPAQUE -v $OVL_XATTR_OPAQUE_VAL $target
88 # Create a redirect directory
95 $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target
98 # Create test directories
99 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
100 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
101 upperdir=$OVL_BASE_SCRATCH_MNT/upper
102 workdir=$OVL_BASE_SCRATCH_MNT/workdir
106 rm -rf $lowerdir $lowerdir2 $upperdir $workdir
107 mkdir -p $lowerdir $lowerdir2 $upperdir $workdir
110 # Test orphan whiteout in lower and upper layer, should remove
111 echo "+ Orphan whiteout"
113 make_whiteout $lowerdir/foo $upperdir/{foo,bar}
115 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
116 echo "fsck should not fail"
120 # Test valid whiteout covering lower target, should not remove
121 echo "+ Valid whiteout"
123 touch $lowerdir2/{foo,bar}
124 make_whiteout $upperdir/foo $lowerdir/bar
126 _overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p >> \
127 $seqres.full 2>&1 || echo "fsck should not fail"
128 check_whiteout $upperdir/foo $lowerdir/bar
130 # Test orphan whiteout in opaque directory, should remove
131 echo "+ Orphan whiteout(2)"
133 mkdir $lowerdir/testdir
134 touch $lowerdir/testdir/foo
135 make_opaque_dir $upperdir/testdir
136 make_whiteout $upperdir/testdir/foo
138 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
139 echo "fsck should not fail"
142 # Test orphan whiteout whose parent path is not an merged directory,
144 echo "+ Orphan whiteout(3)"
146 mkdir $lowerdir2/{testdir1,testdir2,testdir3}
147 touch $lowerdir2/{testdir1/foo,testdir2/foo,testdir3/foo}
148 mkdir $upperdir/{testdir1,testdir2,testdir3,testdir4}
149 touch $lowerdir/testdir1
150 make_whiteout $lowerdir/testdir2
151 make_opaque_dir $lowerdir/testdir3
152 make_whiteout $upperdir/{testdir1/foo,/testdir2/foo,testdir3/foo,testdir4/foo}
154 _overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p >> \
155 $seqres.full 2>&1 || echo "fsck should not fail"
156 ls $upperdir/testdir1
157 ls $upperdir/testdir2
158 ls $upperdir/testdir3
159 ls $upperdir/testdir4
161 # Test orphan whiteout in redirect directory, should remove
162 echo "+ Orphan whiteout(4)"
164 mkdir $lowerdir/{testdir,origin}
165 touch $lowerdir/testdir/foo
166 make_redirect_dir $upperdir/testdir "origin"
167 make_whiteout $upperdir/testdir/foo
169 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
170 echo "fsck should not fail"
173 # Test valid whiteout in redirect directory cover file in lower
174 # redirect origin directory, should not remove
175 echo "+ Valid whiteout(2)"
177 mkdir $lowerdir/origin
178 touch $lowerdir/origin/foo
179 make_redirect_dir $upperdir/testdir "origin"
180 make_whiteout $upperdir/testdir/foo
182 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
183 echo "fsck should not fail"
184 check_whiteout $upperdir/testdir/foo
186 # Test valid whiteout covering lower target whose parent directory
187 # merge with a redirect directory in the middle layer, should not remove.
188 echo "+ Valid whiteout(3)"
190 mkdir -p $lowerdir2/origin/subdir
191 touch $lowerdir2/origin/subdir/foo
192 make_redirect_dir $lowerdir/testdir "origin"
193 mkdir -p $upperdir/testdir/subdir
194 make_whiteout $upperdir/testdir/subdir/foo
196 _overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p \
197 >> $seqres.full 2>&1 || echo "fsck should not fail"
198 check_whiteout $upperdir/testdir/subdir/foo
200 # Test invalid whiteout in opaque subdirectory in a redirect directory,
202 echo "+ Orphan whiteout(5)"
204 mkdir -p $lowerdir/origin/subdir
205 touch $lowerdir/origin/subdir/foo
206 make_redirect_dir $upperdir/testdir "origin"
207 make_opaque_dir $upperdir/testdir/subdir
208 make_whiteout $upperdir/testdir/subdir/foo
210 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
211 echo "fsck should not fail"
212 ls $upperdir/testdir/subdir
214 # Test valid whiteout in reidrect subdirectory in a opaque directory
215 # covering lower target, should not remove
216 echo "+ Valid whiteout(4)"
218 mkdir $lowerdir/origin
219 touch $lowerdir/origin/foo
220 make_opaque_dir $upperdir/testdir
221 make_redirect_dir $upperdir/testdir/subdir "/origin"
222 make_whiteout $upperdir/testdir/subdir/foo
224 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
225 echo "fsck should not fail"
226 check_whiteout $upperdir/testdir/subdir/foo