generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 243
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. 243
6 #
7 # Reflink two large files and DIO CoW them in big chunks.
8 #
9 # This test is dependent on the system page size, so we cannot use md5 in
10 # the golden output; we can only compare to a check file.
11 #
12 . ./common/preamble
13 _begin_fstest auto clone
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_scratch_reflink
28 _require_cp_reflink
29 _require_odirect
30
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
34
35 testdir=$SCRATCH_MNT/test-$seq
36 mkdir $testdir
37
38 blksz=65536
39 nr=6400
40 filesize=$((blksz * nr))
41 bufnr=1280
42 bufsize=$((blksz * bufnr))
43
44 free_blocks=$(stat -f -c '%a' $testdir)
45 real_blksz=$(_get_block_size $testdir)
46 space_needed=$(((filesize * 3) * 5 / 4))
47 space_avail=$((free_blocks * real_blksz))
48 test $space_needed -gt $space_avail && _notrun "Not enough space. $space_avail < $space_needed"
49
50 echo "Create the original files"
51 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
52 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
53 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
54 _scratch_cycle_mount
55
56 echo "Compare files"
57 md5sum $testdir/file1 | _filter_scratch
58 md5sum $testdir/file2 | _filter_scratch
59 md5sum $testdir/file2.chk | _filter_scratch
60
61 echo "CoW and unmount"
62 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $testdir/file2 >> $seqres.full
63 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
64 _scratch_cycle_mount
65
66 echo "Compare files"
67 md5sum $testdir/file1 | _filter_scratch
68 md5sum $testdir/file2 | _filter_scratch
69 md5sum $testdir/file2.chk | _filter_scratch
70
71 # success, all done
72 status=0
73 exit