2 * Copyright (c) 1992, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software donated to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)portal_vfsops.c 8.11 (Berkeley) 5/14/95
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/domain.h>
44 #include <sys/filedesc.h>
45 #include <sys/kernel.h>
47 #include <sys/mutex.h>
48 #include <sys/malloc.h>
49 #include <sys/file.h> /* Must come after sys/malloc.h */
50 #include <sys/mount.h>
52 #include <sys/protosw.h>
53 #include <sys/socket.h>
54 #include <sys/socketvar.h>
55 #include <sys/vnode.h>
57 #include <fs/portalfs/portal.h>
59 static MALLOC_DEFINE(M_PORTALFSMNT, "portal_mount", "PORTAL mount structure");
61 static vfs_unmount_t portal_unmount;
62 static vfs_root_t portal_root;
63 static vfs_statfs_t portal_statfs;
65 static const char *portal_opts[] = {
71 portal_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
73 struct portal_args args;
78 error = copyin(data, &args, sizeof args);
82 ma = mount_argf(ma, "socket", "%d", args.pa_socket);
83 ma = mount_argsu(ma, "config", args.pa_config, MAXPATHLEN);
84 error = kernel_mount(ma, flags);
90 * Mount the per-process file descriptors (/dev/fd)
93 portal_mount(struct mount *mp, struct thread *td)
96 struct portalmount *fmp;
99 struct portalnode *pn;
103 if (vfs_filteropt(mp->mnt_optnew, portal_opts))
106 error = vfs_scanopt(mp->mnt_optnew, "socket", "%d", &v);
109 error = vfs_getopt(mp->mnt_optnew, "config", (void **)&p, NULL);
113 if ((error = fget(td, v, &fp)) != 0)
115 if (fp->f_type != DTYPE_SOCKET) {
119 so = fp->f_data; /* XXX race against userland */
120 if (so->so_proto->pr_domain->dom_family != AF_UNIX) {
122 return (ESOCKTNOSUPPORT);
125 MALLOC(pn, struct portalnode *, sizeof(struct portalnode),
128 MALLOC(fmp, struct portalmount *, sizeof(struct portalmount),
129 M_PORTALFSMNT, M_WAITOK); /* XXX */
131 error = getnewvnode("portal", mp, &portal_vnodeops, &rvp); /* XXX */
133 FREE(fmp, M_PORTALFSMNT);
139 error = insmntque(rvp, mp); /* XXX: Too early for mpsafe fs */
141 FREE(fmp, M_PORTALFSMNT);
148 rvp->v_vflag |= VV_ROOT;
149 VTOPORTAL(rvp)->pt_arg = 0;
150 VTOPORTAL(rvp)->pt_size = 0;
151 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
157 mp->mnt_flag |= MNT_LOCAL;
159 mp->mnt_data = (qaddr_t) fmp;
162 vfs_mountedfrom(mp, p);
168 portal_unmount(mp, mntflags, td)
173 int error, flags = 0;
176 if (mntflags & MNT_FORCE)
180 * Clear out buffer cache. I don't think we
181 * ever get anything cached at this level at the
182 * moment, but who knows...
186 if (mntinvalbuf(mp, 1))
189 /* There is 1 extra root vnode reference (pm_root). */
190 error = vflush(mp, 1, flags, td);
195 * Shutdown the socket. This will cause the select in the
196 * daemon to wake up, and then the accept will get ECONNABORTED
197 * which it interprets as a request to go and bury itself.
199 soshutdown(VFSTOPORTAL(mp)->pm_server->f_data, 2);
201 * Discard reference to underlying file. Must call closef because
202 * this may be the last reference.
204 closef(VFSTOPORTAL(mp)->pm_server, (struct thread *) 0);
206 * Finally, throw away the portalmount structure
208 free(mp->mnt_data, M_PORTALFSMNT); /* XXX */
214 portal_root(mp, flags, vpp, td)
223 * Return locked reference to root.
225 vp = VFSTOPORTAL(mp)->pm_root;
227 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
233 portal_statfs(mp, sbp, td)
240 sbp->f_bsize = DEV_BSIZE;
241 sbp->f_iosize = DEV_BSIZE;
242 sbp->f_blocks = 2; /* 1K to keep df happy */
245 sbp->f_files = 1; /* Allow for "." */
246 sbp->f_ffree = 0; /* See comments above */
250 static struct vfsops portal_vfsops = {
251 .vfs_cmount = portal_cmount,
252 .vfs_mount = portal_mount,
253 .vfs_root = portal_root,
254 .vfs_statfs = portal_statfs,
255 .vfs_unmount = portal_unmount,
258 VFS_SET(portal_vfsops, portalfs, VFCF_SYNTHETIC);