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.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index c3992b7b0c60..e7510ac5559d 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -13,9 +13,11 @@ int btrfs_alloc_file_extent(struct btrfs_trans_handle *trans,
13 int ret = 0; 13 int ret = 0;
14 struct btrfs_file_extent_item *item; 14 struct btrfs_file_extent_item *item;
15 struct btrfs_key file_key; 15 struct btrfs_key file_key;
16 struct btrfs_path path; 16 struct btrfs_path *path;
17 17
18 btrfs_init_path(&path); 18 path = btrfs_alloc_path();
19 BUG_ON(!path);
20 btrfs_init_path(path);
19 ret = btrfs_alloc_extent(trans, root, num_blocks, hint_block, 21 ret = btrfs_alloc_extent(trans, root, num_blocks, hint_block,
20 (u64)-1, objectid, &ins); 22 (u64)-1, objectid, &ins);
21 BUG_ON(ret); 23 BUG_ON(ret);
@@ -24,19 +26,20 @@ int btrfs_alloc_file_extent(struct btrfs_trans_handle *trans,
24 file_key.flags = 0; 26 file_key.flags = 0;
25 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); 27 btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);
26 28
27 ret = btrfs_insert_empty_item(trans, root, &path, &file_key, 29 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
28 sizeof(*item)); 30 sizeof(*item));
29 BUG_ON(ret); 31 BUG_ON(ret);
30 item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), path.slots[0], 32 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
31 struct btrfs_file_extent_item); 33 struct btrfs_file_extent_item);
32 btrfs_set_file_extent_disk_blocknr(item, ins.objectid); 34 btrfs_set_file_extent_disk_blocknr(item, ins.objectid);
33 btrfs_set_file_extent_disk_num_blocks(item, ins.offset); 35 btrfs_set_file_extent_disk_num_blocks(item, ins.offset);
34 btrfs_set_file_extent_offset(item, 0); 36 btrfs_set_file_extent_offset(item, 0);
35 btrfs_set_file_extent_num_blocks(item, ins.offset); 37 btrfs_set_file_extent_num_blocks(item, ins.offset);
36 btrfs_set_file_extent_generation(item, trans->transid); 38 btrfs_set_file_extent_generation(item, trans->transid);
37 btrfs_mark_buffer_dirty(path.nodes[0]); 39 btrfs_mark_buffer_dirty(path->nodes[0]);
38 *result = ins.objectid; 40 *result = ins.objectid;
39 btrfs_release_path(root, &path); 41 btrfs_release_path(root, path);
42 btrfs_free_path(path);
40 return 0; 43 return 0;
41} 44}
42 45
@@ -65,25 +68,28 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
65{ 68{
66 int ret; 69 int ret;
67 struct btrfs_key file_key; 70 struct btrfs_key file_key;
68 struct btrfs_path path; 71 struct btrfs_path *path;
69 struct btrfs_csum_item *item; 72 struct btrfs_csum_item *item;
70 73
71 btrfs_init_path(&path); 74 path = btrfs_alloc_path();
75 BUG_ON(!path);
76 btrfs_init_path(path);
72 file_key.objectid = objectid; 77 file_key.objectid = objectid;
73 file_key.offset = offset; 78 file_key.offset = offset;
74 file_key.flags = 0; 79 file_key.flags = 0;
75 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); 80 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
76 ret = btrfs_insert_empty_item(trans, root, &path, &file_key, 81 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
77 BTRFS_CSUM_SIZE); 82 BTRFS_CSUM_SIZE);
78 if (ret != 0 && ret != -EEXIST) 83 if (ret != 0 && ret != -EEXIST)
79 goto fail; 84 goto fail;
80 item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), path.slots[0], 85 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
81 struct btrfs_csum_item); 86 struct btrfs_csum_item);
82 ret = 0; 87 ret = 0;
83 ret = btrfs_csum_data(root, data, len, item->csum); 88 ret = btrfs_csum_data(root, data, len, item->csum);
84 btrfs_mark_buffer_dirty(path.nodes[0]); 89 btrfs_mark_buffer_dirty(path->nodes[0]);
85fail: 90fail:
86 btrfs_release_path(root, &path); 91 btrfs_release_path(root, path);
92 btrfs_free_path(path);
87 return ret; 93 return ret;
88} 94}
89 95
@@ -93,19 +99,21 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root,
93{ 99{
94 int ret; 100 int ret;
95 struct btrfs_key file_key; 101 struct btrfs_key file_key;
96 struct btrfs_path path; 102 struct btrfs_path *path;
97 struct btrfs_csum_item *item; 103 struct btrfs_csum_item *item;
98 char result[BTRFS_CSUM_SIZE]; 104 char result[BTRFS_CSUM_SIZE];
99 105
100 btrfs_init_path(&path); 106 path = btrfs_alloc_path();
107 BUG_ON(!path);
108 btrfs_init_path(path);
101 file_key.objectid = objectid; 109 file_key.objectid = objectid;
102 file_key.offset = offset; 110 file_key.offset = offset;
103 file_key.flags = 0; 111 file_key.flags = 0;
104 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); 112 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
105 ret = btrfs_search_slot(NULL, root, &file_key, &path, 0, 0); 113 ret = btrfs_search_slot(NULL, root, &file_key, path, 0, 0);
106 if (ret) 114 if (ret)
107 goto fail; 115 goto fail;
108 item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), path.slots[0], 116 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
109 struct btrfs_csum_item); 117 struct btrfs_csum_item);
110 ret = 0; 118 ret = 0;
111 ret = btrfs_csum_data(root, data, len, result); 119 ret = btrfs_csum_data(root, data, len, result);
@@ -113,7 +121,8 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root,
113 if (memcmp(result, item->csum, BTRFS_CSUM_SIZE)) 121 if (memcmp(result, item->csum, BTRFS_CSUM_SIZE))
114 ret = 1; 122 ret = 1;
115fail: 123fail:
116 btrfs_release_path(root, &path); 124 btrfs_release_path(root, path);
125 btrfs_free_path(path);
117 return ret; 126 return ret;
118} 127}
119 128