generic: copy_file_range immutable file test
authorAmir Goldstein <amir73il@gmail.com>
Sun, 2 Jun 2019 12:41:10 +0000 (15:41 +0300)
committerEryu Guan <guaneryu@gmail.com>
Fri, 7 Jun 2019 17:05:19 +0000 (01:05 +0800)
Check that we cannot copy_file_range() to/from an immutable file.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/553 [new file with mode: 0755]
tests/generic/553.out [new file with mode: 0644]
tests/generic/group

diff --git a/tests/generic/553 b/tests/generic/553
new file mode 100755 (executable)
index 0000000..efe25d8
--- /dev/null
@@ -0,0 +1,59 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 553
+#
+# Check that we cannot copy_file_range() to/from an immutable file
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 7 15
+
+workdir="$TEST_DIR/test-$seq"
+_cleanup()
+{
+       $CHATTR_PROG -i $workdir/immutable > /dev/null 2>&1
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_os Linux
+_supported_fs generic
+
+rm -f $seqres.full
+
+_require_test
+_require_chattr i
+_require_xfs_io_command "copy_range"
+_require_xfs_io_command "chattr"
+
+rm -rf $workdir
+mkdir $workdir
+
+rm -f $seqres.full
+
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 128k" $workdir/file >> $seqres.full 2>&1
+
+# we have to open the file to be immutable rw and hold it open over the
+# chattr command to set it immutable, otherwise we won't be able to open it for
+# writing after it's been made immutable. (i.e. would exercise file mode checks,
+# not immutable inode flag checks).
+echo immutable file returns EPERM
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 64k" -c fsync $workdir/immutable | _filter_xfs_io
+$XFS_IO_PROG -f -c "chattr +i" -c "copy_range -l 32k $workdir/file" $workdir/immutable
+$XFS_IO_PROG -f -r -c "chattr -i" $workdir/immutable
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/553.out b/tests/generic/553.out
new file mode 100644 (file)
index 0000000..de1cb5a
--- /dev/null
@@ -0,0 +1,5 @@
+QA output created by 553
+immutable file returns EPERM
+wrote 65536/65536 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+copy_range: Operation not permitted
index 09c068b6460ed3f14f150451acc4685cf2e9745f..fe63b1cd3db27413809ed76003a9a2af21e4d0a1 100644 (file)
 550 auto quick encrypt
 551 auto stress aio
 552 auto quick log
+553 auto quick copy_range