5a6c3be0a2ba9da8d8b8533a4ac90db6ff9ea690
[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         rm -f $tmp.*
34 }
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/filter
39
40 _supported_fs overlay
41
42 _require_chattr ia
43 _require_test_program "t_immutable"
44 _require_scratch
45
46 _scratch_mkfs
47
48 # Preparing test area files in lower dir and check chattr support of base fs
49 mkdir -p $lowerdir
50 mkdir -p $upperdir
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"
54 fi
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
58         mkdir $dir/subdir
59 done
60 # Restore the immutable/append-only flags
61 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
62
63 _scratch_mount
64
65 # Test immutability of files in overlay
66 echo "Before directories copy up"
67 $timmutable $SCRATCH_MNT/testdir 2>&1
68
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
72         touch $dir/subdir
73 done
74
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
81 done
82
83 # immutable/append-only flags still exist on the overlay in-core inode
84 # After mount cycle, flags are forever lost
85 _scratch_cycle_mount
86
87 # Test immutability of files in overlay after directories copy-up
88 echo "After directories copy up"
89 $timmutable $SCRATCH_MNT/testdir 2>&1
90
91 status=$?
92 exit