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