generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
13 _begin_fstest auto quick copy_range
14
15 _register_cleanup "_cleanup" BUS
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20         cd /
21         rm -rf $tmp.*
22         [ -z "$loopdev" ] || _destroy_loop_device $loopdev
23 }
24
25 # Import common functions.
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs generic
30
31 _require_test
32 _require_loop
33 # for mkfifo
34 _require_mknod
35
36 #
37 # This test effectively requires xfs_io with these commits
38 #  2a42470b xfs_io: copy_file_range length is a size_t
39 #  1a05efba io: open pipes in non-blocking mode
40 #
41 # Without those commits test will hang on old kernel when copying
42 # very large size and when copying from a pipe.
43 #
44 # We require a new xfs_io feature of passing an open file as the
45 # copy source, as an indication that the test can run without hanging
46 # with large size argument and to avoid opening pipe in blocking mode.
47 #
48 # Test both basic copy_range and copy_range -f availability
49 _require_xfs_io_command "copy_range"
50 _require_xfs_io_command "copy_range" "-f"
51
52 testdir="$TEST_DIR/test-$seq"
53 rm -rf $testdir
54 mkdir $testdir
55
56 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 128k" $testdir/file >> $seqres.full 2>&1
57
58 echo source range overlaps destination range in same file returns EINVAL
59 $XFS_IO_PROG -f -c "copy_range -s 32k -d 48k -l 32k $testdir/file" $testdir/file
60
61 echo
62 echo destination file O_RDONLY returns EBADF
63 $XFS_IO_PROG -f -r -c "copy_range -l 32k $testdir/file" $testdir/copy
64
65 echo
66 echo destination file O_APPEND returns EBADF
67 $XFS_IO_PROG -f -a -c "copy_range -l 32k $testdir/file" $testdir/copy
68
69 echo
70 echo source/destination as directory returns EISDIR
71 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir
72 $XFS_IO_PROG -f -c "copy_range -l 32k $testdir" $testdir/copy
73
74 echo
75 echo source/destination as blkdev returns EINVAL
76 $XFS_IO_PROG -f -c "truncate 128k" $testdir/img >> $seqres.full 2>&1
77 loopdev=`_create_loop_device $testdir/img`
78 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $loopdev
79 $XFS_IO_PROG -f -c "copy_range -l 32k $loopdev" $testdir/copy
80 _destroy_loop_device $loopdev
81 loopdev=
82
83 echo
84 echo source/destination as chardev returns EINVAL
85 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" /dev/null
86 $XFS_IO_PROG -f -c "copy_range -l 32k /dev/zero" $testdir/copy
87
88 echo
89 echo source/destination as FIFO returns EINVAL
90 mkfifo $testdir/fifo
91 $XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $testdir/fifo
92 # Pass input pipe as non-blocking open file to avoid old xfs_io (<4.20)
93 # opening the pipe in blocking mode and causing the test to hang
94 $XFS_IO_PROG -r -n -f -c "open $testdir/copy" -C "copy_range -l 32k -f 0" $testdir/fifo
95
96 max_off=$((8 * 2**60 - 65536 - 1))
97 min_off=65537
98
99 echo
100 echo length beyond 8EiB wraps around 0 returns EOVERFLOW
101 $XFS_IO_PROG -f -c "copy_range -l 10e -s $max_off $testdir/file" $testdir/copy
102 $XFS_IO_PROG -f -c "copy_range -l 10e -d $max_off $testdir/file" $testdir/copy
103
104 echo
105 echo source range beyond 8TiB returns 0
106 $XFS_IO_PROG -c "copy_range -s $max_off -l $min_off -d 0 $testdir/file" $testdir/copy
107
108 echo
109 echo destination range beyond 8TiB returns EFBIG
110 $XFS_IO_PROG -c "copy_range -l $min_off -s 0 -d $max_off $testdir/file" $testdir/copy
111
112 echo
113 echo destination larger than rlimit returns EFBIG
114 rm -f $testdir/copy
115 $XFS_IO_PROG -c "truncate 128k" $testdir/file
116
117 # need a wrapper so the "File size limit exceeded" error can be filtered
118 do_rlimit_copy()
119 {
120         $XFS_IO_PROG -f -c "copy_range -l 32k -s 0 -d 16m $testdir/file" $testdir/copy
121 }
122
123 ulimit -f $((8 * 1024))
124 ulimit -c 0
125 do_rlimit_copy 2>&1 | grep -o "File size limit exceeded"
126 ulimit -f unlimited
127
128 # success, all done
129 status=0
130 exit