From: Roman Bogorodskiy Date: Sun, 31 Jan 2021 09:23:27 +0000 (+0400) Subject: virfile: workaround for when posix_fallocate() is not supported by FS X-Git-Tag: v7.1.0-rc1~384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31d1835428004add9f58b0ac03715263ad869858;p=thirdparty%2Flibvirt.git 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 Reviewed-by: Michal Privoznik --- diff --git a/src/util/virfile.c b/src/util/virfile.c index 609cafdd34..e8713613e3 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -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; }