posix_fallocate() might be not supported by a filesystem, for example,
it's not supported by ZFS. In that case it fails with
return code 22 (EINVAL), and thus safezero_posix_fallocate() returns -1.
As safezero_posix_fallocate() is the first function tried by safezero()
and it tries other functions only when it returns -2, it fails
immediately without falling back to other methods, such as
safezero_slow().
Fix that by returning -2 if posix_fallocate() returns EINVAL, to give
safezero() a chance to try other functions.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
safezero_posix_fallocate(int fd, off_t offset, off_t len)
{
int ret = posix_fallocate(fd, offset, len);
- if (ret == 0)
+ if (ret == 0) {
return 0;
+ } else if (ret == EINVAL) {
+ /* EINVAL is returned when either:
+ - Operation is not supported by the underlying filesystem,
+ - offset or len argument values are invalid.
+ Assuming that offset and len are valid, this error means
+ the operation is not supported, and we need to fall back
+ to other methods.
+ */
+ return -2;
+ }
+
errno = ret;
return -1;
}