diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-04-17 15:39:32 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-04-17 15:39:32 -0400 |
commit | 70b2befd0c8a4064715d8b340270650cc9d15af8 (patch) | |
tree | 81171607c9ddf501e5c0233dc24d20d1a5b19858 /fs/btrfs/file-item.c | |
parent | b18c6685810af8e6763760711aece31ccc7a8ea8 (diff) |
Btrfs: rework csums and extent item ordering
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r-- | fs/btrfs/file-item.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index f49968ad0a07..ff8f3339c684 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -62,23 +62,19 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | |||
62 | file_key.offset = offset; | 62 | file_key.offset = offset; |
63 | file_key.flags = 0; | 63 | file_key.flags = 0; |
64 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); | 64 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
65 | printk("__lookup for %Lu\n", offset); | ||
66 | ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow); | 65 | ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow); |
67 | if (ret < 0) | 66 | if (ret < 0) |
68 | goto fail; | 67 | goto fail; |
69 | leaf = btrfs_buffer_leaf(path->nodes[0]); | 68 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
70 | if (ret > 0) { | 69 | if (ret > 0) { |
71 | ret = 1; | 70 | ret = 1; |
72 | if (path->slots[0] == 0) { | 71 | if (path->slots[0] == 0) |
73 | printk("fail1\n"); | ||
74 | goto fail; | 72 | goto fail; |
75 | } | ||
76 | path->slots[0]--; | 73 | path->slots[0]--; |
77 | btrfs_disk_key_to_cpu(&found_key, | 74 | btrfs_disk_key_to_cpu(&found_key, |
78 | &leaf->items[path->slots[0]].key); | 75 | &leaf->items[path->slots[0]].key); |
79 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || | 76 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || |
80 | found_key.objectid != objectid) { | 77 | found_key.objectid != objectid) { |
81 | printk("fail2 type %u %Lu %Lu\n", btrfs_key_type(&found_key), found_key.objectid, objectid); | ||
82 | goto fail; | 78 | goto fail; |
83 | } | 79 | } |
84 | csum_offset = (offset - found_key.offset) >> | 80 | csum_offset = (offset - found_key.offset) >> |
@@ -86,7 +82,6 @@ printk("fail2 type %u %Lu %Lu\n", btrfs_key_type(&found_key), found_key.objectid | |||
86 | if (csum_offset >= | 82 | if (csum_offset >= |
87 | btrfs_item_size(leaf->items + path->slots[0]) / | 83 | btrfs_item_size(leaf->items + path->slots[0]) / |
88 | sizeof(struct btrfs_csum_item)) { | 84 | sizeof(struct btrfs_csum_item)) { |
89 | printk("fail3, csum offset %lu size %u\n", csum_offset, btrfs_item_size(leaf->items + path->slots[0]) / sizeof(struct btrfs_csum_item)); | ||
90 | goto fail; | 85 | goto fail; |
91 | } | 86 | } |
92 | } | 87 | } |
@@ -109,26 +104,18 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, | |||
109 | struct btrfs_key file_key; | 104 | struct btrfs_key file_key; |
110 | int ins_len = mod < 0 ? -1 : 0; | 105 | int ins_len = mod < 0 ? -1 : 0; |
111 | int cow = mod != 0; | 106 | int cow = mod != 0; |
112 | struct btrfs_csum_item *csum_item; | ||
113 | 107 | ||
114 | csum_item = btrfs_lookup_csum(trans, root, path, objectid, offset, 0); | ||
115 | if (IS_ERR(csum_item)) | ||
116 | return PTR_ERR(csum_item); | ||
117 | file_key.objectid = objectid; | 108 | file_key.objectid = objectid; |
118 | file_key.offset = btrfs_csum_extent_offset(csum_item); | 109 | file_key.offset = offset; |
119 | file_key.flags = 0; | 110 | file_key.flags = 0; |
120 | btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); | 111 | btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); |
121 | btrfs_release_path(root, path); | ||
122 | printk("lookup file extent searches for %Lu\n", file_key.offset); | ||
123 | ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow); | 112 | ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow); |
124 | printk("ret is %d\n", ret); | ||
125 | return ret; | 113 | return ret; |
126 | } | 114 | } |
127 | 115 | ||
128 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | 116 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
129 | struct btrfs_root *root, | 117 | struct btrfs_root *root, |
130 | u64 objectid, u64 offset, | 118 | u64 objectid, u64 offset, |
131 | u64 extent_offset, | ||
132 | char *data, size_t len) | 119 | char *data, size_t len) |
133 | { | 120 | { |
134 | int ret; | 121 | int ret; |
@@ -151,10 +138,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | |||
151 | file_key.offset = offset; | 138 | file_key.offset = offset; |
152 | file_key.flags = 0; | 139 | file_key.flags = 0; |
153 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); | 140 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
154 | printk("searching for csum %Lu %Lu\n", objectid, offset); | ||
155 | ret = btrfs_search_slot(trans, root, &file_key, path, | 141 | ret = btrfs_search_slot(trans, root, &file_key, path, |
156 | sizeof(struct btrfs_csum_item), 1); | 142 | sizeof(struct btrfs_csum_item), 1); |
157 | printk("ret %d\n", ret); | ||
158 | if (ret < 0) | 143 | if (ret < 0) |
159 | goto fail; | 144 | goto fail; |
160 | if (ret == 0) { | 145 | if (ret == 0) { |
@@ -167,15 +152,12 @@ printk("ret %d\n", ret); | |||
167 | path->slots[0]--; | 152 | path->slots[0]--; |
168 | leaf = btrfs_buffer_leaf(path->nodes[0]); | 153 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
169 | btrfs_disk_key_to_cpu(&found_key, &leaf->items[path->slots[0]].key); | 154 | btrfs_disk_key_to_cpu(&found_key, &leaf->items[path->slots[0]].key); |
170 | printk("found key %Lu %Lu %u\n", found_key.objectid, found_key.offset, found_key.flags); | ||
171 | csum_offset = (offset - found_key.offset) >> | 155 | csum_offset = (offset - found_key.offset) >> |
172 | root->fs_info->sb->s_blocksize_bits; | 156 | root->fs_info->sb->s_blocksize_bits; |
173 | printk("csum_offset %Lu\n", csum_offset); | ||
174 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || | 157 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || |
175 | found_key.objectid != objectid || | 158 | found_key.objectid != objectid || |
176 | csum_offset >= MAX_CSUM_ITEMS(root)) { | 159 | csum_offset >= MAX_CSUM_ITEMS(root)) { |
177 | btrfs_release_path(root, path); | 160 | btrfs_release_path(root, path); |
178 | printk("insert1\n"); | ||
179 | goto insert; | 161 | goto insert; |
180 | } | 162 | } |
181 | if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / | 163 | if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / |
@@ -183,13 +165,11 @@ printk("insert1\n"); | |||
183 | ret = btrfs_extend_item(trans, root, path, | 165 | ret = btrfs_extend_item(trans, root, path, |
184 | sizeof(struct btrfs_csum_item)); | 166 | sizeof(struct btrfs_csum_item)); |
185 | BUG_ON(ret); | 167 | BUG_ON(ret); |
186 | printk("item extended\n"); | ||
187 | goto csum; | 168 | goto csum; |
188 | } | 169 | } |
189 | 170 | ||
190 | insert: | 171 | insert: |
191 | csum_offset = 0; | 172 | csum_offset = 0; |
192 | printk("inserting item %Lu %Lu %u\n", file_key.objectid, file_key.offset, file_key.flags); | ||
193 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, | 173 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
194 | sizeof(struct btrfs_csum_item)); | 174 | sizeof(struct btrfs_csum_item)); |
195 | if (ret != 0 && ret != -EEXIST) | 175 | if (ret != 0 && ret != -EEXIST) |
@@ -201,12 +181,10 @@ csum: | |||
201 | item += csum_offset; | 181 | item += csum_offset; |
202 | found: | 182 | found: |
203 | ret = btrfs_csum_data(root, data, len, item->csum); | 183 | ret = btrfs_csum_data(root, data, len, item->csum); |
204 | btrfs_set_csum_extent_offset(item, extent_offset); | ||
205 | btrfs_mark_buffer_dirty(path->nodes[0]); | 184 | btrfs_mark_buffer_dirty(path->nodes[0]); |
206 | fail: | 185 | fail: |
207 | btrfs_release_path(root, path); | 186 | btrfs_release_path(root, path); |
208 | btrfs_free_path(path); | 187 | btrfs_free_path(path); |
209 | printk("return ret %d\n", ret); | ||
210 | return ret; | 188 | return ret; |
211 | } | 189 | } |
212 | 190 | ||