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