git: b636e35bb724 - stable/14 - vfs mount: Consistently use ENODEV internally for an invalid fstype

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 03 Jan 2024 20:33:20 UTC
The branch stable/14 has been updated by jhb:

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

commit b636e35bb724b9c777fed6c7cf4a713d14316f36
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-11-18 19:08:34 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-01-03 20:18:44 +0000

    vfs mount: Consistently use ENODEV internally for an invalid fstype
    
    Change vfs_byname_kld to always return an error value of ENODEV to
    indicate an unsupported fstype leaving ENOENT to indicate errors such
    as a missing mount point or invalid path.  This allows nmount(2) to
    better distinguish these cases and avoid treating a missing device
    node as an invalid fstype after commit 6e8272f317b8.
    
    While here, change mount(2) to return EINVAL instead of ENODEV for an
    invalid fstype to match nmount(2).
    
    PR:             274600
    Reviewed by:    pstef, markj
    Differential Revision:  https://reviews.freebsd.org/D42327
    
    (cherry picked from commit 3eed4803f943e2937325e81140b88e2e8eea8deb)
---
 sys/kern/vfs_init.c  | 4 +++-
 sys/kern/vfs_mount.c | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c
index c57e1471e356..64263caaef98 100644
--- a/sys/kern/vfs_init.c
+++ b/sys/kern/vfs_init.c
@@ -149,8 +149,10 @@ vfs_byname_kld(const char *fstype, struct thread *td, int *error)
 	loaded = (*error == 0);
 	if (*error == EEXIST)
 		*error = 0;
-	if (*error)
+	if (*error) {
+		*error = ENODEV;
 		return (NULL);
+	}
 
 	/* Look up again to see if the VFS was loaded. */
 	vfsp = vfs_byname(fstype);
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index c42fcfa7537b..c36fda4e8a9e 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -996,7 +996,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions)
 		jail_export = false;
 
 	error = vfs_domount(td, fstype, fspath, fsflags, jail_export, &optlist);
-	if (error == ENOENT) {
+	if (error == ENODEV) {
 		error = EINVAL;
 		if (errmsg != NULL)
 			strncpy(errmsg, "Invalid fstype", errmsg_len);
@@ -1086,7 +1086,7 @@ sys_mount(struct thread *td, struct mount_args *uap)
 	vfsp = vfs_byname_kld(fstype, td, &error);
 	free(fstype, M_TEMP);
 	if (vfsp == NULL)
-		return (ENOENT);
+		return (EINVAL);
 	if (((vfsp->vfc_flags & VFCF_SBDRY) != 0 &&
 	    vfsp->vfc_vfsops_sd->vfs_cmount == NULL) ||
 	    ((vfsp->vfc_flags & VFCF_SBDRY) == 0 &&