portal_vfsops.c revision 28270
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.16 1997/08/02 14:32:07 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/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 int	portal_init __P((struct vfsconf *));
61static int	portal_mount __P((struct mount *mp, char *path, caddr_t data,
62				  struct nameidata *ndp, struct proc *p));
63static int	portal_start __P((struct mount *mp, int flags, struct proc *p));
64static int	portal_unmount __P((struct mount *mp, int mntflags,
65				    struct proc *p));
66static int	portal_root __P((struct mount *mp, struct vnode **vpp));
67static int	portal_statfs __P((struct mount *mp, struct statfs *sbp,
68				   struct proc *p));
69
70static int
71portal_init(vfsp)
72	struct vfsconf *vfsp;
73{
74
75	return (0);
76}
77
78/*
79 * Mount the per-process file descriptors (/dev/fd)
80 */
81static int
82portal_mount(mp, path, data, ndp, p)
83	struct mount *mp;
84	char *path;
85	caddr_t data;
86	struct nameidata *ndp;
87	struct proc *p;
88{
89	struct file *fp;
90	struct portal_args args;
91	struct portalmount *fmp;
92	struct socket *so;
93	struct vnode *rvp;
94	struct portalnode *pn;
95	u_int size;
96	int error;
97
98	/*
99	 * Update is a no-op
100	 */
101	if (mp->mnt_flag & MNT_UPDATE)
102		return (EOPNOTSUPP);
103
104	error = copyin(data, (caddr_t) &args, sizeof(struct portal_args));
105	if (error)
106		return (error);
107
108	error = getsock(p->p_fd, args.pa_socket, &fp);
109	if (error)
110		return (error);
111	so = (struct socket *) fp->f_data;
112	if (so->so_proto->pr_domain->dom_family != AF_UNIX)
113		return (ESOCKTNOSUPPORT);
114
115	MALLOC(pn, struct portalnode *, sizeof(struct portalnode),
116		M_TEMP, M_WAITOK);
117
118	MALLOC(fmp, struct portalmount *, sizeof(struct portalmount),
119		M_UFSMNT, M_WAITOK);	/* XXX */
120
121	error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
122	if (error) {
123		FREE(fmp, M_UFSMNT);
124		FREE(pn, M_TEMP);
125		return (error);
126	}
127
128	rvp->v_data = pn;
129	rvp->v_type = VDIR;
130	rvp->v_flag |= VROOT;
131	VTOPORTAL(rvp)->pt_arg = 0;
132	VTOPORTAL(rvp)->pt_size = 0;
133	VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
134	fmp->pm_root = rvp;
135	fmp->pm_server = fp; fp->f_count++;
136
137	mp->mnt_flag |= MNT_LOCAL;
138	mp->mnt_data = (qaddr_t) fmp;
139	vfs_getnewfsid(mp);
140
141	(void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
142	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
143	(void)copyinstr(args.pa_config,
144	    mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
145	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
146
147#ifdef notdef
148	bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
149	bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
150#endif
151
152	return (0);
153}
154
155static int
156portal_start(mp, flags, p)
157	struct mount *mp;
158	int flags;
159	struct proc *p;
160{
161
162	return (0);
163}
164
165static int
166portal_unmount(mp, mntflags, p)
167	struct mount *mp;
168	int mntflags;
169	struct proc *p;
170{
171	struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
172	int error, flags = 0;
173
174
175	if (mntflags & MNT_FORCE)
176		flags |= FORCECLOSE;
177
178	/*
179	 * Clear out buffer cache.  I don't think we
180	 * ever get anything cached at this level at the
181	 * moment, but who knows...
182	 */
183#ifdef notyet
184	mntflushbuf(mp, 0);
185	if (mntinvalbuf(mp, 1))
186		return (EBUSY);
187#endif
188	if (rootvp->v_usecount > 1)
189		return (EBUSY);
190	error = vflush(mp, rootvp, flags);
191	if (error)
192		return (error);
193
194	/*
195	 * Release reference on underlying root vnode
196	 */
197	vrele(rootvp);
198	/*
199	 * And blow it away for future re-use
200	 */
201	vgone(rootvp);
202	/*
203	 * Shutdown the socket.  This will cause the select in the
204	 * daemon to wake up, and then the accept will get ECONNABORTED
205	 * which it interprets as a request to go and bury itself.
206	 */
207	soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
208	/*
209	 * Discard reference to underlying file.  Must call closef because
210	 * this may be the last reference.
211	 */
212	closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
213	/*
214	 * Finally, throw away the portalmount structure
215	 */
216	free(mp->mnt_data, M_UFSMNT);	/* XXX */
217	mp->mnt_data = 0;
218	return (0);
219}
220
221static int
222portal_root(mp, vpp)
223	struct mount *mp;
224	struct vnode **vpp;
225{
226	struct proc *p = curproc;	/* XXX */
227	struct vnode *vp;
228
229	/*
230	 * Return locked reference to root.
231	 */
232	vp = VFSTOPORTAL(mp)->pm_root;
233	VREF(vp);
234	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
235	*vpp = vp;
236	return (0);
237}
238
239static int
240portal_statfs(mp, sbp, p)
241	struct mount *mp;
242	struct statfs *sbp;
243	struct proc *p;
244{
245
246	sbp->f_flags = 0;
247	sbp->f_bsize = DEV_BSIZE;
248	sbp->f_iosize = DEV_BSIZE;
249	sbp->f_blocks = 2;		/* 1K to keep df happy */
250	sbp->f_bfree = 0;
251	sbp->f_bavail = 0;
252	sbp->f_files = 1;		/* Allow for "." */
253	sbp->f_ffree = 0;		/* See comments above */
254	if (sbp != &mp->mnt_stat) {
255		sbp->f_type = mp->mnt_vfc->vfc_typenum;
256		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
257		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
258		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
259	}
260	return (0);
261}
262
263#define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \
264	    struct sockaddr *, struct vnode **, int *, struct ucred **)))eopnotsupp)
265#define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
266	    struct proc *)))eopnotsupp)
267#define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \
268	    struct proc *)))nullop)
269#define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
270	    size_t, struct proc *)))eopnotsupp)
271#define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
272	    eopnotsupp)
273#define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
274
275static struct vfsops portal_vfsops = {
276	portal_mount,
277	portal_start,
278	portal_unmount,
279	portal_root,
280	portal_quotactl,
281	portal_statfs,
282	portal_sync,
283	portal_vget,
284	portal_fhtovp,
285	portal_vptofh,
286	portal_init,
287};
288
289VFS_SET(portal_vfsops, portal, MOUNT_PORTAL, VFCF_SYNTHETIC);
290