xref: /onnv-gate/usr/src/uts/common/sys/buf.h (revision 8433:8db6aee1dd98)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55251Smrj  * Common Development and Distribution License (the "License").
65251Smrj  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
227547SDonghai.Qiao@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef _SYS_BUF_H
400Sstevel@tonic-gate #define	_SYS_BUF_H
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <sys/types32.h>
430Sstevel@tonic-gate #include <sys/t_lock.h>
440Sstevel@tonic-gate #include <sys/kstat.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef	__cplusplus
470Sstevel@tonic-gate extern "C" {
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  *	Each buffer in the pool is usually doubly linked into 2 lists:
520Sstevel@tonic-gate  *	the device with which it is currently associated (always)
530Sstevel@tonic-gate  *	and also on a list of blocks available for allocation
540Sstevel@tonic-gate  *	for other use (usually).
550Sstevel@tonic-gate  *	The latter list is kept in last-used order, and the two
560Sstevel@tonic-gate  *	lists are doubly linked to make it easy to remove
570Sstevel@tonic-gate  *	a buffer from one list when it was found by
580Sstevel@tonic-gate  *	looking through the other.
590Sstevel@tonic-gate  *	A buffer is on the available list, and is liable
600Sstevel@tonic-gate  *	to be reassigned to another disk block, if and only
610Sstevel@tonic-gate  *	if it is not marked BUSY.  When a buffer is busy, the
620Sstevel@tonic-gate  *	available-list pointers can be used for other purposes.
630Sstevel@tonic-gate  *	Most drivers use the forward ptr as a link in their I/O active queue.
640Sstevel@tonic-gate  *	A buffer header contains all the information required to perform I/O.
650Sstevel@tonic-gate  *	Most of the routines which manipulate these things are in bio.c.
660Sstevel@tonic-gate  *
670Sstevel@tonic-gate  *	There are a number of locks associated with the buffer management
680Sstevel@tonic-gate  *	system.
690Sstevel@tonic-gate  *	hbuf.b_lock:	protects hash chains, buffer hdr freelists
700Sstevel@tonic-gate  *			and delayed write freelist
710Sstevel@tonic-gate  *	bfree_lock;	protects the bfreelist structure
720Sstevel@tonic-gate  *	bhdr_lock:	protects the free header list
730Sstevel@tonic-gate  *	blist_lock:	protects b_list fields
740Sstevel@tonic-gate  *	buf.b_sem:	protects all remaining members in the buf struct
750Sstevel@tonic-gate  *	buf.b_io:	I/O synchronization variable
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  *	A buffer header is never "locked" (b_sem) when it is on
780Sstevel@tonic-gate  *	a "freelist" (bhdrlist or bfreelist avail lists).
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate typedef struct	buf {
810Sstevel@tonic-gate 	int	b_flags;		/* see defines below */
820Sstevel@tonic-gate 	struct buf *b_forw;		/* headed by d_tab of conf.c */
830Sstevel@tonic-gate 	struct buf *b_back;		/*  "  */
840Sstevel@tonic-gate 	struct buf *av_forw;		/* position on free list, */
850Sstevel@tonic-gate 	struct buf *av_back;		/* if not BUSY */
860Sstevel@tonic-gate 	o_dev_t	b_dev;			/* OLD major+minor device name */
870Sstevel@tonic-gate 	size_t b_bcount;		/* transfer count */
880Sstevel@tonic-gate 	union {
890Sstevel@tonic-gate 		caddr_t b_addr;		/* low order core address */
900Sstevel@tonic-gate 		struct fs *b_fs;	/* superblocks */
910Sstevel@tonic-gate 		struct cg *b_cg;	/* UFS cylinder group block */
920Sstevel@tonic-gate 		struct dinode *b_dino;	/* UFS ilist */
930Sstevel@tonic-gate 		daddr32_t *b_daddr;	/* disk blocks */
940Sstevel@tonic-gate 	} b_un;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	lldaddr_t	_b_blkno;	/* block # on device (union) */
970Sstevel@tonic-gate #define	b_lblkno	_b_blkno._f
980Sstevel@tonic-gate #ifdef _LP64
990Sstevel@tonic-gate #define	b_blkno		_b_blkno._f
1000Sstevel@tonic-gate #else
1010Sstevel@tonic-gate #define	b_blkno		_b_blkno._p._l
1020Sstevel@tonic-gate #endif /* _LP64 */
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	char	b_obs1;			/* obsolete */
1050Sstevel@tonic-gate 	size_t	b_resid;		/* words not transferred after error */
1060Sstevel@tonic-gate 	clock_t	b_start;		/* request start time */
1070Sstevel@tonic-gate 	struct  proc  *b_proc;		/* process doing physical or swap I/O */
1080Sstevel@tonic-gate 	struct	page  *b_pages;		/* page list for PAGEIO */
1090Sstevel@tonic-gate 	clock_t b_obs2;			/* obsolete */
1100Sstevel@tonic-gate 	/* Begin new stuff */
1110Sstevel@tonic-gate #define	b_actf	av_forw
1120Sstevel@tonic-gate #define	b_actl	av_back
1130Sstevel@tonic-gate #define	b_active b_bcount
1140Sstevel@tonic-gate #define	b_errcnt b_resid
1150Sstevel@tonic-gate 	size_t	b_bufsize;		/* size of allocated buffer */
1160Sstevel@tonic-gate 	int	(*b_iodone)(struct buf *);	/* function called by iodone */
1170Sstevel@tonic-gate 	struct	vnode *b_vp;		/* vnode associated with block */
1180Sstevel@tonic-gate 	struct 	buf *b_chain;		/* chain together all buffers here */
1190Sstevel@tonic-gate 	int	b_obs3;			/* obsolete */
1200Sstevel@tonic-gate 	int	b_error;		/* expanded error field */
1210Sstevel@tonic-gate 	void	*b_private;		/* "opaque" driver private area */
1220Sstevel@tonic-gate 	dev_t	b_edev;			/* expanded dev field */
1230Sstevel@tonic-gate 	ksema_t	b_sem;			/* Exclusive access to buf */
1240Sstevel@tonic-gate 	ksema_t	b_io;			/* I/O Synchronization */
1250Sstevel@tonic-gate 	struct buf *b_list;		/* List of potential B_DELWRI bufs */
1260Sstevel@tonic-gate 	struct page **b_shadow;		/* shadow page list */
1270Sstevel@tonic-gate 	void	*b_dip;			/* device info pointer */
1280Sstevel@tonic-gate 	struct vnode *b_file;		/* file associated with this buffer */
1290Sstevel@tonic-gate 	offset_t b_offset;		/* offset in file assoc. with buffer */
1300Sstevel@tonic-gate } buf_t;
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate  * Bufhd structures used at the head of the hashed buffer queues.
1340Sstevel@tonic-gate  * We only need seven words for this, so this abbreviated
1350Sstevel@tonic-gate  * definition saves some space.
1360Sstevel@tonic-gate  */
1370Sstevel@tonic-gate struct diskhd {
1380Sstevel@tonic-gate 	int	b_flags;		/* not used, needed for consistency */
1390Sstevel@tonic-gate 	struct buf *b_forw, *b_back;	/* queue of unit queues */
1400Sstevel@tonic-gate 	struct buf *av_forw, *av_back;	/* queue of bufs for this unit */
1410Sstevel@tonic-gate 	o_dev_t	b_dev;			/* OLD major+minor device name */
1420Sstevel@tonic-gate 	size_t b_bcount;		/* transfer count */
1430Sstevel@tonic-gate };
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * Statistics on the buffer cache
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate struct biostats {
1500Sstevel@tonic-gate 	kstat_named_t	bio_lookup;	/* requests to assign buffer */
1510Sstevel@tonic-gate 	kstat_named_t	bio_hit;	/* buffer already associated with blk */
1520Sstevel@tonic-gate 	kstat_named_t	bio_bufwant;	/* kmem_allocs NOSLEEP failed new buf */
1530Sstevel@tonic-gate 	kstat_named_t	bio_bufwait;	/* kmem_allocs with KM_SLEEP for buf */
1540Sstevel@tonic-gate 	kstat_named_t	bio_bufbusy;	/* buffer locked by someone else */
1550Sstevel@tonic-gate 	kstat_named_t	bio_bufdup;	/* duplicate buffer found for block */
1560Sstevel@tonic-gate };
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate  * These flags are kept in b_flags.
1600Sstevel@tonic-gate  * The first group is part of the DDI
1610Sstevel@tonic-gate  */
1620Sstevel@tonic-gate #define	B_BUSY		0x0001	/* not on av_forw/back list */
1630Sstevel@tonic-gate #define	B_DONE		0x0002	/* transaction finished */
1640Sstevel@tonic-gate #define	B_ERROR		0x0004	/* transaction aborted */
1650Sstevel@tonic-gate #define	B_PAGEIO	0x0010	/* do I/O to pages on bp->p_pages */
1660Sstevel@tonic-gate #define	B_PHYS		0x0020	/* Physical IO potentially using UNIBUS map */
1670Sstevel@tonic-gate #define	B_READ		0x0040	/* read when I/O occurs */
1680Sstevel@tonic-gate #define	B_WRITE		0x0100	/* non-read pseudo-flag */
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* Not part of the DDI */
1710Sstevel@tonic-gate #define	B_WANTED	0x0080		/* issue wakeup when BUSY goes off */
1720Sstevel@tonic-gate #define	B_AGE		0x000200	/* delayed write for correct aging */
1730Sstevel@tonic-gate #define	B_ASYNC		0x000400	/* don't wait for I/O completion */
1740Sstevel@tonic-gate #define	B_DELWRI	0x000800	/* delayed write-wait til buf needed */
1750Sstevel@tonic-gate #define	B_STALE		0x001000	/* on av_* list; invalid contents */
1760Sstevel@tonic-gate #define	B_DONTNEED	0x002000	/* after write, need not be cached */
1770Sstevel@tonic-gate #define	B_REMAPPED	0x004000	/* buffer is kernel addressable */
1780Sstevel@tonic-gate #define	B_FREE		0x008000	/* free page when done */
179*8433SMichael.Corcoran@Sun.COM #define	B_INVAL		0x010000	/* destroy page when done */
1800Sstevel@tonic-gate #define	B_FORCE		0x020000	/* semi-permanent removal from cache */
1810Sstevel@tonic-gate #define	B_NOCACHE	0x080000 	/* don't cache block when released */
1820Sstevel@tonic-gate #define	B_TRUNC		0x100000	/* truncate page without I/O */
1830Sstevel@tonic-gate #define	B_SHADOW	0x200000	/* is b_shadow field valid? */
1840Sstevel@tonic-gate #define	B_RETRYWRI	0x400000	/* retry write til works or bfinval */
1850Sstevel@tonic-gate #define	B_FAILFAST	0x1000000	/* Fail promptly if device goes away */
1860Sstevel@tonic-gate #define	B_STARTED	0x2000000	/* io:::start probe called for buf */
1870Sstevel@tonic-gate #define	B_ABRWRITE	0x4000000	/* Application based recovery active */
1887547SDonghai.Qiao@Sun.COM #define	B_PAGE_NOWAIT	0x8000000	/* Skip the page if it is locked */
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /*
191*8433SMichael.Corcoran@Sun.COM  * There is some confusion over the meaning of B_FREE and B_INVAL and what
192*8433SMichael.Corcoran@Sun.COM  * the use of one over the other implies.
193*8433SMichael.Corcoran@Sun.COM  *
194*8433SMichael.Corcoran@Sun.COM  * In both cases, when we are done with the page (buffer) we want to free
195*8433SMichael.Corcoran@Sun.COM  * up the page.  In the case of B_FREE, the page will go to the cachelist.
196*8433SMichael.Corcoran@Sun.COM  * In the case of B_INVAL, the page will be destroyed (hashed out of it's
197*8433SMichael.Corcoran@Sun.COM  * vnode) and placed on the freelist.  Beyond this, there is no difference
198*8433SMichael.Corcoran@Sun.COM  * between the sole use of these two flags.  In both cases, IO will be done
199*8433SMichael.Corcoran@Sun.COM  * if the page is not yet committed to storage.
200*8433SMichael.Corcoran@Sun.COM  *
201*8433SMichael.Corcoran@Sun.COM  * In order to discard pages without writing them back, (B_INVAL | B_TRUNC)
202*8433SMichael.Corcoran@Sun.COM  * should be used.
203*8433SMichael.Corcoran@Sun.COM  *
204*8433SMichael.Corcoran@Sun.COM  * Use (B_INVAL | B_FORCE) to force the page to be destroyed even if we
205*8433SMichael.Corcoran@Sun.COM  * could not successfuly write out the page.
206*8433SMichael.Corcoran@Sun.COM  */
207*8433SMichael.Corcoran@Sun.COM 
208*8433SMichael.Corcoran@Sun.COM /*
2090Sstevel@tonic-gate  * Insq/Remq for the buffer hash lists.
2100Sstevel@tonic-gate  */
2110Sstevel@tonic-gate #define	bremhash(bp) { \
2120Sstevel@tonic-gate 	ASSERT((bp)->b_forw != NULL); \
2130Sstevel@tonic-gate 	ASSERT((bp)->b_back != NULL); \
2140Sstevel@tonic-gate 	(bp)->b_back->b_forw = (bp)->b_forw; \
2150Sstevel@tonic-gate 	(bp)->b_forw->b_back = (bp)->b_back; \
2160Sstevel@tonic-gate 	(bp)->b_forw = (bp)->b_back = NULL; \
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate #define	binshash(bp, dp) { \
2190Sstevel@tonic-gate 	ASSERT((bp)->b_forw == NULL); \
2200Sstevel@tonic-gate 	ASSERT((bp)->b_back == NULL); \
2210Sstevel@tonic-gate 	ASSERT((dp)->b_forw != NULL); \
2220Sstevel@tonic-gate 	ASSERT((dp)->b_back != NULL); \
2230Sstevel@tonic-gate 	(bp)->b_forw = (dp)->b_forw; \
2240Sstevel@tonic-gate 	(bp)->b_back = (dp); \
2250Sstevel@tonic-gate 	(dp)->b_forw->b_back = (bp); \
2260Sstevel@tonic-gate 	(dp)->b_forw = (bp); \
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate  * The hash structure maintains two lists:
2320Sstevel@tonic-gate  *
2330Sstevel@tonic-gate  * 	1) The hash list of buffers (b_forw & b_back)
2340Sstevel@tonic-gate  *	2) The LRU free list of buffers on this hash bucket (av_forw & av_back)
2350Sstevel@tonic-gate  *
2360Sstevel@tonic-gate  * The dwbuf structure keeps a list of delayed write buffers per hash bucket
2370Sstevel@tonic-gate  * hence there are exactly the same number of dwbuf structures as there are
2380Sstevel@tonic-gate  * the hash buckets (hbuf structures) in the system.
2390Sstevel@tonic-gate  *
2400Sstevel@tonic-gate  * The number of buffers on the freelist may not be equal to the number of
2410Sstevel@tonic-gate  * buffers on the hash list. That is because when buffers are busy they are
2420Sstevel@tonic-gate  * taken off the freelist but not off the hash list. "b_length" field keeps
2430Sstevel@tonic-gate  * track of the number of free buffers (including delayed writes ones) on
2440Sstevel@tonic-gate  * the hash bucket. The "b_lock" mutex protects the free list as well as
2450Sstevel@tonic-gate  * the hash list. It also protects the counter "b_length".
2460Sstevel@tonic-gate  *
2470Sstevel@tonic-gate  * Enties b_forw, b_back, av_forw & av_back must be at the same offset
2480Sstevel@tonic-gate  * as the ones in buf structure.
2490Sstevel@tonic-gate  */
2500Sstevel@tonic-gate struct	hbuf {
2510Sstevel@tonic-gate 	int	b_flags;
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	struct	buf	*b_forw;	/* hash list forw pointer */
2540Sstevel@tonic-gate 	struct	buf	*b_back;	/* hash list back pointer */
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate 	struct	buf	*av_forw;	/* free list forw pointer */
2570Sstevel@tonic-gate 	struct	buf	*av_back;	/* free list back pointer */
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 	int		b_length;	/* # of entries on free list */
2600Sstevel@tonic-gate 	kmutex_t	b_lock;		/* lock to protect this structure */
2610Sstevel@tonic-gate };
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate  * The delayed list pointer entries should match with the buf strcuture.
2660Sstevel@tonic-gate  */
2670Sstevel@tonic-gate struct	dwbuf {
2680Sstevel@tonic-gate 	int	b_flags;		/* not used */
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	struct	buf	*b_forw;	/* not used */
2710Sstevel@tonic-gate 	struct	buf	*b_back;	/* not used */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	struct	buf	*av_forw;	/* delayed write forw pointer */
2740Sstevel@tonic-gate 	struct	buf	*av_back;	/* delayed write back pointer */
2750Sstevel@tonic-gate };
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate /*
2790Sstevel@tonic-gate  * Unlink a buffer from the available (free or delayed write) list and mark
2800Sstevel@tonic-gate  * it busy (internal interface).
2810Sstevel@tonic-gate  */
2820Sstevel@tonic-gate #define	notavail(bp) \
2830Sstevel@tonic-gate {\
2840Sstevel@tonic-gate 	ASSERT(SEMA_HELD(&bp->b_sem)); \
2850Sstevel@tonic-gate 	ASSERT((bp)->av_forw != NULL); \
2860Sstevel@tonic-gate 	ASSERT((bp)->av_back != NULL); \
2870Sstevel@tonic-gate 	ASSERT((bp)->av_forw != (bp)); \
2880Sstevel@tonic-gate 	ASSERT((bp)->av_back != (bp)); \
2890Sstevel@tonic-gate 	(bp)->av_back->av_forw = (bp)->av_forw; \
2900Sstevel@tonic-gate 	(bp)->av_forw->av_back = (bp)->av_back; \
2910Sstevel@tonic-gate 	(bp)->b_flags |= B_BUSY; \
2920Sstevel@tonic-gate 	(bp)->av_forw = (bp)->av_back = NULL; \
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate #if defined(_KERNEL)
2960Sstevel@tonic-gate /*
2970Sstevel@tonic-gate  * Macros to avoid the extra function call needed for binary compat.
2980Sstevel@tonic-gate  *
2990Sstevel@tonic-gate  * B_RETRYWRI is not included in clear_flags for BWRITE(), BWRITE2(),
3000Sstevel@tonic-gate  * or brwrite() so that the retry operation is persistent until the
3010Sstevel@tonic-gate  * write either succeeds or the buffer is bfinval()'d.
3020Sstevel@tonic-gate  *
3030Sstevel@tonic-gate  */
3040Sstevel@tonic-gate #define	BREAD(dev, blkno, bsize) \
3050Sstevel@tonic-gate 	bread_common(/* ufsvfsp */ NULL, dev, blkno, bsize)
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate #define	BWRITE(bp) \
3080Sstevel@tonic-gate 	bwrite_common(/* ufsvfsp */ NULL, bp, /* force_wait */ 0, \
3090Sstevel@tonic-gate 		/* do_relse */ 1, \
3100Sstevel@tonic-gate 		/* clear_flags */ (B_READ | B_DONE | B_ERROR | B_DELWRI))
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate #define	BWRITE2(bp) \
3130Sstevel@tonic-gate 	bwrite_common(/* ufsvfsp */ NULL, bp, /* force_wait */ 1, \
3140Sstevel@tonic-gate 		/* do_relse */ 0, \
3150Sstevel@tonic-gate 		/* clear_flags */ (B_READ | B_DONE | B_ERROR | B_DELWRI))
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate #define	GETBLK(dev, blkno, bsize) \
3180Sstevel@tonic-gate 	getblk_common(/* ufsvfsp */ NULL, dev, blkno, bsize, /* errflg */ 0)
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate /*
3220Sstevel@tonic-gate  * Macros for new retry write interfaces.
3230Sstevel@tonic-gate  */
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate /*
3260Sstevel@tonic-gate  * Same as bdwrite() except write failures are retried.
3270Sstevel@tonic-gate  */
3280Sstevel@tonic-gate #define	bdrwrite(bp) { \
3290Sstevel@tonic-gate 	(bp)->b_flags |= B_RETRYWRI; \
3300Sstevel@tonic-gate 	bdwrite((bp)); \
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate /*
3340Sstevel@tonic-gate  * Same as bwrite() except write failures are retried.
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate #define	brwrite(bp) { \
3370Sstevel@tonic-gate 	(bp)->b_flags |= B_RETRYWRI; \
3380Sstevel@tonic-gate 	bwrite_common((bp), /* force_wait */ 0, /* do_relse */ 1, \
3390Sstevel@tonic-gate 		/* clear_flags */ (B_READ | B_DONE | B_ERROR | B_DELWRI)); \
3400Sstevel@tonic-gate }
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate extern struct hbuf	*hbuf;		/* Hash table */
3430Sstevel@tonic-gate extern struct dwbuf	*dwbuf;		/* delayed write hash table */
3440Sstevel@tonic-gate extern struct buf	*buf;		/* The buffer pool itself */
3450Sstevel@tonic-gate extern struct buf	bfreelist;	/* head of available list */
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate extern void (*bio_lufs_strategy)(void *, buf_t *);	/* UFS Logging */
3480Sstevel@tonic-gate extern void (*bio_snapshot_strategy)(void *, buf_t *);	/* UFS snapshots */
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate int	bcheck(dev_t, struct buf *);
3510Sstevel@tonic-gate int	iowait(struct buf *);
3520Sstevel@tonic-gate int	hash2ints(int x, int y);
3530Sstevel@tonic-gate int	bio_busy(int);
3540Sstevel@tonic-gate int	biowait(struct buf *);
3550Sstevel@tonic-gate int	biomodified(struct buf *);
3560Sstevel@tonic-gate int	geterror(struct buf *);
3570Sstevel@tonic-gate void	minphys(struct buf *);
3580Sstevel@tonic-gate /*
3590Sstevel@tonic-gate  * ufsvfsp is declared as a void * to avoid having everyone that uses
3600Sstevel@tonic-gate  * this header file include sys/fs/ufs_inode.h.
3610Sstevel@tonic-gate  */
3620Sstevel@tonic-gate void	bwrite_common(void *ufsvfsp, struct buf *, int force_wait,
3630Sstevel@tonic-gate 	int do_relse, int clear_flags);
3640Sstevel@tonic-gate void	bwrite(struct buf *);
3650Sstevel@tonic-gate void	bwrite2(struct buf *);
3660Sstevel@tonic-gate void	bdwrite(struct buf *);
3670Sstevel@tonic-gate void	bawrite(struct buf *);
3680Sstevel@tonic-gate void	brelse(struct buf *);
3690Sstevel@tonic-gate void	iodone(struct buf *);
3700Sstevel@tonic-gate void	clrbuf(struct buf *);
3710Sstevel@tonic-gate void	bflush(dev_t);
3720Sstevel@tonic-gate void	blkflush(dev_t, daddr_t);
3730Sstevel@tonic-gate void	binval(dev_t);
3740Sstevel@tonic-gate int	bfinval(dev_t, int);
3750Sstevel@tonic-gate void	binit(void);
3760Sstevel@tonic-gate void	biodone(struct buf *);
3770Sstevel@tonic-gate void	bioinit(struct buf *);
3780Sstevel@tonic-gate void	biofini(struct buf *);
3790Sstevel@tonic-gate void	bp_mapin(struct buf *);
3800Sstevel@tonic-gate void	*bp_mapin_common(struct buf *, int);
3810Sstevel@tonic-gate void	bp_mapout(struct buf *);
3825251Smrj int	bp_copyin(struct buf *, void *, offset_t, size_t);
3835251Smrj int	bp_copyout(void *, struct buf *, offset_t, size_t);
3840Sstevel@tonic-gate void	bp_init(size_t, uint_t);
3850Sstevel@tonic-gate int	bp_color(struct buf *);
3860Sstevel@tonic-gate void	pageio_done(struct buf *);
3870Sstevel@tonic-gate struct buf *bread(dev_t, daddr_t, long);
3880Sstevel@tonic-gate struct buf *bread_common(void *, dev_t, daddr_t, long);
3890Sstevel@tonic-gate struct buf *breada(dev_t, daddr_t, daddr_t, long);
3900Sstevel@tonic-gate struct buf *getblk(dev_t, daddr_t, long);
3910Sstevel@tonic-gate struct buf *getblk_common(void *, dev_t, daddr_t, long, int);
3920Sstevel@tonic-gate struct buf *ngeteblk(long);
3930Sstevel@tonic-gate struct buf *geteblk(void);
3940Sstevel@tonic-gate struct buf *pageio_setup(struct page *, size_t, struct vnode *, int);
3950Sstevel@tonic-gate void bioerror(struct buf *bp, int error);
3960Sstevel@tonic-gate void bioreset(struct buf *bp);
3970Sstevel@tonic-gate struct buf *bioclone(struct buf *, off_t, size_t, dev_t, daddr_t,
3980Sstevel@tonic-gate 	int (*)(struct buf *), struct buf *, int);
3990Sstevel@tonic-gate size_t	biosize(void);
4000Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate #ifdef	__cplusplus
4030Sstevel@tonic-gate }
4040Sstevel@tonic-gate #endif
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate #endif	/* _SYS_BUF_H */
407