git: fa393807c57e - main - fusefs: standardize on OPNOTSUPP for posix_fallocate(2)

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Wed, 05 Nov 2025 00:31:15 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=fa393807c57e80a01dde40c668650537490c1eaa

commit fa393807c57e80a01dde40c668650537490c1eaa
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-11-05 00:30:58 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-11-05 00:30:58 +0000

    fusefs: standardize on OPNOTSUPP for posix_fallocate(2)
    
    POSIX Issue 7 had allowed EINVAL for this case, but issue 8 moves it
    to ENOTSUP instead.  ZFS uses the latter and we have some software in
    ports already that's wanting to use that to detect the filesystem not
    supporting it, so let's standardize on it.
    
    Reviewed by:    imp (previous version), asomers, kib
    Differential Revision:  https://reviews.freebsd.org/D53535
---
 sys/fs/fuse/fuse_vnops.c         |  6 +++---
 tests/sys/fs/fusefs/fallocate.cc | 16 ++++++++--------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c
index 6c79e646d2f3..ef5aee5de34c 100644
--- a/sys/fs/fuse/fuse_vnops.c
+++ b/sys/fs/fuse/fuse_vnops.c
@@ -625,7 +625,7 @@ fuse_vnop_allocate(struct vop_allocate_args *ap)
 		return (EROFS);
 
 	if (fsess_not_impl(mp, FUSE_FALLOCATE))
-		return (EXTERROR(EINVAL, "This server does not implement "
+		return (EXTERROR(EOPNOTSUPP, "This server does not implement "
 		    "FUSE_FALLOCATE"));
 
 	io.uio_offset = *offset;
@@ -656,14 +656,14 @@ fuse_vnop_allocate(struct vop_allocate_args *ap)
 
 	if (err == ENOSYS) {
 		fsess_set_notimpl(mp, FUSE_FALLOCATE);
-		err = EXTERROR(EINVAL, "This server does not implement "
+		err = EXTERROR(EOPNOTSUPP, "This server does not implement "
 		    "FUSE_ALLOCATE");
 	} else if (err == EOPNOTSUPP) {
 		/*
 		 * The file system server does not support FUSE_FALLOCATE with
 		 * the supplied mode for this particular file.
 		 */
-		err = EXTERROR(EINVAL, "This file can't be pre-allocated");
+		err = EXTERROR(EOPNOTSUPP, "This file can't be pre-allocated");
 	} else if (!err) {
 		*offset += *len;
 		*len = 0;
diff --git a/tests/sys/fs/fusefs/fallocate.cc b/tests/sys/fs/fusefs/fallocate.cc
index 4e5b047b78b7..1a3a0af36236 100644
--- a/tests/sys/fs/fusefs/fallocate.cc
+++ b/tests/sys/fs/fusefs/fallocate.cc
@@ -205,7 +205,7 @@ TEST_F(Fspacectl, enosys)
 	EXPECT_EQ(0, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL));
 
 	/* Neither should posix_fallocate query the daemon */
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, off1, len1));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, off1, len1));
 
 	leak(fd);
 }
@@ -548,7 +548,7 @@ INSTANTIATE_TEST_SUITE_P(FspacectlCache, FspacectlCache,
 
 /*
  * If the server returns ENOSYS, it indicates that the server does not support
- * FUSE_FALLOCATE.  This and future calls should return EINVAL.
+ * FUSE_FALLOCATE.  This and future calls should return EOPNOTSUPP.
  */
 TEST_F(PosixFallocate, enosys)
 {
@@ -570,10 +570,10 @@ TEST_F(PosixFallocate, enosys)
 
 	fd = open(FULLPATH, O_RDWR);
 	ASSERT_LE(0, fd) << strerror(errno);
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, off0, len0));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, off0, len0));
 
 	/* Subsequent calls shouldn't query the daemon*/
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, off0, len0));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, off0, len0));
 
 	/* Neither should VOP_DEALLOCATE query the daemon */
 	EXPECT_EQ(0, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL));
@@ -607,10 +607,10 @@ TEST_F(PosixFallocate, eopnotsupp)
 
 	fd = open(FULLPATH, O_RDWR);
 	ASSERT_LE(0, fd) << strerror(errno);
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, fsize, length));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, fsize, length));
 
 	/* Subsequent calls should still query the daemon*/
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, offset, length));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, offset, length));
 
 	/* And subsequent VOP_DEALLOCATE calls should also query the daemon */
 	rqsr.r_len = length;
@@ -759,7 +759,7 @@ TEST_F(PosixFallocate, rlimit_fsize)
 }
 
 /* With older servers, no FUSE_FALLOCATE should be attempted */
-TEST_F(PosixFallocate_7_18, einval)
+TEST_F(PosixFallocate_7_18, eopnotsupp)
 {
 	const char FULLPATH[] = "mountpoint/some_file.txt";
 	const char RELPATH[] = "some_file.txt";
@@ -773,7 +773,7 @@ TEST_F(PosixFallocate_7_18, einval)
 
 	fd = open(FULLPATH, O_RDWR);
 	ASSERT_LE(0, fd) << strerror(errno);
-	EXPECT_EQ(EINVAL, posix_fallocate(fd, offset, length));
+	EXPECT_EQ(EOPNOTSUPP, posix_fallocate(fd, offset, length));
 
 	leak(fd);
 }