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

1.92.4.1! mjf         1: /*     $NetBSD: ffs_vnops.c,v 1.93 2007/11/26 19:02:30 pooka 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.92.4.1! mjf        35: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.93 2007/11/26 19:02:30 pooka 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.84      hannken    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 */
1.90      hannken   104:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    105:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   106:        { &vop_bmap_desc, ufs_bmap },                   /* bmap */
                    107:        { &vop_strategy_desc, ufs_strategy },           /* strategy */
                    108:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   109:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   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.88      yamt      113:        { &vop_getpages_desc, genfs_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 */
1.90      hannken   159:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    160:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   161:        { &vop_bmap_desc, spec_bmap },                  /* bmap */
                    162:        { &vop_strategy_desc, spec_strategy },          /* strategy */
                    163:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   164:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   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 */
1.90      hannken   214:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    215:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   216:        { &vop_bmap_desc, fifo_bmap },                  /* bmap */
                    217:        { &vop_strategy_desc, fifo_strategy },          /* strategy */
                    218:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   219:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   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.84      hannken   255:        vp = ap->a_vp;
                    256:
1.87      hannken   257:        fstrans_start(vp->v_mount, FSTRANS_LAZY);
1.33      fvdl      258:        /*
                    259:         * XXX no easy way to sync a range in a file with softdep.
                    260:         */
1.84      hannken   261:        if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(vp) ||
                    262:            (vp->v_type != VREG)) {
                    263:                error = ffs_full_fsync(v);
                    264:                goto out;
                    265:        }
1.33      fvdl      266:
1.84      hannken   267:        bsize = vp->v_mount->mnt_stat.f_iosize;
1.33      fvdl      268:        blk_high = ap->a_offhi / bsize;
                    269:        if (ap->a_offhi % bsize != 0)
                    270:                blk_high++;
                    271:
                    272:        /*
1.35      chs       273:         * First, flush all pages in range.
1.33      fvdl      274:         */
1.35      chs       275:
1.64      dbj       276:        simple_lock(&vp->v_interlock);
                    277:        error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
                    278:            round_page(ap->a_offhi), PGO_CLEANIT |
                    279:            ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
                    280:        if (error) {
1.84      hannken   281:                goto out;
1.39      chs       282:        }
1.33      fvdl      283:
                    284:        /*
1.35      chs       285:         * Then, flush indirect blocks.
1.33      fvdl      286:         */
1.35      chs       287:
1.41      chs       288:        s = splbio();
1.61      kleink    289:        if (blk_high >= NDADDR) {
1.33      fvdl      290:                error = ufs_getlbns(vp, blk_high, ia, &num);
1.42      chs       291:                if (error) {
                    292:                        splx(s);
1.84      hannken   293:                        goto out;
1.42      chs       294:                }
1.33      fvdl      295:                for (i = 0; i < num; i++) {
1.35      chs       296:                        bp = incore(vp, ia[i].in_lbn);
1.62      dbj       297:                        if (bp != NULL) {
                    298:                                simple_lock(&bp->b_interlock);
                    299:                                if (!(bp->b_flags & B_BUSY) && (bp->b_flags & B_DELWRI)) {
                    300:                                        bp->b_flags |= B_BUSY | B_VFLUSH;
                    301:                                        simple_unlock(&bp->b_interlock);
                    302:                                        splx(s);
                    303:                                        bawrite(bp);
                    304:                                        s = splbio();
                    305:                                } else {
                    306:                                        simple_unlock(&bp->b_interlock);
                    307:                                }
1.33      fvdl      308:                        }
                    309:                }
                    310:        }
                    311:
                    312:        if (ap->a_flags & FSYNC_WAIT) {
1.54      pk        313:                simple_lock(&global_v_numoutput_slock);
1.33      fvdl      314:                while (vp->v_numoutput > 0) {
1.92      ad        315:                        vp->v_iflag |= VI_BWAIT;
1.54      pk        316:                        ltsleep(&vp->v_numoutput, PRIBIO + 1, "fsync_range", 0,
                    317:                                &global_v_numoutput_slock);
1.33      fvdl      318:                }
1.54      pk        319:                simple_unlock(&global_v_numoutput_slock);
1.33      fvdl      320:        }
1.34      fvdl      321:        splx(s);
1.33      fvdl      322:
1.76      yamt      323:        error = ffs_update(vp, NULL, NULL,
1.66      thorpej   324:            ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
1.67      wrstuden  325:            ? UPDATE_WAIT : 0);
                    326:
                    327:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
                    328:                int l = 0;
                    329:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
1.92.4.1! mjf       330:                        curlwp->l_cred);
1.67      wrstuden  331:        }
                    332:
1.84      hannken   333: out:
                    334:        fstrans_done(vp->v_mount);
1.67      wrstuden  335:        return error;
1.33      fvdl      336: }
                    337:
1.20      fvdl      338: /*
                    339:  * Synch an open file.
                    340:  */
                    341: /* ARGSUSED */
1.33      fvdl      342: static int
1.70      thorpej   343: ffs_full_fsync(void *v)
1.20      fvdl      344: {
1.29      mycroft   345:        struct vop_fsync_args /* {
1.20      fvdl      346:                struct vnode *a_vp;
1.80      elad      347:                kauth_cred_t a_cred;
1.20      fvdl      348:                int a_flags;
1.46      chs       349:                off_t a_offlo;
                    350:                off_t a_offhi;
1.77      christos  351:                struct lwp *a_l;
1.20      fvdl      352:        } */ *ap = v;
                    353:        struct vnode *vp = ap->a_vp;
                    354:        struct buf *bp, *nbp;
1.47      fvdl      355:        int s, error, passes, skipmeta, inodedeps_only, waitfor;
1.24      fvdl      356:
1.20      fvdl      357:        if (vp->v_type == VBLK &&
                    358:            vp->v_specmountpoint != NULL &&
                    359:            (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
                    360:                softdep_fsync_mountdev(vp);
1.21      perseant  361:
1.47      fvdl      362:        inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM)
1.89      pooka     363:            && UVM_OBJ_IS_CLEAN(&vp->v_uobj) && LIST_EMPTY(&vp->v_dirtyblkhd);
1.47      fvdl      364:
1.35      chs       365:        /*
                    366:         * Flush all dirty data associated with a vnode.
1.20      fvdl      367:         */
1.35      chs       368:
1.72      yamt      369:        if (vp->v_type == VREG || vp->v_type == VBLK) {
1.46      chs       370:                simple_lock(&vp->v_interlock);
                    371:                error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT |
1.84      hannken   372:                    ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0) |
1.85      hannken   373:                    (fstrans_getstate(vp->v_mount) == FSTRANS_SUSPENDING ?
1.84      hannken   374:                        PGO_FREE : 0));
1.39      chs       375:                if (error) {
                    376:                        return error;
                    377:                }
1.35      chs       378:        }
                    379:
1.20      fvdl      380:        passes = NIADDR + 1;
                    381:        skipmeta = 0;
1.61      kleink    382:        if (ap->a_flags & FSYNC_WAIT)
1.20      fvdl      383:                skipmeta = 1;
                    384:        s = splbio();
1.35      chs       385:
1.20      fvdl      386: loop:
1.35      chs       387:        LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
1.20      fvdl      388:                bp->b_flags &= ~B_SCANNED;
1.29      mycroft   389:        for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
                    390:                nbp = LIST_NEXT(bp, b_vnbufs);
1.63      dbj       391:                simple_lock(&bp->b_interlock);
                    392:                if (bp->b_flags & (B_BUSY | B_SCANNED)) {
                    393:                        simple_unlock(&bp->b_interlock);
1.20      fvdl      394:                        continue;
1.63      dbj       395:                }
1.20      fvdl      396:                if ((bp->b_flags & B_DELWRI) == 0)
                    397:                        panic("ffs_fsync: not dirty");
1.63      dbj       398:                if (skipmeta && bp->b_lblkno < 0) {
                    399:                        simple_unlock(&bp->b_interlock);
1.20      fvdl      400:                        continue;
1.63      dbj       401:                }
                    402:                simple_unlock(&bp->b_interlock);
1.20      fvdl      403:                bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED;
                    404:                splx(s);
                    405:                /*
                    406:                 * On our final pass through, do all I/O synchronously
                    407:                 * so that we can find out if our flush is failing
                    408:                 * because of write errors.
                    409:                 */
                    410:                if (passes > 0 || !(ap->a_flags & FSYNC_WAIT))
                    411:                        (void) bawrite(bp);
                    412:                else if ((error = bwrite(bp)) != 0)
                    413:                        return (error);
                    414:                s = splbio();
                    415:                /*
                    416:                 * Since we may have slept during the I/O, we need
                    417:                 * to start from a known point.
                    418:                 */
1.29      mycroft   419:                nbp = LIST_FIRST(&vp->v_dirtyblkhd);
1.20      fvdl      420:        }
1.61      kleink    421:        if (skipmeta) {
1.20      fvdl      422:                skipmeta = 0;
                    423:                goto loop;
                    424:        }
                    425:        if (ap->a_flags & FSYNC_WAIT) {
1.54      pk        426:                simple_lock(&global_v_numoutput_slock);
1.20      fvdl      427:                while (vp->v_numoutput) {
1.92      ad        428:                        vp->v_iflag |= VI_BWAIT;
1.54      pk        429:                        (void) ltsleep(&vp->v_numoutput, PRIBIO + 1,
                    430:                            "ffsfsync", 0, &global_v_numoutput_slock);
1.20      fvdl      431:                }
1.54      pk        432:                simple_unlock(&global_v_numoutput_slock);
1.29      mycroft   433:                splx(s);
1.20      fvdl      434:
1.69      perry     435:                /*
1.20      fvdl      436:                 * Ensure that any filesystem metadata associated
                    437:                 * with the vnode has been written.
                    438:                 */
1.31      mycroft   439:                if ((error = softdep_sync_metadata(ap)) != 0)
1.20      fvdl      440:                        return (error);
1.29      mycroft   441:
1.20      fvdl      442:                s = splbio();
1.29      mycroft   443:                if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
                    444:                        /*
                    445:                        * Block devices associated with filesystems may
                    446:                        * have new I/O requests posted for them even if
                    447:                        * the vnode is locked, so no amount of trying will
                    448:                        * get them clean. Thus we give block devices a
                    449:                        * good effort, then just give up. For all other file
                    450:                        * types, go around and try again until it is clean.
                    451:                        */
                    452:                        if (passes > 0) {
                    453:                                passes--;
                    454:                                goto loop;
                    455:                        }
1.20      fvdl      456: #ifdef DIAGNOSTIC
1.29      mycroft   457:                        if (vp->v_type != VBLK)
                    458:                                vprint("ffs_fsync: dirty", vp);
1.20      fvdl      459: #endif
1.29      mycroft   460:                }
                    461:        }
                    462:        splx(s);
1.47      fvdl      463:
                    464:        if (inodedeps_only)
                    465:                waitfor = 0;
                    466:        else
                    467:                waitfor = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
1.76      yamt      468:        error = ffs_update(vp, NULL, NULL, waitfor);
1.67      wrstuden  469:
1.68      wrstuden  470:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
1.67      wrstuden  471:                int i = 0;
                    472:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
1.92.4.1! mjf       473:                        curlwp->l_cred);
1.67      wrstuden  474:        }
                    475:
                    476:        return error;
1.20      fvdl      477: }
1.1       mycroft   478:
                    479: /*
                    480:  * Reclaim an inode so that it can be used for other purposes.
                    481:  */
                    482: int
1.70      thorpej   483: ffs_reclaim(void *v)
1.6       christos  484: {
1.1       mycroft   485:        struct vop_reclaim_args /* {
                    486:                struct vnode *a_vp;
1.77      christos  487:                struct lwp *a_l;
1.6       christos  488:        } */ *ap = v;
1.26      augustss  489:        struct vnode *vp = ap->a_vp;
1.56      fvdl      490:        struct inode *ip = VTOI(vp);
1.84      hannken   491:        struct mount *mp = vp->v_mount;
1.56      fvdl      492:        struct ufsmount *ump = ip->i_ump;
1.1       mycroft   493:        int error;
                    494:
1.87      hannken   495:        fstrans_start(mp, FSTRANS_LAZY);
1.92.4.1! mjf       496:        if ((error = ufs_reclaim(vp)) != 0) {
1.84      hannken   497:                fstrans_done(mp);
1.1       mycroft   498:                return (error);
1.84      hannken   499:        }
1.57      fvdl      500:        if (ip->i_din.ffs1_din != NULL) {
                    501:                if (ump->um_fstype == UFS1)
                    502:                        pool_put(&ffs_dinode1_pool, ip->i_din.ffs1_din);
                    503:                else
                    504:                        pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din);
                    505:        }
1.16      thorpej   506:        /*
                    507:         * XXX MFS ends up here, too, to free an inode.  Should we create
                    508:         * XXX a separate pool for MFS inodes?
                    509:         */
1.86      ad        510:        genfs_node_destroy(vp);
1.16      thorpej   511:        pool_put(&ffs_inode_pool, vp->v_data);
1.1       mycroft   512:        vp->v_data = NULL;
1.84      hannken   513:        fstrans_done(mp);
1.1       mycroft   514:        return (0);
1.35      chs       515: }
                    516:
1.88      yamt      517: #if 0
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: }
1.88      yamt      552: #endif
1.49      chs       553:
1.35      chs       554: /*
                    555:  * Return the last logical file offset that should be written for this file
                    556:  * if we're doing a write that ends at "size".
                    557:  */
1.39      chs       558:
                    559: void
1.83      christos  560: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35      chs       561: {
1.39      chs       562:        struct inode *ip = VTOI(vp);
1.35      chs       563:        struct fs *fs = ip->i_fs;
1.52      fvdl      564:        daddr_t olbn, nlbn;
1.55      perseant  565:
1.56      fvdl      566:        olbn = lblkno(fs, ip->i_size);
1.39      chs       567:        nlbn = lblkno(fs, size);
1.35      chs       568:        if (nlbn < NDADDR && olbn <= nlbn) {
1.39      chs       569:                *eobp = fragroundup(fs, size);
1.35      chs       570:        } else {
1.39      chs       571:                *eobp = blkroundup(fs, size);
1.35      chs       572:        }
1.1       mycroft   573: }
1.73      thorpej   574:
                    575: int
                    576: ffs_openextattr(void *v)
                    577: {
                    578:        struct vop_openextattr_args /* {
                    579:                struct vnode *a_vp;
1.80      elad      580:                kauth_cred_t a_cred;
1.73      thorpej   581:                struct proc *a_p;
                    582:        } */ *ap = v;
                    583:        struct inode *ip = VTOI(ap->a_vp);
                    584:        struct fs *fs = ip->i_fs;
                    585:
                    586:        /* Not supported for UFS1 file systems. */
                    587:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    588:                return (EOPNOTSUPP);
                    589:
                    590:        /* XXX Not implemented for UFS2 file systems. */
                    591:        return (EOPNOTSUPP);
                    592: }
                    593:
                    594: int
                    595: ffs_closeextattr(void *v)
                    596: {
                    597:        struct vop_closeextattr_args /* {
                    598:                struct vnode *a_vp;
                    599:                int a_commit;
1.80      elad      600:                kauth_cred_t a_cred;
1.73      thorpej   601:                struct proc *a_p;
                    602:        } */ *ap = v;
                    603:        struct inode *ip = VTOI(ap->a_vp);
                    604:        struct fs *fs = ip->i_fs;
                    605:
                    606:        /* Not supported for UFS1 file systems. */
                    607:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    608:                return (EOPNOTSUPP);
                    609:
                    610:        /* XXX Not implemented for UFS2 file systems. */
                    611:        return (EOPNOTSUPP);
                    612: }
                    613:
                    614: int
                    615: ffs_getextattr(void *v)
                    616: {
                    617:        struct vop_getextattr_args /* {
                    618:                struct vnode *a_vp;
                    619:                int a_attrnamespace;
                    620:                const char *a_name;
                    621:                struct uio *a_uio;
                    622:                size_t *a_size;
1.80      elad      623:                kauth_cred_t a_cred;
1.73      thorpej   624:                struct proc *a_p;
                    625:        } */ *ap = v;
1.84      hannken   626:        struct vnode *vp = ap->a_vp;
                    627:        struct inode *ip = VTOI(vp);
1.73      thorpej   628:        struct fs *fs = ip->i_fs;
                    629:
                    630:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    631: #ifdef UFS_EXTATTR
1.84      hannken   632:                int error;
                    633:
1.87      hannken   634:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   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.84      hannken   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.84      hannken   664:                int error;
                    665:
1.87      hannken   666:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   667:                error = ufs_setextattr(ap);
                    668:                fstrans_done(vp->v_mount);
                    669:                return error;
1.73      thorpej   670: #else
                    671:                return (EOPNOTSUPP);
                    672: #endif
                    673:        }
                    674:
                    675:        /* XXX Not implemented for UFS2 file systems. */
                    676:        return (EOPNOTSUPP);
                    677: }
                    678:
                    679: int
                    680: ffs_listextattr(void *v)
                    681: {
                    682:        struct vop_listextattr_args /* {
                    683:                struct vnode *a_vp;
                    684:                int a_attrnamespace;
                    685:                struct uio *a_uio;
                    686:                size_t *a_size;
1.80      elad      687:                kauth_cred_t a_cred;
1.73      thorpej   688:                struct proc *a_p;
                    689:        } */ *ap = v;
                    690:        struct inode *ip = VTOI(ap->a_vp);
                    691:        struct fs *fs = ip->i_fs;
                    692:
                    693:        /* Not supported for UFS1 file systems. */
                    694:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    695:                return (EOPNOTSUPP);
                    696:
                    697:        /* XXX Not implemented for UFS2 file systems. */
                    698:        return (EOPNOTSUPP);
                    699: }
                    700:
                    701: int
                    702: ffs_deleteextattr(void *v)
                    703: {
                    704:        struct vop_deleteextattr_args /* {
                    705:                struct vnode *a_vp;
                    706:                int a_attrnamespace;
1.80      elad      707:                kauth_cred_t a_cred;
1.73      thorpej   708:                struct proc *a_p;
                    709:        } */ *ap = v;
1.84      hannken   710:        struct vnode *vp = ap->a_vp;
                    711:        struct inode *ip = VTOI(vp);
1.73      thorpej   712:        struct fs *fs = ip->i_fs;
                    713:
                    714:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    715: #ifdef UFS_EXTATTR
1.84      hannken   716:                int error;
                    717:
1.87      hannken   718:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   719:                error = ufs_deleteextattr(ap);
                    720:                fstrans_done(vp->v_mount);
                    721:                return error;
1.73      thorpej   722: #else
                    723:                return (EOPNOTSUPP);
                    724: #endif
                    725:        }
                    726:
                    727:        /* XXX Not implemented for UFS2 file systems. */
                    728:        return (EOPNOTSUPP);
                    729: }
1.90      hannken   730:
                    731: /*
                    732:  * Lock the node.
                    733:  */
                    734: int
                    735: ffs_lock(void *v)
                    736: {
                    737:        struct vop_lock_args /* {
                    738:                struct vnode *a_vp;
                    739:                int a_flags;
                    740:        } */ *ap = v;
                    741:        struct vnode *vp = ap->a_vp;
                    742:        struct mount *mp = vp->v_mount;
1.91      hannken   743:        struct lock *lkp;
                    744:        int flags = ap->a_flags;
                    745:        int result;
1.90      hannken   746:
                    747:        /*
                    748:         * Fake lock during file system suspension.
                    749:         */
                    750:        if ((vp->v_type == VREG || vp->v_type == VDIR) &&
                    751:            fstrans_is_owner(mp) &&
                    752:            fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
1.91      hannken   753:                if ((flags & LK_INTERLOCK) != 0)
1.90      hannken   754:                        simple_unlock(&vp->v_interlock);
                    755:                return 0;
                    756:        }
1.91      hannken   757:
                    758:        if ((flags & LK_TYPE_MASK) == LK_DRAIN)
                    759:                return (lockmgr(vp->v_vnlock, flags, &vp->v_interlock));
                    760:
                    761:        KASSERT((flags & ~(LK_SHARED | LK_EXCLUSIVE | LK_SLEEPFAIL |
                    762:            LK_INTERLOCK | LK_NOWAIT | LK_SETRECURSE | LK_CANRECURSE)) == 0);
                    763:        for (;;) {
                    764:                if ((flags & LK_INTERLOCK) == 0) {
                    765:                        simple_lock(&vp->v_interlock);
                    766:                        flags |= LK_INTERLOCK;
                    767:                }
                    768:                lkp = vp->v_vnlock;
                    769:                result = lockmgr(lkp, flags, &vp->v_interlock);
                    770:                if (lkp == vp->v_vnlock || result != 0)
                    771:                        return result;
                    772:                /*
                    773:                 * Apparent success, except that the vnode mutated between
                    774:                 * snapshot file vnode and regular file vnode while this
                    775:                 * thread slept.  The lock currently held is not the right
                    776:                 * lock.  Release it, and try to get the new lock.
                    777:                 */
                    778:                (void) lockmgr(lkp, LK_RELEASE, NULL);
                    779:                flags &= ~LK_INTERLOCK;
                    780:        }
1.90      hannken   781: }
                    782:
                    783: /*
                    784:  * Unlock the node.
                    785:  */
                    786: int
                    787: ffs_unlock(void *v)
                    788: {
                    789:        struct vop_unlock_args /* {
                    790:                struct vnode *a_vp;
                    791:                int a_flags;
                    792:        } */ *ap = v;
                    793:        struct vnode *vp = ap->a_vp;
                    794:        struct mount *mp = vp->v_mount;
                    795:
                    796:        /*
                    797:         * Fake unlock during file system suspension.
                    798:         */
                    799:        if ((vp->v_type == VREG || vp->v_type == VDIR) &&
                    800:            fstrans_is_owner(mp) &&
                    801:            fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
                    802:                if ((ap->a_flags & LK_INTERLOCK) != 0)
                    803:                        simple_unlock(&vp->v_interlock);
                    804:                return 0;
                    805:        }
                    806:        return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE,
                    807:            &vp->v_interlock));
                    808: }
                    809:
                    810: /*
                    811:  * Return whether or not the node is locked.
                    812:  */
                    813: int
                    814: ffs_islocked(void *v)
                    815: {
                    816:        struct vop_islocked_args /* {
                    817:                struct vnode *a_vp;
                    818:        } */ *ap = v;
                    819:        struct vnode *vp = ap->a_vp;
                    820:
                    821:        return (lockstatus(vp->v_vnlock));
                    822: }

CVSweb <webmaster@jp.NetBSD.org>