]> xenbits.xensource.com Git - libvirt.git/commitdiff
virfile: workaround for when posix_fallocate() is not supported by FS
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 31 Jan 2021 09:23:27 +0000 (13:23 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Mon, 1 Feb 2021 16:15:22 +0000 (20:15 +0400)
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>
src/util/virfile.c

index 609cafdd3481871bcdba30c1136aaf9eb29271ca..e8713613e353f0513d75dcc26a2fcf805308b06c 100644 (file)
@@ -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;
 }