xref: /xnu-11215.1.10/bsd/sys/buf_internal.h (revision 8d741a5de7ff4191bf97d57b9f54c2f6d4a15585)
1*8d741a5dSApple OSS Distributions /*
2*8d741a5dSApple OSS Distributions  * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
3*8d741a5dSApple OSS Distributions  *
4*8d741a5dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*8d741a5dSApple OSS Distributions  *
6*8d741a5dSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*8d741a5dSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*8d741a5dSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*8d741a5dSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*8d741a5dSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*8d741a5dSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*8d741a5dSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*8d741a5dSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*8d741a5dSApple OSS Distributions  *
15*8d741a5dSApple OSS Distributions  * Please obtain a copy of the License at
16*8d741a5dSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*8d741a5dSApple OSS Distributions  *
18*8d741a5dSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*8d741a5dSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*8d741a5dSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*8d741a5dSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*8d741a5dSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*8d741a5dSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*8d741a5dSApple OSS Distributions  * limitations under the License.
25*8d741a5dSApple OSS Distributions  *
26*8d741a5dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*8d741a5dSApple OSS Distributions  */
28*8d741a5dSApple OSS Distributions /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29*8d741a5dSApple OSS Distributions /*
30*8d741a5dSApple OSS Distributions  * Copyright (c) 1982, 1986, 1989, 1993
31*8d741a5dSApple OSS Distributions  *	The Regents of the University of California.  All rights reserved.
32*8d741a5dSApple OSS Distributions  * (c) UNIX System Laboratories, Inc.
33*8d741a5dSApple OSS Distributions  * All or some portions of this file are derived from material licensed
34*8d741a5dSApple OSS Distributions  * to the University of California by American Telephone and Telegraph
35*8d741a5dSApple OSS Distributions  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36*8d741a5dSApple OSS Distributions  * the permission of UNIX System Laboratories, Inc.
37*8d741a5dSApple OSS Distributions  *
38*8d741a5dSApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
39*8d741a5dSApple OSS Distributions  * modification, are permitted provided that the following conditions
40*8d741a5dSApple OSS Distributions  * are met:
41*8d741a5dSApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
42*8d741a5dSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
43*8d741a5dSApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
44*8d741a5dSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
45*8d741a5dSApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
46*8d741a5dSApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
47*8d741a5dSApple OSS Distributions  *    must display the following acknowledgement:
48*8d741a5dSApple OSS Distributions  *	This product includes software developed by the University of
49*8d741a5dSApple OSS Distributions  *	California, Berkeley and its contributors.
50*8d741a5dSApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
51*8d741a5dSApple OSS Distributions  *    may be used to endorse or promote products derived from this software
52*8d741a5dSApple OSS Distributions  *    without specific prior written permission.
53*8d741a5dSApple OSS Distributions  *
54*8d741a5dSApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55*8d741a5dSApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56*8d741a5dSApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57*8d741a5dSApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58*8d741a5dSApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59*8d741a5dSApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60*8d741a5dSApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61*8d741a5dSApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62*8d741a5dSApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63*8d741a5dSApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64*8d741a5dSApple OSS Distributions  * SUCH DAMAGE.
65*8d741a5dSApple OSS Distributions  *
66*8d741a5dSApple OSS Distributions  *	@(#)buf.h	8.9 (Berkeley) 3/30/95
67*8d741a5dSApple OSS Distributions  */
68*8d741a5dSApple OSS Distributions 
69*8d741a5dSApple OSS Distributions #ifndef _SYS_BUF_INTERNAL_H_
70*8d741a5dSApple OSS Distributions #define _SYS_BUF_INTERNAL_H_
71*8d741a5dSApple OSS Distributions 
72*8d741a5dSApple OSS Distributions #include <sys/appleapiopts.h>
73*8d741a5dSApple OSS Distributions 
74*8d741a5dSApple OSS Distributions #ifdef KERNEL
75*8d741a5dSApple OSS Distributions #include <sys/queue.h>
76*8d741a5dSApple OSS Distributions #include <sys/errno.h>
77*8d741a5dSApple OSS Distributions #include <sys/vm.h>
78*8d741a5dSApple OSS Distributions #include <sys/cdefs.h>
79*8d741a5dSApple OSS Distributions #include <sys/buf.h>
80*8d741a5dSApple OSS Distributions #include <sys/lock.h>
81*8d741a5dSApple OSS Distributions 
82*8d741a5dSApple OSS Distributions #if CONFIG_PROTECT
83*8d741a5dSApple OSS Distributions #include <sys/cprotect.h>
84*8d741a5dSApple OSS Distributions #endif
85*8d741a5dSApple OSS Distributions 
86*8d741a5dSApple OSS Distributions #define NOLIST ((struct buf *)0x87654321)
87*8d741a5dSApple OSS Distributions 
88*8d741a5dSApple OSS Distributions /*
89*8d741a5dSApple OSS Distributions  * Attributes of an I/O to be used by lower layers
90*8d741a5dSApple OSS Distributions  */
91*8d741a5dSApple OSS Distributions struct bufattr {
92*8d741a5dSApple OSS Distributions #if CONFIG_PROTECT
93*8d741a5dSApple OSS Distributions 	struct cpx *ba_cpx;
94*8d741a5dSApple OSS Distributions 	uint64_t ba_cp_file_off;
95*8d741a5dSApple OSS Distributions #endif
96*8d741a5dSApple OSS Distributions 	uint64_t ba_flags;      /* flags. Some are only in-use on embedded devices */
97*8d741a5dSApple OSS Distributions 	void *ba_verify_ctx;
98*8d741a5dSApple OSS Distributions };
99*8d741a5dSApple OSS Distributions 
100*8d741a5dSApple OSS Distributions /*
101*8d741a5dSApple OSS Distributions  * The buffer header describes an I/O operation in the kernel.
102*8d741a5dSApple OSS Distributions  */
103*8d741a5dSApple OSS Distributions struct buf {
104*8d741a5dSApple OSS Distributions 	LIST_ENTRY(buf) b_hash;         /* Hash chain. */
105*8d741a5dSApple OSS Distributions 	LIST_ENTRY(buf) b_vnbufs;       /* Buffer's associated vnode. */
106*8d741a5dSApple OSS Distributions 	TAILQ_ENTRY(buf) b_freelist;    /* Free list position if not active. */
107*8d741a5dSApple OSS Distributions 	int     b_timestamp;            /* timestamp for queuing operation */
108*8d741a5dSApple OSS Distributions 	struct timeval b_timestamp_tv; /* microuptime for disk conditioner */
109*8d741a5dSApple OSS Distributions 	int     b_whichq;               /* the free list the buffer belongs to */
110*8d741a5dSApple OSS Distributions 	volatile uint32_t       b_flags;        /* B_* flags. */
111*8d741a5dSApple OSS Distributions 	volatile uint32_t       b_lflags;       /* BL_BUSY | BL_WANTED flags... protected by buf_mtx */
112*8d741a5dSApple OSS Distributions 	int     b_error;                /* errno value. */
113*8d741a5dSApple OSS Distributions 	int     b_bufsize;              /* Allocated buffer size. */
114*8d741a5dSApple OSS Distributions 	int     b_bcount;               /* Valid bytes in buffer. */
115*8d741a5dSApple OSS Distributions 	int     b_resid;                /* Remaining I/O. */
116*8d741a5dSApple OSS Distributions 	dev_t   b_dev;                  /* Device associated with buffer. */
117*8d741a5dSApple OSS Distributions 	uintptr_t       b_datap;        /* Memory, superblocks, indirect etc.*/
118*8d741a5dSApple OSS Distributions 	daddr64_t       b_lblkno;       /* Logical block number. */
119*8d741a5dSApple OSS Distributions 	daddr64_t       b_blkno;        /* Underlying physical block number. */
120*8d741a5dSApple OSS Distributions 	void    (*b_iodone)(buf_t, void *);     /* Function to call upon completion. */
121*8d741a5dSApple OSS Distributions 	vnode_t b_vp;                   /* File vnode for data, device vnode for metadata. */
122*8d741a5dSApple OSS Distributions 	kauth_cred_t b_rcred;           /* Read credentials reference. */
123*8d741a5dSApple OSS Distributions 	kauth_cred_t b_wcred;           /* Write credentials reference. */
124*8d741a5dSApple OSS Distributions 	void *  b_upl;                  /* Pointer to UPL */
125*8d741a5dSApple OSS Distributions 	buf_t   b_real_bp;              /* used to track bp generated through cluster_bp */
126*8d741a5dSApple OSS Distributions 	TAILQ_ENTRY(buf)        b_act;  /* Device driver queue when active */
127*8d741a5dSApple OSS Distributions 	void *  b_drvdata;              /* Device driver private use */
128*8d741a5dSApple OSS Distributions 	void *  b_fsprivate;            /* filesystem private use */
129*8d741a5dSApple OSS Distributions 	void *  b_transaction;          /* journal private use */
130*8d741a5dSApple OSS Distributions 	int     b_dirtyoff;             /* Offset in buffer of dirty region. */
131*8d741a5dSApple OSS Distributions 	int     b_dirtyend;             /* Offset of end of dirty region. */
132*8d741a5dSApple OSS Distributions 	int     b_validoff;             /* Offset in buffer of valid region. */
133*8d741a5dSApple OSS Distributions 	int     b_validend;             /* Offset of end of valid region. */
134*8d741a5dSApple OSS Distributions 
135*8d741a5dSApple OSS Distributions 	/* store extra information related to redundancy of data, such as
136*8d741a5dSApple OSS Distributions 	 * which redundancy copy to use, etc
137*8d741a5dSApple OSS Distributions 	 */
138*8d741a5dSApple OSS Distributions 	uint32_t b_redundancy_flags;
139*8d741a5dSApple OSS Distributions 
140*8d741a5dSApple OSS Distributions 	proc_t  b_proc;                 /* Associated proc; NULL if kernel. */
141*8d741a5dSApple OSS Distributions #ifdef BUF_MAKE_PRIVATE
142*8d741a5dSApple OSS Distributions 	buf_t   b_data_store;
143*8d741a5dSApple OSS Distributions #endif
144*8d741a5dSApple OSS Distributions 	struct bufattr b_attr;
145*8d741a5dSApple OSS Distributions #ifdef JOE_DEBUG
146*8d741a5dSApple OSS Distributions 	void *  b_owner;
147*8d741a5dSApple OSS Distributions 	int     b_tag;
148*8d741a5dSApple OSS Distributions 	void *  b_lastbrelse;
149*8d741a5dSApple OSS Distributions 	void *  b_stackbrelse[6];
150*8d741a5dSApple OSS Distributions 	void *  b_stackgetblk[6];
151*8d741a5dSApple OSS Distributions #endif
152*8d741a5dSApple OSS Distributions 	off_t   b_lblksize;           /* Block size used to set b_lbkno if not B_CLUSTER*/
153*8d741a5dSApple OSS Distributions 	vnode_t b_vnop_vp;            /* identifies vp on which VNOP has been called */
154*8d741a5dSApple OSS Distributions };
155*8d741a5dSApple OSS Distributions 
156*8d741a5dSApple OSS Distributions extern vm_offset_t buf_kernel_addrperm;
157*8d741a5dSApple OSS Distributions 
158*8d741a5dSApple OSS Distributions /* cluster_io definitions for use with io bufs */
159*8d741a5dSApple OSS Distributions #define b_uploffset  b_bufsize
160*8d741a5dSApple OSS Distributions #define b_orig       b_freelist.tqe_prev
161*8d741a5dSApple OSS Distributions #define b_shadow     b_freelist.tqe_next
162*8d741a5dSApple OSS Distributions #define b_shadow_ref b_validoff
163*8d741a5dSApple OSS Distributions #ifdef BUF_MAKE_PRIVATE
164*8d741a5dSApple OSS Distributions #define b_data_ref   b_validend
165*8d741a5dSApple OSS Distributions #endif
166*8d741a5dSApple OSS Distributions #define b_trans_head b_freelist.tqe_prev
167*8d741a5dSApple OSS Distributions #define b_trans_next b_freelist.tqe_next
168*8d741a5dSApple OSS Distributions #define b_iostate    b_rcred
169*8d741a5dSApple OSS Distributions #define b_cliodone   b_wcred
170*8d741a5dSApple OSS Distributions #define b_clfoffset  b_lblksize
171*8d741a5dSApple OSS Distributions 
172*8d741a5dSApple OSS Distributions /*
173*8d741a5dSApple OSS Distributions  * These flags are kept in b_lflags...
174*8d741a5dSApple OSS Distributions  * buf_mtx must be held before examining/updating
175*8d741a5dSApple OSS Distributions  */
176*8d741a5dSApple OSS Distributions #define BL_BUSY         0x00000001      /* I/O in progress. */
177*8d741a5dSApple OSS Distributions #define BL_WANTED       0x00000002      /* Process wants this buffer. */
178*8d741a5dSApple OSS Distributions #define BL_IOBUF        0x00000004      /* buffer allocated via 'buf_alloc' */
179*8d741a5dSApple OSS Distributions #define BL_WANTDEALLOC  0x00000010      /* buffer should be put on empty list when clean */
180*8d741a5dSApple OSS Distributions #define BL_SHADOW       0x00000020
181*8d741a5dSApple OSS Distributions #define BL_EXTERNAL     0x00000040
182*8d741a5dSApple OSS Distributions #define BL_WAITSHADOW   0x00000080
183*8d741a5dSApple OSS Distributions #define BL_IOBUF_ALLOC  0x00000100
184*8d741a5dSApple OSS Distributions #define BL_WANTED_REF   0x00000200
185*8d741a5dSApple OSS Distributions #define BL_IOBUF_VDEV   0x00000400      /* iobuf was for a diskimage */
186*8d741a5dSApple OSS Distributions 
187*8d741a5dSApple OSS Distributions /*
188*8d741a5dSApple OSS Distributions  * Parameters for buffer cache garbage collection
189*8d741a5dSApple OSS Distributions  */
190*8d741a5dSApple OSS Distributions #define BUF_STALE_THRESHHOLD    30      /* Collect if untouched in the last 30 seconds */
191*8d741a5dSApple OSS Distributions #define BUF_MAX_GC_BATCH_SIZE   64      /* Under a single grab of the lock */
192*8d741a5dSApple OSS Distributions 
193*8d741a5dSApple OSS Distributions /*
194*8d741a5dSApple OSS Distributions  * mask used by buf_flags... these are the readable external flags
195*8d741a5dSApple OSS Distributions  */
196*8d741a5dSApple OSS Distributions #define BUF_X_RDFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\
197*8d741a5dSApple OSS Distributions 	               B_META | B_CLUSTER | B_DELWRI | B_FUA | B_PASSIVE | B_IOSTREAMING |\
198*8d741a5dSApple OSS Distributions 	               B_ENCRYPTED_IO | B_STATICCONTENT)
199*8d741a5dSApple OSS Distributions /*
200*8d741a5dSApple OSS Distributions  * mask used by buf_clearflags/buf_setflags... these are the writable external flags
201*8d741a5dSApple OSS Distributions  */
202*8d741a5dSApple OSS Distributions #define BUF_X_WRFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\
203*8d741a5dSApple OSS Distributions 	               B_NOCACHE | B_FUA | B_PASSIVE | B_IOSTREAMING)
204*8d741a5dSApple OSS Distributions 
205*8d741a5dSApple OSS Distributions #if 0
206*8d741a5dSApple OSS Distributions /* b_flags defined in buf.h */
207*8d741a5dSApple OSS Distributions #define B_WRITE         0x00000000      /* Write buffer (pseudo flag). */
208*8d741a5dSApple OSS Distributions #define B_READ          0x00000001      /* Read buffer. */
209*8d741a5dSApple OSS Distributions #define B_ASYNC         0x00000002      /* Start I/O, do not wait. */
210*8d741a5dSApple OSS Distributions #define B_NOCACHE       0x00000004      /* Do not cache block after use. */
211*8d741a5dSApple OSS Distributions #define B_DELWRI        0x00000008      /* Delay I/O until buffer reused. */
212*8d741a5dSApple OSS Distributions #define B_LOCKED        0x00000010      /* Locked in core (not reusable). */
213*8d741a5dSApple OSS Distributions #define B_PHYS          0x00000020      /* I/O to user memory. */
214*8d741a5dSApple OSS Distributions #define B_CLUSTER       0x00000040      /* UPL based I/O generated by cluster layer */
215*8d741a5dSApple OSS Distributions #define B_PAGEIO        0x00000080      /* Page in/out */
216*8d741a5dSApple OSS Distributions #define B_META          0x00000100      /* buffer contains meta-data. */
217*8d741a5dSApple OSS Distributions #define B_RAW           0x00000200      /* Set by physio for raw transfers. */
218*8d741a5dSApple OSS Distributions #define B_FUA           0x00000400      /* Write-through disk cache(if supported) */
219*8d741a5dSApple OSS Distributions #define B_PASSIVE       0x00000800      /* PASSIVE I/Os are ignored by THROTTLE I/O */
220*8d741a5dSApple OSS Distributions #define B_IOSTREAMING   0x00001000      /* sequential access pattern detected */
221*8d741a5dSApple OSS Distributions #define B_ENCRYPTED_IO  0x00004000      /* Encrypted I/O */
222*8d741a5dSApple OSS Distributions #define B_STATICCONTENT 0x00008000      /* Buffer is likely to remain unaltered */
223*8d741a5dSApple OSS Distributions #endif
224*8d741a5dSApple OSS Distributions 
225*8d741a5dSApple OSS Distributions /*
226*8d741a5dSApple OSS Distributions  * These flags are kept in b_flags... access is lockless
227*8d741a5dSApple OSS Distributions  * External flags are defined in buf.h and cannot overlap
228*8d741a5dSApple OSS Distributions  * the internal flags
229*8d741a5dSApple OSS Distributions  *
230*8d741a5dSApple OSS Distributions  * these flags are internal... there definition may change
231*8d741a5dSApple OSS Distributions  */
232*8d741a5dSApple OSS Distributions #define B_CACHE         0x00010000      /* getblk found us in the cache. */
233*8d741a5dSApple OSS Distributions #define B_DONE          0x00020000      /* I/O completed. */
234*8d741a5dSApple OSS Distributions #define B_INVAL         0x00040000      /* Does not contain valid info. */
235*8d741a5dSApple OSS Distributions #define B_ERROR         0x00080000      /* I/O error occurred. */
236*8d741a5dSApple OSS Distributions #define B_EINTR         0x00100000      /* I/O was interrupted */
237*8d741a5dSApple OSS Distributions #define B_AGE           0x00200000      /* Move to age queue when I/O done. */
238*8d741a5dSApple OSS Distributions #define B_FILTER        0x00400000      /* call b_iodone from biodone as an in-line filter */
239*8d741a5dSApple OSS Distributions #define B_CALL          0x00800000      /* Call b_iodone from biodone, assumes b_iodone consumes bp */
240*8d741a5dSApple OSS Distributions #define B_EOT           0x01000000      /* last buffer in a transaction list created by cluster_io */
241*8d741a5dSApple OSS Distributions #define B_WASDIRTY      0x02000000      /* page was found dirty in the VM cache */
242*8d741a5dSApple OSS Distributions #define B_HDRALLOC      0x04000000      /* zone allocated buffer header */
243*8d741a5dSApple OSS Distributions #define B_ZALLOC        0x08000000      /* b_datap is zalloc()ed */
244*8d741a5dSApple OSS Distributions /*
245*8d741a5dSApple OSS Distributions  * private flags used by by the cluster layer
246*8d741a5dSApple OSS Distributions  */
247*8d741a5dSApple OSS Distributions #define B_COMMIT_UPL    0x40000000      /* commit/abort the UPL on I/O success/failure */
248*8d741a5dSApple OSS Distributions #define B_TDONE         0x80000000      /* buf_t that is part of a cluster level transaction has completed */
249*8d741a5dSApple OSS Distributions 
250*8d741a5dSApple OSS Distributions /* Flags to low-level allocation routines. */
251*8d741a5dSApple OSS Distributions #define B_CLRBUF        0x01    /* Request allocated buffer be cleared. */
252*8d741a5dSApple OSS Distributions #define B_SYNC          0x02    /* Do all allocations synchronously. */
253*8d741a5dSApple OSS Distributions #define B_NOBUFF        0x04    /* Do not allocate struct buf */
254*8d741a5dSApple OSS Distributions 
255*8d741a5dSApple OSS Distributions /*
256*8d741a5dSApple OSS Distributions  * ba_flags (Buffer Attribute flags)
257*8d741a5dSApple OSS Distributions  * Some of these may be in-use only on embedded devices.
258*8d741a5dSApple OSS Distributions  */
259*8d741a5dSApple OSS Distributions #define BA_RAW_ENCRYPTED_IO     0x00000001
260*8d741a5dSApple OSS Distributions #define BA_THROTTLED_IO         0x00000002
261*8d741a5dSApple OSS Distributions #define BA_DELAYIDLESLEEP       0x00000004      /* Process is marked to delay idle sleep on disk IO */
262*8d741a5dSApple OSS Distributions #define BA_NOCACHE              0x00000008
263*8d741a5dSApple OSS Distributions #define BA_META                 0x00000010
264*8d741a5dSApple OSS Distributions #define BA_GREEDY_MODE          0x00000020      /* High speed writes that consume more storage */
265*8d741a5dSApple OSS Distributions #define BA_QUICK_COMPLETE       0x00000040      /* Request quick completion at expense of storage efficiency */
266*8d741a5dSApple OSS Distributions #define BA_PASSIVE              0x00000080
267*8d741a5dSApple OSS Distributions 
268*8d741a5dSApple OSS Distributions /*
269*8d741a5dSApple OSS Distributions  * Note: IO_TIERs consume 0x0100, 0x0200, 0x0400, 0x0800
270*8d741a5dSApple OSS Distributions  * These are now in-use by the I/O tiering system.
271*8d741a5dSApple OSS Distributions  */
272*8d741a5dSApple OSS Distributions #define BA_IO_TIER_MASK         0x00000f00
273*8d741a5dSApple OSS Distributions #define BA_IO_TIER_SHIFT        8
274*8d741a5dSApple OSS Distributions 
275*8d741a5dSApple OSS Distributions #define BA_ISOCHRONOUS          0x00001000 /* device specific isochronous throughput to media */
276*8d741a5dSApple OSS Distributions 
277*8d741a5dSApple OSS Distributions #define BA_STRATEGY_TRACKED_IO  0x00002000 /* tracked by spec_strategy */
278*8d741a5dSApple OSS Distributions #define BA_IO_TIER_UPGRADE      0x00004000 /* effective I/O tier is higher than BA_IO_TIER */
279*8d741a5dSApple OSS Distributions #define BA_IO_SCHEDULED         0x00008000 /* buf is associated with a mount point that is io scheduled */
280*8d741a5dSApple OSS Distributions #define BA_EXPEDITED_META_IO    0x00010000 /* metadata I/O which needs a high I/O tier */
281*8d741a5dSApple OSS Distributions #define BA_WILL_VERIFY          0x00020000 /* Cluster layer will verify data */
282*8d741a5dSApple OSS Distributions #define BA_ASYNC_VERIFY         0x00040000 /* Allowed to hand off to async threads */
283*8d741a5dSApple OSS Distributions 
284*8d741a5dSApple OSS Distributions #define GET_BUFATTR_IO_TIER(bap)        ((bap->ba_flags & BA_IO_TIER_MASK) >> BA_IO_TIER_SHIFT)
285*8d741a5dSApple OSS Distributions #define SET_BUFATTR_IO_TIER(bap, tier)                                          \
286*8d741a5dSApple OSS Distributions do {                                                                            \
287*8d741a5dSApple OSS Distributions 	(bap)->ba_flags &= (~BA_IO_TIER_MASK);                                  \
288*8d741a5dSApple OSS Distributions 	(bap)->ba_flags |= (((tier) << BA_IO_TIER_SHIFT) & BA_IO_TIER_MASK);    \
289*8d741a5dSApple OSS Distributions } while(0)
290*8d741a5dSApple OSS Distributions 
291*8d741a5dSApple OSS Distributions extern int niobuf_headers;              /* The number of IO buffer headers for cluster IO */
292*8d741a5dSApple OSS Distributions extern int nbuf_headers;                /* The number of buffer headers */
293*8d741a5dSApple OSS Distributions extern int max_nbuf_headers;            /* The max number of buffer headers */
294*8d741a5dSApple OSS Distributions extern int nbuf_hashelements;           /* The number of elements in bufhash */
295*8d741a5dSApple OSS Distributions extern struct buf *buf_headers;         /* The buffer headers. */
296*8d741a5dSApple OSS Distributions 
297*8d741a5dSApple OSS Distributions 
298*8d741a5dSApple OSS Distributions /*
299*8d741a5dSApple OSS Distributions  * Definitions for the buffer free lists.
300*8d741a5dSApple OSS Distributions  */
301*8d741a5dSApple OSS Distributions 
302*8d741a5dSApple OSS Distributions enum bq_opts {
303*8d741a5dSApple OSS Distributions 	BQ_LOCKED   = 0,  /* super-blocks &c */
304*8d741a5dSApple OSS Distributions 	BQ_LRU      = 1,  /* lru, useful buffers */
305*8d741a5dSApple OSS Distributions 	BQ_AGE      = 2,  /* rubbish */
306*8d741a5dSApple OSS Distributions 	BQ_EMPTY    = 3,  /* buffer headers with no memory */
307*8d741a5dSApple OSS Distributions 	BQ_META     = 4,  /* buffer containing metadata */
308*8d741a5dSApple OSS Distributions 	BQ_LAUNDRY  = 5,  /* buffers that need cleaning */
309*8d741a5dSApple OSS Distributions 	BQUEUES     = 6   /* number of free buffer queues */
310*8d741a5dSApple OSS Distributions };
311*8d741a5dSApple OSS Distributions 
312*8d741a5dSApple OSS Distributions #define CLUSTER_IO_BLOCK_SIZE 0x1000
313*8d741a5dSApple OSS Distributions 
314*8d741a5dSApple OSS Distributions __BEGIN_DECLS
315*8d741a5dSApple OSS Distributions 
316*8d741a5dSApple OSS Distributions buf_t   alloc_io_buf(vnode_t, int);
317*8d741a5dSApple OSS Distributions void    free_io_buf(buf_t);
318*8d741a5dSApple OSS Distributions 
319*8d741a5dSApple OSS Distributions int     allocbuf(struct buf *, int);
320*8d741a5dSApple OSS Distributions void    bufinit(void);
321*8d741a5dSApple OSS Distributions 
322*8d741a5dSApple OSS Distributions void    buf_list_lock(void);
323*8d741a5dSApple OSS Distributions void    buf_list_unlock(void);
324*8d741a5dSApple OSS Distributions 
325*8d741a5dSApple OSS Distributions void    cluster_init(void);
326*8d741a5dSApple OSS Distributions 
327*8d741a5dSApple OSS Distributions uint32_t     count_busy_buffers(void);
328*8d741a5dSApple OSS Distributions 
329*8d741a5dSApple OSS Distributions int buf_flushdirtyblks_skipinfo(vnode_t, int, int, const char *);
330*8d741a5dSApple OSS Distributions void buf_wait_for_shadow_io(vnode_t, daddr64_t);
331*8d741a5dSApple OSS Distributions 
332*8d741a5dSApple OSS Distributions #ifdef BUF_MAKE_PRIVATE
333*8d741a5dSApple OSS Distributions errno_t buf_make_private(buf_t bp);
334*8d741a5dSApple OSS Distributions #endif
335*8d741a5dSApple OSS Distributions 
336*8d741a5dSApple OSS Distributions #ifdef CONFIG_PROTECT
337*8d741a5dSApple OSS Distributions void buf_setcpoff(buf_t, uint64_t);
338*8d741a5dSApple OSS Distributions #endif
339*8d741a5dSApple OSS Distributions 
340*8d741a5dSApple OSS Distributions vnode_t buf_vnop_vnode(buf_t);
341*8d741a5dSApple OSS Distributions 
342*8d741a5dSApple OSS Distributions __END_DECLS
343*8d741a5dSApple OSS Distributions 
344*8d741a5dSApple OSS Distributions 
345*8d741a5dSApple OSS Distributions /*
346*8d741a5dSApple OSS Distributions  *	Stats on usefulness of the buffer cache
347*8d741a5dSApple OSS Distributions  */
348*8d741a5dSApple OSS Distributions struct bufstats {
349*8d741a5dSApple OSS Distributions 	long    bufs_incore;            /* found incore */
350*8d741a5dSApple OSS Distributions 	long    bufs_busyincore;        /* found incore. was busy */
351*8d741a5dSApple OSS Distributions 	long    bufs_vmhits;            /* not incore. found in VM */
352*8d741a5dSApple OSS Distributions 	long    bufs_miss;                      /* not incore. not in VM */
353*8d741a5dSApple OSS Distributions 	long    bufs_sleeps;            /* buffer starvation */
354*8d741a5dSApple OSS Distributions 	long    bufs_eblk;                      /* Calls to geteblk */
355*8d741a5dSApple OSS Distributions 	uint32_t    bufs_iobufmax;          /* Max. number of IO buffers used */
356*8d741a5dSApple OSS Distributions 	uint32_t    bufs_iobufinuse;        /* number of IO buffers in use */
357*8d741a5dSApple OSS Distributions 	long    bufs_iobufsleeps;       /* IO buffer starvation */
358*8d741a5dSApple OSS Distributions 	long    bufs_iobufinuse_vdev;   /* number of IO buffers in use by
359*8d741a5dSApple OSS Distributions 	                                 *  diskimages */
360*8d741a5dSApple OSS Distributions };
361*8d741a5dSApple OSS Distributions 
362*8d741a5dSApple OSS Distributions #endif /* KERNEL */
363*8d741a5dSApple OSS Distributions #endif /* !_SYS_BUF_H_ */
364