Skip to content

Commit

Permalink
ZTS: Enable punch-hole tests on FreeBSD
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ka Ho Ng <khng@FreeBSD.org>
Sponsored-by: The FreeBSD Foundation
Closes #12458
  • Loading branch information
khng300 authored and behlendorf committed Aug 30, 2021
1 parent f3bbeb9 commit c3cb57a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
4 changes: 4 additions & 0 deletions tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ tags = ['functional', 'delegate']
tests = ['exec_001_pos', 'exec_002_neg']
tags = ['functional', 'exec']

[tests/functional/fallocate]
tests = ['fallocate_punch-hole']
tags = ['functional', 'fallocate']

[tests/functional/features/async_destroy]
tests = ['async_destroy_001_pos']
tags = ['functional', 'features', 'async_destroy']
Expand Down
2 changes: 1 addition & 1 deletion tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ tests = ['events_001_pos', 'events_002_pos', 'zed_rc_filter', 'zed_fd_spill']
tags = ['functional', 'events']

[tests/functional/fallocate:Linux]
tests = ['fallocate_prealloc', 'fallocate_punch-hole']
tests = ['fallocate_prealloc']
tags = ['functional', 'fallocate']

[tests/functional/fault:Linux]
Expand Down
8 changes: 8 additions & 0 deletions tests/test-runner/bin/zts-report.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ fio_reason = 'Fio v2.3 or newer required'
#
trim_reason = 'DISKS must support discard (TRIM/UNMAP)'

#
# Some tests on FreeBSD require the fspacectl(2) system call and the
# truncate(1) utility supporting the -d option. The system call was first
# introduced in FreeBSD version 1400032.
#
fspacectl_reason = 'fspacectl(2) and truncate -d support required'

#
# Some tests are not applicable to a platform or need to be updated to operate
# in the manor required by the platform. Any tests which are skipped for this
Expand Down Expand Up @@ -224,6 +231,7 @@ maybe = {
'cli_root/zpool_trim/setup': ['SKIP', trim_reason],
'cli_root/zpool_upgrade/zpool_upgrade_004_pos': ['FAIL', '6141'],
'delegate/setup': ['SKIP', exec_reason],
'fallocate/fallocate_punch-hole': ['SKIP', fspacectl_reason],
'history/history_004_pos': ['FAIL', '7026'],
'history/history_005_neg': ['FAIL', '6680'],
'history/history_006_neg': ['FAIL', '5657'],
Expand Down
20 changes: 20 additions & 0 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Copyright (c) 2017, Lawrence Livermore National Security LLC.
# Copyright (c) 2017, Datto Inc. All rights reserved.
# Copyright (c) 2017, Open-E Inc. All rights reserved.
# Copyright (c) 2021, The FreeBSD Foundation.
# Use is subject to license terms.
#

Expand Down Expand Up @@ -4194,6 +4195,25 @@ function get_arcstat # stat
esac
}

function punch_hole # offset length file
{
typeset offset=$1
typeset length=$2
typeset file=$3

case $(uname) in
FreeBSD)
truncate -d -o $offset -l $length "$file"
;;
Linux)
fallocate --punch-hole --offset $offset --length $length "$file"
;;
*)
false
;;
esac
}

#
# Wait for the specified arcstat to reach non-zero quiescence.
# If echo is 1 echo the value after reaching quiescence, otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

#
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
# Copyright (c) 2021 by The FreeBSD Foundation.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# Test `fallocate --punch-hole`
# Test hole-punching functionality
#
# STRATEGY:
# 1. Create a dense file
Expand All @@ -37,6 +38,20 @@

verify_runnable "global"

#
# Prior to __FreeBSD_version 1400032 there are no mechanism to punch hole in a
# file on FreeBSD. truncate -d support is required to call fspacectl(2) on
# behalf of the script.
#
if is_freebsd; then
if [[ $(uname -K) -lt 1400032 ]]; then
log_unsupported "Requires fspacectl(2) support on FreeBSD"
fi
if truncate -d 2>&1 | grep "illegal option" > /dev/null; then
log_unsupported "Requires truncate(1) -d support on FreeBSD"
fi
fi

FILE=$TESTDIR/$TESTFILE0
BLKSZ=$(get_prop recordsize $TESTPOOL)

Expand Down Expand Up @@ -74,23 +89,21 @@ log_must file_write -o create -f $FILE -b $BLKSZ -c 8
log_must check_disk_size $((131072 * 8))

# Punch a hole for the first full block.
log_must fallocate --punch-hole --offset 0 --length $BLKSZ $FILE
log_must punch_hole 0 $BLKSZ $FILE
log_must check_disk_size $((131072 * 7))

# Partially punch a hole in the second block.
log_must fallocate --punch-hole --offset $BLKSZ --length $((BLKSZ / 2)) $FILE
log_must punch_hole $BLKSZ $((BLKSZ / 2)) $FILE
log_must check_disk_size $((131072 * 7))

# Punch a hole which overlaps the third and forth block.
log_must fallocate --punch-hole --offset $(((BLKSZ * 2) + (BLKSZ / 2))) \
--length $((BLKSZ)) $FILE
log_must punch_hole $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE
log_must check_disk_size $((131072 * 7))

# Punch a hole from the fifth block past the end of file. The apparent
# file size should not change since --keep-size is implied.
apparent_size=$(stat_size $FILE)
log_must fallocate --punch-hole --offset $((BLKSZ * 4)) \
--length $((BLKSZ * 10)) $FILE
log_must punch_hole $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE
log_must check_disk_size $((131072 * 4))
log_must check_apparent_size $apparent_size

Expand Down

0 comments on commit c3cb57a

Please sign in to comment.