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