generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 195
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. 195
6 #
7 # Ensuring that copy on write in buffered mode works when the CoW
8 # range originally covers multiple extents, some delalloc, some not.
9 #   - Create a file.
10 #   - Reflink the odd blocks of the first file into the second file.
11 #   - Buffered write the even blocks of the second file.
12 #   - CoW across the halfway mark, starting with the unwritten extent.
13 #   - Check that the files are now different where we say they're different.
14 #
15 . ./common/preamble
16 _begin_fstest auto quick clone
17
18 # Override the default cleanup function.
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $testdir
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30 _require_scratch_reflink
31 _require_xfs_io_command "falloc"
32
33 echo "Format and mount"
34 _scratch_mkfs > $seqres.full 2>&1
35 _scratch_mount >> $seqres.full 2>&1
36
37 testdir=$SCRATCH_MNT/test-$seq
38 mkdir $testdir
39
40 echo "Create the original files"
41 blksz=65536
42 nr=64
43 filesize=$((blksz * nr))
44 _weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
45 _scratch_cycle_mount
46
47 echo "Compare files"
48 md5sum $testdir/file1 | _filter_scratch
49 md5sum $testdir/file3 | _filter_scratch
50 md5sum $testdir/file3.chk | _filter_scratch
51
52 echo "CoW across the transition"
53 cowoff=$((filesize / 4))
54 cowsz=$((filesize / 2))
55 _weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
56 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
57 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
58 _scratch_cycle_mount
59
60 echo "Compare files"
61 md5sum $testdir/file1 | _filter_scratch
62 md5sum $testdir/file3 | _filter_scratch
63 md5sum $testdir/file3.chk | _filter_scratch
64
65 # success, all done
66 status=0
67 exit