From: Ben Gras Date: Mon, 21 Sep 2009 14:47:51 +0000 (+0000) Subject: - No maximum block size any more. X-Git-Tag: v3.1.5~121 X-Git-Url: http://zhaoyanbai.com/repos/dnssec-importkey.html?a=commitdiff_plain;h=a0d8cc0765203140a736424bb224f26ccaf05630;p=minix.git - No maximum block size any more. - If allocation of a new buffer fails, use an already-allocated unused buffer if available (low memory conditions) - Allocate buffers dynamically, so memory isn't wasted on wrong-sized buffers. - No more _MAX_BLOCK_SIZE. --- diff --git a/servers/mfs/Makefile b/servers/mfs/Makefile index dc22f25d9..84b22cd6b 100644 --- a/servers/mfs/Makefile +++ b/servers/mfs/Makefile @@ -25,7 +25,6 @@ OBJ = cache.o device.o link.o \ all build: $(SERVER) $(SERVER): $(OBJ) $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) - install -S `expr $(NR_BUFS) \* $(BS) \* 2.2` $(SERVER) install: $(SERVER) -mv $(DEST) $(DEST).prev diff --git a/servers/mfs/cache.c b/servers/mfs/cache.c index c75f2321a..1936479a7 100644 --- a/servers/mfs/cache.c +++ b/servers/mfs/cache.c @@ -17,6 +17,7 @@ #include "fs.h" #include #include +#include #include "buf.h" #include "super.h" #include "inode.h" @@ -48,7 +49,7 @@ int only_search; /* if NO_READ, don't read, else act normal */ */ int b; - register struct buf *bp, *prev_ptr; + static struct buf *bp, *prev_ptr; ASSERT(fs_block_size > 0); @@ -79,6 +80,29 @@ int only_search; /* if NO_READ, don't read, else act normal */ /* Desired block is not on available chain. Take oldest block ('front'). */ if ((bp = front) == NIL_BUF) panic(__FILE__,"all buffers in use", NR_BUFS); + + if(bp->b_bytes < fs_block_size) { + phys_bytes ph; + ASSERT(!bp->bp); + ASSERT(bp->b_bytes == 0); + if(!(bp->bp = alloc_contig(fs_block_size, 0, &ph))) { + printf("MFS: couldn't allocate a new block.\n"); + for(bp = front; + bp && bp->b_bytes < fs_block_size; bp = bp->b_next) + ; + if(!bp) { + panic("MFS", "no buffer available", NO_NUM); + } + } else { + bp->b_bytes = fs_block_size; + } + } + + ASSERT(bp); + ASSERT(bp->bp); + ASSERT(bp->b_bytes == fs_block_size); + ASSERT(bp->b_count == 0); + rm_lru(bp); /* Remove the block that was just taken from its hash chain. */ @@ -110,27 +134,14 @@ int only_search; /* if NO_READ, don't read, else act normal */ bp->b_count++; /* record that block is being used */ b = BUFHASH(bp->b_blocknr); bp->b_hash = buf_hash[b]; - if(bp->b_bytes < fs_block_size) { - static int n = 0; - phys_bytes ph; - ASSERT(!bp->bp); - ASSERT(bp->b_bytes == 0); - if(!(bp->bp = alloc_contig(fs_block_size, 0, &ph))) - panic(__FILE__,"couldn't allocate FS buffer", n); - bp->b_bytes = fs_block_size; - n++; - } buf_hash[b] = bp; /* add to hash list */ - SANITYCHECK; - /* Go get the requested block unless searching or prefetching. */ if (dev != NO_DEV) { if (only_search == PREFETCH) bp->b_dev = NO_DEV; else if (only_search == NORMAL) { - SANITYCHECK; rw_block(bp, READING); } } @@ -280,9 +291,7 @@ int rw_flag; /* READING or WRITING */ if ( (dev = bp->b_dev) != NO_DEV) { pos = mul64u(bp->b_blocknr, fs_block_size); op = (rw_flag == READING ? MFS_DEV_READ : MFS_DEV_WRITE); - SANITYCHECK; r = block_dev_io(op, dev, SELF_E, bp->b_data, pos, fs_block_size, 0); - SANITYCHECK; if (r != fs_block_size) { if (r >= 0) r = END_OF_FILE; if (r != END_OF_FILE) diff --git a/servers/mfs/super.c b/servers/mfs/super.c index 4715b6c7c..f511bb36d 100644 --- a/servers/mfs/super.c +++ b/servers/mfs/super.c @@ -285,12 +285,6 @@ register struct super_block *sp; /* pointer to a superblock */ if (sp->s_block_size < _MIN_BLOCK_SIZE) { return EINVAL; } - if (sp->s_block_size > _MAX_BLOCK_SIZE) { - printf("Filesystem block size is %d kB; maximum filesystem\n" - "block size is %d kB. This limit can be increased by recompiling.\n", - sp->s_block_size/1024, _MAX_BLOCK_SIZE/1024); - return EINVAL; - } if ((sp->s_block_size % 512) != 0) { return EINVAL; } diff --git a/servers/mfs/super.h b/servers/mfs/super.h index f86db36ad..42bea7cb8 100644 --- a/servers/mfs/super.h +++ b/servers/mfs/super.h @@ -34,7 +34,7 @@ EXTERN struct super_block { /* The block size in bytes. Minimum MIN_BLOCK SIZE. SECTOR_SIZE * multiple. If V1 or V2 filesystem, this should be - * initialised to STATIC_BLOCK_SIZE. Maximum MAX_BLOCK_SIZE. + * initialised to STATIC_BLOCK_SIZE. */ short s_pad2; /* try to avoid compiler-dependent padding */ unsigned short s_block_size; /* block size in bytes. */