2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc. All Rights Reserved.
7 # Exercise copy_file_range() syscall error conditions.
9 # This is a regression test for kernel commit:
10 # 96e6e8f4a68d ("vfs: add missing checks to copy_file_range")
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
25 [ -z "$loopdev" ] || _destroy_loop_device $loopdev
28 # get standard environment, filters and checks
32 # real QA test starts here
44 # This test effectively requires xfs_io with these commits
45 # 2a42470b xfs_io: copy_file_range length is a size_t
46 # 1a05efba io: open pipes in non-blocking mode
48 # Without those commits test will hang on old kernel when copying
49 # very large size and when copying from a pipe.
51 # We require a new xfs_io feature of passing an open file as the
52 # copy source, as an indication that the test can run without hanging
53 # with large size argument and to avoid opening pipe in blocking mode.
55 # Test both basic copy_range and copy_range -f availability
56 _require_xfs_io_command "copy_range"
57 _require_xfs_io_command "copy_range" "-f"
59 testdir="$TEST_DIR/test-$seq"
65 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 128k" $testdir/file >> $seqres.full 2>&1
67 echo source range overlaps destination range in same file returns EINVAL
68 $XFS_IO_PROG -f -c "copy_range -s 32k -d 48k -l 32k $testdir/file" $testdir/file
71 echo destination file O_RDONLY returns EBADF
72 $XFS_IO_PROG -f -r -c "copy_range -l 32k $testdir/file" $testdir/copy
75 echo destination file O_APPEND returns EBADF
76 $XFS_IO_PROG -f -a -c "copy_range -l 32k $testdir/file" $testdir/copy
79 echo source/destination as directory returns EISDIR
80 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir
81 $XFS_IO_PROG -f -c "copy_range -l 32k $testdir" $testdir/copy
84 echo source/destination as blkdev returns EINVAL
85 $XFS_IO_PROG -f -c "truncate 128k" $testdir/img >> $seqres.full 2>&1
86 loopdev=`_create_loop_device $testdir/img`
87 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $loopdev
88 $XFS_IO_PROG -f -c "copy_range -l 32k $loopdev" $testdir/copy
89 _destroy_loop_device $loopdev
93 echo source/destination as chardev returns EINVAL
94 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" /dev/null
95 $XFS_IO_PROG -f -c "copy_range -l 32k /dev/zero" $testdir/copy
98 echo source/destination as FIFO returns EINVAL
100 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir/fifo
101 # Pass input pipe as non-blocking open file to avoid old xfs_io (<4.20)
102 # opening the pipe in blocking mode and causing the test to hang
103 $XFS_IO_PROG -r -n -f -c "open $testdir/copy" -C "copy_range -l 32k -f 0" $testdir/fifo
105 max_off=$((8 * 2**60 - 65536 - 1))
109 echo length beyond 8EiB wraps around 0 returns EOVERFLOW
110 $XFS_IO_PROG -f -c "copy_range -l 10e -s $max_off $testdir/file" $testdir/copy
111 $XFS_IO_PROG -f -c "copy_range -l 10e -d $max_off $testdir/file" $testdir/copy
114 echo source range beyond 8TiB returns 0
115 $XFS_IO_PROG -c "copy_range -s $max_off -l $min_off -d 0 $testdir/file" $testdir/copy
118 echo destination range beyond 8TiB returns EFBIG
119 $XFS_IO_PROG -c "copy_range -l $min_off -s 0 -d $max_off $testdir/file" $testdir/copy
122 echo destination larger than rlimit returns EFBIG
124 $XFS_IO_PROG -c "truncate 128k" $testdir/file
126 # need a wrapper so the "File size limit exceeded" error can be filtered
129 $XFS_IO_PROG -f -c "copy_range -l 32k -s 0 -d 16m $testdir/file" $testdir/copy
132 ulimit -f $((8 * 1024))
134 do_rlimit_copy 2>&1 | grep -o "File size limit exceeded"