generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 155
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. 155
6 #
7 # Ensure that CoW on all copies of a file reflinked N times increases block count
8 #   - Record fs block usage (0)
9 #   - Create a file and some reflink copies
10 #   - Record fs block usage (1)
11 #   - CoW some blocks of the copies
12 #   - Record fs block usage (2)
13 #   - CoW all the rest of the blocks of the copies
14 #   - Compare fs block usage to (2), (1), and (0)
15 #
16 # The main difference from generic/154 is that we use zero range to execute CoW.
17 #
18 . ./common/preamble
19 _begin_fstest auto quick clone zero
20
21 # Override the default cleanup function.
22 _cleanup()
23 {
24     cd /
25     rm -rf $tmp.* $testdir
26 }
27
28 # Import common functions.
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _require_test_reflink
34 _require_cp_reflink
35 _require_xfs_io_command "fzero"
36 _require_odirect
37
38 testdir=$TEST_DIR/test-$seq
39 rm -rf $testdir
40 mkdir $testdir
41
42 echo "Create the original file blocks"
43 blksz="$(_get_block_size $testdir)"
44 blks=2000
45 margin='15%'
46 sz=$((blksz * blks))
47 free_blocks0=$(stat -f $testdir -c '%f')
48 nr=4
49 filesize=$((blksz * nr))
50 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
51 _test_cycle_mount
52
53 echo "Create the reflink copies"
54 for i in `seq 2 $nr`; do
55         _cp_reflink $testdir/file1 $testdir/file$i
56 done
57 _test_cycle_mount
58 free_blocks1=$(stat -f $testdir -c '%f')
59
60 echo "Rewrite some of the blocks"
61 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file2 >> $seqres.full
62 _pwrite_byte 0x63 0 $((sz / 2)) $testdir/file3 -d >> $seqres.full
63 _mwrite_byte 0x64 $((sz / 2)) $((sz / 2)) $sz $testdir/file4 >> $seqres.full
64 _test_cycle_mount
65 free_blocks2=$(stat -f $testdir -c '%f')
66
67 echo "Rewrite all the files"
68 _pwrite_byte 0x62 0 $sz $testdir/file2 -d >> $seqres.full
69 _mwrite_byte 0x63 0 $sz $sz $testdir/file3 >> $seqres.full
70 $XFS_IO_PROG -f -c "fzero 0 $sz" $testdir/file4 >> $seqres.full
71 _test_cycle_mount
72 free_blocks3=$(stat -f $testdir -c '%f')
73
74 echo "Rewrite the original file"
75 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
76 _test_cycle_mount
77 free_blocks4=$(stat -f $testdir -c '%f')
78 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
79
80 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
81
82 _within_tolerance "free blocks after partially CoWing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
83
84 _within_tolerance "free blocks after CoWing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
85
86 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
87
88 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
89
90 # success, all done
91 status=0
92 exit