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

1.111   ! ad          1: /*     $NetBSD: ffs_vnops.c,v 1.110 2009/02/22 20:10:25 ad Exp $       */
1.100     simonb      2:
                      3: /*-
1.109     ad          4:  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
1.100     simonb      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
1.109     ad          8:  * by Wasabi Systems, Inc, and by Andrew Doran.
1.100     simonb      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     20:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     21:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     22:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     23:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29:  * POSSIBILITY OF SUCH DAMAGE.
                     30:  */
1.3       cgd        31:
1.1       mycroft    32: /*
                     33:  * Copyright (c) 1982, 1986, 1989, 1993
                     34:  *     The Regents of the University of California.  All rights reserved.
                     35:  *
                     36:  * Redistribution and use in source and binary forms, with or without
                     37:  * modification, are permitted provided that the following conditions
                     38:  * are met:
                     39:  * 1. Redistributions of source code must retain the above copyright
                     40:  *    notice, this list of conditions and the following disclaimer.
                     41:  * 2. Redistributions in binary form must reproduce the above copyright
                     42:  *    notice, this list of conditions and the following disclaimer in the
                     43:  *    documentation and/or other materials provided with the distribution.
1.60      agc        44:  * 3. Neither the name of the University nor the names of its contributors
1.1       mycroft    45:  *    may be used to endorse or promote products derived from this software
                     46:  *    without specific prior written permission.
                     47:  *
                     48:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     49:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     50:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     51:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     52:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     53:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     54:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     55:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     56:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     57:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     58:  * SUCH DAMAGE.
                     59:  *
1.12      fvdl       60:  *     @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
1.1       mycroft    61:  */
1.44      lukem      62:
                     63: #include <sys/cdefs.h>
1.111   ! ad         64: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.110 2009/02/22 20:10:25 ad Exp $");
1.100     simonb     65:
                     66: #if defined(_KERNEL_OPT)
                     67: #include "opt_ffs.h"
                     68: #include "opt_wapbl.h"
                     69: #endif
1.11      mrg        70:
1.1       mycroft    71: #include <sys/param.h>
                     72: #include <sys/systm.h>
                     73: #include <sys/resourcevar.h>
                     74: #include <sys/kernel.h>
                     75: #include <sys/file.h>
                     76: #include <sys/stat.h>
                     77: #include <sys/buf.h>
1.50      jdolecek   78: #include <sys/event.h>
1.1       mycroft    79: #include <sys/proc.h>
                     80: #include <sys/mount.h>
                     81: #include <sys/vnode.h>
1.16      thorpej    82: #include <sys/pool.h>
1.6       christos   83: #include <sys/signalvar.h>
1.80      elad       84: #include <sys/kauth.h>
1.100     simonb     85: #include <sys/wapbl.h>
1.84      hannken    86: #include <sys/fstrans.h>
1.1       mycroft    87:
1.8       mycroft    88: #include <miscfs/fifofs/fifo.h>
                     89: #include <miscfs/genfs/genfs.h>
1.1       mycroft    90: #include <miscfs/specfs/specdev.h>
                     91:
                     92: #include <ufs/ufs/inode.h>
                     93: #include <ufs/ufs/dir.h>
                     94: #include <ufs/ufs/ufs_extern.h>
1.2       mycroft    95: #include <ufs/ufs/ufsmount.h>
1.100     simonb     96: #include <ufs/ufs/ufs_wapbl.h>
1.1       mycroft    97:
                     98: #include <ufs/ffs/fs.h>
                     99: #include <ufs/ffs/ffs_extern.h>
                    100:
1.49      chs       101: #include <uvm/uvm.h>
                    102:
1.1       mycroft   103: /* Global vfs data structures for ufs. */
1.74      xtraeme   104: int (**ffs_vnodeop_p)(void *);
1.37      jdolecek  105: const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
1.1       mycroft   106:        { &vop_default_desc, vn_default_error },
                    107:        { &vop_lookup_desc, ufs_lookup },               /* lookup */
                    108:        { &vop_create_desc, ufs_create },               /* create */
1.5       mycroft   109:        { &vop_whiteout_desc, ufs_whiteout },           /* whiteout */
1.1       mycroft   110:        { &vop_mknod_desc, ufs_mknod },                 /* mknod */
                    111:        { &vop_open_desc, ufs_open },                   /* open */
                    112:        { &vop_close_desc, ufs_close },                 /* close */
                    113:        { &vop_access_desc, ufs_access },               /* access */
                    114:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                    115:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                    116:        { &vop_read_desc, ffs_read },                   /* read */
                    117:        { &vop_write_desc, ffs_write },                 /* write */
                    118:        { &vop_ioctl_desc, ufs_ioctl },                 /* ioctl */
1.19      wrstuden  119:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft   120:        { &vop_poll_desc, ufs_poll },                   /* poll */
1.50      jdolecek  121:        { &vop_kqfilter_desc, genfs_kqfilter },         /* kqfilter */
1.12      fvdl      122:        { &vop_revoke_desc, ufs_revoke },               /* revoke */
1.1       mycroft   123:        { &vop_mmap_desc, ufs_mmap },                   /* mmap */
                    124:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                    125:        { &vop_seek_desc, ufs_seek },                   /* seek */
                    126:        { &vop_remove_desc, ufs_remove },               /* remove */
                    127:        { &vop_link_desc, ufs_link },                   /* link */
                    128:        { &vop_rename_desc, ufs_rename },               /* rename */
                    129:        { &vop_mkdir_desc, ufs_mkdir },                 /* mkdir */
                    130:        { &vop_rmdir_desc, ufs_rmdir },                 /* rmdir */
                    131:        { &vop_symlink_desc, ufs_symlink },             /* symlink */
                    132:        { &vop_readdir_desc, ufs_readdir },             /* readdir */
                    133:        { &vop_readlink_desc, ufs_readlink },           /* readlink */
                    134:        { &vop_abortop_desc, ufs_abortop },             /* abortop */
                    135:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    136:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
1.90      hannken   137:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    138:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   139:        { &vop_bmap_desc, ufs_bmap },                   /* bmap */
                    140:        { &vop_strategy_desc, ufs_strategy },           /* strategy */
                    141:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   142:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   143:        { &vop_pathconf_desc, ufs_pathconf },           /* pathconf */
                    144:        { &vop_advlock_desc, ufs_advlock },             /* advlock */
1.8       mycroft   145:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.88      yamt      146:        { &vop_getpages_desc, genfs_getpages },         /* getpages */
1.75      yamt      147:        { &vop_putpages_desc, genfs_putpages },         /* putpages */
1.73      thorpej   148:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    149:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    150:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    151:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    152:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    153:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       154:        { NULL, NULL }
1.1       mycroft   155: };
1.37      jdolecek  156: const struct vnodeopv_desc ffs_vnodeop_opv_desc =
1.1       mycroft   157:        { &ffs_vnodeop_p, ffs_vnodeop_entries };
                    158:
1.74      xtraeme   159: int (**ffs_specop_p)(void *);
1.37      jdolecek  160: const struct vnodeopv_entry_desc ffs_specop_entries[] = {
1.1       mycroft   161:        { &vop_default_desc, vn_default_error },
                    162:        { &vop_lookup_desc, spec_lookup },              /* lookup */
                    163:        { &vop_create_desc, spec_create },              /* create */
                    164:        { &vop_mknod_desc, spec_mknod },                /* mknod */
                    165:        { &vop_open_desc, spec_open },                  /* open */
                    166:        { &vop_close_desc, ufsspec_close },             /* close */
                    167:        { &vop_access_desc, ufs_access },               /* access */
                    168:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                    169:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                    170:        { &vop_read_desc, ufsspec_read },               /* read */
                    171:        { &vop_write_desc, ufsspec_write },             /* write */
                    172:        { &vop_ioctl_desc, spec_ioctl },                /* ioctl */
1.19      wrstuden  173:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft   174:        { &vop_poll_desc, spec_poll },                  /* poll */
1.50      jdolecek  175:        { &vop_kqfilter_desc, spec_kqfilter },          /* kqfilter */
1.12      fvdl      176:        { &vop_revoke_desc, spec_revoke },              /* revoke */
1.1       mycroft   177:        { &vop_mmap_desc, spec_mmap },                  /* mmap */
                    178:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                    179:        { &vop_seek_desc, spec_seek },                  /* seek */
                    180:        { &vop_remove_desc, spec_remove },              /* remove */
                    181:        { &vop_link_desc, spec_link },                  /* link */
                    182:        { &vop_rename_desc, spec_rename },              /* rename */
                    183:        { &vop_mkdir_desc, spec_mkdir },                /* mkdir */
                    184:        { &vop_rmdir_desc, spec_rmdir },                /* rmdir */
                    185:        { &vop_symlink_desc, spec_symlink },            /* symlink */
                    186:        { &vop_readdir_desc, spec_readdir },            /* readdir */
                    187:        { &vop_readlink_desc, spec_readlink },          /* readlink */
                    188:        { &vop_abortop_desc, spec_abortop },            /* abortop */
                    189:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    190:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
1.90      hannken   191:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    192:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   193:        { &vop_bmap_desc, spec_bmap },                  /* bmap */
                    194:        { &vop_strategy_desc, spec_strategy },          /* strategy */
                    195:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   196:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   197:        { &vop_pathconf_desc, spec_pathconf },          /* pathconf */
                    198:        { &vop_advlock_desc, spec_advlock },            /* advlock */
1.8       mycroft   199:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.38      chs       200:        { &vop_getpages_desc, spec_getpages },          /* getpages */
                    201:        { &vop_putpages_desc, spec_putpages },          /* putpages */
1.73      thorpej   202:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    203:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    204:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    205:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    206:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    207:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       208:        { NULL, NULL }
1.1       mycroft   209: };
1.37      jdolecek  210: const struct vnodeopv_desc ffs_specop_opv_desc =
1.1       mycroft   211:        { &ffs_specop_p, ffs_specop_entries };
                    212:
1.74      xtraeme   213: int (**ffs_fifoop_p)(void *);
1.37      jdolecek  214: const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
1.1       mycroft   215:        { &vop_default_desc, vn_default_error },
                    216:        { &vop_lookup_desc, fifo_lookup },              /* lookup */
                    217:        { &vop_create_desc, fifo_create },              /* create */
                    218:        { &vop_mknod_desc, fifo_mknod },                /* mknod */
                    219:        { &vop_open_desc, fifo_open },                  /* open */
                    220:        { &vop_close_desc, ufsfifo_close },             /* close */
                    221:        { &vop_access_desc, ufs_access },               /* access */
                    222:        { &vop_getattr_desc, ufs_getattr },             /* getattr */
                    223:        { &vop_setattr_desc, ufs_setattr },             /* setattr */
                    224:        { &vop_read_desc, ufsfifo_read },               /* read */
                    225:        { &vop_write_desc, ufsfifo_write },             /* write */
                    226:        { &vop_ioctl_desc, fifo_ioctl },                /* ioctl */
1.19      wrstuden  227:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.9       mycroft   228:        { &vop_poll_desc, fifo_poll },                  /* poll */
1.50      jdolecek  229:        { &vop_kqfilter_desc, fifo_kqfilter },          /* kqfilter */
1.12      fvdl      230:        { &vop_revoke_desc, fifo_revoke },              /* revoke */
1.1       mycroft   231:        { &vop_mmap_desc, fifo_mmap },                  /* mmap */
                    232:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
                    233:        { &vop_seek_desc, fifo_seek },                  /* seek */
                    234:        { &vop_remove_desc, fifo_remove },              /* remove */
                    235:        { &vop_link_desc, fifo_link },                  /* link */
                    236:        { &vop_rename_desc, fifo_rename },              /* rename */
                    237:        { &vop_mkdir_desc, fifo_mkdir },                /* mkdir */
                    238:        { &vop_rmdir_desc, fifo_rmdir },                /* rmdir */
                    239:        { &vop_symlink_desc, fifo_symlink },            /* symlink */
                    240:        { &vop_readdir_desc, fifo_readdir },            /* readdir */
                    241:        { &vop_readlink_desc, fifo_readlink },          /* readlink */
                    242:        { &vop_abortop_desc, fifo_abortop },            /* abortop */
                    243:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    244:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
1.90      hannken   245:        { &vop_lock_desc, ffs_lock },                   /* lock */
                    246:        { &vop_unlock_desc, ffs_unlock },               /* unlock */
1.1       mycroft   247:        { &vop_bmap_desc, fifo_bmap },                  /* bmap */
                    248:        { &vop_strategy_desc, fifo_strategy },          /* strategy */
                    249:        { &vop_print_desc, ufs_print },                 /* print */
1.90      hannken   250:        { &vop_islocked_desc, ffs_islocked },           /* islocked */
1.1       mycroft   251:        { &vop_pathconf_desc, fifo_pathconf },          /* pathconf */
                    252:        { &vop_advlock_desc, fifo_advlock },            /* advlock */
1.8       mycroft   253:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.40      sommerfe  254:        { &vop_putpages_desc, fifo_putpages },          /* putpages */
1.73      thorpej   255:        { &vop_openextattr_desc, ffs_openextattr },     /* openextattr */
                    256:        { &vop_closeextattr_desc, ffs_closeextattr },   /* closeextattr */
                    257:        { &vop_getextattr_desc, ffs_getextattr },       /* getextattr */
                    258:        { &vop_setextattr_desc, ffs_setextattr },       /* setextattr */
                    259:        { &vop_listextattr_desc, ffs_listextattr },     /* listextattr */
                    260:        { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
1.35      chs       261:        { NULL, NULL }
1.1       mycroft   262: };
1.37      jdolecek  263: const struct vnodeopv_desc ffs_fifoop_opv_desc =
1.1       mycroft   264:        { &ffs_fifoop_p, ffs_fifoop_entries };
                    265:
                    266: #include <ufs/ufs/ufs_readwrite.c>
1.20      fvdl      267:
1.33      fvdl      268: int
1.70      thorpej   269: ffs_fsync(void *v)
1.33      fvdl      270: {
                    271:        struct vop_fsync_args /* {
                    272:                struct vnode *a_vp;
1.80      elad      273:                kauth_cred_t a_cred;
1.33      fvdl      274:                int a_flags;
1.46      chs       275:                off_t a_offlo;
                    276:                off_t a_offhi;
1.77      christos  277:                struct lwp *a_l;
1.33      fvdl      278:        } */ *ap = v;
1.35      chs       279:        struct buf *bp;
1.94      ad        280:        int num, error, i;
1.33      fvdl      281:        struct indir ia[NIADDR + 1];
                    282:        int bsize;
1.45      simonb    283:        daddr_t blk_high;
1.33      fvdl      284:        struct vnode *vp;
1.100     simonb    285: #ifdef WAPBL
                    286:        struct mount *mp;
                    287: #endif
1.33      fvdl      288:
1.84      hannken   289:        vp = ap->a_vp;
                    290:
1.87      hannken   291:        fstrans_start(vp->v_mount, FSTRANS_LAZY);
1.111   ! ad        292:        if ((ap->a_offlo == 0 && ap->a_offhi == 0) || (vp->v_type != VREG)) {
        !           293:                error = ffs_full_fsync(vp, ap->a_flags);
1.84      hannken   294:                goto out;
                    295:        }
1.33      fvdl      296:
1.84      hannken   297:        bsize = vp->v_mount->mnt_stat.f_iosize;
1.33      fvdl      298:        blk_high = ap->a_offhi / bsize;
                    299:        if (ap->a_offhi % bsize != 0)
                    300:                blk_high++;
                    301:
                    302:        /*
1.35      chs       303:         * First, flush all pages in range.
1.33      fvdl      304:         */
1.35      chs       305:
1.94      ad        306:        mutex_enter(&vp->v_interlock);
1.64      dbj       307:        error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
                    308:            round_page(ap->a_offhi), PGO_CLEANIT |
                    309:            ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
                    310:        if (error) {
1.84      hannken   311:                goto out;
1.39      chs       312:        }
1.33      fvdl      313:
1.100     simonb    314: #ifdef WAPBL
                    315:        mp = wapbl_vptomp(vp);
                    316:        if (mp->mnt_wapbl) {
1.110     ad        317:                /*
                    318:                 * Don't bother writing out metadata if the syncer is
                    319:                 * making the request.  We will let the sync vnode
                    320:                 * write it out in a single burst through a call to
                    321:                 * VFS_SYNC().
                    322:                 */
                    323:                if ((ap->a_flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0) {
1.100     simonb    324:                        fstrans_done(vp->v_mount);
                    325:                        return 0;
                    326:                }
                    327:                error = 0;
                    328:                if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
                    329:                    (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
                    330:                                 IN_MODIFIED | IN_ACCESSED)) {
                    331:                        error = UFS_WAPBL_BEGIN(mp);
                    332:                        if (error) {
                    333:                                fstrans_done(vp->v_mount);
                    334:                                return error;
                    335:                        }
                    336:                        error = ffs_update(vp, NULL, NULL,
                    337:                                (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
                    338:                        UFS_WAPBL_END(mp);
                    339:                }
1.110     ad        340:                if (error || (ap->a_flags & FSYNC_NOLOG) != 0) {
1.100     simonb    341:                        fstrans_done(vp->v_mount);
                    342:                        return error;
                    343:                }
                    344:                error = wapbl_flush(mp->mnt_wapbl, 0);
                    345:                fstrans_done(vp->v_mount);
                    346:                return error;
                    347:        }
                    348: #endif /* WAPBL */
                    349:
1.33      fvdl      350:        /*
1.35      chs       351:         * Then, flush indirect blocks.
1.33      fvdl      352:         */
1.35      chs       353:
1.61      kleink    354:        if (blk_high >= NDADDR) {
1.33      fvdl      355:                error = ufs_getlbns(vp, blk_high, ia, &num);
1.94      ad        356:                if (error)
1.84      hannken   357:                        goto out;
1.94      ad        358:
                    359:                mutex_enter(&bufcache_lock);
1.33      fvdl      360:                for (i = 0; i < num; i++) {
1.94      ad        361:                        if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
                    362:                                continue;
                    363:                        if ((bp->b_cflags & BC_BUSY) != 0 ||
                    364:                            (bp->b_oflags & BO_DELWRI) == 0)
                    365:                                continue;
                    366:                        bp->b_cflags |= BC_BUSY | BC_VFLUSH;
                    367:                        mutex_exit(&bufcache_lock);
                    368:                        bawrite(bp);
                    369:                        mutex_enter(&bufcache_lock);
1.33      fvdl      370:                }
1.94      ad        371:                mutex_exit(&bufcache_lock);
1.33      fvdl      372:        }
                    373:
                    374:        if (ap->a_flags & FSYNC_WAIT) {
1.94      ad        375:                mutex_enter(&vp->v_interlock);
                    376:                while (vp->v_numoutput > 0)
                    377:                        cv_wait(&vp->v_cv, &vp->v_interlock);
                    378:                mutex_exit(&vp->v_interlock);
1.33      fvdl      379:        }
                    380:
1.76      yamt      381:        error = ffs_update(vp, NULL, NULL,
1.66      thorpej   382:            ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
1.67      wrstuden  383:            ? UPDATE_WAIT : 0);
                    384:
                    385:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
                    386:                int l = 0;
                    387:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
1.93      pooka     388:                        curlwp->l_cred);
1.67      wrstuden  389:        }
                    390:
1.84      hannken   391: out:
                    392:        fstrans_done(vp->v_mount);
1.67      wrstuden  393:        return error;
1.33      fvdl      394: }
                    395:
1.20      fvdl      396: /*
1.110     ad        397:  * Synch an open file.  Called for VOP_FSYNC().
1.20      fvdl      398:  */
                    399: /* ARGSUSED */
1.94      ad        400: int
                    401: ffs_full_fsync(struct vnode *vp, int flags)
1.20      fvdl      402: {
                    403:        struct buf *bp, *nbp;
1.111   ! ad        404:        int error, passes, skipmeta, waitfor, i;
1.99      ad        405:        struct mount *mp;
                    406:
1.110     ad        407:        KASSERT(VTOI(vp) != NULL);
                    408:        KASSERT(vp->v_tag == VT_UFS);
                    409:
1.99      ad        410:        error = 0;
1.24      fvdl      411:
1.110     ad        412:        mp = vp->v_mount;
                    413:        if (vp->v_type == VBLK && vp->v_specmountpoint != NULL) {
1.105     ad        414:                mp = vp->v_specmountpoint;
                    415:        } else {
                    416:                mp = vp->v_mount;
                    417:        }
                    418:
1.35      chs       419:        /*
1.110     ad        420:         * Flush all dirty data associated with the vnode.
1.20      fvdl      421:         */
1.72      yamt      422:        if (vp->v_type == VREG || vp->v_type == VBLK) {
1.101     oster     423:                int pflags = PGO_ALLPAGES | PGO_CLEANIT;
                    424:
                    425:                if ((flags & FSYNC_WAIT))
                    426:                        pflags |= PGO_SYNCIO;
                    427:                if (vp->v_type == VREG &&
                    428:                    fstrans_getstate(mp) == FSTRANS_SUSPENDING)
                    429:                        pflags |= PGO_FREE;
1.111   ! ad        430:                mutex_enter(&vp->v_interlock);
1.101     oster     431:                error = VOP_PUTPAGES(vp, 0, 0, pflags);
1.99      ad        432:                if (error)
1.39      chs       433:                        return error;
1.100     simonb    434:        }
                    435:
                    436: #ifdef WAPBL
1.111   ! ad        437:        mp = wapbl_vptomp(vp);
1.100     simonb    438:        if (mp && mp->mnt_wapbl) {
1.110     ad        439:                /*
                    440:                 * Don't bother writing out metadata if the syncer is
                    441:                 * making the request.  We will let the sync vnode
                    442:                 * write it out in a single burst through a call to
                    443:                 * VFS_SYNC().
                    444:                 */
                    445:                if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
                    446:                        return 0;
1.100     simonb    447:
1.110     ad        448:                if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
1.109     ad        449:                    | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
1.100     simonb    450:                        error = UFS_WAPBL_BEGIN(mp);
                    451:                        if (error)
                    452:                                return error;
                    453:                        error = ffs_update(vp, NULL, NULL,
1.110     ad        454:                            (flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
1.100     simonb    455:                        UFS_WAPBL_END(mp);
                    456:                }
1.110     ad        457:                if (error || (flags & FSYNC_NOLOG) != 0)
1.100     simonb    458:                        return error;
1.106     ad        459:
1.100     simonb    460:                /*
                    461:                 * Don't flush the log if the vnode being flushed
                    462:                 * contains no dirty buffers that could be in the log.
                    463:                 */
1.109     ad        464:                if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
1.100     simonb    465:                        error = wapbl_flush(mp->mnt_wapbl, 0);
                    466:                        if (error)
                    467:                                return error;
                    468:                }
                    469:
1.109     ad        470:                if ((flags & FSYNC_WAIT) != 0) {
1.100     simonb    471:                        mutex_enter(&vp->v_interlock);
1.110     ad        472:                        while (vp->v_numoutput != 0)
1.100     simonb    473:                                cv_wait(&vp->v_cv, &vp->v_interlock);
                    474:                        mutex_exit(&vp->v_interlock);
                    475:                }
                    476:
                    477:                return error;
                    478:        }
                    479: #endif /* WAPBL */
1.35      chs       480:
1.110     ad        481:        /*
1.111   ! ad        482:         * Write out metadata for non-logging file systems. XXX This block
        !           483:         * should be simplified now that softdep is gone.
1.110     ad        484:         */
1.20      fvdl      485:        passes = NIADDR + 1;
                    486:        skipmeta = 0;
1.94      ad        487:        if (flags & FSYNC_WAIT)
1.20      fvdl      488:                skipmeta = 1;
1.35      chs       489:
1.20      fvdl      490: loop:
1.94      ad        491:        mutex_enter(&bufcache_lock);
                    492:        LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
                    493:                bp->b_cflags &= ~BC_SCANNED;
                    494:        }
1.29      mycroft   495:        for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
                    496:                nbp = LIST_NEXT(bp, b_vnbufs);
1.94      ad        497:                if (bp->b_cflags & (BC_BUSY | BC_SCANNED))
1.20      fvdl      498:                        continue;
1.94      ad        499:                if ((bp->b_oflags & BO_DELWRI) == 0)
1.20      fvdl      500:                        panic("ffs_fsync: not dirty");
1.94      ad        501:                if (skipmeta && bp->b_lblkno < 0)
1.20      fvdl      502:                        continue;
1.94      ad        503:                bp->b_cflags |= BC_BUSY | BC_VFLUSH | BC_SCANNED;
                    504:                mutex_exit(&bufcache_lock);
1.20      fvdl      505:                /*
                    506:                 * On our final pass through, do all I/O synchronously
                    507:                 * so that we can find out if our flush is failing
                    508:                 * because of write errors.
                    509:                 */
1.94      ad        510:                if (passes > 0 || !(flags & FSYNC_WAIT))
1.20      fvdl      511:                        (void) bawrite(bp);
                    512:                else if ((error = bwrite(bp)) != 0)
                    513:                        return (error);
                    514:                /*
1.94      ad        515:                 * Since we unlocked during the I/O, we need
1.20      fvdl      516:                 * to start from a known point.
                    517:                 */
1.94      ad        518:                mutex_enter(&bufcache_lock);
1.29      mycroft   519:                nbp = LIST_FIRST(&vp->v_dirtyblkhd);
1.20      fvdl      520:        }
1.94      ad        521:        mutex_exit(&bufcache_lock);
1.61      kleink    522:        if (skipmeta) {
1.20      fvdl      523:                skipmeta = 0;
                    524:                goto loop;
                    525:        }
1.94      ad        526:
1.109     ad        527:        if ((flags & FSYNC_WAIT) != 0) {
1.94      ad        528:                mutex_enter(&vp->v_interlock);
1.20      fvdl      529:                while (vp->v_numoutput) {
1.94      ad        530:                        cv_wait(&vp->v_cv, &vp->v_interlock);
1.20      fvdl      531:                }
1.94      ad        532:                mutex_exit(&vp->v_interlock);
1.20      fvdl      533:
1.69      perry     534:                /*
1.20      fvdl      535:                 * Ensure that any filesystem metadata associated
                    536:                 * with the vnode has been written.
                    537:                 */
1.29      mycroft   538:                if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
                    539:                        /*
                    540:                        * Block devices associated with filesystems may
                    541:                        * have new I/O requests posted for them even if
                    542:                        * the vnode is locked, so no amount of trying will
                    543:                        * get them clean. Thus we give block devices a
                    544:                        * good effort, then just give up. For all other file
                    545:                        * types, go around and try again until it is clean.
                    546:                        */
                    547:                        if (passes > 0) {
                    548:                                passes--;
                    549:                                goto loop;
                    550:                        }
1.20      fvdl      551: #ifdef DIAGNOSTIC
1.29      mycroft   552:                        if (vp->v_type != VBLK)
                    553:                                vprint("ffs_fsync: dirty", vp);
1.20      fvdl      554: #endif
1.29      mycroft   555:                }
                    556:        }
1.47      fvdl      557:
1.111   ! ad        558:        waitfor = (flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
1.110     ad        559:        error = ffs_update(vp, NULL, NULL, waitfor);
1.67      wrstuden  560:
1.109     ad        561:        if (error == 0 && (flags & FSYNC_CACHE) != 0) {
1.110     ad        562:                (void)VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
                    563:                    kauth_cred_get());
1.67      wrstuden  564:        }
                    565:
                    566:        return error;
1.20      fvdl      567: }
1.1       mycroft   568:
                    569: /*
                    570:  * Reclaim an inode so that it can be used for other purposes.
                    571:  */
                    572: int
1.70      thorpej   573: ffs_reclaim(void *v)
1.6       christos  574: {
1.1       mycroft   575:        struct vop_reclaim_args /* {
                    576:                struct vnode *a_vp;
1.77      christos  577:                struct lwp *a_l;
1.6       christos  578:        } */ *ap = v;
1.26      augustss  579:        struct vnode *vp = ap->a_vp;
1.56      fvdl      580:        struct inode *ip = VTOI(vp);
1.84      hannken   581:        struct mount *mp = vp->v_mount;
1.56      fvdl      582:        struct ufsmount *ump = ip->i_ump;
1.94      ad        583:        void *data;
1.1       mycroft   584:        int error;
                    585:
1.87      hannken   586:        fstrans_start(mp, FSTRANS_LAZY);
1.93      pooka     587:        if ((error = ufs_reclaim(vp)) != 0) {
1.84      hannken   588:                fstrans_done(mp);
1.1       mycroft   589:                return (error);
1.84      hannken   590:        }
1.57      fvdl      591:        if (ip->i_din.ffs1_din != NULL) {
                    592:                if (ump->um_fstype == UFS1)
1.95      ad        593:                        pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
1.57      fvdl      594:                else
1.95      ad        595:                        pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
1.57      fvdl      596:        }
1.16      thorpej   597:        /*
1.94      ad        598:         * To interlock with ffs_sync().
                    599:         */
                    600:        genfs_node_destroy(vp);
                    601:        mutex_enter(&vp->v_interlock);
                    602:        data = vp->v_data;
                    603:        vp->v_data = NULL;
                    604:        mutex_exit(&vp->v_interlock);
                    605:
                    606:        /*
1.16      thorpej   607:         * XXX MFS ends up here, too, to free an inode.  Should we create
                    608:         * XXX a separate pool for MFS inodes?
                    609:         */
1.95      ad        610:        pool_cache_put(ffs_inode_cache, data);
1.84      hannken   611:        fstrans_done(mp);
1.1       mycroft   612:        return (0);
1.35      chs       613: }
                    614:
                    615: /*
                    616:  * Return the last logical file offset that should be written for this file
                    617:  * if we're doing a write that ends at "size".
                    618:  */
1.39      chs       619:
                    620: void
1.83      christos  621: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35      chs       622: {
1.39      chs       623:        struct inode *ip = VTOI(vp);
1.35      chs       624:        struct fs *fs = ip->i_fs;
1.52      fvdl      625:        daddr_t olbn, nlbn;
1.55      perseant  626:
1.56      fvdl      627:        olbn = lblkno(fs, ip->i_size);
1.39      chs       628:        nlbn = lblkno(fs, size);
1.35      chs       629:        if (nlbn < NDADDR && olbn <= nlbn) {
1.39      chs       630:                *eobp = fragroundup(fs, size);
1.35      chs       631:        } else {
1.39      chs       632:                *eobp = blkroundup(fs, size);
1.35      chs       633:        }
1.1       mycroft   634: }
1.73      thorpej   635:
                    636: int
                    637: ffs_openextattr(void *v)
                    638: {
                    639:        struct vop_openextattr_args /* {
                    640:                struct vnode *a_vp;
1.80      elad      641:                kauth_cred_t a_cred;
1.73      thorpej   642:                struct proc *a_p;
                    643:        } */ *ap = v;
                    644:        struct inode *ip = VTOI(ap->a_vp);
                    645:        struct fs *fs = ip->i_fs;
                    646:
                    647:        /* Not supported for UFS1 file systems. */
                    648:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    649:                return (EOPNOTSUPP);
                    650:
                    651:        /* XXX Not implemented for UFS2 file systems. */
                    652:        return (EOPNOTSUPP);
                    653: }
                    654:
                    655: int
                    656: ffs_closeextattr(void *v)
                    657: {
                    658:        struct vop_closeextattr_args /* {
                    659:                struct vnode *a_vp;
                    660:                int a_commit;
1.80      elad      661:                kauth_cred_t a_cred;
1.73      thorpej   662:                struct proc *a_p;
                    663:        } */ *ap = v;
                    664:        struct inode *ip = VTOI(ap->a_vp);
                    665:        struct fs *fs = ip->i_fs;
                    666:
                    667:        /* Not supported for UFS1 file systems. */
                    668:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    669:                return (EOPNOTSUPP);
                    670:
                    671:        /* XXX Not implemented for UFS2 file systems. */
                    672:        return (EOPNOTSUPP);
                    673: }
                    674:
                    675: int
                    676: ffs_getextattr(void *v)
                    677: {
                    678:        struct vop_getextattr_args /* {
                    679:                struct vnode *a_vp;
                    680:                int a_attrnamespace;
                    681:                const char *a_name;
                    682:                struct uio *a_uio;
                    683:                size_t *a_size;
1.80      elad      684:                kauth_cred_t a_cred;
1.73      thorpej   685:                struct proc *a_p;
                    686:        } */ *ap = v;
1.84      hannken   687:        struct vnode *vp = ap->a_vp;
                    688:        struct inode *ip = VTOI(vp);
1.73      thorpej   689:        struct fs *fs = ip->i_fs;
                    690:
                    691:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    692: #ifdef UFS_EXTATTR
1.84      hannken   693:                int error;
                    694:
1.87      hannken   695:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   696:                error = ufs_getextattr(ap);
                    697:                fstrans_done(vp->v_mount);
                    698:                return error;
1.73      thorpej   699: #else
                    700:                return (EOPNOTSUPP);
                    701: #endif
                    702:        }
                    703:
                    704:        /* XXX Not implemented for UFS2 file systems. */
                    705:        return (EOPNOTSUPP);
                    706: }
                    707:
                    708: int
                    709: ffs_setextattr(void *v)
                    710: {
                    711:        struct vop_setextattr_args /* {
                    712:                struct vnode *a_vp;
                    713:                int a_attrnamespace;
                    714:                const char *a_name;
                    715:                struct uio *a_uio;
1.80      elad      716:                kauth_cred_t a_cred;
1.73      thorpej   717:                struct proc *a_p;
                    718:        } */ *ap = v;
1.84      hannken   719:        struct vnode *vp = ap->a_vp;
                    720:        struct inode *ip = VTOI(vp);
1.73      thorpej   721:        struct fs *fs = ip->i_fs;
                    722:
                    723:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    724: #ifdef UFS_EXTATTR
1.84      hannken   725:                int error;
                    726:
1.87      hannken   727:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   728:                error = ufs_setextattr(ap);
                    729:                fstrans_done(vp->v_mount);
                    730:                return error;
1.73      thorpej   731: #else
                    732:                return (EOPNOTSUPP);
                    733: #endif
                    734:        }
                    735:
                    736:        /* XXX Not implemented for UFS2 file systems. */
                    737:        return (EOPNOTSUPP);
                    738: }
                    739:
                    740: int
                    741: ffs_listextattr(void *v)
                    742: {
                    743:        struct vop_listextattr_args /* {
                    744:                struct vnode *a_vp;
                    745:                int a_attrnamespace;
                    746:                struct uio *a_uio;
                    747:                size_t *a_size;
1.80      elad      748:                kauth_cred_t a_cred;
1.73      thorpej   749:                struct proc *a_p;
                    750:        } */ *ap = v;
                    751:        struct inode *ip = VTOI(ap->a_vp);
                    752:        struct fs *fs = ip->i_fs;
                    753:
                    754:        /* Not supported for UFS1 file systems. */
                    755:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    756:                return (EOPNOTSUPP);
                    757:
                    758:        /* XXX Not implemented for UFS2 file systems. */
                    759:        return (EOPNOTSUPP);
                    760: }
                    761:
                    762: int
                    763: ffs_deleteextattr(void *v)
                    764: {
                    765:        struct vop_deleteextattr_args /* {
                    766:                struct vnode *a_vp;
                    767:                int a_attrnamespace;
1.80      elad      768:                kauth_cred_t a_cred;
1.73      thorpej   769:                struct proc *a_p;
                    770:        } */ *ap = v;
1.84      hannken   771:        struct vnode *vp = ap->a_vp;
                    772:        struct inode *ip = VTOI(vp);
1.73      thorpej   773:        struct fs *fs = ip->i_fs;
                    774:
                    775:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    776: #ifdef UFS_EXTATTR
1.84      hannken   777:                int error;
                    778:
1.87      hannken   779:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   780:                error = ufs_deleteextattr(ap);
                    781:                fstrans_done(vp->v_mount);
                    782:                return error;
1.73      thorpej   783: #else
                    784:                return (EOPNOTSUPP);
                    785: #endif
                    786:        }
                    787:
                    788:        /* XXX Not implemented for UFS2 file systems. */
                    789:        return (EOPNOTSUPP);
                    790: }
1.90      hannken   791:
                    792: /*
                    793:  * Lock the node.
                    794:  */
                    795: int
                    796: ffs_lock(void *v)
                    797: {
                    798:        struct vop_lock_args /* {
                    799:                struct vnode *a_vp;
                    800:                int a_flags;
                    801:        } */ *ap = v;
                    802:        struct vnode *vp = ap->a_vp;
                    803:        struct mount *mp = vp->v_mount;
1.91      hannken   804:        int flags = ap->a_flags;
1.90      hannken   805:
1.98      ad        806:        if ((flags & LK_INTERLOCK) != 0) {
                    807:                mutex_exit(&vp->v_interlock);
                    808:                flags &= ~LK_INTERLOCK;
                    809:        }
                    810:
1.90      hannken   811:        /*
                    812:         * Fake lock during file system suspension.
                    813:         */
                    814:        if ((vp->v_type == VREG || vp->v_type == VDIR) &&
                    815:            fstrans_is_owner(mp) &&
                    816:            fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
                    817:                return 0;
                    818:        }
1.91      hannken   819:
1.102     hannken   820:        return (vlockmgr(vp->v_vnlock, flags));
1.90      hannken   821: }
                    822:
                    823: /*
                    824:  * Unlock the node.
                    825:  */
                    826: int
                    827: ffs_unlock(void *v)
                    828: {
                    829:        struct vop_unlock_args /* {
                    830:                struct vnode *a_vp;
                    831:                int a_flags;
                    832:        } */ *ap = v;
                    833:        struct vnode *vp = ap->a_vp;
                    834:        struct mount *mp = vp->v_mount;
                    835:
1.98      ad        836:        KASSERT(ap->a_flags == 0);
                    837:
1.90      hannken   838:        /*
                    839:         * Fake unlock during file system suspension.
                    840:         */
                    841:        if ((vp->v_type == VREG || vp->v_type == VDIR) &&
                    842:            fstrans_is_owner(mp) &&
                    843:            fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
                    844:                return 0;
                    845:        }
1.98      ad        846:        return (vlockmgr(vp->v_vnlock, LK_RELEASE));
1.90      hannken   847: }
                    848:
                    849: /*
                    850:  * Return whether or not the node is locked.
                    851:  */
                    852: int
                    853: ffs_islocked(void *v)
                    854: {
                    855:        struct vop_islocked_args /* {
                    856:                struct vnode *a_vp;
                    857:        } */ *ap = v;
                    858:        struct vnode *vp = ap->a_vp;
                    859:
1.98      ad        860:        return (vlockstatus(vp->v_vnlock));
1.90      hannken   861: }

CVSweb <webmaster@jp.NetBSD.org>