2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Huawei. All Rights Reserved.
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
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # create test directory and test file, mount overlayfs and remove
28 # testfile to create a whiteout in upper dir.
36 mkdir -p $lower/testdir
37 touch $lower/testdir/$file
39 _overlay_scratch_mount_dirs $lower $upper $work
41 rm -f $SCRATCH_MNT/testdir/$file
43 $UMOUNT_PROG $SCRATCH_MNT
46 # get standard environment, filters and checks
52 # real QA test starts here
54 _require_scratch_nocheck
56 # remove all files from previous runs
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
70 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir $workdir1
72 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
74 # clean up the lower directory and mount overlay again,
75 # whiteout will expose.
76 rm -rf $lowerdir1/testdir
78 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
80 ls $SCRATCH_MNT/testdir
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
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
91 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
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
97 $UMOUNT_PROG $SCRATCH_MNT
99 # let lower dir have invalid whiteouts, repeat ls and rmdir test again.
100 rm -rf $lowerdir1/testdir
101 rm -rf $upperdir/testdir
103 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile1
105 rm -rf $lowerdir2/testdir
107 _overlay_scratch_mount_dirs "$lowerdir1:$lowerdir2" $upperdir $workdir
109 ls $SCRATCH_MNT/testdir
110 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
112 $UMOUNT_PROG $SCRATCH_MNT
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
118 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
120 rm -rf $lowerdir1/testdir/$testfile1
122 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile2
124 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
126 ls $SCRATCH_MNT/testdir
127 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
130 echo "Silence is golden"