153845Spendry /* 263246Sbostic * Copyright (c) 1992, 1993 363246Sbostic * The Regents of the University of California. All rights reserved. 453845Spendry * 553845Spendry * This code is derived from software donated to Berkeley by 653845Spendry * Jan-Simon Pendry. 753845Spendry * 853845Spendry * %sccs.include.redist.c% 953845Spendry * 10*68619Smckusick * @(#)portal_vfsops.c 8.8 (Berkeley) 03/29/95 1153845Spendry * 1253845Spendry * $Id: portal_vfsops.c,v 1.5 1992/05/30 10:25:27 jsp Exp jsp $ 1353845Spendry */ 1453845Spendry 1553845Spendry /* 1653845Spendry * Portal Filesystem 1753845Spendry */ 1853845Spendry 1953845Spendry #include <sys/param.h> 2053845Spendry #include <sys/systm.h> 2153845Spendry #include <sys/time.h> 2253845Spendry #include <sys/types.h> 2353845Spendry #include <sys/proc.h> 2453845Spendry #include <sys/filedesc.h> 2553845Spendry #include <sys/file.h> 2653845Spendry #include <sys/vnode.h> 2753845Spendry #include <sys/mount.h> 2853845Spendry #include <sys/namei.h> 2953845Spendry #include <sys/malloc.h> 3053845Spendry #include <sys/mbuf.h> 3153845Spendry #include <sys/socket.h> 3253845Spendry #include <sys/socketvar.h> 3353845Spendry #include <sys/protosw.h> 3453845Spendry #include <sys/domain.h> 3553845Spendry #include <sys/un.h> 3655027Smckusick #include <miscfs/portal/portal.h> 3753845Spendry 3865449Sbostic int 39*68619Smckusick portal_init(vfsp) 40*68619Smckusick struct vfsconf *vfsp; 4153845Spendry { 4255027Smckusick 4365516Spendry return (0); 4453845Spendry } 4553845Spendry 4653845Spendry /* 4753845Spendry * Mount the per-process file descriptors (/dev/fd) 4853845Spendry */ 4965516Spendry int 5053845Spendry portal_mount(mp, path, data, ndp, p) 5153845Spendry struct mount *mp; 5253845Spendry char *path; 5353845Spendry caddr_t data; 5453845Spendry struct nameidata *ndp; 5553845Spendry struct proc *p; 5653845Spendry { 5765449Sbostic struct file *fp; 5853845Spendry struct portal_args args; 5953845Spendry struct portalmount *fmp; 6065449Sbostic struct socket *so; 6153845Spendry struct vnode *rvp; 6265449Sbostic u_int size; 6365449Sbostic int error; 6453845Spendry 6553845Spendry /* 6653845Spendry * Update is a no-op 6753845Spendry */ 6853845Spendry if (mp->mnt_flag & MNT_UPDATE) 6953845Spendry return (EOPNOTSUPP); 7053845Spendry 7153845Spendry if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args))) 7253845Spendry return (error); 7353845Spendry 7453845Spendry if (error = getsock(p->p_fd, args.pa_socket, &fp)) 7553845Spendry return (error); 7653845Spendry so = (struct socket *) fp->f_data; 7753845Spendry if (so->so_proto->pr_domain->dom_family != AF_UNIX) 7853845Spendry return (ESOCKTNOSUPPORT); 7953845Spendry 8065380Spendry error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */ 8153845Spendry if (error) 8253845Spendry return (error); 8353845Spendry MALLOC(rvp->v_data, void *, sizeof(struct portalnode), 8453845Spendry M_TEMP, M_WAITOK); 8553845Spendry 8653845Spendry fmp = (struct portalmount *) malloc(sizeof(struct portalmount), 8753845Spendry M_UFSMNT, M_WAITOK); /* XXX */ 8853845Spendry rvp->v_type = VDIR; 8953845Spendry rvp->v_flag |= VROOT; 9053845Spendry VTOPORTAL(rvp)->pt_arg = 0; 9153845Spendry VTOPORTAL(rvp)->pt_size = 0; 9253845Spendry VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID; 9353845Spendry fmp->pm_root = rvp; 9453845Spendry fmp->pm_server = fp; fp->f_count++; 9553845Spendry 9653845Spendry mp->mnt_flag |= MNT_LOCAL; 9753845Spendry mp->mnt_data = (qaddr_t) fmp; 98*68619Smckusick vfs_getnewfsid(mp); 9953845Spendry 10065449Sbostic (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 10153845Spendry bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 10265449Sbostic (void)copyinstr(args.pa_config, 10365449Sbostic mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); 10453845Spendry bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 10553845Spendry 10653845Spendry #ifdef notdef 10753845Spendry bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); 10853845Spendry bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal")); 10953845Spendry #endif 11053845Spendry 11153845Spendry return (0); 11253845Spendry } 11353845Spendry 11465516Spendry int 11553845Spendry portal_start(mp, flags, p) 11653845Spendry struct mount *mp; 11753845Spendry int flags; 11853845Spendry struct proc *p; 11953845Spendry { 12055027Smckusick 12153845Spendry return (0); 12253845Spendry } 12353845Spendry 12465516Spendry int 12553845Spendry portal_unmount(mp, mntflags, p) 12653845Spendry struct mount *mp; 12753845Spendry int mntflags; 12853845Spendry struct proc *p; 12953845Spendry { 13053845Spendry extern int doforce; 13153845Spendry struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root; 13265448Sbostic int error, flags = 0; 13353845Spendry 13453845Spendry 13553845Spendry if (mntflags & MNT_FORCE) { 13653845Spendry /* portal can never be rootfs so don't check for it */ 13753845Spendry if (!doforce) 13853845Spendry return (EINVAL); 13953845Spendry flags |= FORCECLOSE; 14053845Spendry } 14153845Spendry 14253845Spendry /* 14353845Spendry * Clear out buffer cache. I don't think we 14453845Spendry * ever get anything cached at this level at the 14553845Spendry * moment, but who knows... 14653845Spendry */ 14755027Smckusick #ifdef notyet 14853845Spendry mntflushbuf(mp, 0); 14953845Spendry if (mntinvalbuf(mp, 1)) 15053845Spendry return (EBUSY); 15154977Spendry #endif 15253845Spendry if (rootvp->v_usecount > 1) 15353845Spendry return (EBUSY); 15453845Spendry if (error = vflush(mp, rootvp, flags)) 15553845Spendry return (error); 15653845Spendry 15753845Spendry /* 15853845Spendry * Release reference on underlying root vnode 15953845Spendry */ 16053845Spendry vrele(rootvp); 16153845Spendry /* 16253845Spendry * And blow it away for future re-use 16353845Spendry */ 16468428Smckusick VOP_REVOKE(rootvp, 0); 16553845Spendry /* 16653845Spendry * Shutdown the socket. This will cause the select in the 16753845Spendry * daemon to wake up, and then the accept will get ECONNABORTED 16853845Spendry * which it interprets as a request to go and bury itself. 16953845Spendry */ 17053845Spendry soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2); 17153845Spendry /* 17253845Spendry * Discard reference to underlying file. Must call closef because 17353845Spendry * this may be the last reference. 17453845Spendry */ 17553845Spendry closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0); 17653845Spendry /* 17753845Spendry * Finally, throw away the portalmount structure 17853845Spendry */ 17953845Spendry free(mp->mnt_data, M_UFSMNT); /* XXX */ 18053845Spendry mp->mnt_data = 0; 18155027Smckusick return (0); 18253845Spendry } 18353845Spendry 18465516Spendry int 18553845Spendry portal_root(mp, vpp) 18653845Spendry struct mount *mp; 18753845Spendry struct vnode **vpp; 18853845Spendry { 18953845Spendry struct vnode *vp; 19053845Spendry 19153845Spendry 19253845Spendry /* 19353845Spendry * Return locked reference to root. 19453845Spendry */ 19553845Spendry vp = VFSTOPORTAL(mp)->pm_root; 19653845Spendry VREF(vp); 19753845Spendry VOP_LOCK(vp); 19853845Spendry *vpp = vp; 19953845Spendry return (0); 20053845Spendry } 20153845Spendry 20265516Spendry int 20353845Spendry portal_statfs(mp, sbp, p) 20453845Spendry struct mount *mp; 20553845Spendry struct statfs *sbp; 20653845Spendry struct proc *p; 20753845Spendry { 20853845Spendry 20953845Spendry sbp->f_flags = 0; 21053845Spendry sbp->f_bsize = DEV_BSIZE; 21153845Spendry sbp->f_iosize = DEV_BSIZE; 21253845Spendry sbp->f_blocks = 2; /* 1K to keep df happy */ 21353845Spendry sbp->f_bfree = 0; 21453845Spendry sbp->f_bavail = 0; 21553845Spendry sbp->f_files = 1; /* Allow for "." */ 21653845Spendry sbp->f_ffree = 0; /* See comments above */ 21753845Spendry if (sbp != &mp->mnt_stat) { 218*68619Smckusick sbp->f_type = mp->mnt_vfc->vfc_typenum; 21953845Spendry bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 22053845Spendry bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 22153845Spendry bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 22253845Spendry } 22353845Spendry return (0); 22453845Spendry } 22553845Spendry 226*68619Smckusick #define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \ 227*68619Smckusick struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp) 228*68619Smckusick #define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \ 229*68619Smckusick struct proc *)))eopnotsupp) 230*68619Smckusick #define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \ 231*68619Smckusick struct proc *)))nullop) 232*68619Smckusick #define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ 233*68619Smckusick size_t, struct proc *)))eopnotsupp) 234*68619Smckusick #define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \ 235*68619Smckusick eopnotsupp) 236*68619Smckusick #define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp) 23755027Smckusick 23853845Spendry struct vfsops portal_vfsops = { 23953845Spendry portal_mount, 24053845Spendry portal_start, 24153845Spendry portal_unmount, 24253845Spendry portal_root, 24353845Spendry portal_quotactl, 24453845Spendry portal_statfs, 24553845Spendry portal_sync, 24654977Spendry portal_vget, 24753845Spendry portal_fhtovp, 24853845Spendry portal_vptofh, 24953845Spendry portal_init, 250*68619Smckusick portal_sysctl, 25153845Spendry }; 252