2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Netapp, Inc. All rights reserved.
7 # Tests vfs_copy_file_range():
9 # - Use copy to swap data at beginning and end
10 # - Use copy to swap data in the middle
11 # - Use copy to simultaneously overwrite and append to destination file
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 15
27 # get standard environment
31 # real QA test starts here
35 _require_xfs_io_command "copy_range"
38 testdir=$TEST_DIR/test-$seq
43 echo "Create the original file and then copy"
44 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 1000' $testdir/file >> $seqres.full 2>&1
45 $XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
46 $XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
47 $XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
48 $XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
49 $XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
50 cmp $testdir/file $testdir/copy
51 echo "Original md5sums:"
52 md5sum $testdir/{file,copy} | _filter_test_dir
54 echo "Swap beginning and end of original file"
55 $XFS_IO_PROG -f -c "copy_range -s 4000 -l 1000 $testdir/file" "$testdir/copy"
56 $XFS_IO_PROG -f -c "copy_range -d 4000 -l 1000 $testdir/file" "$testdir/copy"
57 cmp -n 1000 $testdir/file $testdir/copy 4000
58 cmp -n 3000 $testdir/file $testdir/copy 1000 1000
59 cmp -n 1000 $testdir/file $testdir/copy 0 4000
60 echo "md5sums after swapping beginning and end:"
61 md5sum $testdir/{file,copy} | _filter_test_dir
63 echo "Swap middle parts of original file"
64 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 1000 $testdir/file" "$testdir/copy"
65 $XFS_IO_PROG -f -c "copy_range -s 3000 -d 1000 -l 1000 $testdir/file" "$testdir/copy"
66 cmp -n 1000 $testdir/file $testdir/copy 4000
67 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
68 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
69 cmp -n 1000 $testdir/file $testdir/copy 1000 3000
70 cmp -n 1000 $testdir/file $testdir/copy 0 4000
71 echo "md5sums after swapping middle:"
72 md5sum $testdir/{file,copy} | _filter_test_dir
74 echo "Copy tail of original file onto copy"
75 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 4000 $testdir/file" "$testdir/copy"
76 cmp -n 1000 $testdir/file $testdir/copy 4000
77 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
78 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
79 cmp -n 4000 $testdir/file $testdir/copy 1000 3000
80 echo "md5sums after copying tail:"
81 md5sum $testdir/{file,copy} | _filter_test_dir