Home | History | Annotate | Line # | Download | only in lfs
lfs_bio.c revision 1.46
      1 /*	$NetBSD: lfs_bio.c,v 1.46 2002/11/24 16:09:50 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed by the NetBSD
     21  *      Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 /*
     39  * Copyright (c) 1991, 1993
     40  *	The Regents of the University of California.  All rights reserved.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  * 3. All advertising materials mentioning features or use of this software
     51  *    must display the following acknowledgement:
     52  *	This product includes software developed by the University of
     53  *	California, Berkeley and its contributors.
     54  * 4. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  *
     70  *	@(#)lfs_bio.c	8.10 (Berkeley) 6/10/95
     71  */
     72 
     73 #include <sys/cdefs.h>
     74 __KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.46 2002/11/24 16:09:50 yamt Exp $");
     75 
     76 #include <sys/param.h>
     77 #include <sys/systm.h>
     78 #include <sys/proc.h>
     79 #include <sys/buf.h>
     80 #include <sys/vnode.h>
     81 #include <sys/resourcevar.h>
     82 #include <sys/mount.h>
     83 #include <sys/kernel.h>
     84 
     85 #include <ufs/ufs/inode.h>
     86 #include <ufs/ufs/ufsmount.h>
     87 #include <ufs/ufs/ufs_extern.h>
     88 
     89 #include <sys/malloc.h>
     90 #include <ufs/lfs/lfs.h>
     91 #include <ufs/lfs/lfs_extern.h>
     92 
     93 /* Macros to clear/set/test flags. */
     94 # define	SET(t, f)	(t) |= (f)
     95 # define	CLR(t, f)	(t) &= ~(f)
     96 # define	ISSET(t, f)	((t) & (f))
     97 
     98 /*
     99  * LFS block write function.
    100  *
    101  * XXX
    102  * No write cost accounting is done.
    103  * This is almost certainly wrong for synchronous operations and NFS.
    104  */
    105 int	locked_queue_count   = 0;	/* XXX Count of locked-down buffers. */
    106 long	locked_queue_bytes   = 0L;	/* XXX Total size of locked buffers. */
    107 int	lfs_writing          = 0;	/* Set if already kicked off a writer
    108 					   because of buffer space */
    109 extern int lfs_dostats;
    110 
    111 /*
    112  * Try to reserve some blocks, prior to performing a sensitive operation that
    113  * requires the vnode lock to be honored.  If there is not enough space, give
    114  * up the vnode lock temporarily and wait for the space to become available.
    115  *
    116  * Called with vp locked.  (Note nowever that if fsb < 0, vp is ignored.)
    117  *
    118  * XXX YAMT
    119  * it isn't safe to unlock vp here
    120  * because we're passing data using inode from namei.
    121  * (eg. i_offset)
    122  */
    123 int
    124 lfs_reserve(struct lfs *fs, struct vnode *vp, int fsb)
    125 {
    126 	CLEANERINFO *cip;
    127 	struct buf *bp;
    128 	int error, slept;
    129 
    130 	slept = 0;
    131 	while (fsb > 0 && !lfs_fits(fs, fsb + fs->lfs_ravail) &&
    132 	    vp != fs->lfs_unlockvp) {
    133 		VOP_UNLOCK(vp, 0);
    134 
    135 		if (!slept) {
    136 #ifdef DEBUG
    137 			printf("lfs_reserve: waiting for %ld (bfree = %d,"
    138 			       " est_bfree = %d)\n",
    139 			       fsb + fs->lfs_ravail, fs->lfs_bfree,
    140 			       LFS_EST_BFREE(fs));
    141 #endif
    142 		}
    143 		++slept;
    144 
    145 		/* Wake up the cleaner */
    146 		LFS_CLEANERINFO(cip, fs, bp);
    147 		LFS_SYNC_CLEANERINFO(cip, fs, bp, 0);
    148 		wakeup(&lfs_allclean_wakeup);
    149 		wakeup(&fs->lfs_nextseg);
    150 
    151 		error = tsleep(&fs->lfs_avail, PCATCH | PUSER, "lfs_reserve",
    152 			       0);
    153 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* XXX use lockstatus */
    154 		if (error)
    155 			return error;
    156 	}
    157 #ifdef DEBUG
    158 	if (slept)
    159 		printf("lfs_reserve: woke up\n");
    160 #endif
    161 	fs->lfs_ravail += fsb;
    162 	return 0;
    163 }
    164 
    165 /*
    166  *
    167  * XXX we don't let meta-data writes run out of space because they can
    168  * come from the segment writer.  We need to make sure that there is
    169  * enough space reserved so that there's room to write meta-data
    170  * blocks.
    171  *
    172  * Also, we don't let blocks that have come to us from the cleaner
    173  * run out of space.
    174  */
    175 #define CANT_WAIT(BP,F) (IS_IFILE((BP)) || (BP)->b_lblkno < 0 || ((F) & BW_CLEAN))
    176 
    177 int
    178 lfs_bwrite(void *v)
    179 {
    180 	struct vop_bwrite_args /* {
    181 		struct buf *a_bp;
    182 	} */ *ap = v;
    183 	struct buf *bp = ap->a_bp;
    184 
    185 #ifdef DIAGNOSTIC
    186         if (VTOI(bp->b_vp)->i_lfs->lfs_ronly == 0 && (bp->b_flags & B_ASYNC)) {
    187 		panic("bawrite LFS buffer");
    188 	}
    189 #endif /* DIAGNOSTIC */
    190 	return lfs_bwrite_ext(bp,0);
    191 }
    192 
    193 /*
    194  * Determine if there is enough room currently available to write fsb
    195  * blocks.  We need enough blocks for the new blocks, the current
    196  * inode blocks (including potentially the ifile inode), a summary block,
    197  * and the segment usage table, plus an ifile block.
    198  */
    199 int
    200 lfs_fits(struct lfs *fs, int fsb)
    201 {
    202 	int needed;
    203 
    204 	needed = fsb + btofsb(fs, fs->lfs_sumsize) +
    205 		 ((howmany(fs->lfs_uinodes + 1, INOPB(fs)) + fs->lfs_segtabsz +
    206 		   1) << (fs->lfs_blktodb - fs->lfs_fsbtodb));
    207 
    208 	if (needed >= fs->lfs_avail) {
    209 #ifdef DEBUG
    210 		printf("lfs_fits: no fit: fsb = %d, uinodes = %d, "
    211 		       "needed = %d, avail = %d\n",
    212 		       fsb, fs->lfs_uinodes, needed, fs->lfs_avail);
    213 #endif
    214 		return 0;
    215 	}
    216 	return 1;
    217 }
    218 
    219 int
    220 lfs_availwait(struct lfs *fs, int fsb)
    221 {
    222 	int error;
    223 	CLEANERINFO *cip;
    224 	struct buf *cbp;
    225 
    226 	while (!lfs_fits(fs, fsb)) {
    227 		/*
    228 		 * Out of space, need cleaner to run.
    229 		 * Update the cleaner info, then wake it up.
    230 		 * Note the cleanerinfo block is on the ifile
    231 		 * so it CANT_WAIT.
    232 		 */
    233 		LFS_CLEANERINFO(cip, fs, cbp);
    234 		LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0);
    235 
    236 		printf("lfs_availwait: out of available space, "
    237 		       "waiting on cleaner\n");
    238 
    239 		wakeup(&lfs_allclean_wakeup);
    240 		wakeup(&fs->lfs_nextseg);
    241 #ifdef DIAGNOSTIC
    242 		if (fs->lfs_seglock && fs->lfs_lockpid == curproc->p_pid)
    243 			panic("lfs_availwait: deadlock");
    244 #endif
    245 		error = tsleep(&fs->lfs_avail, PCATCH | PUSER, "cleaner", 0);
    246 		if (error)
    247 			return (error);
    248 	}
    249 	return 0;
    250 }
    251 
    252 int
    253 lfs_bwrite_ext(struct buf *bp, int flags)
    254 {
    255 	struct lfs *fs;
    256 	struct inode *ip;
    257 	int fsb, error, s;
    258 
    259 	/*
    260 	 * Don't write *any* blocks if we're mounted read-only.
    261 	 * In particular the cleaner can't write blocks either.
    262 	 */
    263         if (VTOI(bp->b_vp)->i_lfs->lfs_ronly) {
    264 		bp->b_flags &= ~(B_DELWRI | B_READ | B_ERROR);
    265 		LFS_UNLOCK_BUF(bp);
    266 		if (bp->b_flags & B_CALL)
    267 			bp->b_flags &= ~B_BUSY;
    268 		else
    269 			brelse(bp);
    270 		return EROFS;
    271 	}
    272 
    273 	/*
    274 	 * Set the delayed write flag and use reassignbuf to move the buffer
    275 	 * from the clean list to the dirty one.
    276 	 *
    277 	 * Set the B_LOCKED flag and unlock the buffer, causing brelse to move
    278 	 * the buffer onto the LOCKED free list.  This is necessary, otherwise
    279 	 * getnewbuf() would try to reclaim the buffers using bawrite, which
    280 	 * isn't going to work.
    281 	 *
    282 	 * XXX we don't let meta-data writes run out of space because they can
    283 	 * come from the segment writer.  We need to make sure that there is
    284 	 * enough space reserved so that there's room to write meta-data
    285 	 * blocks.
    286 	 */
    287 	if (!(bp->b_flags & B_LOCKED)) {
    288 		fs = VFSTOUFS(bp->b_vp->v_mount)->um_lfs;
    289 		fsb = fragstofsb(fs, numfrags(fs, bp->b_bcount));
    290 		if (!CANT_WAIT(bp, flags)) {
    291 			if ((error = lfs_availwait(fs, fsb)) != 0) {
    292 				brelse(bp);
    293 				return error;
    294 			}
    295 		}
    296 
    297 		ip = VTOI(bp->b_vp);
    298 		if (bp->b_flags & B_CALL) {
    299 			LFS_SET_UINO(ip, IN_CLEANING);
    300 		} else {
    301 			LFS_SET_UINO(ip, IN_MODIFIED);
    302 			if (bp->b_lblkno >= 0)
    303 				LFS_SET_UINO(ip, IN_UPDATE);
    304 		}
    305 		fs->lfs_avail -= fsb;
    306 		bp->b_flags |= B_DELWRI;
    307 
    308 		LFS_LOCK_BUF(bp);
    309 		bp->b_flags &= ~(B_READ | B_DONE | B_ERROR);
    310 		s = splbio();
    311 		reassignbuf(bp, bp->b_vp);
    312 		splx(s);
    313 	}
    314 
    315 	if (bp->b_flags & B_CALL)
    316 		bp->b_flags &= ~B_BUSY;
    317 	else
    318 		brelse(bp);
    319 
    320 	return (0);
    321 }
    322 
    323 void
    324 lfs_flush_fs(struct lfs *fs, int flags)
    325 {
    326 	if (fs->lfs_ronly == 0 && fs->lfs_dirops == 0)
    327 	{
    328 		/* disallow dirops during flush */
    329 		fs->lfs_writer++;
    330 
    331 		/*
    332 		 * We set the queue to 0 here because we
    333 		 * are about to write all the dirty
    334 		 * buffers we have.  If more come in
    335 		 * while we're writing the segment, they
    336 		 * may not get written, so we want the
    337 		 * count to reflect these new writes
    338 		 * after the segwrite completes.
    339 		 */
    340 		if (lfs_dostats)
    341 			++lfs_stats.flush_invoked;
    342 		lfs_segwrite(fs->lfs_ivnode->v_mount, flags);
    343 
    344 		/* XXX KS - allow dirops again */
    345 		if (--fs->lfs_writer == 0)
    346 			wakeup(&fs->lfs_dirops);
    347 	}
    348 }
    349 
    350 /*
    351  * XXX
    352  * This routine flushes buffers out of the B_LOCKED queue when LFS has too
    353  * many locked down.  Eventually the pageout daemon will simply call LFS
    354  * when pages need to be reclaimed.  Note, we have one static count of locked
    355  * buffers, so we can't have more than a single file system.  To make this
    356  * work for multiple file systems, put the count into the mount structure.
    357  */
    358 void
    359 lfs_flush(struct lfs *fs, int flags)
    360 {
    361 	struct mount *mp, *nmp;
    362 
    363 	if (lfs_dostats)
    364 		++lfs_stats.write_exceeded;
    365 	if (lfs_writing && flags == 0) {/* XXX flags */
    366 #ifdef DEBUG_LFS
    367 		printf("lfs_flush: not flushing because another flush is active\n");
    368 #endif
    369 		return;
    370 	}
    371 	lfs_writing = 1;
    372 
    373 	simple_lock(&mountlist_slock);
    374 	for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
    375 		if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
    376 			nmp = mp->mnt_list.cqe_next;
    377 			continue;
    378 		}
    379 		if (strncmp(&mp->mnt_stat.f_fstypename[0], MOUNT_LFS, MFSNAMELEN) == 0)
    380 			lfs_flush_fs(((struct ufsmount *)mp->mnt_data)->ufsmount_u.lfs, flags);
    381 		simple_lock(&mountlist_slock);
    382 		nmp = mp->mnt_list.cqe_next;
    383 		vfs_unbusy(mp);
    384 	}
    385 	simple_unlock(&mountlist_slock);
    386 
    387 	LFS_DEBUG_COUNTLOCKED("flush");
    388 
    389 	lfs_writing = 0;
    390 }
    391 
    392 #define INOCOUNT(fs) howmany((fs)->lfs_uinodes, INOPB(fs))
    393 #define INOBYTES(fs) ((fs)->lfs_uinodes * DINODE_SIZE)
    394 
    395 int
    396 lfs_check(struct vnode *vp, ufs_daddr_t blkno, int flags)
    397 {
    398 	int error;
    399 	struct lfs *fs;
    400 	struct inode *ip;
    401 	extern int lfs_dirvcount;
    402 
    403 	error = 0;
    404 	ip = VTOI(vp);
    405 
    406 	/* If out of buffers, wait on writer */
    407 	/* XXX KS - if it's the Ifile, we're probably the cleaner! */
    408 	if (ip->i_number == LFS_IFILE_INUM)
    409 		return 0;
    410 	/* If we're being called from inside a dirop, don't sleep */
    411 	if (ip->i_flag & IN_ADIROP)
    412 		return 0;
    413 
    414 	fs = ip->i_lfs;
    415 
    416 	/*
    417 	 * If we would flush below, but dirops are active, sleep.
    418 	 * Note that a dirop cannot ever reach this code!
    419 	 */
    420 	while (fs->lfs_dirops > 0 &&
    421 	       (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
    422                 locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES ||
    423                 lfs_dirvcount > LFS_MAXDIROP || fs->lfs_diropwait > 0))
    424 	{
    425 		++fs->lfs_diropwait;
    426 		tsleep(&fs->lfs_writer, PRIBIO+1, "bufdirop", 0);
    427 		--fs->lfs_diropwait;
    428 	}
    429 
    430 	if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
    431 	    locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES ||
    432 	    lfs_dirvcount > LFS_MAXDIROP || fs->lfs_diropwait > 0)
    433 	{
    434 		++fs->lfs_writer;
    435 		lfs_flush(fs, flags);
    436 		if (--fs->lfs_writer == 0)
    437 			wakeup(&fs->lfs_dirops);
    438 	}
    439 
    440 	while (locked_queue_count + INOCOUNT(fs) > LFS_WAIT_BUFS
    441 	       || locked_queue_bytes + INOBYTES(fs) > LFS_WAIT_BYTES)
    442 	{
    443 		if (lfs_dostats)
    444 			++lfs_stats.wait_exceeded;
    445 #ifdef DEBUG_LFS
    446 		printf("lfs_check: waiting: count=%d, bytes=%ld\n",
    447 			locked_queue_count, locked_queue_bytes);
    448 #endif
    449 		error = tsleep(&locked_queue_count, PCATCH | PUSER,
    450 			       "buffers", hz * LFS_BUFWAIT);
    451 		if (error != EWOULDBLOCK)
    452 			break;
    453 		/*
    454 		 * lfs_flush might not flush all the buffers, if some of the
    455 		 * inodes were locked or if most of them were Ifile blocks
    456 		 * and we weren't asked to checkpoint.  Try flushing again
    457 		 * to keep us from blocking indefinitely.
    458 		 */
    459 		if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
    460 		    locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES)
    461 		{
    462 			++fs->lfs_writer;
    463 			lfs_flush(fs, flags | SEGM_CKP);
    464 			if (--fs->lfs_writer == 0)
    465 				wakeup(&fs->lfs_dirops);
    466 		}
    467 	}
    468 	return (error);
    469 }
    470 
    471 /*
    472  * Allocate a new buffer header.
    473  */
    474 #ifdef MALLOCLOG
    475 # define DOMALLOC(S, T, F) _malloc((S), (T), (F), file, line)
    476 struct buf *
    477 lfs_newbuf_malloclog(struct lfs *fs, struct vnode *vp, ufs_daddr_t daddr, size_t size, char *file, int line)
    478 #else
    479 # define DOMALLOC(S, T, F) malloc((S), (T), (F))
    480 struct buf *
    481 lfs_newbuf(struct lfs *fs, struct vnode *vp, ufs_daddr_t daddr, size_t size)
    482 #endif
    483 {
    484 	struct buf *bp;
    485 	size_t nbytes;
    486 	int s;
    487 
    488 	nbytes = roundup(size, fsbtob(fs, 1));
    489 
    490 	bp = DOMALLOC(sizeof(struct buf), M_SEGMENT, M_WAITOK);
    491 	bzero(bp, sizeof(struct buf));
    492 	if (nbytes) {
    493 		bp->b_data = DOMALLOC(nbytes, M_SEGMENT, M_WAITOK);
    494 		bzero(bp->b_data, nbytes);
    495 	}
    496 #ifdef DIAGNOSTIC
    497 	if (vp == NULL)
    498 		panic("vp is NULL in lfs_newbuf");
    499 	if (bp == NULL)
    500 		panic("bp is NULL after malloc in lfs_newbuf");
    501 #endif
    502 	s = splbio();
    503 	bgetvp(vp, bp);
    504 	splx(s);
    505 
    506 	bp->b_saveaddr = (caddr_t)fs;
    507 	bp->b_bufsize = size;
    508 	bp->b_bcount = size;
    509 	bp->b_lblkno = daddr;
    510 	bp->b_blkno = daddr;
    511 	bp->b_error = 0;
    512 	bp->b_resid = 0;
    513 	bp->b_iodone = lfs_callback;
    514 	bp->b_flags |= B_BUSY | B_CALL | B_NOCACHE;
    515 
    516 	return (bp);
    517 }
    518 
    519 #ifdef MALLOCLOG
    520 # define DOFREE(A, T) _free((A), (T), file, line)
    521 void
    522 lfs_freebuf_malloclog(struct buf *bp, char *file, int line)
    523 #else
    524 # define DOFREE(A, T) free((A), (T))
    525 void
    526 lfs_freebuf(struct buf *bp)
    527 #endif
    528 {
    529 	int s;
    530 
    531 	s = splbio();
    532 	if (bp->b_vp)
    533 		brelvp(bp);
    534 	splx(s);
    535 	if (!(bp->b_flags & B_INVAL)) { /* B_INVAL indicates a "fake" buffer */
    536 		DOFREE(bp->b_data, M_SEGMENT);
    537 		bp->b_data = NULL;
    538 	}
    539 	DOFREE(bp, M_SEGMENT);
    540 }
    541 
    542 /*
    543  * Definitions for the buffer free lists.
    544  */
    545 #define BQUEUES		4		/* number of free buffer queues */
    546 
    547 #define BQ_LOCKED	0		/* super-blocks &c */
    548 #define BQ_LRU		1		/* lru, useful buffers */
    549 #define BQ_AGE		2		/* rubbish */
    550 #define BQ_EMPTY	3		/* buffer headers with no memory */
    551 
    552 extern TAILQ_HEAD(bqueues, buf) bufqueues[BQUEUES];
    553 
    554 /*
    555  * Return a count of buffers on the "locked" queue.
    556  * Don't count malloced buffers, since they don't detract from the total.
    557  */
    558 void
    559 lfs_countlocked(int *count, long *bytes, char *msg)
    560 {
    561 	struct buf *bp;
    562 	int n = 0;
    563 	long int size = 0L;
    564 
    565 	for (bp = bufqueues[BQ_LOCKED].tqh_first; bp;
    566 	    bp = bp->b_freelist.tqe_next) {
    567 		if (bp->b_flags & B_CALL) /* Malloced buffer */
    568 			continue;
    569 		n++;
    570 		size += bp->b_bufsize;
    571 #ifdef DEBUG_LOCKED_LIST
    572 		if (n > nbuf)
    573 			panic("lfs_countlocked: this can't happen: more"
    574 			      " buffers locked than exist");
    575 #endif
    576 	}
    577 #ifdef DEBUG_LOCKED_LIST
    578 	/* Theoretically this function never really does anything */
    579 	if (n != *count)
    580 		printf("lfs_countlocked: %s: adjusted buf count from %d to %d\n",
    581 		       msg, *count, n);
    582 	if (size != *bytes)
    583 		printf("lfs_countlocked: %s: adjusted byte count from %ld to %ld\n",
    584 		       msg, *bytes, size);
    585 #endif
    586 	*count = n;
    587 	*bytes = size;
    588 	return;
    589 }
    590