generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / overlay / 075
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 075
6 #
7 # Run the t_immutable test program for immutable/append-only files
8 # and directories that exist in overlayfs lower layer.
9 #
10 # This test is similar and was derived from generic/079, but instead
11 # of creating new files which are created in upper layer, prepare
12 # the test area in lower layer before running the t_immutable test on
13 # the overlayfs mount.
14 #
15 . ./common/preamble
16 _begin_fstest auto quick perms
17
18 timmutable=$here/src/t_immutable
19 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
20 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
21
22 # Override the default cleanup function.
23 _cleanup()
24 {
25         # -r will fail to remove test dirs, because we added subdirs
26         # we just need to remove the flags so use -R
27         $timmutable -R $upperdir/testdir &> /dev/null
28         $timmutable -R $lowerdir/testdir &> /dev/null
29         $timmutable -R $lowerdir/testdir.before &> /dev/null
30         rm -f $tmp.*
31 }
32
33 # Import common functions.
34 . ./common/filter
35
36 _supported_fs overlay
37
38 _require_chattr ia
39 _require_test_program "t_immutable"
40 _require_scratch
41
42 _scratch_mkfs
43
44 # Check chattr support of base fs
45 mkdir -p $lowerdir
46 mkdir -p $upperdir
47 $timmutable -C $lowerdir/testdir.before >$tmp.out 2>&1
48 if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then
49         _notrun "Setting immutable/append flag not supported"
50 fi
51
52 # Prepare test area files in lower dir
53 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
54 # Remove the immutable/append-only flags and create subdirs
55 $timmutable -R $lowerdir/testdir >$tmp.out 2>&1
56 for dir in $lowerdir/testdir/*.d; do
57         mkdir $dir/subdir
58 done
59 # Restore the immutable/append-only flags
60 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
61
62 _scratch_mount
63
64 # Test immutability of files in overlay before copy up
65 echo "Before directories copy up"
66 $timmutable $SCRATCH_MNT/testdir.before 2>&1
67 # Remove the immutable/append-only flags before mount cycle
68 $timmutable -R $SCRATCH_MNT/testdir.before &> /dev/null
69
70 # Trigger copy-up of immutable/append-only dirs by touching their subdirs
71 # inode flags are not copied-up, so immutable/append-only flags are lost
72 for dir in $SCRATCH_MNT/testdir/*.d; do
73         touch $dir/subdir
74 done
75
76 # Trigger copy-up of append-only files by touching them
77 # inode flags are not copied-up, so append-only flags are lost
78 # touch on the immutable files is expected to fail, so immutable
79 # flags will not be lost
80 for file in $SCRATCH_MNT/testdir/*.f; do
81         touch $file > /dev/null 2>&1
82 done
83
84 # immutable/append-only flags still exist on the overlay in-core inode
85 # After mount cycle, flags are forever lost
86 _scratch_cycle_mount
87
88 # Verify that files can be deleted from overlay fs after clearing
89 # immutable/append-only flags and mount cycle
90 rm -rf $SCRATCH_MNT/testdir.before
91
92 # Test immutability of files in overlay after directories copy-up
93 echo "After directories copy up"
94 $timmutable $SCRATCH_MNT/testdir 2>&1
95
96 # Verify that files can be deleted from overlay fs after clearing
97 # immutable/append-only flags
98 $timmutable -R $SCRATCH_MNT/testdir &> /dev/null
99 rm -rf $SCRATCH_MNT/testdir
100
101 status=$?
102 exit