Annotation of src/sys/miscfs/portal/portal_vfsops.c, Revision 1.26.2.2
1.26.2.2! jdolecek 1: /* $NetBSD: portal_vfsops.c,v 1.26.2.1 2002/01/10 20:01:40 thorpej 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.2.1 thorpej 46: #include <sys/cdefs.h>
1.26.2.2! jdolecek 47: __KERNEL_RCSID(0, "$NetBSD: portal_vfsops.c,v 1.26.2.1 2002/01/10 20:01:40 thorpej Exp $");
1.26.2.1 thorpej 48:
1.26 mrg 49: #if defined(_KERNEL_OPT)
1.18 jonathan 50: #include "opt_compat_netbsd.h"
51: #endif
1.1 cgd 52:
53: #include <sys/param.h>
54: #include <sys/systm.h>
55: #include <sys/time.h>
56: #include <sys/proc.h>
57: #include <sys/filedesc.h>
58: #include <sys/file.h>
59: #include <sys/vnode.h>
60: #include <sys/mount.h>
61: #include <sys/namei.h>
62: #include <sys/malloc.h>
63: #include <sys/mbuf.h>
64: #include <sys/socket.h>
65: #include <sys/socketvar.h>
66: #include <sys/protosw.h>
67: #include <sys/domain.h>
68: #include <sys/un.h>
69: #include <miscfs/portal/portal.h>
70:
1.14 christos 71: void portal_init __P((void));
1.23 jdolecek 72: void portal_done __P((void));
1.15 cgd 73: int portal_mount __P((struct mount *, const char *, void *,
1.14 christos 74: struct nameidata *, struct proc *));
75: int portal_start __P((struct mount *, int, struct proc *));
76: int portal_unmount __P((struct mount *, int, struct proc *));
77: int portal_root __P((struct mount *, struct vnode **));
78: int portal_quotactl __P((struct mount *, int, uid_t, caddr_t,
79: struct proc *));
80: int portal_statfs __P((struct mount *, struct statfs *, struct proc *));
81: int portal_sync __P((struct mount *, int, struct ucred *, struct proc *));
82: int portal_vget __P((struct mount *, ino_t, struct vnode **));
1.21 wrstuden 83: int portal_fhtovp __P((struct mount *, struct fid *, struct vnode **));
84: int portal_checkexp __P((struct mount *, struct mbuf *, int *,
85: struct ucred **));
1.14 christos 86: int portal_vptofh __P((struct vnode *, struct fid *));
1.17 fvdl 87: int portal_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
88: struct proc *));
1.14 christos 89:
90: void
1.5 mycroft 91: portal_init()
92: {
1.1 cgd 93: }
94:
1.23 jdolecek 95: void
96: portal_done()
97: {
98: }
99:
1.1 cgd 100: /*
101: * Mount the per-process file descriptors (/dev/fd)
102: */
1.5 mycroft 103: int
1.1 cgd 104: portal_mount(mp, path, data, ndp, p)
105: struct mount *mp;
1.15 cgd 106: const char *path;
107: void *data;
1.1 cgd 108: struct nameidata *ndp;
109: struct proc *p;
110: {
1.5 mycroft 111: struct file *fp;
1.1 cgd 112: struct portal_args args;
113: struct portalmount *fmp;
1.5 mycroft 114: struct socket *so;
1.1 cgd 115: struct vnode *rvp;
1.12 mycroft 116: size_t size;
1.5 mycroft 117: int error;
1.1 cgd 118:
119: /*
120: * Update is a no-op
121: */
122: if (mp->mnt_flag & MNT_UPDATE)
123: return (EOPNOTSUPP);
124:
1.14 christos 125: error = copyin(data, (caddr_t) &args, sizeof(struct portal_args));
126: if (error)
1.1 cgd 127: return (error);
128:
1.22 thorpej 129: /* getsock() will use the descriptor for us */
1.14 christos 130: if ((error = getsock(p->p_fd, args.pa_socket, &fp)) != 0)
1.1 cgd 131: return (error);
132: so = (struct socket *) fp->f_data;
1.22 thorpej 133: FILE_UNUSE(fp, NULL);
1.19 lukem 134: if (so->so_proto->pr_domain->dom_family != AF_LOCAL)
1.1 cgd 135: return (ESOCKTNOSUPPORT);
136:
1.5 mycroft 137: error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
1.1 cgd 138: if (error)
139: return (error);
1.5 mycroft 140: MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
141: M_TEMP, M_WAITOK);
1.1 cgd 142:
143: fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
144: M_UFSMNT, M_WAITOK); /* XXX */
145: rvp->v_type = VDIR;
146: rvp->v_flag |= VROOT;
147: VTOPORTAL(rvp)->pt_arg = 0;
148: VTOPORTAL(rvp)->pt_size = 0;
149: VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
150: fmp->pm_root = rvp;
151: fmp->pm_server = fp; fp->f_count++;
152:
1.5 mycroft 153: mp->mnt_flag |= MNT_LOCAL;
1.26.2.2! jdolecek 154: mp->mnt_data = fmp;
1.24 assar 155: vfs_getnewfsid(mp);
1.1 cgd 156:
1.10 mycroft 157: (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
1.20 perry 158: memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
1.10 mycroft 159: (void) copyinstr(args.pa_config, mp->mnt_stat.f_mntfromname,
160: MNAMELEN - 1, &size);
1.20 perry 161: memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
1.1 cgd 162: return (0);
163: }
164:
1.5 mycroft 165: int
1.1 cgd 166: portal_start(mp, flags, p)
167: struct mount *mp;
168: int flags;
169: struct proc *p;
170: {
1.5 mycroft 171:
1.1 cgd 172: return (0);
173: }
174:
1.5 mycroft 175: int
1.1 cgd 176: portal_unmount(mp, mntflags, p)
177: struct mount *mp;
178: int mntflags;
179: struct proc *p;
180: {
181: struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
1.5 mycroft 182: int error, flags = 0;
1.1 cgd 183:
1.17 fvdl 184: if (mntflags & MNT_FORCE)
1.1 cgd 185: flags |= FORCECLOSE;
186:
187: /*
188: * Clear out buffer cache. I don't think we
189: * ever get anything cached at this level at the
190: * moment, but who knows...
191: */
1.5 mycroft 192: #ifdef notyet
1.1 cgd 193: mntflushbuf(mp, 0);
194: if (mntinvalbuf(mp, 1))
195: return (EBUSY);
1.5 mycroft 196: #endif
1.1 cgd 197: if (rootvp->v_usecount > 1)
198: return (EBUSY);
1.14 christos 199: if ((error = vflush(mp, rootvp, flags)) != 0)
1.1 cgd 200: return (error);
201:
202: /*
203: * Release reference on underlying root vnode
204: */
205: vrele(rootvp);
206: /*
207: * And blow it away for future re-use
208: */
209: vgone(rootvp);
210: /*
211: * Shutdown the socket. This will cause the select in the
212: * daemon to wake up, and then the accept will get ECONNABORTED
213: * which it interprets as a request to go and bury itself.
214: */
1.22 thorpej 215: FILE_USE(VFSTOPORTAL(mp)->pm_server);
1.1 cgd 216: soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
217: /*
218: * Discard reference to underlying file. Must call closef because
219: * this may be the last reference.
220: */
221: closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
222: /*
223: * Finally, throw away the portalmount structure
224: */
225: free(mp->mnt_data, M_UFSMNT); /* XXX */
226: mp->mnt_data = 0;
1.5 mycroft 227: return (0);
1.1 cgd 228: }
229:
1.5 mycroft 230: int
1.1 cgd 231: portal_root(mp, vpp)
232: struct mount *mp;
233: struct vnode **vpp;
234: {
235: struct vnode *vp;
236:
237: /*
238: * Return locked reference to root.
239: */
240: vp = VFSTOPORTAL(mp)->pm_root;
241: VREF(vp);
1.17 fvdl 242: vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1 cgd 243: *vpp = vp;
244: return (0);
245: }
246:
1.5 mycroft 247: int
1.1 cgd 248: portal_quotactl(mp, cmd, uid, arg, p)
249: struct mount *mp;
250: int cmd;
251: uid_t uid;
252: caddr_t arg;
253: struct proc *p;
254: {
1.5 mycroft 255:
1.1 cgd 256: return (EOPNOTSUPP);
257: }
258:
1.5 mycroft 259: int
1.1 cgd 260: portal_statfs(mp, sbp, p)
261: struct mount *mp;
262: struct statfs *sbp;
263: struct proc *p;
264: {
265:
266: sbp->f_bsize = DEV_BSIZE;
1.3 cgd 267: sbp->f_iosize = DEV_BSIZE;
1.1 cgd 268: sbp->f_blocks = 2; /* 1K to keep df happy */
269: sbp->f_bfree = 0;
270: sbp->f_bavail = 0;
271: sbp->f_files = 1; /* Allow for "." */
272: sbp->f_ffree = 0; /* See comments above */
1.17 fvdl 273: #ifdef COMPAT_09
274: sbp->f_type = 12;
275: #else
276: sbp->f_type = 0;
277: #endif
1.1 cgd 278: if (sbp != &mp->mnt_stat) {
1.20 perry 279: memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
280: memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
281: memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
1.1 cgd 282: }
1.10 mycroft 283: strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
1.1 cgd 284: return (0);
285: }
286:
1.14 christos 287: /*ARGSUSED*/
1.5 mycroft 288: int
1.14 christos 289: portal_sync(mp, waitfor, uc, p)
1.1 cgd 290: struct mount *mp;
291: int waitfor;
1.14 christos 292: struct ucred *uc;
293: struct proc *p;
1.1 cgd 294: {
1.5 mycroft 295:
1.1 cgd 296: return (0);
297: }
298:
1.5 mycroft 299: int
300: portal_vget(mp, ino, vpp)
301: struct mount *mp;
302: ino_t ino;
303: struct vnode **vpp;
304: {
305:
306: return (EOPNOTSUPP);
307: }
308:
309: int
1.21 wrstuden 310: portal_fhtovp(mp, fhp, vpp)
1.1 cgd 311: struct mount *mp;
312: struct fid *fhp;
1.21 wrstuden 313: struct vnode **vpp;
314: {
315:
316: return (EOPNOTSUPP);
317: }
318:
319: int
320: portal_checkexp(mp, mb, what, anon)
321: struct mount *mp;
1.14 christos 322: struct mbuf *mb;
323: int *what;
324: struct ucred **anon;
1.1 cgd 325: {
1.5 mycroft 326:
1.1 cgd 327: return (EOPNOTSUPP);
328: }
329:
1.5 mycroft 330: int
1.1 cgd 331: portal_vptofh(vp, fhp)
332: struct vnode *vp;
333: struct fid *fhp;
334: {
1.5 mycroft 335:
1.1 cgd 336: return (EOPNOTSUPP);
337: }
338:
1.17 fvdl 339: int
340: portal_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
341: int *name;
342: u_int namelen;
343: void *oldp;
344: size_t *oldlenp;
345: void *newp;
346: size_t newlen;
347: struct proc *p;
348: {
349: return (EOPNOTSUPP);
350: }
351:
1.25 jdolecek 352: extern const struct vnodeopv_desc portal_vnodeop_opv_desc;
1.16 thorpej 353:
1.25 jdolecek 354: const struct vnodeopv_desc * const portal_vnodeopv_descs[] = {
1.16 thorpej 355: &portal_vnodeop_opv_desc,
356: NULL,
357: };
358:
1.1 cgd 359: struct vfsops portal_vfsops = {
1.2 cgd 360: MOUNT_PORTAL,
1.1 cgd 361: portal_mount,
362: portal_start,
363: portal_unmount,
364: portal_root,
365: portal_quotactl,
366: portal_statfs,
367: portal_sync,
1.5 mycroft 368: portal_vget,
1.1 cgd 369: portal_fhtovp,
370: portal_vptofh,
371: portal_init,
1.26.2.1 thorpej 372: NULL,
1.23 jdolecek 373: portal_done,
1.17 fvdl 374: portal_sysctl,
1.16 thorpej 375: NULL, /* vfs_mountroot */
1.21 wrstuden 376: portal_checkexp,
1.16 thorpej 377: portal_vnodeopv_descs,
1.1 cgd 378: };
CVSweb <webmaster@jp.NetBSD.org>