Skip to content

Commit

Permalink
Add support for FALLOC_FL_ZERO_RANGE
Browse files Browse the repository at this point in the history
For us, I think it's always just FALLOC_FL_PUNCH_HOLE with a fake
mustache on.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Coleman Kane <ckane@colemankane.org>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes openzfs#12975
  • Loading branch information
rincebrain authored and snajpa committed Oct 22, 2022
1 parent fcc5ad9 commit 8f8e5c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions config/kernel-fallocate.m4
Expand Up @@ -3,6 +3,10 @@ dnl # Linux 2.6.38 - 3.x API
dnl # The fallocate callback was moved from the inode_operations
dnl # structure to the file_operations structure.
dnl #
dnl #
dnl # Linux 3.15+
dnl # fallocate learned a new flag, FALLOC_FL_ZERO_RANGE
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_FALLOCATE], [
ZFS_LINUX_TEST_SRC([file_fallocate], [
#include <linux/fs.h>
Expand All @@ -15,12 +19,25 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_FALLOCATE], [
.fallocate = test_fallocate,
};
], [])
ZFS_LINUX_TEST_SRC([falloc_fl_zero_range], [
#include <linux/falloc.h>
],[
int flags __attribute__ ((unused));
flags = FALLOC_FL_ZERO_RANGE;
])
])

AC_DEFUN([ZFS_AC_KERNEL_FALLOCATE], [
AC_MSG_CHECKING([whether fops->fallocate() exists])
ZFS_LINUX_TEST_RESULT([file_fallocate], [
AC_MSG_RESULT(yes)
AC_MSG_CHECKING([whether FALLOC_FL_ZERO_RANGE exists])
ZFS_LINUX_TEST_RESULT([falloc_fl_zero_range], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_FALLOC_FL_ZERO_RANGE, 1, [FALLOC_FL_ZERO_RANGE is defined])
],[
AC_MSG_RESULT(no)
])
],[
ZFS_LINUX_TEST_ERROR([file_fallocate])
])
Expand Down
9 changes: 7 additions & 2 deletions module/os/linux/zfs/zpl_file.c
Expand Up @@ -739,7 +739,12 @@ zpl_fallocate_common(struct inode *ip, int mode, loff_t offset, loff_t len)
fstrans_cookie_t cookie;
int error = 0;

if ((mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) != 0)
int test_mode = FALLOC_FL_PUNCH_HOLE;
#ifdef HAVE_FALLOC_FL_ZERO_RANGE
test_mode |= FALLOC_FL_ZERO_RANGE;
#endif

if ((mode & ~(FALLOC_FL_KEEP_SIZE | test_mode)) != 0)
return (-EOPNOTSUPP);

if (offset < 0 || len <= 0)
Expand All @@ -750,7 +755,7 @@ zpl_fallocate_common(struct inode *ip, int mode, loff_t offset, loff_t len)

crhold(cr);
cookie = spl_fstrans_mark();
if (mode & FALLOC_FL_PUNCH_HOLE) {
if (mode & (test_mode)) {
flock64_t bf;

if (offset > olen)
Expand Down

0 comments on commit 8f8e5c5

Please sign in to comment.