Deleted Added
full compact
portal_vfsops.c (2979) portal_vfsops.c (3034)
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 *
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.2 1994/09/21 03:47:04 wollman Exp $
38 * $Id: portal_vfsops.c,v 1.3 1994/09/22 19:38:17 wollman Exp $
39 */
40
41/*
42 * Portal Filesystem
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
39 */
40
41/*
42 * Portal Filesystem
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include
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
65int
66portal_init()
67{
68
69 return (0);
70}
71
72/*
73 * Mount the per-process file descriptors (/dev/fd)
74 */
75int
76portal_mount(mp, path, data, ndp, p)
77 struct mount *mp;
78 char *path;
79 caddr_t data;
80 struct nameidata *ndp;
81 struct proc *p;
82{
83 struct file *fp;
84 struct portal_args args;
85 struct portalmount *fmp;
86 struct socket *so;
87 struct vnode *rvp;
88 u_int size;
89 int error;
90
91 /*
92 * Update is a no-op
93 */
94 if (mp->mnt_flag & MNT_UPDATE)
95 return (EOPNOTSUPP);
96
97 if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)))
98 return (error);
99
100 if (error = getsock(p->p_fd, args.pa_socket, &fp))
101 return (error);
102 so = (struct socket *) fp->f_data;
103 if (so->so_proto->pr_domain->dom_family != AF_UNIX)
104 return (ESOCKTNOSUPPORT);
105
106 error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
107 if (error)
108 return (error);
109 MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
110 M_TEMP, M_WAITOK);
111
112 fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
113 M_UFSMNT, M_WAITOK); /* XXX */
114 rvp->v_type = VDIR;
115 rvp->v_flag |= VROOT;
116 VTOPORTAL(rvp)->pt_arg = 0;
117 VTOPORTAL(rvp)->pt_size = 0;
118 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
119 fmp->pm_root = rvp;
120 fmp->pm_server = fp; fp->f_count++;
121
122 mp->mnt_flag |= MNT_LOCAL;
123 mp->mnt_data = (qaddr_t) fmp;
124 getnewfsid(mp, MOUNT_PORTAL);
125
126 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
127 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
128 (void)copyinstr(args.pa_config,
129 mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
130 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
131
132#ifdef notdef
133 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
134 bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
135#endif
136
137 return (0);
138}
139
140int
141portal_start(mp, flags, p)
142 struct mount *mp;
143 int flags;
144 struct proc *p;
145{
146
147 return (0);
148}
149
150int
151portal_unmount(mp, mntflags, p)
152 struct mount *mp;
153 int mntflags;
154 struct proc *p;
155{
156 extern int doforce;
157 struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
158 int error, flags = 0;
159
160
161 if (mntflags & MNT_FORCE) {
162 /* portal can never be rootfs so don't check for it */
163 if (!doforce)
164 return (EINVAL);
165 flags |= FORCECLOSE;
166 }
167
168 /*
169 * Clear out buffer cache. I don't think we
170 * ever get anything cached at this level at the
171 * moment, but who knows...
172 */
173#ifdef notyet
174 mntflushbuf(mp, 0);
175 if (mntinvalbuf(mp, 1))
176 return (EBUSY);
177#endif
178 if (rootvp->v_usecount > 1)
179 return (EBUSY);
180 if (error = vflush(mp, rootvp, flags))
181 return (error);
182
183 /*
184 * Release reference on underlying root vnode
185 */
186 vrele(rootvp);
187 /*
188 * And blow it away for future re-use
189 */
190 vgone(rootvp);
191 /*
192 * Shutdown the socket. This will cause the select in the
193 * daemon to wake up, and then the accept will get ECONNABORTED
194 * which it interprets as a request to go and bury itself.
195 */
196 soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
197 /*
198 * Discard reference to underlying file. Must call closef because
199 * this may be the last reference.
200 */
201 closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
202 /*
203 * Finally, throw away the portalmount structure
204 */
205 free(mp->mnt_data, M_UFSMNT); /* XXX */
206 mp->mnt_data = 0;
207 return (0);
208}
209
210int
211portal_root(mp, vpp)
212 struct mount *mp;
213 struct vnode **vpp;
214{
215 struct vnode *vp;
216
217
218 /*
219 * Return locked reference to root.
220 */
221 vp = VFSTOPORTAL(mp)->pm_root;
222 VREF(vp);
223 VOP_LOCK(vp);
224 *vpp = vp;
225 return (0);
226}
227
228int
229portal_quotactl(mp, cmd, uid, arg, p)
230 struct mount *mp;
231 int cmd;
232 uid_t uid;
233 caddr_t arg;
234 struct proc *p;
235{
236
237 return (EOPNOTSUPP);
238}
239
240int
241portal_statfs(mp, sbp, p)
242 struct mount *mp;
243 struct statfs *sbp;
244 struct proc *p;
245{
246
247 sbp->f_type = MOUNT_PORTAL;
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 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
258 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
259 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
260 }
261 return (0);
262}
263
264int
265portal_sync(mp, waitfor)
266 struct mount *mp;
267 int waitfor;
268{
269
270 return (0);
271}
272
273int
274portal_vget(mp, ino, vpp)
275 struct mount *mp;
276 ino_t ino;
277 struct vnode **vpp;
278{
279
280 return (EOPNOTSUPP);
281}
282
283int
284portal_fhtovp(mp, fhp, vpp)
285 struct mount *mp;
286 struct fid *fhp;
287 struct vnode **vpp;
288{
289
290 return (EOPNOTSUPP);
291}
292
293int
294portal_vptofh(vp, fhp)
295 struct vnode *vp;
296 struct fid *fhp;
297{
298
299 return (EOPNOTSUPP);
300}
301
302struct vfsops portal_vfsops = {
303 portal_mount,
304 portal_start,
305 portal_unmount,
306 portal_root,
307 portal_quotactl,
308 portal_statfs,
309 portal_sync,
310 portal_vget,
311 portal_fhtovp,
312 portal_vptofh,
313 portal_init,
314};
315
316VFS_SET(portal_vfsops, portal, MOUNT_PORTAL, 0);
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
65int
66portal_init()
67{
68
69 return (0);
70}
71
72/*
73 * Mount the per-process file descriptors (/dev/fd)
74 */
75int
76portal_mount(mp, path, data, ndp, p)
77 struct mount *mp;
78 char *path;
79 caddr_t data;
80 struct nameidata *ndp;
81 struct proc *p;
82{
83 struct file *fp;
84 struct portal_args args;
85 struct portalmount *fmp;
86 struct socket *so;
87 struct vnode *rvp;
88 u_int size;
89 int error;
90
91 /*
92 * Update is a no-op
93 */
94 if (mp->mnt_flag & MNT_UPDATE)
95 return (EOPNOTSUPP);
96
97 if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)))
98 return (error);
99
100 if (error = getsock(p->p_fd, args.pa_socket, &fp))
101 return (error);
102 so = (struct socket *) fp->f_data;
103 if (so->so_proto->pr_domain->dom_family != AF_UNIX)
104 return (ESOCKTNOSUPPORT);
105
106 error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
107 if (error)
108 return (error);
109 MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
110 M_TEMP, M_WAITOK);
111
112 fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
113 M_UFSMNT, M_WAITOK); /* XXX */
114 rvp->v_type = VDIR;
115 rvp->v_flag |= VROOT;
116 VTOPORTAL(rvp)->pt_arg = 0;
117 VTOPORTAL(rvp)->pt_size = 0;
118 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
119 fmp->pm_root = rvp;
120 fmp->pm_server = fp; fp->f_count++;
121
122 mp->mnt_flag |= MNT_LOCAL;
123 mp->mnt_data = (qaddr_t) fmp;
124 getnewfsid(mp, MOUNT_PORTAL);
125
126 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
127 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
128 (void)copyinstr(args.pa_config,
129 mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
130 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
131
132#ifdef notdef
133 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
134 bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
135#endif
136
137 return (0);
138}
139
140int
141portal_start(mp, flags, p)
142 struct mount *mp;
143 int flags;
144 struct proc *p;
145{
146
147 return (0);
148}
149
150int
151portal_unmount(mp, mntflags, p)
152 struct mount *mp;
153 int mntflags;
154 struct proc *p;
155{
156 extern int doforce;
157 struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
158 int error, flags = 0;
159
160
161 if (mntflags & MNT_FORCE) {
162 /* portal can never be rootfs so don't check for it */
163 if (!doforce)
164 return (EINVAL);
165 flags |= FORCECLOSE;
166 }
167
168 /*
169 * Clear out buffer cache. I don't think we
170 * ever get anything cached at this level at the
171 * moment, but who knows...
172 */
173#ifdef notyet
174 mntflushbuf(mp, 0);
175 if (mntinvalbuf(mp, 1))
176 return (EBUSY);
177#endif
178 if (rootvp->v_usecount > 1)
179 return (EBUSY);
180 if (error = vflush(mp, rootvp, flags))
181 return (error);
182
183 /*
184 * Release reference on underlying root vnode
185 */
186 vrele(rootvp);
187 /*
188 * And blow it away for future re-use
189 */
190 vgone(rootvp);
191 /*
192 * Shutdown the socket. This will cause the select in the
193 * daemon to wake up, and then the accept will get ECONNABORTED
194 * which it interprets as a request to go and bury itself.
195 */
196 soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
197 /*
198 * Discard reference to underlying file. Must call closef because
199 * this may be the last reference.
200 */
201 closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
202 /*
203 * Finally, throw away the portalmount structure
204 */
205 free(mp->mnt_data, M_UFSMNT); /* XXX */
206 mp->mnt_data = 0;
207 return (0);
208}
209
210int
211portal_root(mp, vpp)
212 struct mount *mp;
213 struct vnode **vpp;
214{
215 struct vnode *vp;
216
217
218 /*
219 * Return locked reference to root.
220 */
221 vp = VFSTOPORTAL(mp)->pm_root;
222 VREF(vp);
223 VOP_LOCK(vp);
224 *vpp = vp;
225 return (0);
226}
227
228int
229portal_quotactl(mp, cmd, uid, arg, p)
230 struct mount *mp;
231 int cmd;
232 uid_t uid;
233 caddr_t arg;
234 struct proc *p;
235{
236
237 return (EOPNOTSUPP);
238}
239
240int
241portal_statfs(mp, sbp, p)
242 struct mount *mp;
243 struct statfs *sbp;
244 struct proc *p;
245{
246
247 sbp->f_type = MOUNT_PORTAL;
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 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
258 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
259 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
260 }
261 return (0);
262}
263
264int
265portal_sync(mp, waitfor)
266 struct mount *mp;
267 int waitfor;
268{
269
270 return (0);
271}
272
273int
274portal_vget(mp, ino, vpp)
275 struct mount *mp;
276 ino_t ino;
277 struct vnode **vpp;
278{
279
280 return (EOPNOTSUPP);
281}
282
283int
284portal_fhtovp(mp, fhp, vpp)
285 struct mount *mp;
286 struct fid *fhp;
287 struct vnode **vpp;
288{
289
290 return (EOPNOTSUPP);
291}
292
293int
294portal_vptofh(vp, fhp)
295 struct vnode *vp;
296 struct fid *fhp;
297{
298
299 return (EOPNOTSUPP);
300}
301
302struct vfsops portal_vfsops = {
303 portal_mount,
304 portal_start,
305 portal_unmount,
306 portal_root,
307 portal_quotactl,
308 portal_statfs,
309 portal_sync,
310 portal_vget,
311 portal_fhtovp,
312 portal_vptofh,
313 portal_init,
314};
315
316VFS_SET(portal_vfsops, portal, MOUNT_PORTAL, 0);