aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r--fs/btrfs/file-item.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index ea4dd4c5fce3..226f6d028c3f 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -34,12 +34,12 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
34 struct btrfs_file_extent_item *item; 34 struct btrfs_file_extent_item *item;
35 struct btrfs_key file_key; 35 struct btrfs_key file_key;
36 struct btrfs_path *path; 36 struct btrfs_path *path;
37 struct extent_buffer *leaf;
37 38
38 path = btrfs_alloc_path(); 39 path = btrfs_alloc_path();
39 BUG_ON(!path); 40 BUG_ON(!path);
40 file_key.objectid = objectid; 41 file_key.objectid = objectid;
41 file_key.offset = pos; 42 file_key.offset = pos;
42 file_key.flags = 0;
43 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); 43 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);
44 44
45 ret = btrfs_insert_empty_item(trans, root, path, &file_key, 45 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
@@ -47,15 +47,16 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
47 if (ret < 0) 47 if (ret < 0)
48 goto out; 48 goto out;
49 BUG_ON(ret); 49 BUG_ON(ret);
50 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], 50 leaf = path->nodes[0];
51 item = btrfs_item_ptr(leaf, path->slots[0],
51 struct btrfs_file_extent_item); 52 struct btrfs_file_extent_item);
52 btrfs_set_file_extent_disk_blocknr(item, offset); 53 btrfs_set_file_extent_disk_blocknr(leaf, item, offset);
53 btrfs_set_file_extent_disk_num_blocks(item, disk_num_blocks); 54 btrfs_set_file_extent_disk_num_blocks(leaf, item, disk_num_blocks);
54 btrfs_set_file_extent_offset(item, 0); 55 btrfs_set_file_extent_offset(leaf, item, 0);
55 btrfs_set_file_extent_num_blocks(item, num_blocks); 56 btrfs_set_file_extent_num_blocks(leaf, item, num_blocks);
56 btrfs_set_file_extent_generation(item, trans->transid); 57 btrfs_set_file_extent_generation(leaf, item, trans->transid);
57 btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG); 58 btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG);
58 btrfs_mark_buffer_dirty(path->nodes[0]); 59 btrfs_mark_buffer_dirty(leaf);
59out: 60out:
60 btrfs_free_path(path); 61 btrfs_free_path(path);
61 return ret; 62 return ret;
@@ -71,32 +72,30 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
71 struct btrfs_key file_key; 72 struct btrfs_key file_key;
72 struct btrfs_key found_key; 73 struct btrfs_key found_key;
73 struct btrfs_csum_item *item; 74 struct btrfs_csum_item *item;
74 struct btrfs_leaf *leaf; 75 struct extent_buffer *leaf;
75 u64 csum_offset = 0; 76 u64 csum_offset = 0;
76 int csums_in_item; 77 int csums_in_item;
77 78
78 file_key.objectid = objectid; 79 file_key.objectid = objectid;
79 file_key.offset = offset; 80 file_key.offset = offset;
80 file_key.flags = 0;
81 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); 81 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
82 ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow); 82 ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow);
83 if (ret < 0) 83 if (ret < 0)
84 goto fail; 84 goto fail;
85 leaf = btrfs_buffer_leaf(path->nodes[0]); 85 leaf = path->nodes[0];
86 if (ret > 0) { 86 if (ret > 0) {
87 ret = 1; 87 ret = 1;
88 if (path->slots[0] == 0) 88 if (path->slots[0] == 0)
89 goto fail; 89 goto fail;
90 path->slots[0]--; 90 path->slots[0]--;
91 btrfs_disk_key_to_cpu(&found_key, 91 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
92 &leaf->items[path->slots[0]].key);
93 if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || 92 if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY ||
94 found_key.objectid != objectid) { 93 found_key.objectid != objectid) {
95 goto fail; 94 goto fail;
96 } 95 }
97 csum_offset = (offset - found_key.offset) >> 96 csum_offset = (offset - found_key.offset) >>
98 root->fs_info->sb->s_blocksize_bits; 97 root->fs_info->sb->s_blocksize_bits;
99 csums_in_item = btrfs_item_size(leaf->items + path->slots[0]); 98 csums_in_item = btrfs_item_size_nr(leaf, path->slots[0]);
100 csums_in_item /= BTRFS_CRC32_SIZE; 99 csums_in_item /= BTRFS_CRC32_SIZE;
101 100
102 if (csum_offset >= csums_in_item) { 101 if (csum_offset >= csums_in_item) {
@@ -127,7 +126,6 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
127 126
128 file_key.objectid = objectid; 127 file_key.objectid = objectid;
129 file_key.offset = offset; 128 file_key.offset = offset;
130 file_key.flags = 0;
131 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); 129 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);
132 ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow); 130 ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow);
133 return ret; 131 return ret;
@@ -138,12 +136,14 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
138 u64 objectid, u64 offset, 136 u64 objectid, u64 offset,
139 char *data, size_t len) 137 char *data, size_t len)
140{ 138{
139 return 0;
140#if 0
141 int ret; 141 int ret;
142 struct btrfs_key file_key; 142 struct btrfs_key file_key;
143 struct btrfs_key found_key; 143 struct btrfs_key found_key;
144 struct btrfs_path *path; 144 struct btrfs_path *path;
145 struct btrfs_csum_item *item; 145 struct btrfs_csum_item *item;
146 struct btrfs_leaf *leaf; 146 struct extent_buffer *leaf;
147 u64 csum_offset; 147 u64 csum_offset;
148 148
149 path = btrfs_alloc_path(); 149 path = btrfs_alloc_path();
@@ -161,8 +161,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
161 if (ret == -EFBIG) { 161 if (ret == -EFBIG) {
162 u32 item_size; 162 u32 item_size;
163 /* we found one, but it isn't big enough yet */ 163 /* we found one, but it isn't big enough yet */
164 leaf = btrfs_buffer_leaf(path->nodes[0]); 164 leaf = path->nodes[0];
165 item_size = btrfs_item_size(leaf->items + path->slots[0]); 165 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
166 if ((item_size / BTRFS_CRC32_SIZE) >= MAX_CSUM_ITEMS(root)) { 166 if ((item_size / BTRFS_CRC32_SIZE) >= MAX_CSUM_ITEMS(root)) {
167 /* already at max size, make a new one */ 167 /* already at max size, make a new one */
168 goto insert; 168 goto insert;
@@ -188,8 +188,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
188 goto insert; 188 goto insert;
189 } 189 }
190 path->slots[0]--; 190 path->slots[0]--;
191 leaf = btrfs_buffer_leaf(path->nodes[0]); 191 leaf = path->nodes[0];
192 btrfs_disk_key_to_cpu(&found_key, &leaf->items[path->slots[0]].key); 192 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
193 csum_offset = (offset - found_key.offset) >> 193 csum_offset = (offset - found_key.offset) >>
194 root->fs_info->sb->s_blocksize_bits; 194 root->fs_info->sb->s_blocksize_bits;
195 if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || 195 if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY ||
@@ -197,10 +197,10 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
197 csum_offset >= MAX_CSUM_ITEMS(root)) { 197 csum_offset >= MAX_CSUM_ITEMS(root)) {
198 goto insert; 198 goto insert;
199 } 199 }
200 if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / 200 if (csum_offset >= btrfs_item_size_nr(leaf, path->slots[0]) /
201 BTRFS_CRC32_SIZE) { 201 BTRFS_CRC32_SIZE) {
202 u32 diff = (csum_offset + 1) * BTRFS_CRC32_SIZE; 202 u32 diff = (csum_offset + 1) * BTRFS_CRC32_SIZE;
203 diff = diff - btrfs_item_size(leaf->items + path->slots[0]); 203 diff = diff - btrfs_item_size_nr(leaf, path->slots[0]);
204 if (diff != BTRFS_CRC32_SIZE) 204 if (diff != BTRFS_CRC32_SIZE)
205 goto insert; 205 goto insert;
206 ret = btrfs_extend_item(trans, root, path, diff); 206 ret = btrfs_extend_item(trans, root, path, diff);
@@ -220,21 +220,20 @@ insert:
220 goto fail; 220 goto fail;
221 } 221 }
222csum: 222csum:
223 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], 223 leaf = path->nodes[0];
224 struct btrfs_csum_item); 224 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item);
225 ret = 0; 225 ret = 0;
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);
228found: 228found:
229 btrfs_check_bounds(&item->csum, BTRFS_CRC32_SIZE, 229 /* FIXME!!!!!!!!!!!! */
230 path->nodes[0]->b_data,
231 root->fs_info->sb->s_blocksize);
232 ret = btrfs_csum_data(root, data, len, &item->csum); 230 ret = btrfs_csum_data(root, data, len, &item->csum);
233 btrfs_mark_buffer_dirty(path->nodes[0]); 231 btrfs_mark_buffer_dirty(path->nodes[0]);
234fail: 232fail:
235 btrfs_release_path(root, path); 233 btrfs_release_path(root, path);
236 btrfs_free_path(path); 234 btrfs_free_path(path);
237 return ret; 235 return ret;
236#endif
238} 237}
239 238
240int btrfs_csum_truncate(struct btrfs_trans_handle *trans, 239int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
@@ -242,21 +241,21 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
242 u64 isize) 241 u64 isize)
243{ 242{
244 struct btrfs_key key; 243 struct btrfs_key key;
245 struct btrfs_leaf *leaf = btrfs_buffer_leaf(path->nodes[0]); 244 struct extent_buffer *leaf = path->nodes[0];
246 int slot = path->slots[0]; 245 int slot = path->slots[0];
247 int ret; 246 int ret;
248 u32 new_item_size; 247 u32 new_item_size;
249 u64 new_item_span; 248 u64 new_item_span;
250 u64 blocks; 249 u64 blocks;
251 250
252 btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key); 251 btrfs_item_key_to_cpu(leaf, &key, slot);
253 if (isize <= key.offset) 252 if (isize <= key.offset)
254 return 0; 253 return 0;
255 new_item_span = isize - key.offset; 254 new_item_span = isize - key.offset;
256 blocks = (new_item_span + root->blocksize - 1) >> 255 blocks = (new_item_span + root->sectorsize - 1) >>
257 root->fs_info->sb->s_blocksize_bits; 256 root->fs_info->sb->s_blocksize_bits;
258 new_item_size = blocks * BTRFS_CRC32_SIZE; 257 new_item_size = blocks * BTRFS_CRC32_SIZE;
259 if (new_item_size >= btrfs_item_size(leaf->items + slot)) 258 if (new_item_size >= btrfs_item_size_nr(leaf, slot))
260 return 0; 259 return 0;
261 ret = btrfs_truncate_item(trans, root, path, new_item_size); 260 ret = btrfs_truncate_item(trans, root, path, new_item_size);
262 BUG_ON(ret); 261 BUG_ON(ret);