2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Netapp, Inc. All rights reserved.
7 # Tests vfs_copy_file_range():
9 # - Copy beginning of original to new file
10 # - Copy middle of original to a new file
11 # - Copy end of original to new file
12 # - Copy middle of original to a new file, creating a hole
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment
32 # real QA test starts here
36 _require_xfs_io_command "copy_range"
39 testdir=$TEST_DIR/test-$seq
44 echo "Create the original file and then copy"
45 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 1000' $testdir/file >> $seqres.full 2>&1
46 $XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
47 $XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
48 $XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
49 $XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
50 $XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
51 cmp $testdir/file $testdir/copy
52 echo "Original md5sums:"
53 md5sum $testdir/{file,copy} | _filter_test_dir
55 echo "Copy beginning of original file"
56 $XFS_IO_PROG -f -c "copy_range -l 1000 $testdir/file" "$testdir/beginning"
57 cmp -n 1000 $testdir/file $testdir/beginning
58 echo "md5sums after copying beginning:"
59 md5sum $testdir/{file,beginning} | _filter_test_dir
61 echo "Copy middle of original file"
62 $XFS_IO_PROG -f -c "copy_range -s 1000 -l 3000 $testdir/file" "$testdir/middle"
63 cmp -n 3000 $testdir/file $testdir/middle 1000
64 echo "md5sums after copying middle:"
65 md5sum $testdir/{file,middle} | _filter_test_dir
67 echo "Copy end of original file"
68 $XFS_IO_PROG -f -c "copy_range -s 4000 -l 1000 $testdir/file" "$testdir/end"
69 cmp -n 1000 $testdir/file $testdir/end 4000
70 echo "md5sums after copying end:"
71 md5sum $testdir/{file,end} | _filter_test_dir
73 echo "Copy beyond end of original file"
74 $XFS_IO_PROG -f -c "copy_range -s 4000 -l 2000 $testdir/file" "$testdir/beyond"
75 cmp -n 1000 $testdir/file $testdir/beyond 4000
76 echo "md5sums after copying beyond:"
77 md5sum $testdir/{file,beyond} | _filter_test_dir
79 echo "Copy creates hole in target file"
80 $XFS_IO_PROG -f -c "copy_range -s 1000 -l 3000 -d 1000 $testdir/file" "$testdir/hole"
81 cmp -n 3000 $testdir/file $testdir/hole 1000 1000
82 echo "md5sums after creating hole:"
83 md5sum $testdir/{file,hole} | _filter_test_dir