version 1.69.4.6, 2007/12/07 17:35:20 |
version 1.86.4.9, 2007/08/20 21:28:25 |
Line 246 ffs_fsync(void *v) |
|
Line 246 ffs_fsync(void *v) |
|
struct lwp *a_l; |
struct lwp *a_l; |
} */ *ap = v; |
} */ *ap = v; |
struct buf *bp; |
struct buf *bp; |
int s, num, error, i; |
int num, error, i; |
struct indir ia[NIADDR + 1]; |
struct indir ia[NIADDR + 1]; |
int bsize; |
int bsize; |
daddr_t blk_high; |
daddr_t blk_high; |
Line 273 ffs_fsync(void *v) |
|
Line 273 ffs_fsync(void *v) |
|
* First, flush all pages in range. |
* First, flush all pages in range. |
*/ |
*/ |
|
|
simple_lock(&vp->v_interlock); |
mutex_enter(&vp->v_interlock); |
error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo), |
error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo), |
round_page(ap->a_offhi), PGO_CLEANIT | |
round_page(ap->a_offhi), PGO_CLEANIT | |
((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0)); |
((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0)); |
Line 285 ffs_fsync(void *v) |
|
Line 285 ffs_fsync(void *v) |
|
* Then, flush indirect blocks. |
* Then, flush indirect blocks. |
*/ |
*/ |
|
|
s = splbio(); |
|
if (blk_high >= NDADDR) { |
if (blk_high >= NDADDR) { |
error = ufs_getlbns(vp, blk_high, ia, &num); |
error = ufs_getlbns(vp, blk_high, ia, &num); |
if (error) { |
if (error) |
splx(s); |
|
goto out; |
goto out; |
} |
|
|
mutex_enter(&bqueue_lock); |
for (i = 0; i < num; i++) { |
for (i = 0; i < num; i++) { |
bp = incore(vp, ia[i].in_lbn); |
if ((bp = incore(vp, ia[i].in_lbn)) == NULL) |
if (bp != NULL) { |
continue; |
simple_lock(&bp->b_interlock); |
mutex_enter(&bp->b_interlock); |
if (!(bp->b_flags & B_BUSY) && (bp->b_flags & B_DELWRI)) { |
if ((bp->b_flags & (B_BUSY | B_DELWRI)) != B_DELWRI) { |
bp->b_flags |= B_BUSY | B_VFLUSH; |
mutex_exit(&bp->b_interlock); |
simple_unlock(&bp->b_interlock); |
continue; |
splx(s); |
|
bawrite(bp); |
|
s = splbio(); |
|
} else { |
|
simple_unlock(&bp->b_interlock); |
|
} |
|
} |
} |
|
bp->b_flags |= B_BUSY | B_VFLUSH; |
|
mutex_exit(&bp->b_interlock); |
|
mutex_exit(&bqueue_lock); |
|
bawrite(bp); |
|
mutex_enter(&bqueue_lock); |
} |
} |
|
mutex_exit(&bqueue_lock); |
} |
} |
|
|
if (ap->a_flags & FSYNC_WAIT) { |
if (ap->a_flags & FSYNC_WAIT) { |
simple_lock(&global_v_numoutput_slock); |
mutex_enter(&vp->v_interlock); |
while (vp->v_numoutput > 0) { |
while (vp->v_numoutput > 0) |
vp->v_iflag |= VI_BWAIT; |
cv_wait(&vp->v_cv, &vp->v_interlock); |
ltsleep(&vp->v_numoutput, PRIBIO + 1, "fsync_range", 0, |
mutex_exit(&vp->v_interlock); |
&global_v_numoutput_slock); |
|
} |
|
simple_unlock(&global_v_numoutput_slock); |
|
} |
} |
splx(s); |
|
|
|
error = ffs_update(vp, NULL, NULL, |
error = ffs_update(vp, NULL, NULL, |
((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT) |
((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT) |
Line 327 ffs_fsync(void *v) |
|
Line 322 ffs_fsync(void *v) |
|
if (error == 0 && ap->a_flags & FSYNC_CACHE) { |
if (error == 0 && ap->a_flags & FSYNC_CACHE) { |
int l = 0; |
int l = 0; |
VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE, |
VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE, |
curlwp->l_cred); |
ap->a_l->l_cred, ap->a_l); |
} |
} |
|
|
out: |
out: |
Line 352 ffs_full_fsync(void *v) |
|
Line 347 ffs_full_fsync(void *v) |
|
} */ *ap = v; |
} */ *ap = v; |
struct vnode *vp = ap->a_vp; |
struct vnode *vp = ap->a_vp; |
struct buf *bp, *nbp; |
struct buf *bp, *nbp; |
int s, error, passes, skipmeta, inodedeps_only, waitfor; |
int error, passes, skipmeta, inodedeps_only, waitfor; |
|
|
if (vp->v_type == VBLK && |
if (vp->v_type == VBLK && |
vp->v_specmountpoint != NULL && |
vp->v_specmountpoint != NULL && |
(vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP)) |
(vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP)) |
softdep_fsync_mountdev(vp); |
softdep_fsync_mountdev(vp); |
|
|
|
mutex_enter(&vp->v_interlock); |
|
|
inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM) |
inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM) |
&& UVM_OBJ_IS_CLEAN(&vp->v_uobj) && LIST_EMPTY(&vp->v_dirtyblkhd); |
&& UVM_OBJ_IS_CLEAN(&vp->v_uobj) && LIST_EMPTY(&vp->v_dirtyblkhd); |
|
|
Line 367 ffs_full_fsync(void *v) |
|
Line 364 ffs_full_fsync(void *v) |
|
*/ |
*/ |
|
|
if (vp->v_type == VREG || vp->v_type == VBLK) { |
if (vp->v_type == VREG || vp->v_type == VBLK) { |
simple_lock(&vp->v_interlock); |
|
error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT | |
error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT | |
((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0) | |
((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0) | |
(fstrans_getstate(vp->v_mount) == FSTRANS_SUSPENDING ? |
(fstrans_getstate(vp->v_mount) == FSTRANS_SUSPENDING ? |
Line 375 ffs_full_fsync(void *v) |
|
Line 371 ffs_full_fsync(void *v) |
|
if (error) { |
if (error) { |
return error; |
return error; |
} |
} |
|
mutex_enter(&vp->v_interlock); |
} |
} |
|
|
passes = NIADDR + 1; |
passes = NIADDR + 1; |
skipmeta = 0; |
skipmeta = 0; |
if (ap->a_flags & FSYNC_WAIT) |
if (ap->a_flags & FSYNC_WAIT) |
skipmeta = 1; |
skipmeta = 1; |
s = splbio(); |
|
|
|
loop: |
loop: |
LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) |
LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) { |
|
mutex_enter(&bp->b_interlock); |
bp->b_flags &= ~B_SCANNED; |
bp->b_flags &= ~B_SCANNED; |
|
mutex_exit(&bp->b_interlock); |
|
} |
for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { |
for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { |
nbp = LIST_NEXT(bp, b_vnbufs); |
nbp = LIST_NEXT(bp, b_vnbufs); |
simple_lock(&bp->b_interlock); |
mutex_enter(&bp->b_interlock); |
if (bp->b_flags & (B_BUSY | B_SCANNED)) { |
if (bp->b_flags & (B_BUSY | B_SCANNED)) { |
simple_unlock(&bp->b_interlock); |
mutex_exit(&bp->b_interlock); |
continue; |
continue; |
} |
} |
if ((bp->b_flags & B_DELWRI) == 0) |
if ((bp->b_flags & B_DELWRI) == 0) |
panic("ffs_fsync: not dirty"); |
panic("ffs_fsync: not dirty"); |
if (skipmeta && bp->b_lblkno < 0) { |
if (skipmeta && bp->b_lblkno < 0) { |
simple_unlock(&bp->b_interlock); |
mutex_exit(&bp->b_interlock); |
continue; |
continue; |
} |
} |
simple_unlock(&bp->b_interlock); |
|
bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED; |
bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED; |
splx(s); |
mutex_exit(&bp->b_interlock); |
/* |
/* |
* On our final pass through, do all I/O synchronously |
* On our final pass through, do all I/O synchronously |
* so that we can find out if our flush is failing |
* so that we can find out if our flush is failing |
* because of write errors. |
* because of write errors. |
*/ |
*/ |
|
mutex_exit(&vp->v_interlock); |
if (passes > 0 || !(ap->a_flags & FSYNC_WAIT)) |
if (passes > 0 || !(ap->a_flags & FSYNC_WAIT)) |
(void) bawrite(bp); |
(void) bawrite(bp); |
else if ((error = bwrite(bp)) != 0) |
else if ((error = bwrite(bp)) != 0) |
return (error); |
return (error); |
s = splbio(); |
mutex_enter(&vp->v_interlock); |
/* |
/* |
* Since we may have slept during the I/O, we need |
* Since we may have slept during the I/O, we need |
* to start from a known point. |
* to start from a known point. |
|
|
goto loop; |
goto loop; |
} |
} |
if (ap->a_flags & FSYNC_WAIT) { |
if (ap->a_flags & FSYNC_WAIT) { |
simple_lock(&global_v_numoutput_slock); |
|
while (vp->v_numoutput) { |
while (vp->v_numoutput) { |
vp->v_iflag |= VI_BWAIT; |
cv_wait(&vp->v_cv, &vp->v_interlock); |
(void) ltsleep(&vp->v_numoutput, PRIBIO + 1, |
|
"ffsfsync", 0, &global_v_numoutput_slock); |
|
} |
} |
simple_unlock(&global_v_numoutput_slock); |
mutex_exit(&vp->v_interlock); |
splx(s); |
|
|
|
/* |
/* |
* Ensure that any filesystem metadata associated |
* Ensure that any filesystem metadata associated |
|
|
if ((error = softdep_sync_metadata(ap)) != 0) |
if ((error = softdep_sync_metadata(ap)) != 0) |
return (error); |
return (error); |
|
|
s = splbio(); |
|
if (!LIST_EMPTY(&vp->v_dirtyblkhd)) { |
if (!LIST_EMPTY(&vp->v_dirtyblkhd)) { |
/* |
/* |
* Block devices associated with filesystems may |
* Block devices associated with filesystems may |
|
|
vprint("ffs_fsync: dirty", vp); |
vprint("ffs_fsync: dirty", vp); |
#endif |
#endif |
} |
} |
} |
} else |
splx(s); |
mutex_exit(&vp->v_interlock); |
|
|
if (inodedeps_only) |
if (inodedeps_only) |
waitfor = 0; |
waitfor = 0; |
|
|
if (error == 0 && ap->a_flags & FSYNC_CACHE) { |
if (error == 0 && ap->a_flags & FSYNC_CACHE) { |
int i = 0; |
int i = 0; |
VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE, |
VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE, |
curlwp->l_cred); |
ap->a_l->l_cred, ap->a_l); |
} |
} |
|
|
return error; |
return error; |
Line 490 ffs_reclaim(void *v) |
|
Line 484 ffs_reclaim(void *v) |
|
struct inode *ip = VTOI(vp); |
struct inode *ip = VTOI(vp); |
struct mount *mp = vp->v_mount; |
struct mount *mp = vp->v_mount; |
struct ufsmount *ump = ip->i_ump; |
struct ufsmount *ump = ip->i_ump; |
|
void *data; |
int error; |
int error; |
|
|
fstrans_start(mp, FSTRANS_LAZY); |
fstrans_start(mp, FSTRANS_LAZY); |
if ((error = ufs_reclaim(vp)) != 0) { |
if ((error = ufs_reclaim(vp, ap->a_l)) != 0) { |
fstrans_done(mp); |
fstrans_done(mp); |
return (error); |
return (error); |
} |
} |
Line 504 ffs_reclaim(void *v) |
|
Line 499 ffs_reclaim(void *v) |
|
pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din); |
pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din); |
} |
} |
/* |
/* |
* XXX MFS ends up here, too, to free an inode. Should we create |
* To interlock with ffs_sync(). |
* XXX a separate pool for MFS inodes? |
|
*/ |
*/ |
genfs_node_destroy(vp); |
genfs_node_destroy(vp); |
pool_put(&ffs_inode_pool, vp->v_data); |
mutex_enter(&vp->v_interlock); |
|
data = vp->v_data; |
vp->v_data = NULL; |
vp->v_data = NULL; |
|
mutex_exit(&vp->v_interlock); |
|
|
|
/* |
|
* XXX MFS ends up here, too, to free an inode. Should we create |
|
* XXX a separate pool for MFS inodes? |
|
*/ |
|
pool_put(&ffs_inode_pool, data); |
fstrans_done(mp); |
fstrans_done(mp); |
return (0); |
return (0); |
} |
} |
Line 543 ffs_getpages(void *v) |
|
Line 545 ffs_getpages(void *v) |
|
blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) && |
blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) && |
DOINGSOFTDEP(ap->a_vp)) { |
DOINGSOFTDEP(ap->a_vp)) { |
if ((ap->a_flags & PGO_LOCKED) == 0) { |
if ((ap->a_flags & PGO_LOCKED) == 0) { |
simple_unlock(&vp->v_interlock); |
mutex_exit(&vp->v_interlock); |
} |
} |
return EINVAL; |
return EINVAL; |
} |
} |
Line 740 ffs_lock(void *v) |
|
Line 742 ffs_lock(void *v) |
|
} */ *ap = v; |
} */ *ap = v; |
struct vnode *vp = ap->a_vp; |
struct vnode *vp = ap->a_vp; |
struct mount *mp = vp->v_mount; |
struct mount *mp = vp->v_mount; |
struct lock *lkp; |
|
int flags = ap->a_flags; |
|
int result; |
|
|
|
/* |
/* |
* Fake lock during file system suspension. |
* Fake lock during file system suspension. |
Line 750 ffs_lock(void *v) |
|
Line 749 ffs_lock(void *v) |
|
if ((vp->v_type == VREG || vp->v_type == VDIR) && |
if ((vp->v_type == VREG || vp->v_type == VDIR) && |
fstrans_is_owner(mp) && |
fstrans_is_owner(mp) && |
fstrans_getstate(mp) == FSTRANS_SUSPENDING) { |
fstrans_getstate(mp) == FSTRANS_SUSPENDING) { |
if ((flags & LK_INTERLOCK) != 0) |
if ((ap->a_flags & LK_INTERLOCK) != 0) |
simple_unlock(&vp->v_interlock); |
mutex_exit(&vp->v_interlock); |
return 0; |
return 0; |
} |
} |
|
return (lockmgr(vp->v_vnlock, ap->a_flags, &vp->v_interlock)); |
if ((flags & LK_TYPE_MASK) == LK_DRAIN) |
|
return (lockmgr(vp->v_vnlock, flags, &vp->v_interlock)); |
|
|
|
KASSERT((flags & ~(LK_SHARED | LK_EXCLUSIVE | LK_SLEEPFAIL | |
|
LK_INTERLOCK | LK_NOWAIT | LK_SETRECURSE | LK_CANRECURSE)) == 0); |
|
for (;;) { |
|
if ((flags & LK_INTERLOCK) == 0) { |
|
simple_lock(&vp->v_interlock); |
|
flags |= LK_INTERLOCK; |
|
} |
|
lkp = vp->v_vnlock; |
|
result = lockmgr(lkp, flags, &vp->v_interlock); |
|
if (lkp == vp->v_vnlock || result != 0) |
|
return result; |
|
/* |
|
* Apparent success, except that the vnode mutated between |
|
* snapshot file vnode and regular file vnode while this |
|
* thread slept. The lock currently held is not the right |
|
* lock. Release it, and try to get the new lock. |
|
*/ |
|
(void) lockmgr(lkp, LK_RELEASE, NULL); |
|
flags &= ~LK_INTERLOCK; |
|
} |
|
} |
} |
|
|
/* |
/* |
Line 800 ffs_unlock(void *v) |
|
Line 776 ffs_unlock(void *v) |
|
fstrans_is_owner(mp) && |
fstrans_is_owner(mp) && |
fstrans_getstate(mp) == FSTRANS_SUSPENDING) { |
fstrans_getstate(mp) == FSTRANS_SUSPENDING) { |
if ((ap->a_flags & LK_INTERLOCK) != 0) |
if ((ap->a_flags & LK_INTERLOCK) != 0) |
simple_unlock(&vp->v_interlock); |
mutex_exit(&vp->v_interlock); |
return 0; |
return 0; |
} |
} |
return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, |
return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, |