portal_vfsops.c revision 30354
1/* 2 * Copyright (c) 1992, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software donated to Berkeley by 6 * Jan-Simon Pendry. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)portal_vfsops.c 8.11 (Berkeley) 5/14/95 37 * 38 * $Id: portal_vfsops.c,v 1.17 1997/08/16 19:15:17 wollman Exp $ 39 */ 40 41/* 42 * Portal Filesystem 43 */ 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/proc.h> 49#include <sys/filedesc.h> 50#include <sys/file.h> 51#include <sys/vnode.h> 52#include <sys/mount.h> 53#include <sys/malloc.h> 54#include <sys/socket.h> 55#include <sys/socketvar.h> 56#include <sys/protosw.h> 57#include <sys/domain.h> 58#include <miscfs/portal/portal.h> 59 60static MALLOC_DEFINE(M_PORTALFSMNT, "PORTAL mount", "PORTAL mount structure"); 61 62static int portal_init __P((struct vfsconf *)); 63static int portal_mount __P((struct mount *mp, char *path, caddr_t data, 64 struct nameidata *ndp, struct proc *p)); 65static int portal_start __P((struct mount *mp, int flags, struct proc *p)); 66static int portal_unmount __P((struct mount *mp, int mntflags, 67 struct proc *p)); 68static int portal_root __P((struct mount *mp, struct vnode **vpp)); 69static int portal_statfs __P((struct mount *mp, struct statfs *sbp, 70 struct proc *p)); 71 72static int 73portal_init(vfsp) 74 struct vfsconf *vfsp; 75{ 76 77 return (0); 78} 79 80/* 81 * Mount the per-process file descriptors (/dev/fd) 82 */ 83static int 84portal_mount(mp, path, data, ndp, p) 85 struct mount *mp; 86 char *path; 87 caddr_t data; 88 struct nameidata *ndp; 89 struct proc *p; 90{ 91 struct file *fp; 92 struct portal_args args; 93 struct portalmount *fmp; 94 struct socket *so; 95 struct vnode *rvp; 96 struct portalnode *pn; 97 u_int size; 98 int error; 99 100 /* 101 * Update is a no-op 102 */ 103 if (mp->mnt_flag & MNT_UPDATE) 104 return (EOPNOTSUPP); 105 106 error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)); 107 if (error) 108 return (error); 109 110 error = getsock(p->p_fd, args.pa_socket, &fp); 111 if (error) 112 return (error); 113 so = (struct socket *) fp->f_data; 114 if (so->so_proto->pr_domain->dom_family != AF_UNIX) 115 return (ESOCKTNOSUPPORT); 116 117 MALLOC(pn, struct portalnode *, sizeof(struct portalnode), 118 M_TEMP, M_WAITOK); 119 120 MALLOC(fmp, struct portalmount *, sizeof(struct portalmount), 121 M_PORTALFSMNT, M_WAITOK); /* XXX */ 122 123 error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */ 124 if (error) { 125 FREE(fmp, M_PORTALFSMNT); 126 FREE(pn, M_TEMP); 127 return (error); 128 } 129 130 rvp->v_data = pn; 131 rvp->v_type = VDIR; 132 rvp->v_flag |= VROOT; 133 VTOPORTAL(rvp)->pt_arg = 0; 134 VTOPORTAL(rvp)->pt_size = 0; 135 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID; 136 fmp->pm_root = rvp; 137 fmp->pm_server = fp; fp->f_count++; 138 139 mp->mnt_flag |= MNT_LOCAL; 140 mp->mnt_data = (qaddr_t) fmp; 141 vfs_getnewfsid(mp); 142 143 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 144 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 145 (void)copyinstr(args.pa_config, 146 mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); 147 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 148 149#ifdef notdef 150 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); 151 bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal")); 152#endif 153 154 return (0); 155} 156 157static int 158portal_start(mp, flags, p) 159 struct mount *mp; 160 int flags; 161 struct proc *p; 162{ 163 164 return (0); 165} 166 167static int 168portal_unmount(mp, mntflags, p) 169 struct mount *mp; 170 int mntflags; 171 struct proc *p; 172{ 173 struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root; 174 int error, flags = 0; 175 176 177 if (mntflags & MNT_FORCE) 178 flags |= FORCECLOSE; 179 180 /* 181 * Clear out buffer cache. I don't think we 182 * ever get anything cached at this level at the 183 * moment, but who knows... 184 */ 185#ifdef notyet 186 mntflushbuf(mp, 0); 187 if (mntinvalbuf(mp, 1)) 188 return (EBUSY); 189#endif 190 if (rootvp->v_usecount > 1) 191 return (EBUSY); 192 error = vflush(mp, rootvp, flags); 193 if (error) 194 return (error); 195 196 /* 197 * Release reference on underlying root vnode 198 */ 199 vrele(rootvp); 200 /* 201 * And blow it away for future re-use 202 */ 203 vgone(rootvp); 204 /* 205 * Shutdown the socket. This will cause the select in the 206 * daemon to wake up, and then the accept will get ECONNABORTED 207 * which it interprets as a request to go and bury itself. 208 */ 209 soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2); 210 /* 211 * Discard reference to underlying file. Must call closef because 212 * this may be the last reference. 213 */ 214 closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0); 215 /* 216 * Finally, throw away the portalmount structure 217 */ 218 free(mp->mnt_data, M_PORTALFSMNT); /* XXX */ 219 mp->mnt_data = 0; 220 return (0); 221} 222 223static int 224portal_root(mp, vpp) 225 struct mount *mp; 226 struct vnode **vpp; 227{ 228 struct proc *p = curproc; /* XXX */ 229 struct vnode *vp; 230 231 /* 232 * Return locked reference to root. 233 */ 234 vp = VFSTOPORTAL(mp)->pm_root; 235 VREF(vp); 236 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 237 *vpp = vp; 238 return (0); 239} 240 241static int 242portal_statfs(mp, sbp, p) 243 struct mount *mp; 244 struct statfs *sbp; 245 struct proc *p; 246{ 247 248 sbp->f_flags = 0; 249 sbp->f_bsize = DEV_BSIZE; 250 sbp->f_iosize = DEV_BSIZE; 251 sbp->f_blocks = 2; /* 1K to keep df happy */ 252 sbp->f_bfree = 0; 253 sbp->f_bavail = 0; 254 sbp->f_files = 1; /* Allow for "." */ 255 sbp->f_ffree = 0; /* See comments above */ 256 if (sbp != &mp->mnt_stat) { 257 sbp->f_type = mp->mnt_vfc->vfc_typenum; 258 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 259 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 260 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 261 } 262 return (0); 263} 264 265#define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \ 266 struct sockaddr *, struct vnode **, int *, struct ucred **)))eopnotsupp) 267#define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \ 268 struct proc *)))eopnotsupp) 269#define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \ 270 struct proc *)))nullop) 271#define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ 272 size_t, struct proc *)))eopnotsupp) 273#define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \ 274 eopnotsupp) 275#define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp) 276 277static struct vfsops portal_vfsops = { 278 portal_mount, 279 portal_start, 280 portal_unmount, 281 portal_root, 282 portal_quotactl, 283 portal_statfs, 284 portal_sync, 285 portal_vget, 286 portal_fhtovp, 287 portal_vptofh, 288 portal_init, 289}; 290 291VFS_SET(portal_vfsops, portal, MOUNT_PORTAL, VFCF_SYNTHETIC); 292