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
34 _require_xfs_io_command "copy_range"
37 testdir=$TEST_DIR/test-$seq
42 echo "Create the original file and then copy"
43 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 1000' $testdir/file >> $seqres.full 2>&1
44 $XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
45 $XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
46 $XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
47 $XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
48 $XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
49 cmp $testdir/file $testdir/copy
50 echo "Original md5sums:"
51 md5sum $testdir/{file,copy} | _filter_test_dir
53 echo "Swap beginning and end of original file"
54 $XFS_IO_PROG -f -c "copy_range -s 4000 -l 1000 $testdir/file" "$testdir/copy"
55 $XFS_IO_PROG -f -c "copy_range -d 4000 -l 1000 $testdir/file" "$testdir/copy"
56 cmp -n 1000 $testdir/file $testdir/copy 4000
57 cmp -n 3000 $testdir/file $testdir/copy 1000 1000
58 cmp -n 1000 $testdir/file $testdir/copy 0 4000
59 echo "md5sums after swapping beginning and end:"
60 md5sum $testdir/{file,copy} | _filter_test_dir
62 echo "Swap middle parts of original file"
63 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 1000 $testdir/file" "$testdir/copy"
64 $XFS_IO_PROG -f -c "copy_range -s 3000 -d 1000 -l 1000 $testdir/file" "$testdir/copy"
65 cmp -n 1000 $testdir/file $testdir/copy 4000
66 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
67 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
68 cmp -n 1000 $testdir/file $testdir/copy 1000 3000
69 cmp -n 1000 $testdir/file $testdir/copy 0 4000
70 echo "md5sums after swapping middle:"
71 md5sum $testdir/{file,copy} | _filter_test_dir
73 echo "Copy tail of original file onto copy"
74 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 4000 $testdir/file" "$testdir/copy"
75 cmp -n 1000 $testdir/file $testdir/copy 4000
76 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
77 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
78 cmp -n 4000 $testdir/file $testdir/copy 1000 3000
79 echo "md5sums after copying tail:"
80 md5sum $testdir/{file,copy} | _filter_test_dir