xfs/144: Use _qsetup instead of qsetup
[xfstests-dev.git] / tests / overlay / 045
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test No. 045
6 #
7 # Test fsck.overlay how to deal with whiteouts in overlayfs.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs overlay
34 _require_scratch_nocheck
35 _require_attrs trusted
36 _require_command "$FSCK_OVERLAY_PROG" fsck.overlay
37
38 OVL_XATTR_OPAQUE_VAL=y
39 OVL_XATTR_IMPURE_VAL=y
40
41 # remove all files from previous tests
42 _scratch_mkfs
43
44 # Check whiteout
45 check_whiteout()
46 {
47         for arg in $*; do
48                 local ttype=`stat -c "%F:%t,%T" $arg`
49
50                 [[ "$ttype" == "character special file:0,0" ]] || \
51                         echo "Valid whiteout removed incorrectly"
52         done
53 }
54
55 # Create a whiteout
56 make_whiteout()
57 {
58         for arg in $*; do
59                 mknod $arg c 0 0
60         done
61 }
62
63 # Create an opaque directory
64 make_opaque_dir()
65 {
66         local target=$1
67
68         mkdir -p $target
69         $SETFATTR_PROG -n $OVL_XATTR_OPAQUE -v $OVL_XATTR_OPAQUE_VAL $target
70 }
71
72 # Create impure directories
73 make_impure_dir()
74 {
75         for dir in $*; do
76                 mkdir -p $dir
77                 $SETFATTR_PROG -n $OVL_XATTR_IMPURE -v $OVL_XATTR_IMPURE_VAL $dir
78         done
79 }
80
81 # Create a redirect directory
82 make_redirect_dir()
83 {
84         local target=$1
85         local value=$2
86
87         mkdir -p $target
88         $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target
89 }
90
91 # Create test directories
92 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
93 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
94 upperdir=$OVL_BASE_SCRATCH_MNT/upper
95 workdir=$OVL_BASE_SCRATCH_MNT/workdir
96
97 make_test_dirs()
98 {
99         rm -rf $lowerdir $lowerdir2 $upperdir $workdir
100         mkdir -p $lowerdir $lowerdir2 $upperdir $workdir
101 }
102
103 # Test orphan whiteout in lower and upper layer, should remove
104 echo "+ Orphan whiteout"
105 make_test_dirs
106 make_whiteout $lowerdir/foo $upperdir/{foo,bar}
107
108 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
109 ls $lowerdir
110 ls $upperdir
111
112 # Test valid whiteout covering lower target, should not remove
113 echo "+ Valid whiteout"
114 make_test_dirs
115 touch $lowerdir2/{foo,bar}
116 make_whiteout $upperdir/foo $lowerdir/bar
117
118 _overlay_fsck_expect $FSCK_OK "$lowerdir:$lowerdir2" $upperdir $workdir -p
119 check_whiteout $upperdir/foo $lowerdir/bar
120
121 # Test orphan whiteout in opaque directory, should remove
122 echo "+ Orphan whiteout(2)"
123 make_test_dirs
124 mkdir $lowerdir/testdir
125 touch $lowerdir/testdir/foo
126 make_opaque_dir $upperdir/testdir
127 make_whiteout $upperdir/testdir/foo
128
129 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
130 ls $upperdir/testdir
131
132 # Test orphan whiteout whose parent path is not an merged directory,
133 # should remove
134 echo "+ Orphan whiteout(3)"
135 make_test_dirs
136 mkdir $lowerdir2/{testdir1,testdir2,testdir3}
137 touch $lowerdir2/{testdir1/foo,testdir2/foo,testdir3/foo}
138 mkdir $upperdir/{testdir1,testdir2,testdir3,testdir4}
139 touch $lowerdir/testdir1
140 make_whiteout $lowerdir/testdir2
141 make_opaque_dir $lowerdir/testdir3
142 make_whiteout $upperdir/{testdir1/foo,/testdir2/foo,testdir3/foo,testdir4/foo}
143
144 _overlay_fsck_expect $FSCK_NONDESTRUCT "$lowerdir:$lowerdir2" $upperdir $workdir -p
145 ls $upperdir/testdir1
146 ls $upperdir/testdir2
147 ls $upperdir/testdir3
148 ls $upperdir/testdir4
149
150 # Test orphan whiteout in redirect directory, should remove
151 echo "+ Orphan whiteout(4)"
152 make_test_dirs
153 mkdir $lowerdir/{testdir,origin}
154 touch $lowerdir/testdir/foo
155 make_redirect_dir $upperdir/testdir "origin"
156 make_whiteout $upperdir/testdir/foo
157
158 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
159 ls $upperdir/testdir
160
161 # Test valid whiteout in redirect directory cover file in lower
162 # redirect origin directory, should not remove
163 echo "+ Valid whiteout(2)"
164 make_test_dirs
165 mkdir $lowerdir/origin
166 touch $lowerdir/origin/foo
167 make_impure_dir $upperdir
168 make_redirect_dir $upperdir/testdir "origin"
169 make_whiteout $upperdir/origin $upperdir/testdir/foo
170
171 _overlay_fsck_expect $FSCK_OK $lowerdir $upperdir $workdir -p
172 check_whiteout $upperdir/testdir/foo
173
174 # Test valid whiteout covering lower target whose parent directory
175 # merge with a redirect directory in the middle layer, should not remove.
176 echo "+ Valid whiteout(3)"
177 make_test_dirs
178 mkdir -p $lowerdir2/origin/subdir
179 touch $lowerdir2/origin/subdir/foo
180 make_redirect_dir $lowerdir/testdir "origin"
181 mkdir -p $upperdir/testdir/subdir
182 make_whiteout $lowerdir/origin $upperdir/testdir/subdir/foo
183 make_impure_dir $upperdir/testdir $upperdir
184
185 _overlay_fsck_expect $FSCK_OK "$lowerdir:$lowerdir2" $upperdir $workdir -p
186 check_whiteout $upperdir/testdir/subdir/foo
187
188 # Test invalid whiteout in opaque subdirectory in a redirect directory,
189 # should remove
190 echo "+ Orphan whiteout(5)"
191 make_test_dirs
192 mkdir -p $lowerdir/origin/subdir
193 touch $lowerdir/origin/subdir/foo
194 make_redirect_dir $upperdir/testdir "origin"
195 make_opaque_dir $upperdir/testdir/subdir
196 make_whiteout $upperdir/testdir/subdir/foo
197
198 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
199 ls $upperdir/testdir/subdir
200
201 # Test valid whiteout in reidrect subdirectory in a opaque directory
202 # covering lower target, should not remove
203 echo "+ Valid whiteout(4)"
204 make_test_dirs
205 mkdir $lowerdir/origin
206 touch $lowerdir/origin/foo
207 make_opaque_dir $upperdir/testdir
208 make_redirect_dir $upperdir/testdir/subdir "/origin"
209 make_whiteout $upperdir/origin $upperdir/testdir/subdir/foo
210 make_impure_dir $upperdir/testdir
211
212 _overlay_fsck_expect $FSCK_OK $lowerdir $upperdir $workdir -p
213 check_whiteout $upperdir/testdir/subdir/foo
214
215 # success, all done
216 status=0
217 exit