zfs_file: implement zfs_file_deallocate for FreeBSD 14

FreeBSD 14 gained a `VOP_DEALLOCATE` VFS operation and a `fspacectl`
syscall to use it. At minimum, these zero the given region, and if the
underlying filesystem supports it, can make the region sparse. We can
use this to get TRIM-like behaviour for file vdevs.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #16496
This commit is contained in:
Rob Norris
2024-09-01 12:34:17 +10:00
committed by Brian Behlendorf
parent fa330646b9
commit f245541e24
2 changed files with 19 additions and 1 deletions
+6
View File
@@ -1380,6 +1380,12 @@ zfs_file_deallocate(zfs_file_t *fp, loff_t offset, loff_t len)
#if defined(__linux__)
rc = fallocate(fp->f_fd,
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, len);
#elif defined(__FreeBSD__) && (__FreeBSD_version >= 1400029)
struct spacectl_range rqsr = {
.r_offset = offset,
.r_len = len,
};
rc = fspacectl(fp->f_fd, SPACECTL_DEALLOC, &rqsr, 0, &rqsr);
#else
(void) fp, (void) offset, (void) len;
rc = EOPNOTSUPP;