diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-10-15 16:22:25 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:03:57 -0400 |
commit | ff79f8190b6e955ff7a71faf804a3017d526e657 (patch) | |
tree | d3f56ae2822eb312eba760dcf4df1a058de5a699 /fs | |
parent | cf786e79e3f96f4bc037c69e1a7afb5fb85c6111 (diff) |
Btrfs: Add back file data checksumming
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/disk-io.c | 1 | ||||
-rw-r--r-- | fs/btrfs/disk-io.h | 2 | ||||
-rw-r--r-- | fs/btrfs/extent_map.c | 3 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 17 | ||||
-rw-r--r-- | fs/btrfs/file.c | 1 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 21 |
6 files changed, 26 insertions, 19 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3878772fcffd..5accced2858a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -594,6 +594,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) | |||
594 | tree_root->nodesize = nodesize; | 594 | tree_root->nodesize = nodesize; |
595 | tree_root->leafsize = leafsize; | 595 | tree_root->leafsize = leafsize; |
596 | tree_root->sectorsize = sectorsize; | 596 | tree_root->sectorsize = sectorsize; |
597 | sb_set_blocksize(sb, sectorsize); | ||
597 | 598 | ||
598 | i_size_write(fs_info->btree_inode, | 599 | i_size_write(fs_info->btree_inode, |
599 | btrfs_super_total_bytes(disk_super)); | 600 | btrfs_super_total_bytes(disk_super)); |
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 190b07bc642b..33d2ccfd74d8 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h | |||
@@ -58,4 +58,6 @@ int btrfs_buffer_defrag_done(struct extent_buffer *buf); | |||
58 | int btrfs_clear_buffer_defrag(struct extent_buffer *buf); | 58 | int btrfs_clear_buffer_defrag(struct extent_buffer *buf); |
59 | int btrfs_clear_buffer_defrag_done(struct extent_buffer *buf); | 59 | int btrfs_clear_buffer_defrag_done(struct extent_buffer *buf); |
60 | int btrfs_read_buffer(struct extent_buffer *buf); | 60 | int btrfs_read_buffer(struct extent_buffer *buf); |
61 | u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len); | ||
62 | void btrfs_csum_final(u32 crc, char *result); | ||
61 | #endif | 63 | #endif |
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 2a8bc4bd43a9..e87e476dca92 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -2031,6 +2031,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree, | |||
2031 | i = 1; | 2031 | i = 1; |
2032 | index++; | 2032 | index++; |
2033 | page_cache_get(page0); | 2033 | page_cache_get(page0); |
2034 | mark_page_accessed(page0); | ||
2034 | set_page_extent_mapped(page0); | 2035 | set_page_extent_mapped(page0); |
2035 | set_page_private(page0, EXTENT_PAGE_PRIVATE_FIRST_PAGE | | 2036 | set_page_private(page0, EXTENT_PAGE_PRIVATE_FIRST_PAGE | |
2036 | len << 2); | 2037 | len << 2); |
@@ -2049,6 +2050,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree, | |||
2049 | goto fail; | 2050 | goto fail; |
2050 | } | 2051 | } |
2051 | set_page_extent_mapped(p); | 2052 | set_page_extent_mapped(p); |
2053 | mark_page_accessed(p); | ||
2052 | if (i == 0) { | 2054 | if (i == 0) { |
2053 | eb->first_page = p; | 2055 | eb->first_page = p; |
2054 | set_page_private(p, EXTENT_PAGE_PRIVATE_FIRST_PAGE | | 2056 | set_page_private(p, EXTENT_PAGE_PRIVATE_FIRST_PAGE | |
@@ -2099,6 +2101,7 @@ struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree, | |||
2099 | goto fail; | 2101 | goto fail; |
2100 | } | 2102 | } |
2101 | set_page_extent_mapped(p); | 2103 | set_page_extent_mapped(p); |
2104 | mark_page_accessed(p); | ||
2102 | 2105 | ||
2103 | if (i == 0) { | 2106 | if (i == 0) { |
2104 | eb->first_page = p; | 2107 | eb->first_page = p; |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 9a65e97a4e28..10a4c7408600 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -136,27 +136,27 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | |||
136 | u64 objectid, u64 offset, | 136 | u64 objectid, u64 offset, |
137 | char *data, size_t len) | 137 | char *data, size_t len) |
138 | { | 138 | { |
139 | return 0; | ||
140 | #if 0 | ||
141 | int ret; | 139 | int ret; |
142 | struct btrfs_key file_key; | 140 | struct btrfs_key file_key; |
143 | struct btrfs_key found_key; | 141 | struct btrfs_key found_key; |
144 | struct btrfs_path *path; | 142 | struct btrfs_path *path; |
145 | struct btrfs_csum_item *item; | 143 | struct btrfs_csum_item *item; |
146 | struct extent_buffer *leaf; | 144 | struct extent_buffer *leaf = NULL; |
147 | u64 csum_offset; | 145 | u64 csum_offset; |
146 | u32 csum_result = ~(u32)0; | ||
148 | 147 | ||
149 | path = btrfs_alloc_path(); | 148 | path = btrfs_alloc_path(); |
150 | BUG_ON(!path); | 149 | BUG_ON(!path); |
151 | 150 | ||
152 | file_key.objectid = objectid; | 151 | file_key.objectid = objectid; |
153 | file_key.offset = offset; | 152 | file_key.offset = offset; |
154 | file_key.flags = 0; | ||
155 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); | 153 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
156 | 154 | ||
157 | item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1); | 155 | item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1); |
158 | if (!IS_ERR(item)) | 156 | if (!IS_ERR(item)) { |
157 | leaf = path->nodes[0]; | ||
159 | goto found; | 158 | goto found; |
159 | } | ||
160 | ret = PTR_ERR(item); | 160 | ret = PTR_ERR(item); |
161 | if (ret == -EFBIG) { | 161 | if (ret == -EFBIG) { |
162 | u32 item_size; | 162 | u32 item_size; |
@@ -226,14 +226,15 @@ csum: | |||
226 | item = (struct btrfs_csum_item *)((unsigned char *)item + | 226 | item = (struct btrfs_csum_item *)((unsigned char *)item + |
227 | csum_offset * BTRFS_CRC32_SIZE); | 227 | csum_offset * BTRFS_CRC32_SIZE); |
228 | found: | 228 | found: |
229 | /* FIXME!!!!!!!!!!!! */ | 229 | csum_result = btrfs_csum_data(root, data, csum_result, len); |
230 | ret = btrfs_csum_data(root, data, len, &item->csum); | 230 | btrfs_csum_final(csum_result, (char *)&csum_result); |
231 | write_extent_buffer(leaf, &csum_result, (unsigned long)item, | ||
232 | BTRFS_CRC32_SIZE); | ||
231 | btrfs_mark_buffer_dirty(path->nodes[0]); | 233 | btrfs_mark_buffer_dirty(path->nodes[0]); |
232 | fail: | 234 | fail: |
233 | btrfs_release_path(root, path); | 235 | btrfs_release_path(root, path); |
234 | btrfs_free_path(path); | 236 | btrfs_free_path(path); |
235 | return ret; | 237 | return ret; |
236 | #endif | ||
237 | } | 238 | } |
238 | 239 | ||
239 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, | 240 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index fe28404ae7f4..1af2b6534dad 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -289,6 +289,7 @@ static int dirty_and_release_pages(struct btrfs_trans_handle *trans, | |||
289 | */ | 289 | */ |
290 | inline_size = end_pos; | 290 | inline_size = end_pos; |
291 | if (isize >= BTRFS_MAX_INLINE_DATA_SIZE(root) || | 291 | if (isize >= BTRFS_MAX_INLINE_DATA_SIZE(root) || |
292 | inline_size > 16384 || | ||
292 | inline_size >= BTRFS_MAX_INLINE_DATA_SIZE(root)) { | 293 | inline_size >= BTRFS_MAX_INLINE_DATA_SIZE(root)) { |
293 | u64 last_end; | 294 | u64 last_end; |
294 | 295 | ||
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 80f84b48a70f..ac69f6926afc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -135,7 +135,7 @@ int btrfs_readpage_io_hook(struct page *page, u64 start, u64 end) | |||
135 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | 135 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; |
136 | struct btrfs_csum_item *item; | 136 | struct btrfs_csum_item *item; |
137 | struct btrfs_path *path = NULL; | 137 | struct btrfs_path *path = NULL; |
138 | u64 private; | 138 | u32 csum; |
139 | 139 | ||
140 | mutex_lock(&root->fs_info->fs_mutex); | 140 | mutex_lock(&root->fs_info->fs_mutex); |
141 | path = btrfs_alloc_path(); | 141 | path = btrfs_alloc_path(); |
@@ -145,11 +145,12 @@ int btrfs_readpage_io_hook(struct page *page, u64 start, u64 end) | |||
145 | /* a csum that isn't present is a preallocated region. */ | 145 | /* a csum that isn't present is a preallocated region. */ |
146 | if (ret == -ENOENT || ret == -EFBIG) | 146 | if (ret == -ENOENT || ret == -EFBIG) |
147 | ret = 0; | 147 | ret = 0; |
148 | private = 0; | 148 | csum = 0; |
149 | goto out; | 149 | goto out; |
150 | } | 150 | } |
151 | memcpy((char *)&private, &item->csum, BTRFS_CRC32_SIZE); | 151 | read_extent_buffer(path->nodes[0], &csum, (unsigned long)item, |
152 | set_state_private(em_tree, start, private); | 152 | BTRFS_CRC32_SIZE); |
153 | set_state_private(em_tree, start, csum); | ||
153 | out: | 154 | out: |
154 | if (path) | 155 | if (path) |
155 | btrfs_free_path(path); | 156 | btrfs_free_path(path); |
@@ -165,21 +166,19 @@ int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end) | |||
165 | char *kaddr; | 166 | char *kaddr; |
166 | u64 private; | 167 | u64 private; |
167 | int ret; | 168 | int ret; |
169 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
170 | u32 csum = ~(u32)0; | ||
168 | 171 | ||
169 | ret = get_state_private(em_tree, start, &private); | 172 | ret = get_state_private(em_tree, start, &private); |
170 | kaddr = kmap_atomic(page, KM_IRQ0); | 173 | kaddr = kmap_atomic(page, KM_IRQ0); |
171 | if (ret) { | 174 | if (ret) { |
172 | goto zeroit; | 175 | goto zeroit; |
173 | } | 176 | } |
174 | /* | 177 | csum = btrfs_csum_data(root, kaddr + offset, csum, end - start + 1); |
175 | struct btrfs_root *root = BTRFS_I(inode)->root; | 178 | btrfs_csum_final(csum, (char *)&csum); |
176 | char csum[BTRFS_CRC32_SIZE]; | 179 | if (csum != private) { |
177 | ret = btrfs_csum_data(root, kaddr + offset, end - start + 1, csum); | ||
178 | BUG_ON(ret); | ||
179 | if (memcmp(csum, &private, BTRFS_CRC32_SIZE)) { | ||
180 | goto zeroit; | 180 | goto zeroit; |
181 | } | 181 | } |
182 | */ | ||
183 | kunmap_atomic(kaddr, KM_IRQ0); | 182 | kunmap_atomic(kaddr, KM_IRQ0); |
184 | return 0; | 183 | return 0; |
185 | 184 | ||