Skip to content

Commit 207202c

Browse files
chrislongrosbehlendorf
authored andcommitted
ZTS: fix trim test portability for FreeBSD
Replace GNU-specific du flags (--block-size, -B1) and dd conv=nocreat with POSIX compatible commands. Move -O flag before pool name in zpool create to align with FreeBSD's strict POSIX getopt(). Relax vdev size thresholds in trim_config to account for ZFS-on-ZFS overhead. Add sync_pool before zpool trim -w to ensure freed blocks are committed before trimming. Skip zpool_trim_partial, zpool_trim_verify_trimmed, trim_config, and autotrim_config on FreeBSD where trim does not reclaim space on file vdevs stored on a ZFS filesystem within the test framework. Tested on FreeBSD 16.0-CURRENT: 26 PASS, 4 SKIP, 0 FAIL. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Christos Longros <chris.longros@gmail.com> Closes #18398
1 parent 7f9a480 commit 207202c

7 files changed

Lines changed: 40 additions & 16 deletions

File tree

tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
DISK1=${DISKS%% *}
4141
DISK2="$(echo $DISKS | cut -d' ' -f2)"
4242

43-
log_must zpool create -f $TESTPOOL mirror $DISK1 $DISK2 -O recordsize=4k
43+
log_must zpool create -f -O recordsize=4k $TESTPOOL mirror $DISK1 $DISK2
4444
sync_and_rewrite_some_data_a_few_times $TESTPOOL
4545

4646
log_must zpool trim -r 1 $TESTPOOL $DISK1

tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_partial.ksh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
# 5. Run 'zpool trim' to perform a full TRIM.
3636
# 6. Verify the disk is less than 10% of its original size.
3737

38+
# On FreeBSD, manual 'zpool trim' does not reclaim space on file
39+
# vdevs stored on a ZFS filesystem within the test framework.
40+
if is_freebsd; then
41+
log_unsupported "Manual trim on file vdevs not supported on FreeBSD"
42+
fi
43+
3844
function cleanup
3945
{
4046
if poolexists $TESTPOOL; then
@@ -69,19 +75,19 @@ log_must zpool create -O compression=off $TESTPOOL "$LARGEFILE"
6975
log_must mkfile $(( floor(LARGESIZE * 0.80) )) /$TESTPOOL/file
7076
sync_all_pools
7177

72-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
78+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
7379
log_must test $new_size -le $LARGESIZE
7480
log_must test $new_size -gt $(( floor(LARGESIZE * 0.70) ))
7581

7682
# Expand the pool to create new unallocated metaslabs.
7783
log_must zpool export $TESTPOOL
78-
log_must dd if=/dev/urandom of=$LARGEFILE conv=notrunc,nocreat \
84+
log_must dd if=/dev/urandom of=$LARGEFILE conv=notrunc \
7985
seek=$((LARGESIZE / (1024 * 1024))) bs=$((1024 * 1024)) \
8086
count=$((3 * LARGESIZE / (1024 * 1024)))
8187
log_must zpool import -d $TESTDIR $TESTPOOL
8288
log_must zpool online -e $TESTPOOL "$LARGEFILE"
8389

84-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
90+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
8591
log_must test $new_size -gt $((4 * floor(LARGESIZE * 0.70) ))
8692

8793
# Perform a partial trim, we expect it to skip most of the new metaslabs
@@ -90,25 +96,23 @@ log_must set_tunable64 TRIM_METASLAB_SKIP 1
9096
log_must zpool trim $TESTPOOL
9197
log_must set_tunable64 TRIM_METASLAB_SKIP 0
9298

93-
sync_all_pools
9499
while [[ "$(trim_progress $TESTPOOL $LARGEFILE)" -lt "100" ]]; do
95100
sleep 0.5
96101
done
97102

98-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
103+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
99104
log_must test $new_size -gt $LARGESIZE
100105

101106
# Perform a full trim, all metaslabs will be trimmed the pool vdev
102107
# size will be reduced but not down to its original size due to the
103108
# space usage of the new metaslabs.
104109
log_must zpool trim $TESTPOOL
105110

106-
sync_all_pools
107111
while [[ "$(trim_progress $TESTPOOL $LARGEFILE)" -lt "100" ]]; do
108112
sleep 0.5
109113
done
110114

111-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
115+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
112116
log_must test $new_size -le $(( 2 * LARGESIZE))
113117
log_must test $new_size -gt $(( floor(LARGESIZE * 0.70) ))
114118

tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ DISK2="$(echo $DISKS | cut -d' ' -f2)"
4040
DISK3="$(echo $DISKS | cut -d' ' -f3)"
4141

4242
log_must zpool list -v
43-
log_must zpool create -f $TESTPOOL $DISK1 $DISK2 $DISK3 -O recordsize=4k
43+
log_must zpool create -f -O recordsize=4k $TESTPOOL $DISK1 $DISK2 $DISK3
4444
sync_and_rewrite_some_data_a_few_times $TESTPOOL
4545

4646
log_must zpool trim -r 1 $TESTPOOL $DISK1

tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_verify_trimmed.ksh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
# 3. Trim the pool and verify the file vdev is again sparse.
3535
#
3636

37+
# On FreeBSD, manual 'zpool trim' does not reclaim space on file
38+
# vdevs stored on a ZFS filesystem within the test framework.
39+
if is_freebsd; then
40+
log_unsupported "Manual trim on file vdevs not supported on FreeBSD"
41+
fi
42+
3743
function cleanup
3844
{
3945
if poolexists $TESTPOOL; then
@@ -59,24 +65,24 @@ log_must mkdir "$TESTDIR"
5965
log_must truncate -s $LARGESIZE "$LARGEFILE"
6066
log_must zpool create $TESTPOOL "$LARGEFILE"
6167

62-
original_size=$(du -B1 "$LARGEFILE" | cut -f1)
68+
original_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
6369

6470
log_must zpool initialize $TESTPOOL
6571

6672
while [[ "$(initialize_progress $TESTPOOL $LARGEFILE)" -lt "100" ]]; do
6773
sleep 0.5
6874
done
6975

70-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
71-
log_must within_tolerance $new_size $LARGESIZE $((128 * 1024 * 1024))
76+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
77+
log_must within_tolerance $new_size $LARGESIZE $((200 * 1024 * 1024))
7278

7379
log_must zpool trim $TESTPOOL
7480

7581
while [[ "$(trim_progress $TESTPOOL $LARGEFILE)" -lt "100" ]]; do
7682
sleep 0.5
7783
done
7884

79-
new_size=$(du -B1 "$LARGEFILE" | cut -f1)
85+
new_size=$(du -k "$LARGEFILE" | awk '{print $1 * 1024}')
8086
log_must within_tolerance $new_size $original_size $((128 * 1024 * 1024))
8187

8288
log_pass "Trimmed appropriate amount of disk space"

tests/zfs-tests/tests/functional/trim/autotrim_config.ksh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040

4141
verify_runnable "global"
4242

43+
# On FreeBSD, autotrim does not reclaim space on file vdevs stored
44+
# on a ZFS filesystem within the test framework.
45+
if is_freebsd; then
46+
log_unsupported "Autotrim on file vdevs not supported on FreeBSD"
47+
fi
48+
4349
log_assert "Set 'autotrim=on' verify pool disks were trimmed"
4450

4551
function cleanup

tests/zfs-tests/tests/functional/trim/trim.kshlib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
function get_size_mb
2525
{
26-
du --block-size 1048576 -s "$1" | cut -f1
26+
du -m -s "$1" | cut -f1
2727
}
2828

2929
#

tests/zfs-tests/tests/functional/trim/trim_config.ksh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040

4141
verify_runnable "global"
4242

43+
# On FreeBSD, manual trim does not reclaim space on file vdevs stored
44+
# on a ZFS filesystem within the test framework.
45+
if is_freebsd; then
46+
log_unsupported "Manual trim on file vdevs not supported on FreeBSD"
47+
fi
48+
4349
log_assert "Run 'zpool trim' verify pool disks were trimmed"
4450

4551
function cleanup
@@ -68,8 +74,8 @@ log_must set_tunable64 TRIM_TXG_BATCH 8
6874
typeset vdev_min_ms_count=$(get_tunable VDEV_MIN_MS_COUNT)
6975
log_must set_tunable64 VDEV_MIN_MS_COUNT 32
7076

71-
typeset VDEV_MAX_MB=$(( floor(4 * MINVDEVSIZE * 0.75 / 1024 / 1024) ))
72-
typeset VDEV_MIN_MB=$(( floor(4 * MINVDEVSIZE * 0.30 / 1024 / 1024) ))
77+
typeset VDEV_MAX_MB=$(( floor(4 * MINVDEVSIZE * 0.65 / 1024 / 1024) ))
78+
typeset VDEV_MIN_MB=$(( floor(4 * MINVDEVSIZE * 0.40 / 1024 / 1024) ))
7379

7480
for type in "" "mirror" "raidz2" "draid"; do
7581

@@ -100,7 +106,9 @@ for type in "" "mirror" "raidz2" "draid"; do
100106

101107
# Remove the file, issue trim, verify the vdevs are now sparse.
102108
log_must rm /$TESTPOOL/file
109+
sync_pool $TESTPOOL
103110
log_must timeout 120 zpool trim -w $TESTPOOL
111+
sync_all_pools true
104112
verify_vdevs "-le" "$VDEV_MIN_MB" $VDEVS
105113

106114
log_must zpool destroy $TESTPOOL

0 commit comments

Comments
 (0)