generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 179
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 179
6 #
7 # Ensure that unaligned punch-hole steps around reflinked ranges:
8 #   - Create a reflink clone of a file
9 #   - Perform an unaligned punch in the middle of the file.
10 #   - Check that the reflinked areas are still there.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone punch
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18     cd /
19     rm -rf $tmp.* $testdir
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/reflink
25
26 # real QA test starts here
27 _require_test_reflink
28 _require_cp_reflink
29 _require_xfs_io_command "fpunch"
30
31 testdir=$TEST_DIR/test-$seq
32 rm -rf $testdir
33 mkdir $testdir
34
35 echo "Create the original files"
36 blksz=65536
37 _pwrite_byte 0x61 0 $((blksz * 3)) $testdir/file1 >> $seqres.full
38
39 _cp_reflink $testdir/file1 $testdir/file2
40
41 _pwrite_byte 0x61 0 $((blksz * 3)) $testdir/file2.chk >> $seqres.full
42 _pwrite_byte 0x00 $((blksz - 17)) $((blksz + 17)) $testdir/file2.chk >> $seqres.full
43 _test_cycle_mount
44
45 md5sum $testdir/file1 | _filter_test_dir
46 md5sum $testdir/file2 | _filter_test_dir
47 md5sum $testdir/file2.chk | _filter_test_dir
48
49 c1=$(_md5_checksum $testdir/file1)
50 c2=$(_md5_checksum $testdir/file2)
51
52 test ${c1} = ${c2} || echo "file1 and file2 should match"
53
54 echo "fpunch files"
55 $XFS_IO_PROG -f -c "fpunch $((blksz - 17)) $((blksz + 17))" $testdir/file2
56 _test_cycle_mount
57
58 echo "Compare files"
59 md5sum $testdir/file1 | _filter_test_dir
60 md5sum $testdir/file2 | _filter_test_dir
61 md5sum $testdir/file2.chk | _filter_test_dir
62
63 c1=$(_md5_checksum $testdir/file1)
64 c2=$(_md5_checksum $testdir/file2)
65
66 test ${c1} != ${c2} || echo "file1 and file2 should not match"
67
68 echo "Compare against check files"
69 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
70
71 # success, all done
72 status=0
73 exit