overlay/075: fix wrong invocation of t_immutable
[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 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 timmutable=$here/src/t_immutable
21 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
22 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
23 tmp=/tmp/$$
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
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
34         rm -f $tmp.*
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40
41 _supported_fs overlay
42
43 _require_chattr ia
44 _require_test_program "t_immutable"
45 _require_scratch
46
47 _scratch_mkfs
48
49 # Check chattr support of base fs
50 mkdir -p $lowerdir
51 mkdir -p $upperdir
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"
55 fi
56
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
62         mkdir $dir/subdir
63 done
64 # Restore the immutable/append-only flags
65 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
66
67 _scratch_mount
68
69 # Test immutability of files in overlay before copy up
70 echo "Before directories copy up"
71 $timmutable $SCRATCH_MNT/testdir.before 2>&1
72
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
76         touch $dir/subdir
77 done
78
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
85 done
86
87 # immutable/append-only flags still exist on the overlay in-core inode
88 # After mount cycle, flags are forever lost
89 _scratch_cycle_mount
90
91 # Test immutability of files in overlay after directories copy-up
92 echo "After directories copy up"
93 $timmutable $SCRATCH_MNT/testdir 2>&1
94
95 status=$?
96 exit