generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 528
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 528
6 #
7 # Make sure that regular fallocate functions work ok when the realtime extent
8 # size is and isn't a power of 2.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick rw realtime
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         _scratch_unmount >> $seqres.full 2>&1
18         test -e "$rtdev" && losetup -d $rtdev >> $seqres.full 2>&1
19         rm -f $tmp.* $TEST_DIR/$seq.rtvol
20 }
21
22 # Import common functions.
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs xfs
27 _require_loop
28 _require_command "$FILEFRAG_PROG" filefrag
29 _require_xfs_io_command "fpunch"
30 _require_xfs_io_command "fzero"
31 _require_xfs_io_command "fcollapse"
32 _require_xfs_io_command "finsert"
33 # Note that we don't _require_realtime because we synthesize a rt volume
34 # below.  This also means we cannot run the post-test check.
35 _require_scratch_nocheck
36
37 log() {
38         echo "$@" | tee -a $seqres.full
39 }
40
41 mk_file() {
42         local file="$1"
43         local rextsize="$2"
44
45         $XFS_IO_PROG -f \
46                 -c "pwrite -S 0x57 -b $rextsize 0 $rextsize" \
47                 -c "pwrite -S 0x58 -b $rextsize $rextsize $rextsize" \
48                 -c "pwrite -S 0x59 -b $rextsize $((rextsize * 2)) $rextsize" \
49                 -c fsync \
50                 "$file" >> $seqres.full
51 }
52
53 check_file() {
54         $FILEFRAG_PROG -v "$1" >> $seqres.full
55         od -tx1 -Ad -c "$1" >> $seqres.full
56         md5sum "$1" | _filter_scratch | tee -a $seqres.full
57 }
58
59 test_ops() {
60         local rextsize=$1
61         local sz=$((rextsize * 3))
62         local unaligned_sz=65536
63         local unaligned_off=$((rextsize * 2 + unaligned_sz))
64         local lunaligned_sz=$((rextsize * 2))
65         local lunaligned_off=$unaligned_sz
66
67         log "Format rtextsize=$rextsize"
68         _scratch_unmount
69         _scratch_mkfs -r extsize=$rextsize >> $seqres.full
70         _try_scratch_mount || \
71                 _notrun "Could not mount rextsize=$rextsize with synthetic rt volume"
72
73         # Force all files to be realtime files
74         _xfs_force_bdev realtime $SCRATCH_MNT
75
76         log "Test regular write, rextsize=$rextsize"
77         mk_file $SCRATCH_MNT/write $rextsize
78         check_file $SCRATCH_MNT/write
79
80         log "Test aligned falloc, rextsize=$rextsize"
81         $XFS_IO_PROG -f -c "falloc 0 $sz" $SCRATCH_MNT/falloc >> $seqres.full
82         check_file $SCRATCH_MNT/falloc
83
84         log "Test aligned fcollapse, rextsize=$rextsize"
85         mk_file $SCRATCH_MNT/collapse $rextsize
86         $XFS_IO_PROG -f -c "fcollapse $rextsize $rextsize" $SCRATCH_MNT/collapse >> $seqres.full
87         check_file $SCRATCH_MNT/collapse
88
89         log "Test aligned finsert, rextsize=$rextsize"
90         mk_file $SCRATCH_MNT/insert $rextsize
91         $XFS_IO_PROG -f -c "finsert $rextsize $rextsize" $SCRATCH_MNT/insert >> $seqres.full
92         check_file $SCRATCH_MNT/insert
93
94         log "Test aligned fzero, rextsize=$rextsize"
95         mk_file $SCRATCH_MNT/zero $rextsize
96         $XFS_IO_PROG -f -c "fzero $rextsize $rextsize" $SCRATCH_MNT/zero >> $seqres.full
97         check_file $SCRATCH_MNT/zero
98
99         log "Test aligned fpunch, rextsize=$rextsize"
100         mk_file $SCRATCH_MNT/punch $rextsize
101         $XFS_IO_PROG -f -c "fpunch $rextsize $rextsize" $SCRATCH_MNT/punch >> $seqres.full
102         check_file $SCRATCH_MNT/punch
103
104         log "Test unaligned falloc, rextsize=$rextsize"
105         $XFS_IO_PROG -f -c "falloc $unaligned_off $unaligned_sz" $SCRATCH_MNT/ufalloc >> $seqres.full
106         check_file $SCRATCH_MNT/ufalloc
107
108         log "Test unaligned fcollapse, rextsize=$rextsize"
109         mk_file $SCRATCH_MNT/ucollapse $rextsize
110         $XFS_IO_PROG -f -c "fcollapse $unaligned_off $unaligned_sz" $SCRATCH_MNT/ucollapse >> $seqres.full
111         check_file $SCRATCH_MNT/ucollapse
112
113         log "Test unaligned finsert, rextsize=$rextsize"
114         mk_file $SCRATCH_MNT/uinsert $rextsize
115         $XFS_IO_PROG -f -c "finsert $unaligned_off $unaligned_sz" $SCRATCH_MNT/uinsert >> $seqres.full
116         check_file $SCRATCH_MNT/uinsert
117
118         log "Test unaligned fzero, rextsize=$rextsize"
119         mk_file $SCRATCH_MNT/uzero $rextsize
120         $XFS_IO_PROG -f -c "fzero $unaligned_off $unaligned_sz" $SCRATCH_MNT/uzero >> $seqres.full
121         check_file $SCRATCH_MNT/uzero
122
123         log "Test unaligned fpunch, rextsize=$rextsize"
124         mk_file $SCRATCH_MNT/upunch $rextsize
125         $XFS_IO_PROG -f -c "fpunch $unaligned_off $unaligned_sz" $SCRATCH_MNT/upunch >> $seqres.full
126         check_file $SCRATCH_MNT/upunch
127
128         log "Test large unaligned fzero, rextsize=$rextsize"
129         mk_file $SCRATCH_MNT/luzero $rextsize
130         $XFS_IO_PROG -f -c "fzero $lunaligned_off $lunaligned_sz" $SCRATCH_MNT/luzero >> $seqres.full
131         check_file $SCRATCH_MNT/luzero
132
133         log "Test large unaligned fpunch, rextsize=$rextsize"
134         mk_file $SCRATCH_MNT/lpunch $rextsize
135         $XFS_IO_PROG -f -c "fpunch $lunaligned_off $lunaligned_sz" $SCRATCH_MNT/lpunch >> $seqres.full
136         check_file $SCRATCH_MNT/lpunch
137
138         log "Remount and compare"
139         _scratch_cycle_mount
140         check_file $SCRATCH_MNT/write
141         check_file $SCRATCH_MNT/falloc
142         check_file $SCRATCH_MNT/collapse
143         check_file $SCRATCH_MNT/insert
144         check_file $SCRATCH_MNT/zero
145         check_file $SCRATCH_MNT/punch
146         check_file $SCRATCH_MNT/ufalloc
147         check_file $SCRATCH_MNT/ucollapse
148         check_file $SCRATCH_MNT/uinsert
149         check_file $SCRATCH_MNT/uzero
150         check_file $SCRATCH_MNT/upunch
151         check_file $SCRATCH_MNT/luzero
152         check_file $SCRATCH_MNT/lpunch
153
154         log "Check everything, rextsize=$rextsize"
155         _check_scratch_fs
156 }
157
158 echo "Create fake rt volume"
159 $XFS_IO_PROG -f -c "truncate 400m" $TEST_DIR/$seq.rtvol
160 rtdev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
161
162 echo "Make sure synth rt volume works"
163 export USE_EXTERNAL=yes
164 export SCRATCH_RTDEV=$rtdev
165 _scratch_mkfs > $seqres.full
166 _try_scratch_mount || \
167         _notrun "Could not mount with synthetic rt volume"
168
169 # power of two
170 test_ops 262144
171
172 # not a power of two
173 test_ops 327680
174
175 # success, all done
176 status=0
177 exit