The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/vfs_default.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1989, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * This code is derived from software contributed
    6  * to Berkeley by John Heidemann of the UCLA Ficus project.
    7  *
    8  * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
    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  *
   38  */
   39 
   40 #include <sys/param.h>
   41 #include <sys/systm.h>
   42 #include <sys/kernel.h>
   43 #include <sys/lock.h>
   44 #include <sys/malloc.h>
   45 #include <sys/unistd.h>
   46 #include <sys/vnode.h>
   47 #include <sys/poll.h>
   48 
   49 static int vop_nostrategy __P((struct vop_strategy_args *));
   50 
   51 /*
   52  * This vnode table stores what we want to do if the filesystem doesn't
   53  * implement a particular VOP.
   54  *
   55  * If there is no specific entry here, we will return EOPNOTSUPP.
   56  *
   57  */
   58 
   59 vop_t **default_vnodeop_p;
   60 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
   61         { &vop_default_desc,            (vop_t *) vop_eopnotsupp },
   62         { &vop_abortop_desc,            (vop_t *) vop_null },
   63         { &vop_advlock_desc,            (vop_t *) vop_einval },
   64         { &vop_bwrite_desc,             (vop_t *) vop_stdbwrite },
   65         { &vop_close_desc,              (vop_t *) vop_null },
   66         { &vop_fsync_desc,              (vop_t *) vop_null },
   67         { &vop_ioctl_desc,              (vop_t *) vop_enotty },
   68         { &vop_islocked_desc,           (vop_t *) vop_noislocked },
   69         { &vop_lease_desc,              (vop_t *) vop_null },
   70         { &vop_lock_desc,               (vop_t *) vop_nolock },
   71         { &vop_mmap_desc,               (vop_t *) vop_einval },
   72         { &vop_open_desc,               (vop_t *) vop_null },
   73         { &vop_pathconf_desc,           (vop_t *) vop_einval },
   74         { &vop_poll_desc,               (vop_t *) vop_nopoll },
   75         { &vop_readlink_desc,           (vop_t *) vop_einval },
   76         { &vop_reallocblks_desc,        (vop_t *) vop_eopnotsupp },
   77         { &vop_revoke_desc,             (vop_t *) vop_revoke },
   78         { &vop_strategy_desc,           (vop_t *) vop_nostrategy },
   79         { &vop_unlock_desc,             (vop_t *) vop_nounlock },
   80         { NULL, NULL }
   81 };
   82 
   83 static struct vnodeopv_desc default_vnodeop_opv_desc =
   84         { &default_vnodeop_p, default_vnodeop_entries };
   85 
   86 VNODEOP_SET(default_vnodeop_opv_desc);
   87 
   88 int
   89 vop_eopnotsupp(struct vop_generic_args *ap)
   90 {
   91         /*
   92         printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
   93         */
   94 
   95         return (EOPNOTSUPP);
   96 }
   97 
   98 int
   99 vop_ebadf(struct vop_generic_args *ap)
  100 {
  101 
  102         return (EBADF);
  103 }
  104 
  105 int
  106 vop_enotty(struct vop_generic_args *ap)
  107 {
  108 
  109         return (ENOTTY);
  110 }
  111 
  112 int
  113 vop_einval(struct vop_generic_args *ap)
  114 {
  115 
  116         return (EINVAL);
  117 }
  118 
  119 int
  120 vop_null(struct vop_generic_args *ap)
  121 {
  122 
  123         return (0);
  124 }
  125 
  126 int
  127 vop_defaultop(struct vop_generic_args *ap)
  128 {
  129 
  130         return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
  131 }
  132 
  133 int
  134 vop_panic(struct vop_generic_args *ap)
  135 {
  136 
  137         panic("illegal vnode op called");
  138 }
  139 
  140 static int
  141 vop_nostrategy (struct vop_strategy_args *ap)
  142 {
  143         printf("No strategy for buffer at %p\n", ap->a_bp);
  144         vprint("", ap->a_vp);
  145         vprint("", ap->a_bp->b_vp);
  146         ap->a_bp->b_flags |= B_ERROR;
  147         ap->a_bp->b_error = EOPNOTSUPP;
  148         biodone(ap->a_bp);
  149         return (EOPNOTSUPP);
  150 }
  151 
  152 int
  153 vop_stdpathconf(ap)
  154         struct vop_pathconf_args /* {
  155         struct vnode *a_vp;
  156         int a_name;
  157         int *a_retval;
  158         } */ *ap;
  159 {
  160 
  161         switch (ap->a_name) {
  162                 case _PC_LINK_MAX:
  163                         *ap->a_retval = LINK_MAX;
  164                         return (0);
  165                 case _PC_MAX_CANON:
  166                         *ap->a_retval = MAX_CANON;
  167                         return (0);
  168                 case _PC_MAX_INPUT:
  169                         *ap->a_retval = MAX_INPUT;
  170                         return (0);
  171                 case _PC_PIPE_BUF:
  172                         *ap->a_retval = PIPE_BUF;
  173                         return (0);
  174                 case _PC_CHOWN_RESTRICTED:
  175                         *ap->a_retval = 1;
  176                         return (0);
  177                 case _PC_VDISABLE:
  178                         *ap->a_retval = _POSIX_VDISABLE;
  179                         return (0);
  180                 default:
  181                         return (EINVAL);
  182         }
  183         /* NOTREACHED */
  184 }
  185 
  186 /*
  187  * Standard lock, unlock and islocked functions.
  188  *
  189  * These depend on the lock structure being the first element in the
  190  * inode, ie: vp->v_data points to the the lock!
  191  */
  192 int
  193 vop_stdlock(ap)
  194         struct vop_lock_args /* {
  195                 struct vnode *a_vp;
  196                 int a_flags;
  197                 struct proc *a_p;
  198         } */ *ap;
  199 {               
  200         struct lock *l;
  201 
  202         if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
  203                 if (ap->a_flags & LK_INTERLOCK)
  204                         simple_unlock(&ap->a_vp->v_interlock);
  205                 return 0;
  206         }
  207 
  208 #ifndef DEBUG_LOCKS
  209         return (lockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p));
  210 #else
  211         return (debuglockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p,
  212             "vop_stdlock", ap->a_vp->filename, ap->a_vp->line));
  213 #endif
  214 }
  215 
  216 int
  217 vop_stdunlock(ap)
  218         struct vop_unlock_args /* {
  219                 struct vnode *a_vp;
  220                 int a_flags;
  221                 struct proc *a_p;
  222         } */ *ap;
  223 {
  224         struct lock *l;
  225 
  226         if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
  227                 if (ap->a_flags & LK_INTERLOCK)
  228                         simple_unlock(&ap->a_vp->v_interlock);
  229                 return 0;
  230         }
  231 
  232         return (lockmgr(l, ap->a_flags | LK_RELEASE, &ap->a_vp->v_interlock, 
  233             ap->a_p));
  234 }
  235 
  236 int
  237 vop_stdislocked(ap)
  238         struct vop_islocked_args /* {
  239                 struct vnode *a_vp;
  240         } */ *ap;
  241 {
  242         struct lock *l;
  243 
  244         if ((l = (struct lock *)ap->a_vp->v_data) == NULL)
  245                 return 0;
  246 
  247         return (lockstatus(l));
  248 }
  249 
  250 /*
  251  * Return true for select/poll.
  252  */
  253 int
  254 vop_nopoll(ap)
  255         struct vop_poll_args /* {
  256                 struct vnode *a_vp;
  257                 int  a_events;
  258                 struct ucred *a_cred;
  259                 struct proc *a_p;
  260         } */ *ap;
  261 {
  262         /*
  263          * Return true for read/write.  If the user asked for something
  264          * special, return POLLNVAL, so that clients have a way of
  265          * determining reliably whether or not the extended
  266          * functionality is present without hard-coding knowledge
  267          * of specific filesystem implementations.
  268          */
  269         if (ap->a_events & ~POLLSTANDARD)
  270                 return (POLLNVAL);
  271 
  272         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
  273 }
  274 
  275 /*
  276  * Implement poll for local filesystems that support it.
  277  */
  278 int
  279 vop_stdpoll(ap)
  280         struct vop_poll_args /* {
  281                 struct vnode *a_vp;
  282                 int  a_events;
  283                 struct ucred *a_cred;
  284                 struct proc *a_p;
  285         } */ *ap;
  286 {
  287         if ((ap->a_events & ~POLLSTANDARD) == 0)
  288                 return (ap->a_events & (POLLRDNORM|POLLWRNORM));
  289         return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
  290 }
  291 
  292 int
  293 vop_stdbwrite(ap)
  294         struct vop_bwrite_args *ap;
  295 {
  296         return (bwrite(ap->a_bp));
  297 }
  298 
  299 /*
  300  * Stubs to use when there is no locking to be done on the underlying object.
  301  * A minimal shared lock is necessary to ensure that the underlying object
  302  * is not revoked while an operation is in progress. So, an active shared
  303  * count is maintained in an auxillary vnode lock structure.
  304  */
  305 int
  306 vop_sharedlock(ap)
  307         struct vop_lock_args /* {
  308                 struct vnode *a_vp;
  309                 int a_flags;
  310                 struct proc *a_p;
  311         } */ *ap;
  312 {
  313         /*
  314          * This code cannot be used until all the non-locking filesystems
  315          * (notably NFS) are converted to properly lock and release nodes.
  316          * Also, certain vnode operations change the locking state within
  317          * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
  318          * and symlink). Ideally these operations should not change the
  319          * lock state, but should be changed to let the caller of the
  320          * function unlock them. Otherwise all intermediate vnode layers
  321          * (such as union, umapfs, etc) must catch these functions to do
  322          * the necessary locking at their layer. Note that the inactive
  323          * and lookup operations also change their lock state, but this 
  324          * cannot be avoided, so these two operations will always need
  325          * to be handled in intermediate layers.
  326          */
  327         struct vnode *vp = ap->a_vp;
  328         int vnflags, flags = ap->a_flags;
  329 
  330         if (vp->v_vnlock == NULL) {
  331                 if ((flags & LK_TYPE_MASK) == LK_DRAIN)
  332                         return (0);
  333                 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock),
  334                     M_VNODE, M_WAITOK);
  335                 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, LK_NOPAUSE);
  336         }
  337         switch (flags & LK_TYPE_MASK) {
  338         case LK_DRAIN:
  339                 vnflags = LK_DRAIN;
  340                 break;
  341         case LK_EXCLUSIVE:
  342 #ifdef DEBUG_VFS_LOCKS
  343                 /*
  344                  * Normally, we use shared locks here, but that confuses
  345                  * the locking assertions.
  346                  */
  347                 vnflags = LK_EXCLUSIVE;
  348                 break;
  349 #endif
  350         case LK_SHARED:
  351                 vnflags = LK_SHARED;
  352                 break;
  353         case LK_UPGRADE:
  354         case LK_EXCLUPGRADE:
  355         case LK_DOWNGRADE:
  356                 return (0);
  357         case LK_RELEASE:
  358         default:
  359                 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
  360         }
  361         if (flags & LK_INTERLOCK)
  362                 vnflags |= LK_INTERLOCK;
  363 #ifndef DEBUG_LOCKS
  364         return (lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p));
  365 #else
  366         return (debuglockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p,
  367             "vop_sharedlock", vp->filename, vp->line));
  368 #endif
  369 }
  370 
  371 /*
  372  * Stubs to use when there is no locking to be done on the underlying object.
  373  * A minimal shared lock is necessary to ensure that the underlying object
  374  * is not revoked while an operation is in progress. So, an active shared
  375  * count is maintained in an auxillary vnode lock structure.
  376  */
  377 int
  378 vop_nolock(ap)
  379         struct vop_lock_args /* {
  380                 struct vnode *a_vp;
  381                 int a_flags;
  382                 struct proc *a_p;
  383         } */ *ap;
  384 {
  385 #ifdef notyet
  386         /*
  387          * This code cannot be used until all the non-locking filesystems
  388          * (notably NFS) are converted to properly lock and release nodes.
  389          * Also, certain vnode operations change the locking state within
  390          * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
  391          * and symlink). Ideally these operations should not change the
  392          * lock state, but should be changed to let the caller of the
  393          * function unlock them. Otherwise all intermediate vnode layers
  394          * (such as union, umapfs, etc) must catch these functions to do
  395          * the necessary locking at their layer. Note that the inactive
  396          * and lookup operations also change their lock state, but this 
  397          * cannot be avoided, so these two operations will always need
  398          * to be handled in intermediate layers.
  399          */
  400         struct vnode *vp = ap->a_vp;
  401         int vnflags, flags = ap->a_flags;
  402 
  403         if (vp->v_vnlock == NULL) {
  404                 if ((flags & LK_TYPE_MASK) == LK_DRAIN)
  405                         return (0);
  406                 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock),
  407                     M_VNODE, M_WAITOK);
  408                 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, LK_NOPAUSE);
  409         }
  410         switch (flags & LK_TYPE_MASK) {
  411         case LK_DRAIN:
  412                 vnflags = LK_DRAIN;
  413                 break;
  414         case LK_EXCLUSIVE:
  415         case LK_SHARED:
  416                 vnflags = LK_SHARED;
  417                 break;
  418         case LK_UPGRADE:
  419         case LK_EXCLUPGRADE:
  420         case LK_DOWNGRADE:
  421                 return (0);
  422         case LK_RELEASE:
  423         default:
  424                 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
  425         }
  426         if (flags & LK_INTERLOCK)
  427                 vnflags |= LK_INTERLOCK;
  428         return(lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p));
  429 #else /* for now */
  430         /*
  431          * Since we are not using the lock manager, we must clear
  432          * the interlock here.
  433          */
  434         if (ap->a_flags & LK_INTERLOCK)
  435                 simple_unlock(&ap->a_vp->v_interlock);
  436         return (0);
  437 #endif
  438 }
  439 
  440 /*
  441  * Do the inverse of vop_nolock, handling the interlock in a compatible way.
  442  */
  443 int
  444 vop_nounlock(ap)
  445         struct vop_unlock_args /* {
  446                 struct vnode *a_vp;
  447                 int a_flags;
  448                 struct proc *a_p;
  449         } */ *ap;
  450 {
  451         struct vnode *vp = ap->a_vp;
  452 
  453         if (vp->v_vnlock == NULL) {
  454                 if (ap->a_flags & LK_INTERLOCK)
  455                         simple_unlock(&ap->a_vp->v_interlock);
  456                 return (0);
  457         }
  458         return (lockmgr(vp->v_vnlock, LK_RELEASE | ap->a_flags,
  459                 &ap->a_vp->v_interlock, ap->a_p));
  460 }
  461 
  462 /*
  463  * Return whether or not the node is in use.
  464  */
  465 int
  466 vop_noislocked(ap)
  467         struct vop_islocked_args /* {
  468                 struct vnode *a_vp;
  469         } */ *ap;
  470 {
  471         struct vnode *vp = ap->a_vp;
  472 
  473         if (vp->v_vnlock == NULL)
  474                 return (0);
  475         return (lockstatus(vp->v_vnlock));
  476 }
  477 

Cache object: aee76b179b0b94b2d21f31a7855606f0


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.