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

1.120   ! manu        1: /*     $NetBSD: ffs_vnops.c,v 1.119 2011/06/12 03:36:00 rmind 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.120   ! manu       64: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.119 2011/06/12 03:36:00 rmind 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.113     hannken   137:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    138:        { &vop_unlock_desc, ufs_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.113     hannken   142:        { &vop_islocked_desc, ufs_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 */
1.118     hannken   178:        { &vop_fsync_desc, ffs_spec_fsync },            /* fsync */
1.1       mycroft   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.113     hannken   191:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    192:        { &vop_unlock_desc, ufs_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.113     hannken   196:        { &vop_islocked_desc, ufs_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 },
1.114     pooka     216:        { &vop_lookup_desc, vn_fifo_bypass },           /* lookup */
                    217:        { &vop_create_desc, vn_fifo_bypass },           /* create */
                    218:        { &vop_mknod_desc, vn_fifo_bypass },            /* mknod */
                    219:        { &vop_open_desc, vn_fifo_bypass },             /* open */
1.1       mycroft   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 */
1.114     pooka     226:        { &vop_ioctl_desc, vn_fifo_bypass },            /* ioctl */
1.19      wrstuden  227:        { &vop_fcntl_desc, ufs_fcntl },                 /* fcntl */
1.114     pooka     228:        { &vop_poll_desc, vn_fifo_bypass },             /* poll */
                    229:        { &vop_kqfilter_desc, vn_fifo_bypass },         /* kqfilter */
                    230:        { &vop_revoke_desc, vn_fifo_bypass },           /* revoke */
                    231:        { &vop_mmap_desc, vn_fifo_bypass },             /* mmap */
1.1       mycroft   232:        { &vop_fsync_desc, ffs_fsync },                 /* fsync */
1.114     pooka     233:        { &vop_seek_desc, vn_fifo_bypass },             /* seek */
                    234:        { &vop_remove_desc, vn_fifo_bypass },           /* remove */
                    235:        { &vop_link_desc, vn_fifo_bypass },             /* link */
                    236:        { &vop_rename_desc, vn_fifo_bypass },           /* rename */
                    237:        { &vop_mkdir_desc, vn_fifo_bypass },            /* mkdir */
                    238:        { &vop_rmdir_desc, vn_fifo_bypass },            /* rmdir */
                    239:        { &vop_symlink_desc, vn_fifo_bypass },          /* symlink */
                    240:        { &vop_readdir_desc, vn_fifo_bypass },          /* readdir */
                    241:        { &vop_readlink_desc, vn_fifo_bypass },         /* readlink */
                    242:        { &vop_abortop_desc, vn_fifo_bypass },          /* abortop */
1.1       mycroft   243:        { &vop_inactive_desc, ufs_inactive },           /* inactive */
                    244:        { &vop_reclaim_desc, ffs_reclaim },             /* reclaim */
1.113     hannken   245:        { &vop_lock_desc, ufs_lock },                   /* lock */
                    246:        { &vop_unlock_desc, ufs_unlock },               /* unlock */
1.114     pooka     247:        { &vop_bmap_desc, vn_fifo_bypass },             /* bmap */
                    248:        { &vop_strategy_desc, vn_fifo_bypass },         /* strategy */
1.1       mycroft   249:        { &vop_print_desc, ufs_print },                 /* print */
1.113     hannken   250:        { &vop_islocked_desc, ufs_islocked },           /* islocked */
1.114     pooka     251:        { &vop_pathconf_desc, vn_fifo_bypass },         /* pathconf */
                    252:        { &vop_advlock_desc, vn_fifo_bypass },          /* advlock */
1.8       mycroft   253:        { &vop_bwrite_desc, vn_bwrite },                /* bwrite */
1.114     pooka     254:        { &vop_putpages_desc, vn_fifo_bypass },         /* 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.118     hannken   269: ffs_spec_fsync(void *v)
                    270: {
                    271:        struct vop_fsync_args /* {
                    272:                struct vnode *a_vp;
                    273:                kauth_cred_t a_cred;
                    274:                int a_flags;
                    275:                off_t a_offlo;
                    276:                off_t a_offhi;
                    277:                struct lwp *a_l;
                    278:        } */ *ap = v;
                    279:        int error, flags, uflags;
                    280:        struct vnode *vp;
                    281:        struct mount *mp;
                    282:
                    283:        flags = ap->a_flags;
                    284:        uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
                    285:        vp = ap->a_vp;
                    286:        mp = vp->v_mount;
                    287:
                    288:        fstrans_start(mp, FSTRANS_LAZY);
                    289:
                    290:        error = spec_fsync(v);
                    291:        if (error)
                    292:                goto out;
                    293:
                    294: #ifdef WAPBL
                    295:        if (mp && mp->mnt_wapbl) {
                    296:                /*
                    297:                 * Don't bother writing out metadata if the syncer is
                    298:                 * making the request.  We will let the sync vnode
                    299:                 * write it out in a single burst through a call to
                    300:                 * VFS_SYNC().
                    301:                 */
                    302:                if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
                    303:                        goto out;
                    304:                if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
                    305:                    | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
                    306:                        error = UFS_WAPBL_BEGIN(mp);
                    307:                        if (error != 0)
                    308:                                goto out;
                    309:                        error = ffs_update(vp, NULL, NULL, uflags);
                    310:                        UFS_WAPBL_END(mp);
                    311:                }
                    312:                goto out;
                    313:        }
                    314: #endif /* WAPBL */
                    315:
                    316:        error = ffs_update(vp, NULL, NULL, uflags);
                    317:
                    318: out:
                    319:        fstrans_done(mp);
                    320:        return error;
                    321: }
                    322:
                    323: int
1.70      thorpej   324: ffs_fsync(void *v)
1.33      fvdl      325: {
                    326:        struct vop_fsync_args /* {
                    327:                struct vnode *a_vp;
1.80      elad      328:                kauth_cred_t a_cred;
1.33      fvdl      329:                int a_flags;
1.46      chs       330:                off_t a_offlo;
                    331:                off_t a_offhi;
1.77      christos  332:                struct lwp *a_l;
1.33      fvdl      333:        } */ *ap = v;
1.35      chs       334:        struct buf *bp;
1.94      ad        335:        int num, error, i;
1.33      fvdl      336:        struct indir ia[NIADDR + 1];
                    337:        int bsize;
1.45      simonb    338:        daddr_t blk_high;
1.33      fvdl      339:        struct vnode *vp;
1.100     simonb    340:        struct mount *mp;
1.33      fvdl      341:
1.84      hannken   342:        vp = ap->a_vp;
1.117     hannken   343:        mp = vp->v_mount;
1.84      hannken   344:
1.117     hannken   345:        fstrans_start(mp, FSTRANS_LAZY);
1.111     ad        346:        if ((ap->a_offlo == 0 && ap->a_offhi == 0) || (vp->v_type != VREG)) {
                    347:                error = ffs_full_fsync(vp, ap->a_flags);
1.84      hannken   348:                goto out;
                    349:        }
1.33      fvdl      350:
1.117     hannken   351:        bsize = mp->mnt_stat.f_iosize;
1.33      fvdl      352:        blk_high = ap->a_offhi / bsize;
                    353:        if (ap->a_offhi % bsize != 0)
                    354:                blk_high++;
                    355:
                    356:        /*
1.35      chs       357:         * First, flush all pages in range.
1.33      fvdl      358:         */
1.35      chs       359:
1.119     rmind     360:        mutex_enter(vp->v_interlock);
1.64      dbj       361:        error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
                    362:            round_page(ap->a_offhi), PGO_CLEANIT |
                    363:            ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
                    364:        if (error) {
1.84      hannken   365:                goto out;
1.39      chs       366:        }
1.33      fvdl      367:
1.100     simonb    368: #ifdef WAPBL
1.117     hannken   369:        KASSERT(vp->v_type == VREG);
1.100     simonb    370:        if (mp->mnt_wapbl) {
1.110     ad        371:                /*
                    372:                 * Don't bother writing out metadata if the syncer is
                    373:                 * making the request.  We will let the sync vnode
                    374:                 * write it out in a single burst through a call to
                    375:                 * VFS_SYNC().
                    376:                 */
                    377:                if ((ap->a_flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0) {
1.117     hannken   378:                        fstrans_done(mp);
1.100     simonb    379:                        return 0;
                    380:                }
                    381:                error = 0;
                    382:                if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
                    383:                    (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
                    384:                                 IN_MODIFIED | IN_ACCESSED)) {
                    385:                        error = UFS_WAPBL_BEGIN(mp);
                    386:                        if (error) {
1.117     hannken   387:                                fstrans_done(mp);
1.100     simonb    388:                                return error;
                    389:                        }
1.112     ad        390:                        error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
                    391:                            ((ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0));
1.100     simonb    392:                        UFS_WAPBL_END(mp);
                    393:                }
1.110     ad        394:                if (error || (ap->a_flags & FSYNC_NOLOG) != 0) {
1.117     hannken   395:                        fstrans_done(mp);
1.100     simonb    396:                        return error;
                    397:                }
                    398:                error = wapbl_flush(mp->mnt_wapbl, 0);
1.117     hannken   399:                fstrans_done(mp);
1.100     simonb    400:                return error;
                    401:        }
                    402: #endif /* WAPBL */
                    403:
1.33      fvdl      404:        /*
1.35      chs       405:         * Then, flush indirect blocks.
1.33      fvdl      406:         */
1.35      chs       407:
1.61      kleink    408:        if (blk_high >= NDADDR) {
1.33      fvdl      409:                error = ufs_getlbns(vp, blk_high, ia, &num);
1.94      ad        410:                if (error)
1.84      hannken   411:                        goto out;
1.94      ad        412:
                    413:                mutex_enter(&bufcache_lock);
1.33      fvdl      414:                for (i = 0; i < num; i++) {
1.94      ad        415:                        if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
                    416:                                continue;
                    417:                        if ((bp->b_cflags & BC_BUSY) != 0 ||
                    418:                            (bp->b_oflags & BO_DELWRI) == 0)
                    419:                                continue;
                    420:                        bp->b_cflags |= BC_BUSY | BC_VFLUSH;
                    421:                        mutex_exit(&bufcache_lock);
                    422:                        bawrite(bp);
                    423:                        mutex_enter(&bufcache_lock);
1.33      fvdl      424:                }
1.94      ad        425:                mutex_exit(&bufcache_lock);
1.33      fvdl      426:        }
                    427:
                    428:        if (ap->a_flags & FSYNC_WAIT) {
1.119     rmind     429:                mutex_enter(vp->v_interlock);
1.94      ad        430:                while (vp->v_numoutput > 0)
1.119     rmind     431:                        cv_wait(&vp->v_cv, vp->v_interlock);
                    432:                mutex_exit(vp->v_interlock);
1.33      fvdl      433:        }
                    434:
1.112     ad        435:        error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
                    436:            (((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
                    437:            ? UPDATE_WAIT : 0));
1.67      wrstuden  438:
                    439:        if (error == 0 && ap->a_flags & FSYNC_CACHE) {
                    440:                int l = 0;
                    441:                VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
1.93      pooka     442:                        curlwp->l_cred);
1.67      wrstuden  443:        }
                    444:
1.84      hannken   445: out:
1.117     hannken   446:        fstrans_done(mp);
1.67      wrstuden  447:        return error;
1.33      fvdl      448: }
                    449:
1.20      fvdl      450: /*
1.110     ad        451:  * Synch an open file.  Called for VOP_FSYNC().
1.20      fvdl      452:  */
                    453: /* ARGSUSED */
1.94      ad        454: int
                    455: ffs_full_fsync(struct vnode *vp, int flags)
1.20      fvdl      456: {
1.118     hannken   457:        int error, i, uflags;
1.99      ad        458:        struct mount *mp;
                    459:
1.118     hannken   460:        KASSERT(vp->v_tag == VT_UFS);
1.110     ad        461:        KASSERT(VTOI(vp) != NULL);
1.118     hannken   462:        KASSERT(vp->v_type != VCHR && vp->v_type != VBLK);
1.110     ad        463:
1.99      ad        464:        error = 0;
1.118     hannken   465:        uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
1.24      fvdl      466:
1.110     ad        467:        mp = vp->v_mount;
1.105     ad        468:
1.35      chs       469:        /*
1.110     ad        470:         * Flush all dirty data associated with the vnode.
1.20      fvdl      471:         */
1.118     hannken   472:        if (vp->v_type == VREG) {
1.101     oster     473:                int pflags = PGO_ALLPAGES | PGO_CLEANIT;
                    474:
                    475:                if ((flags & FSYNC_WAIT))
                    476:                        pflags |= PGO_SYNCIO;
1.118     hannken   477:                if (fstrans_getstate(mp) == FSTRANS_SUSPENDING)
1.101     oster     478:                        pflags |= PGO_FREE;
1.119     rmind     479:                mutex_enter(vp->v_interlock);
1.101     oster     480:                error = VOP_PUTPAGES(vp, 0, 0, pflags);
1.99      ad        481:                if (error)
1.39      chs       482:                        return error;
1.100     simonb    483:        }
                    484:
                    485: #ifdef WAPBL
                    486:        if (mp && mp->mnt_wapbl) {
1.110     ad        487:                /*
                    488:                 * Don't bother writing out metadata if the syncer is
                    489:                 * making the request.  We will let the sync vnode
                    490:                 * write it out in a single burst through a call to
                    491:                 * VFS_SYNC().
                    492:                 */
                    493:                if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
                    494:                        return 0;
1.100     simonb    495:
1.110     ad        496:                if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
1.109     ad        497:                    | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
1.100     simonb    498:                        error = UFS_WAPBL_BEGIN(mp);
                    499:                        if (error)
                    500:                                return error;
1.118     hannken   501:                        error = ffs_update(vp, NULL, NULL, uflags);
1.100     simonb    502:                        UFS_WAPBL_END(mp);
                    503:                }
1.110     ad        504:                if (error || (flags & FSYNC_NOLOG) != 0)
1.100     simonb    505:                        return error;
1.106     ad        506:
1.100     simonb    507:                /*
                    508:                 * Don't flush the log if the vnode being flushed
                    509:                 * contains no dirty buffers that could be in the log.
                    510:                 */
1.109     ad        511:                if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
1.100     simonb    512:                        error = wapbl_flush(mp->mnt_wapbl, 0);
                    513:                        if (error)
                    514:                                return error;
                    515:                }
                    516:
1.109     ad        517:                if ((flags & FSYNC_WAIT) != 0) {
1.119     rmind     518:                        mutex_enter(vp->v_interlock);
1.110     ad        519:                        while (vp->v_numoutput != 0)
1.119     rmind     520:                                cv_wait(&vp->v_cv, vp->v_interlock);
                    521:                        mutex_exit(vp->v_interlock);
1.100     simonb    522:                }
                    523:
                    524:                return error;
                    525:        }
                    526: #endif /* WAPBL */
1.35      chs       527:
1.118     hannken   528:        error = vflushbuf(vp, (flags & FSYNC_WAIT) != 0);
                    529:        if (error == 0)
                    530:                error = ffs_update(vp, NULL, NULL, uflags);
1.109     ad        531:        if (error == 0 && (flags & FSYNC_CACHE) != 0) {
1.118     hannken   532:                i = 1;
1.110     ad        533:                (void)VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
                    534:                    kauth_cred_get());
1.67      wrstuden  535:        }
                    536:
                    537:        return error;
1.20      fvdl      538: }
1.1       mycroft   539:
                    540: /*
                    541:  * Reclaim an inode so that it can be used for other purposes.
                    542:  */
                    543: int
1.70      thorpej   544: ffs_reclaim(void *v)
1.6       christos  545: {
1.1       mycroft   546:        struct vop_reclaim_args /* {
                    547:                struct vnode *a_vp;
1.77      christos  548:                struct lwp *a_l;
1.6       christos  549:        } */ *ap = v;
1.26      augustss  550:        struct vnode *vp = ap->a_vp;
1.56      fvdl      551:        struct inode *ip = VTOI(vp);
1.84      hannken   552:        struct mount *mp = vp->v_mount;
1.56      fvdl      553:        struct ufsmount *ump = ip->i_ump;
1.94      ad        554:        void *data;
1.1       mycroft   555:        int error;
                    556:
1.87      hannken   557:        fstrans_start(mp, FSTRANS_LAZY);
1.115     hannken   558:        /*
                    559:         * The inode must be freed and updated before being removed
                    560:         * from its hash chain.  Other threads trying to gain a hold
                    561:         * on the inode will be stalled because it is locked (VI_XLOCK).
                    562:         */
                    563:        error = UFS_WAPBL_BEGIN(mp);
                    564:        if (error) {
                    565:                fstrans_done(mp);
                    566:                return error;
                    567:        }
1.116     hannken   568:        if (ip->i_nlink <= 0 && ip->i_omode != 0 &&
                    569:            (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1.115     hannken   570:                ffs_vfree(vp, ip->i_number, ip->i_omode);
                    571:        UFS_WAPBL_END(mp);
1.93      pooka     572:        if ((error = ufs_reclaim(vp)) != 0) {
1.84      hannken   573:                fstrans_done(mp);
1.1       mycroft   574:                return (error);
1.84      hannken   575:        }
1.57      fvdl      576:        if (ip->i_din.ffs1_din != NULL) {
                    577:                if (ump->um_fstype == UFS1)
1.95      ad        578:                        pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
1.57      fvdl      579:                else
1.95      ad        580:                        pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
1.57      fvdl      581:        }
1.16      thorpej   582:        /*
1.94      ad        583:         * To interlock with ffs_sync().
                    584:         */
                    585:        genfs_node_destroy(vp);
1.119     rmind     586:        mutex_enter(vp->v_interlock);
1.94      ad        587:        data = vp->v_data;
                    588:        vp->v_data = NULL;
1.119     rmind     589:        mutex_exit(vp->v_interlock);
1.94      ad        590:
                    591:        /*
1.16      thorpej   592:         * XXX MFS ends up here, too, to free an inode.  Should we create
                    593:         * XXX a separate pool for MFS inodes?
                    594:         */
1.95      ad        595:        pool_cache_put(ffs_inode_cache, data);
1.84      hannken   596:        fstrans_done(mp);
1.1       mycroft   597:        return (0);
1.35      chs       598: }
                    599:
                    600: /*
                    601:  * Return the last logical file offset that should be written for this file
                    602:  * if we're doing a write that ends at "size".
                    603:  */
1.39      chs       604:
                    605: void
1.83      christos  606: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35      chs       607: {
1.39      chs       608:        struct inode *ip = VTOI(vp);
1.35      chs       609:        struct fs *fs = ip->i_fs;
1.52      fvdl      610:        daddr_t olbn, nlbn;
1.55      perseant  611:
1.56      fvdl      612:        olbn = lblkno(fs, ip->i_size);
1.39      chs       613:        nlbn = lblkno(fs, size);
1.35      chs       614:        if (nlbn < NDADDR && olbn <= nlbn) {
1.39      chs       615:                *eobp = fragroundup(fs, size);
1.35      chs       616:        } else {
1.39      chs       617:                *eobp = blkroundup(fs, size);
1.35      chs       618:        }
1.1       mycroft   619: }
1.73      thorpej   620:
                    621: int
                    622: ffs_openextattr(void *v)
                    623: {
                    624:        struct vop_openextattr_args /* {
                    625:                struct vnode *a_vp;
1.80      elad      626:                kauth_cred_t a_cred;
1.73      thorpej   627:                struct proc *a_p;
                    628:        } */ *ap = v;
                    629:        struct inode *ip = VTOI(ap->a_vp);
                    630:        struct fs *fs = ip->i_fs;
                    631:
                    632:        /* Not supported for UFS1 file systems. */
                    633:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    634:                return (EOPNOTSUPP);
                    635:
                    636:        /* XXX Not implemented for UFS2 file systems. */
                    637:        return (EOPNOTSUPP);
                    638: }
                    639:
                    640: int
                    641: ffs_closeextattr(void *v)
                    642: {
                    643:        struct vop_closeextattr_args /* {
                    644:                struct vnode *a_vp;
                    645:                int a_commit;
1.80      elad      646:                kauth_cred_t a_cred;
1.73      thorpej   647:                struct proc *a_p;
                    648:        } */ *ap = v;
                    649:        struct inode *ip = VTOI(ap->a_vp);
                    650:        struct fs *fs = ip->i_fs;
                    651:
                    652:        /* Not supported for UFS1 file systems. */
                    653:        if (fs->fs_magic == FS_UFS1_MAGIC)
                    654:                return (EOPNOTSUPP);
                    655:
                    656:        /* XXX Not implemented for UFS2 file systems. */
                    657:        return (EOPNOTSUPP);
                    658: }
                    659:
                    660: int
                    661: ffs_getextattr(void *v)
                    662: {
                    663:        struct vop_getextattr_args /* {
                    664:                struct vnode *a_vp;
                    665:                int a_attrnamespace;
                    666:                const char *a_name;
                    667:                struct uio *a_uio;
                    668:                size_t *a_size;
1.80      elad      669:                kauth_cred_t a_cred;
1.73      thorpej   670:                struct proc *a_p;
                    671:        } */ *ap = v;
1.84      hannken   672:        struct vnode *vp = ap->a_vp;
                    673:        struct inode *ip = VTOI(vp);
1.73      thorpej   674:        struct fs *fs = ip->i_fs;
                    675:
                    676:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    677: #ifdef UFS_EXTATTR
1.84      hannken   678:                int error;
                    679:
1.87      hannken   680:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   681:                error = ufs_getextattr(ap);
                    682:                fstrans_done(vp->v_mount);
                    683:                return error;
1.73      thorpej   684: #else
                    685:                return (EOPNOTSUPP);
                    686: #endif
                    687:        }
                    688:
                    689:        /* XXX Not implemented for UFS2 file systems. */
                    690:        return (EOPNOTSUPP);
                    691: }
                    692:
                    693: int
                    694: ffs_setextattr(void *v)
                    695: {
                    696:        struct vop_setextattr_args /* {
                    697:                struct vnode *a_vp;
                    698:                int a_attrnamespace;
                    699:                const char *a_name;
                    700:                struct uio *a_uio;
1.80      elad      701:                kauth_cred_t a_cred;
1.73      thorpej   702:                struct proc *a_p;
                    703:        } */ *ap = v;
1.84      hannken   704:        struct vnode *vp = ap->a_vp;
                    705:        struct inode *ip = VTOI(vp);
1.73      thorpej   706:        struct fs *fs = ip->i_fs;
                    707:
                    708:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    709: #ifdef UFS_EXTATTR
1.84      hannken   710:                int error;
                    711:
1.87      hannken   712:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   713:                error = ufs_setextattr(ap);
                    714:                fstrans_done(vp->v_mount);
                    715:                return error;
1.73      thorpej   716: #else
                    717:                return (EOPNOTSUPP);
                    718: #endif
                    719:        }
                    720:
                    721:        /* XXX Not implemented for UFS2 file systems. */
                    722:        return (EOPNOTSUPP);
                    723: }
                    724:
                    725: int
                    726: ffs_listextattr(void *v)
                    727: {
                    728:        struct vop_listextattr_args /* {
                    729:                struct vnode *a_vp;
                    730:                int a_attrnamespace;
                    731:                struct uio *a_uio;
                    732:                size_t *a_size;
1.80      elad      733:                kauth_cred_t a_cred;
1.73      thorpej   734:                struct proc *a_p;
                    735:        } */ *ap = v;
                    736:        struct inode *ip = VTOI(ap->a_vp);
                    737:        struct fs *fs = ip->i_fs;
                    738:
1.120   ! manu      739:        if (fs->fs_magic == FS_UFS1_MAGIC) {
        !           740: #ifdef UFS_EXTATTR
        !           741:                struct vnode *vp = ap->a_vp;
        !           742:                int error;
        !           743:
        !           744:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
        !           745:                error = ufs_listextattr(ap);
        !           746:                fstrans_done(vp->v_mount);
        !           747:                return error;
        !           748: #else
1.73      thorpej   749:                return (EOPNOTSUPP);
1.120   ! manu      750: #endif
        !           751:        }
1.73      thorpej   752:
                    753:        /* XXX Not implemented for UFS2 file systems. */
                    754:        return (EOPNOTSUPP);
                    755: }
                    756:
                    757: int
                    758: ffs_deleteextattr(void *v)
                    759: {
                    760:        struct vop_deleteextattr_args /* {
                    761:                struct vnode *a_vp;
                    762:                int a_attrnamespace;
1.80      elad      763:                kauth_cred_t a_cred;
1.73      thorpej   764:                struct proc *a_p;
                    765:        } */ *ap = v;
1.84      hannken   766:        struct vnode *vp = ap->a_vp;
                    767:        struct inode *ip = VTOI(vp);
1.73      thorpej   768:        struct fs *fs = ip->i_fs;
                    769:
                    770:        if (fs->fs_magic == FS_UFS1_MAGIC) {
                    771: #ifdef UFS_EXTATTR
1.84      hannken   772:                int error;
                    773:
1.87      hannken   774:                fstrans_start(vp->v_mount, FSTRANS_SHARED);
1.84      hannken   775:                error = ufs_deleteextattr(ap);
                    776:                fstrans_done(vp->v_mount);
                    777:                return error;
1.73      thorpej   778: #else
                    779:                return (EOPNOTSUPP);
                    780: #endif
                    781:        }
                    782:
                    783:        /* XXX Not implemented for UFS2 file systems. */
                    784:        return (EOPNOTSUPP);
                    785: }

CVSweb <webmaster@jp.NetBSD.org>