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
36 # get standard environment, filters and checks
43 _require_test_program "t_immutable"
48 # Preparing test area files in lower dir and check chattr support of base fs
51 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
52 if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then
53 _notrun "Setting immutable/append flag not supported"
55 # Remove the immutable/append-only flags and create subdirs
56 $timmutable -R $lowerdir/testdir >$tmp.out 2>&1
57 for dir in $lowerdir/testdir/*.d; do
60 # Restore the immutable/append-only flags
61 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
65 # Test immutability of files in overlay
66 echo "Before directories copy up"
67 $timmutable $SCRATCH_MNT/testdir 2>&1
69 # Trigger copy-up of immutable/append-only dirs by touching their subdirs
70 # inode flags are not copied-up, so immutable/append-only flags are lost
71 for dir in $SCRATCH_MNT/testdir/*.d; do
75 # Trigger copy-up of append-only files by touching them
76 # inode flags are not copied-up, so append-only flags are lost
77 # touch on the immutable files is expected to fail, so immutable
78 # flags will not be lost
79 for file in $SCRATCH_MNT/testdir/*.f; do
80 touch $file > /dev/null 2>&1
83 # immutable/append-only flags still exist on the overlay in-core inode
84 # After mount cycle, flags are forever lost
87 # Test immutability of files in overlay after directories copy-up
88 echo "After directories copy up"
89 $timmutable $SCRATCH_MNT/testdir 2>&1