[BACK]Return to portal_vfsops.c CVS log [TXT][DIR] Up to [local] / sys / miscfs / portal

Annotation of sys/miscfs/portal/portal_vfsops.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: portal_vfsops.c,v 1.21 2007/06/18 08:30:07 jasper Exp $       */
        !             2: /*     $NetBSD: portal_vfsops.c,v 1.14 1996/02/09 22:40:41 christos Exp $      */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1992, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software donated to Berkeley by
        !             9:  * Jan-Simon Pendry.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. Neither the name of the University nor the names of its contributors
        !            20:  *    may be used to endorse or promote products derived from this software
        !            21:  *    without specific prior written permission.
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            33:  * SUCH DAMAGE.
        !            34:  *
        !            35:  *     from: Id: portal_vfsops.c,v 1.5 1992/05/30 10:25:27 jsp Exp
        !            36:  *     @(#)portal_vfsops.c     8.6 (Berkeley) 1/21/94
        !            37:  */
        !            38:
        !            39: /*
        !            40:  * Portal Filesystem
        !            41:  */
        !            42:
        !            43: #include <sys/param.h>
        !            44: #include <sys/systm.h>
        !            45: #include <sys/time.h>
        !            46: #include <sys/types.h>
        !            47: #include <sys/proc.h>
        !            48: #include <sys/filedesc.h>
        !            49: #include <sys/file.h>
        !            50: #include <sys/vnode.h>
        !            51: #include <sys/mount.h>
        !            52: #include <sys/namei.h>
        !            53: #include <sys/malloc.h>
        !            54: #include <sys/mbuf.h>
        !            55: #include <sys/socket.h>
        !            56: #include <sys/socketvar.h>
        !            57: #include <sys/protosw.h>
        !            58: #include <sys/domain.h>
        !            59: #include <sys/un.h>
        !            60: #include <miscfs/portal/portal.h>
        !            61:
        !            62: #define portal_init ((int (*)(struct vfsconf *))nullop)
        !            63:
        !            64: int    portal_mount(struct mount *, const char *, void *,
        !            65:                          struct nameidata *, struct proc *);
        !            66: int    portal_start(struct mount *, int, struct proc *);
        !            67: int    portal_unmount(struct mount *, int, struct proc *);
        !            68: int    portal_root(struct mount *, struct vnode **);
        !            69: int    portal_statfs(struct mount *, struct statfs *, struct proc *);
        !            70:
        !            71:
        !            72: /*
        !            73:  * Mount the per-process file descriptors (/dev/fd)
        !            74:  */
        !            75: int
        !            76: portal_mount(struct mount *mp, const char *path, void *data, struct nameidata *ndp,
        !            77:     struct proc *p)
        !            78: {
        !            79:        struct file *fp;
        !            80:        struct portal_args args;
        !            81:        struct portalmount *fmp;
        !            82:        struct socket *so;
        !            83:        struct vnode *rvp;
        !            84:        size_t size;
        !            85:        int error;
        !            86:
        !            87:        /*
        !            88:         * Update is a no-op
        !            89:         */
        !            90:        if (mp->mnt_flag & MNT_UPDATE)
        !            91:                return (EOPNOTSUPP);
        !            92:
        !            93:        error = copyin(data, &args, sizeof(struct portal_args));
        !            94:        if (error)
        !            95:                return (error);
        !            96:
        !            97:        if ((error = getsock(p->p_fd, args.pa_socket, &fp)) != 0)
        !            98:                return (error);
        !            99:        so = (struct socket *) fp->f_data;
        !           100:        if (so->so_proto->pr_domain->dom_family != AF_UNIX) {
        !           101:                FRELE(fp);
        !           102:                return (ESOCKTNOSUPPORT);
        !           103:        }
        !           104:
        !           105:        error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
        !           106:        if (error) {
        !           107:                FRELE(fp);
        !           108:                return (error);
        !           109:        }
        !           110:        MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
        !           111:                M_TEMP, M_WAITOK);
        !           112:
        !           113:        fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
        !           114:                                 M_MISCFSMNT, M_WAITOK);
        !           115:        rvp->v_type = VDIR;
        !           116:        rvp->v_flag |= VROOT;
        !           117:        VTOPORTAL(rvp)->pt_arg = 0;
        !           118:        VTOPORTAL(rvp)->pt_size = 0;
        !           119:        VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
        !           120:        fmp->pm_root = rvp;
        !           121:        fmp->pm_server = fp;
        !           122:        fp->f_count++;
        !           123:        FRELE(fp);
        !           124:
        !           125:        mp->mnt_flag |= MNT_LOCAL;
        !           126:        mp->mnt_data = fmp;
        !           127:        vfs_getnewfsid(mp);
        !           128:
        !           129:        (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
        !           130:        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
        !           131:        (void) copyinstr(args.pa_config, mp->mnt_stat.f_mntfromname,
        !           132:            MNAMELEN - 1, &size);
        !           133:        bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
        !           134:        return (0);
        !           135: }
        !           136:
        !           137: int
        !           138: portal_start(struct mount *mp, int flags, struct proc *p)
        !           139: {
        !           140:
        !           141:        return (0);
        !           142: }
        !           143:
        !           144: int
        !           145: portal_unmount(struct mount *mp, int mntflags, struct proc *p)
        !           146: {
        !           147:        struct vnode *rvp = VFSTOPORTAL(mp)->pm_root;
        !           148:        int error, flags = 0;
        !           149:
        !           150:        if (mntflags & MNT_FORCE) {
        !           151:                flags |= FORCECLOSE;
        !           152:        }
        !           153:
        !           154:        /*
        !           155:         * Clear out buffer cache.  I don't think we
        !           156:         * ever get anything cached at this level at the
        !           157:         * moment, but who knows...
        !           158:         */
        !           159: #ifdef notyet
        !           160:        mntflushbuf(mp, 0);
        !           161:        if (mntinvalbuf(mp, 1))
        !           162:                return (EBUSY);
        !           163: #endif
        !           164:        if (rvp->v_usecount > 1 && !(flags & FORCECLOSE))
        !           165:                return (EBUSY);
        !           166:        if ((error = vflush(mp, rvp, flags)) != 0)
        !           167:                return (error);
        !           168:
        !           169:        /*
        !           170:         * Release reference on underlying root vnode
        !           171:         */
        !           172:        vrele(rvp);
        !           173:        /*
        !           174:         * And blow it away for future re-use
        !           175:         */
        !           176:        vgone(rvp);
        !           177:        /*
        !           178:         * Shutdown the socket.  This will cause the select in the
        !           179:         * daemon to wake up, and then the accept will get ECONNABORTED
        !           180:         * which it interprets as a request to go and bury itself.
        !           181:         */
        !           182:        FREF(VFSTOPORTAL(mp)->pm_server);
        !           183:        soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
        !           184:        /*
        !           185:         * Discard reference to underlying file.  Must call closef because
        !           186:         * this may be the last reference.
        !           187:         */
        !           188:        closef(VFSTOPORTAL(mp)->pm_server, NULL);
        !           189:        /*
        !           190:         * Finally, throw away the portalmount structure
        !           191:         */
        !           192:        free(mp->mnt_data, M_MISCFSMNT);
        !           193:        mp->mnt_data = 0;
        !           194:        return (0);
        !           195: }
        !           196:
        !           197: int
        !           198: portal_root(struct mount *mp, struct vnode **vpp)
        !           199: {
        !           200:        struct vnode *vp;
        !           201:        struct proc *p = curproc;
        !           202:
        !           203:        /*
        !           204:         * Return locked reference to root.
        !           205:         */
        !           206:        vp = VFSTOPORTAL(mp)->pm_root;
        !           207:        VREF(vp);
        !           208:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
        !           209:        *vpp = vp;
        !           210:        return (0);
        !           211: }
        !           212:
        !           213: int
        !           214: portal_statfs(struct mount *mp, struct statfs *sbp, struct proc *p)
        !           215: {
        !           216:
        !           217:        sbp->f_bsize = DEV_BSIZE;
        !           218:        sbp->f_iosize = DEV_BSIZE;
        !           219:        sbp->f_blocks = 2;              /* 1K to keep df happy */
        !           220:        sbp->f_bfree = 0;
        !           221:        sbp->f_bavail = 0;
        !           222:        sbp->f_files = 1;               /* Allow for "." */
        !           223:        sbp->f_ffree = 0;               /* See comments above */
        !           224:        if (sbp != &mp->mnt_stat) {
        !           225:                bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
        !           226:                bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
        !           227:                bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
        !           228:        }
        !           229:        strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
        !           230:        return (0);
        !           231: }
        !           232:
        !           233:
        !           234: #define portal_sync ((int (*)(struct mount *, int, struct ucred *, \
        !           235:                                  struct proc *))nullop)
        !           236:
        !           237: #define portal_fhtovp ((int (*)(struct mount *, struct fid *, \
        !           238:            struct vnode **))eopnotsupp)
        !           239: #define portal_quotactl ((int (*)(struct mount *, int, uid_t, caddr_t, \
        !           240:            struct proc *))eopnotsupp)
        !           241: #define portal_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \
        !           242:            size_t, struct proc *))eopnotsupp)
        !           243: #define portal_vget ((int (*)(struct mount *, ino_t, struct vnode **)) \
        !           244:            eopnotsupp)
        !           245: #define portal_vptofh ((int (*)(struct vnode *, struct fid *))eopnotsupp)
        !           246: #define portal_checkexp ((int (*)(struct mount *, struct mbuf *,       \
        !           247:        int *, struct ucred **))eopnotsupp)
        !           248:
        !           249: const struct vfsops portal_vfsops = {
        !           250:        portal_mount,
        !           251:        portal_start,
        !           252:        portal_unmount,
        !           253:        portal_root,
        !           254:        portal_quotactl,
        !           255:        portal_statfs,
        !           256:        portal_sync,
        !           257:        portal_vget,
        !           258:        portal_fhtovp,
        !           259:        portal_vptofh,
        !           260:        portal_init,
        !           261:        portal_sysctl,
        !           262:        portal_checkexp
        !           263: };

CVSweb