Move primary cache code to libminixfs.

Add primary cache management feature to libminixfs as mfs and ext2
currently do separately, remove cache code from mfs and ext2, and make
them use the libminixfs interface. This makes all fields of the buf
struct private to libminixfs and FS clients aren't supposed to access
them at all. Only the opaque 'void *data' field (the FS block contents,
used to be called bp) is to be accessed by the FS client.

The main purpose is to implement the interface to the 2ndary vm cache
just once, get rid of some code duplication, and add a little
abstraction to reduce the code inertia of the whole caching business.

Some minor sanity checking and prohibition done by mfs in this code
as removed from the generic primary cache code as a result:
        - checking all inodes are not in use when allocating/resizing
          the cache
        - checking readonly filesystems aren't written to
        - checking the superblock isn't written to on mounted filesystems

The minixfslib code relies on fs_blockstats() in the client filesystem to
return some FS usage information.
This commit is contained in:
Ben Gras
2012-10-23 19:48:38 +02:00
parent 280d8c668e
commit bd3cde4571
53 changed files with 927 additions and 1630 deletions
+4 -4
View File
@@ -54,10 +54,10 @@ int map; /* IMAP (inode map) or ZMAP (zone map) */
do {
bp = get_block(sp->s_dev, start_block + block, NORMAL);
assert(bp);
wlim = &bp->b_bitmap[FS_BITMAP_CHUNKS(sp->s_block_size)];
wlim = &b_bitmap(bp)[FS_BITMAP_CHUNKS(sp->s_block_size)];
/* Iterate over the words in block. */
for (wptr = &bp->b_bitmap[word]; wptr < wlim; wptr++) {
for (wptr = &b_bitmap(bp)[word]; wptr < wlim; wptr++) {
/* Does this word contain a free bit? */
if (*wptr == (bitchunk_t) ~0) continue;
@@ -67,7 +67,7 @@ int map; /* IMAP (inode map) or ZMAP (zone map) */
for (i = 0; i < 8*sizeof(k); ++i) {
/* Bit number from the start of the bit map. */
b = ((bit_t) block * FS_BITS_PER_BLOCK(sp->s_block_size))
+ (wptr - &bp->b_bitmap[0]) * FS_BITCHUNK_BITS
+ (wptr - &b_bitmap(bp)[0]) * FS_BITCHUNK_BITS
+ i;
/* Don't count bits beyond the end of the map. */
@@ -92,7 +92,7 @@ int map; /* IMAP (inode map) or ZMAP (zone map) */
/*===========================================================================*
* blockstats *
*===========================================================================*/
void blockstats(u32_t *blocks, u32_t *free, u32_t *used)
void fs_blockstats(u32_t *blocks, u32_t *free, u32_t *used)
{
struct super_block *sp;
int scale;