]> git.proxmox.com Git - mirror_zfs.git/commitdiff
ZTS: Enable punch-hole tests on FreeBSD
authorKa Ho Ng <khng@FreeBSD.org>
Sun, 22 Aug 2021 15:22:07 +0000 (23:22 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 30 Aug 2021 20:33:32 +0000 (13:33 -0700)
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

tests/runfiles/common.run
tests/runfiles/linux.run
tests/test-runner/bin/zts-report.py.in
tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/fallocate/fallocate_punch-hole.ksh

index 895e705525fa1b2e8d4d50734d1a80c462355531..505131d2b9bece8fb82a023be668fc76f1d1d1b9 100644 (file)
@@ -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']
index 642ed824d462572f6576bfb3ed0690e06bc557c2..b7831c3acfd141ea7b53bd31bd02b81c92a934d3 100644 (file)
@@ -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]
index f5a43c66fe83927cd43f251ad0532f53fd6dab35..cf56e747e5c55fe1438882a1646c972809d14af8 100755 (executable)
@@ -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
@@ -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'],
index 1dc6881b6d1aa0a3e1d02dfa0947fb8543c28f28..ab0cd5270c994fe74dbb261c279278a5f38e8d98 100644 (file)
@@ -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.
 #
 
@@ -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
index 6a8faa48704d5ff7ed1ee1227f42209d8a76e420..ed83561bd5560713c7b27d991603ff2edb54b71d 100755 (executable)
 
 #
 # 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
 
 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)
 
@@ -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