Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Nov 2023 12:31:20 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 7aaf39f6b3b0 - stable/13 - nfsd: Fix NFS access to .zfs/snapshot snapshots
Message-ID:  <202311301231.3AUCVK7E048630@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by rmacklem:

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

commit 7aaf39f6b3b0bc5cc171eac7ca118d17460ea5db
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2023-11-23 15:23:33 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2023-11-30 12:28:50 +0000

    nfsd: Fix NFS access to .zfs/snapshot snapshots
    
    When a process attempts to access a snapshot under
    /<dataset>/.zfs/snapshot, the snapshot is automounted.
    However, without this patch, the automount does not
    set mnt_exjail, which results in the snapshot not being
    accessible over NFS.
    
    This patch defines a new function called vfs_exjail_clone()
    which sets mnt_exjail from another mount point and
    then uses that function to set mnt_exjail in the snapshot
    automount.  A separate patch that is currently a pull request
    for OpenZFS, calls this function to fix the problem.
    
    PR:     275200
    
    (cherry picked from commit f5f277728adec4c5b3e840a1fb16bd16f8cc956d)
---
 sys/kern/vfs_mount.c | 35 +++++++++++++++++++++++++++++++++++
 sys/sys/mount.h      |  4 ++++
 2 files changed, 39 insertions(+)

diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index 4597ae09a831..cefadf75a3a8 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -2824,6 +2824,41 @@ suspend_all_fs(void)
 	mtx_unlock(&mountlist_mtx);
 }
 
+/*
+ * Clone the mnt_exjail field to a new mount point.
+ */
+void
+vfs_exjail_clone(struct mount *inmp, struct mount *outmp)
+{
+	struct ucred *cr;
+	struct prison *pr;
+
+	MNT_ILOCK(inmp);
+	cr = inmp->mnt_exjail;
+	if (cr != NULL) {
+		crhold(cr);
+		MNT_IUNLOCK(inmp);
+		pr = cr->cr_prison;
+		sx_slock(&allprison_lock);
+		if (!prison_isalive(pr)) {
+			sx_sunlock(&allprison_lock);
+			crfree(cr);
+			return;
+		}
+		MNT_ILOCK(outmp);
+		if (outmp->mnt_exjail == NULL) {
+			outmp->mnt_exjail = cr;
+			atomic_add_int(&pr->pr_exportcnt, 1);
+			cr = NULL;
+		}
+		MNT_IUNLOCK(outmp);
+		sx_sunlock(&allprison_lock);
+		if (cr != NULL)
+			crfree(cr);
+	} else
+		MNT_IUNLOCK(inmp);
+}
+
 void
 resume_all_fs(void)
 {
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index 2d9ee8d78bdd..9c1862956812 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -947,6 +947,9 @@ vfs_statfs_t	__vfs_statfs;
  * exported vnode operations
  */
 
+/* Define this to indicate that vfs_exjail_clone() exists for ZFS to use. */
+#define	VFS_SUPPORTS_EXJAIL_CLONE	1
+
 int	dounmount(struct mount *, int, struct thread *);
 
 int	kernel_mount(struct mntarg *ma, uint64_t flags);
@@ -984,6 +987,7 @@ int	vfs_setpublicfs			    /* set publicly exported fs */
 	    (struct mount *, struct netexport *, struct export_args *);
 void	vfs_periodic(struct mount *, int);
 int	vfs_busy(struct mount *, int);
+void	vfs_exjail_clone(struct mount *, struct mount *);
 int	vfs_export			 /* process mount export info */
 	    (struct mount *, struct export_args *, int);
 void	vfs_free_addrlist(struct netexport *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202311301231.3AUCVK7E048630>