Commit | Line | Data |
---|---|---|
191d1d1a BVA |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2018 Western Digital Corporation or its affiliates. | |
4 | # | |
5 | # This file is released under the GPL. | |
6 | ||
7 | usage() { | |
8 | echo "Usage: $(basename "$0") [-d] [-e] [-r] [-v] [-t <test>] <SMR drive device node>" | |
9 | } | |
10 | ||
11 | max() { | |
12 | if [ "$1" -gt "$2" ]; then | |
13 | echo "$1" | |
14 | else | |
15 | echo "$2" | |
16 | fi | |
17 | } | |
18 | ||
19 | min() { | |
20 | if [ "$1" -lt "$2" ]; then | |
21 | echo "$1" | |
22 | else | |
23 | echo "$2" | |
24 | fi | |
25 | } | |
26 | ||
27 | set_io_scheduler() { | |
28 | local dev=$1 sched=$2 | |
29 | ||
30 | [ -e "/sys/block/$dev" ] || return $? | |
31 | if [ -e "/sys/block/$dev/mq" ]; then | |
32 | case "$sched" in | |
33 | noop) sched=none;; | |
34 | deadline) sched=mq-deadline;; | |
35 | esac | |
36 | else | |
37 | case "$sched" in | |
38 | none) sched=noop;; | |
39 | mq-deadline) sched=deadline;; | |
40 | esac | |
41 | fi | |
42 | ||
43 | echo "$sched" >"/sys/block/$dev/queue/scheduler" | |
44 | } | |
45 | ||
46 | check_read() { | |
47 | local read | |
48 | ||
49 | read=$(fio_read <"${logfile}.${test_number}") | |
50 | echo "read: $read <> $1" >> "${logfile}.${test_number}" | |
51 | [ "$read" = "$1" ] | |
52 | } | |
53 | ||
54 | check_written() { | |
55 | local written | |
56 | ||
57 | written=$(fio_written <"${logfile}.${test_number}") | |
58 | echo "written: $written <> $1" >> "${logfile}.${test_number}" | |
59 | [ "$written" = "$1" ] | |
60 | } | |
61 | ||
62 | # Compare the reset count from the log file with reset count $2 using operator | |
63 | # $1 (=, -ge, -gt, -le, -lt). | |
64 | check_reset_count() { | |
65 | local reset_count | |
66 | ||
67 | reset_count=$(fio_reset_count <"${logfile}.${test_number}") | |
68 | echo "reset_count: test $reset_count $1 $2" >> "${logfile}.${test_number}" | |
69 | eval "[ '$reset_count' '$1' '$2' ]" | |
70 | } | |
71 | ||
72 | # Whether or not $1 (/dev/...) is a SCSI device. | |
73 | is_scsi_device() { | |
74 | local d f | |
75 | ||
76 | d=$(basename "$dev") | |
77 | for f in /sys/class/scsi_device/*/device/block/"$d"; do | |
78 | [ -e "$f" ] && return 0 | |
79 | done | |
80 | return 1 | |
81 | } | |
82 | ||
83 | run_fio() { | |
84 | local fio | |
85 | ||
86 | fio=$(dirname "$0")/../../fio | |
87 | ||
88 | { echo; echo "fio $*"; echo; } >>"${logfile}.${test_number}" | |
89 | ||
90 | "${dynamic_analyzer[@]}" "$fio" "$@" | |
91 | } | |
92 | ||
93 | run_one_fio_job() { | |
94 | local r | |
95 | ||
96 | r=$(((RANDOM << 16) | RANDOM)) | |
97 | run_fio --name="$dev" --filename="$dev" "$@" --randseed="$r" \ | |
98 | --thread=1 --direct=1 | |
99 | } | |
100 | ||
101 | # Run fio on the first four sequential zones of the disk. | |
102 | run_fio_on_seq() { | |
103 | local opts=() | |
104 | ||
105 | opts+=("--offset=$((first_sequential_zone_sector * 512))") | |
106 | opts+=("--size=$((4 * zone_size))" "--zonemode=zbd") | |
107 | if [ -z "$is_zbd" ]; then | |
108 | opts+=("--zonesize=${zone_size}") | |
109 | fi | |
110 | run_one_fio_job "${opts[@]}" "$@" | |
111 | } | |
112 | ||
113 | # Check whether buffered writes are refused. | |
114 | test1() { | |
115 | run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K \ | |
116 | --size="${zone_size}" \ | |
117 | --zonemode=zbd --zonesize="${zone_size}" 2>&1 | | |
118 | tee -a "${logfile}.${test_number}" | | |
119 | grep -q 'Using direct I/O is mandatory for writing to ZBD drives' | |
120 | local fio_rc=${PIPESTATUS[0]} grep_rc=${PIPESTATUS[2]} | |
121 | case "$fio_rc" in | |
122 | 0|1) ;; | |
123 | *) return "$fio_rc" | |
124 | esac | |
125 | if [ -n "$is_zbd" ]; then | |
126 | [ "$grep_rc" = 0 ] | |
127 | else | |
128 | [ "$grep_rc" != 0 ] | |
129 | fi | |
130 | } | |
131 | ||
132 | # Block size exceeds zone size. | |
133 | test2() { | |
134 | local bs off opts=() rc | |
135 | ||
136 | off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512)) | |
137 | bs=$((2 * zone_size)) | |
138 | opts+=("--name=job1" "--filename=$dev" "--rw=write" "--direct=1") | |
139 | opts+=("--zonemode=zbd" "--offset=$off" "--bs=$bs" "--size=$bs") | |
140 | if [ -z "$is_zbd" ]; then | |
141 | opts+=("--zonesize=${zone_size}") | |
142 | fi | |
143 | run_fio "${opts[@]}" 2>&1 | | |
144 | tee -a "${logfile}.${test_number}" | | |
145 | grep -q 'No I/O performed' | |
146 | } | |
147 | ||
148 | # Run fio against an empty zone. This causes fio to report "No I/O performed". | |
149 | test3() { | |
150 | local off opts=() rc | |
151 | ||
152 | off=$((first_sequential_zone_sector * 512 + 128 * zone_size)) | |
153 | size=$((zone_size)) | |
154 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) | |
155 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=4K") | |
156 | opts+=("--size=$size" "--zonemode=zbd") | |
157 | opts+=("--ioengine=psync" "--rw=read" "--direct=1" "--thread=1") | |
158 | if [ -z "$is_zbd" ]; then | |
159 | opts+=("--zonesize=${zone_size}") | |
160 | fi | |
161 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
162 | grep -q "No I/O performed" "${logfile}.${test_number}" | |
163 | rc=$? | |
164 | if [ -n "$is_zbd" ]; then | |
165 | [ $rc = 0 ] | |
166 | else | |
167 | [ $rc != 0 ] | |
168 | fi | |
169 | } | |
170 | ||
171 | # Run fio with --read_beyond_wp=1 against an empty zone. | |
172 | test4() { | |
173 | local off opts=() | |
174 | ||
175 | off=$((first_sequential_zone_sector * 512 + 129 * zone_size)) | |
176 | size=$((zone_size)) | |
177 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) | |
178 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--bs=$size") | |
179 | opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1") | |
180 | opts+=("--ioengine=psync" "--rw=read" "--direct=1" "--disable_lat=1") | |
181 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") | |
182 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
183 | check_read $size || return $? | |
184 | } | |
185 | ||
186 | # Sequential write to sequential zones. | |
187 | test5() { | |
188 | local size | |
189 | ||
190 | size=$((4 * zone_size)) | |
191 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write \ | |
192 | --bs="$(max $((zone_size / 64)) "$logical_block_size")"\ | |
193 | --do_verify=1 --verify=md5 \ | |
194 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
195 | check_written $size || return $? | |
196 | check_read $size || return $? | |
197 | } | |
198 | ||
199 | # Sequential read from sequential zones. Must be run after test5. | |
200 | test6() { | |
201 | local size | |
202 | ||
203 | size=$((4 * zone_size)) | |
204 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=read \ | |
205 | --bs="$(max $((zone_size / 64)) "$logical_block_size")"\ | |
206 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
207 | check_read $size || return $? | |
208 | } | |
209 | ||
210 | # Random write to sequential zones, libaio, queue depth 1. | |
211 | test7() { | |
212 | local size=$((zone_size)) | |
213 | ||
214 | run_fio_on_seq --ioengine=libaio --iodepth=1 --rw=randwrite \ | |
215 | --bs="$(min 16384 "${zone_size}")" \ | |
216 | --do_verify=1 --verify=md5 --size="$size" \ | |
217 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
218 | check_written $size || return $? | |
219 | check_read $size || return $? | |
220 | } | |
221 | ||
222 | # Random write to sequential zones, libaio, queue depth 64. | |
223 | test8() { | |
224 | local size | |
225 | ||
226 | size=$((4 * zone_size)) | |
227 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite \ | |
228 | --bs="$(min 16384 "${zone_size}")" \ | |
229 | --do_verify=1 --verify=md5 \ | |
230 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
231 | check_written $size || return $? | |
232 | check_read $size || return $? | |
233 | } | |
234 | ||
235 | # Random write to sequential zones, sg, queue depth 1. | |
236 | test9() { | |
237 | local size | |
238 | ||
239 | if ! is_scsi_device "$dev"; then | |
240 | echo "$dev is not a SCSI device" >>"${logfile}.${test_number}" | |
241 | return 0 | |
242 | fi | |
243 | ||
244 | size=$((4 * zone_size)) | |
245 | run_fio_on_seq --ioengine=sg --iodepth=1 --rw=randwrite --bs=16K \ | |
246 | --do_verify=1 --verify=md5 \ | |
247 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
248 | check_written $size || return $? | |
249 | check_read $size || return $? | |
250 | } | |
251 | ||
252 | # Random write to sequential zones, sg, queue depth 64. | |
253 | test10() { | |
254 | local size | |
255 | ||
256 | if ! is_scsi_device "$dev"; then | |
257 | echo "$dev is not a SCSI device" >>"${logfile}.${test_number}" | |
258 | return 0 | |
259 | fi | |
260 | ||
261 | size=$((4 * zone_size)) | |
262 | run_fio_on_seq --ioengine=sg --iodepth=64 --rw=randwrite --bs=16K \ | |
263 | --do_verify=1 --verify=md5 \ | |
264 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
265 | check_written $size || return $? | |
266 | check_read $size || return $? | |
267 | } | |
268 | ||
269 | # Random write to sequential zones, libaio, queue depth 64, random block size. | |
270 | test11() { | |
271 | local size | |
272 | ||
273 | size=$((4 * zone_size)) | |
274 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite \ | |
275 | --bsrange=4K-64K --do_verify=1 --verify=md5 \ | |
276 | --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $? | |
277 | check_written $size || return $? | |
278 | check_read $size || return $? | |
279 | } | |
280 | ||
281 | # Random write to sequential zones, libaio, queue depth 64, max 1 open zone. | |
282 | test12() { | |
283 | local size | |
284 | ||
285 | size=$((8 * zone_size)) | |
286 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ | |
287 | --max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \ | |
288 | --debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $? | |
289 | check_written $size || return $? | |
290 | check_read $size || return $? | |
291 | } | |
292 | ||
293 | # Random write to sequential zones, libaio, queue depth 64, max 4 open zones. | |
294 | test13() { | |
295 | local size | |
296 | ||
297 | size=$((8 * zone_size)) | |
298 | run_fio_on_seq --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ | |
299 | --max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \ | |
300 | --debug=zbd \ | |
301 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
302 | check_written $size || return $? | |
303 | check_read $size || return $? | |
304 | } | |
305 | ||
306 | # Random write to conventional zones. | |
307 | test14() { | |
308 | local size | |
309 | ||
310 | size=$((16 * 2**20)) # 20 MB | |
311 | if [ $size -gt $((first_sequential_zone_sector * 512)) ]; then | |
312 | echo "$dev does not have enough sequential zones" \ | |
313 | >>"${logfile}.${test_number}" | |
314 | return 0 | |
315 | fi | |
316 | run_one_fio_job --ioengine=libaio --iodepth=64 --rw=randwrite --bs=16K \ | |
317 | --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \ | |
318 | --verify=md5 --size=$size \ | |
319 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
320 | check_written $((size)) || return $? | |
321 | check_read $((size)) || return $? | |
322 | } | |
323 | ||
324 | # Sequential read on a mix of empty and full zones. | |
325 | test15() { | |
326 | local i off size | |
327 | ||
328 | for ((i=0;i<4;i++)); do | |
329 | [ -n "$is_zbd" ] && | |
330 | reset_zone "$dev" $((first_sequential_zone_sector + | |
331 | i*sectors_per_zone)) | |
332 | done | |
333 | off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512)) | |
334 | size=$((2 * zone_size)) | |
335 | run_one_fio_job --ioengine=psync --rw=write --bs=$((zone_size / 16))\ | |
336 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ | |
337 | --size=$size >>"${logfile}.${test_number}" 2>&1 || | |
338 | return $? | |
339 | check_written $size || return $? | |
340 | off=$((first_sequential_zone_sector * 512)) | |
341 | size=$((4 * zone_size)) | |
342 | run_one_fio_job --ioengine=psync --rw=read --bs=$((zone_size / 16)) \ | |
343 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ | |
344 | --size=$((size)) >>"${logfile}.${test_number}" 2>&1 || | |
345 | return $? | |
346 | if [ -n "$is_zbd" ]; then | |
347 | check_read $((size / 2)) | |
348 | else | |
349 | check_read $size | |
350 | fi | |
351 | } | |
352 | ||
353 | # Random read on a mix of empty and full zones. Must be run after test15. | |
354 | test16() { | |
355 | local off size | |
356 | ||
357 | off=$((first_sequential_zone_sector * 512)) | |
358 | size=$((4 * zone_size)) | |
359 | run_one_fio_job --ioengine=libaio --iodepth=64 --rw=randread --bs=16K \ | |
360 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off \ | |
361 | --size=$size >>"${logfile}.${test_number}" 2>&1 || return $? | |
362 | check_read $size || return $? | |
363 | } | |
364 | ||
365 | # Random reads and writes in the last zone. | |
366 | test17() { | |
367 | local io off read size written | |
368 | ||
369 | off=$(((disk_size / zone_size - 1) * zone_size)) | |
370 | size=$((disk_size - off)) | |
371 | # Overwrite the last zone to avoid that reading from that zone fails. | |
372 | if [ -n "$is_zbd" ]; then | |
373 | reset_zone "$dev" $((off / 512)) || return $? | |
374 | fi | |
375 | run_one_fio_job --ioengine=psync --rw=write --offset="$off" \ | |
376 | --zonemode=zbd --zonesize="${zone_size}" \ | |
377 | --bs="$zone_size" --size="$zone_size" \ | |
378 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
379 | check_written "$zone_size" || return $? | |
380 | run_one_fio_job --ioengine=libaio --iodepth=8 --rw=randrw --bs=4K \ | |
381 | --zonemode=zbd --zonesize="${zone_size}" \ | |
382 | --offset=$off --loops=2 --norandommap=1\ | |
383 | >>"${logfile}.${test_number}" 2>&1 || return $? | |
384 | written=$(fio_written <"${logfile}.${test_number}") | |
385 | read=$(fio_read <"${logfile}.${test_number}") | |
386 | io=$((written + read)) | |
387 | echo "Total number of bytes read and written: $io <> $size" \ | |
388 | >>"${logfile}.${test_number}" | |
389 | [ $io = $((size * 2)) ]; | |
390 | } | |
391 | ||
392 | # Out-of-range zone reset threshold and frequency parameters. | |
393 | test18() { | |
394 | run_fio_on_seq --zone_reset_threshold=-1 |& | |
395 | tee -a "${logfile}.${test_number}" | | |
396 | grep -q 'value out of range' || return $? | |
397 | } | |
398 | ||
399 | test19() { | |
400 | run_fio_on_seq --zone_reset_threshold=2 |& | |
401 | tee -a "${logfile}.${test_number}" | | |
402 | grep -q 'value out of range' || return $? | |
403 | } | |
404 | ||
405 | test20() { | |
406 | run_fio_on_seq --zone_reset_threshold=.4:.6 |& | |
407 | tee -a "${logfile}.${test_number}" | | |
408 | grep -q 'the list exceeding max length' || return $? | |
409 | } | |
410 | ||
411 | test21() { | |
412 | run_fio_on_seq --zone_reset_frequency=-1 |& | |
413 | tee -a "${logfile}.${test_number}" | | |
414 | grep -q 'value out of range' || return $? | |
415 | } | |
416 | ||
417 | test22() { | |
418 | run_fio_on_seq --zone_reset_frequency=2 |& | |
419 | tee -a "${logfile}.${test_number}" | | |
420 | grep -q 'value out of range' || return $? | |
421 | } | |
422 | ||
423 | test23() { | |
424 | run_fio_on_seq --zone_reset_frequency=.4:.6 |& | |
425 | tee -a "${logfile}.${test_number}" | | |
426 | grep -q 'the list exceeding max length' || return $? | |
427 | } | |
428 | ||
429 | test24() { | |
430 | local bs loops=9 size=$((zone_size)) | |
431 | ||
432 | bs=$(min $((256*1024)) "$zone_size") | |
433 | run_fio_on_seq --ioengine=psync --rw=write --bs="$bs" --size=$size \ | |
434 | --loops=$loops \ | |
435 | --zone_reset_frequency=.01 --zone_reset_threshold=.90 \ | |
436 | >> "${logfile}.${test_number}" 2>&1 || return $? | |
437 | check_written $((size * loops)) || return $? | |
438 | check_reset_count -eq 8 || | |
439 | check_reset_count -eq 9 || | |
440 | check_reset_count -eq 10 || return $? | |
441 | } | |
442 | ||
443 | # Multiple non-overlapping sequential write jobs for the same drive. | |
444 | test25() { | |
445 | local i opts=() | |
446 | ||
447 | for ((i=0;i<16;i++)); do | |
448 | [ -n "$is_zbd" ] && | |
449 | reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone)) | |
450 | done | |
451 | for ((i=0;i<16;i++)); do | |
452 | opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1") | |
453 | opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))") | |
454 | opts+=("--size=$zone_size" "--ioengine=psync" "--rw=write" "--bs=16K") | |
455 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1") | |
456 | done | |
457 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
458 | } | |
459 | ||
460 | write_to_first_seq_zone() { | |
461 | local loops=4 r | |
462 | ||
463 | r=$(((RANDOM << 16) | RANDOM)) | |
464 | run_fio --name="$dev" --filename="$dev" --ioengine=psync --rw="$1" \ | |
465 | --thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \ | |
466 | --offset=$((first_sequential_zone_sector * 512)) \ | |
467 | "--size=$zone_size" --loops=$loops --randseed="$r" \ | |
468 | --zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \ | |
469 | --gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $? | |
470 | check_written $((loops * zone_size)) || return $? | |
471 | } | |
472 | ||
473 | # Overwrite the first sequential zone four times sequentially. | |
474 | test26() { | |
475 | write_to_first_seq_zone write | |
476 | } | |
477 | ||
478 | # Overwrite the first sequential zone four times using random writes. | |
479 | test27() { | |
480 | write_to_first_seq_zone randwrite | |
481 | } | |
482 | ||
483 | # Multiple overlapping random write jobs for the same drive. | |
484 | test28() { | |
485 | local i jobs=16 off opts | |
486 | ||
487 | off=$((first_sequential_zone_sector * 512 + 64 * zone_size)) | |
488 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) | |
489 | opts=("--debug=zbd") | |
490 | for ((i=0;i<jobs;i++)); do | |
491 | opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K") | |
492 | opts+=("--size=$zone_size" "--ioengine=psync" "--rw=randwrite") | |
493 | opts+=("--thread=1" "--direct=1" "--zonemode=zbd") | |
494 | opts+=("--zonesize=${zone_size}" "--group_reporting=1") | |
495 | done | |
496 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
497 | check_written $((jobs * zone_size)) || return $? | |
498 | check_reset_count -eq $jobs || | |
499 | check_reset_count -eq $((jobs - 1)) || | |
500 | return $? | |
501 | } | |
502 | ||
503 | # Multiple overlapping random write jobs for the same drive and with a limited | |
504 | # number of open zones. | |
505 | test29() { | |
506 | local i jobs=16 off opts=() | |
507 | ||
508 | off=$((first_sequential_zone_sector * 512 + 64 * zone_size)) | |
509 | size=$((16*zone_size)) | |
510 | [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512)) | |
511 | opts=("--debug=zbd") | |
512 | for ((i=0;i<jobs;i++)); do | |
513 | opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K") | |
514 | opts+=("--size=$size" "--io_size=$zone_size" "--thread=1") | |
515 | opts+=("--ioengine=psync" "--rw=randwrite" "--direct=1") | |
516 | opts+=("--max_open_zones=4" "--group_reporting=1") | |
517 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") | |
518 | done | |
519 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
520 | check_written $((jobs * zone_size)) || return $? | |
521 | } | |
522 | ||
523 | # Random reads and writes across the entire disk for 30s. | |
524 | test30() { | |
525 | local off | |
526 | ||
527 | off=$((first_sequential_zone_sector * 512)) | |
528 | run_one_fio_job --ioengine=libaio --iodepth=8 --rw=randrw \ | |
529 | --bs="$(max $((zone_size / 128)) "$logical_block_size")"\ | |
530 | --zonemode=zbd --zonesize="${zone_size}" --offset=$off\ | |
531 | --loops=2 --time_based --runtime=30s --norandommap=1\ | |
532 | >>"${logfile}.${test_number}" 2>&1 | |
533 | } | |
534 | ||
535 | # Random reads across all sequential zones for 30s. This is not only a fio | |
536 | # test but also allows to verify the performance of a drive. | |
537 | test31() { | |
538 | local bs inc nz off opts size | |
539 | ||
540 | # Start with writing 128 KB to 128 sequential zones. | |
541 | bs=128K | |
542 | nz=128 | |
543 | # shellcheck disable=SC2017 | |
544 | inc=$(((disk_size - (first_sequential_zone_sector * 512)) / (nz * zone_size) | |
545 | * zone_size)) | |
546 | opts=() | |
547 | for ((off = first_sequential_zone_sector * 512; off < disk_size; | |
548 | off += inc)); do | |
549 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--io_size=$bs") | |
550 | opts+=("--bs=$bs" "--size=$zone_size" "--ioengine=libaio") | |
551 | opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0") | |
552 | opts+=("--zonemode=zbd" "--zonesize=${zone_size}") | |
553 | done | |
554 | "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 | |
555 | # Next, run the test. | |
556 | off=$((first_sequential_zone_sector * 512)) | |
557 | size=$((disk_size - off)) | |
558 | opts=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size") | |
559 | opts+=("--bs=$bs" "--ioengine=psync" "--rw=randread" "--direct=1") | |
560 | opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd") | |
561 | opts+=("--zonesize=${zone_size}") | |
562 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
563 | } | |
564 | ||
565 | # Random writes across all sequential zones. This is not only a fio test but | |
566 | # also allows to verify the performance of a drive. | |
567 | test32() { | |
568 | local off opts=() size | |
569 | ||
570 | off=$((first_sequential_zone_sector * 512)) | |
571 | size=$((disk_size - off)) | |
572 | opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size") | |
573 | opts+=("--bs=128K" "--ioengine=psync" "--rw=randwrite" "--direct=1") | |
574 | opts+=("--thread=1" "--time_based" "--runtime=30") | |
575 | opts+=("--max_open_zones=$max_open_zones" "--zonemode=zbd") | |
576 | opts+=("--zonesize=${zone_size}") | |
577 | run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $? | |
578 | } | |
579 | ||
580 | # Write to sequential zones with a block size that is not a divisor of the | |
581 | # zone size. | |
582 | test33() { | |
583 | local bs io_size size | |
584 | ||
585 | size=$((2 * zone_size)) | |
586 | io_size=$((5 * zone_size)) | |
587 | bs=$((3 * zone_size / 4)) | |
588 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write --size=$size \ | |
589 | --io_size=$io_size --bs=$bs \ | |
590 | >> "${logfile}.${test_number}" 2>&1 || return $? | |
591 | check_written $(((io_size + bs - 1) / bs * bs)) || return $? | |
592 | } | |
593 | ||
594 | # Write to sequential zones with a block size that is not a divisor of the | |
595 | # zone size and with data verification enabled. | |
596 | test34() { | |
597 | local size | |
598 | ||
599 | size=$((2 * zone_size)) | |
600 | run_fio_on_seq --ioengine=psync --iodepth=1 --rw=write --size=$size \ | |
601 | --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \ | |
602 | >> "${logfile}.${test_number}" 2>&1 && return 1 | |
603 | grep -q 'not a divisor of' "${logfile}.${test_number}" | |
604 | } | |
605 | ||
606 | # Test 1/4 for the I/O boundary rounding code: $size < $zone_size. | |
607 | test35() { | |
608 | local bs off io_size size | |
609 | ||
610 | off=$(((first_sequential_zone_sector + 1) * 512)) | |
611 | size=$((zone_size - 2 * 512)) | |
612 | bs=$((zone_size / 4)) | |
613 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ | |
614 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ | |
615 | --zonemode=zbd --zonesize="${zone_size}" \ | |
616 | >> "${logfile}.${test_number}" 2>&1 && return 1 | |
617 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" | |
618 | } | |
619 | ||
620 | # Test 2/4 for the I/O boundary rounding code: $size < $zone_size. | |
621 | test36() { | |
622 | local bs off io_size size | |
623 | ||
624 | off=$(((first_sequential_zone_sector) * 512)) | |
625 | size=$((zone_size - 512)) | |
626 | bs=$((zone_size / 4)) | |
627 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ | |
628 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ | |
629 | --zonemode=zbd --zonesize="${zone_size}" \ | |
630 | >> "${logfile}.${test_number}" 2>&1 && return 1 | |
631 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" | |
632 | } | |
633 | ||
634 | # Test 3/4 for the I/O boundary rounding code: $size > $zone_size. | |
635 | test37() { | |
636 | local bs off size | |
637 | ||
638 | if [ "$first_sequential_zone_sector" = 0 ]; then | |
639 | off=0 | |
640 | else | |
641 | off=$(((first_sequential_zone_sector - 1) * 512)) | |
642 | fi | |
643 | size=$((zone_size + 2 * 512)) | |
644 | bs=$((zone_size / 4)) | |
645 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ | |
646 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ | |
647 | --zonemode=zbd --zonesize="${zone_size}" \ | |
648 | >> "${logfile}.${test_number}" 2>&1 | |
649 | check_written $((zone_size)) || return $? | |
650 | } | |
651 | ||
652 | # Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size | |
653 | test38() { | |
654 | local bs off size | |
655 | ||
656 | size=$((logical_block_size)) | |
657 | off=$((disk_size - logical_block_size)) | |
658 | bs=$((logical_block_size)) | |
659 | run_one_fio_job --offset=$off --size=$size --ioengine=psync --iodepth=1 \ | |
660 | --rw=write --do_verify=1 --verify=md5 --bs=$bs \ | |
661 | --zonemode=zbd --zonesize="${zone_size}" \ | |
662 | >> "${logfile}.${test_number}" 2>&1 && return 1 | |
663 | grep -q 'io_size must be at least one zone' "${logfile}.${test_number}" | |
664 | } | |
665 | ||
666 | # Read one block from a block device. | |
667 | read_one_block() { | |
668 | local bs | |
669 | ||
670 | bs=$((logical_block_size)) | |
671 | run_one_fio_job --rw=read --ioengine=psync --bs=$bs --size=$bs "$@" 2>&1 | | |
672 | tee -a "${logfile}.${test_number}" | |
673 | } | |
674 | ||
675 | # Check whether fio accepts --zonemode=none for zoned block devices. | |
676 | test39() { | |
677 | [ -n "$is_zbd" ] || return 0 | |
678 | read_one_block --zonemode=none >/dev/null || return $? | |
679 | check_read $((logical_block_size)) || return $? | |
680 | } | |
681 | ||
682 | # Check whether fio accepts --zonemode=strided for zoned block devices. | |
683 | test40() { | |
684 | local bs | |
685 | ||
686 | bs=$((logical_block_size)) | |
687 | [ -n "$is_zbd" ] || return 0 | |
688 | read_one_block --zonemode=strided | | |
689 | grep -q 'fio: --zonesize must be specified when using --zonemode=strided' || | |
690 | return $? | |
691 | read_one_block --zonemode=strided --zonesize=$bs >/dev/null || return $? | |
692 | check_read $bs || return $? | |
693 | } | |
694 | ||
695 | # Check whether fio checks the zone size for zoned block devices. | |
696 | test41() { | |
697 | [ -n "$is_zbd" ] || return 0 | |
698 | read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) | | |
699 | grep -q 'job parameter zonesize.*does not match disk zone size' | |
700 | } | |
701 | ||
702 | # Check whether fio handles --zonesize=0 correctly for regular block devices. | |
703 | test42() { | |
704 | [ -n "$is_zbd" ] && return 0 | |
705 | read_one_block --zonemode=zbd --zonesize=0 | | |
706 | grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd' | |
707 | } | |
708 | ||
709 | # Check whether fio handles --zonesize=1 correctly. | |
710 | test43() { | |
711 | read_one_block --zonemode=zbd --zonesize=1 | | |
712 | grep -q 'zone size must be at least 512 bytes for --zonemode=zbd' | |
713 | } | |
714 | ||
715 | # Check whether fio handles --zonemode=none --zonesize=1 correctly. | |
716 | test44() { | |
717 | read_one_block --zonemode=none --zonesize=1 | | |
718 | grep -q 'fio: --zonemode=none and --zonesize are not compatible' | |
719 | } | |
720 | ||
721 | test45() { | |
722 | local bs i | |
723 | ||
724 | [ -z "$is_zbd" ] && return 0 | |
725 | bs=$((logical_block_size)) | |
726 | run_one_fio_job --ioengine=psync --iodepth=1 --rw=randwrite --bs=$bs\ | |
727 | --offset=$((first_sequential_zone_sector * 512)) \ | |
728 | --size="$zone_size" --do_verify=1 --verify=md5 2>&1 | | |
729 | tee -a "${logfile}.${test_number}" | | |
730 | grep -q "fio: first I/O failed. If .* is a zoned block device, consider --zonemode=zbd" | |
731 | } | |
732 | ||
733 | tests=() | |
734 | dynamic_analyzer=() | |
735 | reset_all_zones= | |
736 | ||
737 | while [ "${1#-}" != "$1" ]; do | |
738 | case "$1" in | |
739 | -d) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=drd" | |
740 | "--show-confl-seg=no"); | |
741 | shift;; | |
742 | -e) dynamic_analyzer=(valgrind "--read-var-info=yes" "--tool=helgrind"); | |
743 | shift;; | |
744 | -r) reset_all_zones=1; shift;; | |
745 | -t) tests+=("$2"); shift; shift;; | |
746 | -v) dynamic_analyzer=(valgrind "--read-var-info=yes"); | |
747 | shift;; | |
748 | --) shift; break;; | |
749 | esac | |
750 | done | |
751 | ||
752 | if [ $# != 1 ]; then | |
753 | usage | |
754 | exit 1 | |
755 | fi | |
756 | ||
757 | # shellcheck source=functions | |
758 | source "$(dirname "$0")/functions" || exit $? | |
759 | ||
760 | dev=$1 | |
761 | realdev=$(readlink -f "$dev") | |
762 | basename=$(basename "$realdev") | |
763 | disk_size=$(($(<"/sys/block/$basename/size")*512)) | |
764 | logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size") | |
765 | case "$(<"/sys/class/block/$basename/queue/zoned")" in | |
766 | host-managed|host-aware) | |
767 | is_zbd=true | |
768 | if ! result=($(first_sequential_zone "$dev")); then | |
769 | echo "Failed to determine first sequential zone" | |
770 | exit 1 | |
771 | fi | |
772 | first_sequential_zone_sector=${result[0]} | |
773 | sectors_per_zone=${result[1]} | |
774 | zone_size=$((sectors_per_zone * 512)) | |
775 | if ! max_open_zones=$(max_open_zones "$dev"); then | |
776 | echo "Failed to determine maximum number of open zones" | |
777 | exit 1 | |
778 | fi | |
779 | echo "First sequential zone starts at sector $first_sequential_zone_sector; zone size: $((zone_size >> 20)) MB" | |
780 | set_io_scheduler "$basename" deadline || exit $? | |
781 | if [ -n "$reset_all_zones" ]; then | |
782 | reset_zone "$dev" -1 | |
783 | fi | |
784 | ;; | |
785 | *) | |
786 | first_sequential_zone_sector=$(((disk_size / 2) & | |
787 | (logical_block_size - 1))) | |
788 | zone_size=$(max 65536 "$logical_block_size") | |
789 | sectors_per_zone=$((zone_size / 512)) | |
790 | max_open_zones=128 | |
791 | set_io_scheduler "$basename" none || exit $? | |
792 | ;; | |
793 | esac | |
794 | ||
795 | if [ "${#tests[@]}" = 0 ]; then | |
796 | for ((i=1;i<=45;i++)); do | |
797 | tests+=("$i") | |
798 | done | |
799 | fi | |
800 | ||
801 | logfile=$0.log | |
802 | ||
803 | rc=0 | |
804 | for test_number in "${tests[@]}"; do | |
805 | rm -f "${logfile}.${test_number}" | |
806 | echo -n "Running test $test_number ... " | |
807 | if eval "test$test_number"; then | |
808 | status="PASS" | |
809 | else | |
810 | status="FAIL" | |
811 | rc=1 | |
812 | fi | |
813 | echo "$status" | |
814 | echo "$status" >> "${logfile}.${test_number}" | |
815 | done | |
816 | ||
817 | exit $rc |