]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
linux: add basic fallocate(mode=0/2) compatibility
authoradilger <adilger@dilger.ca>
Thu, 18 Jun 2020 18:22:11 +0000 (12:22 -0600)
committerGitHub <noreply@github.com>
Thu, 18 Jun 2020 18:22:11 +0000 (11:22 -0700)
commitf734301d2267cbb33eaffbca195fc93f1dae7b74
tree9cca50f0352df34f2ccf7142e09be836b46c9565
parentd553fb9b9e18e04d1c85bf1930bcf0f46757d32e
linux: add basic fallocate(mode=0/2) compatibility

Implement semi-compatible functionality for mode=0 (preallocation)
and mode=FALLOC_FL_KEEP_SIZE (preallocation beyond EOF) for ZPL.

Since ZFS does COW and snapshots, preallocating blocks for a file
cannot guarantee that writes to the file will not run out of space.
Even if the first overwrite was guaranteed, it would not handle any
later overwrite of blocks due to COW, so strict compliance is futile.
Instead, make a best-effort check that at least enough free space is
currently available in the pool (with a bit of margin), then create
a sparse file of the requested size and continue on with life.

This does not handle all cases (e.g. several fallocate() calls before
writing into the files when the filesystem is nearly full), which
would require a more complex mechanism to be implemented, probably
based on a modified version of dmu_prealloc(), but is usable as-is.

A new module option zfs_fallocate_reserve_percent is used to control
the reserve margin for any single fallocate call.  By default, this
is 110% of the requested preallocation size, so an additional 10% of
available space is reserved for overhead to allow the application a
good chance of finishing the write when the fallocate() succeeds.
If the heuristics of this basic fallocate implementation are not
desirable, the old non-functional behavior of returning EOPNOTSUPP
for calls can be restored by setting zfs_fallocate_reserve_percent=0.

The parameter of zfs_statvfs() is changed to take an inode instead
of a dentry, since no dentry is available in zfs_fallocate_common().

A few tests from @behlendorf cover basic fallocate functionality.

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Arshad Hussain <arshad.super@gmail.com>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Issue #326
Closes #10408
13 files changed:
configure.ac
include/os/linux/zfs/sys/zfs_vfsops.h
man/man5/zfs-module-parameters.5
module/os/linux/zfs/zfs_vfsops.c
module/os/linux/zfs/zpl_file.c
module/os/linux/zfs/zpl_super.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/Makefile.am
tests/zfs-tests/tests/functional/fallocate/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/fallocate/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/fallocate/fallocate_prealloc.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/fallocate/fallocate_punch-hole.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/fallocate/setup.ksh [new file with mode: 0755]