Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128695
b: refs/heads/master
c: 0999df5
h: refs/heads/master
i:
  128693: 1a5a1a2
  128691: 05daa3a
  128687: 1fa2884
v: v3
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent fff5ab7 commit 0c49196
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 37 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ecbe2402cb4e4e7413544dc392c1a78d0f290292
refs/heads/master: 0999df54f850fe1aba29b10d5c869493af107478
5 changes: 5 additions & 0 deletions trunk/fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
} else {
root_gen = 0;
}
if (!(buf->flags & EXTENT_CSUM))
WARN_ON(1);

WARN_ON(root->ref_cows && trans->transid !=
root->fs_info->running_transaction->transid);
Expand Down Expand Up @@ -245,6 +247,8 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans,
root->fs_info->generation);
WARN_ON(1);
}
if (!(buf->flags & EXTENT_CSUM))
WARN_ON(1);

header_trans = btrfs_header_generation(buf);
spin_lock(&root->fs_info->hash_lock);
Expand Down Expand Up @@ -396,6 +400,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
if (search_start == 0)
search_start = last_block;

btrfs_verify_block_csum(root, cur);
err = __btrfs_cow_block(trans, root, cur, parent, i,
&tmp, search_start,
min(16 * blocksize,
Expand Down
86 changes: 50 additions & 36 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,6 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)

static struct extent_io_ops btree_extent_io_ops;

struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
u64 bytenr, u32 blocksize)
{
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_buffer *eb;
eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
bytenr, blocksize, GFP_NOFS);
return eb;
}

struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 bytenr, u32 blocksize)
{
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_buffer *eb;

eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
bytenr, blocksize, NULL, GFP_NOFS);
return eb;
}

struct extent_map *btree_get_extent(struct inode *inode, struct page *page,
size_t page_offset, u64 start, u64 len,
int create)
Expand Down Expand Up @@ -380,36 +359,29 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
return 0;
}

struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
u32 blocksize)
int btrfs_verify_block_csum(struct btrfs_root *root,
struct extent_buffer *buf)
{
struct extent_buffer *buf = NULL;
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_io_tree *io_tree;
u64 end;
int ret;

io_tree = &BTRFS_I(btree_inode)->io_tree;

buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
if (!buf)
return NULL;
read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree, buf, 0, 1,
btree_get_extent);

io_tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
if (buf->flags & EXTENT_CSUM)
return buf;
return 0;

end = buf->start + PAGE_CACHE_SIZE - 1;
end = min_t(u64, buf->len, PAGE_CACHE_SIZE);
end = buf->start + end - 1;
if (test_range_bit(io_tree, buf->start, end, EXTENT_CSUM, 1)) {
buf->flags |= EXTENT_CSUM;
return buf;
return 0;
}

lock_extent(io_tree, buf->start, end, GFP_NOFS);

if (test_range_bit(io_tree, buf->start, end, EXTENT_CSUM, 1)) {
buf->flags |= EXTENT_CSUM;
ret = 0;
goto out_unlock;
}

Expand All @@ -419,6 +391,48 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,

out_unlock:
unlock_extent(io_tree, buf->start, end, GFP_NOFS);
return ret;
}

struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
u64 bytenr, u32 blocksize)
{
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_buffer *eb;
eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
bytenr, blocksize, GFP_NOFS);
return eb;
}

struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 bytenr, u32 blocksize)
{
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_buffer *eb;

eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
bytenr, blocksize, NULL, GFP_NOFS);
return eb;
}


struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
u32 blocksize)
{
struct extent_buffer *buf = NULL;
struct inode *btree_inode = root->fs_info->btree_inode;
struct extent_io_tree *io_tree;
int ret;

io_tree = &BTRFS_I(btree_inode)->io_tree;

buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
if (!buf)
return NULL;
read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree, buf, 0, 1,
btree_get_extent);

ret = btrfs_verify_block_csum(root, buf);
return buf;
}

Expand Down
2 changes: 2 additions & 0 deletions trunk/fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len);
void btrfs_csum_final(u32 crc, char *result);
void btrfs_throttle(struct btrfs_root *root);
int btrfs_open_device(struct btrfs_device *dev);
int btrfs_verify_block_csum(struct btrfs_root *root,
struct extent_buffer *buf);
#endif
2 changes: 2 additions & 0 deletions trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,8 @@ static int noinline walk_down_tree(struct btrfs_trans_handle *trans,
BUG_ON(ret);
continue;
}
} else if (next) {
btrfs_verify_block_csum(root, next);
}
WARN_ON(*level <= 0);
if (path->nodes[*level-1])
Expand Down
1 change: 1 addition & 0 deletions trunk/fs/btrfs/tree-defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static int defrag_walk_down(struct btrfs_trans_handle *trans,
path->slots[*level]++;
continue;
}
btrfs_verify_block_csum(root, next);
} else {
next = read_tree_block(root, bytenr,
btrfs_level_size(root, *level - 1));
Expand Down

0 comments on commit 0c49196

Please sign in to comment.