]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/buf_internal.h
ec3a84dcc2285676ee1fe1f1ee445ca77a1cb1a8
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)buf.h 8.9 (Berkeley) 3/30/95
63 #ifndef _SYS_BUF_INTERNAL_H_
64 #define _SYS_BUF_INTERNAL_H_
66 #include <sys/appleapiopts.h>
69 #include <sys/queue.h>
70 #include <sys/errno.h>
72 #include <sys/cdefs.h>
77 #define NOLIST ((struct buf *)0x87654321)
80 * The buffer header describes an I/O operation in the kernel.
83 LIST_ENTRY(buf
) b_hash
; /* Hash chain. */
84 LIST_ENTRY(buf
) b_vnbufs
; /* Buffer's associated vnode. */
85 TAILQ_ENTRY(buf
) b_freelist
; /* Free list position if not active. */
86 int b_timestamp
; /* timestamp for queuing operation */
87 long b_whichq
; /* the free list the buffer belongs to */
88 volatile long b_flags
; /* B_* flags. */
89 volatile long b_lflags
; /* BL_BUSY | BL_WANTED flags... protected by buf_mtx */
90 int b_error
; /* errno value. */
91 long b_bufsize
; /* Allocated buffer size. */
92 long b_bcount
; /* Valid bytes in buffer. */
93 long b_resid
; /* Remaining I/O. */
94 dev_t b_dev
; /* Device associated with buffer. */
95 uintptr_t b_datap
; /* Memory, superblocks, indirect etc.*/
96 daddr64_t b_lblkno
; /* Logical block number. */
97 daddr64_t b_blkno
; /* Underlying physical block number. */
98 void (*b_iodone
)(buf_t
, void *); /* Function to call upon completion. */
99 vnode_t b_vp
; /* Device vnode. */
100 struct ucred
*b_rcred
; /* Read credentials reference. */
101 struct ucred
*b_wcred
; /* Write credentials reference. */
102 void * b_upl
; /* Pointer to UPL */
103 buf_t b_real_bp
; /* used to track bp generated through cluster_bp */
104 TAILQ_ENTRY(buf
) b_act
; /* Device driver queue when active */
105 void * b_drvdata
; /* Device driver private use */
106 void * b_fsprivate
; /* filesystem private use */
107 void * b_transaction
; /* journal private use */
108 int b_dirtyoff
; /* Offset in buffer of dirty region. */
109 int b_dirtyend
; /* Offset of end of dirty region. */
110 int b_validoff
; /* Offset in buffer of valid region. */
111 int b_validend
; /* Offset of end of valid region. */
112 proc_t b_proc
; /* Associated proc; NULL if kernel. */
117 int b_stackbrelse
[6];
118 int b_stackgetblk
[6];
123 /* cluster_io definitions for use with io bufs */
124 #define b_uploffset b_bufsize
125 #define b_trans_head b_freelist.tqe_prev
126 #define b_trans_next b_freelist.tqe_next
127 #define b_iostate b_rcred
130 * These flags are kept in b_lflags...
131 * buf_mtxp must be held before examining/updating
133 #define BL_BUSY 0x00000001 /* I/O in progress. */
134 #define BL_WANTED 0x00000002 /* Process wants this buffer. */
135 #define BL_IOBUF 0x00000004 /* buffer allocated via 'buf_alloc' */
139 * mask used by buf_flags... these are the readable external flags
141 #define BUF_X_RDFLAGS (B_CLUSTER | B_PHYS | B_LOCKED | B_DELWRI | B_ASYNC |\
142 B_READ | B_WRITE | B_META | B_PAGEIO)
144 * mask used by buf_clearflags/buf_setflags... these are the writable external flags
146 #define BUF_X_WRFLAGS (B_LOCKED | B_NOCACHE | B_ASYNC | B_READ | B_WRITE | B_PAGEIO)
149 * These flags are kept in b_flags... access is lockless
150 * External flags are defined in buf.h and cannot overlap
153 * these flags are internal... there definition may change
155 #define B_CACHE 0x00010000 /* getblk found us in the cache. */
156 #define B_DONE 0x00020000 /* I/O completed. */
157 #define B_INVAL 0x00040000 /* Does not contain valid info. */
158 #define B_ERROR 0x00080000 /* I/O error occurred. */
159 #define B_EINTR 0x00100000 /* I/O was interrupted */
160 #define B_AGE 0x00200000 /* Move to age queue when I/O done. */
161 #define B_FILTER 0x00400000 /* call b_iodone from biodone as an in-line filter */
162 #define B_CALL 0x00800000 /* Call b_iodone from biodone, assumes b_iodone consumes bp */
163 #define B_RAW 0x01000000 /* Set by physio for raw transfers. */
164 #define B_WASDIRTY 0x02000000 /* page was found dirty in the VM cache */
165 #define B_HDRALLOC 0x04000000 /* zone allocated buffer header */
166 #define B_ZALLOC 0x08000000 /* b_datap is zalloc()ed */
168 * private flags used by the journal layer
170 #define B_NORELSE 0x10000000 /* don't brelse() in bwrite() */
172 * private flags used by by the cluster layer
174 #define B_NEED_IODONE 0x20000000 /* need biodone on the real_bp associated with a cluster_io */
175 #define B_COMMIT_UPL 0x40000000 /* commit/abort the UPL on I/O success/failure */
179 #define B_TAPE 0x80000000 /* Magnetic tape I/O. */
182 /* Flags to low-level allocation routines. */
183 #define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
184 #define B_SYNC 0x02 /* Do all allocations synchronously. */
185 #define B_NOBUFF 0x04 /* Do not allocate struct buf */
188 extern int niobuf
; /* The number of IO buffer headers for cluster IO */
189 extern int nbuf
; /* The number of buffer headers */
190 extern struct buf
*buf
; /* The buffer headers. */
191 extern int max_nbuf_headers
; /* The max number of buffer headers */
192 extern int nbuf_hashelements
; /* The number of elements in bufhash */
196 * Definitions for the buffer free lists.
198 #define BQUEUES 6 /* number of free buffer queues */
200 #define BQ_LOCKED 0 /* super-blocks &c */
201 #define BQ_LRU 1 /* lru, useful buffers */
202 #define BQ_AGE 2 /* rubbish */
203 #define BQ_EMPTY 3 /* buffer headers with no memory */
204 #define BQ_META 4 /* buffer containing metadata */
205 #define BQ_LAUNDRY 5 /* buffers that need cleaning */
210 buf_t
alloc_io_buf(vnode_t
, int);
211 void free_io_buf(buf_t
);
213 int allocbuf(struct buf
*, int);
216 void buf_setfilter(buf_t
, void (*)(buf_t
, void *), void *, void **, void **);
219 * Flags for buf_acquire
221 #define BAC_NOWAIT 0x01 /* Don't wait if buffer is busy */
222 #define BAC_REMOVE 0x02 /* Remove from free list once buffer is acquired */
223 #define BAC_SKIP_NONLOCKED 0x04 /* Don't return LOCKED buffers */
224 #define BAC_SKIP_LOCKED 0x08 /* Only return LOCKED buffers */
226 void cluster_init(void);
227 void buf_drop(buf_t
);
228 errno_t
buf_acquire(buf_t
, int, int, int);
230 int count_busy_buffers(void);
231 int count_lock_queue(void);
238 * Stats on usefulness of the buffer cache
241 long bufs_incore
; /* found incore */
242 long bufs_busyincore
; /* found incore. was busy */
243 long bufs_vmhits
; /* not incore. found in VM */
244 long bufs_miss
; /* not incore. not in VM */
245 long bufs_sleeps
; /* buffer starvation */
246 long bufs_eblk
; /* Calls to geteblk */
247 long bufs_iobufmax
; /* Max. number of IO buffers used */
248 long bufs_iobufinuse
; /* number of IO buffers in use */
249 long bufs_iobufsleeps
; /* IO buffer starvation */
253 #endif /* !_SYS_BUF_H_ */