[BACK]Return to portal_vfsops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / miscfs / portal

Annotation of src/sys/miscfs/portal/portal_vfsops.c, Revision 1.26.2.3

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

CVSweb <webmaster@jp.NetBSD.org>