2740c7c3e9c964d35059614f519517131e9c7da6
[xfstests-dev.git] / tests / overlay / 031
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 031
6 #
7 # The unmerged and origined directories may contain invalid
8 # whiteouts when we change underlaying dir (e.g. clean up lowerdir)
9 # and remount overlay. This may lead to whiteouts exposure and
10 # rmdir failure.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # create test directory and test file, mount overlayfs and remove
28 # testfile to create a whiteout in upper dir.
29 create_whiteout()
30 {
31         local lower=$1
32         local upper=$2
33         local work=$3
34         local file=$4
35
36         mkdir -p $lower/testdir
37         touch $lower/testdir/$file
38
39         _overlay_scratch_mount_dirs $lower $upper $work
40
41         rm -f $SCRATCH_MNT/testdir/$file
42
43         $UMOUNT_PROG $SCRATCH_MNT
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49
50 rm -f $seqres.full
51
52 # real QA test starts here
53 _supported_fs overlay
54 _supported_os Linux
55 _require_scratch_nocheck
56
57 # remove all files from previous runs
58 _scratch_mkfs
59
60 # create test directorys and whiteout
61 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
62 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
63 upperdir=$OVL_BASE_SCRATCH_MNT/upper
64 workdir=$OVL_BASE_SCRATCH_MNT/workdir
65 # When overlay inode index feature is enabled, a workdir cannot be reused
66 # with a different upperdir. workdir1 in this test is used as the workdir
67 # when lowerdir1 is used as the upperdir.
68 workdir1=$OVL_BASE_SCRATCH_MNT/workdir1
69 testfile1=a
70 testfile2=b
71 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir $workdir1
72
73 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
74
75 # clean up the lower directory and mount overlay again,
76 # whiteout will expose.
77 rm -rf $lowerdir1/testdir
78
79 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
80
81 ls $SCRATCH_MNT/testdir
82
83 # try to remove test dir from overlay dir, trigger ovl_remove_upper,
84 # it will not clean up the dir and lead to rmdir failure.
85 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
86
87 # umount overlay again, create a new file with the same name and
88 # mount overlay again.
89 $UMOUNT_PROG $SCRATCH_MNT
90 touch $lowerdir1/testdir
91
92 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
93
94 # try to remove test dir from overlay dir, trigger ovl_remove_and_whiteout,
95 # it will not clean up the dir and lead to residue.
96 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
97 ls $workdir/work
98
99 $UMOUNT_PROG $SCRATCH_MNT
100
101 # let lower dir have invalid whiteouts, repeat ls and rmdir test again.
102 rm -rf $lowerdir1/testdir
103 rm -rf $upperdir/testdir
104
105 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile1
106
107 rm -rf $lowerdir2/testdir
108
109 _overlay_scratch_mount_dirs "$lowerdir1:$lowerdir2" $upperdir $workdir
110
111 ls $SCRATCH_MNT/testdir
112 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
113
114 $UMOUNT_PROG $SCRATCH_MNT
115
116 # let lower dir and upper dir both have invalid whiteouts, repeat ls and rmdir again.
117 rm -rf $lowerdir1/testdir
118 rm -rf $upperdir/testdir
119
120 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
121
122 rm -rf $lowerdir1/testdir/$testfile1
123
124 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile2
125
126 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
127
128 ls $SCRATCH_MNT/testdir
129 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
130
131 # success, all done
132 echo "Silence is golden"
133 status=0
134 exit