portal_vfsops.c revision 12769
1/* 2 * Copyright (c) 1992, 1993 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.6 (Berkeley) 1/21/94 37 * 38 * $Id: portal_vfsops.c,v 1.9 1995/11/16 11:24:06 bde 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/time.h> 49#include <sys/types.h> 50#include <sys/proc.h> 51#include <sys/filedesc.h> 52#include <sys/file.h> 53#include <sys/vnode.h> 54#include <sys/mount.h> 55#include <sys/namei.h> 56#include <sys/malloc.h> 57#include <sys/mbuf.h> 58#include <sys/socket.h> 59#include <sys/socketvar.h> 60#include <sys/protosw.h> 61#include <sys/domain.h> 62#include <sys/un.h> 63#include <miscfs/portal/portal.h> 64 65static int portal_init __P((void)); 66static int portal_mount __P((struct mount *mp, char *path, caddr_t data, 67 struct nameidata *ndp, struct proc *p)); 68static int portal_start __P((struct mount *mp, int flags, struct proc *p)); 69static int portal_unmount __P((struct mount *mp, int mntflags, 70 struct proc *p)); 71static int portal_root __P((struct mount *mp, struct vnode **vpp)); 72static int portal_quotactl __P((struct mount *mp, int cmd, uid_t uid, 73 caddr_t arg, struct proc *p)); 74static int portal_statfs __P((struct mount *mp, struct statfs *sbp, 75 struct proc *p)); 76static int portal_sync __P((struct mount *mp, int waitfor, 77 struct ucred *cred, struct proc *p)); 78static int portal_vget __P((struct mount *mp, ino_t ino, 79 struct vnode **vpp)); 80static int portal_fhtovp __P((struct mount *mp, struct fid *fhp, 81 struct mbuf *nam, struct vnode **vpp, 82 int *exflagsp, struct ucred **credanonp)); 83static int portal_vptofh __P((struct vnode *vp, struct fid *fhp)); 84 85static int 86portal_init() 87{ 88 89 return (0); 90} 91 92/* 93 * Mount the per-process file descriptors (/dev/fd) 94 */ 95static int 96portal_mount(mp, path, data, ndp, p) 97 struct mount *mp; 98 char *path; 99 caddr_t data; 100 struct nameidata *ndp; 101 struct proc *p; 102{ 103 struct file *fp; 104 struct portal_args args; 105 struct portalmount *fmp; 106 struct socket *so; 107 struct vnode *rvp; 108 u_int size; 109 int error; 110 111 /* 112 * Update is a no-op 113 */ 114 if (mp->mnt_flag & MNT_UPDATE) 115 return (EOPNOTSUPP); 116 117 error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)); 118 if (error) 119 return (error); 120 121 error = getsock(p->p_fd, args.pa_socket, &fp); 122 if (error) 123 return (error); 124 so = (struct socket *) fp->f_data; 125 if (so->so_proto->pr_domain->dom_family != AF_UNIX) 126 return (ESOCKTNOSUPPORT); 127 128 error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */ 129 if (error) 130 return (error); 131 MALLOC(rvp->v_data, void *, sizeof(struct portalnode), 132 M_TEMP, M_WAITOK); 133 134 fmp = (struct portalmount *) malloc(sizeof(struct portalmount), 135 M_UFSMNT, M_WAITOK); /* XXX */ 136 rvp->v_type = VDIR; 137 rvp->v_flag |= VROOT; 138 VTOPORTAL(rvp)->pt_arg = 0; 139 VTOPORTAL(rvp)->pt_size = 0; 140 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID; 141 fmp->pm_root = rvp; 142 fmp->pm_server = fp; fp->f_count++; 143 144 mp->mnt_flag |= MNT_LOCAL; 145 mp->mnt_data = (qaddr_t) fmp; 146 getnewfsid(mp, MOUNT_PORTAL); 147 148 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 149 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 150 (void)copyinstr(args.pa_config, 151 mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size); 152 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 153 154#ifdef notdef 155 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); 156 bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal")); 157#endif 158 159 return (0); 160} 161 162static int 163portal_start(mp, flags, p) 164 struct mount *mp; 165 int flags; 166 struct proc *p; 167{ 168 169 return (0); 170} 171 172static int 173portal_unmount(mp, mntflags, p) 174 struct mount *mp; 175 int mntflags; 176 struct proc *p; 177{ 178 struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root; 179 int error, flags = 0; 180 181 182 if (mntflags & MNT_FORCE) { 183 /* portal can never be rootfs so don't check for it */ 184 if (!doforce) 185 return (EINVAL); 186 flags |= FORCECLOSE; 187 } 188 189 /* 190 * Clear out buffer cache. I don't think we 191 * ever get anything cached at this level at the 192 * moment, but who knows... 193 */ 194#ifdef notyet 195 mntflushbuf(mp, 0); 196 if (mntinvalbuf(mp, 1)) 197 return (EBUSY); 198#endif 199 if (rootvp->v_usecount > 1) 200 return (EBUSY); 201 error = vflush(mp, rootvp, flags); 202 if (error) 203 return (error); 204 205 /* 206 * Release reference on underlying root vnode 207 */ 208 vrele(rootvp); 209 /* 210 * And blow it away for future re-use 211 */ 212 vgone(rootvp); 213 /* 214 * Shutdown the socket. This will cause the select in the 215 * daemon to wake up, and then the accept will get ECONNABORTED 216 * which it interprets as a request to go and bury itself. 217 */ 218 soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2); 219 /* 220 * Discard reference to underlying file. Must call closef because 221 * this may be the last reference. 222 */ 223 closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0); 224 /* 225 * Finally, throw away the portalmount structure 226 */ 227 free(mp->mnt_data, M_UFSMNT); /* XXX */ 228 mp->mnt_data = 0; 229 return (0); 230} 231 232static int 233portal_root(mp, vpp) 234 struct mount *mp; 235 struct vnode **vpp; 236{ 237 struct vnode *vp; 238 239 240 /* 241 * Return locked reference to root. 242 */ 243 vp = VFSTOPORTAL(mp)->pm_root; 244 VREF(vp); 245 VOP_LOCK(vp); 246 *vpp = vp; 247 return (0); 248} 249 250static int 251portal_quotactl(mp, cmd, uid, arg, p) 252 struct mount *mp; 253 int cmd; 254 uid_t uid; 255 caddr_t arg; 256 struct proc *p; 257{ 258 259 return (EOPNOTSUPP); 260} 261 262static int 263portal_statfs(mp, sbp, p) 264 struct mount *mp; 265 struct statfs *sbp; 266 struct proc *p; 267{ 268 269 sbp->f_type = MOUNT_PORTAL; 270 sbp->f_flags = 0; 271 sbp->f_bsize = DEV_BSIZE; 272 sbp->f_iosize = DEV_BSIZE; 273 sbp->f_blocks = 2; /* 1K to keep df happy */ 274 sbp->f_bfree = 0; 275 sbp->f_bavail = 0; 276 sbp->f_files = 1; /* Allow for "." */ 277 sbp->f_ffree = 0; /* See comments above */ 278 if (sbp != &mp->mnt_stat) { 279 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 280 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 281 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 282 } 283 return (0); 284} 285 286static int 287portal_sync(mp, waitfor, cred, p) 288 struct mount *mp; 289 int waitfor; 290 struct ucred *cred; 291 struct proc *p; 292{ 293 294 return (0); 295} 296 297static int 298portal_vget(mp, ino, vpp) 299 struct mount *mp; 300 ino_t ino; 301 struct vnode **vpp; 302{ 303 304 return (EOPNOTSUPP); 305} 306 307static int 308portal_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp) 309 struct mount *mp; 310 struct fid *fhp; 311 struct mbuf *nam; 312 struct vnode **vpp; 313 int *exflagsp; 314 struct ucred **credanonp; 315{ 316 317 return (EOPNOTSUPP); 318} 319 320static int 321portal_vptofh(vp, fhp) 322 struct vnode *vp; 323 struct fid *fhp; 324{ 325 326 return (EOPNOTSUPP); 327} 328 329static struct vfsops portal_vfsops = { 330 portal_mount, 331 portal_start, 332 portal_unmount, 333 portal_root, 334 portal_quotactl, 335 portal_statfs, 336 portal_sync, 337 portal_vget, 338 portal_fhtovp, 339 portal_vptofh, 340 portal_init, 341}; 342 343VFS_SET(portal_vfsops, portal, MOUNT_PORTAL, VFCF_SYNTHETIC); 344