portal_vfsops.c revision 2946
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1992, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software donated to Berkeley by 61541Srgrimes * Jan-Simon Pendry. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341541Srgrimes * SUCH DAMAGE. 351541Srgrimes * 361541Srgrimes * @(#)portal_vfsops.c 8.6 (Berkeley) 1/21/94 371541Srgrimes * 382946Swollman * $Id: portal_vfsops.c,v 1.1.1.1 1994/05/24 10:05:06 rgrimes Exp $ 391541Srgrimes */ 401541Srgrimes 411541Srgrimes/* 421541Srgrimes * Portal Filesystem 431541Srgrimes */ 441541Srgrimes 451541Srgrimes#include <sys/param.h> 461541Srgrimes#include <sys/systm.h> 471541Srgrimes#include <sys/time.h> 481541Srgrimes#include <sys/types.h> 491541Srgrimes#include <sys/proc.h> 501541Srgrimes#include <sys/filedesc.h> 511541Srgrimes#include <sys/file.h> 521541Srgrimes#include <sys/vnode.h> 531541Srgrimes#include <sys/mount.h> 541541Srgrimes#include <sys/namei.h> 551541Srgrimes#include <sys/malloc.h> 561541Srgrimes#include <sys/mbuf.h> 571541Srgrimes#include <sys/socket.h> 581541Srgrimes#include <sys/socketvar.h> 591541Srgrimes#include <sys/protosw.h> 601541Srgrimes#include <sys/domain.h> 611541Srgrimes#include <sys/un.h> 621541Srgrimes#include <miscfs/portal/portal.h> 631541Srgrimes 641541Srgrimesint 651541Srgrimesportal_init() 661541Srgrimes{ 671541Srgrimes 681541Srgrimes return (0); 691541Srgrimes} 701541Srgrimes 711541Srgrimes/* 721541Srgrimes * Mount the per-process file descriptors (/dev/fd) 731541Srgrimes */ 741541Srgrimesint 751541Srgrimesportal_mount(mp, path, data, ndp, p) 761541Srgrimes struct mount *mp; 771541Srgrimes char *path; 781541Srgrimes caddr_t data; 791541Srgrimes struct nameidata *ndp; 801541Srgrimes struct proc *p; 811541Srgrimes{ 821541Srgrimes struct file *fp; 831541Srgrimes struct portal_args args; 841541Srgrimes struct portalmount *fmp; 851541Srgrimes struct socket *so; 861541Srgrimes struct vnode *rvp; 871541Srgrimes u_int size; 881541Srgrimes int error; 891541Srgrimes 901541Srgrimes /* 911541Srgrimes * Update is a no-op 921541Srgrimes */ 931541Srgrimes if (mp->mnt_flag & MNT_UPDATE) 941541Srgrimes return (EOPNOTSUPP); 951541Srgrimes 961541Srgrimes if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args))) 971541Srgrimes return (error); 981541Srgrimes 991541Srgrimes if (error = getsock(p->p_fd, args.pa_socket, &fp)) 1001541Srgrimes return (error); 1011541Srgrimes so = (struct socket *) fp->f_data; 1021541Srgrimes if (so->so_proto->pr_domain->dom_family != AF_UNIX) 1031541Srgrimes return (ESOCKTNOSUPPORT); 1041541Srgrimes 1051541Srgrimes error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */ 1061541Srgrimes if (error) 1071541Srgrimes return (error); 1081541Srgrimes MALLOC(rvp->v_data, void *, sizeof(struct portalnode), 1091541Srgrimes M_TEMP, M_WAITOK); 1101541Srgrimes 1111541Srgrimes fmp = (struct portalmount *) malloc(sizeof(struct portalmount), 1121541Srgrimes M_UFSMNT, M_WAITOK); /* XXX */ 1131541Srgrimes rvp->v_type = VDIR; 1141541Srgrimes rvp->v_flag |= VROOT; 1151541Srgrimes VTOPORTAL(rvp)->pt_arg = 0; 1161541Srgrimes VTOPORTAL(rvp)->pt_size = 0; 1171541Srgrimes VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID; 1181541Srgrimes fmp->pm_root = rvp; 1191541Srgrimes fmp->pm_server = fp; fp->f_count++; 1201541Srgrimes 1211541Srgrimes mp->mnt_flag |= MNT_LOCAL; 1221541Srgrimes mp->mnt_data = (qaddr_t) fmp; 1231541Srgrimes getnewfsid(mp, MOUNT_PORTAL); 1241541Srgrimes 1251541Srgrimes (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 1261541Srgrimes bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 1271541Srgrimes (void)copyinstr(args.pa_config, 1281541Srgrimes mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); 1291541Srgrimes bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 1301541Srgrimes 1311541Srgrimes#ifdef notdef 1321541Srgrimes bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); 1331541Srgrimes bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal")); 1341541Srgrimes#endif 1351541Srgrimes 1361541Srgrimes return (0); 1371541Srgrimes} 1381541Srgrimes 1391541Srgrimesint 1401541Srgrimesportal_start(mp, flags, p) 1411541Srgrimes struct mount *mp; 1421541Srgrimes int flags; 1431541Srgrimes struct proc *p; 1441541Srgrimes{ 1451541Srgrimes 1461541Srgrimes return (0); 1471541Srgrimes} 1481541Srgrimes 1491541Srgrimesint 1501541Srgrimesportal_unmount(mp, mntflags, p) 1511541Srgrimes struct mount *mp; 1521541Srgrimes int mntflags; 1531541Srgrimes struct proc *p; 1541541Srgrimes{ 1551541Srgrimes extern int doforce; 1561541Srgrimes struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root; 1571541Srgrimes int error, flags = 0; 1581541Srgrimes 1591541Srgrimes 1601541Srgrimes if (mntflags & MNT_FORCE) { 1611541Srgrimes /* portal can never be rootfs so don't check for it */ 1621541Srgrimes if (!doforce) 1631541Srgrimes return (EINVAL); 1641541Srgrimes flags |= FORCECLOSE; 1651541Srgrimes } 1661541Srgrimes 1671541Srgrimes /* 1681541Srgrimes * Clear out buffer cache. I don't think we 1691541Srgrimes * ever get anything cached at this level at the 1701541Srgrimes * moment, but who knows... 1711541Srgrimes */ 1721541Srgrimes#ifdef notyet 1731541Srgrimes mntflushbuf(mp, 0); 1741541Srgrimes if (mntinvalbuf(mp, 1)) 1751541Srgrimes return (EBUSY); 1761541Srgrimes#endif 1771541Srgrimes if (rootvp->v_usecount > 1) 1781541Srgrimes return (EBUSY); 1791541Srgrimes if (error = vflush(mp, rootvp, flags)) 1801541Srgrimes return (error); 1811541Srgrimes 1821541Srgrimes /* 1831541Srgrimes * Release reference on underlying root vnode 1841541Srgrimes */ 1851541Srgrimes vrele(rootvp); 1861541Srgrimes /* 1871541Srgrimes * And blow it away for future re-use 1881541Srgrimes */ 1891541Srgrimes vgone(rootvp); 1901541Srgrimes /* 1911541Srgrimes * Shutdown the socket. This will cause the select in the 1921541Srgrimes * daemon to wake up, and then the accept will get ECONNABORTED 1931541Srgrimes * which it interprets as a request to go and bury itself. 1941541Srgrimes */ 1951541Srgrimes soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2); 1961541Srgrimes /* 1971541Srgrimes * Discard reference to underlying file. Must call closef because 1981541Srgrimes * this may be the last reference. 1991541Srgrimes */ 2001541Srgrimes closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0); 2011541Srgrimes /* 2021541Srgrimes * Finally, throw away the portalmount structure 2031541Srgrimes */ 2041541Srgrimes free(mp->mnt_data, M_UFSMNT); /* XXX */ 2051541Srgrimes mp->mnt_data = 0; 2061541Srgrimes return (0); 2071541Srgrimes} 2081541Srgrimes 2091541Srgrimesint 2101541Srgrimesportal_root(mp, vpp) 2111541Srgrimes struct mount *mp; 2121541Srgrimes struct vnode **vpp; 2131541Srgrimes{ 2141541Srgrimes struct vnode *vp; 2151541Srgrimes 2161541Srgrimes 2171541Srgrimes /* 2181541Srgrimes * Return locked reference to root. 2191541Srgrimes */ 2201541Srgrimes vp = VFSTOPORTAL(mp)->pm_root; 2211541Srgrimes VREF(vp); 2221541Srgrimes VOP_LOCK(vp); 2231541Srgrimes *vpp = vp; 2241541Srgrimes return (0); 2251541Srgrimes} 2261541Srgrimes 2271541Srgrimesint 2281541Srgrimesportal_quotactl(mp, cmd, uid, arg, p) 2291541Srgrimes struct mount *mp; 2301541Srgrimes int cmd; 2311541Srgrimes uid_t uid; 2321541Srgrimes caddr_t arg; 2331541Srgrimes struct proc *p; 2341541Srgrimes{ 2351541Srgrimes 2361541Srgrimes return (EOPNOTSUPP); 2371541Srgrimes} 2381541Srgrimes 2391541Srgrimesint 2401541Srgrimesportal_statfs(mp, sbp, p) 2411541Srgrimes struct mount *mp; 2421541Srgrimes struct statfs *sbp; 2431541Srgrimes struct proc *p; 2441541Srgrimes{ 2451541Srgrimes 2461541Srgrimes sbp->f_type = MOUNT_PORTAL; 2471541Srgrimes sbp->f_flags = 0; 2481541Srgrimes sbp->f_bsize = DEV_BSIZE; 2491541Srgrimes sbp->f_iosize = DEV_BSIZE; 2501541Srgrimes sbp->f_blocks = 2; /* 1K to keep df happy */ 2511541Srgrimes sbp->f_bfree = 0; 2521541Srgrimes sbp->f_bavail = 0; 2531541Srgrimes sbp->f_files = 1; /* Allow for "." */ 2541541Srgrimes sbp->f_ffree = 0; /* See comments above */ 2551541Srgrimes if (sbp != &mp->mnt_stat) { 2561541Srgrimes bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 2571541Srgrimes bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 2581541Srgrimes bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 2591541Srgrimes } 2601541Srgrimes return (0); 2611541Srgrimes} 2621541Srgrimes 2631541Srgrimesint 2641541Srgrimesportal_sync(mp, waitfor) 2651541Srgrimes struct mount *mp; 2661541Srgrimes int waitfor; 2671541Srgrimes{ 2681541Srgrimes 2691541Srgrimes return (0); 2701541Srgrimes} 2711541Srgrimes 2721541Srgrimesint 2731541Srgrimesportal_vget(mp, ino, vpp) 2741541Srgrimes struct mount *mp; 2751541Srgrimes ino_t ino; 2761541Srgrimes struct vnode **vpp; 2771541Srgrimes{ 2781541Srgrimes 2791541Srgrimes return (EOPNOTSUPP); 2801541Srgrimes} 2811541Srgrimes 2821541Srgrimesint 2831541Srgrimesportal_fhtovp(mp, fhp, vpp) 2841541Srgrimes struct mount *mp; 2851541Srgrimes struct fid *fhp; 2861541Srgrimes struct vnode **vpp; 2871541Srgrimes{ 2881541Srgrimes 2891541Srgrimes return (EOPNOTSUPP); 2901541Srgrimes} 2911541Srgrimes 2921541Srgrimesint 2931541Srgrimesportal_vptofh(vp, fhp) 2941541Srgrimes struct vnode *vp; 2951541Srgrimes struct fid *fhp; 2961541Srgrimes{ 2971541Srgrimes 2981541Srgrimes return (EOPNOTSUPP); 2991541Srgrimes} 3001541Srgrimes 3011541Srgrimesstruct vfsops portal_vfsops = { 3021541Srgrimes portal_mount, 3031541Srgrimes portal_start, 3041541Srgrimes portal_unmount, 3051541Srgrimes portal_root, 3061541Srgrimes portal_quotactl, 3071541Srgrimes portal_statfs, 3081541Srgrimes portal_sync, 3091541Srgrimes portal_vget, 3101541Srgrimes portal_fhtovp, 3111541Srgrimes portal_vptofh, 3121541Srgrimes portal_init, 3131541Srgrimes}; 3142946Swollman 3152946SwollmanVFS_SET(portal_vfsops, portal, MOUNT_PORTAL, 0); 316