]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/trim/trim.kshlib
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright (c) 2019 by Tim Chase. All rights reserved.
15 # Copyright (c) 2019 Lawrence Livermore National Security, LLC.
18 .
$STF_SUITE/tests
/functional
/cli_root
/zpool_trim
/zpool_trim.kshlib
21 # Get the actual size on disk for the provided file.
25 typeset rval
=$
(du
--block-size 1048576 -s "$1" |
awk '{print $1}')
30 # Get the number of trim IOs issued for the pool (ind or agg).
34 typeset pool
="${1-:$TESTPOOL}"
35 typeset
type="${2-:ind}"
38 # Sum the ind or agg columns of the trim request size histogram.
41 rval
=$
(zpool iostat
-pr $pool |
awk \
42 '$1 ~ /[0-9].*/ { sum += $12 } END { print sum }')
46 rval
=$
(zpool iostat
-pr $pool |
awk \
47 '$1 ~ /[0-9].*/ { sum += $13 } END { print sum }')
51 log_fail
"Type must be 'ind' or 'agg'"
57 # Verify that trim IOs were send to devices in the pool.
59 function verify_trim_io
61 typeset pool
="${1:-$TESTPOOL}"
62 typeset
type="${2:-ind}"
63 typeset min_trim_ios
=${3:-100}
66 ios
=$
(get_trim_io
$pool $type)
67 if [[ $ios -ge $min_trim_ios ]]; then
68 log_note
"Issued $ios $type trim IOs for pool $pool"
70 log_fail
"Too few trim IOs issued $ios/$min_trim_ios"
75 # Run N txgs which should be enough to trim the entire pool.
77 function wait_trim_io
# pool type txgs
79 typeset pool
="${1-:$TESTPOOL}"
80 typeset
type="${2-:ind}"
83 typeset stop_time
=$
(( $
(date +%s
) + $timeout ))
86 while [[ $i -lt $txgs ]]; do
87 if [ "$(date +%s)" -ge $stop_time ]; then
88 log_fail
"Exceeded trim time limit of ${timeout}s"
96 typeset ios
=$
(get_trim_io
$pool $type)
97 log_note
"Waited for $txgs txgs, $ios $type TRIM IOs"
101 # Verify that file vdevs against a target value.
103 function verify_vdevs
# op size vdevs
110 for vdev
in $vdevs; do
111 typeset size
=$
(get_size_mb
$vdev)
112 if test $size $tgt_op $tgt_size; then
113 log_note
"Success $vdev is $size MB which is $tgt_op" \
116 log_fail
"Failure $vdev is $size MB which is not" \
117 "$tgt_op than $tgt_size MB"