151184Sbostic /* 251493Sbostic * Copyright (c) 1991 Regents of the University of California. 351184Sbostic * All rights reserved. 451184Sbostic * 551184Sbostic * %sccs.include.redist.c% 651184Sbostic * 7*53143Sstaelin * @(#)lfs_bio.c 7.7 (Berkeley) 04/08/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 { 3752347Sbostic int s; 3851851Sbostic #ifdef VERBOSE 3951851Sbostic printf("lfs_bwrite\n"); 4051851Sbostic #endif 4151851Sbostic /* 4252081Sbostic * Set the delayed write flag and use reassignbuf to move the buffer 4352081Sbostic * from the clean list to the dirty one. 4451851Sbostic * 4552081Sbostic * Set the B_LOCKED flag and unlock the buffer, causing brelse to move 4652081Sbostic * the buffer onto the LOCKED free list. This is necessary, otherwise 4752081Sbostic * getnewbuf() would try to reclaim the buffers using bawrite, which 4852081Sbostic * isn't going to work. 4951851Sbostic */ 50*53143Sstaelin if (!(bp->b_flags & B_LOCKED)) { 5152081Sbostic ++locked_queue_count; 52*53143Sstaelin bp->b_flags |= B_DELWRI | B_LOCKED; 53*53143Sstaelin bp->b_flags &= ~(B_READ | B_DONE | B_ERROR); 54*53143Sstaelin s = splbio(); 55*53143Sstaelin #define PMAP_BUG_FIX_HACK 56*53143Sstaelin #ifdef PMAP_BUG_FIX_HACK 57*53143Sstaelin if (((struct ufsmount *) 58*53143Sstaelin (bp->b_vp->v_mount->mnt_data))->um_lfs->lfs_ivnode != 59*53143Sstaelin bp->b_vp) 60*53143Sstaelin #endif 61*53143Sstaelin reassignbuf(bp, bp->b_vp); 62*53143Sstaelin splx(s); 63*53143Sstaelin } 6451184Sbostic brelse(bp); 6551480Sbostic return (0); 6651184Sbostic } 6752081Sbostic 6852081Sbostic /* 6952081Sbostic * XXX 7052081Sbostic * This routine flushes buffers out of the B_LOCKED queue when LFS has too 7152081Sbostic * many locked down. Eventually the pageout daemon will simply call LFS 7252325Sbostic * when pages need to be reclaimed. Note, we have one static count of locked 7352325Sbostic * buffers, so we can't have more than a single file system. To make this 7452325Sbostic * work for multiple file systems, put the count into the mount structure. 7552081Sbostic */ 7652081Sbostic void 7752081Sbostic lfs_flush() 7852081Sbostic { 7952081Sbostic register struct mount *mp; 8052081Sbostic struct mount *omp; 8152081Sbostic 8252325Sbostic /* 1M in a 4K file system. */ 8352325Sbostic if (locked_queue_count < 256) 8452081Sbostic return; 8552081Sbostic mp = rootfs; 8652081Sbostic do { 8752081Sbostic /* 8852081Sbostic * The lock check below is to avoid races with mount 8952081Sbostic * and unmount. 9052081Sbostic */ 9152081Sbostic if (mp->mnt_stat.f_type == MOUNT_LFS && 9252081Sbostic (mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 && 9352081Sbostic !vfs_busy(mp)) { 9452347Sbostic /* 9552347Sbostic * We set the queue to 0 here because we are about to 9652347Sbostic * write all the dirty buffers we have. If more come 9752347Sbostic * in while we're writing the segment, they may not 9852347Sbostic * get written, so we want the count to reflect these 9952347Sbostic * new writes after the segwrite completes. 10052347Sbostic */ 10152347Sbostic locked_queue_count = 0; 10252081Sbostic lfs_segwrite(mp, 0); 10352081Sbostic omp = mp; 10452081Sbostic mp = mp->mnt_next; 10552081Sbostic vfs_unbusy(omp); 10652081Sbostic } else 10752081Sbostic mp = mp->mnt_next; 10852081Sbostic } while (mp != rootfs); 10952081Sbostic } 110