[syslinux:master] btrfs: initialize the block cache early

syslinux-bot for H. Peter Anvin hpa at zytor.com
Fri Jun 25 20:36:02 PDT 2010


Commit-ID:  4b038f7218b382a146a101b685264ca425c13811
Gitweb:     http://syslinux.zytor.com/commit/4b038f7218b382a146a101b685264ca425c13811
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Fri, 25 Jun 2010 20:34:26 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Fri, 25 Jun 2010 20:34:26 -0700

btrfs: initialize the block cache early

Initialize the block cache at the very start.  The block size for
btrfs is fixed, and so we can start by initializing the cache.  That
eliminates a whole bunch of unnecessary I/O as well as extra code.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 core/fs/btrfs/btrfs.c |   49 +++++--------------------------------------------
 1 files changed, 5 insertions(+), 44 deletions(-)

diff --git a/core/fs/btrfs/btrfs.c b/core/fs/btrfs/btrfs.c
index 41e301a..55dce93 100644
--- a/core/fs/btrfs/btrfs.c
+++ b/core/fs/btrfs/btrfs.c
@@ -55,12 +55,9 @@ static int bin_search(void *ptr, int item_size, void *cmp_item, cmp_func func,
 	return 1;
 }
 
-static int cache_ready;
+/* XXX: these should go into the filesystem instance structure */
 static struct btrfs_chunk_map chunk_map;
 static struct btrfs_super_block sb;
-/* used for small chunk read for btrfs_read */
-#define RAW_BUF_SIZE 4096
-static u8 raw_buf[RAW_BUF_SIZE];
 static u64 fs_tree;
 
 static int btrfs_comp_chunk_map(struct btrfs_chunk_map_item *m1,
@@ -128,36 +125,8 @@ static u64 logical_physical(u64 logical)
 			chunk_map.map[slot-1].logical;
 }
 
-/* raw read from disk, offset and count are bytes */
-static int raw_read(struct fs_info *fs, char *buf, u64 offset, u64 count)
-{
-	struct disk *disk = fs->fs_dev->disk;
-	size_t max = RAW_BUF_SIZE >> disk->sector_shift;
-	size_t off, cnt, done, total;
-	sector_t sec;
-
-	total = count;
-	while (count > 0) {
-		sec = offset >> disk->sector_shift;
-		off = offset - (sec << disk->sector_shift);
-		done = disk->rdwr_sectors(disk, raw_buf, sec, max, 0);
-		if (done == 0)/* no data */
-			break;
-		cnt = (done << disk->sector_shift) - off;
-		if (cnt > count)
-			cnt = count;
-		memcpy(buf, raw_buf + off, cnt);
-		count -= cnt;
-		buf += cnt;
-		offset += cnt;
-		if (done != max)/* no enough sectors */
-			break;
-	}
-	return total - count;
-}
-
 /* cache read from disk, offset and count are bytes */
-static int cache_read(struct fs_info *fs, char *buf, u64 offset, u64 count)
+static int btrfs_read(struct fs_info *fs, char *buf, u64 offset, u64 count)
 {
 	const char *cd;
 	size_t block_size = fs->fs_dev->cache_block_size;
@@ -182,13 +151,6 @@ static int cache_read(struct fs_info *fs, char *buf, u64 offset, u64 count)
 	return total - count;
 }
 
-static int btrfs_read(struct fs_info *fs, char *buf, u64 offset, u64 count)
-{
-	if (cache_ready)
-		return cache_read(fs, buf, offset, count);
-	return raw_read(fs, buf, offset, count);
-}
-
 /* btrfs has several super block mirrors, need to calculate their location */
 static inline u64 btrfs_sb_offset(int mirror)
 {
@@ -674,16 +636,15 @@ static int btrfs_fs_init(struct fs_info *fs)
 	fs->block_shift  = BTRFS_BLOCK_SHIFT;
 	fs->block_size   = 1 << fs->block_shift;
 
+	/* Initialize the block cache */
+	cache_init(fs->fs_dev, fs->block_shift);
+
 	btrfs_read_super_block(fs);
 	if (strncmp((char *)(&sb.magic), BTRFS_MAGIC, sizeof(sb.magic)))
 		return -1;
 	btrfs_read_sys_chunk_array();
 	btrfs_read_chunk_tree(fs);
 	btrfs_get_fs_tree(fs);
-	cache_ready = 1;
-
-	/* Initialize the block cache */
-	cache_init(fs->fs_dev, fs->block_shift);
 
 	return fs->block_shift;
 }



More information about the Syslinux-commits mailing list