overlay: skip check for tests finished with corrupt filesystem
[xfstests-dev.git] / tests / overlay / 031
1 #! /bin/bash
2 # FS QA Test 031
3 #
4 # The unmerged and origined directories may contain invalid
5 # whiteouts when we change underlaying dir (e.g. clean up lowerdir)
6 # and remount overlay. This may lead to whiteouts exposure and
7 # rmdir failure.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2017 Huawei.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40 }
41
42 # create test directory and test file, mount overlayfs and remove
43 # testfile to create a whiteout in upper dir.
44 create_whiteout()
45 {
46         local lower=$1
47         local upper=$2
48         local work=$3
49         local file=$4
50
51         mkdir -p $lower/testdir
52         touch $lower/testdir/$file
53
54         _overlay_scratch_mount_dirs $lower $upper $work
55
56         rm -f $SCRATCH_MNT/testdir/$file
57
58         $UMOUNT_PROG $SCRATCH_MNT
59 }
60
61 # get standard environment, filters and checks
62 . ./common/rc
63 . ./common/filter
64
65 rm -f $seqres.full
66
67 # real QA test starts here
68 _supported_fs overlay
69 _supported_os Linux
70 _require_scratch_nocheck
71
72 # remove all files from previous runs
73 _scratch_mkfs
74
75 # create test directorys and whiteout
76 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
77 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
78 upperdir=$OVL_BASE_SCRATCH_MNT/upper
79 workdir=$OVL_BASE_SCRATCH_MNT/workdir
80 # When overlay inode index feature is enabled, a workdir cannot be reused
81 # with a different upperdir. workdir1 in this test is used as the workdir
82 # when lowerdir1 is used as the upperdir.
83 workdir1=$OVL_BASE_SCRATCH_MNT/workdir1
84 testfile1=a
85 testfile2=b
86 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir $workdir1
87
88 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
89
90 # clean up the lower directory and mount overlay again,
91 # whiteout will expose.
92 rm -rf $lowerdir1/testdir
93
94 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
95
96 ls $SCRATCH_MNT/testdir
97
98 # try to remove test dir from overlay dir, trigger ovl_remove_upper,
99 # it will not clean up the dir and lead to rmdir failure.
100 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
101
102 # umount overlay again, create a new file with the same name and
103 # mount overlay again.
104 $UMOUNT_PROG $SCRATCH_MNT
105 touch $lowerdir1/testdir
106
107 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
108
109 # try to remove test dir from overlay dir, trigger ovl_remove_and_whiteout,
110 # it will not clean up the dir and lead to residue.
111 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
112 ls $workdir/work
113
114 $UMOUNT_PROG $SCRATCH_MNT
115
116 # let lower dir have invalid whiteouts, repeat ls and rmdir test again.
117 rm -rf $lowerdir1/testdir
118 rm -rf $upperdir/testdir
119
120 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile1
121
122 rm -rf $lowerdir2/testdir
123
124 _overlay_scratch_mount_dirs "$lowerdir1:$lowerdir2" $upperdir $workdir
125
126 ls $SCRATCH_MNT/testdir
127 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
128
129 $UMOUNT_PROG $SCRATCH_MNT
130
131 # let lower dir and upper dir both have invalid whiteouts, repeat ls and rmdir again.
132 rm -rf $lowerdir1/testdir
133 rm -rf $upperdir/testdir
134
135 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
136
137 rm -rf $lowerdir1/testdir/$testfile1
138
139 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile2
140
141 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
142
143 ls $SCRATCH_MNT/testdir
144 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
145
146 # success, all done
147 echo "Silence is golden"
148 status=0
149 exit