Annotation of XNU/bsd/miscfs/nullfs/null_vnops.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
        !            23: /*
        !            24:  * Copyright (c) 1992, 1993
        !            25:  *     The Regents of the University of California.  All rights reserved.
        !            26:  *
        !            27:  * This code is derived from software contributed to Berkeley by
        !            28:  * John Heidemann of the UCLA Ficus project.
        !            29:  *
        !            30:  * Redistribution and use in source and binary forms, with or without
        !            31:  * modification, are permitted provided that the following conditions
        !            32:  * are met:
        !            33:  * 1. Redistributions of source code must retain the above copyright
        !            34:  *    notice, this list of conditions and the following disclaimer.
        !            35:  * 2. Redistributions in binary form must reproduce the above copyright
        !            36:  *    notice, this list of conditions and the following disclaimer in the
        !            37:  *    documentation and/or other materials provided with the distribution.
        !            38:  * 3. All advertising materials mentioning features or use of this software
        !            39:  *    must display the following acknowledgement:
        !            40:  *     This product includes software developed by the University of
        !            41:  *     California, Berkeley and its contributors.
        !            42:  * 4. Neither the name of the University nor the names of its contributors
        !            43:  *    may be used to endorse or promote products derived from this software
        !            44:  *    without specific prior written permission.
        !            45:  *
        !            46:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            47:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            48:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            49:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            50:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            51:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            52:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            53:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            54:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            55:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            56:  * SUCH DAMAGE.
        !            57:  *
        !            58:  *     @(#)null_vnops.c        8.6 (Berkeley) 5/27/95
        !            59:  *
        !            60:  * Ancestors:
        !            61:  *     @(#)lofs_vnops.c        1.2 (Berkeley) 6/18/92
        !            62:  *     ...and...
        !            63:  *     @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
        !            64:  */
        !            65: 
        !            66: /*
        !            67:  * Null Layer
        !            68:  *
        !            69:  * (See mount_null(8) for more information.)
        !            70:  *
        !            71:  * The null layer duplicates a portion of the file system
        !            72:  * name space under a new name.  In this respect, it is
        !            73:  * similar to the loopback file system.  It differs from
        !            74:  * the loopback fs in two respects:  it is implemented using
        !            75:  * a stackable layers techniques, and it's "null-node"s stack above
        !            76:  * all lower-layer vnodes, not just over directory vnodes.
        !            77:  *
        !            78:  * The null layer has two purposes.  First, it serves as a demonstration
        !            79:  * of layering by proving a layer which does nothing.  (It actually
        !            80:  * does everything the loopback file system does, which is slightly
        !            81:  * more than nothing.)  Second, the null layer can serve as a prototype
        !            82:  * layer.  Since it provides all necessary layer framework,
        !            83:  * new file system layers can be created very easily be starting
        !            84:  * with a null layer.
        !            85:  *
        !            86:  * The remainder of this man page examines the null layer as a basis
        !            87:  * for constructing new layers.
        !            88:  *
        !            89:  *
        !            90:  * INSTANTIATING NEW NULL LAYERS
        !            91:  *
        !            92:  * New null layers are created with mount_null(8).
        !            93:  * Mount_null(8) takes two arguments, the pathname
        !            94:  * of the lower vfs (target-pn) and the pathname where the null
        !            95:  * layer will appear in the namespace (alias-pn).  After
        !            96:  * the null layer is put into place, the contents
        !            97:  * of target-pn subtree will be aliased under alias-pn.
        !            98:  *
        !            99:  *
        !           100:  * OPERATION OF A NULL LAYER
        !           101:  *
        !           102:  * The null layer is the minimum file system layer,
        !           103:  * simply bypassing all possible operations to the lower layer
        !           104:  * for processing there.  The majority of its activity centers
        !           105:  * on the bypass routine, though which nearly all vnode operations
        !           106:  * pass.
        !           107:  *
        !           108:  * The bypass routine accepts arbitrary vnode operations for
        !           109:  * handling by the lower layer.  It begins by examing vnode
        !           110:  * operation arguments and replacing any null-nodes by their
        !           111:  * lower-layer equivlants.  It then invokes the operation
        !           112:  * on the lower layer.  Finally, it replaces the null-nodes
        !           113:  * in the arguments and, if a vnode is return by the operation,
        !           114:  * stacks a null-node on top of the returned vnode.
        !           115:  *
        !           116:  * Although bypass handles most operations, vop_getattr, vop_lock,
        !           117:  * vop_unlock, vop_inactive, vop_reclaim, and vop_print are not
        !           118:  * bypassed. Vop_getattr must change the fsid being returned.
        !           119:  * Vop_lock and vop_unlock must handle any locking for the
        !           120:  * current vnode as well as pass the lock request down.
        !           121:  * Vop_inactive and vop_reclaim are not bypassed so that
        !           122:  * they can handle freeing null-layer specific data. Vop_print
        !           123:  * is not bypassed to avoid excessive debugging information.
        !           124:  * Also, certain vnode operations change the locking state within
        !           125:  * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
        !           126:  * and symlink). Ideally these operations should not change the
        !           127:  * lock state, but should be changed to let the caller of the
        !           128:  * function unlock them. Otherwise all intermediate vnode layers
        !           129:  * (such as union, umapfs, etc) must catch these functions to do
        !           130:  * the necessary locking at their layer.
        !           131:  *
        !           132:  *
        !           133:  * INSTANTIATING VNODE STACKS
        !           134:  *
        !           135:  * Mounting associates the null layer with a lower layer,
        !           136:  * effect stacking two VFSes.  Vnode stacks are instead
        !           137:  * created on demand as files are accessed.
        !           138:  *
        !           139:  * The initial mount creates a single vnode stack for the
        !           140:  * root of the new null layer.  All other vnode stacks
        !           141:  * are created as a result of vnode operations on
        !           142:  * this or other null vnode stacks.
        !           143:  *
        !           144:  * New vnode stacks come into existance as a result of
        !           145:  * an operation which returns a vnode.  
        !           146:  * The bypass routine stacks a null-node above the new
        !           147:  * vnode before returning it to the caller.
        !           148:  *
        !           149:  * For example, imagine mounting a null layer with
        !           150:  * "mount_null /usr/include /dev/layer/null".
        !           151:  * Changing directory to /dev/layer/null will assign
        !           152:  * the root null-node (which was created when the null layer was mounted).
        !           153:  * Now consider opening "sys".  A vop_lookup would be
        !           154:  * done on the root null-node.  This operation would bypass through
        !           155:  * to the lower layer which would return a vnode representing 
        !           156:  * the UFS "sys".  Null_bypass then builds a null-node
        !           157:  * aliasing the UFS "sys" and returns this to the caller.
        !           158:  * Later operations on the null-node "sys" will repeat this
        !           159:  * process when constructing other vnode stacks.
        !           160:  *
        !           161:  *
        !           162:  * CREATING OTHER FILE SYSTEM LAYERS
        !           163:  *
        !           164:  * One of the easiest ways to construct new file system layers is to make
        !           165:  * a copy of the null layer, rename all files and variables, and
        !           166:  * then begin modifing the copy.  Sed can be used to easily rename
        !           167:  * all variables.
        !           168:  *
        !           169:  * The umap layer is an example of a layer descended from the 
        !           170:  * null layer.
        !           171:  *
        !           172:  *
        !           173:  * INVOKING OPERATIONS ON LOWER LAYERS
        !           174:  *
        !           175:  * There are two techniques to invoke operations on a lower layer 
        !           176:  * when the operation cannot be completely bypassed.  Each method
        !           177:  * is appropriate in different situations.  In both cases,
        !           178:  * it is the responsibility of the aliasing layer to make
        !           179:  * the operation arguments "correct" for the lower layer
        !           180:  * by mapping an vnode arguments to the lower layer.
        !           181:  *
        !           182:  * The first approach is to call the aliasing layer's bypass routine.
        !           183:  * This method is most suitable when you wish to invoke the operation
        !           184:  * currently being hanldled on the lower layer.  It has the advantage
        !           185:  * that the bypass routine already must do argument mapping.
        !           186:  * An example of this is null_getattrs in the null layer.
        !           187:  *
        !           188:  * A second approach is to directly invoked vnode operations on
        !           189:  * the lower layer with the VOP_OPERATIONNAME interface.
        !           190:  * The advantage of this method is that it is easy to invoke
        !           191:  * arbitrary operations on the lower layer.  The disadvantage
        !           192:  * is that vnodes arguments must be manualy mapped.
        !           193:  *
        !           194:  */
        !           195: 
        !           196: #include <sys/param.h>
        !           197: #include <sys/systm.h>
        !           198: #include <sys/proc.h>
        !           199: #include <sys/time.h>
        !           200: #include <sys/types.h>
        !           201: #include <sys/vnode.h>
        !           202: #include <sys/mount.h>
        !           203: #include <sys/namei.h>
        !           204: #include <sys/malloc.h>
        !           205: #include <sys/buf.h>
        !           206: #include <miscfs/nullfs/null.h>
        !           207: 
        !           208: 
        !           209: int null_bug_bypass = 0;   /* for debugging: enables bypass printf'ing */
        !           210: 
        !           211: /*
        !           212:  * This is the 10-Apr-92 bypass routine.
        !           213:  *    This version has been optimized for speed, throwing away some
        !           214:  * safety checks.  It should still always work, but it's not as
        !           215:  * robust to programmer errors.
        !           216:  *    Define SAFETY to include some error checking code.
        !           217:  *
        !           218:  * In general, we map all vnodes going down and unmap them on the way back.
        !           219:  * As an exception to this, vnodes can be marked "unmapped" by setting
        !           220:  * the Nth bit in operation's vdesc_flags.
        !           221:  *
        !           222:  * Also, some BSD vnode operations have the side effect of vrele'ing
        !           223:  * their arguments.  With stacking, the reference counts are held
        !           224:  * by the upper node, not the lower one, so we must handle these
        !           225:  * side-effects here.  This is not of concern in Sun-derived systems
        !           226:  * since there are no such side-effects.
        !           227:  *
        !           228:  * This makes the following assumptions:
        !           229:  * - only one returned vpp
        !           230:  * - no INOUT vpp's (Sun's vop_open has one of these)
        !           231:  * - the vnode operation vector of the first vnode should be used
        !           232:  *   to determine what implementation of the op should be invoked
        !           233:  * - all mapped vnodes are of our vnode-type (NEEDSWORK:
        !           234:  *   problems on rmdir'ing mount points and renaming?)
        !           235:  */ 
        !           236: int
        !           237: null_bypass(ap)
        !           238:        struct vop_generic_args /* {
        !           239:                struct vnodeop_desc *a_desc;
        !           240:                <other random data follows, presumably>
        !           241:        } */ *ap;
        !           242: {
        !           243:        extern int (**null_vnodeop_p)();  /* not extern, really "forward" */
        !           244:        register struct vnode **this_vp_p;
        !           245:        int error;
        !           246:        struct vnode *old_vps[VDESC_MAX_VPS];
        !           247:        struct vnode **vps_p[VDESC_MAX_VPS];
        !           248:        struct vnode ***vppp;
        !           249:        struct vnodeop_desc *descp = ap->a_desc;
        !           250:        int reles, i;
        !           251: 
        !           252:        if (null_bug_bypass)
        !           253:                printf ("null_bypass: %s\n", descp->vdesc_name);
        !           254: 
        !           255: #ifdef SAFETY
        !           256:        /*
        !           257:         * We require at least one vp.
        !           258:         */
        !           259:        if (descp->vdesc_vp_offsets == NULL ||
        !           260:            descp->vdesc_vp_offsets[0] == VDESC_NO_OFFSET)
        !           261:                panic ("null_bypass: no vp's in map.\n");
        !           262: #endif
        !           263: 
        !           264:        /*
        !           265:         * Map the vnodes going in.
        !           266:         * Later, we'll invoke the operation based on
        !           267:         * the first mapped vnode's operation vector.
        !           268:         */
        !           269:        reles = descp->vdesc_flags;
        !           270:        for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
        !           271:                if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
        !           272:                        break;   /* bail out at end of list */
        !           273:                vps_p[i] = this_vp_p = 
        !           274:                        VOPARG_OFFSETTO(struct vnode**,descp->vdesc_vp_offsets[i],ap);
        !           275:                /*
        !           276:                 * We're not guaranteed that any but the first vnode
        !           277:                 * are of our type.  Check for and don't map any
        !           278:                 * that aren't.  (We must always map first vp or vclean fails.)
        !           279:                 */
        !           280:                if (i && (*this_vp_p == NULL ||
        !           281:                    (*this_vp_p)->v_op != null_vnodeop_p)) {
        !           282:                        old_vps[i] = NULL;
        !           283:                } else {
        !           284:                        old_vps[i] = *this_vp_p;
        !           285:                        *(vps_p[i]) = NULLVPTOLOWERVP(*this_vp_p);
        !           286:                        /*
        !           287:                         * XXX - Several operations have the side effect
        !           288:                         * of vrele'ing their vp's.  We must account for
        !           289:                         * that.  (This should go away in the future.)
        !           290:                         */
        !           291:                        if (reles & 1)
        !           292:                                VREF(*this_vp_p);
        !           293:                }
        !           294:                        
        !           295:        }
        !           296: 
        !           297:        /*
        !           298:         * Call the operation on the lower layer
        !           299:         * with the modified argument structure.
        !           300:         */
        !           301:        error = VCALL(*(vps_p[0]), descp->vdesc_offset, ap);
        !           302: 
        !           303:        /*
        !           304:         * Maintain the illusion of call-by-value
        !           305:         * by restoring vnodes in the argument structure
        !           306:         * to their original value.
        !           307:         */
        !           308:        reles = descp->vdesc_flags;
        !           309:        for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
        !           310:                if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
        !           311:                        break;   /* bail out at end of list */
        !           312:                if (old_vps[i]) {
        !           313:                        *(vps_p[i]) = old_vps[i];
        !           314:                        if (reles & 1)
        !           315:                                vrele(*(vps_p[i]));
        !           316:                }
        !           317:        }
        !           318: 
        !           319:        /*
        !           320:         * Map the possible out-going vpp
        !           321:         * (Assumes that the lower layer always returns
        !           322:         * a VREF'ed vpp unless it gets an error.)
        !           323:         */
        !           324:        if (descp->vdesc_vpp_offset != VDESC_NO_OFFSET &&
        !           325:            !(descp->vdesc_flags & VDESC_NOMAP_VPP) &&
        !           326:            !error) {
        !           327:                /*
        !           328:                 * XXX - even though some ops have vpp returned vp's,
        !           329:                 * several ops actually vrele this before returning.
        !           330:                 * We must avoid these ops.
        !           331:                 * (This should go away when these ops are regularized.)
        !           332:                 */
        !           333:                if (descp->vdesc_flags & VDESC_VPP_WILLRELE)
        !           334:                        goto out;
        !           335:                vppp = VOPARG_OFFSETTO(struct vnode***,
        !           336:                                 descp->vdesc_vpp_offset,ap);
        !           337:                error = null_node_create(old_vps[0]->v_mount, **vppp, *vppp);
        !           338:        }
        !           339: 
        !           340:  out:
        !           341:        return (error);
        !           342: }
        !           343: 
        !           344: /*
        !           345:  * We have to carry on the locking protocol on the null layer vnodes
        !           346:  * as we progress through the tree. We also have to enforce read-only
        !           347:  * if this layer is mounted read-only.
        !           348:  */
        !           349: null_lookup(ap)
        !           350:        struct vop_lookup_args /* {
        !           351:                struct vnode * a_dvp;
        !           352:                struct vnode ** a_vpp;
        !           353:                struct componentname * a_cnp;
        !           354:        } */ *ap;
        !           355: {
        !           356:        struct componentname *cnp = ap->a_cnp;
        !           357:        struct proc *p = cnp->cn_proc;
        !           358:        int flags = cnp->cn_flags;
        !           359:        struct vop_lock_args lockargs;
        !           360:        struct vop_unlock_args unlockargs;
        !           361:        struct vnode *dvp, *vp;
        !           362:        int error;
        !           363: 
        !           364:        if ((flags & ISLASTCN) && (ap->a_dvp->v_mount->mnt_flag & MNT_RDONLY) &&
        !           365:            (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
        !           366:                return (EROFS);
        !           367:        error = null_bypass(ap);
        !           368:        if (error == EJUSTRETURN && (flags & ISLASTCN) &&
        !           369:            (ap->a_dvp->v_mount->mnt_flag & MNT_RDONLY) &&
        !           370:            (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
        !           371:                error = EROFS;
        !           372:        /*
        !           373:         * We must do the same locking and unlocking at this layer as 
        !           374:         * is done in the layers below us. We could figure this out 
        !           375:         * based on the error return and the LASTCN, LOCKPARENT, and
        !           376:         * LOCKLEAF flags. However, it is more expidient to just find 
        !           377:         * out the state of the lower level vnodes and set ours to the
        !           378:         * same state.
        !           379:         */
        !           380:        dvp = ap->a_dvp;
        !           381:        vp = *ap->a_vpp;
        !           382:        if (dvp == vp)
        !           383:                return (error);
        !           384:        if (!VOP_ISLOCKED(dvp)) {
        !           385:                unlockargs.a_vp = dvp;
        !           386:                unlockargs.a_flags = 0;
        !           387:                unlockargs.a_p = p;
        !           388:                vop_nounlock(&unlockargs);
        !           389:        }
        !           390:        if (vp != NULL && VOP_ISLOCKED(vp)) {
        !           391:                lockargs.a_vp = vp;
        !           392:                lockargs.a_flags = LK_SHARED;
        !           393:                lockargs.a_p = p;
        !           394:                vop_nolock(&lockargs);
        !           395:        }
        !           396:        return (error);
        !           397: }
        !           398: 
        !           399: /*
        !           400:  * Setattr call. Disallow write attempts if the layer is mounted read-only.
        !           401:  */
        !           402: int
        !           403: null_setattr(ap)
        !           404:        struct vop_setattr_args /* {
        !           405:                struct vnodeop_desc *a_desc;
        !           406:                struct vnode *a_vp;
        !           407:                struct vattr *a_vap;
        !           408:                struct ucred *a_cred;
        !           409:                struct proc *a_p;
        !           410:        } */ *ap;
        !           411: {
        !           412:        struct vnode *vp = ap->a_vp;
        !           413:        struct vattr *vap = ap->a_vap;
        !           414: 
        !           415:        if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
        !           416:            vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
        !           417:            vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) &&
        !           418:            (vp->v_mount->mnt_flag & MNT_RDONLY))
        !           419:                return (EROFS);
        !           420:        if (vap->va_size != VNOVAL) {
        !           421:                switch (vp->v_type) {
        !           422:                case VDIR:
        !           423:                        return (EISDIR);
        !           424:                case VCHR:
        !           425:                case VBLK:
        !           426:                case VSOCK:
        !           427:                case VFIFO:
        !           428:                        return (0);
        !           429:                case VREG:
        !           430:                case VLNK:
        !           431:                default:
        !           432:                        /*
        !           433:                         * Disallow write attempts if the filesystem is
        !           434:                         * mounted read-only.
        !           435:                         */
        !           436:                        if (vp->v_mount->mnt_flag & MNT_RDONLY)
        !           437:                                return (EROFS);
        !           438:                }
        !           439:        }
        !           440:        return (null_bypass(ap));
        !           441: }
        !           442: 
        !           443: /*
        !           444:  *  We handle getattr only to change the fsid.
        !           445:  */
        !           446: int
        !           447: null_getattr(ap)
        !           448:        struct vop_getattr_args /* {
        !           449:                struct vnode *a_vp;
        !           450:                struct vattr *a_vap;
        !           451:                struct ucred *a_cred;
        !           452:                struct proc *a_p;
        !           453:        } */ *ap;
        !           454: {
        !           455:        int error;
        !           456: 
        !           457:        if (error = null_bypass(ap))
        !           458:                return (error);
        !           459:        /* Requires that arguments be restored. */
        !           460:        ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0];
        !           461:        return (0);
        !           462: }
        !           463: 
        !           464: int
        !           465: null_access(ap)
        !           466:        struct vop_access_args /* {
        !           467:                struct vnode *a_vp;
        !           468:                int  a_mode;
        !           469:                struct ucred *a_cred;
        !           470:                struct proc *a_p;
        !           471:        } */ *ap;
        !           472: {
        !           473:        struct vnode *vp = ap->a_vp;
        !           474:        mode_t mode = ap->a_mode;
        !           475: 
        !           476:        /*
        !           477:         * Disallow write attempts on read-only layers;
        !           478:         * unless the file is a socket, fifo, or a block or
        !           479:         * character device resident on the file system.
        !           480:         */
        !           481:        if (mode & VWRITE) {
        !           482:                switch (vp->v_type) {
        !           483:                case VDIR:
        !           484:                case VLNK:
        !           485:                case VREG:
        !           486:                        if (vp->v_mount->mnt_flag & MNT_RDONLY)
        !           487:                                return (EROFS);
        !           488:                        break;
        !           489:                }
        !           490:        }
        !           491:        return (null_bypass(ap));
        !           492: }
        !           493: 
        !           494: /*
        !           495:  * We need to process our own vnode lock and then clear the
        !           496:  * interlock flag as it applies only to our vnode, not the
        !           497:  * vnodes below us on the stack.
        !           498:  */
        !           499: int
        !           500: null_lock(ap)
        !           501:        struct vop_lock_args /* {
        !           502:                struct vnode *a_vp;
        !           503:                int a_flags;
        !           504:                struct proc *a_p;
        !           505:        } */ *ap;
        !           506: {
        !           507: 
        !           508:        vop_nolock(ap);
        !           509:        if ((ap->a_flags & LK_TYPE_MASK) == LK_DRAIN)
        !           510:                return (0);
        !           511:        ap->a_flags &= ~LK_INTERLOCK;
        !           512:        return (null_bypass(ap));
        !           513: }
        !           514: 
        !           515: /*
        !           516:  * We need to process our own vnode unlock and then clear the
        !           517:  * interlock flag as it applies only to our vnode, not the
        !           518:  * vnodes below us on the stack.
        !           519:  */
        !           520: int
        !           521: null_unlock(ap)
        !           522:        struct vop_unlock_args /* {
        !           523:                struct vnode *a_vp;
        !           524:                int a_flags;
        !           525:                struct proc *a_p;
        !           526:        } */ *ap;
        !           527: {
        !           528:        struct vnode *vp = ap->a_vp;
        !           529: 
        !           530:        vop_nounlock(ap);
        !           531:        ap->a_flags &= ~LK_INTERLOCK;
        !           532:        return (null_bypass(ap));
        !           533: }
        !           534: 
        !           535: int
        !           536: null_inactive(ap)
        !           537:        struct vop_inactive_args /* {
        !           538:                struct vnode *a_vp;
        !           539:                struct proc *a_p;
        !           540:        } */ *ap;
        !           541: {
        !           542:        /*
        !           543:         * Do nothing (and _don't_ bypass).
        !           544:         * Wait to vrele lowervp until reclaim,
        !           545:         * so that until then our null_node is in the
        !           546:         * cache and reusable.
        !           547:         *
        !           548:         * NEEDSWORK: Someday, consider inactive'ing
        !           549:         * the lowervp and then trying to reactivate it
        !           550:         * with capabilities (v_id)
        !           551:         * like they do in the name lookup cache code.
        !           552:         * That's too much work for now.
        !           553:         */
        !           554:        VOP_UNLOCK(ap->a_vp, 0, ap->a_p);
        !           555:        return (0);
        !           556: }
        !           557: 
        !           558: int
        !           559: null_reclaim(ap)
        !           560:        struct vop_reclaim_args /* {
        !           561:                struct vnode *a_vp;
        !           562:                struct proc *a_p;
        !           563:        } */ *ap;
        !           564: {
        !           565:        struct vnode *vp = ap->a_vp;
        !           566:        struct null_node *xp = VTONULL(vp);
        !           567:        struct vnode *lowervp = xp->null_lowervp;
        !           568: 
        !           569:        /*
        !           570:         * Note: in vop_reclaim, vp->v_op == dead_vnodeop_p,
        !           571:         * so we can't call VOPs on ourself.
        !           572:         */
        !           573:        /* After this assignment, this node will not be re-used. */
        !           574:        xp->null_lowervp = NULL;
        !           575:        LIST_REMOVE(xp, null_hash);
        !           576:        FREE(vp->v_data, M_TEMP);
        !           577:        vp->v_data = NULL;
        !           578:        vrele (lowervp);
        !           579:        return (0);
        !           580: }
        !           581: 
        !           582: int
        !           583: null_print(ap)
        !           584:        struct vop_print_args /* {
        !           585:                struct vnode *a_vp;
        !           586:        } */ *ap;
        !           587: {
        !           588:        register struct vnode *vp = ap->a_vp;
        !           589:        printf ("\ttag VT_NULLFS, vp=%x, lowervp=%x\n", vp, NULLVPTOLOWERVP(vp));
        !           590:        return (0);
        !           591: }
        !           592: 
        !           593: /*
        !           594:  * XXX - vop_strategy must be hand coded because it has no
        !           595:  * vnode in its arguments.
        !           596:  * This goes away with a merged VM/buffer cache.
        !           597:  */
        !           598: int
        !           599: null_strategy(ap)
        !           600:        struct vop_strategy_args /* {
        !           601:                struct buf *a_bp;
        !           602:        } */ *ap;
        !           603: {
        !           604:        struct buf *bp = ap->a_bp;
        !           605:        int error;
        !           606:        struct vnode *savedvp;
        !           607: 
        !           608:        savedvp = bp->b_vp;
        !           609:        bp->b_vp = NULLVPTOLOWERVP(bp->b_vp);
        !           610: 
        !           611:        error = VOP_STRATEGY(bp);
        !           612: 
        !           613:        bp->b_vp = savedvp;
        !           614: 
        !           615:        return (error);
        !           616: }
        !           617: 
        !           618: /*
        !           619:  * XXX - like vop_strategy, vop_bwrite must be hand coded because it has no
        !           620:  * vnode in its arguments.
        !           621:  * This goes away with a merged VM/buffer cache.
        !           622:  */
        !           623: int
        !           624: null_bwrite(ap)
        !           625:        struct vop_bwrite_args /* {
        !           626:                struct buf *a_bp;
        !           627:        } */ *ap;
        !           628: {
        !           629:        struct buf *bp = ap->a_bp;
        !           630:        int error;
        !           631:        struct vnode *savedvp;
        !           632: 
        !           633:        savedvp = bp->b_vp;
        !           634:        bp->b_vp = NULLVPTOLOWERVP(bp->b_vp);
        !           635: 
        !           636:        error = VOP_BWRITE(bp);
        !           637: 
        !           638:        bp->b_vp = savedvp;
        !           639: 
        !           640:        return (error);
        !           641: }
        !           642: 
        !           643: /*
        !           644:  * Global vfs data structures
        !           645:  */
        !           646: int (**null_vnodeop_p)();
        !           647: struct vnodeopv_entry_desc null_vnodeop_entries[] = {
        !           648:        { &vop_default_desc, null_bypass },
        !           649: 
        !           650:        { &vop_lookup_desc, null_lookup },
        !           651:        { &vop_setattr_desc, null_setattr },
        !           652:        { &vop_getattr_desc, null_getattr },
        !           653:        { &vop_access_desc, null_access },
        !           654:        { &vop_lock_desc, null_lock },
        !           655:        { &vop_unlock_desc, null_unlock },
        !           656:        { &vop_inactive_desc, null_inactive },
        !           657:        { &vop_reclaim_desc, null_reclaim },
        !           658:        { &vop_print_desc, null_print },
        !           659: 
        !           660:        { &vop_strategy_desc, null_strategy },
        !           661:        { &vop_bwrite_desc, null_bwrite },
        !           662: 
        !           663:        { (struct vnodeop_desc*)NULL, (int(*)())NULL }
        !           664: };
        !           665: struct vnodeopv_desc null_vnodeop_opv_desc =
        !           666:        { &null_vnodeop_p, null_vnodeop_entries };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.