1 1.14 christos /* $NetBSD: bufcache.h,v 1.14 2018/03/30 12:56:46 christos Exp $ */ 2 1.1 perseant 3 1.1 perseant /*- 4 1.1 perseant * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. 5 1.1 perseant * All rights reserved. 6 1.1 perseant * 7 1.1 perseant * This code is derived from software contributed to The NetBSD Foundation 8 1.1 perseant * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 1.1 perseant * NASA Ames Research Center. 10 1.1 perseant * 11 1.1 perseant * Redistribution and use in source and binary forms, with or without 12 1.1 perseant * modification, are permitted provided that the following conditions 13 1.1 perseant * are met: 14 1.1 perseant * 1. Redistributions of source code must retain the above copyright 15 1.1 perseant * notice, this list of conditions and the following disclaimer. 16 1.1 perseant * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 perseant * notice, this list of conditions and the following disclaimer in the 18 1.1 perseant * documentation and/or other materials provided with the distribution. 19 1.1 perseant * 20 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.1 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.1 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.1 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.1 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.1 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.1 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.1 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.1 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.1 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.1 perseant * POSSIBILITY OF SUCH DAMAGE. 31 1.1 perseant */ 32 1.1 perseant 33 1.1 perseant /* 34 1.1 perseant * Copyright (c) 1982, 1986, 1989, 1993 35 1.1 perseant * The Regents of the University of California. All rights reserved. 36 1.1 perseant * (c) UNIX System Laboratories, Inc. 37 1.1 perseant * All or some portions of this file are derived from material licensed 38 1.1 perseant * to the University of California by American Telephone and Telegraph 39 1.1 perseant * Co. or Unix System Laboratories, Inc. and are reproduced herein with 40 1.1 perseant * the permission of UNIX System Laboratories, Inc. 41 1.1 perseant * 42 1.1 perseant * Redistribution and use in source and binary forms, with or without 43 1.1 perseant * modification, are permitted provided that the following conditions 44 1.1 perseant * are met: 45 1.1 perseant * 1. Redistributions of source code must retain the above copyright 46 1.1 perseant * notice, this list of conditions and the following disclaimer. 47 1.1 perseant * 2. Redistributions in binary form must reproduce the above copyright 48 1.1 perseant * notice, this list of conditions and the following disclaimer in the 49 1.1 perseant * documentation and/or other materials provided with the distribution. 50 1.2 agc * 3. Neither the name of the University nor the names of its contributors 51 1.1 perseant * may be used to endorse or promote products derived from this software 52 1.1 perseant * without specific prior written permission. 53 1.1 perseant * 54 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55 1.1 perseant * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56 1.1 perseant * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57 1.1 perseant * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58 1.1 perseant * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 1.1 perseant * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60 1.1 perseant * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 1.1 perseant * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62 1.1 perseant * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63 1.1 perseant * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64 1.1 perseant * SUCH DAMAGE. 65 1.1 perseant * 66 1.1 perseant * @(#)buf.h 8.9 (Berkeley) 3/30/95 67 1.1 perseant */ 68 1.1 perseant 69 1.1 perseant #define BUF_CACHE_SIZE 1000 70 1.1 perseant 71 1.1 perseant /* 72 1.1 perseant * The buffer header describes an I/O operation. 73 1.1 perseant */ 74 1.1 perseant struct ubuf { 75 1.1 perseant LIST_ENTRY(ubuf) b_hash; /* Hash chain. */ 76 1.1 perseant LIST_ENTRY(ubuf) b_vnbufs; /* Buffer's associated vnode. */ 77 1.1 perseant TAILQ_ENTRY(ubuf) b_freelist; /* Free list position if not active. */ 78 1.1 perseant volatile long b_flags; /* B_* flags. */ 79 1.1 perseant long b_bcount; /* Valid bytes in buffer. */ 80 1.1 perseant #undef b_data 81 1.1 perseant char *b_data; /* Data in buffer */ 82 1.1 perseant daddr_t b_lblkno; /* Logical block number. */ 83 1.1 perseant daddr_t b_blkno; /* Underlying physical block number */ 84 1.1 perseant struct uvnode *b_vp; /* File vnode. */ 85 1.4 perseant int b_hashval; /* Hash value */ 86 1.9 ad void (*b_iodone)(void *); /* unused */ 87 1.1 perseant }; 88 1.1 perseant 89 1.1 perseant #define b_bufsize b_bcount 90 1.1 perseant 91 1.1 perseant /* 92 1.1 perseant * These flags are kept in b_flags. 93 1.1 perseant */ 94 1.1 perseant #define B_AGE 0x00000001 /* Move to age queue when I/O done. */ 95 1.1 perseant #define B_BUSY 0x00000010 /* I/O in progress. */ 96 1.1 perseant #define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */ 97 1.1 perseant #define B_DONE 0x00000200 /* I/O completed. */ 98 1.1 perseant #define B_ERROR 0x00000800 /* I/O error occurred. */ 99 1.1 perseant #define B_GATHERED 0x00001000 /* LFS: already in a segment. */ 100 1.1 perseant #define B_INVAL 0x00002000 /* Does not contain valid info. */ 101 1.1 perseant #define B_LOCKED 0x00004000 /* Locked in core (not reusable). */ 102 1.1 perseant #define B_READ 0x00100000 /* Read buffer. */ 103 1.5 perseant #define B_DONTFREE 0x00010000 /* b_data not managed by bufcache */ 104 1.1 perseant 105 1.9 ad #define b_cflags b_flags 106 1.9 ad 107 1.1 perseant LIST_HEAD(bufhash_struct, ubuf); 108 1.1 perseant 109 1.7 yamt #if !defined(NOCRED) 110 1.7 yamt #define NOCRED ((void *)-1) /* dummy; not actually used */ 111 1.7 yamt #endif /* !defined(NOCRED) */ 112 1.7 yamt 113 1.4 perseant void bufinit(int); 114 1.4 perseant void bufrehash(int); 115 1.1 perseant void bufstats(void); 116 1.1 perseant void buf_destroy(struct ubuf *); 117 1.1 perseant void bremfree(struct ubuf *); 118 1.14 christos struct ubuf *incore(struct uvnode *, daddr_t); 119 1.1 perseant struct ubuf *getblk(struct uvnode *, daddr_t, int); 120 1.1 perseant void bwrite(struct ubuf *); 121 1.8 ad void brelse(struct ubuf *, int); 122 1.12 chopps int bread(struct uvnode *, daddr_t, int, int, struct ubuf **); 123 1.1 perseant void reassignbuf(struct ubuf *, struct uvnode *); 124 1.3 perseant void dump_free_lists(void); 125