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
55 _require_scratch_nocheck
57 # remove all files from previous runs
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
71 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir $workdir1
73 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
75 # clean up the lower directory and mount overlay again,
76 # whiteout will expose.
77 rm -rf $lowerdir1/testdir
79 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
81 ls $SCRATCH_MNT/testdir
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
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
92 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
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
99 $UMOUNT_PROG $SCRATCH_MNT
101 # let lower dir have invalid whiteouts, repeat ls and rmdir test again.
102 rm -rf $lowerdir1/testdir
103 rm -rf $upperdir/testdir
105 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile1
107 rm -rf $lowerdir2/testdir
109 _overlay_scratch_mount_dirs "$lowerdir1:$lowerdir2" $upperdir $workdir
111 ls $SCRATCH_MNT/testdir
112 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
114 $UMOUNT_PROG $SCRATCH_MNT
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
120 create_whiteout $lowerdir1 $upperdir $workdir $testfile1
122 rm -rf $lowerdir1/testdir/$testfile1
124 create_whiteout $lowerdir2 $lowerdir1 $workdir1 $testfile2
126 _overlay_scratch_mount_dirs $lowerdir1 $upperdir $workdir
128 ls $SCRATCH_MNT/testdir
129 rm -rf $SCRATCH_MNT/testdir 2>&1 | _filter_scratch
132 echo "Silence is golden"