2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 CTERA Networks. All Rights Reserved.
7 # Run the t_immutable test program for immutable/append-only files
8 # and directories that exist in overlayfs lower layer.
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.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
20 timmutable=$here/src/t_immutable
21 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
22 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
24 status=1 # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # -r will fail to remove test dirs, because we added subdirs
30 # we just need to remove the flags so use -R
31 $timmutable -R $upperdir/testdir &> /dev/null
32 $timmutable -R $lowerdir/testdir &> /dev/null
33 $timmutable -R $lowerdir/testdir.before &> /dev/null
37 # get standard environment, filters and checks
44 _require_test_program "t_immutable"
49 # Check chattr support of base fs
52 $timmutable -C $lowerdir/testdir.before >$tmp.out 2>&1
53 if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then
54 _notrun "Setting immutable/append flag not supported"
57 # Prepare test area files in lower dir
58 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
59 # Remove the immutable/append-only flags and create subdirs
60 $timmutable -R $lowerdir/testdir >$tmp.out 2>&1
61 for dir in $lowerdir/testdir/*.d; do
64 # Restore the immutable/append-only flags
65 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
69 # Test immutability of files in overlay before copy up
70 echo "Before directories copy up"
71 $timmutable $SCRATCH_MNT/testdir.before 2>&1
73 # Trigger copy-up of immutable/append-only dirs by touching their subdirs
74 # inode flags are not copied-up, so immutable/append-only flags are lost
75 for dir in $SCRATCH_MNT/testdir/*.d; do
79 # Trigger copy-up of append-only files by touching them
80 # inode flags are not copied-up, so append-only flags are lost
81 # touch on the immutable files is expected to fail, so immutable
82 # flags will not be lost
83 for file in $SCRATCH_MNT/testdir/*.f; do
84 touch $file > /dev/null 2>&1
87 # immutable/append-only flags still exist on the overlay in-core inode
88 # After mount cycle, flags are forever lost
91 # Test immutability of files in overlay after directories copy-up
92 echo "After directories copy up"
93 $timmutable $SCRATCH_MNT/testdir 2>&1