generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 432
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Netapp, Inc. All rights reserved.
4 #
5 # FS QA Test No. 432
6 #
7 # Tests vfs_copy_file_range():
8 #   - Copy a file
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
12 . ./common/preamble
13 _begin_fstest auto quick copy_range
14
15 # get standard environment
16 . common/filter
17
18 # real QA test starts here
19 _supported_fs generic
20
21 _require_xfs_io_command "copy_range"
22 _require_test
23
24 testdir=$TEST_DIR/test-$seq
25 rm -rf $testdir
26 mkdir $testdir
27
28 echo "Create the original file and then copy"
29 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0    1000' $testdir/file >> $seqres.full 2>&1
30 $XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
31 $XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
32 $XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
33 $XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
34 $XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
35 cmp $testdir/file  $testdir/copy
36 echo "Original md5sums:"
37 md5sum $testdir/{file,copy} | _filter_test_dir
38
39 echo "Swap beginning and end of original file"
40 $XFS_IO_PROG -f -c "copy_range -s 4000 -l 1000 $testdir/file" "$testdir/copy"
41 $XFS_IO_PROG -f -c "copy_range -d 4000 -l 1000 $testdir/file" "$testdir/copy"
42 cmp -n 1000 $testdir/file $testdir/copy 4000
43 cmp -n 3000 $testdir/file $testdir/copy 1000 1000
44 cmp -n 1000 $testdir/file $testdir/copy 0 4000
45 echo "md5sums after swapping beginning and end:"
46 md5sum $testdir/{file,copy} | _filter_test_dir
47
48 echo "Swap middle parts of original file"
49 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 1000 $testdir/file" "$testdir/copy"
50 $XFS_IO_PROG -f -c "copy_range -s 3000 -d 1000 -l 1000 $testdir/file" "$testdir/copy"
51 cmp -n 1000 $testdir/file $testdir/copy 4000
52 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
53 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
54 cmp -n 1000 $testdir/file $testdir/copy 1000 3000
55 cmp -n 1000 $testdir/file $testdir/copy 0 4000
56 echo "md5sums after swapping middle:"
57 md5sum $testdir/{file,copy} | _filter_test_dir
58
59 echo "Copy tail of original file onto copy"
60 $XFS_IO_PROG -f -c "copy_range -s 1000 -d 3000 -l 4000 $testdir/file" "$testdir/copy"
61 cmp -n 1000 $testdir/file $testdir/copy 4000
62 cmp -n 1000 $testdir/file $testdir/copy 3000 1000
63 cmp -n 1000 $testdir/file $testdir/copy 2000 2000
64 cmp -n 4000 $testdir/file $testdir/copy 1000 3000
65 echo "md5sums after copying tail:"
66 md5sum $testdir/{file,copy} | _filter_test_dir
67
68 #success, all done
69 status=0
70 exit