buf.h revision ed0efa6876ba3b938ff57240b02b5f999f8dcda2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _SYS_BUF_H
#define _SYS_BUF_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Each buffer in the pool is usually doubly linked into 2 lists:
* the device with which it is currently associated (always)
* and also on a list of blocks available for allocation
* for other use (usually).
* The latter list is kept in last-used order, and the two
* lists are doubly linked to make it easy to remove
* a buffer from one list when it was found by
* looking through the other.
* A buffer is on the available list, and is liable
* to be reassigned to another disk block, if and only
* if it is not marked BUSY. When a buffer is busy, the
* available-list pointers can be used for other purposes.
* Most drivers use the forward ptr as a link in their I/O active queue.
* A buffer header contains all the information required to perform I/O.
* Most of the routines which manipulate these things are in bio.c.
*
* There are a number of locks associated with the buffer management
* system.
* hbuf.b_lock: protects hash chains, buffer hdr freelists
* and delayed write freelist
* bfree_lock; protects the bfreelist structure
* bhdr_lock: protects the free header list
* blist_lock: protects b_list fields
* buf.b_sem: protects all remaining members in the buf struct
* buf.b_io: I/O synchronization variable
*
* A buffer header is never "locked" (b_sem) when it is on
* a "freelist" (bhdrlist or bfreelist avail lists).
*/
typedef struct buf {
int b_flags; /* see defines below */
union {
} b_un;
#ifdef _LP64
#else
#endif /* _LP64 */
char b_obs1; /* obsolete */
/* Begin new stuff */
int b_obs3; /* obsolete */
int b_error; /* expanded error field */
void *b_private; /* "opaque" driver private area */
void *b_dip; /* device info pointer */
} buf_t;
/*
* Bufhd structures used at the head of the hashed buffer queues.
* We only need seven words for this, so this abbreviated
* definition saves some space.
*/
struct diskhd {
int b_flags; /* not used, needed for consistency */
};
/*
* Statistics on the buffer cache
*/
struct biostats {
};
/*
* These flags are kept in b_flags.
* The first group is part of the DDI
*/
/* Not part of the DDI */
/*
*/
}
}
/*
* The hash structure maintains two lists:
*
* 1) The hash list of buffers (b_forw & b_back)
* 2) The LRU free list of buffers on this hash bucket (av_forw & av_back)
*
* The dwbuf structure keeps a list of delayed write buffers per hash bucket
* hence there are exactly the same number of dwbuf structures as there are
* the hash buckets (hbuf structures) in the system.
*
* The number of buffers on the freelist may not be equal to the number of
* buffers on the hash list. That is because when buffers are busy they are
* taken off the freelist but not off the hash list. "b_length" field keeps
* track of the number of free buffers (including delayed writes ones) on
* the hash bucket. The "b_lock" mutex protects the free list as well as
* the hash list. It also protects the counter "b_length".
*
* Enties b_forw, b_back, av_forw & av_back must be at the same offset
* as the ones in buf structure.
*/
struct hbuf {
int b_flags;
int b_length; /* # of entries on free list */
};
/*
* The delayed list pointer entries should match with the buf strcuture.
*/
struct dwbuf {
int b_flags; /* not used */
};
/*
* Unlink a buffer from the available (free or delayed write) list and mark
* it busy (internal interface).
*/
{\
}
#if defined(_KERNEL)
/*
* Macros to avoid the extra function call needed for binary compat.
*
* B_RETRYWRI is not included in clear_flags for BWRITE(), BWRITE2(),
* or brwrite() so that the retry operation is persistent until the
* write either succeeds or the buffer is bfinval()'d.
*
*/
/* do_relse */ 1, \
/* do_relse */ 0, \
/*
* Macros for new retry write interfaces.
*/
/*
* Same as bdwrite() except write failures are retried.
*/
}
/*
* Same as bwrite() except write failures are retried.
*/
}
int hash2ints(int x, int y);
int bio_busy(int);
int biomodified(struct buf *);
/*
* ufsvfsp is declared as a void * to avoid having everyone that uses
* this header file include sys/fs/ufs_inode.h.
*/
int do_relse, int clear_flags);
void binit(void);
void *bp_mapin_common(struct buf *, int);
void pageio_done(struct buf *);
#endif /* defined(_KERNEL) */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_BUF_H */