|
Lines 23-29
Link Here
|
| 23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 |
* SUCH DAMAGE. |
24 |
* SUCH DAMAGE. |
| 25 |
* |
25 |
* |
| 26 |
* $Id: bcache.c,v 1.4.2.1 1999/02/06 14:27:29 dcs Exp $ |
26 |
* $Id: bcache.c,v 1.2 2000/02/18 22:35:19 jhood Exp $ |
| 27 |
*/ |
27 |
*/ |
| 28 |
|
28 |
|
| 29 |
/* |
29 |
/* |
|
Lines 62-78
Link Here
|
| 62 |
static int bcache_hits, bcache_misses, bcache_ops, bcache_bypasses; |
62 |
static int bcache_hits, bcache_misses, bcache_ops, bcache_bypasses; |
| 63 |
static int bcache_bcount; |
63 |
static int bcache_bcount; |
| 64 |
|
64 |
|
|
|
65 |
static void *bcache_dkstrategy; |
| 66 |
static int bcache_dkunit; |
| 67 |
|
| 65 |
static void bcache_insert(caddr_t buf, daddr_t blkno); |
68 |
static void bcache_insert(caddr_t buf, daddr_t blkno); |
| 66 |
static int bcache_lookup(caddr_t buf, daddr_t blkno); |
69 |
static int bcache_lookup(caddr_t buf, daddr_t blkno); |
| 67 |
|
70 |
|
| 68 |
/* |
71 |
/* |
|
|
72 |
* Invalidate the cache |
| 73 |
*/ |
| 74 |
void |
| 75 |
bcache_flush(void) |
| 76 |
{ |
| 77 |
int i; |
| 78 |
|
| 79 |
if (bcache_data != NULL) { |
| 80 |
for (i = 0; i < bcache_nblks; i++) { |
| 81 |
bcache_ctl[i].bc_count = -1; |
| 82 |
bcache_ctl[i].bc_blkno = -1; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
/* |
| 69 |
* Initialise the cache for (nblks) of (bsize). |
87 |
* Initialise the cache for (nblks) of (bsize). |
| 70 |
*/ |
88 |
*/ |
| 71 |
int |
89 |
int |
| 72 |
bcache_init(int nblks, size_t bsize) |
90 |
bcache_init(int nblks, size_t bsize) |
| 73 |
{ |
91 |
{ |
| 74 |
int i; |
|
|
| 75 |
|
| 76 |
/* discard any old contents */ |
92 |
/* discard any old contents */ |
| 77 |
if (bcache_data != NULL) { |
93 |
if (bcache_data != NULL) { |
| 78 |
free(bcache_data); |
94 |
free(bcache_data); |
|
Lines 97-107
Link Here
|
| 97 |
return(ENOMEM); |
113 |
return(ENOMEM); |
| 98 |
} |
114 |
} |
| 99 |
|
115 |
|
| 100 |
/* Invalidate the cache */ |
116 |
bcache_dkstrategy = NULL; |
| 101 |
for (i = 0; i < bcache_nblks; i++) { |
117 |
|
| 102 |
bcache_ctl[i].bc_count = -1; |
118 |
/* bcache_flush() will happen on first call to bcache_strategy */ |
| 103 |
bcache_ctl[i].bc_blkno = -1; |
|
|
| 104 |
} |
| 105 |
|
119 |
|
| 106 |
return(0); |
120 |
return(0); |
| 107 |
} |
121 |
} |
|
Lines 130-135
Link Here
|
| 130 |
DEBUG("bypass %d from %d", size / bcache_blksize, blk); |
144 |
DEBUG("bypass %d from %d", size / bcache_blksize, blk); |
| 131 |
bcache_bypasses++; |
145 |
bcache_bypasses++; |
| 132 |
return(dd->dv_strategy(dd->dv_devdata, rw, blk, size, buf, rsize)); |
146 |
return(dd->dv_strategy(dd->dv_devdata, rw, blk, size, buf, rsize)); |
|
|
147 |
} |
| 148 |
|
| 149 |
/* has a new device/unit been requested? flush cache */ |
| 150 |
if ((bcache_dkstrategy != dd->dv_strategy) || |
| 151 |
(bcache_dkunit != dd->dv_dkunit)) { |
| 152 |
DEBUG("cache flush, lastunit = %d newunit = %d", |
| 153 |
bcache_dkunit, dd->dv_dkunit); |
| 154 |
bcache_flush(); |
| 155 |
bcache_dkstrategy = dd->dv_strategy; |
| 156 |
bcache_dkunit = dd->dv_dkunit; |
| 133 |
} |
157 |
} |
| 134 |
|
158 |
|
| 135 |
nblk = size / bcache_blksize; |
159 |
nblk = size / bcache_blksize; |