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