can't get_block(NO_DEV) any more

. 'anonymous' cache blocks (retrieved with NO_DEV as dev
	  parameter) were used to implement read()s from holes in
	  inodes that should return zeroes
	. this is an awkward special case in the cache code though
	  and there's a more direct way to implement the same functionality:
	  instead of copying from a new, anonymous, zero block, to
	  the user target buffer, simply sys_safememset the user target
	  buffer directly. as this was the only use of this feature,
	  this is all that's needed to simplify the cache code a little.
This commit is contained in:
Ben Gras 2012-11-12 19:15:10 +01:00
parent 2d43bf5807
commit a89ec8bc3b
3 changed files with 49 additions and 47 deletions

View file

@ -156,12 +156,13 @@ struct buf *lmfs_get_block(
ASSERT(fs_block_size > 0);
assert(dev != NO_DEV);
/* Search the hash chain for (dev, block). Do_read() can use
* lmfs_get_block(NO_DEV ...) to get an unnamed block to fill with zeros when
* someone wants to read from a hole in a file, in which case this search
* is skipped
*/
if (dev != NO_DEV) {
b = BUFHASH(block);
bp = buf_hash[b];
while (bp != NULL) {
@ -179,7 +180,6 @@ struct buf *lmfs_get_block(
bp = bp->lmfs_hash; /* move to next block on hash chain */
}
}
}
/* Desired block is not on available chain. Take oldest block ('front'). */
if ((bp = front) == NULL) panic("all buffers in use: %d", nr_bufs);
@ -247,13 +247,7 @@ struct buf *lmfs_get_block(
buf_hash[b] = bp; /* add to hash list */
if(dev == NO_DEV) {
if(vmcache && cmp64(yieldid, VM_BLOCKID_NONE) != 0) {
vm_yield_block_get_block(yieldid, VM_BLOCKID_NONE,
bp->data, fs_block_size);
}
return(bp); /* If the caller wanted a NO_DEV block, work is done. */
}
assert(dev != NO_DEV);
/* Go get the requested block unless searching or prefetching. */
if(only_search == PREFETCH || only_search == NORMAL) {
@ -354,11 +348,12 @@ register struct buf *bp; /* buffer pointer */
*/
int r, op_failed;
u64_t pos;
dev_t dev;
dev_t dev = bp->lmfs_dev;
op_failed = 0;
if ( (dev = bp->lmfs_dev) != NO_DEV) {
assert(dev != NO_DEV);
pos = mul64u(bp->lmfs_blocknr, fs_block_size);
r = bdev_read(dev, pos, bp->data, fs_block_size,
BDEV_NOFLAGS);
@ -378,7 +373,6 @@ register struct buf *bp; /* buffer pointer */
rdwt_err = r;
}
}
}
/*===========================================================================*
* lmfs_invalidate *

View file

@ -237,8 +237,12 @@ int *completed; /* number of bytes copied */
if (!block_spec && b == NO_BLOCK) {
if (rw_flag == READING) {
/* Reading from a nonexistent block. Must read as all zeros.*/
bp = get_block(NO_DEV, NO_BLOCK, NORMAL); /* get a buffer */
zero_block(bp);
r = sys_safememset(VFS_PROC_NR, gid, (vir_bytes) buf_off,
0, (size_t) chunk);
if(r != OK) {
printf("ext2fs: sys_safememset failed\n");
}
return r;
} else {
/* Writing to a nonexistent block. Create and enter in inode.*/
if ((bp = new_block(rip, (off_t) ex64lo(position))) == NULL)

View file

@ -246,8 +246,12 @@ int *completed; /* number of bytes copied */
if (!block_spec && b == NO_BLOCK) {
if (rw_flag == READING) {
/* Reading from a nonexistent block. Must read as all zeros.*/
bp = get_block(NO_DEV, NO_BLOCK, NORMAL); /* get a buffer */
zero_block(bp);
r = sys_safememset(VFS_PROC_NR, gid, (vir_bytes) buf_off,
0, (size_t) chunk);
if(r != OK) {
printf("MFS: sys_safememset failed\n");
}
return r;
} else {
/* Writing to a nonexistent block. Create and enter in inode.*/
if ((bp = new_block(rip, (off_t) ex64lo(position))) == NULL)