generic: test for non-zero used blocks while writing into a file
[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 _require_scratch_nocheck
55
56 # remove all files from previous runs
57 _scratch_mkfs
58
59 # create test directorys and whiteout
60 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
61 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
62 upperdir=$OVL_BASE_SCRATCH_MNT/upper
63 workdir=$OVL_BASE_SCRATCH_MNT/workdir
64 # When overlay inode index feature is enabled, a workdir cannot be reused
65 # with a different upperdir. workdir1 in this test is used as the workdir
66 # when lowerdir1 is used as the upperdir.
67 workdir1=$OVL_BASE_SCRATCH_MNT/workdir1
68 testfile1=a
69 testfile2=b
70 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir $workdir1
71
72 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
73
74 # clean up the lower directory and mount overlay again,
75 # whiteout will expose.
76 rm -rf $lowerdir1/testdir
77
78 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
79
80 ls $SCRATCH_MNT/testdir
81
82 # try to remove test dir from overlay dir, trigger ovl_remove_upper,
83 # it will not clean up the dir and lead to rmdir failure.
84 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
85
86 # umount overlay again, create a new file with the same name and
87 # mount overlay again.
88 $UMOUNT_PROG $SCRATCH_MNT
89 touch $lowerdir1/testdir
90
91 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
92
93 # try to remove test dir from overlay dir, trigger ovl_remove_and_whiteout,
94 # it will not clean up the dir and lead to residue.
95 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
96
97 $UMOUNT_PROG $SCRATCH_MNT
98
99 # let lower dir have invalid whiteouts, repeat ls and rmdir test again.
100 rm -rf $lowerdir1/testdir
101 rm -rf $upperdir/testdir
102
103 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile1
104
105 rm -rf $lowerdir2/testdir
106
107 _overlay_scratch_mount_dirs "$lowerdir1:$lowerdir2" $upperdir $workdir
108
109 ls $SCRATCH_MNT/testdir
110 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
111
112 $UMOUNT_PROG $SCRATCH_MNT
113
114 # let lower dir and upper dir both have invalid whiteouts, repeat ls and rmdir again.
115 rm -rf $lowerdir1/testdir
116 rm -rf $upperdir/testdir
117
118 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
119
120 rm -rf $lowerdir1/testdir/$testfile1
121
122 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile2
123
124 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
125
126 ls $SCRATCH_MNT/testdir
127 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
128
129 # success, all done
130 echo "Silence is golden"
131 status=0
132 exit