generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 188
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. 188
6 #
7 # Ensuring that copy on write in direct-io mode works when the CoW
8 # range originally covers multiple extents, some unwritten, some not.
9 #   - Create a file and fallocate a second file.
10 #   - Reflink the odd blocks of the first file into the second file.
11 #   - directio CoW across the halfway mark, starting with the unwritten extent.
12 #   - Check that the files are now different where we say they're different.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick clone
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.* $testdir
22 }
23
24 # Import common functions.
25 . ./common/filter
26 . ./common/reflink
27
28 # real QA test starts here
29 _require_scratch_reflink
30 _require_xfs_io_command "falloc"
31 _require_odirect
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_unwritten $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 "directio CoW across the transition"
53 cowoff=$((filesize / 4))
54 cowsz=$((filesize / 2))
55 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
56 _pwrite_byte 0x63 $cowoff $cowsz $testdir/file3.chk >> $seqres.full
57 _scratch_cycle_mount
58
59 echo "Compare files"
60 md5sum $testdir/file1 | _filter_scratch
61 md5sum $testdir/file3 | _filter_scratch
62 md5sum $testdir/file3.chk | _filter_scratch
63
64 # success, all done
65 status=0
66 exit