tmpfs: Support NFS export of tmpfs filesystems.
authorVenkatesh Srinivas <me@endeavour.zapto.org>
Tue, 31 Jan 2012 05:15:24 +0000 (00:15 -0500)
committerThomas Nikolajsen <thomas@dragonflybsd.org>
Sat, 18 Feb 2012 10:06:41 +0000 (11:06 +0100)
* 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
sys/vfs/tmpfs/tmpfs_vfsops.c
sys/vfs/tmpfs/tmpfs_vnops.c

index 4404cc6..609b1c1 100644 (file)
@@ -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)
index 940643a..55b2ffc 100644 (file)
@@ -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);
index 15a81e1..e8be50c 100644 (file)
@@ -48,6 +48,7 @@
 #include <sys/unistd.h>
 #include <sys/vfsops.h>
 #include <sys/vnode.h>
+#include <sys/mountctl.h>
 
 #include <vm/vm.h>
 #include <vm/vm_object.h>
@@ -1499,6 +1500,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
@@ -1700,6 +1728,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,