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

Annotation of src/sys/miscfs/nullfs/null_vfsops.c, Revision 1.85

1.85    ! hannken     1: /*     $NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $   */
1.2       cgd         2:
1.1       mycroft     3: /*
1.24      wrstuden    4:  * Copyright (c) 1999 National Aeronautics & Space Administration
                      5:  * All rights reserved.
                      6:  *
                      7:  * This software was written by William Studenmund of the
1.30      wiz         8:  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
1.24      wrstuden    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.
1.25      soren      18:  * 3. Neither the name of the National Aeronautics & Space Administration
1.24      wrstuden   19:  *    nor the names of its contributors may be used to endorse or promote
                     20:  *    products derived from this software without specific prior written
                     21:  *    permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
                     24:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     25:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     26:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
                     27:  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
                     28:  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     29:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     30:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     31:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     32:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     33:  * POSSIBILITY OF SUCH DAMAGE.
                     34:  */
1.82      rmind      35:
1.24      wrstuden   36: /*
1.19      fvdl       37:  * Copyright (c) 1992, 1993, 1995
1.1       mycroft    38:  *     The Regents of the University of California.  All rights reserved.
                     39:  *
                     40:  * This code is derived from software donated to Berkeley by
                     41:  * Jan-Simon Pendry.
                     42:  *
                     43:  * Redistribution and use in source and binary forms, with or without
                     44:  * modification, are permitted provided that the following conditions
                     45:  * are met:
                     46:  * 1. Redistributions of source code must retain the above copyright
                     47:  *    notice, this list of conditions and the following disclaimer.
                     48:  * 2. Redistributions in binary form must reproduce the above copyright
                     49:  *    notice, this list of conditions and the following disclaimer in the
                     50:  *    documentation and/or other materials provided with the distribution.
1.43      agc        51:  * 3. Neither the name of the University nor the names of its contributors
1.1       mycroft    52:  *    may be used to endorse or promote products derived from this software
                     53:  *    without specific prior written permission.
                     54:  *
                     55:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     56:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     57:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     58:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     59:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     60:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     61:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     62:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     63:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     64:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     65:  * SUCH DAMAGE.
                     66:  *
                     67:  *     from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
                     68:  *     from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
1.19      fvdl       69:  *     @(#)null_vfsops.c       8.7 (Berkeley) 5/14/95
1.1       mycroft    70:  */
                     71:
                     72: /*
1.82      rmind      73:  * Null file-system: VFS operations.
                     74:  *
                     75:  * See null_vnops.c for a description.
1.1       mycroft    76:  */
1.36      lukem      77:
                     78: #include <sys/cdefs.h>
1.85    ! hannken    79: __KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $");
1.1       mycroft    80:
                     81: #include <sys/param.h>
                     82: #include <sys/systm.h>
1.44      atatat     83: #include <sys/sysctl.h>
1.1       mycroft    84: #include <sys/vnode.h>
                     85: #include <sys/mount.h>
                     86: #include <sys/namei.h>
                     87: #include <sys/malloc.h>
1.76      rumble     88: #include <sys/module.h>
1.33      enami      89:
1.1       mycroft    90: #include <miscfs/nullfs/null.h>
1.24      wrstuden   91: #include <miscfs/genfs/layer_extern.h>
1.1       mycroft    92:
1.80      jld        93: MODULE(MODULE_CLASS_VFS, null, "layerfs");
1.76      rumble     94:
1.68      pooka      95: VFS_PROTOS(nullfs);
1.24      wrstuden   96:
1.77      ad         97: static struct sysctllog *nullfs_sysctl_log;
                     98:
1.1       mycroft    99: int
1.79      dsl       100: nullfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
1.1       mycroft   101: {
1.82      rmind     102:        struct vnode *lowerrootvp, *vp;
1.65      dsl       103:        struct null_args *args = data;
1.24      wrstuden  104:        struct null_mount *nmp;
                    105:        struct layer_mount *lmp;
1.83      dholland  106:        struct pathbuf *pb;
1.82      rmind     107:        struct nameidata nd;
                    108:        int error;
1.1       mycroft   109:
1.82      rmind     110:        if (*data_len < sizeof(*args))
1.65      dsl       111:                return EINVAL;
                    112:
1.38      christos  113:        if (mp->mnt_flag & MNT_GETARGS) {
                    114:                lmp = MOUNTTOLAYERMOUNT(mp);
                    115:                if (lmp == NULL)
                    116:                        return EIO;
1.65      dsl       117:                args->la.target = NULL;
1.82      rmind     118:                *data_len = sizeof(*args);
1.65      dsl       119:                return 0;
1.38      christos  120:        }
1.1       mycroft   121:
1.82      rmind     122:        /* Update is not supported. */
1.57      jmmv      123:        if (mp->mnt_flag & MNT_UPDATE)
                    124:                return EOPNOTSUPP;
1.24      wrstuden  125:
1.82      rmind     126:        /* Find the lower vnode and lock it. */
1.83      dholland  127:        error = pathbuf_copyin(args->la.target, &pb);
                    128:        if (error) {
                    129:                return error;
                    130:        }
                    131:        NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb);
1.82      rmind     132:        if ((error = namei(&nd)) != 0) {
1.83      dholland  133:                pathbuf_destroy(pb);
1.82      rmind     134:                return error;
                    135:        }
1.68      pooka     136:        lowerrootvp = nd.ni_vp;
1.83      dholland  137:        pathbuf_destroy(pb);
1.1       mycroft   138:
1.82      rmind     139:        /* Create the mount point. */
1.84      rmind     140:        nmp = kmem_zalloc(sizeof(struct null_mount), KM_SLEEP);
1.37      soren     141:        mp->mnt_data = nmp;
1.24      wrstuden  142:        nmp->nullm_vfs = lowerrootvp->v_mount;
                    143:        if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL)
                    144:                mp->mnt_flag |= MNT_LOCAL;
1.1       mycroft   145:
                    146:        /*
1.24      wrstuden  147:         * Make sure that the mount point is sufficiently initialized
                    148:         * that the node create call will work.
1.1       mycroft   149:         */
1.27      assar     150:        vfs_getnewfsid(mp);
1.24      wrstuden  151:
1.33      enami     152:        nmp->nullm_size = sizeof(struct null_node);
1.24      wrstuden  153:        nmp->nullm_tag = VT_NULL;
                    154:        nmp->nullm_bypass = layer_bypass;
                    155:        nmp->nullm_alloc = layer_node_alloc;    /* the default alloc is fine */
                    156:        nmp->nullm_vnodeop_p = null_vnodeop_p;
1.69      ad        157:        mutex_init(&nmp->nullm_hashlock, MUTEX_DEFAULT, IPL_NONE);
1.75      ad        158:        nmp->nullm_node_hashtbl = hashinit(desiredvnodes, HASH_LIST, true,
                    159:            &nmp->nullm_node_hash);
1.1       mycroft   160:
1.82      rmind     161:        /* Setup a null node for root vnode. */
1.85    ! hannken   162:        VOP_UNLOCK(lowerrootvp);
1.24      wrstuden  163:        error = layer_node_create(mp, lowerrootvp, &vp);
1.1       mycroft   164:        if (error) {
1.85    ! hannken   165:                vrele(lowerrootvp);
1.75      ad        166:                hashdone(nmp->nullm_node_hashtbl, HASH_LIST,
                    167:                    nmp->nullm_node_hash);
1.84      rmind     168:                kmem_free(nmp, sizeof(struct null_mount));
1.82      rmind     169:                return error;
1.1       mycroft   170:        }
1.21      wrstuden  171:        /*
1.82      rmind     172:         * Keep a held reference to the root vnode.  It will be released on
                    173:         * umount.  Note: nullfs is MP-safe.
1.21      wrstuden  174:         */
1.85    ! hannken   175:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.69      ad        176:        vp->v_vflag |= VV_ROOT;
1.72      ad        177:        nmp->nullm_rootvp = vp;
                    178:        mp->mnt_iflag |= IMNT_MPSAFE;
1.81      hannken   179:        VOP_UNLOCK(vp);
1.1       mycroft   180:
1.65      dsl       181:        error = set_statvfs_info(path, UIO_USERSPACE, args->la.target,
1.82      rmind     182:            UIO_USERSPACE, mp->mnt_op->vfs_name, mp, curlwp);
1.54      perry     183:        return error;
1.1       mycroft   184: }
                    185:
                    186: int
1.70      pooka     187: nullfs_unmount(struct mount *mp, int mntflags)
1.1       mycroft   188: {
1.34      enami     189:        struct null_mount *nmp = MOUNTTONULLMOUNT(mp);
                    190:        struct vnode *null_rootvp = nmp->nullm_rootvp;
1.82      rmind     191:        int error, flags = 0;
1.1       mycroft   192:
1.19      fvdl      193:        if (mntflags & MNT_FORCE)
1.1       mycroft   194:                flags |= FORCECLOSE;
                    195:
1.64      pooka     196:        if (null_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
1.82      rmind     197:                return EBUSY;
                    198:
1.24      wrstuden  199:        if ((error = vflush(mp, null_rootvp, flags)) != 0)
1.82      rmind     200:                return error;
1.1       mycroft   201:
1.82      rmind     202:        /* Eliminate all activity and release the vnode. */
1.24      wrstuden  203:        vgone(null_rootvp);
1.33      enami     204:
1.82      rmind     205:        /* Finally, destroy the mount point structures. */
1.75      ad        206:        hashdone(nmp->nullm_node_hashtbl, HASH_LIST, nmp->nullm_node_hash);
1.69      ad        207:        mutex_destroy(&nmp->nullm_hashlock);
1.84      rmind     208:        kmem_free(mp->mnt_data, sizeof(struct null_mount));
1.33      enami     209:        mp->mnt_data = NULL;
1.82      rmind     210:        return 0;
1.1       mycroft   211: }
                    212:
1.29      jdolecek  213: extern const struct vnodeopv_desc null_vnodeop_opv_desc;
1.18      thorpej   214:
1.29      jdolecek  215: const struct vnodeopv_desc * const nullfs_vnodeopv_descs[] = {
1.19      fvdl      216:        &null_vnodeop_opv_desc,
1.18      thorpej   217:        NULL,
                    218: };
                    219:
1.17      thorpej   220: struct vfsops nullfs_vfsops = {
1.1       mycroft   221:        MOUNT_NULL,
1.65      dsl       222:        sizeof (struct null_args),
1.1       mycroft   223:        nullfs_mount,
1.24      wrstuden  224:        layerfs_start,
1.1       mycroft   225:        nullfs_unmount,
1.24      wrstuden  226:        layerfs_root,
                    227:        layerfs_quotactl,
1.47      christos  228:        layerfs_statvfs,
1.24      wrstuden  229:        layerfs_sync,
                    230:        layerfs_vget,
                    231:        layerfs_fhtovp,
                    232:        layerfs_vptofh,
                    233:        layerfs_init,
1.32      chs       234:        NULL,
1.26      jdolecek  235:        layerfs_done,
1.18      thorpej   236:        NULL,                           /* vfs_mountroot */
1.51      wrstuden  237:        layerfs_snapshot,
1.53      thorpej   238:        vfs_stdextattrctl,
1.67      pooka     239:        (void *)eopnotsupp,             /* vfs_suspendctl */
1.73      dholland  240:        layerfs_renamelock_enter,
                    241:        layerfs_renamelock_exit,
1.74      ad        242:        (void *)eopnotsupp,
1.18      thorpej   243:        nullfs_vnodeopv_descs,
1.59      christos  244:        0,
                    245:        { NULL, NULL },
1.1       mycroft   246: };
1.76      rumble    247:
                    248: static int
1.80      jld       249: null_modcmd(modcmd_t cmd, void *arg)
1.76      rumble    250: {
1.77      ad        251:        int error;
1.76      rumble    252:
                    253:        switch (cmd) {
                    254:        case MODULE_CMD_INIT:
1.77      ad        255:                error = vfs_attach(&nullfs_vfsops);
                    256:                if (error != 0)
                    257:                        break;
                    258:                sysctl_createv(&nullfs_sysctl_log, 0, NULL, NULL,
                    259:                    CTLFLAG_PERMANENT,
                    260:                    CTLTYPE_NODE, "vfs", NULL,
                    261:                    NULL, 0, NULL, 0,
                    262:                    CTL_VFS, CTL_EOL);
                    263:                sysctl_createv(&nullfs_sysctl_log, 0, NULL, NULL,
                    264:                    CTLFLAG_PERMANENT,
                    265:                    CTLTYPE_NODE, "null",
                    266:                    SYSCTL_DESCR("Loopback file system"),
                    267:                    NULL, 0, NULL, 0,
                    268:                    CTL_VFS, 9, CTL_EOL);
                    269:                /*
                    270:                 * XXX the "9" above could be dynamic, thereby eliminating
                    271:                 * one more instance of the "number to vfs" mapping problem,
                    272:                 * but "9" is the order as taken from sys/mount.h
                    273:                 */
                    274:                break;
1.76      rumble    275:        case MODULE_CMD_FINI:
1.77      ad        276:                error = vfs_detach(&nullfs_vfsops);
                    277:                if (error != 0)
                    278:                        break;
                    279:                sysctl_teardown(&nullfs_sysctl_log);
                    280:                break;
1.76      rumble    281:        default:
1.77      ad        282:                error = ENOTTY;
                    283:                break;
1.76      rumble    284:        }
1.77      ad        285:        return error;
1.76      rumble    286: }

CVSweb <webmaster@jp.NetBSD.org>