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/ufs/ffs/ffs_vnops.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ffs_vnops.c,v 1.66 2003/11/15 01:19:38 thorpej Exp $   */
    2 
    3 /*
    4  * Copyright (c) 1982, 1986, 1989, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.66 2003/11/15 01:19:38 thorpej Exp $");
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/resourcevar.h>
   40 #include <sys/kernel.h>
   41 #include <sys/file.h>
   42 #include <sys/stat.h>
   43 #include <sys/buf.h>
   44 #include <sys/event.h>
   45 #include <sys/proc.h>
   46 #include <sys/mount.h>
   47 #include <sys/vnode.h>
   48 #include <sys/pool.h>
   49 #include <sys/signalvar.h>
   50 
   51 #include <miscfs/fifofs/fifo.h>
   52 #include <miscfs/genfs/genfs.h>
   53 #include <miscfs/specfs/specdev.h>
   54 
   55 #include <ufs/ufs/inode.h>
   56 #include <ufs/ufs/dir.h>
   57 #include <ufs/ufs/ufs_extern.h>
   58 #include <ufs/ufs/ufsmount.h>
   59 
   60 #include <ufs/ffs/fs.h>
   61 #include <ufs/ffs/ffs_extern.h>
   62 
   63 #include <uvm/uvm.h>
   64 
   65 static int ffs_full_fsync __P((void *));
   66 
   67 /* Global vfs data structures for ufs. */
   68 int (**ffs_vnodeop_p) __P((void *));
   69 const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
   70         { &vop_default_desc, vn_default_error },
   71         { &vop_lookup_desc, ufs_lookup },               /* lookup */
   72         { &vop_create_desc, ufs_create },               /* create */
   73         { &vop_whiteout_desc, ufs_whiteout },           /* whiteout */
   74         { &vop_mknod_desc, ufs_mknod },                 /* mknod */
   75         { &vop_open_desc, ufs_open },                   /* open */
   76         { &vop_close_desc, ufs_close },                 /* close */
   77         { &vop_access_desc, ufs_access },               /* access */
   78         { &vop_getattr_desc, ufs_getattr },             /* getattr */
   79         { &vop_setattr_desc, ufs_setattr },             /* setattr */
   80         { &vop_read_desc, ffs_read },                   /* read */
   81         { &vop_write_desc, ffs_write },                 /* write */
   82         { &vop_lease_desc, ufs_lease_check },           /* lease */
   83         { &vop_ioctl_desc, ufs_ioctl },                 /* ioctl */
   84         { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
   85         { &vop_poll_desc, ufs_poll },                   /* poll */
   86         { &vop_kqfilter_desc, genfs_kqfilter },         /* kqfilter */
   87         { &vop_revoke_desc, ufs_revoke },               /* revoke */
   88         { &vop_mmap_desc, ufs_mmap },                   /* mmap */
   89         { &vop_fsync_desc, ffs_fsync },                 /* fsync */
   90         { &vop_seek_desc, ufs_seek },                   /* seek */
   91         { &vop_remove_desc, ufs_remove },               /* remove */
   92         { &vop_link_desc, ufs_link },                   /* link */
   93         { &vop_rename_desc, ufs_rename },               /* rename */
   94         { &vop_mkdir_desc, ufs_mkdir },                 /* mkdir */
   95         { &vop_rmdir_desc, ufs_rmdir },                 /* rmdir */
   96         { &vop_symlink_desc, ufs_symlink },             /* symlink */
   97         { &vop_readdir_desc, ufs_readdir },             /* readdir */
   98         { &vop_readlink_desc, ufs_readlink },           /* readlink */
   99         { &vop_abortop_desc, ufs_abortop },             /* abortop */
  100         { &vop_inactive_desc, ufs_inactive },           /* inactive */
  101         { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
  102         { &vop_lock_desc, ufs_lock },                   /* lock */
  103         { &vop_unlock_desc, ufs_unlock },               /* unlock */
  104         { &vop_bmap_desc, ufs_bmap },                   /* bmap */
  105         { &vop_strategy_desc, ufs_strategy },           /* strategy */
  106         { &vop_print_desc, ufs_print },                 /* print */
  107         { &vop_islocked_desc, ufs_islocked },           /* islocked */
  108         { &vop_pathconf_desc, ufs_pathconf },           /* pathconf */
  109         { &vop_advlock_desc, ufs_advlock },             /* advlock */
  110         { &vop_blkatoff_desc, ffs_blkatoff },           /* blkatoff */
  111         { &vop_valloc_desc, ffs_valloc },               /* valloc */
  112         { &vop_balloc_desc, ffs_balloc },               /* balloc */
  113         { &vop_reallocblks_desc, ffs_reallocblks },     /* reallocblks */
  114         { &vop_vfree_desc, ffs_vfree },                 /* vfree */
  115         { &vop_truncate_desc, ffs_truncate },           /* truncate */
  116         { &vop_update_desc, ffs_update },               /* update */
  117         { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
  118         { &vop_getpages_desc, ffs_getpages },           /* getpages */
  119         { &vop_putpages_desc, ffs_putpages },           /* putpages */
  120         { NULL, NULL }
  121 };
  122 const struct vnodeopv_desc ffs_vnodeop_opv_desc =
  123         { &ffs_vnodeop_p, ffs_vnodeop_entries };
  124 
  125 int (**ffs_specop_p) __P((void *));
  126 const struct vnodeopv_entry_desc ffs_specop_entries[] = {
  127         { &vop_default_desc, vn_default_error },
  128         { &vop_lookup_desc, spec_lookup },              /* lookup */
  129         { &vop_create_desc, spec_create },              /* create */
  130         { &vop_mknod_desc, spec_mknod },                /* mknod */
  131         { &vop_open_desc, spec_open },                  /* open */
  132         { &vop_close_desc, ufsspec_close },             /* close */
  133         { &vop_access_desc, ufs_access },               /* access */
  134         { &vop_getattr_desc, ufs_getattr },             /* getattr */
  135         { &vop_setattr_desc, ufs_setattr },             /* setattr */
  136         { &vop_read_desc, ufsspec_read },               /* read */
  137         { &vop_write_desc, ufsspec_write },             /* write */
  138         { &vop_lease_desc, spec_lease_check },          /* lease */
  139         { &vop_ioctl_desc, spec_ioctl },                /* ioctl */
  140         { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
  141         { &vop_poll_desc, spec_poll },                  /* poll */
  142         { &vop_kqfilter_desc, spec_kqfilter },          /* kqfilter */
  143         { &vop_revoke_desc, spec_revoke },              /* revoke */
  144         { &vop_mmap_desc, spec_mmap },                  /* mmap */
  145         { &vop_fsync_desc, ffs_fsync },                 /* fsync */
  146         { &vop_seek_desc, spec_seek },                  /* seek */
  147         { &vop_remove_desc, spec_remove },              /* remove */
  148         { &vop_link_desc, spec_link },                  /* link */
  149         { &vop_rename_desc, spec_rename },              /* rename */
  150         { &vop_mkdir_desc, spec_mkdir },                /* mkdir */
  151         { &vop_rmdir_desc, spec_rmdir },                /* rmdir */
  152         { &vop_symlink_desc, spec_symlink },            /* symlink */
  153         { &vop_readdir_desc, spec_readdir },            /* readdir */
  154         { &vop_readlink_desc, spec_readlink },          /* readlink */
  155         { &vop_abortop_desc, spec_abortop },            /* abortop */
  156         { &vop_inactive_desc, ufs_inactive },           /* inactive */
  157         { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
  158         { &vop_lock_desc, ufs_lock },                   /* lock */
  159         { &vop_unlock_desc, ufs_unlock },               /* unlock */
  160         { &vop_bmap_desc, spec_bmap },                  /* bmap */
  161         { &vop_strategy_desc, spec_strategy },          /* strategy */
  162         { &vop_print_desc, ufs_print },                 /* print */
  163         { &vop_islocked_desc, ufs_islocked },           /* islocked */
  164         { &vop_pathconf_desc, spec_pathconf },          /* pathconf */
  165         { &vop_advlock_desc, spec_advlock },            /* advlock */
  166         { &vop_blkatoff_desc, spec_blkatoff },          /* blkatoff */
  167         { &vop_valloc_desc, spec_valloc },              /* valloc */
  168         { &vop_reallocblks_desc, spec_reallocblks },    /* reallocblks */
  169         { &vop_vfree_desc, ffs_vfree },                 /* vfree */
  170         { &vop_truncate_desc, spec_truncate },          /* truncate */
  171         { &vop_update_desc, ffs_update },               /* update */
  172         { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
  173         { &vop_getpages_desc, spec_getpages },          /* getpages */
  174         { &vop_putpages_desc, spec_putpages },          /* putpages */
  175         { NULL, NULL }
  176 };
  177 const struct vnodeopv_desc ffs_specop_opv_desc =
  178         { &ffs_specop_p, ffs_specop_entries };
  179 
  180 int (**ffs_fifoop_p) __P((void *));
  181 const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
  182         { &vop_default_desc, vn_default_error },
  183         { &vop_lookup_desc, fifo_lookup },              /* lookup */
  184         { &vop_create_desc, fifo_create },              /* create */
  185         { &vop_mknod_desc, fifo_mknod },                /* mknod */
  186         { &vop_open_desc, fifo_open },                  /* open */
  187         { &vop_close_desc, ufsfifo_close },             /* close */
  188         { &vop_access_desc, ufs_access },               /* access */
  189         { &vop_getattr_desc, ufs_getattr },             /* getattr */
  190         { &vop_setattr_desc, ufs_setattr },             /* setattr */
  191         { &vop_read_desc, ufsfifo_read },               /* read */
  192         { &vop_write_desc, ufsfifo_write },             /* write */
  193         { &vop_lease_desc, fifo_lease_check },          /* lease */
  194         { &vop_ioctl_desc, fifo_ioctl },                /* ioctl */
  195         { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
  196         { &vop_poll_desc, fifo_poll },                  /* poll */
  197         { &vop_kqfilter_desc, fifo_kqfilter },          /* kqfilter */
  198         { &vop_revoke_desc, fifo_revoke },              /* revoke */
  199         { &vop_mmap_desc, fifo_mmap },                  /* mmap */
  200         { &vop_fsync_desc, ffs_fsync },                 /* fsync */
  201         { &vop_seek_desc, fifo_seek },                  /* seek */
  202         { &vop_remove_desc, fifo_remove },              /* remove */
  203         { &vop_link_desc, fifo_link },                  /* link */
  204         { &vop_rename_desc, fifo_rename },              /* rename */
  205         { &vop_mkdir_desc, fifo_mkdir },                /* mkdir */
  206         { &vop_rmdir_desc, fifo_rmdir },                /* rmdir */
  207         { &vop_symlink_desc, fifo_symlink },            /* symlink */
  208         { &vop_readdir_desc, fifo_readdir },            /* readdir */
  209         { &vop_readlink_desc, fifo_readlink },          /* readlink */
  210         { &vop_abortop_desc, fifo_abortop },            /* abortop */
  211         { &vop_inactive_desc, ufs_inactive },           /* inactive */
  212         { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
  213         { &vop_lock_desc, ufs_lock },                   /* lock */
  214         { &vop_unlock_desc, ufs_unlock },               /* unlock */
  215         { &vop_bmap_desc, fifo_bmap },                  /* bmap */
  216         { &vop_strategy_desc, fifo_strategy },          /* strategy */
  217         { &vop_print_desc, ufs_print },                 /* print */
  218         { &vop_islocked_desc, ufs_islocked },           /* islocked */
  219         { &vop_pathconf_desc, fifo_pathconf },          /* pathconf */
  220         { &vop_advlock_desc, fifo_advlock },            /* advlock */
  221         { &vop_blkatoff_desc, fifo_blkatoff },          /* blkatoff */
  222         { &vop_valloc_desc, fifo_valloc },              /* valloc */
  223         { &vop_reallocblks_desc, fifo_reallocblks },    /* reallocblks */
  224         { &vop_vfree_desc, ffs_vfree },                 /* vfree */
  225         { &vop_truncate_desc, fifo_truncate },          /* truncate */
  226         { &vop_update_desc, ffs_update },               /* update */
  227         { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
  228         { &vop_putpages_desc, fifo_putpages },          /* putpages */
  229         { NULL, NULL }
  230 };
  231 const struct vnodeopv_desc ffs_fifoop_opv_desc =
  232         { &ffs_fifoop_p, ffs_fifoop_entries };
  233 
  234 #include <ufs/ufs/ufs_readwrite.c>
  235 
  236 int
  237 ffs_fsync(v)
  238         void *v;
  239 {
  240         struct vop_fsync_args /* {
  241                 struct vnode *a_vp;
  242                 struct ucred *a_cred;
  243                 int a_flags;
  244                 off_t a_offlo;
  245                 off_t a_offhi;
  246                 struct proc *a_p;
  247         } */ *ap = v;
  248         struct buf *bp;
  249         int s, num, error, i;
  250         struct indir ia[NIADDR + 1];
  251         int bsize;
  252         daddr_t blk_high;
  253         struct vnode *vp;
  254 
  255         /*
  256          * XXX no easy way to sync a range in a file with softdep.
  257          */
  258         if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(ap->a_vp) ||
  259                         (ap->a_vp->v_type != VREG))
  260                 return ffs_full_fsync(v);
  261 
  262         vp = ap->a_vp;
  263 
  264         bsize = ap->a_vp->v_mount->mnt_stat.f_iosize;
  265         blk_high = ap->a_offhi / bsize;
  266         if (ap->a_offhi % bsize != 0)
  267                 blk_high++;
  268 
  269         /*
  270          * First, flush all pages in range.
  271          */
  272 
  273         simple_lock(&vp->v_interlock);
  274         error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
  275             round_page(ap->a_offhi), PGO_CLEANIT |
  276             ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
  277         if (error) {
  278                 return error;
  279         }
  280 
  281         /*
  282          * Then, flush indirect blocks.
  283          */
  284 
  285         s = splbio();
  286         if (blk_high >= NDADDR) {
  287                 error = ufs_getlbns(vp, blk_high, ia, &num);
  288                 if (error) {
  289                         splx(s);
  290                         return error;
  291                 }
  292                 for (i = 0; i < num; i++) {
  293                         bp = incore(vp, ia[i].in_lbn);
  294                         if (bp != NULL) {
  295                                 simple_lock(&bp->b_interlock);
  296                                 if (!(bp->b_flags & B_BUSY) && (bp->b_flags & B_DELWRI)) {
  297                                         bp->b_flags |= B_BUSY | B_VFLUSH;
  298                                         simple_unlock(&bp->b_interlock);
  299                                         splx(s);
  300                                         bawrite(bp);
  301                                         s = splbio();
  302                                 } else {
  303                                         simple_unlock(&bp->b_interlock);
  304                                 }
  305                         }
  306                 }
  307         }
  308 
  309         if (ap->a_flags & FSYNC_WAIT) {
  310                 simple_lock(&global_v_numoutput_slock);
  311                 while (vp->v_numoutput > 0) {
  312                         vp->v_flag |= VBWAIT;
  313                         ltsleep(&vp->v_numoutput, PRIBIO + 1, "fsync_range", 0,
  314                                 &global_v_numoutput_slock);
  315                 }
  316                 simple_unlock(&global_v_numoutput_slock);
  317         }
  318         splx(s);
  319 
  320         return (VOP_UPDATE(vp, NULL, NULL,
  321             ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
  322             ? UPDATE_WAIT : 0));
  323 }
  324 
  325 /*
  326  * Synch an open file.
  327  */
  328 /* ARGSUSED */
  329 static int
  330 ffs_full_fsync(v)
  331         void *v;
  332 {
  333         struct vop_fsync_args /* {
  334                 struct vnode *a_vp;
  335                 struct ucred *a_cred;
  336                 int a_flags;
  337                 off_t a_offlo;
  338                 off_t a_offhi;
  339                 struct proc *a_p;
  340         } */ *ap = v;
  341         struct vnode *vp = ap->a_vp;
  342         struct buf *bp, *nbp;
  343         int s, error, passes, skipmeta, inodedeps_only, waitfor;
  344 
  345         if (vp->v_type == VBLK &&
  346             vp->v_specmountpoint != NULL &&
  347             (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
  348                 softdep_fsync_mountdev(vp);
  349 
  350         inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM)
  351             && vp->v_uobj.uo_npages == 0 && LIST_EMPTY(&vp->v_dirtyblkhd);
  352 
  353         /*
  354          * Flush all dirty data associated with a vnode.
  355          */
  356 
  357         if (vp->v_type == VREG) {
  358                 simple_lock(&vp->v_interlock);
  359                 error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT |
  360                     ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
  361                 if (error) {
  362                         return error;
  363                 }
  364         }
  365 
  366         passes = NIADDR + 1;
  367         skipmeta = 0;
  368         if (ap->a_flags & FSYNC_WAIT)
  369                 skipmeta = 1;
  370         s = splbio();
  371 
  372 loop:
  373         LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
  374                 bp->b_flags &= ~B_SCANNED;
  375         for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
  376                 nbp = LIST_NEXT(bp, b_vnbufs);
  377                 simple_lock(&bp->b_interlock);
  378                 if (bp->b_flags & (B_BUSY | B_SCANNED)) {
  379                         simple_unlock(&bp->b_interlock);
  380                         continue;
  381                 }
  382                 if ((bp->b_flags & B_DELWRI) == 0)
  383                         panic("ffs_fsync: not dirty");
  384                 if (skipmeta && bp->b_lblkno < 0) {
  385                         simple_unlock(&bp->b_interlock);
  386                         continue;
  387                 }
  388                 simple_unlock(&bp->b_interlock);
  389                 bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED;
  390                 splx(s);
  391                 /*
  392                  * On our final pass through, do all I/O synchronously
  393                  * so that we can find out if our flush is failing
  394                  * because of write errors.
  395                  */
  396                 if (passes > 0 || !(ap->a_flags & FSYNC_WAIT))
  397                         (void) bawrite(bp);
  398                 else if ((error = bwrite(bp)) != 0)
  399                         return (error);
  400                 s = splbio();
  401                 /*
  402                  * Since we may have slept during the I/O, we need
  403                  * to start from a known point.
  404                  */
  405                 nbp = LIST_FIRST(&vp->v_dirtyblkhd);
  406         }
  407         if (skipmeta) {
  408                 skipmeta = 0;
  409                 goto loop;
  410         }
  411         if (ap->a_flags & FSYNC_WAIT) {
  412                 simple_lock(&global_v_numoutput_slock);
  413                 while (vp->v_numoutput) {
  414                         vp->v_flag |= VBWAIT;
  415                         (void) ltsleep(&vp->v_numoutput, PRIBIO + 1,
  416                             "ffsfsync", 0, &global_v_numoutput_slock);
  417                 }
  418                 simple_unlock(&global_v_numoutput_slock);
  419                 splx(s);
  420 
  421                 /* 
  422                  * Ensure that any filesystem metadata associated
  423                  * with the vnode has been written.
  424                  */
  425                 if ((error = softdep_sync_metadata(ap)) != 0)
  426                         return (error);
  427 
  428                 s = splbio();
  429                 if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
  430                         /*
  431                         * Block devices associated with filesystems may
  432                         * have new I/O requests posted for them even if
  433                         * the vnode is locked, so no amount of trying will
  434                         * get them clean. Thus we give block devices a
  435                         * good effort, then just give up. For all other file
  436                         * types, go around and try again until it is clean.
  437                         */
  438                         if (passes > 0) {
  439                                 passes--;
  440                                 goto loop;
  441                         }
  442 #ifdef DIAGNOSTIC
  443                         if (vp->v_type != VBLK)
  444                                 vprint("ffs_fsync: dirty", vp);
  445 #endif
  446                 }
  447         }
  448         splx(s);
  449 
  450         if (inodedeps_only)
  451                 waitfor = 0;
  452         else
  453                 waitfor = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
  454         return (VOP_UPDATE(vp, NULL, NULL, waitfor));
  455 }
  456 
  457 /*
  458  * Reclaim an inode so that it can be used for other purposes.
  459  */
  460 int
  461 ffs_reclaim(v)
  462         void *v;
  463 {
  464         struct vop_reclaim_args /* {
  465                 struct vnode *a_vp;
  466                 struct proc *a_p;
  467         } */ *ap = v;
  468         struct vnode *vp = ap->a_vp;
  469         struct inode *ip = VTOI(vp);
  470         struct ufsmount *ump = ip->i_ump;
  471         int error;
  472 
  473         if ((error = ufs_reclaim(vp, ap->a_p)) != 0)
  474                 return (error);
  475         if (ip->i_din.ffs1_din != NULL) {
  476                 if (ump->um_fstype == UFS1)
  477                         pool_put(&ffs_dinode1_pool, ip->i_din.ffs1_din);
  478                 else
  479                         pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din);
  480         }
  481         /*
  482          * XXX MFS ends up here, too, to free an inode.  Should we create
  483          * XXX a separate pool for MFS inodes?
  484          */
  485         pool_put(&ffs_inode_pool, vp->v_data);
  486         vp->v_data = NULL;
  487         return (0);
  488 }
  489 
  490 int
  491 ffs_getpages(void *v)
  492 {
  493         struct vop_getpages_args /* {
  494                 struct vnode *a_vp;
  495                 voff_t a_offset;
  496                 struct vm_page **a_m;
  497                 int *a_count;
  498                 int a_centeridx;
  499                 vm_prot_t a_access_type;
  500                 int a_advice;
  501                 int a_flags;
  502         } */ *ap = v;
  503         struct vnode *vp = ap->a_vp;
  504         struct inode *ip = VTOI(vp);
  505         struct fs *fs = ip->i_fs;
  506 
  507         /*
  508          * don't allow a softdep write to create pages for only part of a block.
  509          * the dependency tracking requires that all pages be in memory for
  510          * a block involved in a dependency.
  511          */
  512 
  513         if (ap->a_flags & PGO_OVERWRITE &&
  514             (blkoff(fs, ap->a_offset) != 0 ||
  515              blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) &&
  516             DOINGSOFTDEP(ap->a_vp)) {
  517                 if ((ap->a_flags & PGO_LOCKED) == 0) {
  518                         simple_unlock(&vp->v_interlock);
  519                 }
  520                 return EINVAL;
  521         }
  522         return genfs_getpages(v);
  523 }
  524 
  525 int
  526 ffs_putpages(void *v)
  527 {
  528         struct vop_putpages_args /* {
  529                 struct vnode *a_vp;
  530                 voff_t a_offlo;
  531                 voff_t a_offhi;
  532                 int a_flags;
  533         } */ *ap = v;
  534         struct vnode *vp = ap->a_vp;
  535         struct uvm_object *uobj = &vp->v_uobj;
  536         struct inode *ip = VTOI(vp);
  537         struct fs *fs = ip->i_fs;
  538         struct vm_page *pg;
  539         off_t off;
  540 
  541         if (!DOINGSOFTDEP(vp) || (ap->a_flags & PGO_CLEANIT) == 0) {
  542                 return genfs_putpages(v);
  543         }
  544 
  545         /*
  546          * for softdep files, force the pages in a block to be written together.
  547          * if we're the pagedaemon and we would have to wait for other pages,
  548          * just fail the request.  the pagedaemon will pick a different page.
  549          */
  550 
  551         ap->a_offlo &= ~fs->fs_qbmask;
  552         ap->a_offhi = blkroundup(fs, ap->a_offhi);
  553         if (curproc == uvm.pagedaemon_proc) {
  554                 for (off = ap->a_offlo; off < ap->a_offhi; off += PAGE_SIZE) {
  555                         pg = uvm_pagelookup(uobj, off);
  556 
  557                         /*
  558                          * we only have missing pages here because the
  559                          * calculation of offhi above doesn't account for
  560                          * fragments.  so once we see one missing page,
  561                          * the rest should be missing as well, but we'll
  562                          * check for the rest just to be paranoid.
  563                          */
  564 
  565                         if (pg == NULL) {
  566                                 continue;
  567                         }
  568                         if (pg->flags & PG_BUSY) {
  569                                 simple_unlock(&uobj->vmobjlock);
  570                                 return EBUSY;
  571                         }
  572                 }
  573         }
  574         return genfs_putpages(v);
  575 }
  576 
  577 /*
  578  * Return the last logical file offset that should be written for this file
  579  * if we're doing a write that ends at "size".
  580  */
  581 
  582 void
  583 ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
  584 {
  585         struct inode *ip = VTOI(vp);
  586         struct fs *fs = ip->i_fs;
  587         daddr_t olbn, nlbn;
  588 
  589         KASSERT(flags & (GOP_SIZE_READ | GOP_SIZE_WRITE));
  590         KASSERT((flags & (GOP_SIZE_READ | GOP_SIZE_WRITE)) 
  591                 != (GOP_SIZE_READ | GOP_SIZE_WRITE));
  592 
  593         olbn = lblkno(fs, ip->i_size);
  594         nlbn = lblkno(fs, size);
  595         if (nlbn < NDADDR && olbn <= nlbn) {
  596                 *eobp = fragroundup(fs, size);
  597         } else {
  598                 *eobp = blkroundup(fs, size);
  599         }
  600 }

Cache object: d643411337763551dab47f8f155f8814


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