xref: /csrg-svn/sys/ufs/lfs/lfs_bio.c (revision 52081)
151184Sbostic /*
251493Sbostic  * Copyright (c) 1991 Regents of the University of California.
351184Sbostic  * All rights reserved.
451184Sbostic  *
551184Sbostic  * %sccs.include.redist.c%
651184Sbostic  *
7*52081Sbostic  *	@(#)lfs_bio.c	7.4 (Berkeley) 12/31/91
851184Sbostic  */
951184Sbostic 
1051480Sbostic #include <sys/param.h>
1151480Sbostic #include <sys/proc.h>
1251480Sbostic #include <sys/buf.h>
13*52081Sbostic #include <sys/vnode.h>
1451480Sbostic #include <sys/resourcevar.h>
15*52081Sbostic #include <sys/mount.h>
1651184Sbostic 
17*52081Sbostic #include <ufs/ufs/quota.h>
18*52081Sbostic #include <ufs/ufs/inode.h>
19*52081Sbostic #include <ufs/ufs/ufsmount.h>
20*52081Sbostic 
2151493Sbostic #include <ufs/lfs/lfs.h>
2251493Sbostic #include <ufs/lfs/lfs_extern.h>
2351480Sbostic 
24*52081Sbostic /*
25*52081Sbostic  * LFS block write function.
26*52081Sbostic  *
27*52081Sbostic  * XXX
28*52081Sbostic  * No write cost accounting is done.
29*52081Sbostic  * This is almost certainly wrong for synchronous operations and NFS.
30*52081Sbostic  */
31*52081Sbostic int	locked_queue_count;		/* XXX Count of locked-down buffers. */
32*52081Sbostic 
3351480Sbostic int
3451184Sbostic lfs_bwrite(bp)
3551184Sbostic 	register BUF *bp;
3651184Sbostic {
3751851Sbostic #ifdef VERBOSE
3851851Sbostic printf("lfs_bwrite\n");
3951851Sbostic #endif
4051851Sbostic 	/*
41*52081Sbostic 	 * Set the delayed write flag and use reassignbuf to move the buffer
42*52081Sbostic 	 * from the clean list to the dirty one.
4351851Sbostic 	 *
44*52081Sbostic 	 * Set the B_LOCKED flag and unlock the buffer, causing brelse to move
45*52081Sbostic 	 * the buffer onto the LOCKED free list.  This is necessary, otherwise
46*52081Sbostic 	 * getnewbuf() would try to reclaim the buffers using bawrite, which
47*52081Sbostic 	 * isn't going to work.
4851851Sbostic 	 */
49*52081Sbostic 	if (!(bp->b_flags & B_LOCKED))
50*52081Sbostic 		++locked_queue_count;
5151913Sbostic 	bp->b_flags |= B_DELWRI | B_LOCKED;
5251215Sbostic 	bp->b_flags &= ~(B_READ | B_DONE | B_ERROR);
5351851Sbostic 	reassignbuf(bp, bp->b_vp);
5451184Sbostic 	brelse(bp);
5551480Sbostic 	return (0);
5651184Sbostic }
57*52081Sbostic 
58*52081Sbostic /*
59*52081Sbostic  * XXX
60*52081Sbostic  * This routine flushes buffers out of the B_LOCKED queue when LFS has too
61*52081Sbostic  * many locked down.  Eventually the pageout daemon will simply call LFS
62*52081Sbostic  * when pages need to be reclaimed.
63*52081Sbostic  */
64*52081Sbostic void
65*52081Sbostic lfs_flush()
66*52081Sbostic {
67*52081Sbostic 	register struct mount *mp;
68*52081Sbostic 	struct mount *omp;
69*52081Sbostic 
70*52081Sbostic 	/* 800K in a 4K file system. */
71*52081Sbostic 	if (locked_queue_count < 200)
72*52081Sbostic 		return;
73*52081Sbostic 	mp = rootfs;
74*52081Sbostic 	do {
75*52081Sbostic 		/*
76*52081Sbostic 		 * The lock check below is to avoid races with mount
77*52081Sbostic 		 * and unmount.
78*52081Sbostic 		 */
79*52081Sbostic 		if (mp->mnt_stat.f_type == MOUNT_LFS &&
80*52081Sbostic 		    (mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 &&
81*52081Sbostic 		    !vfs_busy(mp)) {
82*52081Sbostic 			lfs_segwrite(mp, 0);
83*52081Sbostic 			omp = mp;
84*52081Sbostic 			mp = mp->mnt_next;
85*52081Sbostic 			vfs_unbusy(omp);
86*52081Sbostic 		} else
87*52081Sbostic 			mp = mp->mnt_next;
88*52081Sbostic 	} while (mp != rootfs);
89*52081Sbostic 	/* Not exact, but it doesn't matter. */
90*52081Sbostic 	locked_queue_count = 0;
91*52081Sbostic }
92