git: 6fd6a0e342fb - main - nfsd: Handle file systems without a VOP_VPTOFH()

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Fri, 23 Dec 2022 23:18:42 UTC
The branch main has been updated by rmacklem:

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

commit 6fd6a0e342fbfb8513ae56105cf0f85f55c6276e
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-12-23 23:17:34 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-12-23 23:17:34 +0000

    nfsd: Handle file systems without a VOP_VPTOFH()
    
    Unlike NFSv3, the NFSv4 server follows mount points
    within the file system tree below the NFSv4 root directory.
    If there is a file system mounted within this subtree
    that returns EOPNOTSUPP for VOP_VPTOFH(), the NFSv4 server
    would return an error for the mount point entry.
    This resulted in an "I/O error" report from the Linux NFSv4
    client.  It also put an error code in the Readdir reply
    that is not defined in the NFSv4 RFCs.
    
    For the FreeBSD NFSv4 client, the entry with the error would
    be ignored, which I think is reasonable behaviour for a
    mounted file system that can never be exported.
    
    This patch changes the NFSv4 server behaviour to ignore the
    mount point entry and not send it in the Readdir reply.
    It also changes the behaviour of Lookup for the entry so
    that it replies ENOENT for the mount point directory, so
    that it is consistent with no entry in the Readdir reply.
    
    With these two changes, the Linux client behaviour is the
    same as the FreeBSD client behaviour.  It also avoids
    putting an unknown error on the wire to the client.
    
    MFC after:      1 week
---
 sys/fs/nfsserver/nfs_nfsdport.c | 11 +++++++++--
 sys/fs/nfsserver/nfs_nfsdserv.c |  9 ++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index e11477b20ee2..665e2c00ce08 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -2699,15 +2699,22 @@ again:
 				 * For NFSv4 the behavior is controlled by
 				 * RDATTRERROR: we either ignore the error or
 				 * fail the request.
+				 * The exception is EOPNOTSUPP, which can be
+				 * returned by nfsvno_getfh() for certain
+				 * file systems, such as devfs.  This indicates
+				 * that the file system cannot be exported,
+				 * so just skip over the entry.
 				 * Note that RDATTRERROR is never set for NFSv3.
 				 */
 				if (r != 0) {
 					if (!NFSISSET_ATTRBIT(&attrbits,
-					    NFSATTRBIT_RDATTRERROR)) {
+					    NFSATTRBIT_RDATTRERROR) ||
+					    r == EOPNOTSUPP) {
 						vput(nvp);
 						if (needs_unbusy != 0)
 							vfs_unbusy(new_mp);
-						if ((nd->nd_flag & ND_NFSV3))
+						if ((nd->nd_flag & ND_NFSV3) ||
+						    r == EOPNOTSUPP)
 							goto invalid;
 						nd->nd_repstat = r;
 						break;
diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c
index 5a547fabb541..709dc84d5d91 100644
--- a/sys/fs/nfsserver/nfs_nfsdserv.c
+++ b/sys/fs/nfsserver/nfs_nfsdserv.c
@@ -645,8 +645,15 @@ nfsrvd_lookup(struct nfsrv_descript *nd, __unused int isdgram,
 		 * non-exported volumes during NFSv4 mounting.
 		 */
 		nd->nd_repstat = ENOENT;
-	if (nd->nd_repstat == 0)
+	if (nd->nd_repstat == 0) {
 		nd->nd_repstat = nfsvno_getfh(vp, fhp, p);
+		/*
+		 * EOPNOTSUPP indicates the file system cannot be exported,
+		 * so just pretend the entry does not exist.
+		 */
+		if (nd->nd_repstat == EOPNOTSUPP)
+			nd->nd_repstat = ENOENT;
+	}
 	if (!(nd->nd_flag & ND_NFSV4) && !nd->nd_repstat)
 		nd->nd_repstat = nfsvno_getattr(vp, &nva, nd, p, 1, NULL);
 	if (vpp != NULL && nd->nd_repstat == 0)