From 49532259e5e915ee294bc2d7f966615ab26ceed3 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 21 Sep 2011 17:52:45 +0000 Subject: [PATCH] mfs: improve & simplify secondary cache logic . fixes "!" errors when booting from cd --- servers/mfs/cache.c | 31 ++++++++++++++----------------- servers/mfs/read.c | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/servers/mfs/cache.c b/servers/mfs/cache.c index 96715f6c5..49a82ebdd 100644 --- a/servers/mfs/cache.c +++ b/servers/mfs/cache.c @@ -28,7 +28,7 @@ FORWARD _PROTOTYPE( void rm_lru, (struct buf *bp) ); FORWARD _PROTOTYPE( void rw_block, (struct buf *, int) ); -PRIVATE int vmcache_avail = -1; /* 0 if not available, >0 if available. */ +PRIVATE int vmcache = 0; /* are we using vm's secondary cache? (initially not) */ /*===========================================================================* * get_block * @@ -57,27 +57,11 @@ PUBLIC struct buf *get_block( int b; static struct buf *bp, *prev_ptr; u64_t yieldid = VM_BLOCKID_NONE, getid = make64(dev, block); - int vmcache = 0; assert(buf_hash); assert(buf); assert(nr_bufs > 0); - if(vmcache_avail < 0) { - /* Test once for the availability of the vm yield block feature. */ - if(vm_forgetblock(VM_BLOCKID_NONE) == ENOSYS) { - vmcache_avail = 0; - } else { - vmcache_avail = 1; - } - } - - /* use vmcache if it's available, and allowed, and we're not doing - * i/o on a ram disk device. - */ - if(vmcache_avail && may_use_vmcache && major(dev) != MEMORY_MAJOR) - vmcache = 1; - ASSERT(fs_block_size > 0); /* Search the hash chain for (dev, block). Do_read() can use @@ -586,6 +570,19 @@ PUBLIC void set_blocksize(struct super_block *sp) cache_resize(sp->s_block_size, MINBUFS); bufs = bufs_heuristic(sp); cache_resize(sp->s_block_size, bufs); + + /* Decide whether to use seconday cache or not. + * Only do this if + * - it's available, and + * - use of it hasn't been disabled for this fs, and + * - our main FS device isn't a memory device + */ + + vmcache = 0; + if(vm_forgetblock(VM_BLOCKID_NONE) != ENOSYS && + may_use_vmcache && major(sp->s_dev) != MEMORY_MAJOR) { + vmcache = 1; + } } /*===========================================================================* diff --git a/servers/mfs/read.c b/servers/mfs/read.c index ae1a22367..abf0af653 100644 --- a/servers/mfs/read.c +++ b/servers/mfs/read.c @@ -412,7 +412,7 @@ PUBLIC void read_ahead() rdahed_inode = NULL; /* turn off read ahead */ if ( (b = read_map(rip, rdahedpos)) == NO_BLOCK) return; /* at EOF */ - assert(rdahedpos > 0); /* So we can safely cast it to unsigned below */ + assert(rdahedpos >= 0); /* So we can safely cast it to unsigned below */ bp = rahead(rip, b, cvul64( (unsigned long) rdahedpos), block_size); put_block(bp, PARTIAL_DATA_BLOCK); -- 2.44.0