153845Spendry /* 263246Sbostic * Copyright (c) 1992, 1993 363246Sbostic * The Regents of the University of California. All rights reserved. 453845Spendry * All rights reserved. 553845Spendry * 653845Spendry * This code is derived from software donated to Berkeley by 753845Spendry * Jan-Simon Pendry. 853845Spendry * 953845Spendry * %sccs.include.redist.c% 1053845Spendry * 11*65516Spendry * @(#)portal_vfsops.c 8.5 (Berkeley) 01/05/94 1253845Spendry * 1353845Spendry * $Id: portal_vfsops.c,v 1.5 1992/05/30 10:25:27 jsp Exp jsp $ 1453845Spendry */ 1553845Spendry 1653845Spendry /* 1753845Spendry * Portal Filesystem 1853845Spendry */ 1953845Spendry 2053845Spendry #include <sys/param.h> 2153845Spendry #include <sys/systm.h> 2253845Spendry #include <sys/time.h> 2353845Spendry #include <sys/types.h> 2453845Spendry #include <sys/proc.h> 2553845Spendry #include <sys/filedesc.h> 2653845Spendry #include <sys/file.h> 2753845Spendry #include <sys/vnode.h> 2853845Spendry #include <sys/mount.h> 2953845Spendry #include <sys/namei.h> 3053845Spendry #include <sys/malloc.h> 3153845Spendry #include <sys/mbuf.h> 3253845Spendry #include <sys/socket.h> 3353845Spendry #include <sys/socketvar.h> 3453845Spendry #include <sys/protosw.h> 3553845Spendry #include <sys/domain.h> 3653845Spendry #include <sys/un.h> 3755027Smckusick #include <miscfs/portal/portal.h> 3853845Spendry 3965449Sbostic int 4065449Sbostic portal_init() 4153845Spendry { 4255027Smckusick 43*65516Spendry return (0); 4453845Spendry } 4553845Spendry 4653845Spendry /* 4753845Spendry * Mount the per-process file descriptors (/dev/fd) 4853845Spendry */ 49*65516Spendry 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; 9853845Spendry getnewfsid(mp, MOUNT_PORTAL); 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 114*65516Spendry 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 124*65516Spendry 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 */ 16453845Spendry vgone(rootvp); 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 184*65516Spendry 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 202*65516Spendry int 20353845Spendry portal_quotactl(mp, cmd, uid, arg, p) 20453845Spendry struct mount *mp; 20553845Spendry int cmd; 20653845Spendry uid_t uid; 20753845Spendry caddr_t arg; 20853845Spendry struct proc *p; 20953845Spendry { 21055027Smckusick 21153845Spendry return (EOPNOTSUPP); 21253845Spendry } 21353845Spendry 214*65516Spendry int 21553845Spendry portal_statfs(mp, sbp, p) 21653845Spendry struct mount *mp; 21753845Spendry struct statfs *sbp; 21853845Spendry struct proc *p; 21953845Spendry { 22053845Spendry 22153845Spendry sbp->f_type = MOUNT_PORTAL; 22253845Spendry sbp->f_flags = 0; 22353845Spendry sbp->f_bsize = DEV_BSIZE; 22453845Spendry sbp->f_iosize = DEV_BSIZE; 22553845Spendry sbp->f_blocks = 2; /* 1K to keep df happy */ 22653845Spendry sbp->f_bfree = 0; 22753845Spendry sbp->f_bavail = 0; 22853845Spendry sbp->f_files = 1; /* Allow for "." */ 22953845Spendry sbp->f_ffree = 0; /* See comments above */ 23053845Spendry if (sbp != &mp->mnt_stat) { 23153845Spendry bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 23253845Spendry bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 23353845Spendry bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 23453845Spendry } 23553845Spendry return (0); 23653845Spendry } 23753845Spendry 238*65516Spendry int 23953845Spendry portal_sync(mp, waitfor) 24053845Spendry struct mount *mp; 24153845Spendry int waitfor; 24253845Spendry { 24355027Smckusick 24453845Spendry return (0); 24553845Spendry } 24653845Spendry 247*65516Spendry int 24854977Spendry portal_vget(mp, ino, vpp) 24954977Spendry struct mount *mp; 25054977Spendry ino_t ino; 25154977Spendry struct vnode **vpp; 25254977Spendry { 25354977Spendry 25454977Spendry return (EOPNOTSUPP); 25554977Spendry } 25654977Spendry 257*65516Spendry int 25853845Spendry portal_fhtovp(mp, fhp, vpp) 25953845Spendry struct mount *mp; 26053845Spendry struct fid *fhp; 26153845Spendry struct vnode **vpp; 26253845Spendry { 26355027Smckusick 26453845Spendry return (EOPNOTSUPP); 26553845Spendry } 26653845Spendry 267*65516Spendry int 26853845Spendry portal_vptofh(vp, fhp) 26953845Spendry struct vnode *vp; 27053845Spendry struct fid *fhp; 27153845Spendry { 27255027Smckusick 27353845Spendry return (EOPNOTSUPP); 27453845Spendry } 27553845Spendry 27653845Spendry struct vfsops portal_vfsops = { 27753845Spendry portal_mount, 27853845Spendry portal_start, 27953845Spendry portal_unmount, 28053845Spendry portal_root, 28153845Spendry portal_quotactl, 28253845Spendry portal_statfs, 28353845Spendry portal_sync, 28454977Spendry portal_vget, 28553845Spendry portal_fhtovp, 28653845Spendry portal_vptofh, 28753845Spendry portal_init, 28853845Spendry }; 289