aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file-item.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-06-22 14:16:25 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-06-22 14:16:25 -0400
commit54aa1f4dfdacd60a19c4471220b24e581be6f774 (patch)
tree1462277822cc63c00ad31b522457363a5c6be6ab /fs/btrfs/file-item.c
parent11bd143fc8243cf48c934dc1c4479a5aacf58ce3 (diff)
Btrfs: Audit callers and return codes to make sure -ENOSPC gets up the stack
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r--fs/btrfs/file-item.c46
1 files changed, 6 insertions, 40 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index cf894f09f6c7..68859934ae25 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -45,6 +45,8 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
45 45
46 ret = btrfs_insert_empty_item(trans, root, path, &file_key, 46 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
47 sizeof(*item)); 47 sizeof(*item));
48 if (ret < 0)
49 goto out;
48 BUG_ON(ret); 50 BUG_ON(ret);
49 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], 51 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
50 struct btrfs_file_extent_item); 52 struct btrfs_file_extent_item);
@@ -55,10 +57,9 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
55 btrfs_set_file_extent_generation(item, trans->transid); 57 btrfs_set_file_extent_generation(item, trans->transid);
56 btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG); 58 btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG);
57 btrfs_mark_buffer_dirty(path->nodes[0]); 59 btrfs_mark_buffer_dirty(path->nodes[0]);
58 60out:
59 btrfs_release_path(root, path);
60 btrfs_free_path(path); 61 btrfs_free_path(path);
61 return 0; 62 return ret;
62} 63}
63 64
64struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, 65struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
@@ -213,6 +214,8 @@ insert:
213 csum_offset = 0; 214 csum_offset = 0;
214 ret = btrfs_insert_empty_item(trans, root, path, &file_key, 215 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
215 BTRFS_CRC32_SIZE); 216 BTRFS_CRC32_SIZE);
217 if (ret < 0)
218 goto fail;
216 if (ret != 0) { 219 if (ret != 0) {
217 WARN_ON(1); 220 WARN_ON(1);
218 goto fail; 221 goto fail;
@@ -261,40 +264,3 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
261 return ret; 264 return ret;
262} 265}
263 266
264int btrfs_csum_verify_file_block(struct btrfs_root *root,
265 u64 objectid, u64 offset,
266 char *data, size_t len)
267{
268 int ret;
269 struct btrfs_key file_key;
270 struct btrfs_path *path;
271 struct btrfs_csum_item *item;
272 char result[BTRFS_CRC32_SIZE];
273
274 path = btrfs_alloc_path();
275 BUG_ON(!path);
276 file_key.objectid = objectid;
277 file_key.offset = offset;
278 file_key.flags = 0;
279 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
280 mutex_lock(&root->fs_info->fs_mutex);
281
282 item = btrfs_lookup_csum(NULL, root, path, objectid, offset, 0);
283 if (IS_ERR(item)) {
284 ret = PTR_ERR(item);
285 /* a csum that isn't present is a preallocated region. */
286 if (ret == -ENOENT || ret == -EFBIG)
287 ret = -ENOENT;
288 goto fail;
289 }
290
291 ret = btrfs_csum_data(root, data, len, result);
292 WARN_ON(ret);
293 if (memcmp(result, &item->csum, BTRFS_CRC32_SIZE))
294 ret = 1;
295fail:
296 btrfs_release_path(root, path);
297 btrfs_free_path(path);
298 mutex_unlock(&root->fs_info->fs_mutex);
299 return ret;
300}