Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128508
b: refs/heads/master
c: f578d4b
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 648a90c commit 4eb8fec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 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: 5ee78ac70f6c01f2a5acf662c2af975665710edc
refs/heads/master: f578d4bd7e141dd03ca7e8695c1cc118c326e69e
1 change: 1 addition & 0 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
u64 bytenr, int mod);
int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *inode,
u64 objectid, u64 offset,
char *data, size_t len);
struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
Expand Down
37 changes: 36 additions & 1 deletion trunk/fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,22 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,

int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *inode,
u64 objectid, u64 offset,
char *data, size_t len)
{
int ret;
struct btrfs_key file_key;
struct btrfs_key found_key;
u64 next_offset = (u64)-1;
int found_next = 0;
struct btrfs_path *path;
struct btrfs_csum_item *item;
struct extent_buffer *leaf = NULL;
u64 csum_offset;
u32 csum_result = ~(u32)0;
u32 nritems;
u32 ins_size;

path = btrfs_alloc_path();
BUG_ON(!path);
Expand All @@ -168,7 +173,27 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
goto insert;
}
} else {
int slot = path->slots[0] + 1;
/* we didn't find a csum item, insert one */
nritems = btrfs_header_nritems(path->nodes[0]);
if (path->slots[0] >= nritems - 1) {
ret = btrfs_next_leaf(root, path);
if (ret == 1) {
found_next = 1;
} else if (ret == 0) {
slot = 0;
} else {
goto insert;
}
}
btrfs_item_key_to_cpu(path->nodes[0], &found_key, slot);
if (found_key.objectid != objectid ||
found_key.type != BTRFS_CSUM_ITEM_KEY) {
found_next = 1;
goto insert;
}
next_offset = found_key.offset;
found_next = 1;
goto insert;
}

Expand Down Expand Up @@ -211,8 +236,18 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
insert:
btrfs_release_path(root, path);
csum_offset = 0;
if (found_next) {
u64 tmp = min((u64)i_size_read(inode), next_offset);
tmp -= offset + root->sectorsize - 1;
tmp >>= root->fs_info->sb->s_blocksize_bits;
tmp = max((u64)1, tmp);
tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root));
ins_size = BTRFS_CRC32_SIZE * tmp;
} else {
ins_size = BTRFS_CRC32_SIZE;
}
ret = btrfs_insert_empty_item(trans, root, path, &file_key,
BTRFS_CRC32_SIZE);
ins_size);
if (ret < 0)
goto fail;
if (ret != 0) {
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int btrfs_writepage_io_hook(struct page *page, u64 start, u64 end)
trans = btrfs_start_transaction(root, 1);
btrfs_set_trans_block_group(trans, inode);
kaddr = kmap(page);
btrfs_csum_file_block(trans, root, inode->i_ino,
btrfs_csum_file_block(trans, root, inode, inode->i_ino,
start, kaddr + offset, end - start + 1);
kunmap(page);
ret = btrfs_end_transaction(trans, root);
Expand Down

0 comments on commit 4eb8fec

Please sign in to comment.