mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
virfile: workaround for when posix_fallocate() is not supported by FS
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>
This commit is contained in:
parent
b943099c87
commit
31d1835428
@ -1117,8 +1117,19 @@ static int
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user