generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 218
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. 218
6 #
7 # See what happens if we CoW blocks 2-4 of a page's worth of blocks when the
8 # second block is a hole.
9 #
10 # This test is dependent on the system page size, so we cannot use md5 in
11 # the golden output; we can only compare to a check file.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick clone
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19     cd /
20     rm -rf $tmp.* $testdir
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26
27 # real QA test starts here
28 _require_scratch_reflink
29 _require_xfs_io_command "falloc"
30
31 pagesz=$(getconf PAGE_SIZE)
32 blksz=$((pagesz / 4))
33
34 echo "Format and mount"
35 _scratch_mkfs_blocksized $blksz > $seqres.full 2>&1
36 _scratch_mount >> $seqres.full 2>&1
37
38 testdir=$SCRATCH_MNT/test-$seq
39 mkdir $testdir
40
41 real_blksz=$(_get_file_block_size $testdir)
42 test $real_blksz != $blksz && _notrun "Failed to format with small blocksize."
43
44 echo "Create the original files"
45 _pwrite_byte 0x61 0 $pagesz $testdir/file1 >> $seqres.full
46
47 $XFS_IO_PROG -f -c "truncate $pagesz" $testdir/file2 >> $seqres.full
48 $XFS_IO_PROG -f -c "truncate $pagesz" $testdir/file2.chk >> $seqres.full
49
50 _reflink_range $testdir/file1 $blksz $testdir/file2 $((blksz * 2)) $blksz >> $seqres.full
51 _pwrite_byte 0x61 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
52 _scratch_cycle_mount
53
54 echo "Compare files"
55 ! cmp -s $testdir/file1 $testdir/file2 || _fail "file1 and file2 don't match."
56 cmp -s $testdir/file2 $testdir/file2.chk || _fail "file2 and file2.chk don't match."
57
58 echo "CoW and unmount"
59 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $testdir/file2 >> $seqres.full
60 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz + 17)) $((blksz * 3 - 34))" $testdir/file2.chk >> $seqres.full
61 _scratch_cycle_mount
62
63 echo "Compare files"
64 ! cmp -s $testdir/file1 $testdir/file2 || _fail "file1 and file2 don't match."
65 cmp -s $testdir/file2 $testdir/file2.chk || _fail "file2 and file2.chk don't match."
66
67 # success, all done
68 status=0
69 exit