[PATCH] virfile: safezero: handle posix_fallocate()'s EOPNOTSUPP

Roman Bogorodskiy posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20260420183951.38892-1-bogorodskiy@gmail.com
src/util/virfile.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] virfile: safezero: handle posix_fallocate()'s EOPNOTSUPP
Posted by Roman Bogorodskiy 1 month ago
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>
---
 src/util/virfile.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index e3c0026841..a0c6cb8048 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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;
     }
-- 
2.52.0

Re: [PATCH] virfile: safezero: handle posix_fallocate()'s EOPNOTSUPP
Posted by Daniel P. Berrangé via Devel 1 month ago
On Mon, Apr 20, 2026 at 08:39:51PM +0200, Roman Bogorodskiy wrote:
> 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>
> ---
>  src/util/virfile.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|