git: 23004dbe58f6 - stable/15 - Revert "zfsctl_root_readdir: if there were no dirents to copy out, return EINVAL"

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 22 Sep 2025 04:53:50 UTC
The branch stable/15 has been updated by kib:

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

commit 23004dbe58f62be4e9646ed96192ad4aa556a3eb
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-19 17:06:54 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-21 23:25:16 +0000

    Revert "zfsctl_root_readdir: if there were no dirents to copy out, return EINVAL"
    
    (cherry picked from commit 72924ce99c7f177db486bd2764a76bcf25892a17)
---
 .../openzfs/module/os/freebsd/zfs/zfs_ctldir.c     | 40 ++++++++--------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
index a222c5de4a2a..4de48e013ec4 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
@@ -674,7 +674,6 @@ zfsctl_root_readdir(struct vop_readdir_args *ap)
 	zfs_uio_t uio;
 	int *eofp = ap->a_eofflag;
 	off_t dots_offset;
-	ssize_t orig_resid;
 	int error;
 
 	zfs_uio_init(&uio, ap->a_uio);
@@ -694,11 +693,13 @@ zfsctl_root_readdir(struct vop_readdir_args *ap)
 		return (0);
 	}
 
-	orig_resid = zfs_uio_resid(&uio);
 	error = sfs_readdir_common(zfsvfs->z_root, ZFSCTL_INO_ROOT, ap, &uio,
 	    &dots_offset);
-	if (error != 0)
-		goto err;
+	if (error != 0) {
+		if (error == ENAMETOOLONG) /* ran out of destination space */
+			error = 0;
+		return (error);
+	}
 	if (zfs_uio_offset(&uio) != dots_offset)
 		return (SET_ERROR(EINVAL));
 
@@ -711,11 +712,8 @@ zfsctl_root_readdir(struct vop_readdir_args *ap)
 	entry.d_reclen = sizeof (entry);
 	error = vfs_read_dirent(ap, &entry, zfs_uio_offset(&uio));
 	if (error != 0) {
-err:
-		if (error == ENAMETOOLONG) {
-			error = orig_resid == zfs_uio_resid(&uio) ?
-			    EINVAL : 0;
-		}
+		if (error == ENAMETOOLONG)
+			error = 0;
 		return (SET_ERROR(error));
 	}
 	if (eofp != NULL)
@@ -1060,21 +1058,17 @@ zfsctl_snapdir_readdir(struct vop_readdir_args *ap)
 	zfs_uio_t uio;
 	int *eofp = ap->a_eofflag;
 	off_t dots_offset;
-	ssize_t orig_resid;
 	int error;
 
 	zfs_uio_init(&uio, ap->a_uio);
-	orig_resid = zfs_uio_resid(&uio);
 
 	ASSERT3S(vp->v_type, ==, VDIR);
 
 	error = sfs_readdir_common(ZFSCTL_INO_ROOT, ZFSCTL_INO_SNAPDIR, ap,
 	    &uio, &dots_offset);
 	if (error != 0) {
-		if (error == ENAMETOOLONG) { /* ran out of destination space */
-			error = orig_resid == zfs_uio_resid(&uio) ?
-			    EINVAL : 0;
-		}
+		if (error == ENAMETOOLONG) /* ran out of destination space */
+			error = 0;
 		return (error);
 	}
 
@@ -1092,13 +1086,9 @@ zfsctl_snapdir_readdir(struct vop_readdir_args *ap)
 		dsl_pool_config_exit(dmu_objset_pool(zfsvfs->z_os), FTAG);
 		if (error != 0) {
 			if (error == ENOENT) {
-				if (orig_resid == zfs_uio_resid(&uio)) {
-					error = EINVAL;
-				} else {
-					error = 0;
-					if (eofp != NULL)
-						*eofp = 1;
-				}
+				if (eofp != NULL)
+					*eofp = 1;
+				error = 0;
 			}
 			zfs_exit(zfsvfs, FTAG);
 			return (error);
@@ -1111,10 +1101,8 @@ zfsctl_snapdir_readdir(struct vop_readdir_args *ap)
 		entry.d_reclen = sizeof (entry);
 		error = vfs_read_dirent(ap, &entry, zfs_uio_offset(&uio));
 		if (error != 0) {
-			if (error == ENAMETOOLONG) {
-				error = orig_resid == zfs_uio_resid(&uio) ?
-				    EINVAL : 0;
-			}
+			if (error == ENAMETOOLONG)
+				error = 0;
 			zfs_exit(zfsvfs, FTAG);
 			return (SET_ERROR(error));
 		}