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  * 4. Neither the name of the University nor the names of its contributors
   19  *    may be used to endorse or promote products derived from this software
   20  *    without specific prior written permission.
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   32  * SUCH DAMAGE.
   33  */
   34 
   35 #include <sys/cdefs.h>
   36 __FBSDID("$FreeBSD: src/sys/kern/vfs_default.c,v 1.97.2.2 2005/02/23 23:06:29 alc Exp $");
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/bio.h>
   41 #include <sys/buf.h>
   42 #include <sys/conf.h>
   43 #include <sys/kernel.h>
   44 #include <sys/limits.h>
   45 #include <sys/lock.h>
   46 #include <sys/malloc.h>
   47 #include <sys/mount.h>
   48 #include <sys/mutex.h>
   49 #include <sys/unistd.h>
   50 #include <sys/vnode.h>
   51 #include <sys/poll.h>
   52 
   53 #include <vm/vm.h>
   54 #include <vm/vm_object.h>
   55 #include <vm/vm_extern.h>
   56 #include <vm/pmap.h>
   57 #include <vm/vm_map.h>
   58 #include <vm/vm_page.h>
   59 #include <vm/vm_pager.h>
   60 #include <vm/vnode_pager.h>
   61 
   62 static int      vop_nolookup(struct vop_lookup_args *);
   63 static int      vop_nostrategy(struct vop_strategy_args *);
   64 
   65 /*
   66  * This vnode table stores what we want to do if the filesystem doesn't
   67  * implement a particular VOP.
   68  *
   69  * If there is no specific entry here, we will return EOPNOTSUPP.
   70  *
   71  */
   72 
   73 vop_t **default_vnodeop_p;
   74 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
   75         { &vop_default_desc,            (vop_t *) vop_eopnotsupp },
   76         { &vop_advlock_desc,            (vop_t *) vop_einval },
   77         { &vop_bmap_desc,               (vop_t *) vop_stdbmap },
   78         { &vop_close_desc,              (vop_t *) vop_null },
   79         { &vop_createvobject_desc,      (vop_t *) vop_stdcreatevobject },
   80         { &vop_destroyvobject_desc,     (vop_t *) vop_stddestroyvobject },
   81         { &vop_fsync_desc,              (vop_t *) vop_null },
   82         { &vop_getpages_desc,           (vop_t *) vop_stdgetpages },
   83         { &vop_getvobject_desc,         (vop_t *) vop_stdgetvobject },
   84         { &vop_inactive_desc,           (vop_t *) vop_stdinactive },
   85         { &vop_ioctl_desc,              (vop_t *) vop_enotty },
   86         { &vop_islocked_desc,           (vop_t *) vop_stdislocked },
   87         { &vop_lease_desc,              (vop_t *) vop_null },
   88         { &vop_lock_desc,               (vop_t *) vop_stdlock },
   89         { &vop_lookup_desc,             (vop_t *) vop_nolookup },
   90         { &vop_open_desc,               (vop_t *) vop_null },
   91         { &vop_pathconf_desc,           (vop_t *) vop_einval },
   92         { &vop_poll_desc,               (vop_t *) vop_nopoll },
   93         { &vop_putpages_desc,           (vop_t *) vop_stdputpages },
   94         { &vop_readlink_desc,           (vop_t *) vop_einval },
   95         { &vop_revoke_desc,             (vop_t *) vop_revoke },
   96         { &vop_specstrategy_desc,       (vop_t *) vop_panic },
   97         { &vop_strategy_desc,           (vop_t *) vop_nostrategy },
   98         { &vop_unlock_desc,             (vop_t *) vop_stdunlock },
   99         { NULL, NULL }
  100 };
  101 
  102 static struct vnodeopv_desc default_vnodeop_opv_desc =
  103         { &default_vnodeop_p, default_vnodeop_entries };
  104 
  105 VNODEOP_SET(default_vnodeop_opv_desc);
  106 
  107 /*
  108  * Series of placeholder functions for various error returns for
  109  * VOPs.
  110  */
  111 
  112 int
  113 vop_eopnotsupp(struct vop_generic_args *ap)
  114 {
  115         /*
  116         printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
  117         */
  118 
  119         return (EOPNOTSUPP);
  120 }
  121 
  122 int
  123 vop_ebadf(struct vop_generic_args *ap)
  124 {
  125 
  126         return (EBADF);
  127 }
  128 
  129 int
  130 vop_enotty(struct vop_generic_args *ap)
  131 {
  132 
  133         return (ENOTTY);
  134 }
  135 
  136 int
  137 vop_einval(struct vop_generic_args *ap)
  138 {
  139 
  140         return (EINVAL);
  141 }
  142 
  143 int
  144 vop_null(struct vop_generic_args *ap)
  145 {
  146 
  147         return (0);
  148 }
  149 
  150 /*
  151  * Used to make a defined VOP fall back to the default VOP.
  152  */
  153 int
  154 vop_defaultop(struct vop_generic_args *ap)
  155 {
  156 
  157         return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
  158 }
  159 
  160 /*
  161  * Helper function to panic on some bad VOPs in some filesystems.
  162  */
  163 int
  164 vop_panic(struct vop_generic_args *ap)
  165 {
  166 
  167         panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
  168 }
  169 
  170 /*
  171  * vop_std<something> and vop_no<something> are default functions for use by
  172  * filesystems that need the "default reasonable" implementation for a
  173  * particular operation.
  174  *
  175  * The documentation for the operations they implement exists (if it exists)
  176  * in the VOP_<SOMETHING>(9) manpage (all uppercase).
  177  */
  178 
  179 /*
  180  * Default vop for filesystems that do not support name lookup
  181  */
  182 static int
  183 vop_nolookup(ap)
  184         struct vop_lookup_args /* {
  185                 struct vnode *a_dvp;
  186                 struct vnode **a_vpp;
  187                 struct componentname *a_cnp;
  188         } */ *ap;
  189 {
  190 
  191         *ap->a_vpp = NULL;
  192         return (ENOTDIR);
  193 }
  194 
  195 /*
  196  *      vop_nostrategy:
  197  *
  198  *      Strategy routine for VFS devices that have none.
  199  *
  200  *      BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
  201  *      routine.  Typically this is done for a BIO_READ strategy call.
  202  *      Typically B_INVAL is assumed to already be clear prior to a write
  203  *      and should not be cleared manually unless you just made the buffer
  204  *      invalid.  BIO_ERROR should be cleared either way.
  205  */
  206 
  207 static int
  208 vop_nostrategy (struct vop_strategy_args *ap)
  209 {
  210         KASSERT(ap->a_vp == ap->a_bp->b_vp, ("%s(%p != %p)",
  211             __func__, ap->a_vp, ap->a_bp->b_vp));
  212         printf("No strategy for buffer at %p\n", ap->a_bp);
  213         vprint("vnode", ap->a_vp);
  214         vprint("device vnode", ap->a_bp->b_vp);
  215         ap->a_bp->b_ioflags |= BIO_ERROR;
  216         ap->a_bp->b_error = EOPNOTSUPP;
  217         bufdone(ap->a_bp);
  218         return (EOPNOTSUPP);
  219 }
  220 
  221 /*
  222  * vop_stdpathconf:
  223  *
  224  * Standard implementation of POSIX pathconf, to get information about limits
  225  * for a filesystem.
  226  * Override per filesystem for the case where the filesystem has smaller
  227  * limits.
  228  */
  229 int
  230 vop_stdpathconf(ap)
  231         struct vop_pathconf_args /* {
  232         struct vnode *a_vp;
  233         int a_name;
  234         int *a_retval;
  235         } */ *ap;
  236 {
  237 
  238         switch (ap->a_name) {
  239                 case _PC_LINK_MAX:
  240                         *ap->a_retval = LINK_MAX;
  241                         return (0);
  242                 case _PC_MAX_CANON:
  243                         *ap->a_retval = MAX_CANON;
  244                         return (0);
  245                 case _PC_MAX_INPUT:
  246                         *ap->a_retval = MAX_INPUT;
  247                         return (0);
  248                 case _PC_PIPE_BUF:
  249                         *ap->a_retval = PIPE_BUF;
  250                         return (0);
  251                 case _PC_CHOWN_RESTRICTED:
  252                         *ap->a_retval = 1;
  253                         return (0);
  254                 case _PC_VDISABLE:
  255                         *ap->a_retval = _POSIX_VDISABLE;
  256                         return (0);
  257                 default:
  258                         return (EINVAL);
  259         }
  260         /* NOTREACHED */
  261 }
  262 
  263 /*
  264  * Standard lock, unlock and islocked functions.
  265  */
  266 int
  267 vop_stdlock(ap)
  268         struct vop_lock_args /* {
  269                 struct vnode *a_vp;
  270                 int a_flags;
  271                 struct thread *a_td;
  272         } */ *ap;
  273 {
  274         struct vnode *vp = ap->a_vp;
  275 
  276 #ifndef DEBUG_LOCKS
  277         return (lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td));
  278 #else
  279         return (debuglockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp),
  280             ap->a_td, "vop_stdlock", vp->filename, vp->line));
  281 #endif
  282 }
  283 
  284 /* See above. */
  285 int
  286 vop_stdunlock(ap)
  287         struct vop_unlock_args /* {
  288                 struct vnode *a_vp;
  289                 int a_flags;
  290                 struct thread *a_td;
  291         } */ *ap;
  292 {
  293         struct vnode *vp = ap->a_vp;
  294 
  295         return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
  296             ap->a_td));
  297 }
  298 
  299 /* See above. */
  300 int
  301 vop_stdislocked(ap)
  302         struct vop_islocked_args /* {
  303                 struct vnode *a_vp;
  304                 struct thread *a_td;
  305         } */ *ap;
  306 {
  307 
  308         return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
  309 }
  310 
  311 /* Mark the vnode inactive */
  312 int
  313 vop_stdinactive(ap)
  314         struct vop_inactive_args /* {
  315                 struct vnode *a_vp;
  316                 struct thread *a_td;
  317         } */ *ap;
  318 {
  319 
  320         VOP_UNLOCK(ap->a_vp, 0, ap->a_td);
  321         return (0);
  322 }
  323 
  324 /*
  325  * Return true for select/poll.
  326  */
  327 int
  328 vop_nopoll(ap)
  329         struct vop_poll_args /* {
  330                 struct vnode *a_vp;
  331                 int  a_events;
  332                 struct ucred *a_cred;
  333                 struct thread *a_td;
  334         } */ *ap;
  335 {
  336         /*
  337          * Return true for read/write.  If the user asked for something
  338          * special, return POLLNVAL, so that clients have a way of
  339          * determining reliably whether or not the extended
  340          * functionality is present without hard-coding knowledge
  341          * of specific filesystem implementations.
  342          * Stay in sync with kern_conf.c::no_poll().
  343          */
  344         if (ap->a_events & ~POLLSTANDARD)
  345                 return (POLLNVAL);
  346 
  347         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
  348 }
  349 
  350 /*
  351  * Implement poll for local filesystems that support it.
  352  */
  353 int
  354 vop_stdpoll(ap)
  355         struct vop_poll_args /* {
  356                 struct vnode *a_vp;
  357                 int  a_events;
  358                 struct ucred *a_cred;
  359                 struct thread *a_td;
  360         } */ *ap;
  361 {
  362         if (ap->a_events & ~POLLSTANDARD)
  363                 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
  364         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
  365 }
  366 
  367 /*
  368  * Return our mount point, as we will take charge of the writes.
  369  */
  370 int
  371 vop_stdgetwritemount(ap)
  372         struct vop_getwritemount_args /* {
  373                 struct vnode *a_vp;
  374                 struct mount **a_mpp;
  375         } */ *ap;
  376 {
  377 
  378         *(ap->a_mpp) = ap->a_vp->v_mount;
  379         return (0);
  380 }
  381 
  382 /* Create the VM system backing object for this vnode */
  383 int
  384 vop_stdcreatevobject(ap)
  385         struct vop_createvobject_args /* {
  386                 struct vnode *vp;
  387                 struct ucred *cred;
  388                 struct thread *td;
  389         } */ *ap;
  390 {
  391         struct vnode *vp = ap->a_vp;
  392         struct ucred *cred = ap->a_cred;
  393         struct thread *td = ap->a_td;
  394         struct vattr vat;
  395         vm_object_t object;
  396         int error = 0;
  397 
  398         GIANT_REQUIRED;
  399 
  400         if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
  401                 return (0);
  402 
  403 retry:
  404         if ((object = vp->v_object) == NULL) {
  405                 if (vp->v_type == VREG || vp->v_type == VDIR) {
  406                         if ((error = VOP_GETATTR(vp, &vat, cred, td)) != 0)
  407                                 goto retn;
  408                         object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
  409                 } else if (devsw(vp->v_rdev) != NULL) {
  410                         /*
  411                          * This simply allocates the biggest object possible
  412                          * for a disk vnode.  This should be fixed, but doesn't
  413                          * cause any problems (yet).
  414                          */
  415                         object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
  416                 } else {
  417                         goto retn;
  418                 }
  419                 /*
  420                  * Dereference the reference we just created.  This assumes
  421                  * that the object is associated with the vp.
  422                  */
  423                 VM_OBJECT_LOCK(object);
  424                 object->ref_count--;
  425                 VM_OBJECT_UNLOCK(object);
  426                 vrele(vp);
  427         } else {
  428                 VM_OBJECT_LOCK(object);
  429                 if (object->flags & OBJ_DEAD) {
  430                         VOP_UNLOCK(vp, 0, td);
  431                         vm_object_set_flag(object, OBJ_DISCONNECTWNT);
  432                         msleep(object, VM_OBJECT_MTX(object), PDROP | PVM,
  433                             "vodead", 0);
  434                         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
  435                         goto retry;
  436                 }
  437                 VM_OBJECT_UNLOCK(object);
  438         }
  439 
  440         KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
  441         vp->v_vflag |= VV_OBJBUF;
  442 
  443 retn:
  444         return (error);
  445 }
  446 
  447 /* Destroy the VM system object associated with this vnode */
  448 int
  449 vop_stddestroyvobject(ap)
  450         struct vop_destroyvobject_args /* {
  451                 struct vnode *vp;
  452         } */ *ap;
  453 {
  454         struct vnode *vp = ap->a_vp;
  455         vm_object_t obj = vp->v_object;
  456 
  457         GIANT_REQUIRED;
  458 
  459         if (obj == NULL)
  460                 return (0);
  461         VM_OBJECT_LOCK(obj);
  462         if (obj->ref_count == 0) {
  463                 /*
  464                  * vclean() may be called twice. The first time
  465                  * removes the primary reference to the object,
  466                  * the second time goes one further and is a
  467                  * special-case to terminate the object.
  468                  *
  469                  * don't double-terminate the object
  470                  */
  471                 if ((obj->flags & OBJ_DEAD) == 0)
  472                         vm_object_terminate(obj);
  473                 else
  474                         VM_OBJECT_UNLOCK(obj);
  475         } else {
  476                 /*
  477                  * Woe to the process that tries to page now :-).
  478                  */
  479                 vm_pager_deallocate(obj);
  480                 VM_OBJECT_UNLOCK(obj);
  481         }
  482         return (0);
  483 }
  484 
  485 /*
  486  * Return the underlying VM object.  This routine may be called with or
  487  * without the vnode interlock held.  If called without, the returned
  488  * object is not guarenteed to be valid.  The syncer typically gets the
  489  * object without holding the interlock in order to quickly test whether
  490  * it might be dirty before going heavy-weight.  vm_object's use zalloc
  491  * and thus stable-storage, so this is safe.
  492  */
  493 int
  494 vop_stdgetvobject(ap)
  495         struct vop_getvobject_args /* {
  496                 struct vnode *vp;
  497                 struct vm_object **objpp;
  498         } */ *ap;
  499 {
  500         struct vnode *vp = ap->a_vp;
  501         struct vm_object **objpp = ap->a_objpp;
  502 
  503         if (objpp)
  504                 *objpp = vp->v_object;
  505         return (vp->v_object ? 0 : EINVAL);
  506 }
  507 
  508 /* XXX Needs good comment and VOP_BMAP(9) manpage */
  509 int
  510 vop_stdbmap(ap)
  511         struct vop_bmap_args /* {
  512                 struct vnode *a_vp;
  513                 daddr_t  a_bn;
  514                 struct vnode **a_vpp;
  515                 daddr_t *a_bnp;
  516                 int *a_runp;
  517                 int *a_runb;
  518         } */ *ap;
  519 {
  520 
  521         if (ap->a_vpp != NULL)
  522                 *ap->a_vpp = ap->a_vp;
  523         if (ap->a_bnp != NULL)
  524                 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
  525         if (ap->a_runp != NULL)
  526                 *ap->a_runp = 0;
  527         if (ap->a_runb != NULL)
  528                 *ap->a_runb = 0;
  529         return (0);
  530 }
  531 
  532 int
  533 vop_stdfsync(ap)
  534         struct vop_fsync_args /* {
  535                 struct vnode *a_vp;
  536                 struct ucred *a_cred;
  537                 int a_waitfor;
  538                 struct thread *a_td;
  539         } */ *ap;
  540 {
  541         struct vnode *vp = ap->a_vp;
  542         struct buf *bp;
  543         struct buf *nbp;
  544         int s, error = 0;
  545         int maxretry = 100;     /* large, arbitrarily chosen */
  546 
  547         VI_LOCK(vp);
  548 loop1:
  549         /*
  550          * MARK/SCAN initialization to avoid infinite loops.
  551          */
  552         s = splbio();
  553         TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
  554                 bp->b_vflags &= ~BV_SCANNED;
  555                 bp->b_error = 0;
  556         }
  557         splx(s);
  558 
  559         /*
  560          * Flush all dirty buffers associated with a block device.
  561          */
  562 loop2:
  563         s = splbio();
  564         for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp != NULL; bp = nbp) {
  565                 nbp = TAILQ_NEXT(bp, b_vnbufs);
  566                 if ((bp->b_vflags & BV_SCANNED) != 0)
  567                         continue;
  568                 bp->b_vflags |= BV_SCANNED;
  569                 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
  570                         continue;
  571                 VI_UNLOCK(vp);
  572                 if ((bp->b_flags & B_DELWRI) == 0)
  573                         panic("fsync: not dirty");
  574                 if ((vp->v_vflag & VV_OBJBUF) && (bp->b_flags & B_CLUSTEROK)) {
  575                         vfs_bio_awrite(bp);
  576                         splx(s);
  577                 } else {
  578                         bremfree(bp);
  579                         splx(s);
  580                         bawrite(bp);
  581                 }
  582                 VI_LOCK(vp);
  583                 goto loop2;
  584         }
  585 
  586         /*
  587          * If synchronous the caller expects us to completely resolve all
  588          * dirty buffers in the system.  Wait for in-progress I/O to
  589          * complete (which could include background bitmap writes), then
  590          * retry if dirty blocks still exist.
  591          */
  592         if (ap->a_waitfor == MNT_WAIT) {
  593                 while (vp->v_numoutput) {
  594                         vp->v_iflag |= VI_BWAIT;
  595                         msleep((caddr_t)&vp->v_numoutput, VI_MTX(vp),
  596                             PRIBIO + 1, "fsync", 0);
  597                 }
  598                 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
  599                         /*
  600                          * If we are unable to write any of these buffers
  601                          * then we fail now rather than trying endlessly
  602                          * to write them out.
  603                          */
  604                         TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
  605                                 if ((error = bp->b_error) == 0)
  606                                         continue;
  607                         if (error == 0 && --maxretry >= 0) {
  608                                 splx(s);
  609                                 goto loop1;
  610                         }
  611                         vprint("fsync: giving up on dirty", vp);
  612                         error = EAGAIN;
  613                 }
  614         }
  615         VI_UNLOCK(vp);
  616         splx(s);
  617 
  618         return (error);
  619 }
  620 
  621 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
  622 int
  623 vop_stdgetpages(ap)
  624         struct vop_getpages_args /* {
  625                 struct vnode *a_vp;
  626                 vm_page_t *a_m;
  627                 int a_count;
  628                 int a_reqpage;
  629                 vm_ooffset_t a_offset;
  630         } */ *ap;
  631 {
  632 
  633         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
  634             ap->a_count, ap->a_reqpage);
  635 }
  636 
  637 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
  638 int
  639 vop_stdputpages(ap)
  640         struct vop_putpages_args /* {
  641                 struct vnode *a_vp;
  642                 vm_page_t *a_m;
  643                 int a_count;
  644                 int a_sync;
  645                 int *a_rtvals;
  646                 vm_ooffset_t a_offset;
  647         } */ *ap;
  648 {
  649 
  650         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
  651              ap->a_sync, ap->a_rtvals);
  652 }
  653 
  654 /*
  655  * vfs default ops
  656  * used to fill the vfs function table to get reasonable default return values.
  657  */
  658 int
  659 vfs_stdroot (mp, vpp, td)
  660         struct mount *mp;
  661         struct vnode **vpp;
  662         struct thread *td;
  663 {
  664 
  665         return (EOPNOTSUPP);
  666 }
  667 
  668 int
  669 vfs_stdstatfs (mp, sbp, td)
  670         struct mount *mp;
  671         struct statfs *sbp;
  672         struct thread *td;
  673 {
  674 
  675         return (EOPNOTSUPP);
  676 }
  677 
  678 int
  679 vfs_stdvptofh (vp, fhp)
  680         struct vnode *vp;
  681         struct fid *fhp;
  682 {
  683 
  684         return (EOPNOTSUPP);
  685 }
  686 
  687 int
  688 vfs_stdstart (mp, flags, td)
  689         struct mount *mp;
  690         int flags;
  691         struct thread *td;
  692 {
  693 
  694         return (0);
  695 }
  696 
  697 int
  698 vfs_stdquotactl (mp, cmds, uid, arg, td)
  699         struct mount *mp;
  700         int cmds;
  701         uid_t uid;
  702         caddr_t arg;
  703         struct thread *td;
  704 {
  705 
  706         return (EOPNOTSUPP);
  707 }
  708 
  709 int
  710 vfs_stdsync(mp, waitfor, cred, td)
  711         struct mount *mp;
  712         int waitfor;
  713         struct ucred *cred;
  714         struct thread *td;
  715 {
  716         struct vnode *vp, *nvp;
  717         int error, lockreq, allerror = 0;
  718 
  719         lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
  720         if (waitfor != MNT_WAIT)
  721                 lockreq |= LK_NOWAIT;
  722         /*
  723          * Force stale buffer cache information to be flushed.
  724          */
  725         MNT_ILOCK(mp);
  726 loop:
  727         MNT_VNODE_FOREACH(vp, mp, nvp) {
  728 
  729                 VI_LOCK(vp);
  730                 if (TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
  731                         VI_UNLOCK(vp);
  732                         continue;
  733                 }
  734                 MNT_IUNLOCK(mp);
  735 
  736                 if ((error = vget(vp, lockreq, td)) != 0) {
  737                         MNT_ILOCK(mp);
  738                         if (error == ENOENT)
  739                                 goto loop;
  740                         continue;
  741                 }
  742                 error = VOP_FSYNC(vp, cred, waitfor, td);
  743                 if (error)
  744                         allerror = error;
  745 
  746                 VOP_UNLOCK(vp, 0, td);
  747                 vrele(vp);
  748                 MNT_ILOCK(mp);
  749         }
  750         MNT_IUNLOCK(mp);
  751         return (allerror);
  752 }
  753 
  754 int
  755 vfs_stdnosync (mp, waitfor, cred, td)
  756         struct mount *mp;
  757         int waitfor;
  758         struct ucred *cred;
  759         struct thread *td;
  760 {
  761 
  762         return (0);
  763 }
  764 
  765 int
  766 vfs_stdvget (mp, ino, flags, vpp)
  767         struct mount *mp;
  768         ino_t ino;
  769         int flags;
  770         struct vnode **vpp;
  771 {
  772 
  773         return (EOPNOTSUPP);
  774 }
  775 
  776 int
  777 vfs_stdfhtovp (mp, fhp, vpp)
  778         struct mount *mp;
  779         struct fid *fhp;
  780         struct vnode **vpp;
  781 {
  782 
  783         return (EOPNOTSUPP);
  784 }
  785 
  786 int
  787 vfs_stdinit (vfsp)
  788         struct vfsconf *vfsp;
  789 {
  790 
  791         return (0);
  792 }
  793 
  794 int
  795 vfs_stduninit (vfsp)
  796         struct vfsconf *vfsp;
  797 {
  798 
  799         return(0);
  800 }
  801 
  802 int
  803 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
  804         struct mount *mp;
  805         int cmd;
  806         struct vnode *filename_vp;
  807         int attrnamespace;
  808         const char *attrname;
  809         struct thread *td;
  810 {
  811 
  812         if (filename_vp != NULL)
  813                 VOP_UNLOCK(filename_vp, 0, td);
  814         return (EOPNOTSUPP);
  815 }
  816 
  817 int
  818 vfs_stdsysctl(mp, op, req)
  819         struct mount *mp;
  820         fsctlop_t op;
  821         struct sysctl_req *req;
  822 {
  823 
  824         return (EOPNOTSUPP);
  825 }
  826 
  827 /* end of vfs default ops */

Cache object: 927e057aa7378ebddfd06ec7ca978b92


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