[BACK]Return to ffs_vnops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ufs / ffs

Annotation of src/sys/ufs/ffs/ffs_vnops.c, Revision 1.81.4.2

1.81.4.2! ad          1: /*     $NetBSD: ffs_vnops.c,v 1.85 2007/01/29 15:42:50 hannken Exp $   */
1.3       cgd         2:
1.1       mycroft     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.
1.60      agc        15:  * 3. Neither the name of the University nor the names of its contributors
1.1       mycroft    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:  *
1.12      fvdl       31:  *     @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
1.1       mycroft    32:  */
1.44      lukem      33:
                     34: #include <sys/cdefs.h>
1.81.4.2! ad         35: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.85 2007/01/29 15:42:50 hannken Exp $");
1.11      mrg        36:
1.1       mycroft    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>
1.50      jdolecek   44: #include <sys/event.h>
1.1       mycroft    45: #include <sys/proc.h>
                     46: #include <sys/mount.h>
                     47: #include <sys/vnode.h>
1.16      thorpej    48: #include <sys/pool.h>
1.6       christos   49: #include <sys/signalvar.h>
1.80      elad       50: #include <sys/kauth.h>
1.81.4.2! ad         51: #include <sys/fstrans.h>
1.1       mycroft    52:
1.8       mycroft    53: #include <miscfs/fifofs/fifo.h>
                     54: #include <miscfs/genfs/genfs.h>
1.1       mycroft    55: #include <miscfs/specfs/specdev.h>
                     56:
                     57: #include <ufs/ufs/inode.h>
                     58: #include <ufs/ufs/dir.h>
                     59: #include <ufs/ufs/ufs_extern.h>
1.2       mycroft    60: #include <ufs/ufs/ufsmount.h>
1.1       mycroft    61:
                     62: #include <ufs/ffs/fs.h>
                     63: #include <ufs/ffs/ffs_extern.h>
                     64:
1.49      chs        65: #include <uvm/uvm.h>
                     66:
1.74      xtraeme    67: static int ffs_full_fsync(void *);
1.33      fvdl       68:
1.1       mycroft    69: /* Global vfs data structures for ufs. */
1.74      xtraeme    70: int (**ffs_vnodeop_p)(void *);
1.37      jdolecek   71: const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
1.1       mycroft    72:        { &vop_default_desc, vn_default_error },
                     73:        { &vop_lookup_desc, ufs_lookup },               /* lookup */
                     74:        { &vop_create_desc, ufs_create },               /* create */
1.5       mycroft    75:        { &vop_whiteout_desc, ufs_whiteout },           /* whiteout */
1.1       mycroft    76:        { &vop_mknod_desc, ufs_mknod },                 /* mknod */
                     77:        { &vop_open_desc, ufs_open },                   /* open */
                     78:        { &vop_close_desc, ufs_close },                 /* close */
                     79:        { &vop_access_desc, ufs_access },               /* access */
                     80:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                     81:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                     82:        { &vop_read_desc, ffs_read },                   /* read */
                     83:        { &vop_write_desc, ffs_write },                 /* write */
1.4       mycroft    84:        { &vop_lease_desc, ufs_lease_check },           /* lease */
1.1       mycroft    85:        { &vop_ioctl_desc, ufs_ioctl },                 /* ioctl */
1.19      wrstuden   86:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft    87:        { &vop_poll_desc, ufs_poll },                   /* poll */
1.50      jdolecek   88:        { &vop_kqfilter_desc, genfs_kqfilter },         /* kqfilter */
1.12      fvdl       89:        { &vop_revoke_desc, ufs_revoke },               /* revoke */
1.1       mycroft    90:        { &vop_mmap_desc, ufs_mmap },                   /* mmap */
                     91:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                     92:        { &vop_seek_desc, ufs_seek },                   /* seek */
                     93:        { &vop_remove_desc, ufs_remove },               /* remove */
                     94:        { &vop_link_desc, ufs_link },                   /* link */
                     95:        { &vop_rename_desc, ufs_rename },               /* rename */
                     96:        { &vop_mkdir_desc, ufs_mkdir },                 /* mkdir */
                     97:        { &vop_rmdir_desc, ufs_rmdir },                 /* rmdir */
                     98:        { &vop_symlink_desc, ufs_symlink },             /* symlink */
                     99:        { &vop_readdir_desc, ufs_readdir },             /* readdir */
                    100:        { &vop_readlink_desc, ufs_readlink },           /* readlink */
                    101:        { &vop_abortop_desc, ufs_abortop },             /* abortop */
                    102:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    103:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
                    104:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    105:        { &vop_unlock_desc, ufs_unlock },               /* unlock */
                    106:        { &vop_bmap_desc, ufs_bmap },                   /* bmap */
                    107:        { &vop_strategy_desc, ufs_strategy },           /* strategy */
                    108:        { &vop_print_desc, ufs_print },                 /* print */
                    109:        { &vop_islocked_desc, ufs_islocked },           /* islocked */
                    110:        { &vop_pathconf_desc, ufs_pathconf },           /* pathconf */
                    111:        { &vop_advlock_desc, ufs_advlock },             /* advlock */
1.8       mycroft   112:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.39      chs       113:        { &vop_getpages_desc, ffs_getpages },           /* getpages */
1.75      yamt      114:        { &vop_putpages_desc, genfs_putpages },         /* putpages */
1.73      thorpej   115:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    116:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    117:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    118:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    119:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    120:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       121:        { NULL, NULL }
1.1       mycroft   122: };
1.37      jdolecek  123: const struct vnodeopv_desc ffs_vnodeop_opv_desc =
1.1       mycroft   124:        { &ffs_vnodeop_p, ffs_vnodeop_entries };
                    125:
1.74      xtraeme   126: int (**ffs_specop_p)(void *);
1.37      jdolecek  127: const struct vnodeopv_entry_desc ffs_specop_entries[] = {
1.1       mycroft   128:        { &vop_default_desc, vn_default_error },
                    129:        { &vop_lookup_desc, spec_lookup },              /* lookup */
                    130:        { &vop_create_desc, spec_create },              /* create */
                    131:        { &vop_mknod_desc, spec_mknod },                /* mknod */
                    132:        { &vop_open_desc, spec_open },                  /* open */
                    133:        { &vop_close_desc, ufsspec_close },             /* close */
                    134:        { &vop_access_desc, ufs_access },               /* access */
                    135:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                    136:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                    137:        { &vop_read_desc, ufsspec_read },               /* read */
                    138:        { &vop_write_desc, ufsspec_write },             /* write */
1.4       mycroft   139:        { &vop_lease_desc, spec_lease_check },          /* lease */
1.1       mycroft   140:        { &vop_ioctl_desc, spec_ioctl },                /* ioctl */
1.19      wrstuden  141:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft   142:        { &vop_poll_desc, spec_poll },                  /* poll */
1.50      jdolecek  143:        { &vop_kqfilter_desc, spec_kqfilter },          /* kqfilter */
1.12      fvdl      144:        { &vop_revoke_desc, spec_revoke },              /* revoke */
1.1       mycroft   145:        { &vop_mmap_desc, spec_mmap },                  /* mmap */
                    146:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                    147:        { &vop_seek_desc, spec_seek },                  /* seek */
                    148:        { &vop_remove_desc, spec_remove },              /* remove */
                    149:        { &vop_link_desc, spec_link },                  /* link */
                    150:        { &vop_rename_desc, spec_rename },              /* rename */
                    151:        { &vop_mkdir_desc, spec_mkdir },                /* mkdir */
                    152:        { &vop_rmdir_desc, spec_rmdir },                /* rmdir */
                    153:        { &vop_symlink_desc, spec_symlink },            /* symlink */
                    154:        { &vop_readdir_desc, spec_readdir },            /* readdir */
                    155:        { &vop_readlink_desc, spec_readlink },          /* readlink */
                    156:        { &vop_abortop_desc, spec_abortop },            /* abortop */
                    157:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    158:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
                    159:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    160:        { &vop_unlock_desc, ufs_unlock },               /* unlock */
                    161:        { &vop_bmap_desc, spec_bmap },                  /* bmap */
                    162:        { &vop_strategy_desc, spec_strategy },          /* strategy */
                    163:        { &vop_print_desc, ufs_print },                 /* print */
                    164:        { &vop_islocked_desc, ufs_islocked },           /* islocked */
                    165:        { &vop_pathconf_desc, spec_pathconf },          /* pathconf */
                    166:        { &vop_advlock_desc, spec_advlock },            /* advlock */
1.8       mycroft   167:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.38      chs       168:        { &vop_getpages_desc, spec_getpages },          /* getpages */
                    169:        { &vop_putpages_desc, spec_putpages },          /* putpages */
1.73      thorpej   170:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    171:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    172:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    173:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    174:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    175:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       176:        { NULL, NULL }
1.1       mycroft   177: };
1.37      jdolecek  178: const struct vnodeopv_desc ffs_specop_opv_desc =
1.1       mycroft   179:        { &ffs_specop_p, ffs_specop_entries };
                    180:
1.74      xtraeme   181: int (**ffs_fifoop_p)(void *);
1.37      jdolecek  182: const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
1.1       mycroft   183:        { &vop_default_desc, vn_default_error },
                    184:        { &vop_lookup_desc, fifo_lookup },              /* lookup */
                    185:        { &vop_create_desc, fifo_create },              /* create */
                    186:        { &vop_mknod_desc, fifo_mknod },                /* mknod */
                    187:        { &vop_open_desc, fifo_open },                  /* open */
                    188:        { &vop_close_desc, ufsfifo_close },             /* close */
                    189:        { &vop_access_desc, ufs_access },               /* access */
                    190:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                    191:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                    192:        { &vop_read_desc, ufsfifo_read },               /* read */
                    193:        { &vop_write_desc, ufsfifo_write },             /* write */
1.4       mycroft   194:        { &vop_lease_desc, fifo_lease_check },          /* lease */
1.1       mycroft   195:        { &vop_ioctl_desc, fifo_ioctl },                /* ioctl */
1.19      wrstuden  196:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft   197:        { &vop_poll_desc, fifo_poll },                  /* poll */
1.50      jdolecek  198:        { &vop_kqfilter_desc, fifo_kqfilter },          /* kqfilter */
1.12      fvdl      199:        { &vop_revoke_desc, fifo_revoke },              /* revoke */
1.1       mycroft   200:        { &vop_mmap_desc, fifo_mmap },                  /* mmap */
                    201:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                    202:        { &vop_seek_desc, fifo_seek },                  /* seek */
                    203:        { &vop_remove_desc, fifo_remove },              /* remove */
                    204:        { &vop_link_desc, fifo_link },                  /* link */
                    205:        { &vop_rename_desc, fifo_rename },              /* rename */
                    206:        { &vop_mkdir_desc, fifo_mkdir },                /* mkdir */
                    207:        { &vop_rmdir_desc, fifo_rmdir },                /* rmdir */
                    208:        { &vop_symlink_desc, fifo_symlink },            /* symlink */
                    209:        { &vop_readdir_desc, fifo_readdir },            /* readdir */
                    210:        { &vop_readlink_desc, fifo_readlink },          /* readlink */
                    211:        { &vop_abortop_desc, fifo_abortop },            /* abortop */
                    212:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    213:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
                    214:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    215:        { &vop_unlock_desc, ufs_unlock },               /* unlock */
                    216:        { &vop_bmap_desc, fifo_bmap },                  /* bmap */
                    217:        { &vop_strategy_desc, fifo_strategy },          /* strategy */
                    218:        { &vop_print_desc, ufs_print },                 /* print */
                    219:        { &vop_islocked_desc, ufs_islocked },           /* islocked */
                    220:        { &vop_pathconf_desc, fifo_pathconf },          /* pathconf */
                    221:        { &vop_advlock_desc, fifo_advlock },            /* advlock */
1.8       mycroft   222:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.40      sommerfe  223:        { &vop_putpages_desc, fifo_putpages },          /* putpages */
1.73      thorpej   224:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    225:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    226:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    227:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    228:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    229:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       230:        { NULL, NULL }
1.1       mycroft   231: };
1.37      jdolecek  232: const struct vnodeopv_desc ffs_fifoop_opv_desc =
1.1       mycroft   233:        { &ffs_fifoop_p, ffs_fifoop_entries };
                    234:
                    235: #include <ufs/ufs/ufs_readwrite.c>
1.20      fvdl      236:
1.33      fvdl      237: int
1.70      thorpej   238: ffs_fsync(void *v)
1.33      fvdl      239: {
                    240:        struct vop_fsync_args /* {
                    241:                struct vnode *a_vp;
1.80      elad      242:                kauth_cred_t a_cred;
1.33      fvdl      243:                int a_flags;
1.46      chs       244:                off_t a_offlo;
                    245:                off_t a_offhi;
1.77      christos  246:                struct lwp *a_l;
1.33      fvdl      247:        } */ *ap = v;
1.35      chs       248:        struct buf *bp;
1.33      fvdl      249:        int s, num, error, i;
                    250:        struct indir ia[NIADDR + 1];
                    251:        int bsize;
1.45      simonb    252:        daddr_t blk_high;
1.33      fvdl      253:        struct vnode *vp;
                    254:
1.81.4.2! ad        255:        vp = ap->a_vp;
        !           256:
        !           257:        if ((error = fstrans_start(vp->v_mount, FSTRANS_LAZY)) != 0)
        !           258:                return error;
1.33      fvdl      259:        /*
                    260:         * XXX no easy way to sync a range in a file with softdep.
                    261:         */
1.81.4.2! ad        262:        if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(vp) ||
        !           263:            (vp->v_type != VREG)) {
        !           264:                error = ffs_full_fsync(v);
        !           265:                goto out;
        !           266:        }
1.33      fvdl      267:
1.81.4.2! ad        268:        bsize = vp->v_mount->mnt_stat.f_iosize;
1.33      fvdl      269:        blk_high = ap->a_offhi / bsize;
                    270:        if (ap->a_offhi % bsize != 0)
                    271:                blk_high++;
                    272:
                    273:        /*
1.35      chs       274:         * First, flush all pages in range.
1.33      fvdl      275:         */
1.35      chs       276:
1.64      dbj       277:        simple_lock(&vp->v_interlock);
                    278:        error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
                    279:            round_page(ap->a_offhi), PGO_CLEANIT |
                    280:            ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
                    281:        if (error) {
1.81.4.2! ad        282:                goto out;
1.39      chs       283:        }
1.33      fvdl      284:
                    285:        /*
1.35      chs       286:         * Then, flush indirect blocks.
1.33      fvdl      287:         */
1.35      chs       288:
1.41      chs       289:        s = splbio();
1.61      kleink    290:        if (blk_high >= NDADDR) {
1.33      fvdl      291:                error = ufs_getlbns(vp, blk_high, ia, &num);
1.42      chs       292:                if (error) {
                    293:                        splx(s);
1.81.4.2! ad        294:                        goto out;
1.42      chs       295:                }
1.33      fvdl      296:                for (i = 0; i < num; i++) {
1.35      chs       297:                        bp = incore(vp, ia[i].in_lbn);
1.62      dbj       298:                        if (bp != NULL) {
                    299:                                simple_lock(&bp->b_interlock);
                    300:                                if (!(bp->b_flags & B_BUSY) && (bp->b_flags & B_DELWRI)) {
                    301:                                        bp->b_flags |= B_BUSY | B_VFLUSH;
                    302:                                        simple_unlock(&bp->b_interlock);
                    303:                                        splx(s);
                    304:                                        bawrite(bp);
                    305:                                        s = splbio();
                    306:                                } else {
                    307:                                        simple_unlock(&bp->b_interlock);
                    308:                                }
1.33      fvdl      309:                        }
                    310:                }
                    311:        }
                    312:
                    313:        if (ap->a_flags & FSYNC_WAIT) {
1.54      pk        314:                simple_lock(&global_v_numoutput_slock);
1.33      fvdl      315:                while (vp->v_numoutput > 0) {
                    316:                        vp->v_flag |= VBWAIT;
1.54      pk        317:                        ltsleep(&vp->v_numoutput, PRIBIO + 1, "fsync_range", 0,
                    318:                                &global_v_numoutput_slock);
1.33      fvdl      319:                }
1.54      pk        320:                simple_unlock(&global_v_numoutput_slock);
1.33      fvdl      321:        }
1.34      fvdl      322:        splx(s);
1.33      fvdl      323:
1.76      yamt      324:        error = ffs_update(vp, NULL, NULL,
1.66      thorpej   325:            ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
1.67      wrstuden  326:            ? UPDATE_WAIT : 0);
                    327:
                    328:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
                    329:                int l = 0;
                    330:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
1.81      ad        331:                        ap->a_l->l_cred, ap->a_l);
1.67      wrstuden  332:        }
                    333:
1.81.4.2! ad        334: out:
        !           335:        fstrans_done(vp->v_mount);
1.67      wrstuden  336:        return error;
1.33      fvdl      337: }
                    338:
1.20      fvdl      339: /*
                    340:  * Synch an open file.
                    341:  */
                    342: /* ARGSUSED */
1.33      fvdl      343: static int
1.70      thorpej   344: ffs_full_fsync(void *v)
1.20      fvdl      345: {
1.29      mycroft   346:        struct vop_fsync_args /* {
1.20      fvdl      347:                struct vnode *a_vp;
1.80      elad      348:                kauth_cred_t a_cred;
1.20      fvdl      349:                int a_flags;
1.46      chs       350:                off_t a_offlo;
                    351:                off_t a_offhi;
1.77      christos  352:                struct lwp *a_l;
1.20      fvdl      353:        } */ *ap = v;
                    354:        struct vnode *vp = ap->a_vp;
                    355:        struct buf *bp, *nbp;
1.47      fvdl      356:        int s, error, passes, skipmeta, inodedeps_only, waitfor;
1.24      fvdl      357:
1.20      fvdl      358:        if (vp->v_type == VBLK &&
                    359:            vp->v_specmountpoint != NULL &&
                    360:            (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
                    361:                softdep_fsync_mountdev(vp);
1.21      perseant  362:
1.47      fvdl      363:        inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM)
1.48      thorpej   364:            && vp->v_uobj.uo_npages == 0 && LIST_EMPTY(&vp->v_dirtyblkhd);
1.47      fvdl      365:
1.35      chs       366:        /*
                    367:         * Flush all dirty data associated with a vnode.
1.20      fvdl      368:         */
1.35      chs       369:
1.72      yamt      370:        if (vp->v_type == VREG || vp->v_type == VBLK) {
1.46      chs       371:                simple_lock(&vp->v_interlock);
                    372:                error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT |
1.81.4.2! ad        373:                    ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0) |
        !           374:                    (fstrans_getstate(vp->v_mount) == FSTRANS_SUSPENDING ?
        !           375:                        PGO_FREE : 0));
1.39      chs       376:                if (error) {
                    377:                        return error;
                    378:                }
1.35      chs       379:        }
                    380:
1.20      fvdl      381:        passes = NIADDR + 1;
                    382:        skipmeta = 0;
1.61      kleink    383:        if (ap->a_flags & FSYNC_WAIT)
1.20      fvdl      384:                skipmeta = 1;
                    385:        s = splbio();
1.35      chs       386:
1.20      fvdl      387: loop:
1.35      chs       388:        LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
1.20      fvdl      389:                bp->b_flags &= ~B_SCANNED;
1.29      mycroft   390:        for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
                    391:                nbp = LIST_NEXT(bp, b_vnbufs);
1.63      dbj       392:                simple_lock(&bp->b_interlock);
                    393:                if (bp->b_flags & (B_BUSY | B_SCANNED)) {
                    394:                        simple_unlock(&bp->b_interlock);
1.20      fvdl      395:                        continue;
1.63      dbj       396:                }
1.20      fvdl      397:                if ((bp->b_flags & B_DELWRI) == 0)
                    398:                        panic("ffs_fsync: not dirty");
1.63      dbj       399:                if (skipmeta && bp->b_lblkno < 0) {
                    400:                        simple_unlock(&bp->b_interlock);
1.20      fvdl      401:                        continue;
1.63      dbj       402:                }
                    403:                simple_unlock(&bp->b_interlock);
1.20      fvdl      404:                bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED;
                    405:                splx(s);
                    406:                /*
                    407:                 * On our final pass through, do all I/O synchronously
                    408:                 * so that we can find out if our flush is failing
                    409:                 * because of write errors.
                    410:                 */
                    411:                if (passes > 0 || !(ap->a_flags & FSYNC_WAIT))
                    412:                        (void) bawrite(bp);
                    413:                else if ((error = bwrite(bp)) != 0)
                    414:                        return (error);
                    415:                s = splbio();
                    416:                /*
                    417:                 * Since we may have slept during the I/O, we need
                    418:                 * to start from a known point.
                    419:                 */
1.29      mycroft   420:                nbp = LIST_FIRST(&vp->v_dirtyblkhd);
1.20      fvdl      421:        }
1.61      kleink    422:        if (skipmeta) {
1.20      fvdl      423:                skipmeta = 0;
                    424:                goto loop;
                    425:        }
                    426:        if (ap->a_flags & FSYNC_WAIT) {
1.54      pk        427:                simple_lock(&global_v_numoutput_slock);
1.20      fvdl      428:                while (vp->v_numoutput) {
                    429:                        vp->v_flag |= VBWAIT;
1.54      pk        430:                        (void) ltsleep(&vp->v_numoutput, PRIBIO + 1,
                    431:                            "ffsfsync", 0, &global_v_numoutput_slock);
1.20      fvdl      432:                }
1.54      pk        433:                simple_unlock(&global_v_numoutput_slock);
1.29      mycroft   434:                splx(s);
1.20      fvdl      435:
1.69      perry     436:                /*
1.20      fvdl      437:                 * Ensure that any filesystem metadata associated
                    438:                 * with the vnode has been written.
                    439:                 */
1.31      mycroft   440:                if ((error = softdep_sync_metadata(ap)) != 0)
1.20      fvdl      441:                        return (error);
1.29      mycroft   442:
1.20      fvdl      443:                s = splbio();
1.29      mycroft   444:                if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
                    445:                        /*
                    446:                        * Block devices associated with filesystems may
                    447:                        * have new I/O requests posted for them even if
                    448:                        * the vnode is locked, so no amount of trying will
                    449:                        * get them clean. Thus we give block devices a
                    450:                        * good effort, then just give up. For all other file
                    451:                        * types, go around and try again until it is clean.
                    452:                        */
                    453:                        if (passes > 0) {
                    454:                                passes--;
                    455:                                goto loop;
                    456:                        }
1.20      fvdl      457: #ifdef DIAGNOSTIC
1.29      mycroft   458:                        if (vp->v_type != VBLK)
                    459:                                vprint("ffs_fsync: dirty", vp);
1.20      fvdl      460: #endif
1.29      mycroft   461:                }
                    462:        }
                    463:        splx(s);
1.47      fvdl      464:
                    465:        if (inodedeps_only)
                    466:                waitfor = 0;
                    467:        else
                    468:                waitfor = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
1.76      yamt      469:        error = ffs_update(vp, NULL, NULL, waitfor);
1.67      wrstuden  470:
1.68      wrstuden  471:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
1.67      wrstuden  472:                int i = 0;
                    473:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
1.81      ad        474:                        ap->a_l->l_cred, ap->a_l);
1.67      wrstuden  475:        }
                    476:
                    477:        return error;
1.20      fvdl      478: }
1.1       mycroft   479:
                    480: /*
                    481:  * Reclaim an inode so that it can be used for other purposes.
                    482:  */
                    483: int
1.70      thorpej   484: ffs_reclaim(void *v)
1.6       christos  485: {
1.1       mycroft   486:        struct vop_reclaim_args /* {
                    487:                struct vnode *a_vp;
1.77      christos  488:                struct lwp *a_l;
1.6       christos  489:        } */ *ap = v;
1.26      augustss  490:        struct vnode *vp = ap->a_vp;
1.56      fvdl      491:        struct inode *ip = VTOI(vp);
1.81.4.2! ad        492:        struct mount *mp = vp->v_mount;
1.56      fvdl      493:        struct ufsmount *ump = ip->i_ump;
1.1       mycroft   494:        int error;
                    495:
1.81.4.2! ad        496:        if ((error = fstrans_start(mp, FSTRANS_LAZY)) != 0)
        !           497:                return error;
        !           498:        if ((error = ufs_reclaim(vp, ap->a_l)) != 0) {
        !           499:                fstrans_done(mp);
1.1       mycroft   500:                return (error);
1.81.4.2! ad        501:        }
1.57      fvdl      502:        if (ip->i_din.ffs1_din != NULL) {
                    503:                if (ump->um_fstype == UFS1)
                    504:                        pool_put(&ffs_dinode1_pool, ip->i_din.ffs1_din);
                    505:                else
                    506:                        pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din);
                    507:        }
1.16      thorpej   508:        /*
                    509:         * XXX MFS ends up here, too, to free an inode.  Should we create
                    510:         * XXX a separate pool for MFS inodes?
                    511:         */
                    512:        pool_put(&ffs_inode_pool, vp->v_data);
1.1       mycroft   513:        vp->v_data = NULL;
1.81.4.2! ad        514:        fstrans_done(mp);
1.1       mycroft   515:        return (0);
1.35      chs       516: }
                    517:
1.39      chs       518: int
                    519: ffs_getpages(void *v)
                    520: {
                    521:        struct vop_getpages_args /* {
                    522:                struct vnode *a_vp;
                    523:                voff_t a_offset;
                    524:                struct vm_page **a_m;
                    525:                int *a_count;
                    526:                int a_centeridx;
                    527:                vm_prot_t a_access_type;
                    528:                int a_advice;
                    529:                int a_flags;
                    530:        } */ *ap = v;
                    531:        struct vnode *vp = ap->a_vp;
                    532:        struct inode *ip = VTOI(vp);
                    533:        struct fs *fs = ip->i_fs;
                    534:
                    535:        /*
                    536:         * don't allow a softdep write to create pages for only part of a block.
                    537:         * the dependency tracking requires that all pages be in memory for
                    538:         * a block involved in a dependency.
                    539:         */
                    540:
                    541:        if (ap->a_flags & PGO_OVERWRITE &&
                    542:            (blkoff(fs, ap->a_offset) != 0 ||
                    543:             blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) &&
                    544:            DOINGSOFTDEP(ap->a_vp)) {
                    545:                if ((ap->a_flags & PGO_LOCKED) == 0) {
1.46      chs       546:                        simple_unlock(&vp->v_interlock);
1.39      chs       547:                }
                    548:                return EINVAL;
                    549:        }
                    550:        return genfs_getpages(v);
1.49      chs       551: }
                    552:
1.35      chs       553: /*
                    554:  * Return the last logical file offset that should be written for this file
                    555:  * if we're doing a write that ends at "size".
                    556:  */
1.39      chs       557:
                    558: void
1.55      perseant  559: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35      chs       560: {
1.39      chs       561:        struct inode *ip = VTOI(vp);
1.35      chs       562:        struct fs *fs = ip->i_fs;
1.52      fvdl      563:        daddr_t olbn, nlbn;
1.55      perseant  564:
1.56      fvdl      565:        olbn = lblkno(fs, ip->i_size);
1.39      chs       566:        nlbn = lblkno(fs, size);
1.35      chs       567:        if (nlbn < NDADDR && olbn <= nlbn) {
1.39      chs       568:                *eobp = fragroundup(fs, size);
1.35      chs       569:        } else {
1.39      chs       570:                *eobp = blkroundup(fs, size);
1.35      chs       571:        }
1.1       mycroft   572: }
1.73      thorpej   573:
                    574: int
                    575: ffs_openextattr(void *v)
                    576: {
                    577:        struct vop_openextattr_args /* {
                    578:                struct vnode *a_vp;
1.80      elad      579:                kauth_cred_t a_cred;
1.73      thorpej   580:                struct proc *a_p;
                    581:        } */ *ap = v;
                    582:        struct inode *ip = VTOI(ap->a_vp);
                    583:        struct fs *fs = ip->i_fs;
                    584:
                    585:        /* Not supported for UFS1 file systems. */
                    586:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    587:                return (EOPNOTSUPP);
                    588:
                    589:        /* XXX Not implemented for UFS2 file systems. */
                    590:        return (EOPNOTSUPP);
                    591: }
                    592:
                    593: int
                    594: ffs_closeextattr(void *v)
                    595: {
                    596:        struct vop_closeextattr_args /* {
                    597:                struct vnode *a_vp;
                    598:                int a_commit;
1.80      elad      599:                kauth_cred_t a_cred;
1.73      thorpej   600:                struct proc *a_p;
                    601:        } */ *ap = v;
                    602:        struct inode *ip = VTOI(ap->a_vp);
                    603:        struct fs *fs = ip->i_fs;
                    604:
                    605:        /* Not supported for UFS1 file systems. */
                    606:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    607:                return (EOPNOTSUPP);
                    608:
                    609:        /* XXX Not implemented for UFS2 file systems. */
                    610:        return (EOPNOTSUPP);
                    611: }
                    612:
                    613: int
                    614: ffs_getextattr(void *v)
                    615: {
                    616:        struct vop_getextattr_args /* {
                    617:                struct vnode *a_vp;
                    618:                int a_attrnamespace;
                    619:                const char *a_name;
                    620:                struct uio *a_uio;
                    621:                size_t *a_size;
1.80      elad      622:                kauth_cred_t a_cred;
1.73      thorpej   623:                struct proc *a_p;
                    624:        } */ *ap = v;
1.81.4.2! ad        625:        struct vnode *vp = ap->a_vp;
        !           626:        struct inode *ip = VTOI(vp);
1.73      thorpej   627:        struct fs *fs = ip->i_fs;
                    628:
                    629:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    630: #ifdef UFS_EXTATTR
1.81.4.2! ad        631:                int error;
        !           632:
        !           633:                if ((error = fstrans_start(vp->v_mount, FSTRANS_SHARED)) != 0)
        !           634:                        return error;
        !           635:                error = ufs_getextattr(ap);
        !           636:                fstrans_done(vp->v_mount);
        !           637:                return error;
1.73      thorpej   638: #else
                    639:                return (EOPNOTSUPP);
                    640: #endif
                    641:        }
                    642:
                    643:        /* XXX Not implemented for UFS2 file systems. */
                    644:        return (EOPNOTSUPP);
                    645: }
                    646:
                    647: int
                    648: ffs_setextattr(void *v)
                    649: {
                    650:        struct vop_setextattr_args /* {
                    651:                struct vnode *a_vp;
                    652:                int a_attrnamespace;
                    653:                const char *a_name;
                    654:                struct uio *a_uio;
1.80      elad      655:                kauth_cred_t a_cred;
1.73      thorpej   656:                struct proc *a_p;
                    657:        } */ *ap = v;
1.81.4.2! ad        658:        struct vnode *vp = ap->a_vp;
        !           659:        struct inode *ip = VTOI(vp);
1.73      thorpej   660:        struct fs *fs = ip->i_fs;
                    661:
                    662:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    663: #ifdef UFS_EXTATTR
1.81.4.2! ad        664:                int error;
        !           665:
        !           666:                if ((error = fstrans_start(vp->v_mount, FSTRANS_SHARED)) != 0)
        !           667:                        return error;
        !           668:                error = ufs_setextattr(ap);
        !           669:                fstrans_done(vp->v_mount);
        !           670:                return error;
1.73      thorpej   671: #else
                    672:                return (EOPNOTSUPP);
                    673: #endif
                    674:        }
                    675:
                    676:        /* XXX Not implemented for UFS2 file systems. */
                    677:        return (EOPNOTSUPP);
                    678: }
                    679:
                    680: int
                    681: ffs_listextattr(void *v)
                    682: {
                    683:        struct vop_listextattr_args /* {
                    684:                struct vnode *a_vp;
                    685:                int a_attrnamespace;
                    686:                struct uio *a_uio;
                    687:                size_t *a_size;
1.80      elad      688:                kauth_cred_t a_cred;
1.73      thorpej   689:                struct proc *a_p;
                    690:        } */ *ap = v;
                    691:        struct inode *ip = VTOI(ap->a_vp);
                    692:        struct fs *fs = ip->i_fs;
                    693:
                    694:        /* Not supported for UFS1 file systems. */
                    695:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    696:                return (EOPNOTSUPP);
                    697:
                    698:        /* XXX Not implemented for UFS2 file systems. */
                    699:        return (EOPNOTSUPP);
                    700: }
                    701:
                    702: int
                    703: ffs_deleteextattr(void *v)
                    704: {
                    705:        struct vop_deleteextattr_args /* {
                    706:                struct vnode *a_vp;
                    707:                int a_attrnamespace;
1.80      elad      708:                kauth_cred_t a_cred;
1.73      thorpej   709:                struct proc *a_p;
                    710:        } */ *ap = v;
1.81.4.2! ad        711:        struct vnode *vp = ap->a_vp;
        !           712:        struct inode *ip = VTOI(vp);
1.73      thorpej   713:        struct fs *fs = ip->i_fs;
                    714:
                    715:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    716: #ifdef UFS_EXTATTR
1.81.4.2! ad        717:                int error;
        !           718:
        !           719:                if ((error = fstrans_start(vp->v_mount, FSTRANS_SHARED)) != 0)
        !           720:                        return error;
        !           721:                error = ufs_deleteextattr(ap);
        !           722:                fstrans_done(vp->v_mount);
        !           723:                return error;
1.73      thorpej   724: #else
                    725:                return (EOPNOTSUPP);
                    726: #endif
                    727:        }
                    728:
                    729:        /* XXX Not implemented for UFS2 file systems. */
                    730:        return (EOPNOTSUPP);
                    731: }

CVSweb <webmaster@jp.NetBSD.org>