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 #include <sys/cdefs.h>
   40 __FBSDID("$FreeBSD: releng/5.2/sys/kern/vfs_default.c 122091 2003-11-05 04:30:08Z kan $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/bio.h>
   45 #include <sys/buf.h>
   46 #include <sys/conf.h>
   47 #include <sys/kernel.h>
   48 #include <sys/limits.h>
   49 #include <sys/lock.h>
   50 #include <sys/malloc.h>
   51 #include <sys/mount.h>
   52 #include <sys/mutex.h>
   53 #include <sys/unistd.h>
   54 #include <sys/vnode.h>
   55 #include <sys/poll.h>
   56 
   57 #include <vm/vm.h>
   58 #include <vm/vm_object.h>
   59 #include <vm/vm_extern.h>
   60 #include <vm/pmap.h>
   61 #include <vm/vm_map.h>
   62 #include <vm/vm_page.h>
   63 #include <vm/vm_pager.h>
   64 #include <vm/vnode_pager.h>
   65 
   66 static int      vop_nolookup(struct vop_lookup_args *);
   67 static int      vop_nostrategy(struct vop_strategy_args *);
   68 
   69 /*
   70  * This vnode table stores what we want to do if the filesystem doesn't
   71  * implement a particular VOP.
   72  *
   73  * If there is no specific entry here, we will return EOPNOTSUPP.
   74  *
   75  */
   76 
   77 vop_t **default_vnodeop_p;
   78 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
   79         { &vop_default_desc,            (vop_t *) vop_eopnotsupp },
   80         { &vop_advlock_desc,            (vop_t *) vop_einval },
   81         { &vop_bmap_desc,               (vop_t *) vop_stdbmap },
   82         { &vop_close_desc,              (vop_t *) vop_null },
   83         { &vop_createvobject_desc,      (vop_t *) vop_stdcreatevobject },
   84         { &vop_destroyvobject_desc,     (vop_t *) vop_stddestroyvobject },
   85         { &vop_fsync_desc,              (vop_t *) vop_null },
   86         { &vop_getpages_desc,           (vop_t *) vop_stdgetpages },
   87         { &vop_getvobject_desc,         (vop_t *) vop_stdgetvobject },
   88         { &vop_inactive_desc,           (vop_t *) vop_stdinactive },
   89         { &vop_ioctl_desc,              (vop_t *) vop_enotty },
   90         { &vop_islocked_desc,           (vop_t *) vop_stdislocked },
   91         { &vop_lease_desc,              (vop_t *) vop_null },
   92         { &vop_lock_desc,               (vop_t *) vop_stdlock },
   93         { &vop_lookup_desc,             (vop_t *) vop_nolookup },
   94         { &vop_open_desc,               (vop_t *) vop_null },
   95         { &vop_pathconf_desc,           (vop_t *) vop_einval },
   96         { &vop_poll_desc,               (vop_t *) vop_nopoll },
   97         { &vop_putpages_desc,           (vop_t *) vop_stdputpages },
   98         { &vop_readlink_desc,           (vop_t *) vop_einval },
   99         { &vop_revoke_desc,             (vop_t *) vop_revoke },
  100         { &vop_specstrategy_desc,       (vop_t *) vop_panic },
  101         { &vop_strategy_desc,           (vop_t *) vop_nostrategy },
  102         { &vop_unlock_desc,             (vop_t *) vop_stdunlock },
  103         { NULL, NULL }
  104 };
  105 
  106 static struct vnodeopv_desc default_vnodeop_opv_desc =
  107         { &default_vnodeop_p, default_vnodeop_entries };
  108 
  109 VNODEOP_SET(default_vnodeop_opv_desc);
  110 
  111 /*
  112  * Series of placeholder functions for various error returns for
  113  * VOPs.
  114  */
  115 
  116 int
  117 vop_eopnotsupp(struct vop_generic_args *ap)
  118 {
  119         /*
  120         printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
  121         */
  122 
  123         return (EOPNOTSUPP);
  124 }
  125 
  126 int
  127 vop_ebadf(struct vop_generic_args *ap)
  128 {
  129 
  130         return (EBADF);
  131 }
  132 
  133 int
  134 vop_enotty(struct vop_generic_args *ap)
  135 {
  136 
  137         return (ENOTTY);
  138 }
  139 
  140 int
  141 vop_einval(struct vop_generic_args *ap)
  142 {
  143 
  144         return (EINVAL);
  145 }
  146 
  147 int
  148 vop_null(struct vop_generic_args *ap)
  149 {
  150 
  151         return (0);
  152 }
  153 
  154 /*
  155  * Used to make a defined VOP fall back to the default VOP.
  156  */
  157 int
  158 vop_defaultop(struct vop_generic_args *ap)
  159 {
  160 
  161         return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
  162 }
  163 
  164 /*
  165  * Helper function to panic on some bad VOPs in some filesystems.
  166  */
  167 int
  168 vop_panic(struct vop_generic_args *ap)
  169 {
  170 
  171         panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
  172 }
  173 
  174 /*
  175  * vop_std<something> and vop_no<something> are default functions for use by
  176  * filesystems that need the "default reasonable" implementation for a
  177  * particular operation.
  178  *
  179  * The documentation for the operations they implement exists (if it exists)
  180  * in the VOP_<SOMETHING>(9) manpage (all uppercase).
  181  */
  182 
  183 /*
  184  * Default vop for filesystems that do not support name lookup
  185  */
  186 static int
  187 vop_nolookup(ap)
  188         struct vop_lookup_args /* {
  189                 struct vnode *a_dvp;
  190                 struct vnode **a_vpp;
  191                 struct componentname *a_cnp;
  192         } */ *ap;
  193 {
  194 
  195         *ap->a_vpp = NULL;
  196         return (ENOTDIR);
  197 }
  198 
  199 /*
  200  *      vop_nostrategy:
  201  *
  202  *      Strategy routine for VFS devices that have none.
  203  *
  204  *      BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
  205  *      routine.  Typically this is done for a BIO_READ strategy call.
  206  *      Typically B_INVAL is assumed to already be clear prior to a write
  207  *      and should not be cleared manually unless you just made the buffer
  208  *      invalid.  BIO_ERROR should be cleared either way.
  209  */
  210 
  211 static int
  212 vop_nostrategy (struct vop_strategy_args *ap)
  213 {
  214         KASSERT(ap->a_vp == ap->a_bp->b_vp, ("%s(%p != %p)",
  215             __func__, ap->a_vp, ap->a_bp->b_vp));
  216         printf("No strategy for buffer at %p\n", ap->a_bp);
  217         vprint("vnode", ap->a_vp);
  218         vprint("device vnode", ap->a_bp->b_vp);
  219         ap->a_bp->b_ioflags |= BIO_ERROR;
  220         ap->a_bp->b_error = EOPNOTSUPP;
  221         bufdone(ap->a_bp);
  222         return (EOPNOTSUPP);
  223 }
  224 
  225 /*
  226  * vop_stdpathconf:
  227  *
  228  * Standard implementation of POSIX pathconf, to get information about limits
  229  * for a filesystem.
  230  * Override per filesystem for the case where the filesystem has smaller
  231  * limits.
  232  */
  233 int
  234 vop_stdpathconf(ap)
  235         struct vop_pathconf_args /* {
  236         struct vnode *a_vp;
  237         int a_name;
  238         int *a_retval;
  239         } */ *ap;
  240 {
  241 
  242         switch (ap->a_name) {
  243                 case _PC_LINK_MAX:
  244                         *ap->a_retval = LINK_MAX;
  245                         return (0);
  246                 case _PC_MAX_CANON:
  247                         *ap->a_retval = MAX_CANON;
  248                         return (0);
  249                 case _PC_MAX_INPUT:
  250                         *ap->a_retval = MAX_INPUT;
  251                         return (0);
  252                 case _PC_PIPE_BUF:
  253                         *ap->a_retval = PIPE_BUF;
  254                         return (0);
  255                 case _PC_CHOWN_RESTRICTED:
  256                         *ap->a_retval = 1;
  257                         return (0);
  258                 case _PC_VDISABLE:
  259                         *ap->a_retval = _POSIX_VDISABLE;
  260                         return (0);
  261                 default:
  262                         return (EINVAL);
  263         }
  264         /* NOTREACHED */
  265 }
  266 
  267 /*
  268  * Standard lock, unlock and islocked functions.
  269  */
  270 int
  271 vop_stdlock(ap)
  272         struct vop_lock_args /* {
  273                 struct vnode *a_vp;
  274                 int a_flags;
  275                 struct thread *a_td;
  276         } */ *ap;
  277 {
  278         struct vnode *vp = ap->a_vp;
  279 
  280 #ifndef DEBUG_LOCKS
  281         return (lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td));
  282 #else
  283         return (debuglockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp),
  284             ap->a_td, "vop_stdlock", vp->filename, vp->line));
  285 #endif
  286 }
  287 
  288 /* See above. */
  289 int
  290 vop_stdunlock(ap)
  291         struct vop_unlock_args /* {
  292                 struct vnode *a_vp;
  293                 int a_flags;
  294                 struct thread *a_td;
  295         } */ *ap;
  296 {
  297         struct vnode *vp = ap->a_vp;
  298 
  299         return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
  300             ap->a_td));
  301 }
  302 
  303 /* See above. */
  304 int
  305 vop_stdislocked(ap)
  306         struct vop_islocked_args /* {
  307                 struct vnode *a_vp;
  308                 struct thread *a_td;
  309         } */ *ap;
  310 {
  311 
  312         return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
  313 }
  314 
  315 /* Mark the vnode inactive */
  316 int
  317 vop_stdinactive(ap)
  318         struct vop_inactive_args /* {
  319                 struct vnode *a_vp;
  320                 struct thread *a_td;
  321         } */ *ap;
  322 {
  323 
  324         VOP_UNLOCK(ap->a_vp, 0, ap->a_td);
  325         return (0);
  326 }
  327 
  328 /*
  329  * Return true for select/poll.
  330  */
  331 int
  332 vop_nopoll(ap)
  333         struct vop_poll_args /* {
  334                 struct vnode *a_vp;
  335                 int  a_events;
  336                 struct ucred *a_cred;
  337                 struct thread *a_td;
  338         } */ *ap;
  339 {
  340         /*
  341          * Return true for read/write.  If the user asked for something
  342          * special, return POLLNVAL, so that clients have a way of
  343          * determining reliably whether or not the extended
  344          * functionality is present without hard-coding knowledge
  345          * of specific filesystem implementations.
  346          * Stay in sync with kern_conf.c::no_poll().
  347          */
  348         if (ap->a_events & ~POLLSTANDARD)
  349                 return (POLLNVAL);
  350 
  351         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
  352 }
  353 
  354 /*
  355  * Implement poll for local filesystems that support it.
  356  */
  357 int
  358 vop_stdpoll(ap)
  359         struct vop_poll_args /* {
  360                 struct vnode *a_vp;
  361                 int  a_events;
  362                 struct ucred *a_cred;
  363                 struct thread *a_td;
  364         } */ *ap;
  365 {
  366         if (ap->a_events & ~POLLSTANDARD)
  367                 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
  368         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
  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_sharedlock(ap)
  379         struct vop_lock_args /* {
  380                 struct vnode *a_vp;
  381                 int a_flags;
  382                 struct thread *a_td;
  383         } */ *ap;
  384 {
  385         /*
  386          * This code cannot be used until all the non-locking filesystems
  387          * (notably NFS) are converted to properly lock and release nodes.
  388          * Also, certain vnode operations change the locking state within
  389          * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
  390          * and symlink). Ideally these operations should not change the
  391          * lock state, but should be changed to let the caller of the
  392          * function unlock them. Otherwise all intermediate vnode layers
  393          * (such as union, umapfs, etc) must catch these functions to do
  394          * the necessary locking at their layer. Note that the inactive
  395          * and lookup operations also change their lock state, but this
  396          * cannot be avoided, so these two operations will always need
  397          * to be handled in intermediate layers.
  398          */
  399         struct vnode *vp = ap->a_vp;
  400         int vnflags, flags = ap->a_flags;
  401 
  402         switch (flags & LK_TYPE_MASK) {
  403         case LK_DRAIN:
  404                 vnflags = LK_DRAIN;
  405                 break;
  406         case LK_EXCLUSIVE:
  407 #ifdef DEBUG_VFS_LOCKS
  408                 /*
  409                  * Normally, we use shared locks here, but that confuses
  410                  * the locking assertions.
  411                  */
  412                 vnflags = LK_EXCLUSIVE;
  413                 break;
  414 #endif
  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_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
  425         }
  426         vnflags |= flags & (LK_INTERLOCK | LK_EXTFLG_MASK);
  427 #ifndef DEBUG_LOCKS
  428         return (lockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td));
  429 #else
  430         return (debuglockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td,
  431             "vop_sharedlock", vp->filename, vp->line));
  432 #endif
  433 }
  434 
  435 /*
  436  * Stubs to use when there is no locking to be done on the underlying object.
  437  * A minimal shared lock is necessary to ensure that the underlying object
  438  * is not revoked while an operation is in progress. So, an active shared
  439  * count is maintained in an auxillary vnode lock structure.
  440  */
  441 int
  442 vop_nolock(ap)
  443         struct vop_lock_args /* {
  444                 struct vnode *a_vp;
  445                 int a_flags;
  446                 struct thread *a_td;
  447         } */ *ap;
  448 {
  449 #ifdef notyet
  450         /*
  451          * This code cannot be used until all the non-locking filesystems
  452          * (notably NFS) are converted to properly lock and release nodes.
  453          * Also, certain vnode operations change the locking state within
  454          * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
  455          * and symlink). Ideally these operations should not change the
  456          * lock state, but should be changed to let the caller of the
  457          * function unlock them. Otherwise all intermediate vnode layers
  458          * (such as union, umapfs, etc) must catch these functions to do
  459          * the necessary locking at their layer. Note that the inactive
  460          * and lookup operations also change their lock state, but this
  461          * cannot be avoided, so these two operations will always need
  462          * to be handled in intermediate layers.
  463          */
  464         struct vnode *vp = ap->a_vp;
  465         int vnflags, flags = ap->a_flags;
  466 
  467         switch (flags & LK_TYPE_MASK) {
  468         case LK_DRAIN:
  469                 vnflags = LK_DRAIN;
  470                 break;
  471         case LK_EXCLUSIVE:
  472         case LK_SHARED:
  473                 vnflags = LK_SHARED;
  474                 break;
  475         case LK_UPGRADE:
  476         case LK_EXCLUPGRADE:
  477         case LK_DOWNGRADE:
  478                 return (0);
  479         case LK_RELEASE:
  480         default:
  481                 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
  482         }
  483         vnflags |= flags & (LK_INTERLOCK | LK_EXTFLG_MASK);
  484         return(lockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td));
  485 #else /* for now */
  486         /*
  487          * Since we are not using the lock manager, we must clear
  488          * the interlock here.
  489          */
  490         if (ap->a_flags & LK_INTERLOCK)
  491                 VI_UNLOCK(ap->a_vp);
  492         return (0);
  493 #endif
  494 }
  495 
  496 /*
  497  * Do the inverse of vop_nolock, handling the interlock in a compatible way.
  498  */
  499 int
  500 vop_nounlock(ap)
  501         struct vop_unlock_args /* {
  502                 struct vnode *a_vp;
  503                 int a_flags;
  504                 struct thread *a_td;
  505         } */ *ap;
  506 {
  507 
  508         /*
  509          * Since we are not using the lock manager, we must clear
  510          * the interlock here.
  511          */
  512         if (ap->a_flags & LK_INTERLOCK)
  513                 VI_UNLOCK(ap->a_vp);
  514         return (0);
  515 }
  516 
  517 /*
  518  * Return whether or not the node is in use.
  519  */
  520 int
  521 vop_noislocked(ap)
  522         struct vop_islocked_args /* {
  523                 struct vnode *a_vp;
  524                 struct thread *a_td;
  525         } */ *ap;
  526 {
  527 
  528         return (0);
  529 }
  530 
  531 /*
  532  * Return our mount point, as we will take charge of the writes.
  533  */
  534 int
  535 vop_stdgetwritemount(ap)
  536         struct vop_getwritemount_args /* {
  537                 struct vnode *a_vp;
  538                 struct mount **a_mpp;
  539         } */ *ap;
  540 {
  541 
  542         *(ap->a_mpp) = ap->a_vp->v_mount;
  543         return (0);
  544 }
  545 
  546 /* Create the VM system backing object for this vnode */
  547 int
  548 vop_stdcreatevobject(ap)
  549         struct vop_createvobject_args /* {
  550                 struct vnode *vp;
  551                 struct ucred *cred;
  552                 struct thread *td;
  553         } */ *ap;
  554 {
  555         struct vnode *vp = ap->a_vp;
  556         struct ucred *cred = ap->a_cred;
  557         struct thread *td = ap->a_td;
  558         struct vattr vat;
  559         vm_object_t object;
  560         int error = 0;
  561 
  562         GIANT_REQUIRED;
  563 
  564         if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
  565                 return (0);
  566 
  567 retry:
  568         if ((object = vp->v_object) == NULL) {
  569                 if (vp->v_type == VREG || vp->v_type == VDIR) {
  570                         if ((error = VOP_GETATTR(vp, &vat, cred, td)) != 0)
  571                                 goto retn;
  572                         object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
  573                 } else if (devsw(vp->v_rdev) != NULL) {
  574                         /*
  575                          * This simply allocates the biggest object possible
  576                          * for a disk vnode.  This should be fixed, but doesn't
  577                          * cause any problems (yet).
  578                          */
  579                         object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
  580                 } else {
  581                         goto retn;
  582                 }
  583                 /*
  584                  * Dereference the reference we just created.  This assumes
  585                  * that the object is associated with the vp.
  586                  */
  587                 VM_OBJECT_LOCK(object);
  588                 object->ref_count--;
  589                 VM_OBJECT_UNLOCK(object);
  590                 vrele(vp);
  591         } else {
  592                 VM_OBJECT_LOCK(object);
  593                 if (object->flags & OBJ_DEAD) {
  594                         VOP_UNLOCK(vp, 0, td);
  595                         msleep(object, VM_OBJECT_MTX(object), PDROP | PVM,
  596                             "vodead", 0);
  597                         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
  598                         goto retry;
  599                 }
  600                 VM_OBJECT_UNLOCK(object);
  601         }
  602 
  603         KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
  604         vp->v_vflag |= VV_OBJBUF;
  605 
  606 retn:
  607         return (error);
  608 }
  609 
  610 /* Destroy the VM system object associated with this vnode */
  611 int
  612 vop_stddestroyvobject(ap)
  613         struct vop_destroyvobject_args /* {
  614                 struct vnode *vp;
  615         } */ *ap;
  616 {
  617         struct vnode *vp = ap->a_vp;
  618         vm_object_t obj = vp->v_object;
  619 
  620         GIANT_REQUIRED;
  621 
  622         if (obj == NULL)
  623                 return (0);
  624         VM_OBJECT_LOCK(obj);
  625         if (obj->ref_count == 0) {
  626                 /*
  627                  * vclean() may be called twice. The first time
  628                  * removes the primary reference to the object,
  629                  * the second time goes one further and is a
  630                  * special-case to terminate the object.
  631                  *
  632                  * don't double-terminate the object
  633                  */
  634                 if ((obj->flags & OBJ_DEAD) == 0)
  635                         vm_object_terminate(obj);
  636                 else
  637                         VM_OBJECT_UNLOCK(obj);
  638         } else {
  639                 /*
  640                  * Woe to the process that tries to page now :-).
  641                  */
  642                 vm_pager_deallocate(obj);
  643                 VM_OBJECT_UNLOCK(obj);
  644         }
  645         return (0);
  646 }
  647 
  648 /*
  649  * Return the underlying VM object.  This routine may be called with or
  650  * without the vnode interlock held.  If called without, the returned
  651  * object is not guarenteed to be valid.  The syncer typically gets the
  652  * object without holding the interlock in order to quickly test whether
  653  * it might be dirty before going heavy-weight.  vm_object's use zalloc
  654  * and thus stable-storage, so this is safe.
  655  */
  656 int
  657 vop_stdgetvobject(ap)
  658         struct vop_getvobject_args /* {
  659                 struct vnode *vp;
  660                 struct vm_object **objpp;
  661         } */ *ap;
  662 {
  663         struct vnode *vp = ap->a_vp;
  664         struct vm_object **objpp = ap->a_objpp;
  665 
  666         if (objpp)
  667                 *objpp = vp->v_object;
  668         return (vp->v_object ? 0 : EINVAL);
  669 }
  670 
  671 /* XXX Needs good comment and VOP_BMAP(9) manpage */
  672 int
  673 vop_stdbmap(ap)
  674         struct vop_bmap_args /* {
  675                 struct vnode *a_vp;
  676                 daddr_t  a_bn;
  677                 struct vnode **a_vpp;
  678                 daddr_t *a_bnp;
  679                 int *a_runp;
  680                 int *a_runb;
  681         } */ *ap;
  682 {
  683 
  684         if (ap->a_vpp != NULL)
  685                 *ap->a_vpp = ap->a_vp;
  686         if (ap->a_bnp != NULL)
  687                 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
  688         if (ap->a_runp != NULL)
  689                 *ap->a_runp = 0;
  690         if (ap->a_runb != NULL)
  691                 *ap->a_runb = 0;
  692         return (0);
  693 }
  694 
  695 int
  696 vop_stdfsync(ap)
  697         struct vop_fsync_args /* {
  698                 struct vnode *a_vp;
  699                 struct ucred *a_cred;
  700                 int a_waitfor;
  701                 struct thread *a_td;
  702         } */ *ap;
  703 {
  704         struct vnode *vp = ap->a_vp;
  705         struct buf *bp;
  706         struct buf *nbp;
  707         int s, error = 0;
  708         int maxretry = 100;     /* large, arbitrarily chosen */
  709 
  710         VI_LOCK(vp);
  711 loop1:
  712         /*
  713          * MARK/SCAN initialization to avoid infinite loops.
  714          */
  715         s = splbio();
  716         TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
  717                 bp->b_vflags &= ~BV_SCANNED;
  718                 bp->b_error = 0;
  719         }
  720         splx(s);
  721 
  722         /*
  723          * Flush all dirty buffers associated with a block device.
  724          */
  725 loop2:
  726         s = splbio();
  727         for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp != NULL; bp = nbp) {
  728                 nbp = TAILQ_NEXT(bp, b_vnbufs);
  729                 if ((bp->b_vflags & BV_SCANNED) != 0)
  730                         continue;
  731                 bp->b_vflags |= BV_SCANNED;
  732                 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
  733                         continue;
  734                 VI_UNLOCK(vp);
  735                 if ((bp->b_flags & B_DELWRI) == 0)
  736                         panic("fsync: not dirty");
  737                 if ((vp->v_vflag & VV_OBJBUF) && (bp->b_flags & B_CLUSTEROK)) {
  738                         vfs_bio_awrite(bp);
  739                         splx(s);
  740                 } else {
  741                         bremfree(bp);
  742                         splx(s);
  743                         bawrite(bp);
  744                 }
  745                 VI_LOCK(vp);
  746                 goto loop2;
  747         }
  748 
  749         /*
  750          * If synchronous the caller expects us to completely resolve all
  751          * dirty buffers in the system.  Wait for in-progress I/O to
  752          * complete (which could include background bitmap writes), then
  753          * retry if dirty blocks still exist.
  754          */
  755         if (ap->a_waitfor == MNT_WAIT) {
  756                 while (vp->v_numoutput) {
  757                         vp->v_iflag |= VI_BWAIT;
  758                         msleep((caddr_t)&vp->v_numoutput, VI_MTX(vp),
  759                             PRIBIO + 1, "fsync", 0);
  760                 }
  761                 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
  762                         /*
  763                          * If we are unable to write any of these buffers
  764                          * then we fail now rather than trying endlessly
  765                          * to write them out.
  766                          */
  767                         TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
  768                                 if ((error = bp->b_error) == 0)
  769                                         continue;
  770                         if (error == 0 && --maxretry >= 0) {
  771                                 splx(s);
  772                                 goto loop1;
  773                         }
  774                         vprint("fsync: giving up on dirty", vp);
  775                         error = EAGAIN;
  776                 }
  777         }
  778         VI_UNLOCK(vp);
  779         splx(s);
  780 
  781         return (error);
  782 }
  783 
  784 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
  785 int
  786 vop_stdgetpages(ap)
  787         struct vop_getpages_args /* {
  788                 struct vnode *a_vp;
  789                 vm_page_t *a_m;
  790                 int a_count;
  791                 int a_reqpage;
  792                 vm_ooffset_t a_offset;
  793         } */ *ap;
  794 {
  795 
  796         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
  797             ap->a_count, ap->a_reqpage);
  798 }
  799 
  800 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
  801 int
  802 vop_stdputpages(ap)
  803         struct vop_putpages_args /* {
  804                 struct vnode *a_vp;
  805                 vm_page_t *a_m;
  806                 int a_count;
  807                 int a_sync;
  808                 int *a_rtvals;
  809                 vm_ooffset_t a_offset;
  810         } */ *ap;
  811 {
  812 
  813         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
  814              ap->a_sync, ap->a_rtvals);
  815 }
  816 
  817 /*
  818  * vfs default ops
  819  * used to fill the vfs function table to get reasonable default return values.
  820  */
  821 int
  822 vfs_stdroot (mp, vpp)
  823         struct mount *mp;
  824         struct vnode **vpp;
  825 {
  826         return (EOPNOTSUPP);
  827 }
  828 
  829 int
  830 vfs_stdstatfs (mp, sbp, td)
  831         struct mount *mp;
  832         struct statfs *sbp;
  833         struct thread *td;
  834 {
  835         return (EOPNOTSUPP);
  836 }
  837 
  838 int
  839 vfs_stdvptofh (vp, fhp)
  840         struct vnode *vp;
  841         struct fid *fhp;
  842 {
  843         return (EOPNOTSUPP);
  844 }
  845 
  846 int
  847 vfs_stdstart (mp, flags, td)
  848         struct mount *mp;
  849         int flags;
  850         struct thread *td;
  851 {
  852         return (0);
  853 }
  854 
  855 int
  856 vfs_stdquotactl (mp, cmds, uid, arg, td)
  857         struct mount *mp;
  858         int cmds;
  859         uid_t uid;
  860         caddr_t arg;
  861         struct thread *td;
  862 {
  863         return (EOPNOTSUPP);
  864 }
  865 
  866 int
  867 vfs_stdsync(mp, waitfor, cred, td)
  868         struct mount *mp;
  869         int waitfor;
  870         struct ucred *cred;
  871         struct thread *td;
  872 {
  873         struct vnode *vp, *nvp;
  874         int error, lockreq, allerror = 0;
  875 
  876         lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
  877         if (waitfor != MNT_WAIT)
  878                 lockreq |= LK_NOWAIT;
  879         /*
  880          * Force stale buffer cache information to be flushed.
  881          */
  882         MNT_ILOCK(mp);
  883 loop:
  884         for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) {
  885                 /*
  886                  * If the vnode that we are about to sync is no longer
  887                  * associated with this mount point, start over.
  888                  */
  889                 if (vp->v_mount != mp)
  890                         goto loop;
  891 
  892                 nvp = TAILQ_NEXT(vp, v_nmntvnodes);
  893 
  894                 VI_LOCK(vp);
  895                 if (TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
  896                         VI_UNLOCK(vp);
  897                         continue;
  898                 }
  899                 MNT_IUNLOCK(mp);
  900 
  901                 if ((error = vget(vp, lockreq, td)) != 0) {
  902                         MNT_ILOCK(mp);
  903                         if (error == ENOENT)
  904                                 goto loop;
  905                         continue;
  906                 }
  907                 error = VOP_FSYNC(vp, cred, waitfor, td);
  908                 if (error)
  909                         allerror = error;
  910 
  911                 VOP_UNLOCK(vp, 0, td);
  912                 vrele(vp);
  913                 MNT_ILOCK(mp);
  914         }
  915         MNT_IUNLOCK(mp);
  916         return (allerror);
  917 }
  918 
  919 int
  920 vfs_stdnosync (mp, waitfor, cred, td)
  921         struct mount *mp;
  922         int waitfor;
  923         struct ucred *cred;
  924         struct thread *td;
  925 {
  926         return (0);
  927 }
  928 
  929 int
  930 vfs_stdvget (mp, ino, flags, vpp)
  931         struct mount *mp;
  932         ino_t ino;
  933         int flags;
  934         struct vnode **vpp;
  935 {
  936         return (EOPNOTSUPP);
  937 }
  938 
  939 int
  940 vfs_stdfhtovp (mp, fhp, vpp)
  941         struct mount *mp;
  942         struct fid *fhp;
  943         struct vnode **vpp;
  944 {
  945         return (EOPNOTSUPP);
  946 }
  947 
  948 int
  949 vfs_stdinit (vfsp)
  950         struct vfsconf *vfsp;
  951 {
  952         return (0);
  953 }
  954 
  955 int
  956 vfs_stduninit (vfsp)
  957         struct vfsconf *vfsp;
  958 {
  959         return(0);
  960 }
  961 
  962 int
  963 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
  964         struct mount *mp;
  965         int cmd;
  966         struct vnode *filename_vp;
  967         int attrnamespace;
  968         const char *attrname;
  969         struct thread *td;
  970 {
  971         if (filename_vp != NULL)
  972                 VOP_UNLOCK(filename_vp, 0, td);
  973         return(EOPNOTSUPP);
  974 }
  975 
  976 /* end of vfs default ops */

Cache object: 8f2b254eb074e5d0c20879fb84370dc4


[ 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.