generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 231
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 231
6 #
7 # Test recovery of unused CoW reservations:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Dirty a single byte on a number of CoW reservations in the second file.
10 # - Fsync to flush out the dirty pages.
11 # - Wait for the reclaim to run.
12 # - Write more and see how bad fragmentation is.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick clone
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20         cd /
21         test -n "$old_cowgc_interval" && \
22                 _xfs_set_cowgc_interval $old_cowgc_interval
23         rm -rf $tmp.*
24 }
25
26 # Import common functions.
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_fs xfs
32 _require_scratch_reflink
33 _require_cp_reflink
34 _require_xfs_io_command "cowextsize"
35 _require_xfs_io_command "falloc"
36 _require_xfs_io_command "fiemap"
37
38 old_cowgc_interval=$(_xfs_get_cowgc_interval)
39
40 echo "Format and mount"
41 _scratch_mkfs > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 blksz=65536
48 nr=64
49 filesize=$((blksz * nr))
50 bufnr=2
51 bufsize=$((blksz * bufnr))
52
53 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
54 real_blksz=$(_get_block_size $testdir)
55 internal_blks=$((filesize / real_blksz))
56
57 echo "Create the original files"
58 $XFS_IO_PROG -c "cowextsize $bufsize" $testdir
59 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
60 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
61 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
62 _scratch_cycle_mount
63
64 echo "Compare files"
65 md5sum $testdir/file1 | _filter_scratch
66 md5sum $testdir/file2 | _filter_scratch
67 md5sum $testdir/file2.chk | _filter_scratch
68
69 echo "CoW and leave leftovers"
70 _xfs_set_cowgc_interval 2
71 seq 2 2 $((nr - 1)) | while read f; do
72         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
73         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
74 done
75 sync
76
77 echo "Wait for CoW expiration"
78 sleep 3
79
80 echo "Allocate free space"
81 for i in $(seq 1 32); do
82         $XFS_IO_PROG -f -c "falloc 0 1" $testdir/junk.$i >> $seqres.full
83 done
84 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
85
86 echo "CoW and leave leftovers"
87 _xfs_set_cowgc_interval $old_cowgc_interval
88 seq 2 2 $((nr - 1)) | while read f; do
89         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
90         $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
91 done
92 sync
93
94 echo "Compare files"
95 md5sum $testdir/file1 | _filter_scratch
96 md5sum $testdir/file2 | _filter_scratch
97 md5sum $testdir/file2.chk | _filter_scratch
98
99 echo "Check extent counts"
100 old_extents=$(_count_extents $testdir/file1)
101 new_extents=$(_count_extents $testdir/file2)
102
103 echo "old extents: $old_extents" >> $seqres.full
104 echo "new extents: $new_extents" >> $seqres.full
105 echo "maximum extents: $internal_blks" >> $seqres.full
106 test $new_extents -le $((3 * nr / bufnr)) || echo "file2 more fragmented than expected"
107
108 # success, all done
109 status=0
110 exit