2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc. All Rights Reserved.
7 # Check that we cannot copy_file_range() to an immutable file
9 # This is a regression test for kernel commit:
10 # a31713517dac ("vfs: introduce generic_file_rw_checks()")
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 7 15
21 workdir="$TEST_DIR/test-$seq"
24 $XFS_IO_PROG -f -r -c "chattr -i" $workdir/immutable >/dev/null 2>&1
29 # get standard environment, filters and checks
33 # real QA test starts here
40 _require_xfs_io_command "copy_range"
41 _require_xfs_io_command "chattr" "i"
48 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 128k" $workdir/file >> $seqres.full 2>&1
50 # we have to open the file to be immutable rw and hold it open over the
51 # chattr command to set it immutable, otherwise we won't be able to open it for
52 # writing after it's been made immutable. (i.e. would exercise file mode checks,
53 # not immutable inode flag checks).
54 echo immutable file returns EPERM
55 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 64k" -c fsync $workdir/immutable | _filter_xfs_io
56 $XFS_IO_PROG -f -c "chattr +i" -c "copy_range -l 32k $workdir/file" $workdir/immutable
57 $XFS_IO_PROG -f -r -c "chattr -i" $workdir/immutable