]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virfile: safezero: handle posix_fallocate()'s EOPNOTSUPP master
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Mon, 20 Apr 2026 18:06:58 +0000 (20:06 +0200)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 21 Apr 2026 16:11:01 +0000 (18:11 +0200)
FreeBSD 15.x updated posix_fallocate() to return EOPNOTSUPP
instead of EINVAL when the operation is not supported.
Quoting posix_fallocate(2):

     Previous versions of posix_fallocate used EINVAL to indicate that the
     operation is not supported by the file system, as specified in IEEE Std
     1003.1 (“POSIX.1”) Base Specifications, Issue 7.  IEEE Std 1003.1
     (“POSIX.1”) Base Specifications, Issue 8 switched to requiring EOPNOTSUPP
     for this error case.  ZFS adopted the latter convention in FreeBSD 15.0,
     and the remaining filesystems in base adopted it in FreeBSD 15.1.

Update safezero_posix_fallocate() to handle this return value
along with EINVAL to fix the waterfall down to safezero_slow()
for filesystems that do not support that.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virfile.c

index e3c0026841d876d15328a8c3b67ac5bf5fc153df..a0c6cb804862d68357c63ae43ab590d6f5ce0427 100644 (file)
@@ -1301,13 +1301,16 @@ safezero_posix_fallocate(int fd, off_t offset, off_t len)
     int ret = posix_fallocate(fd, offset, len);
     if (ret == 0) {
         return 0;
-    } else if (ret == EINVAL) {
+    } else if (ret == EINVAL || ret == EOPNOTSUPP) {
         /* 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.
+
+           Newer versions of FreeBSD return EOPNOTSUPP when the
+           operation is not supported.
         */
         return -2;
     }