1 /* 2 * Copyright (c) 1991 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)lfs_bio.c 7.8 (Berkeley) 04/08/92 8 */ 9 10 #include <sys/param.h> 11 #include <sys/proc.h> 12 #include <sys/buf.h> 13 #include <sys/vnode.h> 14 #include <sys/resourcevar.h> 15 #include <sys/mount.h> 16 17 #include <ufs/ufs/quota.h> 18 #include <ufs/ufs/inode.h> 19 #include <ufs/ufs/ufsmount.h> 20 21 #include <ufs/lfs/lfs.h> 22 #include <ufs/lfs/lfs_extern.h> 23 24 /* 25 * LFS block write function. 26 * 27 * XXX 28 * No write cost accounting is done. 29 * This is almost certainly wrong for synchronous operations and NFS. 30 */ 31 int locked_queue_count; /* XXX Count of locked-down buffers. */ 32 33 int 34 lfs_bwrite(bp) 35 register struct buf *bp; 36 { 37 int s; 38 #ifdef VERBOSE 39 printf("lfs_bwrite\n"); 40 #endif 41 /* 42 * Set the delayed write flag and use reassignbuf to move the buffer 43 * from the clean list to the dirty one. 44 * 45 * Set the B_LOCKED flag and unlock the buffer, causing brelse to move 46 * the buffer onto the LOCKED free list. This is necessary, otherwise 47 * getnewbuf() would try to reclaim the buffers using bawrite, which 48 * isn't going to work. 49 */ 50 if (!(bp->b_flags & B_LOCKED)) { 51 ++locked_queue_count; 52 bp->b_flags |= B_DELWRI | B_LOCKED; 53 bp->b_flags &= ~(B_READ | B_DONE | B_ERROR); 54 s = splbio(); 55 #define PMAP_BUG_FIX_HACK 56 #ifdef PMAP_BUG_FIX_HACK 57 if (((struct ufsmount *) 58 (bp->b_vp->v_mount->mnt_data))->um_lfs->lfs_ivnode != 59 bp->b_vp) 60 #endif 61 reassignbuf(bp, bp->b_vp); 62 splx(s); 63 } 64 brelse(bp); 65 return (0); 66 } 67 68 /* 69 * XXX 70 * This routine flushes buffers out of the B_LOCKED queue when LFS has too 71 * many locked down. Eventually the pageout daemon will simply call LFS 72 * when pages need to be reclaimed. Note, we have one static count of locked 73 * buffers, so we can't have more than a single file system. To make this 74 * work for multiple file systems, put the count into the mount structure. 75 */ 76 void 77 lfs_flush() 78 { 79 register struct mount *mp; 80 struct mount *omp; 81 82 /* 1M in a 4K file system. */ 83 if (locked_queue_count < 256) 84 return; 85 mp = rootfs; 86 do { 87 /* 88 * The lock check below is to avoid races with mount 89 * and unmount. 90 */ 91 if (mp->mnt_stat.f_type == MOUNT_LFS && 92 (mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 && 93 !vfs_busy(mp)) { 94 /* 95 * We set the queue to 0 here because we are about to 96 * write all the dirty buffers we have. If more come 97 * in while we're writing the segment, they may not 98 * get written, so we want the count to reflect these 99 * new writes after the segwrite completes. 100 */ 101 locked_queue_count = 0; 102 lfs_segwrite(mp, 0); 103 omp = mp; 104 mp = mp->mnt_next; 105 vfs_unbusy(omp); 106 } else 107 mp = mp->mnt_next; 108 } while (mp != rootfs); 109 } 110