generic/395: remove workarounds for wrong error codes
[xfstests-dev.git] / tests / generic / 564
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 564
6 #
7 # Exercise copy_file_range() syscall error conditions.
8 #
9 # This is a regression test for kernel commit:
10 #   96e6e8f4a68d ("vfs: add missing checks to copy_file_range")
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 7 15
20
21 _cleanup()
22 {
23         cd /
24         rm -rf $tmp.*
25         [ -z "$loopdev" ] || _destroy_loop_device $loopdev
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # real QA test starts here
33 _supported_fs generic
34
35 rm -f $seqres.full
36
37 _require_test
38 _require_loop
39 # for mkfifo
40 _require_mknod
41
42 #
43 # This test effectively requires xfs_io with these commits
44 #  2a42470b xfs_io: copy_file_range length is a size_t
45 #  1a05efba io: open pipes in non-blocking mode
46 #
47 # Without those commits test will hang on old kernel when copying
48 # very large size and when copying from a pipe.
49 #
50 # We require a new xfs_io feature of passing an open file as the
51 # copy source, as an indication that the test can run without hanging
52 # with large size argument and to avoid opening pipe in blocking mode.
53 #
54 # Test both basic copy_range and copy_range -f availability
55 _require_xfs_io_command "copy_range"
56 _require_xfs_io_command "copy_range" "-f"
57
58 testdir="$TEST_DIR/test-$seq"
59 rm -rf $testdir
60 mkdir $testdir
61
62 rm -f $seqres.full
63
64 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 128k" $testdir/file >> $seqres.full 2>&1
65
66 echo source range overlaps destination range in same file returns EINVAL
67 $XFS_IO_PROG -f -c "copy_range -s 32k -d 48k -l 32k $testdir/file" $testdir/file
68
69 echo
70 echo destination file O_RDONLY returns EBADF
71 $XFS_IO_PROG -f -r -c "copy_range -l 32k $testdir/file" $testdir/copy
72
73 echo
74 echo destination file O_APPEND returns EBADF
75 $XFS_IO_PROG -f -a -c "copy_range -l 32k $testdir/file" $testdir/copy
76
77 echo
78 echo source/destination as directory returns EISDIR
79 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir
80 $XFS_IO_PROG -f -c "copy_range -l 32k $testdir" $testdir/copy
81
82 echo
83 echo source/destination as blkdev returns EINVAL
84 $XFS_IO_PROG -f -c "truncate 128k" $testdir/img >> $seqres.full 2>&1
85 loopdev=`_create_loop_device $testdir/img`
86 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $loopdev
87 $XFS_IO_PROG -f -c "copy_range -l 32k $loopdev" $testdir/copy
88 _destroy_loop_device $loopdev
89 loopdev=
90
91 echo
92 echo source/destination as chardev returns EINVAL
93 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" /dev/null
94 $XFS_IO_PROG -f -c "copy_range -l 32k /dev/zero" $testdir/copy
95
96 echo
97 echo source/destination as FIFO returns EINVAL
98 mkfifo $testdir/fifo
99 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir/fifo
100 # Pass input pipe as non-blocking open file to avoid old xfs_io (<4.20)
101 # opening the pipe in blocking mode and causing the test to hang
102 $XFS_IO_PROG -r -n -f -c "open $testdir/copy" -C "copy_range -l 32k -f 0" $testdir/fifo
103
104 max_off=$((8 * 2**60 - 65536 - 1))
105 min_off=65537
106
107 echo
108 echo length beyond 8EiB wraps around 0 returns EOVERFLOW
109 $XFS_IO_PROG -f -c "copy_range -l 10e -s $max_off $testdir/file" $testdir/copy
110 $XFS_IO_PROG -f -c "copy_range -l 10e -d $max_off $testdir/file" $testdir/copy
111
112 echo
113 echo source range beyond 8TiB returns 0
114 $XFS_IO_PROG -c "copy_range -s $max_off -l $min_off -d 0 $testdir/file" $testdir/copy
115
116 echo
117 echo destination range beyond 8TiB returns EFBIG
118 $XFS_IO_PROG -c "copy_range -l $min_off -s 0 -d $max_off $testdir/file" $testdir/copy
119
120 echo
121 echo destination larger than rlimit returns EFBIG
122 rm -f $testdir/copy
123 $XFS_IO_PROG -c "truncate 128k" $testdir/file
124
125 # need a wrapper so the "File size limit exceeded" error can be filtered
126 do_rlimit_copy()
127 {
128         $XFS_IO_PROG -f -c "copy_range -l 32k -s 0 -d 16m $testdir/file" $testdir/copy
129 }
130
131 ulimit -f $((8 * 1024))
132 ulimit -c 0
133 do_rlimit_copy 2>&1 | grep -o "File size limit exceeded"
134 ulimit -f unlimited
135
136 # success, all done
137 status=0
138 exit