Annotation of src/sys/miscfs/portal/portal_vfsops.c, Revision 1.26
1.26 ! mrg 1: /* $NetBSD: portal_vfsops.c,v 1.25 2001/01/22 12:17:39 jdolecek Exp $ */
1.6 cgd 2:
1.1 cgd 3: /*
1.17 fvdl 4: * Copyright (c) 1992, 1993, 1995
1.5 mycroft 5: * The Regents of the University of California. All rights reserved.
1.1 cgd 6: *
7: * This code is derived from software donated to Berkeley by
8: * Jan-Simon Pendry.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
1.5 mycroft 38: * from: Id: portal_vfsops.c,v 1.5 1992/05/30 10:25:27 jsp Exp
1.17 fvdl 39: * @(#)portal_vfsops.c 8.11 (Berkeley) 5/14/95
1.1 cgd 40: */
41:
42: /*
43: * Portal Filesystem
44: */
1.18 jonathan 45:
1.26 ! mrg 46: #if defined(_KERNEL_OPT)
1.18 jonathan 47: #include "opt_compat_netbsd.h"
48: #endif
1.1 cgd 49:
50: #include <sys/param.h>
51: #include <sys/systm.h>
52: #include <sys/time.h>
53: #include <sys/types.h>
54: #include <sys/proc.h>
55: #include <sys/filedesc.h>
56: #include <sys/file.h>
57: #include <sys/vnode.h>
58: #include <sys/mount.h>
59: #include <sys/namei.h>
60: #include <sys/malloc.h>
61: #include <sys/mbuf.h>
62: #include <sys/socket.h>
63: #include <sys/socketvar.h>
64: #include <sys/protosw.h>
65: #include <sys/domain.h>
66: #include <sys/un.h>
67: #include <miscfs/portal/portal.h>
68:
1.14 christos 69: void portal_init __P((void));
1.23 jdolecek 70: void portal_done __P((void));
1.15 cgd 71: int portal_mount __P((struct mount *, const char *, void *,
1.14 christos 72: struct nameidata *, struct proc *));
73: int portal_start __P((struct mount *, int, struct proc *));
74: int portal_unmount __P((struct mount *, int, struct proc *));
75: int portal_root __P((struct mount *, struct vnode **));
76: int portal_quotactl __P((struct mount *, int, uid_t, caddr_t,
77: struct proc *));
78: int portal_statfs __P((struct mount *, struct statfs *, struct proc *));
79: int portal_sync __P((struct mount *, int, struct ucred *, struct proc *));
80: int portal_vget __P((struct mount *, ino_t, struct vnode **));
1.21 wrstuden 81: int portal_fhtovp __P((struct mount *, struct fid *, struct vnode **));
82: int portal_checkexp __P((struct mount *, struct mbuf *, int *,
83: struct ucred **));
1.14 christos 84: int portal_vptofh __P((struct vnode *, struct fid *));
1.17 fvdl 85: int portal_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
86: struct proc *));
1.14 christos 87:
88: void
1.5 mycroft 89: portal_init()
90: {
1.1 cgd 91: }
92:
1.23 jdolecek 93: void
94: portal_done()
95: {
96: }
97:
1.1 cgd 98: /*
99: * Mount the per-process file descriptors (/dev/fd)
100: */
1.5 mycroft 101: int
1.1 cgd 102: portal_mount(mp, path, data, ndp, p)
103: struct mount *mp;
1.15 cgd 104: const char *path;
105: void *data;
1.1 cgd 106: struct nameidata *ndp;
107: struct proc *p;
108: {
1.5 mycroft 109: struct file *fp;
1.1 cgd 110: struct portal_args args;
111: struct portalmount *fmp;
1.5 mycroft 112: struct socket *so;
1.1 cgd 113: struct vnode *rvp;
1.12 mycroft 114: size_t size;
1.5 mycroft 115: int error;
1.1 cgd 116:
117: /*
118: * Update is a no-op
119: */
120: if (mp->mnt_flag & MNT_UPDATE)
121: return (EOPNOTSUPP);
122:
1.14 christos 123: error = copyin(data, (caddr_t) &args, sizeof(struct portal_args));
124: if (error)
1.1 cgd 125: return (error);
126:
1.22 thorpej 127: /* getsock() will use the descriptor for us */
1.14 christos 128: if ((error = getsock(p->p_fd, args.pa_socket, &fp)) != 0)
1.1 cgd 129: return (error);
130: so = (struct socket *) fp->f_data;
1.22 thorpej 131: FILE_UNUSE(fp, NULL);
1.19 lukem 132: if (so->so_proto->pr_domain->dom_family != AF_LOCAL)
1.1 cgd 133: return (ESOCKTNOSUPPORT);
134:
1.5 mycroft 135: error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
1.1 cgd 136: if (error)
137: return (error);
1.5 mycroft 138: MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
139: M_TEMP, M_WAITOK);
1.1 cgd 140:
141: fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
142: M_UFSMNT, M_WAITOK); /* XXX */
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:
1.5 mycroft 151: mp->mnt_flag |= MNT_LOCAL;
1.7 mycroft 152: mp->mnt_data = (qaddr_t)fmp;
1.24 assar 153: vfs_getnewfsid(mp);
1.1 cgd 154:
1.10 mycroft 155: (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
1.20 perry 156: memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
1.10 mycroft 157: (void) copyinstr(args.pa_config, mp->mnt_stat.f_mntfromname,
158: MNAMELEN - 1, &size);
1.20 perry 159: memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
1.1 cgd 160: return (0);
161: }
162:
1.5 mycroft 163: int
1.1 cgd 164: portal_start(mp, flags, p)
165: struct mount *mp;
166: int flags;
167: struct proc *p;
168: {
1.5 mycroft 169:
1.1 cgd 170: return (0);
171: }
172:
1.5 mycroft 173: int
1.1 cgd 174: portal_unmount(mp, mntflags, p)
175: struct mount *mp;
176: int mntflags;
177: struct proc *p;
178: {
179: struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
1.5 mycroft 180: int error, flags = 0;
1.1 cgd 181:
1.17 fvdl 182: if (mntflags & MNT_FORCE)
1.1 cgd 183: flags |= FORCECLOSE;
184:
185: /*
186: * Clear out buffer cache. I don't think we
187: * ever get anything cached at this level at the
188: * moment, but who knows...
189: */
1.5 mycroft 190: #ifdef notyet
1.1 cgd 191: mntflushbuf(mp, 0);
192: if (mntinvalbuf(mp, 1))
193: return (EBUSY);
1.5 mycroft 194: #endif
1.1 cgd 195: if (rootvp->v_usecount > 1)
196: return (EBUSY);
1.14 christos 197: if ((error = vflush(mp, rootvp, flags)) != 0)
1.1 cgd 198: return (error);
199:
200: /*
201: * Release reference on underlying root vnode
202: */
203: vrele(rootvp);
204: /*
205: * And blow it away for future re-use
206: */
207: vgone(rootvp);
208: /*
209: * Shutdown the socket. This will cause the select in the
210: * daemon to wake up, and then the accept will get ECONNABORTED
211: * which it interprets as a request to go and bury itself.
212: */
1.22 thorpej 213: FILE_USE(VFSTOPORTAL(mp)->pm_server);
1.1 cgd 214: soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
215: /*
216: * Discard reference to underlying file. Must call closef because
217: * this may be the last reference.
218: */
219: closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
220: /*
221: * Finally, throw away the portalmount structure
222: */
223: free(mp->mnt_data, M_UFSMNT); /* XXX */
224: mp->mnt_data = 0;
1.5 mycroft 225: return (0);
1.1 cgd 226: }
227:
1.5 mycroft 228: int
1.1 cgd 229: portal_root(mp, vpp)
230: struct mount *mp;
231: struct vnode **vpp;
232: {
233: struct vnode *vp;
234:
235: /*
236: * Return locked reference to root.
237: */
238: vp = VFSTOPORTAL(mp)->pm_root;
239: VREF(vp);
1.17 fvdl 240: vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1 cgd 241: *vpp = vp;
242: return (0);
243: }
244:
1.5 mycroft 245: int
1.1 cgd 246: portal_quotactl(mp, cmd, uid, arg, p)
247: struct mount *mp;
248: int cmd;
249: uid_t uid;
250: caddr_t arg;
251: struct proc *p;
252: {
1.5 mycroft 253:
1.1 cgd 254: return (EOPNOTSUPP);
255: }
256:
1.5 mycroft 257: int
1.1 cgd 258: portal_statfs(mp, sbp, p)
259: struct mount *mp;
260: struct statfs *sbp;
261: struct proc *p;
262: {
263:
264: sbp->f_bsize = DEV_BSIZE;
1.3 cgd 265: sbp->f_iosize = DEV_BSIZE;
1.1 cgd 266: sbp->f_blocks = 2; /* 1K to keep df happy */
267: sbp->f_bfree = 0;
268: sbp->f_bavail = 0;
269: sbp->f_files = 1; /* Allow for "." */
270: sbp->f_ffree = 0; /* See comments above */
1.17 fvdl 271: #ifdef COMPAT_09
272: sbp->f_type = 12;
273: #else
274: sbp->f_type = 0;
275: #endif
1.1 cgd 276: if (sbp != &mp->mnt_stat) {
1.20 perry 277: memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
278: memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
279: memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
1.1 cgd 280: }
1.10 mycroft 281: strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
1.1 cgd 282: return (0);
283: }
284:
1.14 christos 285: /*ARGSUSED*/
1.5 mycroft 286: int
1.14 christos 287: portal_sync(mp, waitfor, uc, p)
1.1 cgd 288: struct mount *mp;
289: int waitfor;
1.14 christos 290: struct ucred *uc;
291: struct proc *p;
1.1 cgd 292: {
1.5 mycroft 293:
1.1 cgd 294: return (0);
295: }
296:
1.5 mycroft 297: int
298: portal_vget(mp, ino, vpp)
299: struct mount *mp;
300: ino_t ino;
301: struct vnode **vpp;
302: {
303:
304: return (EOPNOTSUPP);
305: }
306:
307: int
1.21 wrstuden 308: portal_fhtovp(mp, fhp, vpp)
1.1 cgd 309: struct mount *mp;
310: struct fid *fhp;
1.21 wrstuden 311: struct vnode **vpp;
312: {
313:
314: return (EOPNOTSUPP);
315: }
316:
317: int
318: portal_checkexp(mp, mb, what, anon)
319: struct mount *mp;
1.14 christos 320: struct mbuf *mb;
321: int *what;
322: struct ucred **anon;
1.1 cgd 323: {
1.5 mycroft 324:
1.1 cgd 325: return (EOPNOTSUPP);
326: }
327:
1.5 mycroft 328: int
1.1 cgd 329: portal_vptofh(vp, fhp)
330: struct vnode *vp;
331: struct fid *fhp;
332: {
1.5 mycroft 333:
1.1 cgd 334: return (EOPNOTSUPP);
335: }
336:
1.17 fvdl 337: int
338: portal_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
339: int *name;
340: u_int namelen;
341: void *oldp;
342: size_t *oldlenp;
343: void *newp;
344: size_t newlen;
345: struct proc *p;
346: {
347: return (EOPNOTSUPP);
348: }
349:
1.25 jdolecek 350: extern const struct vnodeopv_desc portal_vnodeop_opv_desc;
1.16 thorpej 351:
1.25 jdolecek 352: const struct vnodeopv_desc * const portal_vnodeopv_descs[] = {
1.16 thorpej 353: &portal_vnodeop_opv_desc,
354: NULL,
355: };
356:
1.1 cgd 357: struct vfsops portal_vfsops = {
1.2 cgd 358: MOUNT_PORTAL,
1.1 cgd 359: portal_mount,
360: portal_start,
361: portal_unmount,
362: portal_root,
363: portal_quotactl,
364: portal_statfs,
365: portal_sync,
1.5 mycroft 366: portal_vget,
1.1 cgd 367: portal_fhtovp,
368: portal_vptofh,
369: portal_init,
1.23 jdolecek 370: portal_done,
1.17 fvdl 371: portal_sysctl,
1.16 thorpej 372: NULL, /* vfs_mountroot */
1.21 wrstuden 373: portal_checkexp,
1.16 thorpej 374: portal_vnodeopv_descs,
1.1 cgd 375: };
CVSweb <webmaster@jp.NetBSD.org>