151184Sbostic /* 251493Sbostic * Copyright (c) 1991 Regents of the University of California. 351184Sbostic * All rights reserved. 451184Sbostic * 551184Sbostic * %sccs.include.redist.c% 651184Sbostic * 7*52325Sbostic * @(#)lfs_bio.c 7.5 (Berkeley) 02/04/92 851184Sbostic */ 951184Sbostic 1051480Sbostic #include <sys/param.h> 1151480Sbostic #include <sys/proc.h> 1251480Sbostic #include <sys/buf.h> 1352081Sbostic #include <sys/vnode.h> 1451480Sbostic #include <sys/resourcevar.h> 1552081Sbostic #include <sys/mount.h> 1651184Sbostic 1752081Sbostic #include <ufs/ufs/quota.h> 1852081Sbostic #include <ufs/ufs/inode.h> 1952081Sbostic #include <ufs/ufs/ufsmount.h> 2052081Sbostic 2151493Sbostic #include <ufs/lfs/lfs.h> 2251493Sbostic #include <ufs/lfs/lfs_extern.h> 2351480Sbostic 2452081Sbostic /* 2552081Sbostic * LFS block write function. 2652081Sbostic * 2752081Sbostic * XXX 2852081Sbostic * No write cost accounting is done. 2952081Sbostic * This is almost certainly wrong for synchronous operations and NFS. 3052081Sbostic */ 3152081Sbostic int locked_queue_count; /* XXX Count of locked-down buffers. */ 3252081Sbostic 3351480Sbostic int 3451184Sbostic lfs_bwrite(bp) 3551184Sbostic register BUF *bp; 3651184Sbostic { 3751851Sbostic #ifdef VERBOSE 3851851Sbostic printf("lfs_bwrite\n"); 3951851Sbostic #endif 4051851Sbostic /* 4152081Sbostic * Set the delayed write flag and use reassignbuf to move the buffer 4252081Sbostic * from the clean list to the dirty one. 4351851Sbostic * 4452081Sbostic * Set the B_LOCKED flag and unlock the buffer, causing brelse to move 4552081Sbostic * the buffer onto the LOCKED free list. This is necessary, otherwise 4652081Sbostic * getnewbuf() would try to reclaim the buffers using bawrite, which 4752081Sbostic * isn't going to work. 4851851Sbostic */ 4952081Sbostic if (!(bp->b_flags & B_LOCKED)) 5052081Sbostic ++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 } 5752081Sbostic 5852081Sbostic /* 5952081Sbostic * XXX 6052081Sbostic * This routine flushes buffers out of the B_LOCKED queue when LFS has too 6152081Sbostic * many locked down. Eventually the pageout daemon will simply call LFS 62*52325Sbostic * when pages need to be reclaimed. Note, we have one static count of locked 63*52325Sbostic * buffers, so we can't have more than a single file system. To make this 64*52325Sbostic * work for multiple file systems, put the count into the mount structure. 6552081Sbostic */ 6652081Sbostic void 6752081Sbostic lfs_flush() 6852081Sbostic { 6952081Sbostic register struct mount *mp; 7052081Sbostic struct mount *omp; 7152081Sbostic 72*52325Sbostic /* 1M in a 4K file system. */ 73*52325Sbostic if (locked_queue_count < 256) 7452081Sbostic return; 7552081Sbostic mp = rootfs; 7652081Sbostic do { 7752081Sbostic /* 7852081Sbostic * The lock check below is to avoid races with mount 7952081Sbostic * and unmount. 8052081Sbostic */ 8152081Sbostic if (mp->mnt_stat.f_type == MOUNT_LFS && 8252081Sbostic (mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 && 8352081Sbostic !vfs_busy(mp)) { 8452081Sbostic lfs_segwrite(mp, 0); 8552081Sbostic omp = mp; 8652081Sbostic mp = mp->mnt_next; 8752081Sbostic vfs_unbusy(omp); 88*52325Sbostic /* Not exact, but it doesn't matter. */ 89*52325Sbostic locked_queue_count = 0; 9052081Sbostic } else 9152081Sbostic mp = mp->mnt_next; 9252081Sbostic } while (mp != rootfs); 9352081Sbostic } 94