From 66fa44e7a3111d837743cb11af67100a0cd8b8c6 Mon Sep 17 00:00:00 2001 From: Venkatesh Srinivas Date: Tue, 31 Jan 2012 00:15:24 -0500 Subject: [PATCH] tmpfs: Support NFS export of tmpfs filesystems. * Implement vop_mountctl and MOUNTCTL_SET_EXPORT interfaces to allow mountd to export a tmpfs filesystem. * Implement vfs_checkexp to allow NFS to function. Closes: Bug 2277 --- sys/vfs/tmpfs/tmpfs.h | 2 ++ sys/vfs/tmpfs/tmpfs_vfsops.c | 23 ++++++++++++++++++++++- sys/vfs/tmpfs/tmpfs_vnops.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/sys/vfs/tmpfs/tmpfs.h b/sys/vfs/tmpfs/tmpfs.h index 4404cc6588..609b1c18e9 100644 --- a/sys/vfs/tmpfs/tmpfs.h +++ b/sys/vfs/tmpfs/tmpfs.h @@ -399,6 +399,8 @@ struct tmpfs_mount { struct objcache *tm_node_pool; int tm_flags; + + struct netexport tm_export; }; #define TMPFS_LOCK(tm) lockmgr(&(tm)->allnode_lock, LK_EXCLUSIVE|LK_RETRY) diff --git a/sys/vfs/tmpfs/tmpfs_vfsops.c b/sys/vfs/tmpfs/tmpfs_vfsops.c index 940643a569..55b2ffc770 100644 --- a/sys/vfs/tmpfs/tmpfs_vfsops.c +++ b/sys/vfs/tmpfs/tmpfs_vfsops.c @@ -518,6 +518,26 @@ tmpfs_vptofh(struct vnode *vp, struct fid *fhp) /* --------------------------------------------------------------------- */ +static int +tmpfs_checkexp(struct mount *mp, struct sockaddr *nam, int *exflagsp, + struct ucred **credanonp) +{ + struct tmpfs_mount *tmp; + struct netcred *nc; + + tmp = (struct tmpfs_mount *) mp->mnt_data; + nc = vfs_export_lookup(mp, &tmp->tm_export, nam); + if (nc == NULL) + return (EACCES); + + *exflagsp = nc->netc_exflags; + *credanonp = &nc->netc_anon; + + return (0); +} + +/* --------------------------------------------------------------------- */ + /* * tmpfs vfs operations. */ @@ -529,7 +549,8 @@ static struct vfsops tmpfs_vfsops = { .vfs_statfs = tmpfs_statfs, .vfs_fhtovp = tmpfs_fhtovp, .vfs_vptofh = tmpfs_vptofh, - .vfs_sync = vfs_stdsync + .vfs_sync = vfs_stdsync, + .vfs_checkexp = tmpfs_checkexp, }; VFS_SET(tmpfs_vfsops, tmpfs, 0); diff --git a/sys/vfs/tmpfs/tmpfs_vnops.c b/sys/vfs/tmpfs/tmpfs_vnops.c index 3a5d7a09dd..c30b8fa70c 100644 --- a/sys/vfs/tmpfs/tmpfs_vnops.c +++ b/sys/vfs/tmpfs/tmpfs_vnops.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -1498,6 +1499,33 @@ tmpfs_reclaim(struct vop_reclaim_args *v) return 0; } +/* --------------------------------------------------------------------- */ + +static int +tmpfs_mountctl(struct vop_mountctl_args *ap) +{ + struct tmpfs_mount *tmp; + struct mount *mp; + int rc; + + switch (ap->a_op) { + case (MOUNTCTL_SET_EXPORT): + mp = ap->a_head.a_ops->head.vv_mount; + tmp = (struct tmpfs_mount *) mp->mnt_data; + + if (ap->a_ctllen != sizeof(struct export_args)) + rc = (EINVAL); + else + rc = vfs_export(mp, &tmp->tm_export, + (const struct export_args *) ap->a_ctl); + break; + default: + rc = vop_stdmountctl(ap); + break; + } + return (rc); +} + /* --------------------------------------------------------------------- */ static int @@ -1699,6 +1727,7 @@ struct vop_ops tmpfs_vnode_vops = { .vop_read = tmpfs_read, .vop_write = tmpfs_write, .vop_fsync = tmpfs_fsync, + .vop_mountctl = tmpfs_mountctl, .vop_nremove = tmpfs_nremove, .vop_nlink = tmpfs_nlink, .vop_nrename = tmpfs_nrename, -- 2.41.0